home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume24 / gnudiff1.15 / part06 / regex.c2
Text File  |  1991-03-05  |  38KB  |  1,267 lines

  1.  
  2.  
  3.  
  4. /* Like re_search_2, below, but only one string is specified, and
  5.    doesn't let you say where to stop matching. */
  6.  
  7. int
  8. re_search (pbufp, string, size, startpos, range, regs)
  9.      struct re_pattern_buffer *pbufp;
  10.      char *string;
  11.      int size, startpos, range;
  12.      struct re_registers *regs;
  13. {
  14.   return re_search_2 (pbufp, (char *) 0, 0, string, size, startpos, range, 
  15.               regs, size);
  16. }
  17.  
  18.  
  19. /* Using the compiled pattern in PBUFP->buffer, first tries to match the
  20.    virtual concatenation of STRING1 and STRING2, starting first at index
  21.    STARTPOS, then at STARTPOS + 1, and so on.  RANGE is the number of
  22.    places to try before giving up.  If RANGE is negative, it searches
  23.    backwards, i.e., the starting positions tried are STARTPOS, STARTPOS
  24.    - 1, etc.  STRING1 and STRING2 are of SIZE1 and SIZE2, respectively.
  25.    In REGS, return the indices of the virtual concatenation of STRING1
  26.    and STRING2 that matched the entire PBUFP->buffer and its contained
  27.    subexpressions.  Do not consider matching one past the index MSTOP in
  28.    the virtual concatenation of STRING1 and STRING2.
  29.  
  30.    The value returned is the position in the strings at which the match
  31.    was found, or -1 if no match was found, or -2 if error (such as
  32.    failure stack overflow).  */
  33.  
  34. int
  35. re_search_2 (pbufp, string1, size1, string2, size2, startpos, range,
  36.          regs, mstop)
  37.      struct re_pattern_buffer *pbufp;
  38.      char *string1, *string2;
  39.      int size1, size2;
  40.      int startpos;
  41.      register int range;
  42.      struct re_registers *regs;
  43.      int mstop;
  44. {
  45.   register char *fastmap = pbufp->fastmap;
  46.   register unsigned char *translate = (unsigned char *) pbufp->translate;
  47.   int total_size = size1 + size2;
  48.   int endpos = startpos + range;
  49.   int val;
  50.  
  51.   /* Check for out-of-range starting position.  */
  52.   if (startpos < 0  ||  startpos > total_size)
  53.     return -1;
  54.     
  55.   /* Fix up range if it would eventually take startpos outside of the
  56.      virtual concatenation of string1 and string2.  */
  57.   if (endpos < -1)
  58.     range = -1 - startpos;
  59.   else if (endpos > total_size)
  60.     range = total_size - startpos;
  61.  
  62.   /* Update the fastmap now if not correct already.  */
  63.   if (fastmap && !pbufp->fastmap_accurate)
  64.     re_compile_fastmap (pbufp);
  65.   
  66.   /* If the search isn't to be a backwards one, don't waste time in a
  67.      long search for a pattern that says it is anchored.  */
  68.   if (pbufp->used > 0 && (enum regexpcode) pbufp->buffer[0] == begbuf
  69.       && range > 0)
  70.     {
  71.       if (startpos > 0)
  72.     return -1;
  73.       else
  74.     range = 1;
  75.     }
  76.  
  77.   while (1)
  78.     { 
  79.       /* If a fastmap is supplied, skip quickly over characters that
  80.          cannot possibly be the start of a match.  Note, however, that
  81.          if the pattern can possibly match the null string, we must
  82.          test it at each starting point so that we take the first null
  83.          string we get.  */
  84.  
  85.       if (fastmap && startpos < total_size && pbufp->can_be_null != 1)
  86.     {
  87.       if (range > 0)    /* Searching forwards.  */
  88.         {
  89.           register int lim = 0;
  90.           register unsigned char *p;
  91.           int irange = range;
  92.           if (startpos < size1 && startpos + range >= size1)
  93.         lim = range - (size1 - startpos);
  94.  
  95.           p = ((unsigned char *)
  96.            &(startpos >= size1 ? string2 - size1 : string1)[startpos]);
  97.  
  98.               while (range > lim && !fastmap[translate 
  99.                                              ? translate[*p++]
  100.                                              : *p++])
  101.             range--;
  102.           startpos += irange - range;
  103.         }
  104.       else                /* Searching backwards.  */
  105.         {
  106.           register unsigned char c;
  107.  
  108.               if (string1 == 0 || startpos >= size1)
  109.         c = string2[startpos - size1];
  110.           else 
  111.         c = string1[startpos];
  112.  
  113.               c &= 0xff;
  114.           if (translate ? !fastmap[translate[c]] : !fastmap[c])
  115.         goto advance;
  116.         }
  117.     }
  118.  
  119.       if (range >= 0 && startpos == total_size
  120.       && fastmap && pbufp->can_be_null == 0)
  121.     return -1;
  122.  
  123.       val = re_match_2 (pbufp, string1, size1, string2, size2, startpos,
  124.             regs, mstop);
  125.       if (val >= 0)
  126.     return startpos;
  127.       if (val == -2)
  128.     return -2;
  129.  
  130. #ifdef C_ALLOCA
  131.       alloca (0);
  132. #endif /* C_ALLOCA */
  133.  
  134.     advance:
  135.       if (!range) 
  136.         break;
  137.       else if (range > 0) 
  138.         {
  139.           range--; 
  140.           startpos++;
  141.         }
  142.       else
  143.         {
  144.           range++; 
  145.           startpos--;
  146.         }
  147.     }
  148.   return -1;
  149. }
  150.  
  151.  
  152.  
  153. #ifndef emacs   /* emacs never uses this.  */
  154. int
  155. re_match (pbufp, string, size, pos, regs)
  156.      struct re_pattern_buffer *pbufp;
  157.      char *string;
  158.      int size, pos;
  159.      struct re_registers *regs;
  160. {
  161.   return re_match_2 (pbufp, (char *) 0, 0, string, size, pos, regs, size); 
  162. }
  163. #endif /* not emacs */
  164.  
  165.  
  166. /* The following are used for re_match_2, defined below:  */
  167.  
  168. /* Roughly the maximum number of failure points on the stack.  Would be
  169.    exactly that if always pushed MAX_NUM_FAILURE_ITEMS each time we failed.  */
  170.    
  171. int re_max_failures = 2000;
  172.  
  173. /* Routine used by re_match_2.  */
  174. static int bcmp_translate ();
  175.  
  176.  
  177. /* Structure and accessing macros used in re_match_2:  */
  178.  
  179. struct register_info
  180. {
  181.   unsigned is_active : 1;
  182.   unsigned matched_something : 1;
  183. };
  184.  
  185. #define IS_ACTIVE(R)  ((R).is_active)
  186. #define MATCHED_SOMETHING(R)  ((R).matched_something)
  187.  
  188.  
  189. /* Macros used by re_match_2:  */
  190.  
  191.  
  192. /* I.e., regstart, regend, and reg_info.  */
  193.  
  194. #define NUM_REG_ITEMS  3
  195.  
  196. /* We push at most this many things on the stack whenever we
  197.    fail.  The `+ 2' refers to PATTERN_PLACE and STRING_PLACE, which are
  198.    arguments to the PUSH_FAILURE_POINT macro.  */
  199.  
  200. #define MAX_NUM_FAILURE_ITEMS   (RE_NREGS * NUM_REG_ITEMS + 2)
  201.  
  202.  
  203. /* We push this many things on the stack whenever we fail.  */
  204.  
  205. #define NUM_FAILURE_ITEMS  (last_used_reg * NUM_REG_ITEMS + 2)
  206.  
  207.  
  208. /* This pushes most of the information about the current state we will want
  209.    if we ever fail back to it.  */
  210.  
  211. #define PUSH_FAILURE_POINT(pattern_place, string_place)            \
  212.   {                                    \
  213.     short last_used_reg, this_reg;                    \
  214.                                     \
  215.     /* Find out how many registers are active or have been matched.    \
  216.        (Aside from register zero, which is only set at the end.)  */    \
  217.     for (last_used_reg = RE_NREGS - 1; last_used_reg > 0; last_used_reg--)\
  218.       if (regstart[last_used_reg] != (unsigned char *) -1)        \
  219.         break;                                \
  220.                                     \
  221.     if (stacke - stackp < NUM_FAILURE_ITEMS)                \
  222.       {                                    \
  223.     unsigned char **stackx;                        \
  224.     if (stacke - stackb > re_max_failures * MAX_NUM_FAILURE_ITEMS)    \
  225.       return -2;                            \
  226.                                     \
  227.         /* Roughly double the size of the stack.  */            \
  228.         stackx = (unsigned char **) alloca (2 * MAX_NUM_FAILURE_ITEMS    \
  229.                             * (stacke - stackb)        \
  230.                                             * sizeof (unsigned char *));\
  231.     /* Only copy what is in use.  */                \
  232.         bcopy (stackb, stackx, (stackp - stackb) * sizeof (char *));    \
  233.     stackp = stackx + (stackp - stackb);                \
  234.     stackb = stackx;                        \
  235.     stacke = stackb + 2 * MAX_NUM_FAILURE_ITEMS * (stacke - stackb);\
  236.       }                                    \
  237.                                     \
  238.     /* Now push the info for each of those registers.  */        \
  239.     for (this_reg = 1; this_reg <= last_used_reg; this_reg++)        \
  240.       {                                    \
  241.         *stackp++ = regstart[this_reg];                    \
  242.         *stackp++ = regend[this_reg];                    \
  243.         *stackp++ = (unsigned char *) ®_info[this_reg];        \
  244.       }                                    \
  245.                                     \
  246.     /* Push how many registers we saved.  */                \
  247.     *stackp++ = (unsigned char *) last_used_reg;            \
  248.                                     \
  249.     *stackp++ = pattern_place;                                          \
  250.     *stackp++ = string_place;                                           \
  251.   }
  252.   
  253.  
  254. /* This pops what PUSH_FAILURE_POINT pushes.  */
  255.  
  256. #define POP_FAILURE_POINT()                        \
  257.   {                                    \
  258.     int temp;                                \
  259.     stackp -= 2;        /* Remove failure points.  */        \
  260.     temp = (int) *--stackp;    /* How many regs pushed.  */            \
  261.     temp *= NUM_REG_ITEMS;    /* How much to take off the stack.  */    \
  262.     stackp -= temp;         /* Remove the register info.  */    \
  263.   }
  264.  
  265.  
  266. #define MATCHING_IN_FIRST_STRING  (dend == end_match_1)
  267.  
  268. /* Is true if there is a first string and if PTR is pointing anywhere
  269.    inside it or just past the end.  */
  270.    
  271. #define IS_IN_FIRST_STRING(ptr)                     \
  272.     (size1 && string1 <= (ptr) && (ptr) <= string1 + size1)
  273.  
  274. /* Call before fetching a character with *d.  This switches over to
  275.    string2 if necessary.  */
  276.  
  277. #define PREFETCH                            \
  278.  while (d == dend)                                \
  279.   {                                    \
  280.     /* end of string2 => fail.  */                    \
  281.     if (dend == end_match_2)                         \
  282.       goto fail;                            \
  283.     /* end of string1 => advance to string2.  */             \
  284.     d = string2;                                \
  285.     dend = end_match_2;                            \
  286.   }
  287.  
  288.  
  289. /* Call this when have matched something; it sets `matched' flags for the
  290.    registers corresponding to the subexpressions of which we currently
  291.    are inside.  */
  292. #define SET_REGS_MATCHED                         \
  293.   { unsigned this_reg;                             \
  294.     for (this_reg = 0; this_reg < RE_NREGS; this_reg++)         \
  295.       {                                 \
  296.         if (IS_ACTIVE(reg_info[this_reg]))                \
  297.           MATCHED_SOMETHING(reg_info[this_reg]) = 1;            \
  298.         else                                \
  299.           MATCHED_SOMETHING(reg_info[this_reg]) = 0;            \
  300.       }                                 \
  301.   }
  302.  
  303. /* Test if at very beginning or at very end of the virtual concatenation
  304.    of string1 and string2.  If there is only one string, we've put it in
  305.    string2.  */
  306.  
  307. #define AT_STRINGS_BEG  (d == (size1 ? string1 : string2)  ||  !size2)
  308. #define AT_STRINGS_END  (d == end2)    
  309.  
  310. #define AT_WORD_BOUNDARY                        \
  311.   (AT_STRINGS_BEG || AT_STRINGS_END || IS_A_LETTER (d - 1) != IS_A_LETTER (d))
  312.  
  313. /* We have two special cases to check for: 
  314.      1) if we're past the end of string1, we have to look at the first
  315.         character in string2;
  316.      2) if we're before the beginning of string2, we have to look at the
  317.         last character in string1; we assume there is a string1, so use
  318.         this in conjunction with AT_STRINGS_BEG.  */
  319. #define IS_A_LETTER(d)                            \
  320.   (SYNTAX ((d) == end1 ? *string2 : (d) == string2 - 1 ? *(end1 - 1) : *(d))\
  321.    == Sword)
  322.  
  323.  
  324. /* Match the pattern described by PBUFP against the virtual
  325.    concatenation of STRING1 and STRING2, which are of SIZE1 and SIZE2,
  326.    respectively.  Start the match at index POS in the virtual
  327.    concatenation of STRING1 and STRING2.  In REGS, return the indices of
  328.    the virtual concatenation of STRING1 and STRING2 that matched the
  329.    entire PBUFP->buffer and its contained subexpressions.  Do not
  330.    consider matching one past the index MSTOP in the virtual
  331.    concatenation of STRING1 and STRING2.
  332.  
  333.    If pbufp->fastmap is nonzero, then it had better be up to date.
  334.  
  335.    The reason that the data to match are specified as two components
  336.    which are to be regarded as concatenated is so this function can be
  337.    used directly on the contents of an Emacs buffer.
  338.  
  339.    -1 is returned if there is no match.  -2 is returned if there is an
  340.    error (such as match stack overflow).  Otherwise the value is the
  341.    length of the substring which was matched.  */
  342.  
  343. int
  344. re_match_2 (pbufp, string1_arg, size1, string2_arg, size2, pos, regs, mstop)
  345.      struct re_pattern_buffer *pbufp;
  346.      char *string1_arg, *string2_arg;
  347.      int size1, size2;
  348.      int pos;
  349.      struct re_registers *regs;
  350.      int mstop;
  351. {
  352.   register unsigned char *p = (unsigned char *) pbufp->buffer;
  353.  
  354.   /* Pointer to beyond end of buffer.  */
  355.   register unsigned char *pend = p + pbufp->used;
  356.  
  357.   unsigned char *string1 = (unsigned char *) string1_arg;
  358.   unsigned char *string2 = (unsigned char *) string2_arg;
  359.   unsigned char *end1;        /* Just past end of first string.  */
  360.   unsigned char *end2;        /* Just past end of second string.  */
  361.  
  362.   /* Pointers into string1 and string2, just past the last characters in
  363.      each to consider matching.  */
  364.   unsigned char *end_match_1, *end_match_2;
  365.  
  366.   register unsigned char *d, *dend;
  367.   register int mcnt;            /* Multipurpose.  */
  368.   unsigned char *translate = (unsigned char *) pbufp->translate;
  369.   unsigned is_a_jump_n = 0;
  370.  
  371.  /* Failure point stack.  Each place that can handle a failure further
  372.     down the line pushes a failure point on this stack.  It consists of
  373.     restart, regend, and reg_info for all registers corresponding to the
  374.     subexpressions we're currently inside, plus the number of such
  375.     registers, and, finally, two char *'s.  The first char * is where to
  376.     resume scanning the pattern; the second one is where to resume
  377.     scanning the strings.  If the latter is zero, the failure point is a
  378.     ``dummy''; if a failure happens and the failure point is a dummy, it
  379.     gets discarded and the next next one is tried.  */
  380.  
  381.   unsigned char *initial_stack[MAX_NUM_FAILURE_ITEMS * NFAILURES];
  382.   unsigned char **stackb = initial_stack;
  383.   unsigned char **stackp = stackb;
  384.   unsigned char **stacke = &stackb[MAX_NUM_FAILURE_ITEMS * NFAILURES];
  385.  
  386.  
  387.   /* Information on the contents of registers. These are pointers into
  388.      the input strings; they record just what was matched (on this
  389.      attempt) by a subexpression part of the pattern, that is, the
  390.      regnum-th regstart pointer points to where in the pattern we began
  391.      matching and the regnum-th regend points to right after where we
  392.      stopped matching the regnum-th subexpression.  (The zeroth register
  393.      keeps track of what the whole pattern matches.)  */
  394.      
  395.   unsigned char *regstart[RE_NREGS];
  396.   unsigned char *regend[RE_NREGS];
  397.  
  398.   /* The is_active field of reg_info helps us keep track of which (possibly
  399.      nested) subexpressions we are currently in. The matched_something
  400.      field of reg_info[reg_num] helps us tell whether or not we have
  401.      matched any of the pattern so far this time through the reg_num-th
  402.      subexpression.  These two fields get reset each time through any
  403.      loop their register is in.  */
  404.  
  405.   struct register_info reg_info[RE_NREGS];
  406.  
  407.  
  408.   /* The following record the register info as found in the above
  409.      variables when we find a match better than any we've seen before. 
  410.      This happens as we backtrack through the failure points, which in
  411.      turn happens only if we have not yet matched the entire string.  */
  412.  
  413.   unsigned best_regs_set = 0;
  414.   unsigned char *best_regstart[RE_NREGS];
  415.   unsigned char *best_regend[RE_NREGS];
  416.  
  417.  
  418.   /* Initialize subexpression text positions to -1 to mark ones that no
  419.      \( or ( and \) or ) has been seen for. Also set all registers to
  420.      inactive and mark them as not having matched anything or ever
  421.      failed.  */
  422.   for (mcnt = 0; mcnt < RE_NREGS; mcnt++)
  423.     {
  424.       regstart[mcnt] = regend[mcnt] = (unsigned char *) -1;
  425.       IS_ACTIVE (reg_info[mcnt]) = 0;
  426.       MATCHED_SOMETHING (reg_info[mcnt]) = 0;
  427.     }
  428.   
  429.   if (regs)
  430.     for (mcnt = 0; mcnt < RE_NREGS; mcnt++)
  431.       regs->start[mcnt] = regs->end[mcnt] = -1;
  432.  
  433.   /* Set up pointers to ends of strings.
  434.      Don't allow the second string to be empty unless both are empty.  */
  435.   if (size2 == 0)
  436.     {
  437.       string2 = string1;
  438.       size2 = size1;
  439.       string1 = 0;
  440.       size1 = 0;
  441.     }
  442.   end1 = string1 + size1;
  443.   end2 = string2 + size2;
  444.  
  445.   /* Compute where to stop matching, within the two strings.  */
  446.   if (mstop <= size1)
  447.     {
  448.       end_match_1 = string1 + mstop;
  449.       end_match_2 = string2;
  450.     }
  451.   else
  452.     {
  453.       end_match_1 = end1;
  454.       end_match_2 = string2 + mstop - size1;
  455.     }
  456.  
  457.   /* `p' scans through the pattern as `d' scans through the data. `dend'
  458.      is the end of the input string that `d' points within. `d' is
  459.      advanced into the following input string whenever necessary, but
  460.      this happens before fetching; therefore, at the beginning of the
  461.      loop, `d' can be pointing at the end of a string, but it cannot
  462.      equal string2.  */
  463.  
  464.   if (size1 != 0 && pos <= size1)
  465.     d = string1 + pos, dend = end_match_1;
  466.   else
  467.     d = string2 + pos - size1, dend = end_match_2;
  468.  
  469.  
  470.   /* This loops over pattern commands.  It exits by returning from the
  471.      function if match is complete, or it drops through if match fails
  472.      at this starting point in the input data.  */
  473.  
  474.   while (1)
  475.     {
  476.       is_a_jump_n = 0;
  477.       /* End of pattern means we might have succeeded.  */
  478.       if (p == pend)
  479.     {
  480.       /* If not end of string, try backtracking.  Otherwise done.  */
  481.           if (d != end_match_2)
  482.         {
  483.               if (stackp != stackb)
  484.                 {
  485.                   /* More failure points to try.  */
  486.  
  487.                   unsigned in_same_string = 
  488.                           IS_IN_FIRST_STRING (best_regend[0]) 
  489.                         == MATCHING_IN_FIRST_STRING;
  490.  
  491.                   /* If exceeds best match so far, save it.  */
  492.                   if (! best_regs_set
  493.                       || (in_same_string && d > best_regend[0])
  494.                       || (! in_same_string && ! MATCHING_IN_FIRST_STRING))
  495.                     {
  496.                       best_regs_set = 1;
  497.                       best_regend[0] = d;    /* Never use regstart[0].  */
  498.                       
  499.                       for (mcnt = 1; mcnt < RE_NREGS; mcnt++)
  500.                         {
  501.                           best_regstart[mcnt] = regstart[mcnt];
  502.                           best_regend[mcnt] = regend[mcnt];
  503.                         }
  504.                     }
  505.                   goto fail;           
  506.                 }
  507.               /* If no failure points, don't restore garbage.  */
  508.               else if (best_regs_set)   
  509.                 {
  510.           restore_best_regs:
  511.                   /* Restore best match.  */
  512.                   d = best_regend[0];
  513.                   
  514.           for (mcnt = 0; mcnt < RE_NREGS; mcnt++)
  515.             {
  516.               regstart[mcnt] = best_regstart[mcnt];
  517.               regend[mcnt] = best_regend[mcnt];
  518.             }
  519.                 }
  520.             }
  521.  
  522.       /* If caller wants register contents data back, convert it 
  523.          to indices.  */
  524.       if (regs)
  525.         {
  526.           regs->start[0] = pos;
  527.           if (MATCHING_IN_FIRST_STRING)
  528.         regs->end[0] = d - string1;
  529.           else
  530.         regs->end[0] = d - string2 + size1;
  531.           for (mcnt = 1; mcnt < RE_NREGS; mcnt++)
  532.         {
  533.           if (regend[mcnt] == (unsigned char *) -1)
  534.             {
  535.               regs->start[mcnt] = -1;
  536.               regs->end[mcnt] = -1;
  537.               continue;
  538.             }
  539.           if (IS_IN_FIRST_STRING (regstart[mcnt]))
  540.             regs->start[mcnt] = regstart[mcnt] - string1;
  541.           else
  542.             regs->start[mcnt] = regstart[mcnt] - string2 + size1;
  543.                     
  544.           if (IS_IN_FIRST_STRING (regend[mcnt]))
  545.             regs->end[mcnt] = regend[mcnt] - string1;
  546.           else
  547.             regs->end[mcnt] = regend[mcnt] - string2 + size1;
  548.         }
  549.         }
  550.       return d - pos - (MATCHING_IN_FIRST_STRING 
  551.                 ? string1 
  552.                 : string2 - size1);
  553.         }
  554.  
  555.       /* Otherwise match next pattern command.  */
  556. #ifdef SWITCH_ENUM_BUG
  557.       switch ((int) ((enum regexpcode) *p++))
  558. #else
  559.       switch ((enum regexpcode) *p++)
  560. #endif
  561.     {
  562.  
  563.     /* \( [or `(', as appropriate] is represented by start_memory,
  564.            \) by stop_memory.  Both of those commands are followed by
  565.            a register number in the next byte.  The text matched
  566.            within the \( and \) is recorded under that number.  */
  567.     case start_memory:
  568.           regstart[*p] = d;
  569.           IS_ACTIVE (reg_info[*p]) = 1;
  570.           MATCHED_SOMETHING (reg_info[*p]) = 0;
  571.           p++;
  572.           break;
  573.  
  574.     case stop_memory:
  575.           regend[*p] = d;
  576.           IS_ACTIVE (reg_info[*p]) = 0;
  577.  
  578.           /* If just failed to match something this time around with a sub-
  579.          expression that's in a loop, try to force exit from the loop.  */
  580.           if ((! MATCHED_SOMETHING (reg_info[*p])
  581.            || (enum regexpcode) p[-3] == start_memory)
  582.           && (p + 1) != pend)              
  583.             {
  584.           register unsigned char *p2 = p + 1;
  585.               mcnt = 0;
  586.               switch (*p2++)
  587.                 {
  588.                   case jump_n:
  589.             is_a_jump_n = 1;
  590.                   case finalize_jump:
  591.           case maybe_finalize_jump:
  592.           case jump:
  593.           case dummy_failure_jump:
  594.                     EXTRACT_NUMBER_AND_INCR (mcnt, p2);
  595.             if (is_a_jump_n)
  596.               p2 += 2;
  597.                     break;
  598.                 }
  599.           p2 += mcnt;
  600.         
  601.               /* If the next operation is a jump backwards in the pattern
  602.              to an on_failure_jump, exit from the loop by forcing a
  603.                  failure after pushing on the stack the on_failure_jump's 
  604.                  jump in the pattern, and d.  */
  605.           if (mcnt < 0 && (enum regexpcode) *p2++ == on_failure_jump)
  606.         {
  607.                   EXTRACT_NUMBER_AND_INCR (mcnt, p2);
  608.                   PUSH_FAILURE_POINT (p2 + mcnt, d);
  609.                   goto fail;
  610.                 }
  611.             }
  612.           p++;
  613.           break;
  614.  
  615.     /* \<digit> has been turned into a `duplicate' command which is
  616.            followed by the numeric value of <digit> as the register number.  */
  617.         case duplicate:
  618.       {
  619.         int regno = *p++;   /* Get which register to match against */
  620.         register unsigned char *d2, *dend2;
  621.  
  622.         /* Where in input to try to start matching.  */
  623.             d2 = regstart[regno];
  624.             
  625.             /* Where to stop matching; if both the place to start and
  626.                the place to stop matching are in the same string, then
  627.                set to the place to stop, otherwise, for now have to use
  628.                the end of the first string.  */
  629.  
  630.             dend2 = ((IS_IN_FIRST_STRING (regstart[regno]) 
  631.               == IS_IN_FIRST_STRING (regend[regno]))
  632.              ? regend[regno] : end_match_1);
  633.         while (1)
  634.           {
  635.         /* If necessary, advance to next segment in register
  636.                    contents.  */
  637.         while (d2 == dend2)
  638.           {
  639.             if (dend2 == end_match_2) break;
  640.             if (dend2 == regend[regno]) break;
  641.             d2 = string2, dend2 = regend[regno];  /* end of string1 => advance to string2. */
  642.           }
  643.         /* At end of register contents => success */
  644.         if (d2 == dend2) break;
  645.  
  646.         /* If necessary, advance to next segment in data.  */
  647.         PREFETCH;
  648.  
  649.         /* How many characters left in this segment to match.  */
  650.         mcnt = dend - d;
  651.                 
  652.         /* Want how many consecutive characters we can match in
  653.                    one shot, so, if necessary, adjust the count.  */
  654.                 if (mcnt > dend2 - d2)
  655.           mcnt = dend2 - d2;
  656.                   
  657.         /* Compare that many; failure if mismatch, else move
  658.                    past them.  */
  659.         if (translate 
  660.                     ? bcmp_translate (d, d2, mcnt, translate) 
  661.                     : bcmp (d, d2, mcnt))
  662.           goto fail;
  663.         d += mcnt, d2 += mcnt;
  664.           }
  665.       }
  666.       break;
  667.  
  668.     case anychar:
  669.       PREFETCH;      /* Fetch a data character. */
  670.       /* Match anything but a newline, maybe even a null.  */
  671.       if ((translate ? translate[*d] : *d) == '\n'
  672.               || ((obscure_syntax & RE_DOT_NOT_NULL) 
  673.                   && (translate ? translate[*d] : *d) == '\000'))
  674.         goto fail;
  675.       SET_REGS_MATCHED;
  676.           d++;
  677.       break;
  678.  
  679.     case charset:
  680.     case charset_not:
  681.       {
  682.         int not = 0;        /* Nonzero for charset_not.  */
  683.         register int c;
  684.         if (*(p - 1) == (unsigned char) charset_not)
  685.           not = 1;
  686.  
  687.         PREFETCH;        /* Fetch a data character. */
  688.  
  689.         if (translate)
  690.           c = translate[*d];
  691.         else
  692.           c = *d;
  693.  
  694.         if (c < *p * BYTEWIDTH
  695.         && p[1 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
  696.           not = !not;
  697.  
  698.         p += 1 + *p;
  699.  
  700.         if (!not) goto fail;
  701.         SET_REGS_MATCHED;
  702.             d++;
  703.         break;
  704.       }
  705.  
  706.     case begline:
  707.           if ((size1 != 0 && d == string1)
  708.               || (size1 == 0 && size2 != 0 && d == string2)
  709.               || (d && d[-1] == '\n')
  710.               || (size1 == 0 && size2 == 0))
  711.             break;
  712.           else
  713.             goto fail;
  714.             
  715.     case endline:
  716.       if (d == end2
  717.           || (d == end1 ? (size2 == 0 || *string2 == '\n') : *d == '\n'))
  718.         break;
  719.       goto fail;
  720.  
  721.     /* `or' constructs are handled by starting each alternative with
  722.            an on_failure_jump that points to the start of the next
  723.            alternative.  Each alternative except the last ends with a
  724.            jump to the joining point.  (Actually, each jump except for
  725.            the last one really jumps to the following jump, because
  726.            tensioning the jumps is a hassle.)  */
  727.  
  728.     /* The start of a stupid repeat has an on_failure_jump that points
  729.        past the end of the repeat text. This makes a failure point so 
  730.            that on failure to match a repetition, matching restarts past
  731.            as many repetitions have been found with no way to fail and
  732.            look for another one.  */
  733.  
  734.     /* A smart repeat is similar but loops back to the on_failure_jump
  735.        so that each repetition makes another failure point.  */
  736.  
  737.     case on_failure_jump:
  738.         on_failure:
  739.           EXTRACT_NUMBER_AND_INCR (mcnt, p);
  740.           PUSH_FAILURE_POINT (p + mcnt, d);
  741.           break;
  742.  
  743.     /* The end of a smart repeat has a maybe_finalize_jump back.
  744.        Change it either to a finalize_jump or an ordinary jump.  */
  745.     case maybe_finalize_jump:
  746.           EXTRACT_NUMBER_AND_INCR (mcnt, p);
  747.       {
  748.         register unsigned char *p2 = p;
  749.         /* Compare what follows with the beginning of the repeat.
  750.            If we can establish that there is nothing that they would
  751.            both match, we can change to finalize_jump.  */
  752.         while (p2 + 1 != pend
  753.            && (*p2 == (unsigned char) stop_memory
  754.                || *p2 == (unsigned char) start_memory))
  755.           p2 += 2;                /* Skip over reg number.  */
  756.         if (p2 == pend)
  757.           p[-3] = (unsigned char) finalize_jump;
  758.         else if (*p2 == (unsigned char) exactn
  759.              || *p2 == (unsigned char) endline)
  760.           {
  761.         register int c = *p2 == (unsigned char) endline ? '\n' : p2[2];
  762.         register unsigned char *p1 = p + mcnt;
  763.         /* p1[0] ... p1[2] are an on_failure_jump.
  764.            Examine what follows that.  */
  765.         if (p1[3] == (unsigned char) exactn && p1[5] != c)
  766.           p[-3] = (unsigned char) finalize_jump;
  767.         else if (p1[3] == (unsigned char) charset
  768.              || p1[3] == (unsigned char) charset_not)
  769.           {
  770.             int not = p1[3] == (unsigned char) charset_not;
  771.             if (c < p1[4] * BYTEWIDTH
  772.             && p1[5 + c / BYTEWIDTH] & (1 << (c % BYTEWIDTH)))
  773.               not = !not;
  774.             /* `not' is 1 if c would match.  */
  775.             /* That means it is not safe to finalize.  */
  776.             if (!not)
  777.               p[-3] = (unsigned char) finalize_jump;
  778.           }
  779.           }
  780.       }
  781.       p -= 2;        /* Point at relative address again.  */
  782.       if (p[-1] != (unsigned char) finalize_jump)
  783.         {
  784.           p[-1] = (unsigned char) jump;    
  785.           goto nofinalize;
  786.         }
  787.         /* Note fall through.  */
  788.  
  789.     /* The end of a stupid repeat has a finalize_jump back to the
  790.            start, where another failure point will be made which will
  791.            point to after all the repetitions found so far.  */
  792.  
  793.         /* Take off failure points put on by matching on_failure_jump 
  794.            because didn't fail.  Also remove the register information
  795.            put on by the on_failure_jump.  */
  796.         case finalize_jump:
  797.           POP_FAILURE_POINT ();
  798.         /* Note fall through.  */
  799.         
  800.     /* Jump without taking off any failure points.  */
  801.         case jump:
  802.     nofinalize:
  803.       EXTRACT_NUMBER_AND_INCR (mcnt, p);
  804.       p += mcnt;
  805.       break;
  806.  
  807.         case dummy_failure_jump:
  808.           /* Normally, the on_failure_jump pushes a failure point, which
  809.              then gets popped at finalize_jump.  We will end up at
  810.              finalize_jump, also, and with a pattern of, say, `a+', we
  811.              are skipping over the on_failure_jump, so we have to push
  812.              something meaningless for finalize_jump to pop.  */
  813.           PUSH_FAILURE_POINT (0, 0);
  814.           goto nofinalize;
  815.  
  816.  
  817.         /* Have to succeed matching what follows at least n times.  Then
  818.           just handle like an on_failure_jump.  */
  819.         case succeed_n: 
  820.           EXTRACT_NUMBER (mcnt, p + 2);
  821.           /* Originally, this is how many times we HAVE to succeed.  */
  822.           if (mcnt)
  823.             {
  824.                mcnt--;
  825.            p += 2;
  826.                STORE_NUMBER_AND_INCR (p, mcnt);
  827.             }
  828.       else if (mcnt == 0)
  829.             {
  830.           p[2] = unused;
  831.               p[3] = unused;
  832.               goto on_failure;
  833.             }
  834.           else
  835.         { 
  836.               fprintf (stderr, "regex: the succeed_n's n is not set.\n");
  837.               exit (1);
  838.         }
  839.           break;
  840.         
  841.         case jump_n: 
  842.           EXTRACT_NUMBER (mcnt, p + 2);
  843.           /* Originally, this is how many times we CAN jump.  */
  844.           if (mcnt)
  845.             {
  846.                mcnt--;
  847.                STORE_NUMBER(p + 2, mcnt);
  848.            goto nofinalize;         /* Do the jump without taking off
  849.                             any failure points.  */
  850.             }
  851.           /* If don't have to jump any more, skip over the rest of command.  */
  852.       else      
  853.         p += 4;             
  854.           break;
  855.         
  856.     case set_number_at:
  857.       {
  858.           register unsigned char *p1;
  859.  
  860.             EXTRACT_NUMBER_AND_INCR (mcnt, p);
  861.             p1 = p + mcnt;
  862.             EXTRACT_NUMBER_AND_INCR (mcnt, p);
  863.         STORE_NUMBER (p1, mcnt);
  864.             break;
  865.           }
  866.  
  867.         /* Ignore these.  Used to ignore the n of succeed_n's which
  868.            currently have n == 0.  */
  869.         case unused:
  870.           break;
  871.  
  872.         case wordbound:
  873.       if (AT_WORD_BOUNDARY)
  874.         break;
  875.       goto fail;
  876.  
  877.     case notwordbound:
  878.       if (AT_WORD_BOUNDARY)
  879.         goto fail;
  880.       break;
  881.  
  882.     case wordbeg:
  883.       if (IS_A_LETTER (d) && (!IS_A_LETTER (d - 1) || AT_STRINGS_BEG))
  884.         break;
  885.       goto fail;
  886.  
  887.     case wordend:
  888.           /* Have to check if AT_STRINGS_BEG before looking at d - 1.  */
  889.       if (!AT_STRINGS_BEG && IS_A_LETTER (d - 1) 
  890.               && (!IS_A_LETTER (d) || AT_STRINGS_END))
  891.         break;
  892.       goto fail;
  893.  
  894. #ifdef emacs
  895.     case before_dot:
  896.       if (PTR_CHAR_POS (d) >= point)
  897.         goto fail;
  898.       break;
  899.  
  900.     case at_dot:
  901.       if (PTR_CHAR_POS (d) != point)
  902.         goto fail;
  903.       break;
  904.  
  905.     case after_dot:
  906.       if (PTR_CHAR_POS (d) <= point)
  907.         goto fail;
  908.       break;
  909.  
  910.     case wordchar:
  911.       mcnt = (int) Sword;
  912.       goto matchsyntax;
  913.  
  914.     case syntaxspec:
  915.       mcnt = *p++;
  916.     matchsyntax:
  917.       PREFETCH;
  918.       if (SYNTAX (*d++) != (enum syntaxcode) mcnt) goto fail;
  919.           SET_REGS_MATCHED;
  920.       break;
  921.       
  922.     case notwordchar:
  923.       mcnt = (int) Sword;
  924.       goto matchnotsyntax;
  925.  
  926.     case notsyntaxspec:
  927.       mcnt = *p++;
  928.     matchnotsyntax:
  929.       PREFETCH;
  930.       if (SYNTAX (*d++) == (enum syntaxcode) mcnt) goto fail;
  931.       SET_REGS_MATCHED;
  932.           break;
  933.  
  934. #else /* not emacs */
  935.  
  936.     case wordchar:
  937.       PREFETCH;
  938.           if (!IS_A_LETTER (d))
  939.             goto fail;
  940.       SET_REGS_MATCHED;
  941.       break;
  942.       
  943.     case notwordchar:
  944.       PREFETCH;
  945.       if (IS_A_LETTER (d))
  946.             goto fail;
  947.           SET_REGS_MATCHED;
  948.       break;
  949.  
  950. #endif /* not emacs */
  951.  
  952.     case begbuf:
  953.           if (AT_STRINGS_BEG)
  954.             break;
  955.           goto fail;
  956.  
  957.         case endbuf:
  958.       if (AT_STRINGS_END)
  959.         break;
  960.       goto fail;
  961.  
  962.     case exactn:
  963.       /* Match the next few pattern characters exactly.
  964.          mcnt is how many characters to match.  */
  965.       mcnt = *p++;
  966.       /* This is written out as an if-else so we don't waste time
  967.              testing `translate' inside the loop.  */
  968.           if (translate)
  969.         {
  970.           do
  971.         {
  972.           PREFETCH;
  973.           if (translate[*d++] != *p++) goto fail;
  974.         }
  975.           while (--mcnt);
  976.         }
  977.       else
  978.         {
  979.           do
  980.         {
  981.           PREFETCH;
  982.           if (*d++ != *p++) goto fail;
  983.         }
  984.           while (--mcnt);
  985.         }
  986.       SET_REGS_MATCHED;
  987.           break;
  988.     }
  989.       continue;  /* Successfully executed one pattern command; keep going.  */
  990.  
  991.     /* Jump here if any matching operation fails. */
  992.     fail:
  993.       if (stackp != stackb)
  994.     /* A restart point is known.  Restart there and pop it. */
  995.     {
  996.           short last_used_reg, this_reg;
  997.           
  998.           /* If this failure point is from a dummy_failure_point, just
  999.              skip it.  */
  1000.       if (!stackp[-2])
  1001.             {
  1002.               POP_FAILURE_POINT ();
  1003.               goto fail;
  1004.             }
  1005.  
  1006.           d = *--stackp;
  1007.       p = *--stackp;
  1008.           if (d >= string1 && d <= end1)
  1009.         dend = end_match_1;
  1010.           /* Restore register info.  */
  1011.           last_used_reg = (short) *--stackp;
  1012.           
  1013.           /* Make the ones that weren't saved -1 or 0 again.  */
  1014.           for (this_reg = RE_NREGS - 1; this_reg > last_used_reg; this_reg--)
  1015.             {
  1016.               regend[this_reg] = (unsigned char *) -1;
  1017.               regstart[this_reg] = (unsigned char *) -1;
  1018.               IS_ACTIVE (reg_info[this_reg]) = 0;
  1019.               MATCHED_SOMETHING (reg_info[this_reg]) = 0;
  1020.             }
  1021.           
  1022.           /* And restore the rest from the stack.  */
  1023.           for ( ; this_reg > 0; this_reg--)
  1024.             {
  1025.               reg_info[this_reg] = *(struct register_info *) *--stackp;
  1026.               regend[this_reg] = *--stackp;
  1027.               regstart[this_reg] = *--stackp;
  1028.             }
  1029.     }
  1030.       else
  1031.         break;   /* Matching at this starting point really fails.  */
  1032.     }
  1033.  
  1034.   if (best_regs_set)
  1035.     goto restore_best_regs;
  1036.   return -1;                     /* Failure to match.  */
  1037. }
  1038.  
  1039.  
  1040. static int
  1041. bcmp_translate (s1, s2, len, translate)
  1042.      unsigned char *s1, *s2;
  1043.      register int len;
  1044.      unsigned char *translate;
  1045. {
  1046.   register unsigned char *p1 = s1, *p2 = s2;
  1047.   while (len)
  1048.     {
  1049.       if (translate [*p1++] != translate [*p2++]) return 1;
  1050.       len--;
  1051.     }
  1052.   return 0;
  1053. }
  1054.  
  1055.  
  1056.  
  1057. /* Entry points compatible with 4.2 BSD regex library.  */
  1058.  
  1059. #ifndef emacs
  1060.  
  1061. static struct re_pattern_buffer re_comp_buf;
  1062.  
  1063. char *
  1064. re_comp (s)
  1065.      char *s;
  1066. {
  1067.   if (!s)
  1068.     {
  1069.       if (!re_comp_buf.buffer)
  1070.     return "No previous regular expression";
  1071.       return 0;
  1072.     }
  1073.  
  1074.   if (!re_comp_buf.buffer)
  1075.     {
  1076.       if (!(re_comp_buf.buffer = (char *) malloc (200)))
  1077.     return "Memory exhausted";
  1078.       re_comp_buf.allocated = 200;
  1079.       if (!(re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH)))
  1080.     return "Memory exhausted";
  1081.     }
  1082.   return re_compile_pattern (s, strlen (s), &re_comp_buf);
  1083. }
  1084.  
  1085. int
  1086. re_exec (s)
  1087.      char *s;
  1088. {
  1089.   int len = strlen (s);
  1090.   return 0 <= re_search (&re_comp_buf, s, len, 0, len,
  1091.              (struct re_registers *) 0);
  1092. }
  1093. #endif /* not emacs */
  1094.  
  1095.  
  1096.  
  1097. #ifdef test
  1098.  
  1099. #include <stdio.h>
  1100.  
  1101. /* Indexed by a character, gives the upper case equivalent of the
  1102.    character.  */
  1103.  
  1104. char upcase[0400] = 
  1105.   { 000, 001, 002, 003, 004, 005, 006, 007,
  1106.     010, 011, 012, 013, 014, 015, 016, 017,
  1107.     020, 021, 022, 023, 024, 025, 026, 027,
  1108.     030, 031, 032, 033, 034, 035, 036, 037,
  1109.     040, 041, 042, 043, 044, 045, 046, 047,
  1110.     050, 051, 052, 053, 054, 055, 056, 057,
  1111.     060, 061, 062, 063, 064, 065, 066, 067,
  1112.     070, 071, 072, 073, 074, 075, 076, 077,
  1113.     0100, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
  1114.     0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
  1115.     0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
  1116.     0130, 0131, 0132, 0133, 0134, 0135, 0136, 0137,
  1117.     0140, 0101, 0102, 0103, 0104, 0105, 0106, 0107,
  1118.     0110, 0111, 0112, 0113, 0114, 0115, 0116, 0117,
  1119.     0120, 0121, 0122, 0123, 0124, 0125, 0126, 0127,
  1120.     0130, 0131, 0132, 0173, 0174, 0175, 0176, 0177,
  1121.     0200, 0201, 0202, 0203, 0204, 0205, 0206, 0207,
  1122.     0210, 0211, 0212, 0213, 0214, 0215, 0216, 0217,
  1123.     0220, 0221, 0222, 0223, 0224, 0225, 0226, 0227,
  1124.     0230, 0231, 0232, 0233, 0234, 0235, 0236, 0237,
  1125.     0240, 0241, 0242, 0243, 0244, 0245, 0246, 0247,
  1126.     0250, 0251, 0252, 0253, 0254, 0255, 0256, 0257,
  1127.     0260, 0261, 0262, 0263, 0264, 0265, 0266, 0267,
  1128.     0270, 0271, 0272, 0273, 0274, 0275, 0276, 0277,
  1129.     0300, 0301, 0302, 0303, 0304, 0305, 0306, 0307,
  1130.     0310, 0311, 0312, 0313, 0314, 0315, 0316, 0317,
  1131.     0320, 0321, 0322, 0323, 0324, 0325, 0326, 0327,
  1132.     0330, 0331, 0332, 0333, 0334, 0335, 0336, 0337,
  1133.     0340, 0341, 0342, 0343, 0344, 0345, 0346, 0347,
  1134.     0350, 0351, 0352, 0353, 0354, 0355, 0356, 0357,
  1135.     0360, 0361, 0362, 0363, 0364, 0365, 0366, 0367,
  1136.     0370, 0371, 0372, 0373, 0374, 0375, 0376, 0377
  1137.   };
  1138.  
  1139. #ifdef canned
  1140.  
  1141. #include "tests.h"
  1142.  
  1143. typedef enum { extended_test, basic_test } test_type;
  1144.  
  1145. /* Use this to run the tests we've thought of.  */
  1146.  
  1147. void
  1148. main ()
  1149. {
  1150.   test_type t = extended_test;
  1151.  
  1152.   if (t == basic_test)
  1153.     {
  1154.       printf ("Running basic tests:\n\n");
  1155.       test_posix_basic ();
  1156.     }
  1157.   else if (t == extended_test)
  1158.     {
  1159.       printf ("Running extended tests:\n\n");
  1160.       test_posix_extended (); 
  1161.     }
  1162. }
  1163.  
  1164. #else /* not canned */
  1165.  
  1166. /* Use this to run interactive tests.  */
  1167.  
  1168. void
  1169. main (argc, argv)
  1170.      int argc;
  1171.      char **argv;
  1172. {
  1173.   char pat[80];
  1174.   struct re_pattern_buffer buf;
  1175.   int i;
  1176.   char c;
  1177.   char fastmap[(1 << BYTEWIDTH)];
  1178.  
  1179.   /* Allow a command argument to specify the style of syntax.  */
  1180.   if (argc > 1)
  1181.     obscure_syntax = atoi (argv[1]);
  1182.  
  1183.   buf.allocated = 40;
  1184.   buf.buffer = (char *) malloc (buf.allocated);
  1185.   buf.fastmap = fastmap;
  1186.   buf.translate = upcase;
  1187.  
  1188.   while (1)
  1189.     {
  1190.       gets (pat);
  1191.  
  1192.       if (*pat)
  1193.     {
  1194.           re_compile_pattern (pat, strlen(pat), &buf);
  1195.  
  1196.       for (i = 0; i < buf.used; i++)
  1197.         printchar (buf.buffer[i]);
  1198.  
  1199.       putchar ('\n');
  1200.  
  1201.       printf ("%d allocated, %d used.\n", buf.allocated, buf.used);
  1202.  
  1203.       re_compile_fastmap (&buf);
  1204.       printf ("Allowed by fastmap: ");
  1205.       for (i = 0; i < (1 << BYTEWIDTH); i++)
  1206.         if (fastmap[i]) printchar (i);
  1207.       putchar ('\n');
  1208.     }
  1209.  
  1210.       gets (pat);    /* Now read the string to match against */
  1211.  
  1212.       i = re_match (&buf, pat, strlen (pat), 0, 0);
  1213.       printf ("Match value %d.\n", i);
  1214.     }
  1215. }
  1216.  
  1217. #endif
  1218.  
  1219.  
  1220. #ifdef NOTDEF
  1221. print_buf (bufp)
  1222.      struct re_pattern_buffer *bufp;
  1223. {
  1224.   int i;
  1225.  
  1226.   printf ("buf is :\n----------------\n");
  1227.   for (i = 0; i < bufp->used; i++)
  1228.     printchar (bufp->buffer[i]);
  1229.   
  1230.   printf ("\n%d allocated, %d used.\n", bufp->allocated, bufp->used);
  1231.   
  1232.   printf ("Allowed by fastmap: ");
  1233.   for (i = 0; i < (1 << BYTEWIDTH); i++)
  1234.     if (bufp->fastmap[i])
  1235.       printchar (i);
  1236.   printf ("\nAllowed by translate: ");
  1237.   if (bufp->translate)
  1238.     for (i = 0; i < (1 << BYTEWIDTH); i++)
  1239.       if (bufp->translate[i])
  1240.     printchar (i);
  1241.   printf ("\nfastmap is%s accurate\n", bufp->fastmap_accurate ? "" : "n't");
  1242.   printf ("can %s be null\n----------", bufp->can_be_null ? "" : "not");
  1243. }
  1244. #endif /* NOTDEF */
  1245.  
  1246. printchar (c)
  1247.      char c;
  1248. {
  1249.   if (c < 040 || c >= 0177)
  1250.     {
  1251.       putchar ('\\');
  1252.       putchar (((c >> 6) & 3) + '0');
  1253.       putchar (((c >> 3) & 7) + '0');
  1254.       putchar ((c & 7) + '0');
  1255.     }
  1256.   else
  1257.     putchar (c);
  1258. }
  1259.  
  1260. error (string)
  1261.      char *string;
  1262. {
  1263.   puts (string);
  1264.   exit (1);
  1265. }
  1266. #endif /* test */
  1267.