home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !gcc / include / unixlib / h / regex < prev    next >
Encoding:
Text File  |  2006-09-17  |  6.3 KB  |  175 lines

  1. #ifndef _REGEX_H_
  2. #define _REGEX_H_                /* never again */
  3. /*
  4.  * regular expressions
  5.  *
  6.  * Copyright (c) 1998, 1999 Henry Spencer.    All rights reserved.
  7.  *
  8.  * Development of this software was funded, in part, by Cray Research Inc.,
  9.  * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
  10.  * Corporation, none of whom are responsible for the results.  The author
  11.  * thanks all of them.
  12.  *
  13.  * Redistribution and use in source and binary forms -- with or without
  14.  * modification -- are permitted for any purpose, provided that
  15.  * redistributions in source form retain this entire copyright notice and
  16.  * indicate the origin and nature of any modifications.
  17.  *
  18.  * I'd appreciate being given credit for this package in the documentation
  19.  * of software which uses it, but that is not a requirement.
  20.  *
  21.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  22.  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  23.  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
  24.  * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29.  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  30.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  */
  33.  
  34. /*
  35.  * interface types etc.
  36.  */
  37.  
  38. /*
  39.  * regoff_t has to be large enough to hold either off_t or ssize_t,
  40.  * and must be signed; it's only a guess that long is suitable.
  41.  */
  42. typedef long regoff_t;
  43.  
  44. /*
  45.  * other interface types
  46.  */
  47.  
  48. /* the biggie, a compiled RE (or rather, a front end to same) */
  49. typedef struct
  50. {
  51.     int        re_magic;        /* magic number */
  52.     size_t        re_nsub;        /* number of subexpressions */
  53.     long        re_info;        /* information about RE */
  54. #define  REG_UBACKREF         000001
  55. #define  REG_ULOOKAHEAD         000002
  56. #define  REG_UBOUNDS         000004
  57. #define  REG_UBRACES         000010
  58. #define  REG_UBSALNUM         000020
  59. #define  REG_UPBOTCH         000040
  60. #define  REG_UBBS         000100
  61. #define  REG_UNONPOSIX         000200
  62. #define  REG_UUNSPEC         000400
  63. #define  REG_UUNPORT         001000
  64. #define  REG_ULOCALE         002000
  65. #define  REG_UEMPTYMATCH     004000
  66. #define  REG_UIMPOSSIBLE     010000
  67. #define  REG_USHORTEST         020000
  68.     int        re_csize;        /* sizeof(character) */
  69.     char        *re_endp;    /* backward compatibility kludge */
  70.     /* the rest is opaque pointers to hidden innards */
  71.     char        *re_guts;    /* `char *' is more portable than `void *' */
  72.     char        *re_fns;
  73. } regex_t;
  74.  
  75. /* result reporting (may acquire more fields later) */
  76. typedef struct
  77. {
  78.     regoff_t    rm_so;            /* start of substring */
  79.     regoff_t    rm_eo;            /* end of substring */
  80. } regmatch_t;
  81.  
  82. /* supplementary control and reporting */
  83. typedef struct
  84. {
  85.     regmatch_t    rm_extend;        /* see REG_EXPECT */
  86. } rm_detail_t;
  87.  
  88.  
  89.  
  90. /*
  91.  * regex compilation flags
  92.  */
  93. #define REG_BASIC    000000        /* BREs (convenience) */
  94. #define REG_EXTENDED    000001        /* EREs */
  95. #define REG_ADVF    000002        /* advanced features in EREs */
  96. #define REG_ADVANCED    000003        /* AREs (which are also EREs) */
  97. #define REG_QUOTE    000004        /* no special characters, none */
  98. #define REG_NOSPEC    REG_QUOTE    /* historical synonym */
  99. #define REG_ICASE    000010        /* ignore case */
  100. #define REG_NOSUB    000020        /* don't care about subexpressions */
  101. #define REG_EXPANDED    000040        /* expanded format, white space & comments */
  102. #define REG_NLSTOP    000100        /* \n doesn't match . or [^ ] */
  103. #define REG_NLANCH    000200        /* ^ matches after \n, $ before */
  104. #define REG_NEWLINE    000300        /* newlines are line terminators */
  105. #define REG_PEND    000400        /* ugh -- backward-compatibility hack */
  106. #define REG_EXPECT    001000        /* report details on partial/limited
  107.                                  * matches */
  108. #define REG_BOSONLY    002000        /* temporary kludge for BOS-only matches */
  109. #define REG_DUMP    004000        /* none of your business :-) */
  110. #define REG_FAKE    010000        /* none of your business :-) */
  111. #define REG_PROGRESS    020000        /* none of your business :-) */
  112.  
  113.  
  114.  
  115. /*
  116.  * regex execution flags
  117.  */
  118. #define REG_NOTBOL    0001        /* BOS is not BOL */
  119. #define REG_NOTEOL    0002        /* EOS is not EOL */
  120. #define REG_STARTEND    0004        /* backward compatibility kludge */
  121. #define REG_FTRACE    0010        /* none of your business */
  122. #define REG_MTRACE    0020        /* none of your business */
  123. #define REG_SMALL    0040        /* none of your business */
  124.  
  125.  
  126. /*
  127.  * error reporting
  128.  * Be careful if modifying the list of error codes -- the table used by
  129.  * regerror() is generated automatically from this file!
  130.  */
  131. #define REG_OKAY     0        /* no errors detected */
  132. #define REG_NOMATCH     1        /* failed to match */
  133. #define REG_BADPAT     2        /* invalid regexp */
  134. #define REG_ECOLLATE     3        /* invalid collating element */
  135. #define REG_ECTYPE     4        /* invalid character class */
  136. #define REG_EESCAPE     5        /* invalid escape \ sequence */
  137. #define REG_ESUBREG     6        /* invalid backreference number */
  138. #define REG_EBRACK     7        /* brackets [] not balanced */
  139. #define REG_EPAREN     8        /* parentheses () not balanced */
  140. #define REG_EBRACE     9        /* braces {} not balanced */
  141. #define REG_BADBR    10        /* invalid repetition count(s) */
  142. #define REG_ERANGE    11        /* invalid character range */
  143. #define REG_ESPACE    12        /* out of memory */
  144. #define REG_BADRPT    13        /* quantifier operand invalid */
  145. #define REG_ASSERT    15        /* "can't happen" -- you found a bug */
  146. #define REG_INVARG    16        /* invalid argument to regex function */
  147. #define REG_MIXED    17        /* character widths of regex and string
  148.                              * differ */
  149. #define REG_BADOPT    18        /* invalid embedded option */
  150. /* two specials for debugging and testing */
  151. #define REG_ATOI    101        /* convert error-code name to number */
  152. #define REG_ITOA    102        /* convert error-code number to name */
  153.  
  154.  
  155.  
  156. /*
  157.  * the prototypes for exported functions
  158.  */
  159. extern int    ul_regcomp(regex_t *, const char *, size_t, int);
  160.  
  161. extern int    ul_regexec(regex_t *, const char *, size_t, size_t,
  162.                 rm_detail_t *, size_t, regmatch_t[], int);
  163. extern void    regfree(regex_t *);
  164. extern size_t    regerror(int, const regex_t *, char *, size_t);
  165.  
  166. /* This evilness is necessary to provide the expected POSIX API */
  167. #define regcomp(preg, regex, cflags) \
  168.         ul_regcomp((preg), (regex), strlen((regex)), (cflags))
  169.  
  170. #define regexec(preg, string, nmatch, pmatch, eflags) \
  171.         ul_regexec((preg), (string), strlen((string)), 0, \
  172.                 NULL, (nmatch), (pmatch), (eflags))
  173.  
  174. #endif   /* _REGEX_H_ */
  175.