home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Texteditors / Origami / Sources / src / lib / bregex.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-09-27  |  8.0 KB  |  218 lines

  1. /************************************************************************
  2.  *    bregex -- The `Better/BuGless/Berg' Regular Expression library    *
  3.  *                                    *
  4.  *    This package contains a regular expression library based on    *
  5.  *    the POSIX interface.  It has been written in ANSI and K&R    *
  6.  *    conforming C.                            *
  7.  *    The library is fully POSIX compliant except for the following:    *
  8.  *        - regexec() can not be called concurrently on the same    *
  9.  *          compiled regex_t struct (use regcopy() instead).    *
  10.  *        - Bracket expressions currently do not support:        *
  11.  *            Collating symbols [. .]                *
  12.  *            Equivalence class expressions [= =]        *
  13.  *        - Basic regular expressions do not allow backreference    *
  14.  *          expressions in the search pattern.            *
  15.  *                                    *
  16.  *    Copyright (c) 1991-1993, by S.R. van den Berg, The Netherlands    *
  17.  *                                    *
  18.  *    You are allowed to use this library or any work derived        *
  19.  *    thereof in any non-commercial package as long as you give    *
  20.  *    me credit somewhere within this package.  When in doubt,    *
  21.  *    contact me for an agreement.                    *
  22.  *                                    *
  23.  *    I can be reached on Internet under the following addresses:    *
  24.  *            <berg@pool.informatik.rwth-aachen.de>        *
  25.  *            <berg@physik.tu-muenchen.de>            *
  26.  ************************************************************************/
  27. #ifndef BREGEX_H_
  28. #define BREGEX_H_
  29. /*$Id*/
  30. /*
  31.  * The following defines can be uncommented in any combination you see fit.
  32.  * The default configuration (none of them defined) will be POSIX conforming
  33.  * (exceptions noted above).  Uncommenting one or the other will cause the
  34.  * regular expression library to change in compiled code size and speed.
  35.  *
  36.  * The following legenda applies:
  37.  *    +    noticable increase
  38.  *    -    noticable decrease
  39.  *    .    no noticable change
  40.  *    ?    change will depend on C-compiler/C-library
  41.  *
  42.  * The columns correspond to the following characteristics:
  43.  *    bregex.o size, regcomp() speed, heap+stack size, regexec() speed.
  44.  */
  45.  
  46. /*#define RE_pNOSUB        -+-+              /* permanent REG_NOSUB */
  47. /*#define RE_pNEWLINE        -.-.            /* permanent REG_NEWLINE */
  48. /*#define RE_nNEWLINE        -.-+           /* permanently no REG_NEWLINE */
  49. /*#define RE_pEXTENDED        -...           /* permanent REG_EXTENDED */
  50. /*#define RE_nEXTENDED        -...          /* permanently no REG_EXTENDED */
  51. /*#define RE_HEX_CHAR        +...    /* \x41 \x0a etc. will be recognised */
  52. /*#define RE_OCT_CHAR        +...      /* \11 \12 etc. will be recognised */
  53. /*#define RE_SPEC_CHAR        +...        /* \n \t etc. will be recognised */
  54. /*#define RE_EXEC_ERROR        +..-    /* erroneous regexps can be executed */
  55. /*#define RE_COMMON_SUBXP    ?.??  /* your C-optimiser had better be good */
  56. /*#define RE_COPY        +...          /* regcopy() will be available */
  57. /*#define RE_STRLEN        -..+    /* you supply the strlen of the text */
  58.           /* advantages: embedded \0 characters allowed, increased speed */
  59. /*#define RE_MEMCHR        ...?           /* use memchr(), not relevant */
  60.                         /* when RE_STRLEN is defined */
  61. /*#define RE_nCTYPE        ?...      /* do not use the <ctype.h> macros */
  62. /*#define RE_nCHAR_CLASS    -...  /* character classes are not supported */
  63. /*#define RE_nCASE_TABLE    -..-           /* do not use two case tables */
  64. /*#define RE_nJUMP_TABLE    -+--        /* do not create a jumptable */
  65. /*#define RE_SMALL_JUMP_TABLE    ?.-?          /* use a smaller jumptable */
  66. /*#define RE_NSUBMAX        ...+         /* support REG_NSUBMAX flag */
  67. /*#define RE_SUBSTR_PTR        -..+     /* regmatch_t will contain pointers */
  68. /*#define RE_nBRACES        -+..    /* e.g. a{3,5} will not be supported */
  69. /*#define RE_nERROR_DETECT    -+..   /* regexp errors are silently `fixed' */
  70. /*#define RE_nERROR_REPORT    -...     /* regerror() will not be available */
  71. /*#define RE_nCONCUR_COMPILE    -+-.      /* regcomp() will be non-reentrant */
  72. /*#define RE_nREUSABLE        -..+   /* only one execution/compiled regexp */
  73. /*#define RE_EMPTY_OR        +... /* empty or branches behave as expected */
  74. /*#define RE_SURE_MINIMAL    -+..  /* regexps are expected to be in their */
  75.              /* minimal form, if they aren't, hangups can result */
  76. /*#define RE_DUMB_ANCHOR    -+..  /* unquoted ^ and $ are always special */
  77.                   /* crashes might result if used improperly */
  78. /*
  79.  * You can define RE_ABORT_EXPR to some expression that will be evaluated
  80.  * in the main search loop of regexec() (once for every character in the input
  81.  * stream).  As soon as it evaluates to true, regexec() will abort the search.
  82.  *    Optimisations:        +..-
  83.  */
  84.  
  85. /*#define P(args) args          /* you can uncomment this if your compiler */
  86.                                /* understands ANSI C */
  87. #ifdef RE_CONF              /* define RE_CONF to make bregex.h include */
  88. #include "bregex.conf"             /* your personal configuration file */
  89. #endif
  90.  
  91. /**************************************************
  92.  * All configurable options are *above* this line *
  93.  **************************************************/
  94.  
  95. #ifndef P
  96. #define P(args) ()
  97. #define RE_P
  98. #ifndef const
  99. #define const
  100. #define RE_const
  101. #endif
  102. #endif
  103.  
  104. #define C_BACKREF       'g'               /* extend number for backreference */
  105.  
  106. #define REG_EXTENDED    1         /* use extended regular expressions */
  107. #define REG_ICASE    2                 /* ignore case in match */
  108. #define REG_NOSUB    4    /* equivalent to REG_NSUBMAX with re_nsub==0 */
  109. #define REG_NEWLINE    8          /* a dot and a class will not match \n */
  110. #define REG_NOTBOL    16         /* do not match ^ at the very start */
  111. #define REG_NOTEOL    32           /* do not match $ at the very end */
  112.  
  113. #define REG_LOWMEM    64     /* regexec() will save memory and be slower */
  114. #define REG_NSUBMAX    128             /* regcomp() will check re_nsub */
  115. #define REG_NOOFFSET    256       /* regerror() will not display the offset */
  116.  
  117. #define REG_SIMPLE    512                  /* used internally */
  118. #define REG_ERROR    1024                  /* used internally */
  119. #define REG_OUTOFMEM    2048                  /* used internally */
  120.  
  121. #define REG_NOMATCH    1                  /* Failed to match */
  122. #define REG_BADPAT    2               /* Invalid regular expression */
  123. #define REG_ECOLLATE    3            /* Invalid collating element */
  124. #define REG_ECTYPE    4             /* Invalid character class type */
  125. #define REG_EESCAPE    5                       /* Trailing \ */
  126. #define REG_ESUBREG    6             /* Number in \digit invalid */
  127. #define REG_EBRACK    7                    /* [ ] imbalance */
  128. #define REG_EPAREN    8                    /* ( ) imbalance */
  129. #define REG_EBRACE    9                    /* { } imbalance */
  130. #define REG_BADBR    10               /* Content of { } invalid */
  131. #define REG_ERANGE    11         /* Invalid endpoint in range expression */
  132. #define REG_ESPACE    12                    /* Out of memory */
  133. #define REG_BADRPT    13         /* Inappropriate use of magic character */
  134.  
  135. #define REG_ABORT    14                   /* Search aborted */
  136.  
  137. #ifndef RE_SUBSTR_PTR
  138. typedef int regoff_t;
  139. typedef struct
  140. { union
  141.    { regoff_t    rm_o;
  142.      char*    rm_p;
  143.    }        rm_ss,rm_es;
  144. } regmatch_t;
  145.  
  146. #define rm_so    rm_ss.rm_o
  147. #define rm_eo    rm_es.rm_o
  148. #define rm_sp    rm_ss.rm_p
  149. #define rm_ep    rm_es.rm_p
  150. #else
  151.  
  152. typedef char*regptr_t;
  153. typedef struct
  154. { char        *rm_sp,*rm_ep;
  155. } regmatch_t;
  156. #endif /* RE_SUBSTR_PTR */
  157.  
  158. typedef struct
  159. { size_t    re_nsub;
  160.   unsigned    re_flags;
  161. #ifndef RE_nJUMP_TABLE
  162.   unsigned    re_maxjump;
  163. #endif
  164.   void*        re_compiled;
  165.   void*        re_finpoint;
  166.   union
  167.    { size_t    re_error;
  168.      void*    re_stack;
  169.    }        re_es;
  170. } regex_t;
  171.  
  172. #define re_erroffset    re_es.re_error         /* can be used to determine */
  173.                    /* the offset at which the error occurred */
  174. #define regcomp        bregcomp       /* use defines to prevent clashes */
  175. #define regexec        bregexec         /* with an existing library */
  176. #define regfree        bregfree
  177. #define regerror    bregerror
  178.  
  179. int
  180.  regcomp P((regex_t*const preg,const char*const pattern,int cflags)),
  181. #ifdef RE_STRLEN
  182.  regexec P((/*const*/regex_t*preg,const char*const string,size_t length,
  183.   size_t nmatch,regmatch_t pmatch[],int eflags));
  184. #else
  185.  regexec P((/*const*/regex_t*preg,const char*const string,size_t nmatch,
  186.   regmatch_t pmatch[],int eflags));
  187. #endif
  188. #ifdef RE_COPY
  189. int
  190.  regcopy P((regex_t*const dest,const regex_t*const src));
  191. #endif
  192. #ifndef RE_nERROR_REPORT
  193. size_t
  194.  regerror P((const errcode,const regex_t*const preg,char*const errbuf,
  195.   size_t errbuf_size));
  196. #endif
  197. void
  198.  regfree P((regex_t*rg));
  199.  
  200. #ifndef reg_malloc
  201. extern void
  202.  *(*reg_malloc)P((size_t size)),
  203.  *(*reg_realloc)P((void*ptr,size_t size)),
  204.  (*reg_free)P((void*ptr));
  205. #endif
  206.  
  207. #ifndef BREGEX_C_
  208. #ifdef RE_P
  209. #undef P
  210. #endif
  211. #ifdef RE_const
  212. #undef const
  213. #endif
  214. #endif /* BREGEX_C_ */
  215.  
  216. #endif /* BREGEX_H_ */
  217. /*{{{}}}*/
  218.