home *** CD-ROM | disk | FTP | other *** search
- /* Definitions for data structures callers pass the regex library.
-
- Copyright (C) 1985, 1989-90 Free Software Foundation, Inc.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
- any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
-
- #ifndef __REGEX_H
- #define __REGEX_H
-
- /* We need size_t. There are three possibilities:
- 1. Require <stddef.h> to be included before "regex.h" - obnoxious.
- 2. Include <stddef.h> here - nested includes are a nuisance.
- 3. Copy the definition from <stddef.h> - this is the approach Acorn
- uses, and it seems the lesser evil. Requires keeping in line...
- */
-
- #ifndef __size_t
- #define __size_t 1
- typedef unsigned int size_t; /* others (e.g. <stddef.h>) define */
- /* the unsigned integral type of the result of the sizeof operator. */
- #endif
-
- /* Define number of parens for which we record the beginnings and ends.
- This affects how much space the `struct re_registers' type takes up. */
- #define RE_NREGS 10
-
- /* Maximum number of duplicates an interval can allow. */
- #define RE_DUP_MAX ((1 << 15) - 1)
-
- /* The following section contains GNU regex compatibility functions.
- * These allow (in the GNU version) for run-time tailoring of the regex
- * syntax allowed. In this version, the syntax is fixed and these functions
- * do nothing.
- */
- #define RE_NO_BK_PARENS 0
- #define RE_NO_BK_VBAR 0
- #define RE_BK_PLUS_QM 0
- #define RE_TIGHT_VBAR 0
- #define RE_NEWLINE_OR 0
- #define RE_CONTEXT_INDEP_OPS 0
- #define RE_AWK_CLASS_HACK 0
- #define RE_INTERVALS 0
- #define RE_NO_BK_CURLY_BRACES 0
- #define RE_CHAR_CLASSES 0
- #define RE_DOT_NOT_NULL 0
- #define RE_HAT_NOT_NEWLINE 0
- #define RE_NO_BK_REFS 0
- #define RE_NO_EMPTY_BK_REF 0
- #define RE_NO_EMPTY_BRACKETS 0
- #define RE_CONTEXTUAL_INVALID_OPS 0
- #define RE_LIMITED_OPS 0
- #define RE_NO_EMPTY_RANGES 0
- #define RE_NO_HYPHEN_RANGE_END 0
- #define RE_SYNTAX_POSIX_AWK 0
- #define RE_SYNTAX_AWK 0
- #define RE_SYNTAX_EGREP 0
- #define RE_SYNTAX_GREP 0
- #define RE_SYNTAX_EMACS 0
- #define RE_SYNTAX_POSIX_BASIC 0
- #define RE_SYNTAX_POSIX_EXTENDED 0
- #define RE_EXACTN_VALUE 1 /* Used in GNU emacs... */
- #define re_set_syntax(n) 0
-
- /* This data structure is used to represent a compiled pattern.
- *
- * The fields are:
- *
- * buffer - Space holding the compiled pattern commands.
- * allocated - Size of the space that buffer points to.
- * used - Length of the portion of buffer which is actually
- * occupied.
- * fastmap - Pointer to the fastmap (if any). This is set up by
- * re_search to skip over characters which can't start
- * a match.
- * translate - Translation table to apply to all characters before
- * comparing (NULL if no translation is to occur).
- * fastmap_accurate - Set to 1 when the fastmap is correct.
- * can_be_null - Set when the fastmap is compiled. Zero means the
- * pattern cannot match the null string, 1 means it
- * may, and 2 means it may match a null at the end of
- * a line, or before a character in the fastmap.
- */
-
- typedef struct re_pattern_buffer
- {
- char *buffer;
- size_t allocated;
- size_t used;
- char *fastmap;
- const char *translate;
- char fastmap_accurate;
- char can_be_null;
- }
- REGEX;
-
- /* This data structure is used to store register contents data in.
- *
- * Pass the address of such a structure as an argument to re_match, etc.,
- * if you want this information back.
- *
- * For i from 1 to RE_NREGS - 1, start[i] records the starting index in
- * the string of where the ith subexpression matched, and end[i] records
- * one after the ending index. start[0] and end[0] are analogous, for
- * the entire pattern.
- */
-
- typedef struct re_registers
- {
- int start[RE_NREGS];
- int end[RE_NREGS];
- }
- REREGS;
-
- /* Return values from re_match */
- #define RE_FAIL (-1)
- #define RE_ERROR (-2)
-
- /* The following is the external interface */
-
- /* GNU compatible interface */
- extern char *re_compile_pattern (char *, int, REGEX *);
- extern void re_compile_fastmap (REGEX *);
- extern int re_search_2 (REGEX *, char *, int, char *, int, int, int,
- REREGS *, int);
- extern int re_match_2 (REGEX *, char *, int, char *, int, int, REREGS *, int);
-
- /* BSD compatible interface */
- extern char *re_comp (char *);
- extern int re_exec (char *);
-
- /* Simpler matching functions for one string only - prototypes would be
- *
- * int re_match (REGEX *, char *, int, int, REREGS *)
- * int re_search (REGEX *, char*, int, int, int, REREGS *)
- *
- * Provided as functions in the GNU package, but macros here.
- */
-
- #define re_search(re,str,size,start,range,regs) \
- re_search_2 (re, 0, 0, str, size, start, range, regs, size)
- #define re_match(re,str,size,pos,regs) \
- re_match_2 (re, 0, 0, str, size, pos, regs, size)
-
- /* Creation and deletion of regex buffers */
- extern REGEX *re_create (const char *);
- extern void re_free (REGEX *);
-
- #endif /* !__REGEX_H */
-