/[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.176.2.1 by miles, Fri Apr 4 06:21:03 2003 UTC
# Line 33  Line 33 
33    #pragma alloca    #pragma alloca
34  #endif  #endif
35    
 #undef  _GNU_SOURCE  
 #define _GNU_SOURCE  
   
36  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
37  # include <config.h>  # include <config.h>
38  #endif  #endif
# Line 160  Line 157 
157         {                                                                \         {                                                                \
158           re_char *dtemp = (p) == (str2) ? (end1) : (p);                 \           re_char *dtemp = (p) == (str2) ? (end1) : (p);                 \
159           re_char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \           re_char *dlimit = ((p) > (str2) && (p) <= (end2)) ? (str2) : (str1); \
160           while (dtemp-- > dlimit && !CHAR_HEAD_P (*dtemp));             \           re_char *d0 = dtemp;                                           \
161           c = STRING_CHAR (dtemp, (p) - dtemp);                          \           PREV_CHAR_BOUNDARY (d0, dlimit);                               \
162             c = STRING_CHAR (d0, dtemp - d0);                              \
163         }                                                                \         }                                                                \
164       else                                                               \       else                                                               \
165         (c = ((p) == (str2) ? (end1) : (p))[-1]);                        \         (c = ((p) == (str2) ? (end1) : (p))[-1]);                        \
# Line 238  enum syntaxcode { Swhitespace = 0, Sword Line 236  enum syntaxcode { Swhitespace = 0, Sword
236  # define SINGLE_BYTE_CHAR_P(c) (1)  # define SINGLE_BYTE_CHAR_P(c) (1)
237  # define SAME_CHARSET_P(c1, c2) (1)  # define SAME_CHARSET_P(c1, c2) (1)
238  # define MULTIBYTE_FORM_LENGTH(p, s) (1)  # define MULTIBYTE_FORM_LENGTH(p, s) (1)
239    # define PREV_CHAR_BOUNDARY(p, limit) ((p)--)
240  # define STRING_CHAR(p, s) (*(p))  # define STRING_CHAR(p, s) (*(p))
241  # define RE_STRING_CHAR STRING_CHAR  # define RE_STRING_CHAR STRING_CHAR
242  # define CHAR_STRING(c, s) (*(s) = (c), 1)  # define CHAR_STRING(c, s) (*(s) = (c), 1)
# Line 922  print_partial_compiled_pattern (start, e Line 921  print_partial_compiled_pattern (start, e
921    
922    if (start == NULL)    if (start == NULL)
923      {      {
924        printf ("(null)\n");        fprintf (stderr, "(null)\n");
925        return;        return;
926      }      }
927    
928    /* Loop over pattern commands.  */    /* Loop over pattern commands.  */
929    while (p < pend)    while (p < pend)
930      {      {
931        printf ("%d:\t", p - start);        fprintf (stderr, "%d:\t", p - start);
932    
933        switch ((re_opcode_t) *p++)        switch ((re_opcode_t) *p++)
934          {          {
935          case no_op:          case no_op:
936            printf ("/no_op");            fprintf (stderr, "/no_op");
937            break;            break;
938    
939          case succeed:          case succeed:
940            printf ("/succeed");            fprintf (stderr, "/succeed");
941            break;            break;
942    
943          case exactn:          case exactn:
944            mcnt = *p++;            mcnt = *p++;
945            printf ("/exactn/%d", mcnt);            fprintf (stderr, "/exactn/%d", mcnt);
946            do            do
947              {              {
948                putchar ('/');                fprintf (stderr, "/%c", *p++);
               putchar (*p++);  
949              }              }
950            while (--mcnt);            while (--mcnt);
951            break;            break;
952    
953          case start_memory:          case start_memory:
954            printf ("/start_memory/%d", *p++);            fprintf (stderr, "/start_memory/%d", *p++);
955            break;            break;
956    
957          case stop_memory:          case stop_memory:
958            printf ("/stop_memory/%d", *p++);            fprintf (stderr, "/stop_memory/%d", *p++);
959            break;            break;
960    
961          case duplicate:          case duplicate:
962            printf ("/duplicate/%d", *p++);            fprintf (stderr, "/duplicate/%d", *p++);
963            break;            break;
964    
965          case anychar:          case anychar:
966            printf ("/anychar");            fprintf (stderr, "/anychar");
967            break;            break;
968    
969          case charset:          case charset:
# Line 976  print_partial_compiled_pattern (start, e Line 974  print_partial_compiled_pattern (start, e
974              int length = CHARSET_BITMAP_SIZE (p - 1);              int length = CHARSET_BITMAP_SIZE (p - 1);
975              int has_range_table = CHARSET_RANGE_TABLE_EXISTS_P (p - 1);              int has_range_table = CHARSET_RANGE_TABLE_EXISTS_P (p - 1);
976    
977              printf ("/charset [%s",              fprintf (stderr, "/charset [%s",
978                      (re_opcode_t) *(p - 1) == charset_not ? "^" : "");                      (re_opcode_t) *(p - 1) == charset_not ? "^" : "");
979    
980              assert (p + *p < pend);              assert (p + *p < pend);
# Line 988  print_partial_compiled_pattern (start, e Line 986  print_partial_compiled_pattern (start, e
986                    /* Are we starting a range?  */                    /* Are we starting a range?  */
987                    if (last + 1 == c && ! in_range)                    if (last + 1 == c && ! in_range)
988                      {                      {
989                        putchar ('-');                        fprintf (stderr, "-");
990                        in_range = 1;                        in_range = 1;
991                      }                      }
992                    /* Have we broken a range?  */                    /* Have we broken a range?  */
993                    else if (last + 1 != c && in_range)                    else if (last + 1 != c && in_range)
994                      {                      {
995                        putchar (last);                        fprintf (stderr, "%c", last);
996                        in_range = 0;                        in_range = 0;
997                      }                      }
998    
999                    if (! in_range)                    if (! in_range)
1000                      putchar (c);                      fprintf (stderr, "%c", c);
1001    
1002                    last = c;                    last = c;
1003                }                }
1004    
1005              if (in_range)              if (in_range)
1006                putchar (last);                fprintf (stderr, "%c", last);
1007    
1008              putchar (']');              fprintf (stderr, "]");
1009    
1010              p += 1 + length;              p += 1 + length;
1011    
1012              if (has_range_table)              if (has_range_table)
1013                {                {
1014                  int count;                  int count;
1015                  printf ("has-range-table");                  fprintf (stderr, "has-range-table");
1016    
1017                  /* ??? Should print the range table; for now, just skip it.  */                  /* ??? Should print the range table; for now, just skip it.  */
1018                  p += 2;         /* skip range table bits */                  p += 2;         /* skip range table bits */
# Line 1025  print_partial_compiled_pattern (start, e Line 1023  print_partial_compiled_pattern (start, e
1023            break;            break;
1024    
1025          case begline:          case begline:
1026            printf ("/begline");            fprintf (stderr, "/begline");
1027            break;            break;
1028    
1029          case endline:          case endline:
1030            printf ("/endline");            fprintf (stderr, "/endline");
1031            break;            break;
1032    
1033          case on_failure_jump:          case on_failure_jump:
1034            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1035            printf ("/on_failure_jump to %d", p + mcnt - start);            fprintf (stderr, "/on_failure_jump to %d", p + mcnt - start);
1036            break;            break;
1037    
1038          case on_failure_keep_string_jump:          case on_failure_keep_string_jump:
1039            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1040            printf ("/on_failure_keep_string_jump to %d", p + mcnt - start);            fprintf (stderr, "/on_failure_keep_string_jump to %d", p + mcnt - start);
1041            break;            break;
1042    
1043          case on_failure_jump_nastyloop:          case on_failure_jump_nastyloop:
1044            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1045            printf ("/on_failure_jump_nastyloop to %d", p + mcnt - start);            fprintf (stderr, "/on_failure_jump_nastyloop to %d", p + mcnt - start);
1046            break;            break;
1047    
1048          case on_failure_jump_loop:          case on_failure_jump_loop:
1049            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1050            printf ("/on_failure_jump_loop to %d", p + mcnt - start);            fprintf (stderr, "/on_failure_jump_loop to %d", p + mcnt - start);
1051            break;            break;
1052    
1053          case on_failure_jump_smart:          case on_failure_jump_smart:
1054            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1055            printf ("/on_failure_jump_smart to %d", p + mcnt - start);            fprintf (stderr, "/on_failure_jump_smart to %d", p + mcnt - start);
1056            break;            break;
1057    
1058          case jump:          case jump:
1059            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1060            printf ("/jump to %d", p + mcnt - start);            fprintf (stderr, "/jump to %d", p + mcnt - start);
1061            break;            break;
1062    
1063          case succeed_n:          case succeed_n:
1064            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1065            extract_number_and_incr (&mcnt2, &p);            extract_number_and_incr (&mcnt2, &p);
1066            printf ("/succeed_n to %d, %d times", p - 2 + mcnt - start, mcnt2);            fprintf (stderr, "/succeed_n to %d, %d times", p - 2 + mcnt - start, mcnt2);
1067            break;            break;
1068    
1069          case jump_n:          case jump_n:
1070            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1071            extract_number_and_incr (&mcnt2, &p);            extract_number_and_incr (&mcnt2, &p);
1072            printf ("/jump_n to %d, %d times", p - 2 + mcnt - start, mcnt2);            fprintf (stderr, "/jump_n to %d, %d times", p - 2 + mcnt - start, mcnt2);
1073            break;            break;
1074    
1075          case set_number_at:          case set_number_at:
1076            extract_number_and_incr (&mcnt, &p);            extract_number_and_incr (&mcnt, &p);
1077            extract_number_and_incr (&mcnt2, &p);            extract_number_and_incr (&mcnt2, &p);
1078            printf ("/set_number_at location %d to %d", p - 2 + mcnt - start, mcnt2);            fprintf (stderr, "/set_number_at location %d to %d", p - 2 + mcnt - start, mcnt2);
1079            break;            break;
1080    
1081          case wordbound:          case wordbound:
1082            printf ("/wordbound");            fprintf (stderr, "/wordbound");
1083            break;            break;
1084    
1085          case notwordbound:          case notwordbound:
1086            printf ("/notwordbound");            fprintf (stderr, "/notwordbound");
1087            break;            break;
1088    
1089          case wordbeg:          case wordbeg:
1090            printf ("/wordbeg");            fprintf (stderr, "/wordbeg");
1091            break;            break;
1092    
1093          case wordend:          case wordend:
1094            printf ("/wordend");            fprintf (stderr, "/wordend");
1095    
1096          case syntaxspec:          case syntaxspec:
1097            printf ("/syntaxspec");            fprintf (stderr, "/syntaxspec");
1098            mcnt = *p++;            mcnt = *p++;
1099            printf ("/%d", mcnt);            fprintf (stderr, "/%d", mcnt);
1100            break;            break;
1101    
1102          case notsyntaxspec:          case notsyntaxspec:
1103            printf ("/notsyntaxspec");            fprintf (stderr, "/notsyntaxspec");
1104            mcnt = *p++;            mcnt = *p++;
1105            printf ("/%d", mcnt);            fprintf (stderr, "/%d", mcnt);
1106            break;            break;
1107    
1108  # ifdef emacs  # ifdef emacs
1109          case before_dot:          case before_dot:
1110            printf ("/before_dot");            fprintf (stderr, "/before_dot");
1111            break;            break;
1112    
1113          case at_dot:          case at_dot:
1114            printf ("/at_dot");            fprintf (stderr, "/at_dot");
1115            break;            break;
1116    
1117          case after_dot:          case after_dot:
1118            printf ("/after_dot");            fprintf (stderr, "/after_dot");
1119            break;            break;
1120    
1121          case categoryspec:          case categoryspec:
1122            printf ("/categoryspec");            fprintf (stderr, "/categoryspec");
1123            mcnt = *p++;            mcnt = *p++;
1124            printf ("/%d", mcnt);            fprintf (stderr, "/%d", mcnt);
1125            break;            break;
1126    
1127          case notcategoryspec:          case notcategoryspec:
1128            printf ("/notcategoryspec");            fprintf (stderr, "/notcategoryspec");
1129            mcnt = *p++;            mcnt = *p++;
1130            printf ("/%d", mcnt);            fprintf (stderr, "/%d", mcnt);
1131            break;            break;
1132  # endif /* emacs */  # endif /* emacs */
1133    
1134          case begbuf:          case begbuf:
1135            printf ("/begbuf");            fprintf (stderr, "/begbuf");
1136            break;            break;
1137    
1138          case endbuf:          case endbuf:
1139            printf ("/endbuf");            fprintf (stderr, "/endbuf");
1140            break;            break;
1141    
1142          default:          default:
1143            printf ("?%d", *(p-1));            fprintf (stderr, "?%d", *(p-1));
1144          }          }
1145    
1146        putchar ('\n');        fprintf (stderr, "\n");
1147      }      }
1148    
1149    printf ("%d:\tend of pattern.\n", p - start);    fprintf (stderr, "%d:\tend of pattern.\n", p - start);
1150  }  }
1151    
1152    
# Line 1518  do {                                                                   \ Line 1516  do {                                                                   \
1516      }                                                                   \      }                                                                   \
1517  } while (0)  } while (0)
1518    
 /* Discard a saved register off the stack.  */  
 #define DISCARD_FAILURE_REG_OR_COUNT()                                  \  
 do {                                                                    \  
   int reg = POP_FAILURE_INT ();                                         \  
   if (reg == -1)                                                        \  
     {                                                                   \  
       /* It's a counter.  */                                            \  
       POP_FAILURE_POINTER ();                                           \  
       reg = POP_FAILURE_INT ();                                         \  
       DEBUG_PRINT3 ("     Discard counter %p = %d\n", ptr, reg);        \  
     }                                                                   \  
   else                                                                  \  
     {                                                                   \  
       POP_FAILURE_POINTER ();                                           \  
       POP_FAILURE_POINTER ();                                           \  
       DEBUG_PRINT4 ("     Discard reg %d (spanning %p -> %p)\n",        \  
                     reg, regstart[reg], regend[reg]);                   \  
     }                                                                   \  
 } while (0)  
   
