| 5659 | */ |
| 5660 | |
| 5661 | static void |
| 5662 | pwg_unppdize_name(const char *ppd, /* I - PPD keyword */ |
| 5663 | char *name, /* I - Name buffer */ |
| 5664 | size_t namesize, /* I - Size of name buffer */ |
| 5665 | const char *dashchars)/* I - Characters to be replaced by dashes */ |
| 5666 | { |
| 5667 | char *ptr, /* Pointer into name buffer */ |
| 5668 | *end; /* End of name buffer */ |
| 5669 | int nodash = 1; /* Next char in IPP name cannot be a |
| 5670 | dash (first char or after a dash) */ |
| 5671 | |
| 5672 | |
| 5673 | if (_cups_islower(*ppd)) |
| 5674 | { |
| 5675 | /* |
| 5676 | * Already lowercase name, use as-is? |
| 5677 | */ |
| 5678 | |
| 5679 | const char *ppdptr; /* Pointer into PPD keyword */ |
| 5680 | |
| 5681 | for (ppdptr = ppd + 1; *ppdptr; ppdptr ++) |
| 5682 | if (_cups_isupper(*ppdptr) || strchr(dashchars, *ppdptr) || |
| 5683 | (*ppdptr == '-' && *(ppdptr - 1) == '-') || |
| 5684 | (*ppdptr == '-' && *(ppdptr + 1) == '\0')) |
| 5685 | break; |
| 5686 | |
| 5687 | if (!*ppdptr) |
| 5688 | { |
| 5689 | strlcpy(name, ppd, namesize); |
| 5690 | return; |
| 5691 | } |
| 5692 | } |
| 5693 | |
| 5694 | for (ptr = name, end = name + namesize - 1; *ppd && ptr < end; ppd ++) |
| 5695 | { |
| 5696 | if (_cups_isalnum(*ppd) || *ppd == '.' || *ppd == '_') |
| 5697 | { |
| 5698 | *ptr++ = (char)tolower(*ppd & 255); |
| 5699 | nodash = 0; |
| 5700 | } |
| 5701 | else if (*ppd == '-' || strchr(dashchars, *ppd)) |
| 5702 | { |
| 5703 | if (nodash == 0) |
| 5704 | { |
| 5705 | *ptr++ = '-'; |
| 5706 | nodash = 1; |
| 5707 | } |
| 5708 | } |
| 5709 | |
| 5710 | if (nodash == 0) |
| 5711 | { |
| 5712 | if (!_cups_isupper(*ppd) && _cups_isalnum(*ppd) && |
| 5713 | _cups_isupper(ppd[1]) && ptr < end) |
| 5714 | { |
| 5715 | *ptr++ = '-'; |
| 5716 | nodash = 1; |
| 5717 | } |
| 5718 | else if (!isdigit(*ppd & 255) && isdigit(ppd[1] & 255)) |
no test coverage detected