| 108 | */ |
| 109 | |
| 110 | int /* O - 1 on success, 0 on failure */ |
| 111 | _cupsArrayAddStrings(cups_array_t *a, /* I - Array */ |
| 112 | const char *s, /* I - Delimited strings or NULL */ |
| 113 | char delim)/* I - Delimiter character */ |
| 114 | { |
| 115 | char *buffer, /* Copy of string */ |
| 116 | *start, /* Start of string */ |
| 117 | *end; /* End of string */ |
| 118 | int status = 1; /* Status of add */ |
| 119 | |
| 120 | |
| 121 | DEBUG_printf(("_cupsArrayAddStrings(a=%p, s=\"%s\", delim='%c')", (void *)a, s, delim)); |
| 122 | |
| 123 | if (!a || !s || !*s) |
| 124 | { |
| 125 | DEBUG_puts("1_cupsArrayAddStrings: Returning 0"); |
| 126 | return (0); |
| 127 | } |
| 128 | |
| 129 | if (delim == ' ') |
| 130 | { |
| 131 | /* |
| 132 | * Skip leading whitespace... |
| 133 | */ |
| 134 | |
| 135 | DEBUG_puts("1_cupsArrayAddStrings: Skipping leading whitespace."); |
| 136 | |
| 137 | while (*s && isspace(*s & 255)) |
| 138 | s ++; |
| 139 | |
| 140 | DEBUG_printf(("1_cupsArrayAddStrings: Remaining string \"%s\".", s)); |
| 141 | } |
| 142 | |
| 143 | if (!strchr(s, delim) && |
| 144 | (delim != ' ' || (!strchr(s, '\t') && !strchr(s, '\n')))) |
| 145 | { |
| 146 | /* |
| 147 | * String doesn't contain a delimiter, so add it as a single value... |
| 148 | */ |
| 149 | |
| 150 | DEBUG_puts("1_cupsArrayAddStrings: No delimiter seen, adding a single " |
| 151 | "value."); |
| 152 | |
| 153 | if (!cupsArrayFind(a, (void *)s)) |
| 154 | status = cupsArrayAdd(a, (void *)s); |
| 155 | } |
| 156 | else if ((buffer = strdup(s)) == NULL) |
| 157 | { |
| 158 | DEBUG_puts("1_cupsArrayAddStrings: Unable to duplicate string."); |
| 159 | status = 0; |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | for (start = end = buffer; *end; start = end) |
| 164 | { |
| 165 | /* |
| 166 | * Find the end of the current delimited string and see if we need to add |
| 167 | * it... |