1519  /* Check that we are not stuck in an infinite loop.  */  /* Check that we are not stuck in an infinite loop.  */
1520  #define CHECK_INFINITE_LOOP(pat_cur, string_place)                      \  #define CHECK_INFINITE_LOOP(pat_cur, string_place)                      \
1521  do {                                                                    \  do {                                                                    \
# Line 1551  do {                                                                   \ Line 1529  do {                                                                   \
1529                && FAILURE_PAT (failure) <= bufp->buffer + bufp->used);   \                && FAILURE_PAT (failure) <= bufp->buffer + bufp->used);   \
1530        if (FAILURE_PAT (failure) == pat_cur)                             \        if (FAILURE_PAT (failure) == pat_cur)                             \
1531          {                                                               \          {                                                               \
1532            while (fail_stack.frame < fail_stack.avail)                   \            cycle = 1;                                                    \
1533              DISCARD_FAILURE_REG_OR_COUNT ();                            \            break;                                                        \
           goto fail;                                                    \  
1534          }                                                               \          }                                                               \
1535        DEBUG_PRINT2 ("  Other pattern: %p\n", FAILURE_PAT (failure));    \        DEBUG_PRINT2 ("  Other pattern: %p\n", FAILURE_PAT (failure));    \
1536        failure = NEXT_FAILURE_HANDLE(failure);                           \        failure = NEXT_FAILURE_HANDLE(failure);                           \
1537      }                                                                   \      }                                                                   \
1538    DEBUG_PRINT2 ("  Other string: %p\n", FAILURE_STR (failure));         \    DEBUG_PRINT2 ("  Other string: %p\n", FAILURE_STR (failure));         \
1539  } while (0)  } while (0)
1540        
1541  /* Push the information about the state we will need  /* Push the information about the state we will need
1542     if we ever fail back to it.     if we ever fail back to it.
1543    
# Line 1682  static re_char *skip_one_char _RE_ARGS ( Line 1659  static re_char *skip_one_char _RE_ARGS (
1659  static int analyse_first _RE_ARGS ((re_char *p, re_char *pend,  static int analyse_first _RE_ARGS ((re_char *p, re_char *pend,
1660                                      char *fastmap, const int multibyte));                                      char *fastmap, const int multibyte));
1661    
 /* Fetch the next character in the uncompiled pattern---translating it  
    if necessary.  */  
 #define PATFETCH(c)                                                     \  
   do {                                                                  \  
     PATFETCH_RAW (c);                                                   \  
     c = TRANSLATE (c);                                                  \  
   } while (0)  
   
