Mercurial > hg > octave-jordi > gnulib-hg
comparison lib/regex.c @ 80:d689538c6d85
merge with 1.4.1
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Sat, 01 May 1993 19:59:12 +0000 |
parents | c2b3b494a819 |
children | 8bc040c4fa94 |
comparison
equal
deleted
inserted
replaced
79:a2b5af765702 | 80:d689538c6d85 |
---|---|
1 /* Extended regular expression matching and search library, | 1 /* Extended regular expression matching and search library, |
2 version 0.11. | 2 version 0.12. |
3 (Implements POSIX draft P10003.2/D11.2, except for | 3 (Implements POSIX draft P10003.2/D11.2, except for |
4 internationalization features.) | 4 internationalization features.) |
5 | 5 |
6 Copyright (C) 1993 Free Software Foundation, Inc. | 6 Copyright (C) 1993 Free Software Foundation, Inc. |
7 | 7 |
125 #include "regex.h" | 125 #include "regex.h" |
126 | 126 |
127 /* isalpha etc. are used for the character classes. */ | 127 /* isalpha etc. are used for the character classes. */ |
128 #include <ctype.h> | 128 #include <ctype.h> |
129 | 129 |
130 #if !defined (isascii) || defined (STDC_HEADERS) | 130 /* Jim Meyering writes: |
131 | |
132 "... Some ctype macros are valid only for character codes that | |
133 isascii says are ASCII (SGI's IRIX-4.0.5 is one such system --when | |
134 using /bin/cc or gcc but without giving an ansi option). So, all | |
135 ctype uses should be through macros like ISPRINT... If | |
136 STDC_HEADERS is defined, then autoconf has verified that the ctype | |
137 macros don't need to be guarded with references to isascii. ... | |
138 Defining isascii to 1 should let any compiler worth its salt | |
139 eliminate the && through constant folding." */ | |
140 #if ! defined (isascii) || defined (STDC_HEADERS) | |
131 #undef isascii | 141 #undef isascii |
132 #define isascii(c) 1 | 142 #define isascii(c) 1 |
133 #endif | 143 #endif |
134 | 144 |
135 #ifdef isblank | 145 #ifdef isblank |
1301 because laststart was nonzero. And we've already | 1311 because laststart was nonzero. And we've already |
1302 incremented `p', by the way, to be the character after | 1312 incremented `p', by the way, to be the character after |
1303 the `*'. Do we have to do something analogous here | 1313 the `*'. Do we have to do something analogous here |
1304 for null bytes, because of RE_DOT_NOT_NULL? */ | 1314 for null bytes, because of RE_DOT_NOT_NULL? */ |
1305 if (TRANSLATE (*(p - 2)) == TRANSLATE ('.') | 1315 if (TRANSLATE (*(p - 2)) == TRANSLATE ('.') |
1316 && zero_times_ok | |
1306 && p < pend && TRANSLATE (*p) == TRANSLATE ('\n') | 1317 && p < pend && TRANSLATE (*p) == TRANSLATE ('\n') |
1307 && !(syntax & RE_DOT_NEWLINE)) | 1318 && !(syntax & RE_DOT_NEWLINE)) |
1308 { /* We have .*\n. */ | 1319 { /* We have .*\n. */ |
1309 STORE_JUMP (jump, b, laststart); | 1320 STORE_JUMP (jump, b, laststart); |
1310 keep_string_p = true; | 1321 keep_string_p = true; |
1611 compile_stack.avail++; | 1622 compile_stack.avail++; |
1612 | 1623 |
1613 fixup_alt_jump = 0; | 1624 fixup_alt_jump = 0; |
1614 laststart = 0; | 1625 laststart = 0; |
1615 begalt = b; | 1626 begalt = b; |
1627 /* If we've reached MAX_REGNUM groups, then this open | |
1628 won't actually generate any code, so we'll have to | |
1629 clear pending_exact explicitly. */ | |
1630 pending_exact = 0; | |
1616 break; | 1631 break; |
1617 | 1632 |
1618 | 1633 |
1619 case ')': | 1634 case ')': |
1620 if (syntax & RE_NO_BK_PARENS) goto normal_backslash; | 1635 if (syntax & RE_NO_BK_PARENS) goto normal_backslash; |
1660 = COMPILE_STACK_TOP.fixup_alt_jump | 1675 = COMPILE_STACK_TOP.fixup_alt_jump |
1661 ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 | 1676 ? bufp->buffer + COMPILE_STACK_TOP.fixup_alt_jump - 1 |
1662 : 0; | 1677 : 0; |
1663 laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; | 1678 laststart = bufp->buffer + COMPILE_STACK_TOP.laststart_offset; |
1664 this_group_regnum = COMPILE_STACK_TOP.regnum; | 1679 this_group_regnum = COMPILE_STACK_TOP.regnum; |
1680 /* If we've reached MAX_REGNUM groups, then this open | |
1681 won't actually generate any code, so we'll have to | |
1682 clear pending_exact explicitly. */ | |
1683 pending_exact = 0; | |
1665 | 1684 |
1666 /* We're at the end of the group, so now we know how many | 1685 /* We're at the end of the group, so now we know how many |
1667 groups were inside this one. */ | 1686 groups were inside this one. */ |
1668 if (this_group_regnum <= MAX_REGNUM) | 1687 if (this_group_regnum <= MAX_REGNUM) |
1669 { | 1688 { |
2929 | 2948 |
2930 /* Written out as an if-else to avoid testing `translate' | 2949 /* Written out as an if-else to avoid testing `translate' |
2931 inside the loop. */ | 2950 inside the loop. */ |
2932 if (translate) | 2951 if (translate) |
2933 while (range > lim | 2952 while (range > lim |
2934 && !fastmap[(unsigned char) translate[*d++]]) | 2953 && !fastmap[(unsigned char) |
2954 translate[(unsigned char) *d++]]) | |
2935 range--; | 2955 range--; |
2936 else | 2956 else |
2937 while (range > lim && !fastmap[(unsigned char) *d++]) | 2957 while (range > lim && !fastmap[(unsigned char) *d++]) |
2938 range--; | 2958 range--; |
2939 | 2959 |
3452 if (regs->start == NULL || regs->end == NULL) | 3472 if (regs->start == NULL || regs->end == NULL) |
3453 return -2; | 3473 return -2; |
3454 } | 3474 } |
3455 } | 3475 } |
3456 else | 3476 else |
3457 assert (bufp->regs_allocated == REGS_FIXED); | 3477 { |
3478 /* These braces fend off a "empty body in an else-statement" | |
3479 warning under GCC when assert expands to nothing. */ | |
3480 assert (bufp->regs_allocated == REGS_FIXED); | |
3481 } | |
3458 | 3482 |
3459 /* Convert the pointer data in `regstart' and `regend' to | 3483 /* Convert the pointer data in `regstart' and `regend' to |
3460 indices. Register zero has to be set differently, | 3484 indices. Register zero has to be set differently, |
3461 since we haven't kept track of any info for it. */ | 3485 since we haven't kept track of any info for it. */ |
3462 if (regs->num_regs > 0) | 3486 if (regs->num_regs > 0) |
4879 to this routine. If we are given anything else, or if other regex | 4903 to this routine. If we are given anything else, or if other regex |
4880 code generates an invalid error code, then the program has a bug. | 4904 code generates an invalid error code, then the program has a bug. |
4881 Dump core so we can fix it. */ | 4905 Dump core so we can fix it. */ |
4882 abort (); | 4906 abort (); |
4883 | 4907 |
4908 msg = re_error_msg[errcode]; | |
4909 | |
4910 /* POSIX doesn't require that we do anything in this case, but why | |
4911 not be nice. */ | |
4912 if (! msg) | |
4913 msg = "Success"; | |
4914 | |
4884 msg_size = strlen (msg) + 1; /* Includes the null. */ | 4915 msg_size = strlen (msg) + 1; /* Includes the null. */ |
4885 | 4916 |
4886 if (errbuf_size != 0) | 4917 if (errbuf_size != 0) |
4887 { | 4918 { |
4888 if (msg_size > errbuf_size) | 4919 if (msg_size > errbuf_size) |