home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff256.lzh / Stevie / regexp.cat < prev    next >
Text File  |  1989-10-19  |  9KB  |  257 lines

  1.  
  2.  
  3.  
  4.  
  5. REGEXP(3)                Library Functions               REGEXP(3)
  6.  
  7.  
  8.  
  9. NNAAMMEE
  10.      regcomp, regexec, regsub, regerror - regular expression
  11.      handler
  12.  
  13. SSYYNNOOPPSSIISS
  14.      ##iinncclluuddee <<rreeggeexxpp..hh>>
  15.  
  16.      rreeggeexxpp **rreeggccoommpp((eexxpp))
  17.      cchhaarr **eexxpp;;
  18.  
  19.      iinntt rreeggeexxeecc((pprroogg,, ssttrriinngg))
  20.      rreeggeexxpp **pprroogg;;
  21.      cchhaarr **ssttrriinngg;;
  22.  
  23.      rreeggssuubb((pprroogg,, ssoouurrccee,, ddeesstt))
  24.      rreeggeexxpp **pprroogg;;
  25.      cchhaarr **ssoouurrccee;;
  26.      cchhaarr **ddeesstt;;
  27.  
  28.      rreeggeerrrroorr((mmssgg))
  29.      cchhaarr **mmssgg;;
  30.  
  31. DDEESSCCRRIIPPTTIIOONN
  32.      These functions implement
  33.      _e_g_r_e_p(1)-style
  34.      regular expressions and supporting facilities.
  35.  
  36.      _R_e_g_c_o_m_p
  37.      compiles a regular expression into a structure of type
  38.      _r_e_g_e_x_p,
  39.      and returns a pointer to it.
  40.      The space has been allocated using
  41.      _m_a_l_l_o_c(3)
  42.      and may be released by
  43.      _f_r_e_e.
  44.  
  45.      _R_e_g_e_x_e_c
  46.      matches a NUL-terminated _s_t_r_i_n_g against the compiled regular expression
  47.      in _p_r_o_g.
  48.      It returns 1 for success and 0 for failure, and adjusts the contents of
  49.      _p_r_o_g's _s_t_a_r_t_p and _e_n_d_p (see below) accordingly.
  50.  
  51.      The members of a
  52.      _r_e_g_e_x_p
  53.      structure include at least the following (not necessarily in order):
  54.  
  55.           char *startp[NSUBEXP];
  56.           char *endp[NSUBEXP];
  57.  
  58.      where
  59.      _N_S_U_B_E_X_P
  60.      is defined (as 10) in the header file.
  61.  
  62.  
  63.  
  64. Formatted 88/12/30            local                             1
  65.  
  66.  
  67.  
  68.  
  69. REGEXP(3)                Library Functions               REGEXP(3)
  70.  
  71.  
  72.  
  73.      Once a successful _r_e_g_e_x_e_c has been done using the _r_e_g_e_x_p,
  74.      each _s_t_a_r_t_p-_e_n_d_p pair describes one substring
  75.      within the _s_t_r_i_n_g,
  76.      with the _s_t_a_r_t_p pointing to the first character of the substring and
  77.      the _e_n_d_p pointing to the first character following the substring.
  78.      The 0th substring is the substring of _s_t_r_i_n_g that matched the whole
  79.      regular expression.
  80.      The others are those substrings that matched parenthesized expressions
  81.      within the regular expression, with parenthesized expressions numbered
  82.      in left-to-right order of their opening parentheses.
  83.  
  84.      _R_e_g_s_u_b
  85.      copies _s_o_u_r_c_e to _d_e_s_t, making substitutions according to the
  86.      most recent _r_e_g_e_x_e_c performed using _p_r_o_g.
  87.      Each instance of `&' in _s_o_u_r_c_e is replaced by the substring
  88.      indicated by _s_t_a_r_t_p[_0] and
  89.      _e_n_d_p[_0].
  90.      Each instance of `\_n', where _n is a digit, is replaced by
  91.      the substring indicated by
  92.      _s_t_a_r_t_p[_n] and
  93.      _e_n_d_p[_n].
  94.      To get a literal `&' or `\_n' into _d_e_s_t, prefix it with `\';
  95.      to get a literal `\' preceding `&' or `\_n', prefix it with
  96.      another `\'.
  97.  
  98.      _R_e_g_e_r_r_o_r
  99.      is called whenever an error is detected in _r_e_g_c_o_m_p, _r_e_g_e_x_e_c,
  100.      or _r_e_g_s_u_b.
  101.      The default _r_e_g_e_r_r_o_r writes the string _m_s_g,
  102.      with a suitable indicator of origin,
  103.      on the standard
  104.      error output
  105.      and invokes _e_x_i_t(2).
  106.      _R_e_g_e_r_r_o_r
  107.      can be replaced by the user if other actions are desirable.
  108.  
  109. RREEGGUULLAARR EEXXPPRREESSSSIIOONN SSYYNNTTAAXX
  110.      A regular expression is zero or more _b_r_a_n_c_h_e_s, separated by `|'.
  111.      It matches anything that matches one of the branches.
  112.  
  113.      A branch is zero or more _p_i_e_c_e_s, concatenated.
  114.      It matches a match for the first, followed by a match for the second, etc.
  115.  
  116.      A piece is an _a_t_o_m possibly followed by `*', `+', or `?'.
  117.      An atom followed by `*' matches a sequence of 0 or more matches of the atom.
  118.      An atom followed by `+' matches a sequence of 1 or more matches of the atom.
  119.      An atom followed by `?' matches a match of the atom, or the null string.
  120.  
  121.      An atom is a regular expression in parentheses (matching a match for the
  122.      regular expression), a _r_a_n_g_e (see below), `.'
  123.      (matching any single character), `^' (matching the null string at the
  124.      beginning of the input string), `$' (matching the null string at the
  125.  
  126.  
  127.  
  128. Formatted 88/12/30            local                             2
  129.  
  130.  
  131.  
  132.  
  133. REGEXP(3)                Library Functions               REGEXP(3)
  134.  
  135.  
  136.  
  137.      end of the input string), a `\' followed by a single character (matching
  138.      that character), or a single character with no other significance
  139.      (matching that character).
  140.  
  141.      A _r_a_n_g_e is a sequence of characters enclosed in `[]'.
  142.      It normally matches any single character from the sequence.
  143.      If the sequence begins with `^',
  144.      it matches any single character _n_o_t from the rest of the sequence.
  145.      If two characters in the sequence are separated by `-', this is shorthand
  146.      for the full list of ASCII characters between them
  147.      (e.g. `[0-9]' matches any decimal digit).
  148.      To include a literal `]' in the sequence, make it the first character
  149.      (following a possible `^').
  150.      To include a literal `-', make it the first or last character.
  151.  
  152. AAMMBBIIGGUUIITTYY
  153.      If a regular expression could match two different parts of the input string,
  154.      it will match the one which begins earliest.
  155.      If both begin in the same place    but match different lengths, or match
  156.      the same length in different ways, life gets messier, as follows.
  157.  
  158.      In general, the possibilities in a list of branches are considered in
  159.      left-to-right order, the possibilities for `*', `+', and `?' are
  160.      considered longest-first, nested constructs are considered from the
  161.      outermost in, and concatenated constructs are considered leftmost-first.
  162.      The match that will be chosen is the one that uses the earliest
  163.      possibility in the first choice that has to be made.
  164.      If there is more than one choice, the next will be made in the same manner
  165.      (earliest possibility) subject to the decision on the first choice.
  166.      And so forth.
  167.  
  168.      For example, `(ab|a)b*c' could match `abc' in one of two ways.
  169.      The first choice is between `ab' and `a'; since `ab' is earlier, and does
  170.      lead to a successful overall match, it is chosen.
  171.      Since the `b' is already spoken for,
  172.      the `b*' must match its last possibility--the empty string--since
  173.      it must respect the earlier choice.
  174.  
  175.      In the particular case where no `|'s are present and there is only one
  176.      `*', `+', or `?', the net effect is that the longest possible
  177.      match will be chosen.
  178.      So `ab*', presented with `xabbbby', will match `abbbb'.
  179.      Note that if `ab*' is tried against `xabyabbbz', it
  180.      will match `ab' just after `x', due to the begins-earliest rule.
  181.      (In effect, the decision on where to start the match is the first choice
  182.      to be made, hence subsequent choices must respect it even if this leads them
  183.      to less-preferred alternatives.)
  184.  
  185. SSEEEE AALLSSOO
  186.      egrep(1), expr(1)
  187.  
  188.  
  189.  
  190.  
  191.  
  192. Formatted 88/12/30            local                             3
  193.  
  194.  
  195.  
  196.  
  197. REGEXP(3)                Library Functions               REGEXP(3)
  198.  
  199.  
  200.  
  201. DDIIAAGGNNOOSSTTIICCSS
  202.      _R_e_g_c_o_m_p returns NULL for a failure
  203.      (_r_e_g_e_r_r_o_r permitting),
  204.      where failures are syntax errors, exceeding implementation limits,
  205.      or applying `+' or `*' to a possibly-null operand.
  206.  
  207. HHIISSTTOORRYY
  208.      Both code and manual page were
  209.      written at U of T.
  210.      They are intended to be compatible with the Bell V8 _r_e_g_e_x_p(3),
  211.      but are not derived from Bell code.
  212.  
  213. BBUUGGSS
  214.      Empty branches and empty regular expressions are not portable to V8.
  215.  
  216.      The restriction against
  217.      applying `*' or `+' to a possibly-null operand is an artifact of the
  218.      simplistic implementation.
  219.  
  220.      Does not support _e_g_r_e_p's newline-separated branches;
  221.      neither does the V8 _r_e_g_e_x_p(3), though.
  222.  
  223.      Due to emphasis on
  224.      compactness and simplicity,
  225.      it's not strikingly fast.
  226.      It does give special attention to handling simple cases quickly.
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256. Formatted 88/12/30            local                             4
  257.