1662  /* Fetch the next character in the uncompiled pattern, with no  /* Fetch the next character in the uncompiled pattern, with no
1663     translation.  */     translation.  */
1664  #define PATFETCH_RAW(c)                                                 \  #define PATFETCH(c)                                                     \
1665    do {                                                                  \    do {                                                                  \
1666      int len;                                                            \      int len;                                                            \
1667      if (p == pend) return REG_EEND;                                     \      if (p == pend) return REG_EEND;                                     \
# Line 1840  static int analyse_first _RE_ARGS ((re_c Line 1809  static int analyse_first _RE_ARGS ((re_c
1809    
1810  /* But patterns can have more than `MAX_REGNUM' registers.  We just  /* But patterns can have more than `MAX_REGNUM' registers.  We just
1811     ignore the excess.  */     ignore the excess.  */
1812  typedef unsigned regnum_t;  typedef int regnum_t;
1813    
1814    
1815  /* Macros for the compile stack.  */  /* Macros for the compile stack.  */
# Line 1875  typedef struct Line 1844  typedef struct
1844  /* The next available element.  */  /* The next available element.  */
1845  #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])  #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
1846    
1847    /* Explicit quit checking is only used on NTemacs.  */
1848    #if defined WINDOWSNT && defined emacs && defined QUIT
1849    extern int immediate_quit;
1850    # define IMMEDIATE_QUIT_CHECK                   \
1851        do {                                        \
1852          if (immediate_quit) QUIT;                 \
1853        } while (0)
1854    #else
1855    # define IMMEDIATE_QUIT_CHECK    ((void)0)
1856    #endif
1857    
1858  /* Structure to manage work area for range table.  */  /* Structure to manage work area for range table.  */
1859  struct range_table_work_area  struct range_table_work_area
1860  {  {
# Line 1885  struct range_table_work_area Line 1864  struct range_table_work_area
1864    int bits;                     /* flag to record character classes */    int bits;                     /* flag to record character classes */
1865  };  };
1866    
1867  /* Make sure that WORK_AREA can hold more N multibyte characters.  */  /* Make sure that WORK_AREA can hold more N multibyte characters.
1868  #define EXTEND_RANGE_TABLE_WORK_AREA(work_area, n)                        \     This is used only in set_image_of_range and set_image_of_range_1.
1869    do {                                                                    \     It expects WORK_AREA to be a pointer.
1870      if (((work_area).used + (n)) * sizeof (int) > (work_area).allocated)  \     If it can't get the space, it returns from the surrounding function.  */
1871        {                                                                   \  
1872          (work_area).allocated += 16 * sizeof (int);                       \  #define EXTEND_RANGE_TABLE(work_area, n)                                \
1873          if ((work_area).table)                                            \    do {                                                                  \
1874            (work_area).table                                               \      if (((work_area)->used + (n)) * sizeof (int) > (work_area)->allocated) \
1875              = (int *) realloc ((work_area).table, (work_area).allocated); \        {                                                                 \
1876          else                                                              \          extend_range_table_work_area (work_area);                       \
1877            (work_area).table                                               \          if ((work_area)->table == 0)                                    \
1878              = (int *) malloc ((work_area).allocated);                     \            return (REG_ESPACE);                                          \
1879          if ((work_area).table == 0)                                       \        }                                                                 \
           FREE_STACK_RETURN (REG_ESPACE);                                 \  
       }                                                                   \  
1880    } while (0)    } while (0)
1881    
1882  #define SET_RANGE_TABLE_WORK_AREA_BIT(work_area, bit)           \  #define SET_RANGE_TABLE_WORK_AREA_BIT(work_area, bit)           \
# Line 1914  struct range_table_work_area Line 1891  struct range_table_work_area
1891  #define BIT_UPPER       0x10  #define BIT_UPPER       0x10
1892  #define BIT_MULTIBYTE   0x20  #define BIT_MULTIBYTE   0x20
1893    
1894  /* Set a range (RANGE_START, RANGE_END) to WORK_AREA.  */  /* Set a range START..END to WORK_AREA.
1895  #define SET_RANGE_TABLE_WORK_AREA(work_area, range_start, range_end)    \     The range is passed through TRANSLATE, so START and END
1896       should be untranslated.  */
1897    #define SET_RANGE_TABLE_WORK_AREA(work_area, start, end)                \
1898    do {                                                                  \    do {                                                                  \
1899      EXTEND_RANGE_TABLE_WORK_AREA ((work_area), 2);                      \      int tem;                                                            \
1900      (work_area).table[(work_area).used++] = (range_start);              \      tem = set_image_of_range (&work_area, start, end, translate);       \
1901      (work_area).table[(work_area).used++] = (range_end);                \      if (tem > 0)                                                        \
1902          FREE_STACK_RETURN (tem);                                          \
1903    } while (0)    } while (0)
1904    
1905  /* Free allocated memory for WORK_AREA.  */  /* Free allocated memory for WORK_AREA.  */
# Line 1933  struct range_table_work_area Line 1913  struct range_table_work_area
1913  #define RANGE_TABLE_WORK_USED(work_area) ((work_area).used)  #define RANGE_TABLE_WORK_USED(work_area) ((work_area).used)
1914  #define RANGE_TABLE_WORK_BITS(work_area) ((work_area).bits)  #define RANGE_TABLE_WORK_BITS(work_area) ((work_area).bits)
1915  #define RANGE_TABLE_WORK_ELT(work_area, i) ((work_area).table[i])  #define RANGE_TABLE_WORK_ELT(work_area, i) ((work_area).table[i])
1916    
1917    
1918  /* Set the bit for character C in a list.  */  /* Set the bit for character C in a list.  */
1919  #define SET_LIST_BIT(c) (b[((c)) / BYTEWIDTH] |= 1 << ((c) % BYTEWIDTH))  #define SET_LIST_BIT(c) (b[((c)) / BYTEWIDTH] |= 1 << ((c) % BYTEWIDTH))
# Line 1963  struct range_table_work_area Line 1943  struct range_table_work_area
1943           FREE_STACK_RETURN (REG_BADBR);                                 \           FREE_STACK_RETURN (REG_BADBR);                                 \
1944         }                                                                \         }                                                                \
1945      } while (0)      } while (0)
1946    
1947  #if WIDE_CHAR_SUPPORT  #if WIDE_CHAR_SUPPORT
1948  /* The GNU C library provides support for user-defined character classes  /* The GNU C library provides support for user-defined character classes
1949     and the functions from ISO C amendement 1.  */     and the functions from ISO C amendement 1.  */
# Line 2076  re_wctype_to_bit (cc) Line 2056  re_wctype_to_bit (cc)
2056      }      }
2057  }  }
2058  #endif  #endif
2059    
2060    /* Filling in the work area of a range.  */
2061    
2062  /* Explicit quit checking is only used on NTemacs.  */  /* Actually extend the space in WORK_AREA.  */
2063  #if defined WINDOWSNT && defined emacs && defined QUIT  
2064  extern int immediate_quit;  static void
2065  # define IMMEDIATE_QUIT_CHECK                   \  extend_range_table_work_area (work_area)
2066      do {                                        \       struct range_table_work_area *work_area;
2067        if (immediate_quit) QUIT;                 \  {
2068      } while (0)    work_area->allocated += 16 * sizeof (int);
2069  #else    if (work_area->table)
2070  # define IMMEDIATE_QUIT_CHECK    ((void)0)      work_area->table
2071          = (int *) realloc (work_area->table, work_area->allocated);
2072      else
2073        work_area->table
2074          = (int *) malloc (work_area->allocated);
2075    }
2076    
2077    #ifdef emacs
2078    
2079    /* Carefully find the ranges of codes that are equivalent
2080       under case conversion to the range start..end when passed through
2081       TRANSLATE.  Handle the case where non-letters can come in between
2082       two upper-case letters (which happens in Latin-1).
2083       Also handle the case of groups of more than 2 case-equivalent chars.
2084    
2085       The basic method is to look at consecutive characters and see
2086       if they can form a run that can be handled as one.
2087    
2088       Returns -1 if successful, REG_ESPACE if ran out of space.  */
2089    
2090    static int
2091    set_image_of_range_1 (work_area, start, end, translate)
2092         RE_TRANSLATE_TYPE translate;
2093         struct range_table_work_area *work_area;
2094         re_wchar_t start, end;
2095    {
2096      /* `one_case' indicates a character, or a run of characters,
2097         each of which is an isolate (no case-equivalents).
2098         This includes all ASCII non-letters.
2099    
2100         `two_case' indicates a character, or a run of characters,
2101         each of which has two case-equivalent forms.
2102         This includes all ASCII letters.
2103    
2104         `strange' indicates a character that has more than one
2105         case-equivalent.  */
2106    
2107      enum case_type {one_case, two_case, strange};
2108    
2109      /* Describe the run that is in progress,
2110         which the next character can try to extend.
2111         If run_type is strange, that means there really is no run.
2112         If run_type is one_case, then run_start...run_end is the run.
2113         If run_type is two_case, then the run is run_start...run_end,
2114         and the case-equivalents end at run_eqv_end.  */
2115    
2116      enum case_type run_type = strange;
2117      int run_start, run_end, run_eqv_end;
2118    
2119      Lisp_Object eqv_table;
2120    
2121      if (!RE_TRANSLATE_P (translate))
2122        {
2123          EXTEND_RANGE_TABLE (work_area, 2);
2124          work_area->table[work_area->used++] = (start);
2125          work_area->table[work_area->used++] = (end);
2126          return -1;
2127        }
2128    
2129      eqv_table = XCHAR_TABLE (translate)->extras[2];
2130    
2131      for (; start <= end; start++)
2132        {
2133          enum case_type this_type;
2134          int eqv = RE_TRANSLATE (eqv_table, start);
2135          int minchar, maxchar;
2136    
2137          /* Classify this character */
2138          if (eqv == start)
2139            this_type = one_case;
2140          else if (RE_TRANSLATE (eqv_table, eqv) == start)
2141            this_type = two_case;
2142          else
2143            this_type = strange;
2144    
2145          if (start < eqv)
2146            minchar = start, maxchar = eqv;
2147          else
2148            minchar = eqv, maxchar = start;
2149    
2150          /* Can this character extend the run in progress?  */
2151          if (this_type == strange || this_type != run_type
2152              || !(minchar == run_end + 1
2153                   && (run_type == two_case
2154                       ? maxchar == run_eqv_end + 1 : 1)))
2155            {
2156              /* No, end the run.
2157                 Record each of its equivalent ranges.  */
2158              if (run_type == one_case)
2159                {
2160                  EXTEND_RANGE_TABLE (work_area, 2);
2161                  work_area->table[work_area->used++] = run_start;
2162                  work_area->table[work_area->used++] = run_end;
2163                }
2164              else if (run_type == two_case)
2165                {
2166                  EXTEND_RANGE_TABLE (work_area, 4);
2167                  work_area->table[work_area->used++] = run_start;
2168                  work_area->table[work_area->used++] = run_end;
2169                  work_area->table[work_area->used++]
2170                    = RE_TRANSLATE (eqv_table, run_start);
2171                  work_area->table[work_area->used++]
2172                    = RE_TRANSLATE (eqv_table, run_end);
2173                }
2174              run_type = strange;
2175            }
2176    
2177          if (this_type == strange)
2178            {
2179              /* For a strange character, add each of its equivalents, one
2180                 by one.  Don't start a range.  */
2181              do
2182                {
2183                  EXTEND_RANGE_TABLE (work_area, 2);
2184                  work_area->table[work_area->used++] = eqv;
2185                  work_area->table[work_area->used++] = eqv;
2186                  eqv = RE_TRANSLATE (eqv_table, eqv);
2187                }
2188              while (eqv != start);
2189            }
2190    
2191          /* Add this char to the run, or start a new run.  */
2192          else if (run_type == strange)
2193            {
2194              /* Initialize a new range.  */
2195              run_type = this_type;
2196              run_start = start;
2197              run_end = start;
2198              run_eqv_end = RE_TRANSLATE (eqv_table, run_end);
2199            }
2200          else
2201            {
2202              /* Extend a running range.  */
2203              run_end = minchar;
2204              run_eqv_end = RE_TRANSLATE (eqv_table, run_end);
2205            }
2206        }
2207    
2208      /* If a run is still in progress at the end, finish it now
2209         by recording its equivalent ranges.  */
2210      if (run_type == one_case)
2211        {
2212          EXTEND_RANGE_TABLE (work_area, 2);
2213          work_area->table[work_area->used++] = run_start;
2214          work_area->table[work_area->used++] = run_end;
2215        }
2216      else if (run_type == two_case)
2217        {
2218          EXTEND_RANGE_TABLE (work_area, 4);
2219          work_area->table[work_area->used++] = run_start;
2220          work_area->table[work_area->used++] = run_end;
2221          work_area->table[work_area->used++]
2222            = RE_TRANSLATE (eqv_table, run_start);
2223          work_area->table[work_area->used++]
2224            = RE_TRANSLATE (eqv_table, run_end);
2225        }
2226    
2227      return -1;
2228    }
2229    
2230    #endif /* emacs */
2231    
2232    /* Record the the image of the range start..end when passed through
2233       TRANSLATE.  This is not necessarily TRANSLATE(start)..TRANSLATE(end)
2234       and is not even necessarily contiguous.
2235       Normally we approximate it with the smallest contiguous range that contains
2236       all the chars we need.  However, for Latin-1 we go to extra effort
2237       to do a better job.
2238    
2239       This function is not called for ASCII ranges.
2240    
2241       Returns -1 if successful, REG_ESPACE if ran out of space.  */
2242    
2243    static int
2244    set_image_of_range (work_area, start, end, translate)
2245         RE_TRANSLATE_TYPE translate;
2246         struct range_table_work_area *work_area;
2247         re_wchar_t start, end;
2248    {
2249      re_wchar_t cmin, cmax;
2250    
2251    #ifdef emacs
2252      /* For Latin-1 ranges, use set_image_of_range_1
2253         to get proper handling of ranges that include letters and nonletters.
2254         For a range that includes the whole of Latin-1, this is not necessary.
2255         For other character sets, we don't bother to get this right.  */
2256      if (RE_TRANSLATE_P (translate) && start < 04400
2257          && !(start < 04200 && end >= 04377))
2258        {
2259          int newend;
2260          int tem;
2261          newend = end;
2262          if (newend > 04377)
2263            newend = 04377;
2264          tem = set_image_of_range_1 (work_area, start, newend, translate);
2265          if (tem > 0)
2266            return tem;
2267    
2268          start = 04400;
2269          if (end < 04400)
2270            return -1;
2271        }
2272  #endif  #endif
2273    
2274      EXTEND_RANGE_TABLE (work_area, 2);
2275      work_area->table[work_area->used++] = (start);
2276      work_area->table[work_area->used++] = (end);
2277    
2278      cmin = -1, cmax = -1;
2279    
2280      if (RE_TRANSLATE_P (translate))
2281        {
2282          int ch;
2283    
2284          for (ch = start; ch <= end; ch++)
2285            {
2286              re_wchar_t c = TRANSLATE (ch);
2287              if (! (start <= c && c <= end))
2288                {
2289                  if (cmin == -1)
2290                    cmin = c, cmax = c;
2291                  else
2292                    {
2293                      cmin = MIN (cmin, c);
2294                      cmax = MAX (cmax, c);
2295                    }
2296                }
2297            }
2298    
2299          if (cmin != -1)
2300            {
2301              EXTEND_RANGE_TABLE (work_area, 2);
2302              work_area->table[work_area->used++] = (cmin);
2303              work_area->table[work_area->used++] = (cmax);
2304            }
2305        }
2306    
2307      return -1;
2308    }
2309    
2310  #ifndef MATCH_MAY_ALLOCATE  #ifndef MATCH_MAY_ALLOCATE
2311    
# Line 2401  regex_compile (pattern, size, syntax, bu Line 2620  regex_compile (pattern, size, syntax, bu
2620                      unsigned int startoffset = 0;                      unsigned int startoffset = 0;
2621                      re_opcode_t ofj =                      re_opcode_t ofj =
2622                        /* Check if the loop can match the empty string.  */                        /* Check if the loop can match the empty string.  */
2623                        (simple || !analyse_first (laststart, b, NULL, 0)) ?                        (simple || !analyse_first (laststart, b, NULL, 0))
2624                        on_failure_jump : on_failure_jump_loop;                        ? on_failure_jump : on_failure_jump_loop;
2625                      assert (skip_one_char (laststart) <= b);                      assert (skip_one_char (laststart) <= b);
2626                        
2627                      if (!zero_times_ok && simple)                      if (!zero_times_ok && simple)
2628                        { /* Since simple * loops can be made faster by using                        { /* Since simple * loops can be made faster by using
2629                             on_failure_keep_string_jump, we turn simple P+                             on_failure_keep_string_jump, we turn simple P+
# Line 2450  regex_compile (pattern, size, syntax, bu Line 2669  regex_compile (pattern, size, syntax, bu
2669                    {                    {
2670                      boolean emptyp = analyse_first (laststart, b, NULL, 0);                      boolean emptyp = analyse_first (laststart, b, NULL, 0);
2671    
2672                      /* The non-greedy multiple match looks like a repeat..until:                      /* The non-greedy multiple match looks like
2673                         we only need a conditional jump at the end of the loop */                         a repeat..until: we only need a conditional jump
2674                           at the end of the loop.  */
2675                      if (emptyp) BUF_PUSH (no_op);                      if (emptyp) BUF_PUSH (no_op);
2676                      STORE_JUMP (emptyp ? on_failure_jump_nastyloop                      STORE_JUMP (emptyp ? on_failure_jump_nastyloop
2677                                  : on_failure_jump, b, laststart);                                  : on_failure_jump, b, laststart);
# Line 2460  regex_compile (pattern, size, syntax, bu Line 2680  regex_compile (pattern, size, syntax, bu
2680                        {                        {
2681                          /* The repeat...until naturally matches one or more.                          /* The repeat...until naturally matches one or more.
2682                             To also match zero times, we need to first jump to                             To also match zero times, we need to first jump to
2683                             the end of the loop (its conditional jump). */                             the end of the loop (its conditional jump).  */
2684                          INSERT_JUMP (jump, laststart, b);                          INSERT_JUMP (jump, laststart, b);
2685                          b += 3;                          b += 3;
2686                        }                        }
# Line 2525  regex_compile (pattern, size, syntax, bu Line 2745  regex_compile (pattern, size, syntax, bu
2745    
2746                  if (p == pend) FREE_STACK_RETURN (REG_EBRACK);                  if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
2747    
2748                    /* Don't translate yet.  The range TRANSLATE(X..Y) cannot
2749                       always be determined from TRANSLATE(X) and TRANSLATE(Y)
2750                       So the translation is done later in a loop.  Example:
2751                       (let ((case-fold-search t)) (string-match "[A-_]" "A"))  */
2752                  PATFETCH (c);                  PATFETCH (c);
2753    
2754                  /* \ might escape characters inside [...] and [^...].  */                  /* \ might escape characters inside [...] and [^...].  */
# Line 2584  regex_compile (pattern, size, syntax, bu Line 2808  regex_compile (pattern, size, syntax, bu
2808                         them).  */                         them).  */
2809                      if (c == ':' && *p == ']')                      if (c == ':' && *p == ']')
2810                        {                        {
2811                          int ch;                          re_wchar_t ch;
2812                          re_wctype_t cc;                          re_wctype_t cc;
2813    
2814                          cc = re_wctype (str);                          cc = re_wctype (str);
# Line 2653  regex_compile (pattern, size, syntax, bu Line 2877  regex_compile (pattern, size, syntax, bu
2877                                 starting at the smallest character in                                 starting at the smallest character in
2878                                 the charset of C1 and ending at C1.  */                                 the charset of C1 and ending at C1.  */
2879                              int charset = CHAR_CHARSET (c1);                              int charset = CHAR_CHARSET (c1);
2880                              int c2 = MAKE_CHAR (charset, 0, 0);                              re_wchar_t c2 = MAKE_CHAR (charset, 0, 0);
2881                                
2882                              SET_RANGE_TABLE_WORK_AREA (range_table_work,                              SET_RANGE_TABLE_WORK_AREA (range_table_work,
2883                                                         c2, c1);                                                         c2, c1);
2884                              c1 = 0377;                              c1 = 0377;
# Line 2672  regex_compile (pattern, size, syntax, bu Line 2896  regex_compile (pattern, size, syntax, bu
2896                    /* ... into bitmap.  */                    /* ... into bitmap.  */
2897                    {                    {
2898                      re_wchar_t this_char;                      re_wchar_t this_char;
2899                      int range_start = c, range_end = c1;                      re_wchar_t range_start = c, range_end = c1;
2900    
2901                      /* If the start is after the end, the range is empty.  */                      /* If the start is after the end, the range is empty.  */
2902                      if (range_start > range_end)                      if (range_start > range_end)
# Line 2769  regex_compile (pattern, size, syntax, bu Line 2993  regex_compile (pattern, size, syntax, bu
2993            /* Do not translate the character after the \, so that we can            /* Do not translate the character after the \, so that we can
2994               distinguish, e.g., \B from \b, even if we normally would               distinguish, e.g., \B from \b, even if we normally would
2995               translate, e.g., B to b.  */               translate, e.g., B to b.  */
2996            PATFETCH_RAW (c);            PATFETCH (c);
2997    
2998            switch (c)            switch (c)
2999              {              {
# Line 2993  regex_compile (pattern, size, syntax, bu Line 3217  regex_compile (pattern, size, syntax, bu
3217                        goto unfetch_interval;                        goto unfetch_interval;
3218                    }                    }
3219    
3220                   if (upper_bound == 0)                  if (upper_bound == 0)
3221                     /* If the upper bound is zero, just drop the sub pattern                    /* If the upper bound is zero, just drop the sub pattern
3222                        altogether.  */                       altogether.  */
3223                     b = laststart;                    b = laststart;
3224                   else if (lower_bound == 1 && upper_bound == 1)                  else if (lower_bound == 1 && upper_bound == 1)
3225                     /* Just match it once: nothing to do here.  */                    /* Just match it once: nothing to do here.  */
3226                     ;                    ;
3227    
3228                   /* Otherwise, we have a nontrivial interval.  When                  /* Otherwise, we have a nontrivial interval.  When
3229                      we're all done, the pattern will look like:                     we're all done, the pattern will look like:
3230                        set_number_at <jump count> <upper bound>                     set_number_at <jump count> <upper bound>
3231                        set_number_at <succeed_n count> <lower bound>                     set_number_at <succeed_n count> <lower bound>
3232                        succeed_n <after jump addr> <succeed_n count>                     succeed_n <after jump addr> <succeed_n count>
3233                        <body of loop>                     <body of loop>
3234                        jump_n <succeed_n addr> <jump count>                     jump_n <succeed_n addr> <jump count>
3235                      (The upper bound and `jump_n' are omitted if                     (The upper bound and `jump_n' are omitted if
3236                      `upper_bound' is 1, though.)  */                     `upper_bound' is 1, though.)  */
3237                   else                  else
3238                     { /* If the upper bound is > 1, we need to insert                    { /* If the upper bound is > 1, we need to insert
3239                          more at the end of the loop.  */                         more at the end of the loop.  */
3240                       unsigned int nbytes = (upper_bound < 0 ? 3                      unsigned int nbytes = (upper_bound < 0 ? 3
3241                                              : upper_bound > 1 ? 5 : 0);                                             : upper_bound > 1 ? 5 : 0);
3242                       unsigned int startoffset = 0;                      unsigned int startoffset = 0;
3243    
3244                       GET_BUFFER_SPACE (20); /* We might use less.  */                      GET_BUFFER_SPACE (20); /* We might use less.  */
3245    
3246                       if (lower_bound == 0)                      if (lower_bound == 0)
3247                         {                        {
3248                           /* A succeed_n that starts with 0 is really a                          /* A succeed_n that starts with 0 is really a
3249                              a simple on_failure_jump_loop.  */                             a simple on_failure_jump_loop.  */
3250                           INSERT_JUMP (on_failure_jump_loop, laststart,                          INSERT_JUMP (on_failure_jump_loop, laststart,
3251                                        b + 3 + nbytes);                                       b + 3 + nbytes);
3252                           b += 3;                          b += 3;
3253                         }                        }
3254                       else                      else
3255                         {                        {
3256                           /* Initialize lower bound of the `succeed_n', even                          /* Initialize lower bound of the `succeed_n', even
3257                              though it will be set during matching by its                             though it will be set during matching by its
3258                              attendant `set_number_at' (inserted next),                             attendant `set_number_at' (inserted next),
3259                              because `re_compile_fastmap' needs to know.                             because `re_compile_fastmap' needs to know.
3260                              Jump to the `jump_n' we might insert below.  */                             Jump to the `jump_n' we might insert below.  */
3261                           INSERT_JUMP2 (succeed_n, laststart,                          INSERT_JUMP2 (succeed_n, laststart,
3262                                         b + 5 + nbytes,                                        b + 5 + nbytes,
3263                                         lower_bound);                                        lower_bound);
3264                           b += 5;                          b += 5;
3265    
3266                           /* Code to initialize the lower bound.  Insert                          /* Code to initialize the lower bound.  Insert
3267                              before the `succeed_n'.      The `5' is the last two                             before the `succeed_n'.       The `5' is the last two
3268                              bytes of this `set_number_at', plus 3 bytes of                             bytes of this `set_number_at', plus 3 bytes of
3269                              the following `succeed_n'.  */                             the following `succeed_n'.  */
3270                           insert_op2 (set_number_at, laststart, 5, lower_bound, b);                          insert_op2 (set_number_at, laststart, 5, lower_bound, b);
3271                           b += 5;                          b += 5;
3272                           startoffset += 5;                          startoffset += 5;
3273                         }                        }
3274    
3275                       if (upper_bound < 0)                      if (upper_bound < 0)
3276                         {                        {
3277                           /* A negative upper bound stands for infinity,                          /* A negative upper bound stands for infinity,
3278                              in which case it degenerates to a plain jump.  */                             in which case it degenerates to a plain jump.  */
3279                           STORE_JUMP (jump, b, laststart + startoffset);                          STORE_JUMP (jump, b, laststart + startoffset);
3280                           b += 3;                          b += 3;
3281                         }                        }
3282                       else if (upper_bound > 1)                      else if (upper_bound > 1)
3283                         { /* More than one repetition is allowed, so                        { /* More than one repetition is allowed, so
3284                              append a backward jump to the `succeed_n'                             append a backward jump to the `succeed_n'
3285                              that starts this interval.                             that starts this interval.
3286    
3287                              When we've reached this during matching,                             When we've reached this during matching,
3288                              we'll have matched the interval once, so                             we'll have matched the interval once, so
3289                              jump back only `upper_bound - 1' times.  */                             jump back only `upper_bound - 1' times.  */
3290                           STORE_JUMP2 (jump_n, b, laststart + startoffset,                          STORE_JUMP2 (jump_n, b, laststart + startoffset,
3291                                        upper_bound - 1);                                       upper_bound - 1);
3292                           b += 5;                          b += 5;
3293    
3294                           /* The location we want to set is the second                          /* The location we want to set is the second
3295                              parameter of the `jump_n'; that is `b-2' as                             parameter of the `jump_n'; that is `b-2' as
3296                              an absolute address.  `laststart' will be                             an absolute address.  `laststart' will be
3297                              the `set_number_at' we're about to insert;                             the `set_number_at' we're about to insert;
3298                              `laststart+3' the number to set, the source                             `laststart+3' the number to set, the source
3299                              for the relative address.  But we are                             for the relative address.  But we are
3300                              inserting into the middle of the pattern --                             inserting into the middle of the pattern --
3301                              so everything is getting moved up by 5.                             so everything is getting moved up by 5.
3302                              Conclusion: (b - 2) - (laststart + 3) + 5,                             Conclusion: (b - 2) - (laststart + 3) + 5,
3303                              i.e., b - laststart.                             i.e., b - laststart.
3304    
3305                              We insert this at the beginning of the loop                             We insert this at the beginning of the loop
3306                              so that if we fail during matching, we'll                             so that if we fail during matching, we'll
3307                              reinitialize the bounds.  */                             reinitialize the bounds.  */
3308                           insert_op2 (set_number_at, laststart, b - laststart,                          insert_op2 (set_number_at, laststart, b - laststart,
3309                                       upper_bound - 1, b);                                      upper_bound - 1, b);
3310                           b += 5;                          b += 5;
3311                         }                        }
3312                     }                    }
3313                  pending_exact = 0;                  pending_exact = 0;
3314                  beg_interval = NULL;                  beg_interval = NULL;
3315                }                }
# Line 3129  regex_compile (pattern, size, syntax, bu Line 3353  regex_compile (pattern, size, syntax, bu
3353    
3354              case 'c':              case 'c':
3355                laststart = b;                laststart = b;
3356                PATFETCH_RAW (c);                PATFETCH (c);
3357                BUF_PUSH_2 (categoryspec, c);                BUF_PUSH_2 (categoryspec, c);
3358                break;                break;
3359    
3360              case 'C':              case 'C':
3361                laststart = b;                laststart = b;
3362                PATFETCH_RAW (c);                PATFETCH (c);
3363                BUF_PUSH_2 (notcategoryspec, c);                BUF_PUSH_2 (notcategoryspec, c);
3364                break;                break;
3365  #endif /* emacs */  #endif /* emacs */
# Line 3225  regex_compile (pattern, size, syntax, bu Line 3449  regex_compile (pattern, size, syntax, bu
3449                /* You might think it would be useful for \ to mean                /* You might think it would be useful for \ to mean
3450                   not to translate; but if we don't translate it                   not to translate; but if we don't translate it
3451                   it will never match anything.  */                   it will never match anything.  */
               c = TRANSLATE (c);  
