1/**************************************************************** 2Copyright (C) Lucent Technologies 1997 3All Rights Reserved 4 5Permission to use, copy, modify, and distribute this software and 6its documentation for any purpose and without fee is hereby 7granted, provided that the above copyright notice appear in all 8copies and that both that the copyright notice and this --- 268 unchanged lines hidden (view full) --- 277 } 278 c = n; 279 } /* else */ 280 /* c = c; */ 281 *pp = p; 282 return c; 283} 284 |
285static int collate_range_cmp(int a, int b) 286{ 287 int r; 288 static char s[2][2]; 289 290 if ((uschar)a == (uschar)b) 291 return 0; 292 s[0][0] = a; 293 s[1][0] = b; 294 if ((r = strcoll(s[0], s[1])) == 0) 295 r = (uschar)a - (uschar)b; 296 return r; 297} 298 |
299char *cclenter(const char *argp) /* add a character class */ 300{ 301 int i, c, c2; |
302 int j; |
303 uschar *p = (uschar *) argp; 304 uschar *op, *bp; 305 static uschar *buf = 0; 306 static int bufsz = 100; 307 308 op = p; 309 if (buf == 0 && (buf = (uschar *) malloc(bufsz)) == NULL) 310 FATAL("out of space for character class [%.10s...] 1", p); 311 bp = buf; 312 for (i = 0; (c = *p++) != 0; ) { 313 if (c == '\\') { 314 c = quoted((char **) &p); 315 } else if (c == '-' && i > 0 && bp[-1] != 0) { 316 if (*p != 0) { 317 c = bp[-1]; 318 c2 = *p++; 319 if (c2 == '\\') 320 c2 = quoted((char **) &p); |
321 if (collate_range_cmp(c, c2) > 0) { /* empty; ignore */ |
322 bp--; 323 i--; 324 continue; 325 } |
326 for (j = 0; j < NCHARS; j++) { 327 if ((collate_range_cmp(c, j) > 0) || 328 collate_range_cmp(j, c2) > 0) 329 continue; |
330 if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, 0)) 331 FATAL("out of space for character class [%.10s...] 2", p); |
332 *bp++ = j; |
333 i++; 334 } 335 continue; 336 } 337 } 338 if (!adjbuf((char **) &buf, &bufsz, bp-buf+2, 100, (char **) &bp, 0)) 339 FATAL("out of space for character class [%.10s...] 3", p); 340 *bp++ = c; --- 367 unchanged lines hidden (view full) --- 708 * defined in IEEE P1003.1 draft 7 of June 2001, assuming the source 709 * and operating character sets are both ASCII (ISO646) or supersets 710 * thereof. 711 * 712 * Note that to avoid overflowing the temporary buffer used in 713 * relex(), the expanded character class (prior to range expansion) 714 * must be less than twice the size of their full name. 715 */ |
716 717/* Because isblank doesn't show up in any of the header files on any 718 * system i use, it's defined here. if some other locale has a richer 719 * definition of "blank", define HAS_ISBLANK and provide your own 720 * version. 721 */ 722 723#ifndef HAS_ISBLANK 724 725int isblank(int c) 726{ 727 return c==' ' || c=='\t'; 728} 729 730#endif 731 |
732struct charclass { 733 const char *cc_name; 734 int cc_namelen; |
735 int (*cc_func)(int); |
736} charclasses[] = { |
737 { "alnum", 5, isalnum }, 738 { "alpha", 5, isalpha }, 739 { "blank", 5, isblank }, 740 { "cntrl", 5, iscntrl }, 741 { "digit", 5, isdigit }, 742 { "graph", 5, isgraph }, 743 { "lower", 5, islower }, 744 { "print", 5, isprint }, 745 { "punct", 5, ispunct }, 746 { "space", 5, isspace }, 747 { "upper", 5, isupper }, 748 { "xdigit", 6, isxdigit }, |
749 { NULL, 0, NULL }, 750}; 751 752 753int relex(void) /* lexical analyzer for reparse */ 754{ 755 int c, n; 756 int cflag; 757 static uschar *buf = 0; 758 static int bufsz = 100; 759 uschar *bp; 760 struct charclass *cc; |
761 int i; |
762 763 switch (c = *prestr++) { 764 case '|': return OR; 765 case '*': return STAR; 766 case '+': return PLUS; 767 case '?': return QUEST; 768 case '.': return DOT; 769 case '\0': prestr--; return '\0'; --- 32 unchanged lines hidden (view full) --- 802 } else if (c == '[' && *prestr == ':') { 803 /* POSIX char class names, Dag-Erling Smorgrav, des@ofug.org */ 804 for (cc = charclasses; cc->cc_name; cc++) 805 if (strncmp((const char *) prestr + 1, (const char *) cc->cc_name, cc->cc_namelen) == 0) 806 break; 807 if (cc->cc_name != NULL && prestr[1 + cc->cc_namelen] == ':' && 808 prestr[2 + cc->cc_namelen] == ']') { 809 prestr += cc->cc_namelen + 3; |
810 for (i = 0; i < NCHARS; i++) { 811 if (!adjbuf((char **) &buf, &bufsz, bp-buf+1, 100, (char **) &bp, 0)) 812 FATAL("out of space for reg expr %.10s...", lastre); 813 if (cc->cc_func(i)) { 814 *bp++ = i; 815 n++; 816 } 817 } |
818 } else 819 *bp++ = c; 820 } else if (c == '\0') { 821 FATAL("nonterminated character class %.20s", lastre); 822 } else if (bp == buf) { /* 1st char is special */ 823 *bp++ = c; 824 } else if (c == ']') { 825 *bp++ = 0; --- 117 unchanged lines hidden --- |