home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gnurx.zip / rx / rxgnucomp.c < prev    next >
C/C++ Source or Header  |  1995-12-31  |  40KB  |  1,464 lines

  1. /*    Copyright (C) 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  2.  * 
  3.  * This program is free software; you can redistribute it and/or modify
  4.  * it under the terms of the GNU Library General Public License as published by
  5.  * the Free Software Foundation; either version 2, or (at your option)
  6.  * any later version.
  7.  * 
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11.  * GNU Library General Public License for more details.
  12.  * 
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this software; see the file COPYING.  If not, write to
  15.  * the Free Software Foundation, 59 Temple Place - Suite 330, 
  16.  * Boston, MA 02111-1307, USA. 
  17.  */
  18.  
  19.  
  20. #include "rxall.h"
  21. #include "rxgnucomp.h"
  22.  
  23. /* {A Syntax Table} 
  24.  */
  25.  
  26. /* Define the syntax basics for \<, \>, etc.
  27.  */
  28.  
  29. #ifndef emacs
  30. #define CHARBITS 8
  31. #define CHAR_SET_SIZE (1 << CHARBITS)
  32. #define Sword 1
  33. #define SYNTAX(c) re_syntax_table[c]
  34. char re_syntax_table[CHAR_SET_SIZE];
  35.  
  36. #ifdef __STDC__
  37. static void
  38. init_syntax_once (void)
  39. #else
  40. static void
  41. init_syntax_once ()
  42. #endif
  43. {
  44.    register int c;
  45.    static int done = 0;
  46.  
  47.    if (done)
  48.      return;
  49.  
  50.    bzero (re_syntax_table, sizeof re_syntax_table);
  51.  
  52.    for (c = 'a'; c <= 'z'; c++)
  53.      re_syntax_table[c] = Sword;
  54.  
  55.    for (c = 'A'; c <= 'Z'; c++)
  56.      re_syntax_table[c] = Sword;
  57.  
  58.    for (c = '0'; c <= '9'; c++)
  59.      re_syntax_table[c] = Sword;
  60.  
  61.    re_syntax_table['_'] = Sword;
  62.  
  63.    done = 1;
  64. }
  65. #endif /* not emacs */
  66.  
  67.  
  68.  
  69.  
  70.  
  71. const char *rx_error_msg[] =
  72. {
  73.   0,                        /* REG_NOUT */
  74.   "No match",                    /* REG_NOMATCH */
  75.   "Invalid regular expression",            /* REG_BADPAT */
  76.   "Invalid collation character",        /* REG_ECOLLATE */
  77.   "Invalid character class name",        /* REG_ECTYPE */
  78.   "Trailing backslash",                /* REG_EESCAPE */
  79.   "Invalid back reference",            /* REG_ESUBREG */
  80.   "Unmatched [ or [^",                /* REG_EBRACK */
  81.   "Unmatched ( or \\(",                /* REG_EPAREN */
  82.   "Unmatched \\{",                /* REG_EBRACE */
  83.   "Invalid content of \\{\\}",            /* REG_BADBR */
  84.   "Invalid range end",                /* REG_ERANGE */
  85.   "Memory exhausted",                /* REG_ESPACE */
  86.   "Invalid preceding regular expression",    /* REG_BADRPT */
  87.   "Premature end of regular expression",    /* REG_EEND */
  88.   "Regular expression too big",            /* REG_ESIZE */
  89.   "Unmatched ) or \\)",                /* REG_ERPAREN */
  90. };
  91.  
  92.  
  93.  
  94. /* 
  95.  * Macros used while compiling patterns.
  96.  *
  97.  * By convention, PEND points just past the end of the uncompiled pattern,
  98.  * P points to the read position in the pattern.  `translate' is the name
  99.  * of the translation table (`TRANSLATE' is the name of a macro that looks
  100.  * things up in `translate').
  101.  */
  102.  
  103.  
  104. /*
  105.  * Fetch the next character in the uncompiled pattern---translating it 
  106.  * if necessary. *Also cast from a signed character in the constant
  107.  * string passed to us by the user to an unsigned char that we can use
  108.  * as an array index (in, e.g., `translate').
  109.  */
  110. #define PATFETCH(c)                            \
  111.  do {if (p == pend) return REG_EEND;                    \
  112.     c = (unsigned char) *p++;                        \
  113.     c = translate[c];                             \
  114.  } while (0)
  115.  
  116. /* 
  117.  * Fetch the next character in the uncompiled pattern, with no
  118.  * translation.
  119.  */
  120. #define PATFETCH_RAW(c)                            \
  121.   do {if (p == pend) return REG_EEND;                    \
  122.     c = (unsigned char) *p++;                         \
  123.   } while (0)
  124.  
  125. /* Go backwards one character in the pattern.  */
  126. #define PATUNFETCH p--
  127.  
  128.  
  129. #define TRANSLATE(d) translate[(unsigned char) (d)]
  130.  
  131. typedef unsigned regnum_t;
  132.  
  133. /* Since offsets can go either forwards or backwards, this type needs to
  134.  * be able to hold values from -(MAX_BUF_SIZE - 1) to MAX_BUF_SIZE - 1.
  135.  */
  136. typedef int pattern_offset_t;
  137.  
  138. typedef struct
  139. {
  140.   struct rexp_node ** top_expression; /* was begalt */
  141.   struct rexp_node ** last_expression; /* was laststart */
  142.   pattern_offset_t inner_group_offset;
  143.   regnum_t regnum;
  144. } compile_stack_elt_t;
  145.  
  146. typedef struct
  147. {
  148.   compile_stack_elt_t *stack;
  149.   unsigned size;
  150.   unsigned avail;            /* Offset of next open position.  */
  151. } compile_stack_type;
  152.  
  153.  
  154. #define INIT_COMPILE_STACK_SIZE 32
  155.  
  156. #define COMPILE_STACK_EMPTY  (compile_stack.avail == 0)
  157. #define COMPILE_STACK_FULL  (compile_stack.avail == compile_stack.size)
  158.  
  159. /* The next available element.  */
  160. #define COMPILE_STACK_TOP (compile_stack.stack[compile_stack.avail])
  161.  
  162.  
  163. /* Set the bit for character C in a list.  */
  164. #define SET_LIST_BIT(c)                               \
  165.   (b[((unsigned char) (c)) / CHARBITS]               \
  166.    |= 1 << (((unsigned char) c) % CHARBITS))
  167.  
  168. /* Get the next unsigned number in the uncompiled pattern.  */
  169. #define GET_UNSIGNED_NUMBER(num)                     \
  170.   { if (p != pend)                            \
  171.      {                                    \
  172.        PATFETCH (c);                             \
  173.        while (isdigit (c))                         \
  174.          {                                 \
  175.            if (num < 0)                            \
  176.               num = 0;                            \
  177.            num = num * 10 + c - '0';                     \
  178.            if (p == pend)                         \
  179.               break;                             \
  180.            PATFETCH (c);                        \
  181.          }                                 \
  182.        }                                 \
  183.     }        
  184.  
  185. #define CHAR_CLASS_MAX_LENGTH  6 /* Namely, `xdigit'.  */
  186.  
  187. #define IS_CHAR_CLASS(string)                        \
  188.    (!strcmp (string, "alpha") || !strcmp (string, "upper")        \
  189.     || !strcmp (string, "lower") || !strcmp (string, "digit")        \
  190.     || !strcmp (string, "alnum") || !strcmp (string, "xdigit")        \
  191.     || !strcmp (string, "space") || !strcmp (string, "print")        \
  192.     || !strcmp (string, "punct") || !strcmp (string, "graph")        \
  193.     || !strcmp (string, "cntrl") || !strcmp (string, "blank"))
  194.  
  195.  
  196. /* These predicates are used in regex_compile. */
  197.  
  198. /* P points to just after a ^ in PATTERN.  Return true if that ^ comes
  199.  * after an alternative or a begin-subexpression.  We assume there is at
  200.  * least one character before the ^.  
  201.  */
  202.  
  203. #ifdef __STDC__
  204. static int
  205. at_begline_loc_p (const char *pattern, const char * p, unsigned long syntax)
  206. #else
  207. static int
  208. at_begline_loc_p (pattern, p, syntax)
  209.      const char *pattern;
  210.      const char * p;
  211.      unsigned long syntax;
  212. #endif
  213. {
  214.   const char *prev = p - 2;
  215.   int prev_prev_backslash = ((prev > pattern) && (prev[-1] == '\\'));
  216.   
  217.     return
  218.       
  219.       (/* After a subexpression?  */
  220.        ((*prev == '(') && ((syntax & RE_NO_BK_PARENS) || prev_prev_backslash))
  221.        ||
  222.        /* After an alternative?  */
  223.        ((*prev == '|') && ((syntax & RE_NO_BK_VBAR) || prev_prev_backslash))
  224.        );
  225. }
  226.  
  227. /* The dual of at_begline_loc_p.  This one is for $.  We assume there is
  228.  * at least one character after the $, i.e., `P < PEND'.
  229.  */
  230.  
  231. #ifdef __STDC__
  232. static int
  233. at_endline_loc_p (const char *p, const char *pend, int syntax)
  234. #else
  235. static int
  236. at_endline_loc_p (p, pend, syntax)
  237.      const char *p;
  238.      const char *pend;
  239.      int syntax;
  240. #endif
  241. {
  242.   const char *next = p;
  243.   int next_backslash = (*next == '\\');
  244.   const char *next_next = (p + 1 < pend) ? (p + 1) : 0;
  245.   
  246.   return
  247.     (
  248.      /* Before a subexpression?  */
  249.      ((syntax & RE_NO_BK_PARENS)
  250.       ? (*next == ')')
  251.       : (next_backslash && next_next && (*next_next == ')')))
  252.     ||
  253.      /* Before an alternative?  */
  254.      ((syntax & RE_NO_BK_VBAR)
  255.       ? (*next == '|')
  256.       : (next_backslash && next_next && (*next_next == '|')))
  257.      );
  258. }
  259.  
  260.  
  261. unsigned char rx_id_translation[256] =
  262. {
  263.   0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
  264.  10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  265.  20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  266.  30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  267.  40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
  268.  50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
  269.  60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
  270.  70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  271.  80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
  272.  90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
  273.  
  274.  100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
  275.  110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
  276.  120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
  277.  130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
  278.  140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
  279.  150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
  280.  160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
  281.  170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
  282.  180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
  283.  190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
  284.  
  285.  200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
  286.  210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
  287.  220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
  288.  230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
  289.  240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
  290.  250, 251, 252, 253, 254, 255
  291. };
  292.  
  293. /* The compiler keeps an inverted translation table.
  294.  * This looks up/inititalize elements.
  295.  * VALID is an array of booleans that validate CACHE.
  296.  */
  297.  
  298. #ifdef __STDC__
  299. static rx_Bitset
  300. inverse_translation (int cset_size, char * valid, rx_Bitset cache, unsigned char * translate, int c)
  301. #else
  302. static rx_Bitset
  303. inverse_translation (cset_size, valid, cache, translate, c)
  304.      int cset_size;
  305.      char * valid;
  306.      rx_Bitset cache;
  307.      unsigned char * translate;
  308.      int c;
  309. #endif
  310. {
  311.   rx_Bitset cs;
  312.   cs = cache + c * rx_bitset_numb_subsets (cset_size); 
  313.  
  314.   if (!valid[c])
  315.     {
  316.       int x;
  317.       int c_tr = TRANSLATE(c);
  318.       rx_bitset_null (cset_size, cs);
  319.       for (x = 0; x < 256; ++x)    /* &&&& 13.37 */
  320.     if (TRANSLATE(x) == c_tr)
  321.       RX_bitset_enjoin (cs, x);
  322.       valid[c] = 1;
  323.     }
  324.   return cs;
  325. }
  326.  
  327.  
  328.  
  329.  
  330. /* More subroutine declarations and macros for regex_compile.  */
  331.  
  332. /* Returns true if REGNUM is in one of COMPILE_STACK's elements and 
  333.  * false if it's not.
  334.  */
  335.  
  336. #ifdef __STDC__
  337. static int
  338. group_in_compile_stack (compile_stack_type compile_stack, regnum_t regnum)
  339. #else
  340. static int
  341. group_in_compile_stack (compile_stack, regnum)
  342.     compile_stack_type compile_stack;
  343.     regnum_t regnum;
  344. #endif
  345. {
  346.   int this_element;
  347.  
  348.   for (this_element = compile_stack.avail - 1;  
  349.        this_element >= 0; 
  350.        this_element--)
  351.     if (compile_stack.stack[this_element].regnum == regnum)
  352.       return 1;
  353.  
  354.   return 0;
  355. }
  356.  
  357.  
  358. /*
  359.  * Read the ending character of a range (in a bracket expression) from the
  360.  * uncompiled pattern *P_PTR (which ends at PEND).  We assume the
  361.  * starting character is in `P[-2]'.  (`P[-1]' is the character `-'.)
  362.  * Then we set the translation of all bits between the starting and
  363.  * ending characters (inclusive) in the compiled pattern B.
  364.  * 
  365.  * Return an error code.
  366.  * 
  367.  * We use these short variable names so we can use the same macros as
  368.  * `regex_compile' itself.  
  369.  */
  370.  
  371. #ifdef __STDC__
  372. static reg_errcode_t
  373. compile_range (int cset_size, rx_Bitset cs, const char ** p_ptr, const char * pend, unsigned char * translate, unsigned long syntax, rx_Bitset inv_tr, char * valid_inv_tr)
  374. #else
  375. static reg_errcode_t
  376. compile_range (cset_size, cs, p_ptr, pend, translate, syntax, inv_tr, valid_inv_tr)
  377.      int cset_size;
  378.      rx_Bitset cs;
  379.      const char ** p_ptr;
  380.      const char * pend;
  381.      unsigned char * translate;
  382.      unsigned long syntax;
  383.      rx_Bitset inv_tr;
  384.      char * valid_inv_tr;
  385. #endif
  386. {
  387.   unsigned this_char;
  388.  
  389.   const char *p = *p_ptr;
  390.  
  391.   unsigned char range_end;
  392.   unsigned char range_start = TRANSLATE(p[-2]);
  393.  
  394.   if (p == pend)
  395.     return REG_ERANGE;
  396.  
  397.   PATFETCH (range_end);
  398.  
  399.   (*p_ptr)++;
  400.  
  401.   if (range_start > range_end)
  402.     return syntax & RE_NO_EMPTY_RANGES ? REG_ERANGE : REG_NOERROR;
  403.  
  404.   for (this_char = range_start; this_char <= range_end; this_char++)
  405.     {
  406.       rx_Bitset it =
  407.     inverse_translation (cset_size, valid_inv_tr, inv_tr, translate, this_char);
  408.       rx_bitset_union (cset_size, cs, it);
  409.     }
  410.   
  411.   return REG_NOERROR;
  412. }
  413.  
  414.  
  415. #ifdef __STDC__
  416. static int
  417. pointless_if_repeated (struct rexp_node * node)
  418. #else
  419. static int
  420. pointless_if_repeated (node)
  421.      struct rexp_node * node;
  422. #endif
  423. {
  424.   if (!node)
  425.     return 1;
  426.   switch (node->type)
  427.     {
  428.     case r_cset:
  429.       return 0;
  430.     case r_concat:
  431.     case r_alternate:
  432.       return (pointless_if_repeated (node->params.pair.left)
  433.           && pointless_if_repeated (node->params.pair.right));
  434.     case r_opt:
  435.     case r_star:
  436.     case r_interval:
  437.     case r_parens:
  438.       return pointless_if_repeated (node->params.pair.left);
  439.     case r_context:
  440.       switch (node->params.intval)
  441.     {
  442.     case '=':
  443.     case '<':
  444.     case '^':
  445.     case 'b':
  446.     case 'B':
  447.     case '`':
  448.     case '\'':
  449.       return 1;
  450.     default:
  451.       return 0;
  452.     }
  453.     default:
  454.       return 0;
  455.     }
  456. }
  457.  
  458.  
  459.  
  460. #define isa_blank(C) (((C) == ' ') || ((C) != '\t'))
  461.  
  462. #ifdef __STDC__
  463. reg_errcode_t
  464. rx_parse (struct rexp_node ** rexp_p,
  465.       const char *pattern,
  466.       int size,
  467.       unsigned long syntax,
  468.       int cset_size,
  469.       unsigned char *translate)
  470. #else
  471. reg_errcode_t
  472. rx_parse (rexp_p, pattern, size, syntax, cset_size, translate)
  473.      struct rexp_node ** rexp_p;
  474.      const char *pattern;
  475.      int size;
  476.      unsigned long syntax;
  477.      int cset_size;
  478.      unsigned char *translate;
  479. #endif
  480. {
  481.   reg_errcode_t compile_error;
  482.   RX_subset
  483.     inverse_translate [CHAR_SET_SIZE * rx_bitset_numb_subsets(CHAR_SET_SIZE)];
  484.   char
  485.     validate_inv_tr [CHAR_SET_SIZE * rx_bitset_numb_subsets(CHAR_SET_SIZE)];
  486.  
  487.   /* We fetch characters from PATTERN here.  Even though PATTERN is
  488.      `char *' (i.e., signed), we declare these variables as unsigned, so
  489.      they can be reliably used as array indices.  */
  490.   register unsigned char c;
  491.   register unsigned char c1;
  492.   
  493.   /* A random tempory spot in PATTERN.  */
  494.   const char *p1;
  495.   
  496.   /* Keeps track of unclosed groups.  */
  497.   compile_stack_type compile_stack;
  498.  
  499.   /* Points to the current (ending) position in the pattern.  */
  500.   const char *p;
  501.   const char *pend;
  502.   
  503.   /* When parsing is done, this will hold the expression tree. */
  504.   struct rexp_node * rexp;
  505.  
  506.   /* This and top_expression are saved on the compile stack. */
  507.   struct rexp_node ** top_expression;
  508.   struct rexp_node ** last_expression;
  509.   
  510.   /* Parameter to `goto append_node' */
  511.   struct rexp_node * append;
  512.  
  513.   /* Counts open-groups as they are encountered.  This is the index of the
  514.    * innermost group being compiled.
  515.    */
  516.   regnum_t regnum;
  517.  
  518.   /* Place in the uncompiled pattern (i.e., the {) to
  519.    * which to go back if the interval is invalid.  
  520.    */
  521.   const char *beg_interval;
  522.  
  523.   int side;
  524.  
  525.  
  526.  
  527.   if (!translate)
  528.     translate = rx_id_translation;
  529.  
  530.   /* Points to the current (ending) position in the pattern.  */
  531.   p = pattern;
  532.   pend = pattern + size;
  533.   
  534.   /* When parsing is done, this will hold the expression tree. */
  535.   rexp = 0;
  536.  
  537.   /* In the midst of compilation, this holds onto the regexp 
  538.    * first parst while rexp goes on to aquire additional constructs.
  539.    */
  540.   top_expression = &rexp;
  541.   last_expression = top_expression;
  542.   
  543.   /* Counts open-groups as they are encountered.  This is the index of the
  544.    * innermost group being compiled.
  545.    */
  546.   regnum = 0;
  547.  
  548.   bzero (validate_inv_tr, sizeof (validate_inv_tr));
  549.  
  550.  
  551.   /* Initialize the compile stack.  */
  552.   compile_stack.stack =  (( compile_stack_elt_t *) malloc ((INIT_COMPILE_STACK_SIZE) * sizeof ( compile_stack_elt_t)));
  553.   if (compile_stack.stack == 0)
  554.     return REG_ESPACE;
  555.  
  556.   compile_stack.size = INIT_COMPILE_STACK_SIZE;
  557.   compile_stack.avail = 0;
  558.  
  559. #if !defined (emacs) && !defined (SYNTAX_TABLE)
  560.   /* Initialize the syntax table.  */
  561.    init_syntax_once ();
  562. #endif
  563.  
  564.   /* Loop through the uncompiled pattern until we're at the end.  */
  565.   while (p != pend)
  566.     {
  567.       PATFETCH (c);
  568.  
  569.       switch (c)
  570.         {
  571.         case '^':
  572.           {
  573.             if (   /* If at start of pattern, it's an operator.  */
  574.                    p == pattern + 1
  575.                    /* If context independent, it's an operator.  */
  576.                 || syntax & RE_CONTEXT_INDEP_ANCHORS
  577.                    /* Otherwise, depends on what's come before.  */
  578.                 || at_begline_loc_p (pattern, p, syntax))
  579.           {
  580.         struct rexp_node * n
  581.           = rx_mk_r_int (r_context, '^');
  582.         if (!n)
  583.           goto space_error;
  584.         append = n;
  585.         goto append_node;
  586.           }
  587.             else
  588.               goto normal_char;
  589.           }
  590.           break;
  591.  
  592.  
  593.         case '$':
  594.           {
  595.             if (   /* If at end of pattern, it's an operator.  */
  596.                    p == pend 
  597.                    /* If context independent, it's an operator.  */
  598.                 || syntax & RE_CONTEXT_INDEP_ANCHORS
  599.                    /* Otherwise, depends on what's next.  */
  600.                 || at_endline_loc_p (p, pend, syntax))
  601.           {
  602.         struct rexp_node * n
  603.           = rx_mk_r_int (r_context, '$');
  604.         if (!n)
  605.           goto space_error;
  606.         append = n;
  607.         goto append_node;
  608.           }
  609.              else
  610.                goto normal_char;
  611.            }
  612.            break;
  613.  
  614.  
  615.     case '+':
  616.         case '?':
  617.           if ((syntax & RE_BK_PLUS_QM)
  618.               || (syntax & RE_LIMITED_OPS))
  619.             goto normal_char;
  620.  
  621.         handle_plus:
  622.         case '*':
  623.           /* If there is no previous pattern... */
  624.           if (pointless_if_repeated (*last_expression))
  625.             {
  626.               if (syntax & RE_CONTEXT_INVALID_OPS)
  627.         {
  628.           compile_error = REG_BADRPT;
  629.           goto error_return;
  630.         }
  631.               else if (!(syntax & RE_CONTEXT_INDEP_OPS))
  632.                 goto normal_char;
  633.             }
  634.  
  635.           {
  636.             /* 1 means zero (many) matches is allowed.  */
  637.             char zero_times_ok = 0, many_times_ok = 0;
  638.  
  639.             /* If there is a sequence of repetition chars, collapse it
  640.                down to just one (the right one).  We can't combine
  641.                interval operators with these because of, e.g., `a{2}*',
  642.                which should only match an even number of `a's.  */
  643.  
  644.             for (;;)
  645.               {
  646.                 zero_times_ok |= c != '+';
  647.                 many_times_ok |= c != '?';
  648.  
  649.                 if (p == pend)
  650.                   break;
  651.  
  652.                 PATFETCH (c);
  653.  
  654.                 if (c == '*'
  655.                     || (!(syntax & RE_BK_PLUS_QM) && (c == '+' || c == '?')))
  656.                   ;
  657.  
  658.                 else if (syntax & RE_BK_PLUS_QM  &&  c == '\\')
  659.                   {
  660.                     if (p == pend)
  661.               {
  662.             compile_error = REG_EESCAPE;
  663.             goto error_return;
  664.               }
  665.  
  666.                     PATFETCH (c1);
  667.                     if (!(c1 == '+' || c1 == '?'))
  668.                       {
  669.                         PATUNFETCH;
  670.                         PATUNFETCH;
  671.                         break;
  672.                       }
  673.  
  674.                     c = c1;
  675.                   }
  676.                 else
  677.                   {
  678.                     PATUNFETCH;
  679.                     break;
  680.                   }
  681.  
  682.                 /* If we get here, we found another repeat character.  */
  683.                }
  684.  
  685.         /* Now we know whether or not zero matches is allowed
  686.          * and also whether or not two or more matches is allowed.
  687.          */
  688.  
  689.         {
  690.           struct rexp_node * inner_exp;
  691.           struct rexp_node * star;
  692.  
  693.           inner_exp = *last_expression;
  694.           star = rx_mk_r_monop ((many_times_ok
  695.                      ? (zero_times_ok ? r_star : r_plus)
  696.                      : r_opt),
  697.                     inner_exp);
  698.           if (!star)
  699.         goto space_error;
  700.           *last_expression = star;
  701.         }
  702.       }
  703.       break;
  704.  
  705.  
  706.     case '.':
  707.       {
  708.         rx_Bitset cs;
  709.         struct rexp_node * n;
  710.         cs = rx_cset (cset_size);
  711.         if (!cs)
  712.           goto space_error;
  713.         n = rx_mk_r_cset (r_cset, cset_size, cs);
  714.         if (!n)
  715.           {
  716.         rx_free_cset (cs);
  717.         goto space_error;
  718.           }
  719.         rx_bitset_universe (cset_size, cs);
  720.         if (!(syntax & RE_DOT_NEWLINE))
  721.           RX_bitset_remove (cs, '\n');
  722.         if (!(syntax & RE_DOT_NOT_NULL))
  723.           RX_bitset_remove (cs, 0);
  724.  
  725.         append = n;
  726.         goto append_node;
  727.         break;
  728.       }
  729.  
  730.  
  731.         case '[':
  732.       if (p == pend)
  733.         {
  734.           compile_error = REG_EBRACK;
  735.           goto error_return;
  736.         }
  737.           {
  738.             int had_char_class;
  739.         rx_Bitset cs;
  740.         struct rexp_node * node;
  741.         int is_inverted;
  742.  
  743.             had_char_class = 0;
  744.         is_inverted = *p == '^';
  745.         cs = rx_cset (cset_size);
  746.         if (!cs)
  747.           goto space_error;
  748.         node = rx_mk_r_cset (r_cset, cset_size ,cs);
  749.         if (!node)
  750.           {
  751.         rx_free_cset (cs);
  752.         goto space_error;
  753.           }
  754.         
  755.         /* This branch of the switch is normally exited with
  756.          *`goto append_node'
  757.          */
  758.         append = node;
  759.         
  760.             if (is_inverted)
  761.           p++;
  762.         
  763.             /* Remember the first position in the bracket expression.  */
  764.             p1 = p;
  765.         
  766.             /* Read in characters and ranges, setting map bits.  */
  767.             for (;;)
  768.               {
  769.                 if (p == pend)
  770.           {
  771.             compile_error = REG_EBRACK;
  772.             goto error_return;
  773.           }
  774.         
  775.                 PATFETCH (c);
  776.         
  777.                 /* \ might escape characters inside [...] and [^...].  */
  778.                 if ((syntax & RE_BACKSLASH_ESCAPE_IN_LISTS) && c == '\\')
  779.                   {
  780.                     if (p == pend)
  781.               {
  782.             compile_error = REG_EESCAPE;
  783.             goto error_return;
  784.               }
  785.             
  786.                     PATFETCH (c1);
  787.             {
  788.               rx_Bitset it = inverse_translation (cset_size,
  789.                               validate_inv_tr,
  790.                               inverse_translate,
  791.                               translate,
  792.                               c1);
  793.               rx_bitset_union (cset_size, cs, it);
  794.             }
  795.                     continue;
  796.                   }
  797.         
  798.                 /* Could be the end of the bracket expression.  If it's
  799.                    not (i.e., when the bracket expression is `[]' so
  800.                    far), the ']' character bit gets set way below.  */
  801.                 if (c == ']' && p != p1 + 1)
  802.                   goto finalize_class_and_append;
  803.         
  804.                 /* Look ahead to see if it's a range when the last thing
  805.                    was a character class.  */
  806.                 if (had_char_class && c == '-' && *p != ']')
  807.                   {
  808.             compile_error = REG_ERANGE;
  809.             goto error_return;
  810.           }
  811.         
  812.                 /* Look ahead to see if it's a range when the last thing
  813.                    was a character: if this is a hyphen not at the
  814.                    beginning or the end of a list, then it's the range
  815.                    operator.  */
  816.                 if (c == '-' 
  817.                     && !(p - 2 >= pattern && p[-2] == '[') 
  818.                     && !(p - 3 >= pattern && p[-3] == '[' && p[-2] == '^')
  819.                     && *p != ']')
  820.                   {
  821.                     reg_errcode_t ret
  822.                       = compile_range (cset_size, cs, &p, pend, translate, syntax,
  823.                        inverse_translate, validate_inv_tr);
  824.                     if (ret != REG_NOERROR)
  825.               {
  826.             compile_error = ret;
  827.             goto error_return;
  828.               }
  829.                   }
  830.         
  831.                 else if (p[0] == '-' && p[1] != ']')
  832.                   { /* This handles ranges made up of characters only.  */
  833.                     reg_errcode_t ret;
  834.             
  835.             /* Move past the `-'.  */
  836.                     PATFETCH (c1);
  837.                     
  838.                     ret = compile_range (cset_size, cs, &p, pend, translate, syntax,
  839.                      inverse_translate, validate_inv_tr);
  840.                     if (ret != REG_NOERROR)
  841.               {
  842.             compile_error = ret;
  843.             goto error_return;
  844.               }
  845.                   }
  846.         
  847.                 /* See if we're at the beginning of a possible character
  848.                    class.  */
  849.         
  850.         else if ((syntax & RE_CHAR_CLASSES)
  851.              && (c == '[') && (*p == ':'))
  852.                   {
  853.                     char str[CHAR_CLASS_MAX_LENGTH + 1];
  854.             
  855.                     PATFETCH (c);
  856.                     c1 = 0;
  857.             
  858.                     /* If pattern is `[[:'.  */
  859.                     if (p == pend)
  860.               {
  861.             compile_error = REG_EBRACK;
  862.             goto error_return;
  863.               }
  864.             
  865.                     for (;;)
  866.                       {
  867.                         PATFETCH (c);
  868.                         if (c == ':' || c == ']' || p == pend
  869.                             || c1 == CHAR_CLASS_MAX_LENGTH)
  870.               break;
  871.                         str[c1++] = c;
  872.                       }
  873.                     str[c1] = '\0';
  874.             
  875.                     /* If isn't a word bracketed by `[:' and:`]':
  876.                        undo the ending character, the letters, and leave 
  877.                        the leading `:' and `[' (but set bits for them).  */
  878.                     if (c == ':' && *p == ']')
  879.                       {
  880.                         int ch;
  881.                         int is_alnum = !strcmp (str, "alnum");
  882.                         int is_alpha = !strcmp (str, "alpha");
  883.                         int is_blank = !strcmp (str, "blank");
  884.                         int is_cntrl = !strcmp (str, "cntrl");
  885.                         int is_digit = !strcmp (str, "digit");
  886.                         int is_graph = !strcmp (str, "graph");
  887.                         int is_lower = !strcmp (str, "lower");
  888.                         int is_print = !strcmp (str, "print");
  889.                         int is_punct = !strcmp (str, "punct");
  890.                         int is_space = !strcmp (str, "space");
  891.                         int is_upper = !strcmp (str, "upper");
  892.                         int is_xdigit = !strcmp (str, "xdigit");
  893.                         
  894.                         if (!IS_CHAR_CLASS (str))
  895.               {
  896.                 compile_error = REG_ECTYPE;
  897.                 goto error_return;
  898.               }
  899.             
  900.                         /* Throw away the ] at the end of the character
  901.                            class.  */
  902.                         PATFETCH (c);                    
  903.             
  904.                         if (p == pend) { compile_error = REG_EBRACK; goto error_return; }
  905.             
  906.                         for (ch = 0; ch < 1 << CHARBITS; ch++)
  907.                           {
  908.                             if (   (is_alnum  && isalnum (ch))
  909.                                 || (is_alpha  && isalpha (ch))
  910.                                 || (is_blank  && isa_blank (ch))
  911.                                 || (is_cntrl  && iscntrl (ch))
  912.                                 || (is_digit  && isdigit (ch))
  913.                                 || (is_graph  && isgraph (ch))
  914.                                 || (is_lower  && islower (ch))
  915.                                 || (is_print  && isprint (ch))
  916.                                 || (is_punct  && ispunct (ch))
  917.                                 || (is_space  && isspace (ch))
  918.                                 || (is_upper  && isupper (ch))
  919.                                 || (is_xdigit && isxdigit (ch)))
  920.                   {
  921.                 rx_Bitset it =
  922.                   inverse_translation (cset_size,
  923.                                validate_inv_tr,
  924.                                inverse_translate,
  925.                                translate,
  926.                                ch);
  927.                 rx_bitset_union (cset_size,
  928.                          cs, it);
  929.                   }
  930.                           }
  931.                         had_char_class = 1;
  932.                       }
  933.                     else
  934.                       {
  935.                         c1++;
  936.                         while (c1--)    
  937.                           PATUNFETCH;
  938.             {
  939.               rx_Bitset it =
  940.                 inverse_translation (cset_size,
  941.                          validate_inv_tr,
  942.                          inverse_translate,
  943.                          translate,
  944.                          '[');
  945.               rx_bitset_union (cset_size,
  946.                        cs, it);
  947.             }
  948.             {
  949.               rx_Bitset it =
  950.                 inverse_translation (cset_size,
  951.                          validate_inv_tr,
  952.                          inverse_translate,
  953.                          translate,
  954.                          ':');
  955.               rx_bitset_union (cset_size,
  956.                        cs, it);
  957.             }
  958.                         had_char_class = 0;
  959.                       }
  960.                   }
  961.                 else
  962.                   {
  963.                     had_char_class = 0;
  964.             {
  965.               rx_Bitset it = inverse_translation (cset_size,
  966.                               validate_inv_tr,
  967.                               inverse_translate,
  968.                               translate,
  969.                               c);
  970.               rx_bitset_union (cset_size, cs, it);
  971.             }
  972.                   }
  973.               }
  974.  
  975.       finalize_class_and_append:
  976.         if (is_inverted)
  977.           {
  978.         rx_bitset_complement (cset_size, cs);
  979.         if (syntax & RE_HAT_LISTS_NOT_NEWLINE)
  980.           RX_bitset_remove (cs, '\n');
  981.           }
  982.         goto append_node;
  983.           }
  984.           break;
  985.  
  986.  
  987.     case '(':
  988.           if (syntax & RE_NO_BK_PARENS)
  989.             goto handle_open;
  990.           else
  991.             goto normal_char;
  992.  
  993.  
  994.         case ')':
  995.           if (syntax & RE_NO_BK_PARENS)
  996.             goto handle_close;
  997.           else
  998.             goto normal_char;
  999.  
  1000.  
  1001.         case '\n':
  1002.           if (syntax & RE_NEWLINE_ALT)
  1003.             goto handle_alt;
  1004.           else
  1005.             goto normal_char;
  1006.  
  1007.  
  1008.     case '|':
  1009.           if (syntax & RE_NO_BK_VBAR)
  1010.             goto handle_alt;
  1011.           else
  1012.             goto normal_char;
  1013.  
  1014.  
  1015.         case '{':
  1016.       if ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
  1017.         goto handle_interval;
  1018.       else
  1019.         goto normal_char;
  1020.  
  1021.  
  1022.         case '\\':
  1023.           if (p == pend) { compile_error = REG_EESCAPE; goto error_return; }
  1024.  
  1025.           /* Do not translate the character after the \, so that we can
  1026.              distinguish, e.g., \B from \b, even if we normally would
  1027.              translate, e.g., B to b.  */
  1028.           PATFETCH_RAW (c);
  1029.  
  1030.           switch (c)
  1031.             {
  1032.             case '(':
  1033.               if (syntax & RE_NO_BK_PARENS)
  1034.                 goto normal_backslash;
  1035.  
  1036.             handle_open:
  1037.               regnum++;
  1038.               if (COMPILE_STACK_FULL)
  1039.                 { 
  1040.                   compile_stack.stack
  1041.             = ((compile_stack_elt_t *)
  1042.                realloc (compile_stack.stack,
  1043.                 (compile_stack.size << 1) * sizeof (compile_stack_elt_t)));
  1044.           if (compile_stack.stack == 0)
  1045.             goto space_error;
  1046.           compile_stack.size <<= 1;
  1047.         }
  1048.  
  1049.           if (*last_expression)
  1050.         {
  1051.           struct rexp_node * concat;
  1052.           concat = rx_mk_r_binop (r_concat, *last_expression, 0);
  1053.           if (!concat)
  1054.             goto space_error;
  1055.           *last_expression = concat;
  1056.           last_expression = &concat->params.pair.right;
  1057.         }
  1058.  
  1059.               /*
  1060.            * These are the values to restore when we hit end of this
  1061.                * group.  
  1062.            */
  1063.           COMPILE_STACK_TOP.top_expression = top_expression;
  1064.           COMPILE_STACK_TOP.last_expression = last_expression;
  1065.               COMPILE_STACK_TOP.regnum = regnum;
  1066.           
  1067.               compile_stack.avail++;
  1068.           
  1069.           top_expression = last_expression;
  1070.           break;
  1071.  
  1072.  
  1073.             case ')':
  1074.               if (syntax & RE_NO_BK_PARENS) goto normal_backslash;
  1075.  
  1076.             handle_close:
  1077.               /* See similar code for backslashed left paren above.  */
  1078.               if (COMPILE_STACK_EMPTY)
  1079.                 if (syntax & RE_UNMATCHED_RIGHT_PAREN_ORD)
  1080.                   goto normal_char;
  1081.                 else
  1082.                   { compile_error = REG_ERPAREN; goto error_return; }
  1083.  
  1084.               /* Since we just checked for an empty stack above, this
  1085.                * ``can't happen''. 
  1086.            */
  1087.  
  1088.               {
  1089.                 /* We don't just want to restore into `regnum', because
  1090.                  * later groups should continue to be numbered higher,
  1091.                  * as in `(ab)c(de)' -- the second group is #2.
  1092.          */
  1093.                 regnum_t this_group_regnum;
  1094.         struct rexp_node ** inner;
  1095.         struct rexp_node * parens;
  1096.  
  1097.         inner = top_expression;
  1098.                 compile_stack.avail--;
  1099.         top_expression = COMPILE_STACK_TOP.top_expression;
  1100.         last_expression = COMPILE_STACK_TOP.last_expression;
  1101.                 this_group_regnum = COMPILE_STACK_TOP.regnum;
  1102.  
  1103.         parens = rx_mk_r_monop (r_parens, *inner);
  1104.         if (!parens)
  1105.           goto space_error;
  1106.         parens->params.intval = this_group_regnum;
  1107.         *inner = parens;
  1108.         break;
  1109.           }
  1110.  
  1111.             case '|':                    /* `\|'.  */
  1112.               if ((syntax & RE_LIMITED_OPS) || (syntax & RE_NO_BK_VBAR))
  1113.                 goto normal_backslash;
  1114.             handle_alt:
  1115.               if (syntax & RE_LIMITED_OPS)
  1116.                 goto normal_char;
  1117.  
  1118.           {
  1119.         struct rexp_node * alt;
  1120.  
  1121.         alt = rx_mk_r_binop (r_alternate, *top_expression, 0);
  1122.         if (!alt)
  1123.           goto space_error;
  1124.         *top_expression = alt;
  1125.         last_expression = &alt->params.pair.right;
  1126.           }
  1127.               break;
  1128.  
  1129.  
  1130.             case '{': 
  1131.               /* If \{ is a literal.  */
  1132.               if (!(syntax & RE_INTERVALS)
  1133.                      /* If we're at `\{' and it's not the open-interval 
  1134.                         operator.  */
  1135.                   || ((syntax & RE_INTERVALS) && (syntax & RE_NO_BK_BRACES))
  1136.                   || (p - 2 == pattern  &&  p == pend))
  1137.                 goto normal_backslash;
  1138.  
  1139.             handle_interval:
  1140.               {
  1141.                 /* If got here, then the syntax allows intervals. 
  1142.          */
  1143.  
  1144.                 /* At least (most) this many matches must be made.  
  1145.          */
  1146.                 int lower_bound;
  1147.         int upper_bound;
  1148.  
  1149.         lower_bound = -1;
  1150.         upper_bound = -1;
  1151.  
  1152.         /* We're about to parse the bounds of the interval.
  1153.          * It may turn out that this isn't an interval after
  1154.          * all, in which case these same characters will have
  1155.          * to be reparsed as literals.   This remembers
  1156.          * the backtrack point in the parse:
  1157.          */
  1158.                 beg_interval = p - 1;
  1159.  
  1160.                 if (p == pend)
  1161.                   {
  1162.                     if (syntax & RE_NO_BK_BRACES)
  1163.                       goto unfetch_interval;
  1164.                     else
  1165.                       { compile_error = REG_EBRACE; goto error_return; }
  1166.                   }
  1167.  
  1168.                 GET_UNSIGNED_NUMBER (lower_bound);
  1169.  
  1170.                 if (c == ',')
  1171.                   {
  1172.                     GET_UNSIGNED_NUMBER (upper_bound);
  1173.                     if (upper_bound < 0) upper_bound = RE_DUP_MAX;
  1174.                   }
  1175.                 else
  1176.                   /* Interval such as `{n}' => match exactly n times.
  1177.            */
  1178.                   upper_bound = lower_bound;
  1179.  
  1180.                 if (lower_bound < 0
  1181.             || upper_bound > RE_DUP_MAX
  1182.                     || lower_bound > upper_bound)
  1183.                   {
  1184.                     if (syntax & RE_NO_BK_BRACES)
  1185.                       goto unfetch_interval;
  1186.                     else 
  1187.                       { compile_error = REG_BADBR; goto error_return; }
  1188.                   }
  1189.  
  1190.                 if (!(syntax & RE_NO_BK_BRACES)) 
  1191.                   {
  1192.                     if (c != '\\') { compile_error = REG_EBRACE; goto error_return; }
  1193.                     PATFETCH (c);
  1194.                   }
  1195.  
  1196.                 if (c != '}')
  1197.                   {
  1198.                     if (syntax & RE_NO_BK_BRACES)
  1199.                       goto unfetch_interval;
  1200.                     else 
  1201.                       { compile_error = REG_BADBR; goto error_return; }
  1202.                   }
  1203.  
  1204.                 /* We just parsed a valid interval.
  1205.          * lower_bound and upper_bound are set.
  1206.          */
  1207.  
  1208.                 /* If it's invalid to have no preceding re.
  1209.          */
  1210.                 if (pointless_if_repeated (*last_expression))
  1211.                   {
  1212.                     if (syntax & RE_CONTEXT_INVALID_OPS)
  1213.                       { compile_error = REG_BADRPT; goto error_return; }
  1214.                     else if (!(syntax & RE_CONTEXT_INDEP_OPS))
  1215.               /* treat the interval spec as literal chars. */
  1216.                       goto unfetch_interval; 
  1217.                   }
  1218.  
  1219.         {
  1220.           struct rexp_node * interval;
  1221.  
  1222.           interval = rx_mk_r_monop (r_interval, *last_expression);
  1223.           if (!interval)
  1224.             goto space_error;
  1225.           interval->params.intval = lower_bound;
  1226.           interval->params.intval2 = upper_bound;
  1227.           *last_expression = interval;
  1228.         }
  1229.                 beg_interval = 0;
  1230.               }
  1231.               break;
  1232.  
  1233.             unfetch_interval:
  1234.               /* If an invalid interval, match the characters as literals.  */
  1235.                p = beg_interval;
  1236.                beg_interval = 0;
  1237.  
  1238.                /* normal_char and normal_backslash need `c'.  */
  1239.                PATFETCH (c);    
  1240.  
  1241.                if (!(syntax & RE_NO_BK_BRACES))
  1242.                  {
  1243.                    if ((p > pattern)  &&  (p[-1] == '\\'))
  1244.                      goto normal_backslash;
  1245.                  }
  1246.                goto normal_char;
  1247.  
  1248. #ifdef emacs
  1249.             /* There is no way to specify the before_dot and after_dot
  1250.              * operators.  rms says this is ok.  --karl
  1251.          */
  1252.             case '=':
  1253.           side = '=';
  1254.           goto add_side_effect;
  1255.               break;
  1256.  
  1257.             case 's':
  1258.         case 'S':
  1259.           {
  1260.         rx_Bitset cs;
  1261.         struct rexp_node * set;
  1262.  
  1263.         cs = rx_cset (&cset_size);
  1264.         if (!cs)
  1265.           goto space_error;
  1266.         set = rx_mk_r_cset (r_cset, cset_size, cs);
  1267.         if (!set)
  1268.           {
  1269.             rx_free_cset (cs);
  1270.             goto space_error;
  1271.           }
  1272.         if (c == 'S')
  1273.           rx_bitset_universe (cset_size, cs);
  1274.  
  1275.         PATFETCH (c);
  1276.         {
  1277.           int x;
  1278.           enum syntaxcode code = syntax_spec_code [c];
  1279.           for (x = 0; x < 256; ++x)
  1280.             {
  1281.               
  1282.               if (SYNTAX (x) == code)
  1283.             {
  1284.               rx_Bitset it =
  1285.                 inverse_translation (cset_size, validate_inv_tr,
  1286.                          inverse_translate,
  1287.                          translate, x);
  1288.               rx_bitset_xor (cset_size, cs, it);
  1289.             }
  1290.             }
  1291.         }
  1292.         append = set;
  1293.         goto append_node;
  1294.           }
  1295.               break;
  1296. #endif /* emacs */
  1297.  
  1298.  
  1299.             case 'w':
  1300.             case 'W':
  1301.           {
  1302.         rx_Bitset cs;
  1303.         struct rexp_node * n;
  1304.  
  1305.         cs = rx_cset (cset_size);
  1306.         n = (cs ? rx_mk_r_cset (r_cset, cset_size, cs) : 0);
  1307.         if (!(cs && n))
  1308.           {
  1309.             if (cs)
  1310.               rx_free_cset (cs);
  1311.             goto space_error;
  1312.           }
  1313.         if (c == 'W')
  1314.           rx_bitset_universe (cset_size ,cs);
  1315.         {
  1316.           int x;
  1317.           for (x = cset_size - 1; x > 0; --x)
  1318.             if (SYNTAX(x) & Sword)
  1319.               RX_bitset_toggle (cs, x);
  1320.         }
  1321.         append = n;
  1322.         goto append_node;
  1323.           }
  1324.               break;
  1325.  
  1326.             case '<':
  1327.           side = '<';
  1328.           goto add_side_effect;
  1329.               break;
  1330.  
  1331.             case '>':
  1332.               side = '>';
  1333.           goto add_side_effect;
  1334.               break;
  1335.  
  1336.             case 'b':
  1337.               side = 'b';
  1338.           goto add_side_effect;
  1339.               break;
  1340.  
  1341.             case 'B':
  1342.               side = 'B';
  1343.           goto add_side_effect;
  1344.               break;
  1345.  
  1346.             case '`':
  1347.           side = '`';
  1348.           goto add_side_effect;
  1349.           break;
  1350.           
  1351.             case '\'':
  1352.           side = '\'';
  1353.           goto add_side_effect;
  1354.               break;
  1355.  
  1356.         add_side_effect:
  1357.           {
  1358.         struct rexp_node * se;
  1359.         se = rx_mk_r_int (r_context, side);
  1360.         if (!se)
  1361.           goto space_error;
  1362.         append = se;
  1363.         goto append_node;
  1364.           }
  1365.           break;
  1366.  
  1367.             case '1': case '2': case '3': case '4': case '5':
  1368.             case '6': case '7': case '8': case '9':
  1369.               if (syntax & RE_NO_BK_REFS)
  1370.                 goto normal_char;
  1371.  
  1372.               c1 = c - '0';
  1373.  
  1374.               if (c1 > regnum)
  1375.                 { compile_error = REG_ESUBREG; goto error_return; }
  1376.  
  1377.           side = c;
  1378.           goto add_side_effect;
  1379.               break;
  1380.  
  1381.             case '+':
  1382.             case '?':
  1383.               if (syntax & RE_BK_PLUS_QM)
  1384.                 goto handle_plus;
  1385.               else
  1386.                 goto normal_backslash;
  1387.  
  1388.             default:
  1389.             normal_backslash:
  1390.               /* You might think it would be useful for \ to mean
  1391.                * not to translate; but if we don't translate it
  1392.                * it will never match anything.
  1393.            */
  1394.               c = TRANSLATE (c);
  1395.               goto normal_char;
  1396.             }
  1397.           break;
  1398.  
  1399.  
  1400.     default:
  1401.         /* Expects the character in `c'.  */
  1402.     normal_char:
  1403.         {
  1404.           rx_Bitset cs;
  1405.           struct rexp_node * match;
  1406.           rx_Bitset it;
  1407.  
  1408.           cs = rx_cset (cset_size);
  1409.           match = (cs ? rx_mk_r_cset (r_cset, cset_size, cs) : 0);
  1410.           if (!(cs && match))
  1411.         {
  1412.           if (cs)
  1413.             rx_free_cset (cs);
  1414.           goto space_error;
  1415.         }
  1416.           it = inverse_translation (cset_size, validate_inv_tr,
  1417.                     inverse_translate, translate, c);
  1418.           rx_bitset_union (CHAR_SET_SIZE, cs, it);
  1419.           append = match;
  1420.  
  1421.         append_node:
  1422.           /* This genericly appends the rexp APPEND to *LAST_EXPRESSION
  1423.            * and then parses the next character normally.
  1424.            */
  1425.           if (*last_expression)
  1426.         {
  1427.           struct rexp_node * concat;
  1428.           concat = rx_mk_r_binop (r_concat,
  1429.                       *last_expression, append);
  1430.           if (!concat)
  1431.             goto space_error;
  1432.           *last_expression = concat;
  1433.           last_expression = &concat->params.pair.right;
  1434.         }
  1435.           else
  1436.         *last_expression = append;
  1437.         }
  1438.     } /* switch (c) */
  1439.     } /* while p != pend */
  1440.  
  1441.   
  1442.   /* Through the pattern now.  */
  1443.  
  1444.   if (!COMPILE_STACK_EMPTY) 
  1445.     { compile_error = REG_EPAREN; goto error_return; }
  1446.   free (compile_stack.stack);
  1447.  
  1448.  
  1449.   *rexp_p = rexp;
  1450.   return REG_NOERROR;
  1451.  
  1452.  space_error:
  1453.   compile_error = REG_ESPACE;
  1454.  
  1455.  error_return:
  1456.   free (compile_stack.stack);
  1457.   /* Free expressions pushed onto the compile stack! */
  1458.   if (rexp)
  1459.     rx_free_rexp (rexp);
  1460.   return compile_error;
  1461. }
  1462.  
  1463.  
  1464.