3452                goto normal_char;                goto normal_char;
3453              }              }
3454            break;            break;
# Line 3234  regex_compile (pattern, size, syntax, bu Line 3457  regex_compile (pattern, size, syntax, bu
3457          default:          default:
3458          /* Expects the character in `c'.  */          /* Expects the character in `c'.  */
3459          normal_char:          normal_char:
3460                /* If no exactn currently being built.  */            /* If no exactn currently being built.  */
3461            if (!pending_exact            if (!pending_exact
3462    
3463                /* If last exactn not at current position.  */                /* If last exactn not at current position.  */
# Line 3265  regex_compile (pattern, size, syntax, bu Line 3488  regex_compile (pattern, size, syntax, bu
3488            {            {
3489              int len;              int len;
3490    
3491                c = TRANSLATE (c);
3492              if (multibyte)              if (multibyte)
3493                len = CHAR_STRING (c, b);                len = CHAR_STRING (c, b);
3494              else              else
# Line 3716  analyse_first (p, pend, fastmap, multiby Line 3940  analyse_first (p, pend, fastmap, multiby
3940               case has already been handled, so we only need to look at the               case has already been handled, so we only need to look at the
3941               fallthrough case.  */               fallthrough case.  */
3942            continue;            continue;
3943              
3944          case succeed_n:          case succeed_n:
3945            /* If N == 0, it should be an on_failure_jump_loop instead.  */            /* If N == 0, it should be an on_failure_jump_loop instead.  */
3946            DEBUG_STATEMENT (EXTRACT_NUMBER (j, p + 2); assert (j > 0));            DEBUG_STATEMENT (EXTRACT_NUMBER (j, p + 2); assert (j > 0));
# Line 3841  re_search (bufp, string, size, startpos, Line 4065  re_search (bufp, string, size, startpos,
4065  }  }
4066  WEAK_ALIAS (__re_search, re_search)  WEAK_ALIAS (__re_search, re_search)
4067    
4068    /* Head address of virtual concatenation of string.  */
4069    #define HEAD_ADDR_VSTRING(P)            \
4070      (((P) >= size1 ? string2 : string1))
4071    
4072  /* End address of virtual concatenation of string.  */  /* End address of virtual concatenation of string.  */
4073  #define STOP_ADDR_VSTRING(P)                            \  #define STOP_ADDR_VSTRING(P)                            \
4074    (((P) >= size1 ? string2 + size2 : string1 + size1))    (((P) >= size1 ? string2 + size2 : string1 + size1))
# Line 4076  re_search_2 (bufp, str1, size1, str2, si Line 4304  re_search_2 (bufp, str1, size1, str2, si
4304            /* Update STARTPOS to the previous character boundary.  */            /* Update STARTPOS to the previous character boundary.  */
4305            if (multibyte)            if (multibyte)
4306              {              {
4307                re_char *p = POS_ADDR_VSTRING (startpos);                re_char *p = POS_ADDR_VSTRING (startpos) + 1;
4308                int len = 0;                re_char *p0 = p;
4309                  re_char *phead = HEAD_ADDR_VSTRING (startpos);
4310    
4311                /* Find the head of multibyte form.  */                /* Find the head of multibyte form.  */
4312                while (!CHAR_HEAD_P (*p))                PREV_CHAR_BOUNDARY (p, phead);
4313                  p--, len++;                range += p0 - 1 - p;
4314                  if (range > 0)
4315                /* Adjust it. */                  break;
 #if 0                           /* XXX */  
               if (MULTIBYTE_FORM_LENGTH (p, len + 1) != (len + 1))  
                 ;  
               else  
 #endif  
                 {  
                   range += len;  
                   if (range > 0)  
                     break;  
4316    
4317                    startpos -= len;                startpos -= p0 - 1 - p;
                 }  
4318              }              }
4319          }          }
4320      }      }
# Line 4204  skip_one_char (p) Line 4423  skip_one_char (p)
4423      {      {
4424      case anychar:      case anychar:
4425        break;        break;
4426          
4427      case exactn:      case exactn:
4428        p += *p + 1;        p += *p + 1;
4429        break;        break;
# Line 4221  skip_one_char (p) Line 4440  skip_one_char (p)
4440        else        else
4441          p += 1 + CHARSET_BITMAP_SIZE (p - 1);          p += 1 + CHARSET_BITMAP_SIZE (p - 1);
4442        break;        break;
4443          
4444      case syntaxspec:      case syntaxspec:
4445      case notsyntaxspec:      case notsyntaxspec:
4446  #ifdef emacs  #ifdef emacs
# Line 4304  mutually_exclusive_p (bufp, p1, p2) Line 4523  mutually_exclusive_p (bufp, p1, p2)
4523            return 1;            return 1;
4524          }          }
4525        break;        break;
4526          
4527      case endline:      case endline:
4528      case exactn:      case exactn:
4529        {        {
# Line 4414  mutually_exclusive_p (bufp, p1, p2) Line 4633  mutually_exclusive_p (bufp, p1, p2)
4633            }            }
4634        }        }
4635        break;        break;
4636          
4637      case charset_not:      case charset_not:
4638        switch (SWITCH_ENUM_CAST (*p1))        switch (SWITCH_ENUM_CAST (*p1))
4639          {          {
# Line 4427  mutually_exclusive_p (bufp, p1, p2) Line 4646  mutually_exclusive_p (bufp, p1, p2)
4646               they don't overlap.  The union of the two sets of excluded               they don't overlap.  The union of the two sets of excluded
4647               chars should cover all possible chars, which, as a matter of               chars should cover all possible chars, which, as a matter of
4648               fact, is virtually impossible in multibyte buffers.  */               fact, is virtually impossible in multibyte buffers.  */
4649            ;            break;
4650          }          }
4651        break;        break;
4652    
# Line 5098  re_match_2_internal (bufp, string1, size Line 5317  re_match_2_internal (bufp, string1, size
5317    
5318            assert (!REG_UNSET (regstart[*p]));            assert (!REG_UNSET (regstart[*p]));
5319            /* Strictly speaking, there should be code such as:            /* Strictly speaking, there should be code such as:
5320                
5321                  assert (REG_UNSET (regend[*p]));                  assert (REG_UNSET (regend[*p]));
5322                  PUSH_FAILURE_REGSTOP ((unsigned int)*p);                  PUSH_FAILURE_REGSTOP ((unsigned int)*p);
5323    
# Line 5270  re_match_2_internal (bufp, string1, size Line 5489  re_match_2_internal (bufp, string1, size
5489               cycle detection cannot work.  Worse yet, such a detection               cycle detection cannot work.  Worse yet, such a detection
5490               can not only fail to detect a cycle, but it can also wrongly               can not only fail to detect a cycle, but it can also wrongly
5491               detect a cycle (between different instantiations of the same               detect a cycle (between different instantiations of the same
5492               loop.               loop).
5493               So the method used for those nasty loops is a little different:               So the method used for those nasty loops is a little different:
5494               We use a special cycle-detection-stack-frame which is pushed               We use a special cycle-detection-stack-frame which is pushed
5495               when the on_failure_jump_nastyloop failure-point is *popped*.               when the on_failure_jump_nastyloop failure-point is *popped*.
# Line 5284  re_match_2_internal (bufp, string1, size Line 5503  re_match_2_internal (bufp, string1, size
5503                          mcnt, p + mcnt);                          mcnt, p + mcnt);
5504    
5505            assert ((re_opcode_t)p[-4] == no_op);            assert ((re_opcode_t)p[-4] == no_op);
5506            CHECK_INFINITE_LOOP (p - 4, d);            {
5507            PUSH_FAILURE_POINT (p - 3, d);              int cycle = 0;
5508                CHECK_INFINITE_LOOP (p - 4, d);
5509                if (!cycle)
5510                  /* If there's a cycle, just continue without pushing
5511                     this failure point.  The failure point is the "try again"
5512                     option, which shouldn't be tried.
5513                     We want (x?)*?y\1z to match both xxyz and xxyxz.  */
5514                  PUSH_FAILURE_POINT (p - 3, d);
5515              }
5516            break;            break;
5517    
   
