/[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.25 by kasal, Fri Nov 19 16:38:52 2004 UTC revision 1.26 by kasal, Fri Nov 19 16:48:15 2004 UTC
# Line 407  static wchar_t *inputwcs;      /* Wide charac Line 407  static wchar_t *inputwcs;      /* Wide charac
407                                     And inputwcs[i] is the codepoint.  */                                     And inputwcs[i] is the codepoint.  */
408  static unsigned char const *buf_begin;  /* reference to begin in dfaexec().  */  static unsigned char const *buf_begin;  /* reference to begin in dfaexec().  */
409  static unsigned char const *buf_end;    /* reference to end in dfaexec().  */  static unsigned char const *buf_end;    /* reference to end in dfaexec().  */
 static unsigned long buf_offset; /* Go fast. */  
410  #endif /* MBS_SUPPORT  */  #endif /* MBS_SUPPORT  */
411    
412  #ifdef MBS_SUPPORT  #ifdef MBS_SUPPORT
# Line 2374  build_state_zero (struct dfa *d) Line 2373  build_state_zero (struct dfa *d)
2373  #define SKIP_REMAINS_MB_IF_INITIAL_STATE(s, p)          \  #define SKIP_REMAINS_MB_IF_INITIAL_STATE(s, p)          \
2374    if (s == 0)                                           \    if (s == 0)                                           \
2375      {                                                   \      {                                                   \
2376        while (inputwcs[p - buf_begin + buf_offset] == 0  \        while (inputwcs[p - buf_begin] == 0               \
2377              && mblen_buf[p - buf_begin + buf_offset] > 0\              && mblen_buf[p - buf_begin] > 0             \
2378              && p < buf_end)                             \              && p < buf_end)                             \
2379          ++p;                                            \          ++p;                                            \
2380        if (p >= end)                                     \        if (p >= end)                                     \
2381          {                                               \          {                                               \
2382              free(mblen_buf);                              \
2383              free(inputwcs);                               \
2384            return (size_t) -1;                           \            return (size_t) -1;                           \
2385          }                                               \          }                                               \
2386      }      }
# Line 2472  match_anychar (struct dfa *d, int s, pos Line 2473  match_anychar (struct dfa *d, int s, pos
2473    wchar_t wc;    wchar_t wc;
2474    int mbclen;    int mbclen;
2475    
2476    wc = inputwcs[index + buf_offset];    wc = inputwcs[index];
2477    mbclen = (mblen_buf[index + buf_offset] == 0)? 1 : mblen_buf[index + buf_offset];    mbclen = (mblen_buf[index] == 0)? 1 : mblen_buf[index];
2478    
2479    /* Check context.  */    /* Check context.  */
2480    if (wc == (wchar_t)eolbyte)    if (wc == (wchar_t)eolbyte)
# Line 2522  match_mb_charset (struct dfa *d, int s, Line 2523  match_mb_charset (struct dfa *d, int s,
2523    int letter = 0;    int letter = 0;
2524    wchar_t wc;           /* Current refering character.  */    wchar_t wc;           /* Current refering character.  */
2525    
2526    wc = inputwcs[index + buf_offset];    wc = inputwcs[index];
2527    
2528    /* Check context.  */    /* Check context.  */
2529    if (wc == (wchar_t)eolbyte)    if (wc == (wchar_t)eolbyte)
# Line 2546  match_mb_charset (struct dfa *d, int s, Line 2547  match_mb_charset (struct dfa *d, int s,
2547    /* Assign the current refering operator to work_mbc.  */    /* Assign the current refering operator to work_mbc.  */
2548    work_mbc = &(d->mbcsets[(d->multibyte_prop[pos.index]) >> 2]);    work_mbc = &(d->mbcsets[(d->multibyte_prop[pos.index]) >> 2]);
2549    match = !work_mbc->invert;    match = !work_mbc->invert;
2550    match_len = (mblen_buf[index + buf_offset] == 0)? 1 : mblen_buf[index + buf_offset];    match_len = (mblen_buf[index] == 0)? 1 : mblen_buf[index];
2551    
2552    /* match with a character class?  */    /* match with a character class?  */
2553    for (i = 0; i<work_mbc->nch_classes; i++)    for (i = 0; i<work_mbc->nch_classes; i++)
# Line 2661  transit_state_consume_1char (struct dfa Line 2662  transit_state_consume_1char (struct dfa
2662    
2663    /* Calculate the length of the (single/multi byte) character    /* Calculate the length of the (single/multi byte) character
2664       to which p points.  */       to which p points.  */
2665    *mbclen = (mblen_buf[*pp - buf_begin + buf_offset] == 0)? 1    *mbclen = (mblen_buf[*pp - buf_begin] == 0)? 1
2666      : mblen_buf[*pp - buf_begin + buf_offset];      : mblen_buf[*pp - buf_begin];
2667    
2668    /* Calculate the state which can be reached from the state `s' by    /* Calculate the state which can be reached from the state `s' by
2669       consuming `*mbclen' single bytes from the buffer.  */       consuming `*mbclen' single bytes from the buffer.  */
# Line 2756  transit_state (struct dfa *d, int s, uns Line 2757  transit_state (struct dfa *d, int s, uns
2757       `maxlen' bytes.  */       `maxlen' bytes.  */
2758    rs = transit_state_consume_1char(d, s, pp, match_lens, &mbclen, &follows);    rs = transit_state_consume_1char(d, s, pp, match_lens, &mbclen, &follows);
2759    
2760    wc = inputwcs[*pp - mbclen - buf_begin + buf_offset];    wc = inputwcs[*pp - mbclen - buf_begin];
2761    s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));    s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));
2762    realloc_trans_if_necessary(d, s1);    realloc_trans_if_necessary(d, s1);
2763    
# Line 2774  transit_state (struct dfa *d, int s, uns Line 2775  transit_state (struct dfa *d, int s, uns
2775                       &follows);                       &follows);
2776          }          }
2777    
2778        wc = inputwcs[*pp - mbclen - buf_begin + buf_offset];        wc = inputwcs[*pp - mbclen - buf_begin];
2779        s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));        s1 = state_index(d, &follows, wc == L'\n', iswalnum(wc));
2780        realloc_trans_if_necessary(d, s1);        realloc_trans_if_necessary(d, s1);
2781      }      }
# Line 2828  dfaexec (struct dfa *d, char const *begi Line 2829  dfaexec (struct dfa *d, char const *begi
2829    if (MB_CUR_MAX > 1)    if (MB_CUR_MAX > 1)
2830      {      {
2831        int remain_bytes, i;        int remain_bytes, i;
       buf_begin -= buf_offset;  
       if (buf_begin <= (unsigned char const *)begin && end <= buf_end) {  
         buf_offset = (unsigned char const *)begin - buf_begin;  
         buf_begin = begin;  
         buf_end = end;  
         goto go_fast;  
       }  
   
       buf_offset = 0;  
2832        buf_begin = begin;        buf_begin = begin;
2833        buf_end = end;        buf_end = end;
2834    
2835        /* initialize mblen_buf, and inputwcs.  */        /* initialize mblen_buf, and inputwcs.  */
2836        REALLOC(mblen_buf, unsigned char, end - (unsigned char const *)begin + 2);        MALLOC(mblen_buf, unsigned char, end - (unsigned char const *)begin + 2);
2837        REALLOC(inputwcs, wchar_t, end - (unsigned char const *)begin + 2);        MALLOC(inputwcs, wchar_t, end - (unsigned char const *)begin + 2);
2838        memset(&mbs, 0, sizeof(mbstate_t));        memset(&mbs, 0, sizeof(mbstate_t));
2839        remain_bytes = 0;        remain_bytes = 0;
2840        for (i = 0; i < end - (unsigned char const *)begin + 1; i++)        for (i = 0; i < end - (unsigned char const *)begin + 1; i++)
# Line 2874  dfaexec (struct dfa *d, char const *begi Line 2866  dfaexec (struct dfa *d, char const *begi
2866        mblen_buf[i] = 0;        mblen_buf[i] = 0;
2867        inputwcs[i] = 0; /* sentinel */        inputwcs[i] = 0; /* sentinel */
2868      }      }
 go_fast:  
2869  #endif /* MBS_SUPPORT */  #endif /* MBS_SUPPORT */
2870    
2871    for (;;)    for (;;)
# Line 2913  go_fast: Line 2904  go_fast:
2904          {          {
2905            if (p == end)            if (p == end)
2906              {              {
2907    #ifdef MBS_SUPPORT
2908                  if (MB_CUR_MAX > 1)
2909                    {
2910                      free(mblen_buf);
2911                      free(inputwcs);
2912                    }
2913    #endif /* MBS_SUPPORT */
2914                return (size_t) -1;                return (size_t) -1;
2915              }              }
2916            s = 0;            s = 0;
# Line 2923  go_fast: Line 2921  go_fast:
2921              {              {
2922                if (backref)                if (backref)
2923                  *backref = (d->states[s].backref != 0);                  *backref = (d->states[s].backref != 0);
2924    #ifdef MBS_SUPPORT
2925                  if (MB_CUR_MAX > 1)
2926                    {
2927                      free(mblen_buf);
2928                      free(inputwcs);
2929                    }
2930    #endif /* MBS_SUPPORT */
2931                return (char const *) p - begin;                return (char const *) p - begin;
2932              }              }
2933    

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.26

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