/[emacs]/emacs/src/regex.c
ViewVC logotype

Diff of /emacs/src/regex.c

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

revision 1.176 by rms, Mon Mar 25 00:45:48 2002 UTC revision 1.177 by monnier, Fri Aug 23 22:19:56 2002 UTC
# Line 19  Line 19 
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20     USA.  */     USA.  */
21    
22  /* TODO:  /* BUGS:
23       - (x?)*y\1z should match both xxxxyxz and xxxyz.
24       TODO:
25     - structure the opcode space into opcode+flag.     - structure the opcode space into opcode+flag.
26     - merge with glibc's regex.[ch].     - merge with glibc's regex.[ch].
27     - replace (succeed_n + jump_n + set_number_at) with something that doesn't     - replace (succeed_n + jump_n + set_number_at) with something that doesn't
# Line 1682  static re_char *skip_one_char _RE_ARGS ( Line 1684  static re_char *skip_one_char _RE_ARGS (
1684  static int analyse_first _RE_ARGS ((re_char *p, re_char *pend,  static int analyse_first _RE_ARGS ((re_char *p, re_char *pend,
1685                                      char *fastmap, const int multibyte));                                      char *fastmap, const int multibyte));
1686    
 /* Fetch the next character in the uncompiled pattern---translating it  
    if necessary.  */  
 #define PATFETCH(c)                                                     \  
   do {                                                                  \  
     PATFETCH_RAW (c);                                                   \  
     c = TRANSLATE (c);                                                  \  
   } while (0)  
   