5518            /* Simple loop detecting on_failure_jump:  just check on the            /* Simple loop detecting on_failure_jump:  just check on the
5519               failure stack if the same spot was already hit earlier.  */               failure stack if the same spot was already hit earlier.  */
5520          case on_failure_jump_loop:          case on_failure_jump_loop:
# Line 5296  re_match_2_internal (bufp, string1, size Line 5522  re_match_2_internal (bufp, string1, size
5522            EXTRACT_NUMBER_AND_INCR (mcnt, p);            EXTRACT_NUMBER_AND_INCR (mcnt, p);
5523            DEBUG_PRINT3 ("EXECUTING on_failure_jump_loop %d (to %p):\n",            DEBUG_PRINT3 ("EXECUTING on_failure_jump_loop %d (to %p):\n",
5524                          mcnt, p + mcnt);                          mcnt, p + mcnt);
5525              {
5526            CHECK_INFINITE_LOOP (p - 3, d);              int cycle = 0;
5527            PUSH_FAILURE_POINT (p - 3, d);              CHECK_INFINITE_LOOP (p - 3, d);
5528                if (cycle)
5529                  /* If there's a cycle, get out of the loop, as if the matching
5530                     had failed.  We used to just `goto fail' here, but that was
5531                     aborting the search a bit too early: we want to keep the
5532                     empty-loop-match and keep matching after the loop.
5533                     We want (x?)*y\1z to match both xxyz and xxyxz.  */
5534                  p += mcnt;
5535                else
5536                  PUSH_FAILURE_POINT (p - 3, d);
5537              }
5538            break;            break;
5539    
5540    
# Line 5498  re_match_2_internal (bufp, string1, size Line 5734  re_match_2_internal (bufp, string1, size
5734                PREFETCH ();                PREFETCH ();
5735                c2 = RE_STRING_CHAR (d, dend - d);                c2 = RE_STRING_CHAR (d, dend - d);
5736                s2 = SYNTAX (c2);                s2 = SYNTAX (c2);
5737            
5738                /* Case 2: S2 is not Sword. */                /* Case 2: S2 is not Sword. */
5739                if (s2 != Sword)                if (s2 != Sword)
5740                  goto fail;                  goto fail;
# Line 5959  regexec (preg, string, nmatch, pmatch, e Line 6195  regexec (preg, string, nmatch, pmatch, e
6195      const regex_t *__restrict preg;      const regex_t *__restrict preg;
6196      const char *__restrict string;      const char *__restrict string;
6197      size_t nmatch;      size_t nmatch;
6198      regmatch_t pmatch[];      regmatch_t pmatch[__restrict_arr];
6199      int eflags;      int eflags;
6200  {  {
6201    int ret;    int ret;

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

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