home *** CD-ROM | disk | FTP | other *** search
- *** SCSI::SCSIDisc4.$.Programs.Utils.Regex.C.Regex Sun May 12 15:07:30 1991
- --- SCSI::SCSIDisc4.$.Programs.Utils.Regex.C.Regex1 Thu Sep 19 01:27:55 1991
- *************** enum regexpcod
- *** 149,154 ****
- --- 149,156 ----
- notspacechar, /* Matches any non-whitespace character */
- digit, /* Matches any digit character */
- notdigit, /* Matches any non-digit character */
- + begword, /* Succeeds if at beginning of word. */
- + endword, /* Succeeds if at end of word. */
- wordbound, /* Succeeds if at a word boundary */
- notwordbound /* Succeeds if not at a word boundary */
- };
- *************** enum regexpcod
- *** 167,173 ****
- /* Store NUMBER in two contiguous bytes starting at DESTINATION. */
- #define STORE_NUMBER(destination, number)\
- { (destination)[0] = (number) & 0377;\
- ! (destination)[1] = (number) >> 8; }
-
- /* Same as STORE_NUMBER, except increment the destination pointer to
- the byte after where the number is stored. Watch out that values for
- --- 169,175 ----
- /* Store NUMBER in two contiguous bytes starting at DESTINATION. */
- #define STORE_NUMBER(destination, number)\
- { (destination)[0] = (number) & 0377;\
- ! (destination)[1] = ((number) >> 8) & 0377; }
-
- /* Same as STORE_NUMBER, except increment the destination pointer to
- the byte after where the number is stored. Watch out that values for
- *************** int obscure_syntax = 0
- *** 221,226 ****
- --- 223,229 ----
- #define PATFETCH(c)\
- {if (p == pend) goto end_of_pattern;\
- c = * (unsigned char *) p++;\
- + fprintf(stderr,"%c",c);\
- if (translate) c = translate[c]; }
-
- /* Fetch the next character in the uncompiled pattern, with no
- *************** char *re_compile_pattern (char *pattern, int size
- *** 787,793 ****
- /* When hit this when matching, reset the
- preceding jump_n's n to upper_bound - 1. */
- BUFPUSH (set_number_at);
- ! GET_BUFFER_SPACE (2);
- STORE_NUMBER_AND_INCR (b, -5);
- STORE_NUMBER_AND_INCR (b, upper_bound - 1);
- }
- --- 790,796 ----
- /* When hit this when matching, reset the
- preceding jump_n's n to upper_bound - 1. */
- BUFPUSH (set_number_at);
- ! GET_BUFFER_SPACE (4);
- STORE_NUMBER_AND_INCR (b, -5);
- STORE_NUMBER_AND_INCR (b, upper_bound - 1);
- }
- *************** char *re_compile_pattern (char *pattern, int size
- *** 936,941 ****
- --- 939,952 ----
- BUFPUSH (notwordbound);
- break;
-
- + case '<':
- + BUFPUSH (begword);
- + break;
- +
- + case '>':
- + BUFPUSH (endword);
- + break;
- +
- case '`':
- BUFPUSH (begbuf);
- break;
- *************** static void insert_op_2 (char op, char *there, char *current
- *** 1136,1142 ****
- quickly over totally implausible text.
-
- The caller must supply the address of a CHAR_NUM-byte data
- ! area as bufp->fastmap.
- The other components of bufp describe the pattern to be used. */
-
- void re_compile_fastmap (struct re_pattern_buffer *bufp)
- --- 1147,1154 ----
- quickly over totally implausible text.
-
- The caller must supply the address of a CHAR_NUM-byte data
- ! area as bufp->fastmap, or NULL (in which case, re_compile_fastmap
- ! will allocate an area, using malloc()).
- The other components of bufp describe the pattern to be used. */
-
- void re_compile_fastmap (struct re_pattern_buffer *bufp)
- *************** void re_compile_fastmap (struct re_pattern_buffer *bufp
- *** 1154,1161 ****
-
- unsigned is_a_succeed_n;
-
- - bzero (fastmap, CHAR_NUM);
- bufp->fastmap_accurate = 1;
- bufp->can_be_null = 0;
-
- while (p)
- --- 1166,1187 ----
-
- unsigned is_a_succeed_n;
-
- bufp->fastmap_accurate = 1;
- +
- + if (fastmap == NULL)
- + {
- + fastmap = malloc(CHAR_NUM);
- +
- + /* If no luck, return without a fastmap (but with fastmap_accurate set,
- + so that callers know we tried). */
- +
- + if (fastmap == NULL)
- + return;
- +
- + bufp->fastmap = fastmap;
- + }
- +
- + bzero (fastmap, CHAR_NUM);
- bufp->can_be_null = 0;
-
- while (p)
- *************** void re_compile_fastmap (struct re_pattern_buffer *bufp
- *** 1179,1184 ****
- --- 1205,1212 ----
- case begline:
- case begbuf:
- case endbuf:
- + case begword:
- + case endword:
- case wordbound:
- case notwordbound:
- continue;
- *************** int re_search_2 (struct re_pattern_buffer *pbufp, char *stri
- *** 1383,1388 ****
- --- 1411,1421 ----
- if (startpos < 0 || startpos > total_size)
- return -1;
-
- + /* A range of zero means "as far as possible" (use re_match for an
- + anchored match). */
- + if (range == 0)
- + range = total_size - startpos;
- +
- /* Fix up range if it would eventually take startpos outside of the
- virtual concatenation of string1 and string2. */
- if (endpos < -1)
- *************** int re_search_2 (struct re_pattern_buffer *pbufp, char *stri
- *** 1391,1398 ****
- range = total_size - startpos;
-
- /* Update the fastmap now if not correct already. */
- ! if (fastmap && !pbufp->fastmap_accurate)
- ! re_compile_fastmap (pbufp);
-
- /* If the search isn't to be a backwards one, don't waste time in a
- long search for a pattern that says it is anchored. */
- --- 1424,1435 ----
- range = total_size - startpos;
-
- /* Update the fastmap now if not correct already. */
- ! if (!pbufp->fastmap_accurate)
- ! {
- ! re_compile_fastmap (pbufp);
- ! /* Re-assign fastmap, in case re_compile_fastmap() allocated it */
- ! fastmap = pbufp->fastmap;
- ! }
-
- /* If the search isn't to be a backwards one, don't waste time in a
- long search for a pattern that says it is anchored. */
- *************** struct register_inf
- *** 1640,1645 ****
- --- 1677,1688 ----
- #define IS_A_LETTER(d)\
- (HAS_SYNTAX (CURRENT_CHAR(d),Sword))
-
- + #define AT_WORD_BEG\
- + (AT_STRINGS_BEG || (!IS_A_LETTER (d - 1) && IS_A_LETTER (d)))
- +
- + #define AT_WORD_END\
- + (AT_STRINGS_END || (IS_A_LETTER (d - 1) && !IS_A_LETTER (d)))
- +
- #define AT_WORD_BOUNDARY\
- (AT_STRINGS_BEG || AT_STRINGS_END || IS_A_LETTER (d - 1) != IS_A_LETTER (d))
-
- *************** int re_match_2 (struct re_pattern_buffer *pbufp, char *strin
- *** 2265,2270 ****
- --- 2308,2323 ----
- d++;
- break;
-
- + case begword:
- + if (AT_WORD_BEG)
- + break;
- + goto fail;
- +
- + case endword:
- + if (AT_WORD_END)
- + break;
- + goto fail;
- +
- case begbuf:
- if (AT_STRINGS_BEG)
- break;
- *************** int main (void
- *** 2493,2499 ****
- {
- char pat[80];
- struct re_pattern_buffer buf;
- ! int i;
- char fastmap[CHAR_NUM];
-
- buf.allocated = 40;
- --- 2546,2554 ----
- {
- char pat[80];
- struct re_pattern_buffer buf;
- ! struct re_registers regs;
- ! int i, j;
- ! char *p;
- char fastmap[CHAR_NUM];
-
- buf.allocated = 40;
- *************** int main (void
- *** 2534,2541 ****
- if (*pat == 0)
- break;
-
- ! i = re_match (&buf, pat, strlen (pat), 0, 0);
- ! printf ("Match value %d.\n", i);
- }
- }
- }
- --- 2589,2598 ----
- if (*pat == 0)
- break;
-
- ! i = re_search (&buf, pat, strlen (pat), 0, 0, ®s);
- ! j = regs.end[0] - regs.start[0];
- ! p = pat + regs.start[0];
- ! printf ("Found \"%.*s\" at %d.\n", j, p, i);
- }
- }
- }
- *************** static void dump_buffer (struct re_pattern_buffer *bufp
- *** 2629,2634 ****
- --- 2686,2697 ----
- break;
- case duplicate:
- printf("Duplicate (%d)", *p++);
- + break;
- + case begword:
- + printf("Start of word");
- + break;
- + case endword:
- + printf("End of word");
- break;
- case begbuf:
- printf("Start of buffer");
-