1687  /* Fetch the next character in the uncompiled pattern, with no  /* Fetch the next character in the uncompiled pattern, with no
1688     translation.  */     translation.  */
1689  #define PATFETCH_RAW(c)                                                 \  #define PATFETCH(c)                                                     \
1690    do {                                                                  \    do {                                                                  \
1691      int len;                                                            \      int len;                                                            \
1692      if (p == pend) return REG_EEND;                                     \      if (p == pend) return REG_EEND;                                     \
# Line 1914  struct range_table_work_area Line 1908  struct range_table_work_area
1908  #define BIT_UPPER       0x10  #define BIT_UPPER       0x10
1909  #define BIT_MULTIBYTE   0x20  #define BIT_MULTIBYTE   0x20
1910    
1911  /* Set a range (RANGE_START, RANGE_END) to WORK_AREA.  */  /* Set a range START..END to WORK_AREA.
1912  #define SET_RANGE_TABLE_WORK_AREA(work_area, range_start, range_end)    \     The range is passed through TRANSLATE, so START and END
1913    do {                                                                  \     should be untranslated.  */
1914      EXTEND_RANGE_TABLE_WORK_AREA ((work_area), 2);                      \  #define SET_RANGE_TABLE_WORK_AREA(work_area, start, end)        \
1915      (work_area).table[(work_area).used++] = (range_start);              \    do {                                                          \
1916      (work_area).table[(work_area).used++] = (range_end);                \      EXTEND_RANGE_TABLE_WORK_AREA ((work_area), 2);              \
1917        set_image_of_range (&work_area, start, end, translate);     \
1918    } while (0)    } while (0)
1919    
1920  /* Free allocated memory for WORK_AREA.  */  /* Free allocated memory for WORK_AREA.  */
# Line 2077  re_wctype_to_bit (cc) Line 2072  re_wctype_to_bit (cc)
2072  }  }
2073  #endif  #endif
2074    
2075    
2076    
2077    /* We need to find the image of the range start..end when passed through
2078       TRANSLATE.  This is not necessarily TRANSLATE(start)..TRANSLATE(end)
2079       and is not even necessarily contiguous.
2080       We approximate it with the smallest contiguous range that contains
2081       all the chars we need.  */
2082    static void
2083    set_image_of_range (work_area, start, end, translate)
2084         RE_TRANSLATE_TYPE translate;
2085         struct range_table_work_area *work_area;
2086         re_wchar_t start, end;
2087    {
2088      re_wchar_t cmin = TRANSLATE (start), cmax = TRANSLATE (end);
2089      if (RE_TRANSLATE_P (translate))
2090        for (; start <= end; start++)
2091          {
2092            re_wchar_t c = TRANSLATE (start);
2093            cmin = MIN (cmin, c);
2094            cmax = MAX (cmax, c);
2095          }
2096      work_area->table[work_area->used++] = (cmin);
2097      work_area->table[work_area->used++] = (cmax);
2098    }
2099    
2100  /* Explicit quit checking is only used on NTemacs.  */  /* Explicit quit checking is only used on NTemacs.  */
2101  #if defined WINDOWSNT && defined emacs && defined QUIT  #if defined WINDOWSNT && defined emacs && defined QUIT
2102  extern int immediate_quit;  extern int immediate_quit;
# Line 2525  regex_compile (pattern, size, syntax, bu Line 2545  regex_compile (pattern, size, syntax, bu
2545    
2546                  if (p == pend) FREE_STACK_RETURN (REG_EBRACK);                  if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
2547    
2548                    /* Don't translate yet.  The range TRANSLATE(X..Y) cannot
2549                       always be determined from TRANSLATE(X) and TRANSLATE(Y)
2550                       So the translation is done later in a loop.  Example:
2551                       (let ((case-fold-search t)) (string-match "[A-_]" "A"))  */
2552                  PATFETCH (c);                  PATFETCH (c);
2553    
2554                  /* \ might escape characters inside [...] and [^...].  */                  /* \ might escape characters inside [...] and [^...].  */
# Line 2584  regex_compile (pattern, size, syntax, bu Line 2608  regex_compile (pattern, size, syntax, bu
2608                         them).  */                         them).  */
2609                      if (c == ':' && *p == ']')                      if (c == ':' && *p == ']')
2610                        {                        {
2611                          int ch;                          re_wchar_t ch;
2612                          re_wctype_t cc;                          re_wctype_t cc;
2613    
2614                          cc = re_wctype (str);                          cc = re_wctype (str);
# Line 2653  regex_compile (pattern, size, syntax, bu Line 2677  regex_compile (pattern, size, syntax, bu
2677                                 starting at the smallest character in                                 starting at the smallest character in
2678                                 the charset of C1 and ending at C1.  */                                 the charset of C1 and ending at C1.  */
2679                              int charset = CHAR_CHARSET (c1);                              int charset = CHAR_CHARSET (c1);
2680                              int c2 = MAKE_CHAR (charset, 0, 0);                              re_wchar_t c2 = MAKE_CHAR (charset, 0, 0);
2681                                
2682                              SET_RANGE_TABLE_WORK_AREA (range_table_work,                              SET_RANGE_TABLE_WORK_AREA (range_table_work,
2683                                                         c2, c1);                                                         c2, c1);
2684                              c1 = 0377;                              c1 = 0377;
# Line 2672  regex_compile (pattern, size, syntax, bu Line 2696  regex_compile (pattern, size, syntax, bu
2696                    /* ... into bitmap.  */                    /* ... into bitmap.  */
2697                    {                    {
2698                      re_wchar_t this_char;                      re_wchar_t this_char;
2699                      int range_start = c, range_end = c1;                      re_wchar_t range_start = c, range_end = c1;
2700    
2701                      /* If the start is after the end, the range is empty.  */                      /* If the start is after the end, the range is empty.  */
2702                      if (range_start > range_end)                      if (range_start > range_end)
# Line 2769  regex_compile (pattern, size, syntax, bu Line 2793  regex_compile (pattern, size, syntax, bu
2793            /* Do not translate the character after the \, so that we can            /* Do not translate the character after the \, so that we can
2794               distinguish, e.g., \B from \b, even if we normally would               distinguish, e.g., \B from \b, even if we normally would
2795               translate, e.g., B to b.  */               translate, e.g., B to b.  */
2796            PATFETCH_RAW (c);            PATFETCH (c);
2797    
2798            switch (c)            switch (c)
2799              {              {
# Line 3129  regex_compile (pattern, size, syntax, bu Line 3153  regex_compile (pattern, size, syntax, bu
3153    
3154              case 'c':              case 'c':
3155                laststart = b;                laststart = b;
3156                PATFETCH_RAW (c);                PATFETCH (c);
3157                BUF_PUSH_2 (categoryspec, c);                BUF_PUSH_2 (categoryspec, c);
3158                break;                break;
3159    
3160              case 'C':              case 'C':
3161                laststart = b;                laststart = b;
3162                PATFETCH_RAW (c);                PATFETCH (c);
3163                BUF_PUSH_2 (notcategoryspec, c);                BUF_PUSH_2 (notcategoryspec, c);
3164                break;                break;
3165  #endif /* emacs */  #endif /* emacs */
# Line 3225  regex_compile (pattern, size, syntax, bu Line 3249  regex_compile (pattern, size, syntax, bu
3249                /* You might think it would be useful for \ to mean                /* You might think it would be useful for \ to mean
3250                   not to translate; but if we don't translate it                   not to translate; but if we don't translate it
3251                   it will never match anything.  */                   it will never match anything.  */
               c = TRANSLATE (c);  
3252                goto normal_char;                goto normal_char;
3253              }              }
3254            break;            break;
# Line 3234  regex_compile (pattern, size, syntax, bu Line 3257  regex_compile (pattern, size, syntax, bu
3257          default:          default:
3258          /* Expects the character in `c'.  */          /* Expects the character in `c'.  */
3259          normal_char:          normal_char:
3260                /* If no exactn currently being built.  */            /* If no exactn currently being built.  */
3261            if (!pending_exact            if (!pending_exact
3262    
3263                /* If last exactn not at current position.  */                /* If last exactn not at current position.  */
# Line 3265  regex_compile (pattern, size, syntax, bu Line 3288  regex_compile (pattern, size, syntax, bu
3288            {            {
3289              int len;              int len;
3290    
3291                c = TRANSLATE (c);
3292              if (multibyte)              if (multibyte)
3293                len = CHAR_STRING (c, b);                len = CHAR_STRING (c, b);
3294              else              else
# Line 4427  mutually_exclusive_p (bufp, p1, p2) Line 4451  mutually_exclusive_p (bufp, p1, p2)
4451               they don't overlap.  The union of the two sets of excluded               they don't overlap.  The union of the two sets of excluded
4452               chars should cover all possible chars, which, as a matter of               chars should cover all possible chars, which, as a matter of
4453               fact, is virtually impossible in multibyte buffers.  */               fact, is virtually impossible in multibyte buffers.  */
4454            ;            break;
4455          }          }
4456        break;        break;
4457    

Legend:
Removed from v.1.176  
changed lines
  Added in v.1.177

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