/[grep]/grep/src/dfa.c
ViewVC logotype

Diff of /grep/src/dfa.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.30 by kasal, Thu Dec 16 07:18:15 2004 UTC revision 1.31 by kasal, Thu Dec 16 08:19:29 2004 UTC
# Line 365  setbit_case_fold (unsigned b, charclass Line 365  setbit_case_fold (unsigned b, charclass
365     reader is referred to the GNU Regex documentation for the     reader is referred to the GNU Regex documentation for the
366     meaning of the @#%!@#%^!@ syntax bits. */     meaning of the @#%!@#%^!@ syntax bits. */
367    
 static char const *lexstart;    /* Pointer to beginning of input string. */  
368  static char const *lexptr;      /* Pointer to next input character. */  static char const *lexptr;      /* Pointer to next input character. */
369  static int lexleft;             /* Number of characters remaining. */  static int lexleft;             /* Number of characters remaining. */
370  static token lasttok;           /* Previous token returned; initially END. */  static token lasttok;           /* Previous token returned; initially END. */
# Line 383  static int cur_mb_len;         /* Byte length o Line 382  static int cur_mb_len;         /* Byte length o
382  static int cur_mb_index;        /* Byte index of the current scanning multibyte  static int cur_mb_index;        /* Byte index of the current scanning multibyte
383                                     character.                                     character.
384    
385                                     singlebyte character : cur_mb_index = 0                                     single byte character : cur_mb_index = 0
386                                     multibyte character                                     multibyte character
387                                         1st byte : cur_mb_index = 1                                         1st byte : cur_mb_index = 1
388                                         2nd byte : cur_mb_index = 2                                         2nd byte : cur_mb_index = 2
# Line 394  static unsigned char *mblen_buf;/* Corre Line 393  static unsigned char *mblen_buf;/* Corre
393                                     byte of corresponding multibyte character                                     byte of corresponding multibyte character
394                                     in the input string.  A element's value                                     in the input string.  A element's value
395                                     is 0 if corresponding character is a                                     is 0 if corresponding character is a
396                                     singlebyte chracter.                                     single byte chracter.
397                                     e.g. input : 'a', <mb(0)>, <mb(1)>, <mb(2)>                                     e.g. input : 'a', <mb(0)>, <mb(1)>, <mb(2)>
398                                      mblen_buf :   0,       3,       2,       1                                      mblen_buf :   0,       3,       2,       1
399                                  */                                  */
# Line 432  update_mb_len_index (unsigned char const Line 431  update_mb_len_index (unsigned char const
431             cur_mb_len was already set by mbrlen().  */             cur_mb_len was already set by mbrlen().  */
432          cur_mb_index = 1;          cur_mb_index = 1;
433        else if (cur_mb_len < 1)        else if (cur_mb_len < 1)
434          /* Invalid sequence.  We treat it as a singlebyte character.          /* Invalid sequence.  We treat it as a single byte character.
435             cur_mb_index is aleady 0.  */             cur_mb_index is aleady 0.  */
436          cur_mb_len = 1;          cur_mb_len = 1;
437        /* Otherwise, cur_mb_len == 1, it is a singlebyte character.        /* Otherwise, cur_mb_len == 1, it is a single byte character.
438           cur_mb_index is aleady 0.  */           cur_mb_index is aleady 0.  */
439      }      }
440  }  }
# Line 528  parse_bracket_exp_mb () Line 527  parse_bracket_exp_mb ()
527    
528    work_mbc->nchars = work_mbc->nranges = work_mbc->nch_classes = 0;    work_mbc->nchars = work_mbc->nranges = work_mbc->nch_classes = 0;
529    work_mbc->nequivs = work_mbc->ncoll_elems = 0;    work_mbc->nequivs = work_mbc->ncoll_elems = 0;
530    work_mbc->chars = work_mbc->ch_classes = NULL;    work_mbc->chars = NULL;
531      work_mbc->ch_classes = NULL;
532    work_mbc->range_sts = work_mbc->range_ends = NULL;    work_mbc->range_sts = work_mbc->range_ends = NULL;
533    work_mbc->equivs = work_mbc->coll_elems = NULL;    work_mbc->equivs = work_mbc->coll_elems = NULL;
534    
# Line 1098  lex (void) Line 1098  lex (void)
1098                            setbit_case_fold (c, ccl);                            setbit_case_fold (c, ccl);
1099                        } else {                        } else {
1100                          /* POSIX locales are painful - leave the decision to libc */                          /* POSIX locales are painful - leave the decision to libc */
                         char expr[6] = { '[', 0 /* c */, '-', 0 /* c2 */, ']', '\0' };  
1101                          regex_t re;                          regex_t re;
1102                          expr[1] = c;                          char expr[6]; /* = { '[', c, '-', c2, ']', '\0' }; */
1103                          expr[3] = c2;  
1104                            expr[0] = '['; expr[1] = c; expr[2] = '-';
1105                            expr[3] = c2; expr[4] = ']'; expr[5] = '\0';
1106                          if (regcomp (&re, expr, case_fold ? REG_ICASE : 0) == REG_NOERROR) {                          if (regcomp (&re, expr, case_fold ? REG_ICASE : 0) == REG_NOERROR) {
1107                            for (c = 0; c < NOTCHAR; ++c) {                            for (c = 0; c < NOTCHAR; ++c) {
                             char buf[2] = { 0 /* c */, '\0' };  
1108                              regmatch_t mat;                              regmatch_t mat;
1109                              buf[0] = c;                              char buf[2]; /* = { c, '\0' }; */
1110    
1111                                buf[0] = c; buf[1] = '\0';
1112                              if (regexec (&re, buf, 1, &mat, 0) == REG_NOERROR                              if (regexec (&re, buf, 1, &mat, 0) == REG_NOERROR
1113                                 && mat.rm_so == 0 && mat.rm_eo == 1)                                 && mat.rm_so == 0 && mat.rm_eo == 1)
1114                                setbit_case_fold (c, ccl);                                setbit_case_fold (c, ccl);
# Line 1179  addtok (token t) Line 1181  addtok (token t)
1181            : (((cur_mb_index == 1)? 1 : 0) /* 1st-byte of multibyte char */            : (((cur_mb_index == 1)? 1 : 0) /* 1st-byte of multibyte char */
1182               + ((cur_mb_index == cur_mb_len)? 2 : 0)); /* last-byte */               + ((cur_mb_index == cur_mb_len)? 2 : 0)); /* last-byte */
1183        else        else
1184          /* It may be unnecesssary, but it is safer to treat other          /* It may be unnecessary, but it is safer to treat other
1185             symbols as singlebyte characters.  */             symbols as single byte characters.  */
1186          dfa->multibyte_prop[dfa->tindex] = 3;          dfa->multibyte_prop[dfa->tindex] = 3;
1187      }      }
1188  #endif  #endif
# Line 1406  void Line 1408  void
1408  dfaparse (char const *s, size_t len, struct dfa *d)  dfaparse (char const *s, size_t len, struct dfa *d)
1409  {  {
1410    dfa = d;    dfa = d;
1411    lexstart = lexptr = s;    lexptr = s;
1412    lexleft = len;    lexleft = len;
1413    lasttok = END;    lasttok = END;
1414    laststart = 1;    laststart = 1;
# Line 2000  dfastate (int s, struct dfa *d, int tran Line 2002  dfastate (int s, struct dfa *d, int tran
2002    int state_letter;             /* New state on a letter transition. */    int state_letter;             /* New state on a letter transition. */
2003    static int initialized;       /* Flag for static initialization. */    static int initialized;       /* Flag for static initialization. */
2004  #ifdef MBS_SUPPORT  #ifdef MBS_SUPPORT
2005    int next_isnt_1st_byte = 0;   /* Flag If we can't add state0.  */    int next_isnt_1st_byte = 0;   /* Flag if we can't add state0.  */
2006  #endif  #endif
2007    int i, j, k;    int i, j, k;
2008    
# Line 2183  dfastate (int s, struct dfa *d, int tran Line 2185  dfastate (int s, struct dfa *d, int tran
2185               character, or the states of follows must accept the bytes               character, or the states of follows must accept the bytes
2186               which are not 1st byte of the multibyte character.               which are not 1st byte of the multibyte character.
2187               Then, if a state of follows encounter a byte, it must not be               Then, if a state of follows encounter a byte, it must not be
2188               a 1st byte of a multibyte character nor singlebyte character.               a 1st byte of a multibyte character nor single byte character.
2189               We cansel to add state[0].follows to next state, because               We cansel to add state[0].follows to next state, because
2190               state[0] must accept 1st-byte               state[0] must accept 1st-byte
2191    
2192               For example, we assume <sb a> is a certain singlebyte               For example, we assume <sb a> is a certain single byte
2193               character, <mb A> is a certain multibyte character, and the               character, <mb A> is a certain multibyte character, and the
2194               codepoint of <sb a> equals the 2nd byte of the codepoint of               codepoint of <sb a> equals the 2nd byte of the codepoint of
2195               <mb A>.               <mb A>.
# Line 2363  build_state_zero (struct dfa *d) Line 2365  build_state_zero (struct dfa *d)
2365  #ifdef MBS_SUPPORT  #ifdef MBS_SUPPORT
2366  /* Multibyte character handling sub-routines for dfaexec.  */  /* Multibyte character handling sub-routines for dfaexec.  */
2367    
2368  /* Initial state may encounter the byte which is not a singlebyte character  /* Initial state may encounter the byte which is not a single byte character
2369     nor 1st byte of a multibyte character.  But it is incorrect for initial     nor 1st byte of a multibyte character.  But it is incorrect for initial
2370     state to accept such a byte.     state to accept such a byte.
2371     For example, in sjis encoding the regular expression like "\\" accepts     For example, in sjis encoding the regular expression like "\\" accepts
2372     the codepoint 0x5c, but should not accept the 2nd byte of the codepoint     the codepoint 0x5c, but should not accept the 2nd byte of the codepoint
2373     0x815c. Then Initial state must skip the bytes which are not a singlebyte     0x815c. Then Initial state must skip the bytes which are not a single byte
2374     character nor 1st byte of a multibyte character.  */     character nor 1st byte of a multibyte character.  */
2375  #define SKIP_REMAINS_MB_IF_INITIAL_STATE(s, p)          \  #define SKIP_REMAINS_MB_IF_INITIAL_STATE(s, p)          \
2376    if (s == 0)                                           \    if (s == 0)                                           \
# Line 2733  transit_state (struct dfa *d, int s, uns Line 2735  transit_state (struct dfa *d, int s, uns
2735    
2736    if (nelem == 0 || maxlen == 0)    if (nelem == 0 || maxlen == 0)
2737      /* This state has no multibyte operator which can match.      /* This state has no multibyte operator which can match.
2738         We need to check only one singlebyte character.  */         We need to check only one single byte character.  */
2739      {      {
2740        status_transit_state rs;        status_transit_state rs;
2741        rs = transit_state_singlebyte(d, s, *pp, &s1);        rs = transit_state_singlebyte(d, s, *pp, &s1);

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.31

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26