168
168
int wordamount=1;
170
174
pat = (URLPattern*)&glob->pattern[glob->size / 2];
171
175
/* patterns 0,1,2,... correspond to size=1,3,5,... */
174
178
if (isalpha((int)*pattern)) { /* character range detected */
175
182
pat->type = UPTCharRange;
176
if (sscanf(pattern, "%c-%c]", &pat->content.CharRange.min_c,
177
&pat->content.CharRange.max_c) != 2 ||
178
pat->content.CharRange.min_c >= pat->content.CharRange.max_c ||
179
pat->content.CharRange.max_c - pat->content.CharRange.min_c > 'z' - 'a') {
183
rc = sscanf(pattern, "%c-%c%c%d%c", &min_c, &max_c, &sep, &step, &sep2);
184
if ((rc < 3) || (min_c >= max_c) || ((max_c - min_c) > ('z' - 'a'))) {
180
185
/* the pattern is not well-formed */
181
186
snprintf(glob->errormsg, sizeof(glob->errormsg),
182
"illegal pattern or range specification after pos %d\n", pos);
185
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c;
186
/* always check for a literal (may be "") between patterns */
188
if(GLOB_ERROR == glob_word(glob, pattern + 4, pos + 4, &wordamount))
191
*amount = (pat->content.CharRange.max_c -
192
pat->content.CharRange.min_c + 1) *
187
"errpr: bad range specification after pos %d\n", pos);
191
/* check the (first) separating character */
192
if((sep != ']') && (sep != ':')) {
193
snprintf(glob->errormsg, sizeof(glob->errormsg),
194
"error: unsupported character (%c) after range at pos %d\n",
199
/* if there was a ":[num]" thing, use that as step or else use 1 */
200
pat->content.CharRange.step =
201
((sep == ':') && (rc == 5) && (sep2 == ']'))?step:1;
203
pat->content.CharRange.ptr_c = pat->content.CharRange.min_c = min_c;
204
pat->content.CharRange.max_c = max_c;
198
if (isdigit((int)*pattern)) { /* numeric range detected */
206
else if (isdigit((int)*pattern)) { /* numeric range detected */
200
210
pat->type = UPTNumRange;
201
211
pat->content.NumRange.padlength = 0;
202
if (sscanf(pattern, "%d-%d]",
203
&pat->content.NumRange.min_n,
204
&pat->content.NumRange.max_n) != 2 ||
205
pat->content.NumRange.min_n >= pat->content.NumRange.max_n) {
213
rc = sscanf(pattern, "%d-%d%c%d%c", &min_n, &max_n, &sep, &step, &sep2);
215
if ((rc < 2) || (min_n >= max_n)) {
206
216
/* the pattern is not well-formed */
207
217
snprintf(glob->errormsg, sizeof(glob->errormsg),
208
"error: illegal pattern or range specification after pos %d\n",
218
"error: bad range specification after pos %d\n", pos);
210
219
return GLOB_ERROR;
221
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n = min_n;
222
pat->content.NumRange.max_n = max_n;
224
/* if there was a ":[num]" thing, use that as step or else use 1 */
225
pat->content.NumRange.step =
226
((sep == ':') && (rc == 5) && (sep2 == ']'))?step:1;
212
228
if (*pattern == '0') { /* leading zero specified */
214
230
while (isdigit((int)*c++))
215
231
++pat->content.NumRange.padlength; /* padding length is set for all
216
232
instances of this pattern */
218
pat->content.NumRange.ptr_n = pat->content.NumRange.min_n;
219
c = (char*)strchr(pattern, ']'); /* continue after next ']' */
223
snprintf(glob->errormsg, sizeof(glob->errormsg), "missing ']'");
224
return GLOB_ERROR; /* missing ']' */
227
/* always check for a literal (may be "") between patterns */
229
if(GLOB_ERROR == glob_word(glob, c, pos + (c - pattern), &wordamount))
237
snprintf(glob->errormsg, sizeof(glob->errormsg),
238
"illegal character in range specification at pos %d\n", pos);
242
c = (char*)strchr(pattern, ']'); /* continue after next ']' */
246
snprintf(glob->errormsg, sizeof(glob->errormsg), "missing ']'");
247
return GLOB_ERROR; /* missing ']' */
250
/* always check for a literal (may be "") between patterns */
252
if(GLOB_ERROR == glob_word(glob, c, pos + (c - pattern), &wordamount))
255
if(pat->type == UPTCharRange)
256
*amount = (pat->content.CharRange.max_c -
257
pat->content.CharRange.min_c + 1) *
232
260
*amount = (pat->content.NumRange.max_n -
233
pat->content.NumRange.min_n + 1) *
261
pat->content.NumRange.min_n + 1) * wordamount;
238
snprintf(glob->errormsg, sizeof(glob->errormsg),
239
"illegal character in range specification at pos %d\n", pos);
243
266
static GlobCode glob_word(URLGlob *glob, char *pattern,