Home | History | Annotate | Line # | Download | only in re
      1 /*
      2  * Copyright (c) 2002 by The XFree86 Project, Inc.
      3  *
      4  * Permission is hereby granted, free of charge, to any person obtaining a
      5  * copy of this software and associated documentation files (the "Software"),
      6  * to deal in the Software without restriction, including without limitation
      7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      8  * and/or sell copies of the Software, and to permit persons to whom the
      9  * Software is furnished to do so, subject to the following conditions:
     10  *
     11  * The above copyright notice and this permission notice shall be included in
     12  * all copies or substantial portions of the Software.
     13  *
     14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     17  * THE XFREE86 PROJECT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
     18  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
     19  * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     20  * SOFTWARE.
     21  *
     22  * Except as contained in this notice, the name of the XFree86 Project shall
     23  * not be used in advertising or otherwise to promote the sale, use or other
     24  * dealings in this Software without prior written authorization from the
     25  * XFree86 Project.
     26  *
     27  * Author: Paulo Csar Pereira de Andrade
     28  */
     29 
     30 /* $XFree86: xc/programs/xedit/lisp/re/re.h,v 1.1 2002/09/08 02:29:50 paulo Exp $ */
     31 
     32 #include <stdlib.h>
     33 #include <string.h>
     34 #include <ctype.h>
     35 
     36 #ifndef _re_h
     37 #define _re_h
     38 
     39 /*
     40  * Defines
     41  */
     42 
     43 	/* Compile flags options */
     44 #define REG_BASIC		0000	/* Not used */
     45 #define REG_EXTENDED		0001	/* Not used, only extended supported */
     46 
     47 #define RE_ICASE		0002
     48 #define RE_NOSUB		0004
     49 #define RE_NEWLINE		0010
     50 #define RE_NOSPEC		0020
     51 #define RE_PEND			0040
     52 #define RE_DUMP			0200
     53 
     54 
     55 
     56 	/* Execute flag options */
     57 #define RE_NOTBOL		1
     58 #define RE_NOTEOL		2
     59 #define RE_STARTEND		4
     60 #define RE_TRACE		00400	/* Not used/supported */
     61 #define RE_LARGE		01000	/* Not used/supported */
     62 #define RE_BACKR		02000	/* Not used/supported */
     63 
     64 	/* Value returned by reexec when match fails */
     65 #define RE_NOMATCH		1
     66 	/* Compile error values */
     67 #define RE_BADPAT		2
     68 #define RE_ECOLLATE		3
     69 #define RE_ECTYPE		4
     70 #define RE_EESCAPE		5
     71 #define RE_ESUBREG		6
     72 #define RE_EBRACK		7
     73 #define RE_EPAREN		8
     74 #define RE_EBRACE		9
     75 #define RE_EBADBR		10
     76 #define RE_ERANGE		11
     77 #define RE_ESPACE		12
     78 #define RE_BADRPT		13
     79 #define RE_EMPTY		14
     80 #define RE_ASSERT		15
     81 #define RE_INVARG		16
     82 #define RE_ATOI			255	/* Not used/supported */
     83 #define RE_ITOA			0400	/* Not used/supported */
     84 
     85 
     86 /*
     87  * Types
     88  */
     89 
     90 /* (re)gular expression (mat)ch result */
     91 typedef struct _re_mat {
     92     long rm_so;
     93     long rm_eo;
     94 } re_mat;
     95 
     96 /* (re)gular expression (cod)e */
     97 typedef struct _re_cod {
     98     unsigned char *cod;
     99     int re_nsub;		/* Public member */
    100     const char *re_endp;	/* Support for RE_PEND */
    101 } re_cod;
    102 
    103 
    104 /*
    105  * Prototypes
    106  */
    107 	/* compile the given pattern string
    108 	 * returns 0 on success, error code otherwise */
    109 int recomp(re_cod *preg, const char *pattern, int flags);
    110 
    111 	/* execute the compiled pattern on the string.
    112 	 * returns 0 if matched, RE_NOMATCH if failed, error code otherwise */
    113 int reexec(const re_cod *preg, const char *string,
    114 	   int nmat, re_mat pmat[], int flags);
    115 
    116 	/* formats an error message for the given code in ebuffer */
    117 int reerror(int ecode, const re_cod *preg, char *ebuffer, int ebuffer_size);
    118 
    119 	/* frees the given parameter */
    120 void refree(re_cod *preg);
    121 
    122 
    123 #endif /* _re_h */
    124