Blame regex.h

Packit 6f02de
/*
Packit 6f02de
 * regex.h -- regular expression definitions for lsof
Packit 6f02de
 *
Packit 6f02de
 * This header file is used only when the dialect has no POSIX-conformant
Packit 6f02de
 * regular expression function set.  When that is the case, the dialect's
Packit 6f02de
 * machine.h will define USE_LIB_REGEX.
Packit 6f02de
 *
Packit 6f02de
 * When the dialect has a POSIX-conformant regular expression function set,
Packit 6f02de
 * USE_LIB_REGEX is not defined and this header file #include's <regex.h>.
Packit 6f02de
 *
Packit 6f02de
 * V. Abell <abe@purdue.edu>
Packit 6f02de
 * Purdue University
Packit 6f02de
 */
Packit 6f02de
Packit 6f02de
Packit 6f02de
/*
Packit 6f02de
 * Copyright 2000 Purdue Research Foundation, West Lafayette, Indiana
Packit 6f02de
 * 47907.  All rights reserved.
Packit 6f02de
 *
Packit 6f02de
 * Written by Victor A. Abell
Packit 6f02de
 *
Packit 6f02de
 * This software is not subject to any license of the American Telephone
Packit 6f02de
 * and Telegraph Company or the Regents of the University of California.
Packit 6f02de
 *
Packit 6f02de
 * This software has been adapted from snprintf.c in sendmail 8.9.3.  It
Packit 6f02de
 * is subject to the sendmail copyright statements listed below, and the
Packit 6f02de
 * sendmail licensing terms stated in the sendmail LICENSE file comment
Packit 6f02de
 * section of this file.
Packit 6f02de
 *
Packit 6f02de
 * Permission is granted to anyone to use this software for any purpose on
Packit 6f02de
 * any computer system, and to alter it and redistribute it freely, subject
Packit 6f02de
 * to the following restrictions:
Packit 6f02de
 *
Packit 6f02de
 * 1. Neither the authors nor Purdue University are responsible for any
Packit 6f02de
 *    consequences of the use of this software.
Packit 6f02de
 *
Packit 6f02de
 * 2. The origin of this software must not be misrepresented, either by
Packit 6f02de
 *    explicit claim or by omission.  Credit to the authors and Purdue
Packit 6f02de
 *    University must appear in documentation and sources.
Packit 6f02de
 *
Packit 6f02de
 * 3. Altered versions must be plainly marked as such, and must not be
Packit 6f02de
 *    misrepresented as being the original software.
Packit 6f02de
 *
Packit 6f02de
 * 4. This notice may not be removed or altered.
Packit 6f02de
 */
Packit 6f02de
Packit 6f02de
Packit 6f02de
#ifdef	USE_LIB_REGEX
Packit 6f02de
/*
Packit 6f02de
 * This section comes from GLIBC 2.2.  It is used only when the dialect
Packit 6f02de
 * has no POSIX-conformant regular expression function set.  When that is
Packit 6f02de
 * the case, the dialect's machine.h will define USE_LIB_REGEX.
Packit 6f02de
 */
Packit 6f02de
Packit 6f02de
/* Definitions for data structures and routines for the regular
Packit 6f02de
   expression library, version 0.12.
Packit 6f02de
   Copyright (C) 1985,1989-1993,1995-1998, 2000 Free Software Foundation, Inc.
Packit 6f02de
Packit 6f02de
   This file is part of the GNU C Library.  Its master source is NOT part of
Packit 6f02de
   the C library, however.  The master source lives in /gd/gnu/lib.
Packit 6f02de
Packit 6f02de
   The GNU C Library is free software; you can redistribute it and/or
Packit 6f02de
   modify it under the terms of the GNU Library General Public License as
Packit 6f02de
   published by the Free Software Foundation; either version 2 of the
Packit 6f02de
   License, or (at your option) any later version.
Packit 6f02de
Packit 6f02de
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6f02de
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6f02de
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6f02de
   Library General Public License for more details.
Packit 6f02de
Packit 6f02de
   You should have received a copy of the GNU Library General Public
Packit 6f02de
   License along with the GNU C Library; see the file COPYING.LIB.  If not,
Packit 6f02de
   write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Packit 6f02de
   Boston, MA 02111-1307, USA.  */
Packit 6f02de
Packit 6f02de
#ifndef _REGEX_H
Packit 6f02de
#define _REGEX_H 1
Packit 6f02de
Packit 6f02de
/* Allow the use in C++ code.  */
Packit 6f02de
#ifdef __cplusplus
Packit 6f02de
extern "C" {
Packit 6f02de
#endif
Packit 6f02de
Packit 6f02de
/* POSIX says that <sys/types.h> must be included (by the caller) before
Packit 6f02de
   <regex.h>.  */
Packit 6f02de
Packit 6f02de
#if !defined _POSIX_C_SOURCE && !defined _POSIX_SOURCE && defined VMS
Packit 6f02de
/* VMS doesn't have `size_t' in <sys/types.h>, even though POSIX says it
Packit 6f02de
   should be there.  */
Packit 6f02de
# include <stddef.h>
Packit 6f02de
#endif
Packit 6f02de
Packit 6f02de
/* The following two types have to be signed and unsigned integer type
Packit 6f02de
   wide enough to hold a value of a pointer.  For most ANSI compilers
Packit 6f02de
   ptrdiff_t and size_t should be likely OK.  Still size of these two
Packit 6f02de
   types is 2 for Microsoft C.  Ugh... */
Packit 6f02de
typedef long int s_reg_t;
Packit 6f02de
typedef unsigned long int active_reg_t;
Packit 6f02de
Packit 6f02de
/* The following bits are used to determine the regexp syntax we
Packit 6f02de
   recognize.  The set/not-set meanings are chosen so that Emacs syntax
Packit 6f02de
   remains the value 0.  The bits are given in alphabetical order, and
Packit 6f02de
   the definitions shifted by one from the previous bit; thus, when we
Packit 6f02de
   add or remove a bit, only one other definition need change.  */
Packit 6f02de
typedef unsigned long int reg_syntax_t;
Packit 6f02de
Packit 6f02de
/* If this bit is not set, then \ inside a bracket expression is literal.
Packit 6f02de
   If set, then such a \ quotes the following character.  */
Packit 6f02de
#define RE_BACKSLASH_ESCAPE_IN_LISTS ((unsigned long int) 1)
Packit 6f02de
Packit 6f02de
/* If this bit is not set, then + and ? are operators, and \+ and \? are
Packit 6f02de
     literals.
Packit 6f02de
   If set, then \+ and \? are operators and + and ? are literals.  */
Packit 6f02de
#define RE_BK_PLUS_QM (RE_BACKSLASH_ESCAPE_IN_LISTS << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then character classes are supported.  They are:
Packit 6f02de
     [:alpha:], [:upper:], [:lower:],  [:digit:], [:alnum:], [:xdigit:],
Packit 6f02de
     [:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
Packit 6f02de
   If not set, then character classes are not supported.  */
Packit 6f02de
#define RE_CHAR_CLASSES (RE_BK_PLUS_QM << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then ^ and $ are always anchors (outside bracket
Packit 6f02de
     expressions, of course).
Packit 6f02de
   If this bit is not set, then it depends:
Packit 6f02de
        ^  is an anchor if it is at the beginning of a regular
Packit 6f02de
           expression or after an open-group or an alternation operator;
Packit 6f02de
        $  is an anchor if it is at the end of a regular expression, or
Packit 6f02de
           before a close-group or an alternation operator.
Packit 6f02de
Packit 6f02de
   This bit could be (re)combined with RE_CONTEXT_INDEP_OPS, because
Packit 6f02de
   POSIX draft 11.2 says that * etc. in leading positions is undefined.
Packit 6f02de
   We already implemented a previous draft which made those constructs
Packit 6f02de
   invalid, though, so we haven't changed the code back.  */
Packit 6f02de
#define RE_CONTEXT_INDEP_ANCHORS (RE_CHAR_CLASSES << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then special characters are always special
Packit 6f02de
     regardless of where they are in the pattern.
Packit 6f02de
   If this bit is not set, then special characters are special only in
Packit 6f02de
     some contexts; otherwise they are ordinary.  Specifically,
Packit 6f02de
     * + ? and intervals are only special when not after the beginning,
Packit 6f02de
     open-group, or alternation operator.  */
Packit 6f02de
#define RE_CONTEXT_INDEP_OPS (RE_CONTEXT_INDEP_ANCHORS << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then *, +, ?, and { cannot be first in an re or
Packit 6f02de
     immediately after an alternation or begin-group operator.  */
Packit 6f02de
#define RE_CONTEXT_INVALID_OPS (RE_CONTEXT_INDEP_OPS << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then . matches newline.
Packit 6f02de
   If not set, then it doesn't.  */
Packit 6f02de
#define RE_DOT_NEWLINE (RE_CONTEXT_INVALID_OPS << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then . doesn't match NUL.
Packit 6f02de
   If not set, then it does.  */
Packit 6f02de
#define RE_DOT_NOT_NULL (RE_DOT_NEWLINE << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, nonmatching lists [^...] do not match newline.
Packit 6f02de
   If not set, they do.  */
Packit 6f02de
#define RE_HAT_LISTS_NOT_NEWLINE (RE_DOT_NOT_NULL << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, either \{...\} or {...} defines an
Packit 6f02de
     interval, depending on RE_NO_BK_BRACES.
Packit 6f02de
   If not set, \{, \}, {, and } are literals.  */
Packit 6f02de
#define RE_INTERVALS (RE_HAT_LISTS_NOT_NEWLINE << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, +, ? and | aren't recognized as operators.
Packit 6f02de
   If not set, they are.  */
Packit 6f02de
#define RE_LIMITED_OPS (RE_INTERVALS << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, newline is an alternation operator.
Packit 6f02de
   If not set, newline is literal.  */
Packit 6f02de
#define RE_NEWLINE_ALT (RE_LIMITED_OPS << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then `{...}' defines an interval, and \{ and \}
Packit 6f02de
     are literals.
Packit 6f02de
  If not set, then `\{...\}' defines an interval.  */
Packit 6f02de
#define RE_NO_BK_BRACES (RE_NEWLINE_ALT << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, (...) defines a group, and \( and \) are literals.
Packit 6f02de
   If not set, \(...\) defines a group, and ( and ) are literals.  */
Packit 6f02de
#define RE_NO_BK_PARENS (RE_NO_BK_BRACES << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then \<digit> matches <digit>.
Packit 6f02de
   If not set, then \<digit> is a back-reference.  */
Packit 6f02de
#define RE_NO_BK_REFS (RE_NO_BK_PARENS << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then | is an alternation operator, and \| is literal.
Packit 6f02de
   If not set, then \| is an alternation operator, and | is literal.  */
Packit 6f02de
#define RE_NO_BK_VBAR (RE_NO_BK_REFS << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then an ending range point collating higher
Packit 6f02de
     than the starting range point, as in [z-a], is invalid.
Packit 6f02de
   If not set, then when ending range point collates higher than the
Packit 6f02de
     starting range point, the range is ignored.  */
Packit 6f02de
#define RE_NO_EMPTY_RANGES (RE_NO_BK_VBAR << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then an unmatched ) is ordinary.
Packit 6f02de
   If not set, then an unmatched ) is invalid.  */
Packit 6f02de
#define RE_UNMATCHED_RIGHT_PAREN_ORD (RE_NO_EMPTY_RANGES << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, succeed as soon as we match the whole pattern,
Packit 6f02de
   without further backtracking.  */
Packit 6f02de
#define RE_NO_POSIX_BACKTRACKING (RE_UNMATCHED_RIGHT_PAREN_ORD << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, do not process the GNU regex operators.
Packit 6f02de
   If not set, then the GNU regex operators are recognized. */
Packit 6f02de
#define RE_NO_GNU_OPS (RE_NO_POSIX_BACKTRACKING << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, turn on internal regex debugging.
Packit 6f02de
   If not set, and debugging was on, turn it off.
Packit 6f02de
   This only works if regex.c is compiled -DDEBUG.
Packit 6f02de
   We define this bit always, so that all that's needed to turn on
Packit 6f02de
   debugging is to recompile regex.c; the calling code can always have
Packit 6f02de
   this bit set, and it won't affect anything in the normal case. */
Packit 6f02de
#define RE_DEBUG (RE_NO_GNU_OPS << 1)
Packit 6f02de
Packit 6f02de
/* This global variable defines the particular regexp syntax to use (for
Packit 6f02de
   some interfaces).  When a regexp is compiled, the syntax used is
Packit 6f02de
   stored in the pattern buffer, so changing this does not affect
Packit 6f02de
   already-compiled regexps.  */
Packit 6f02de
extern reg_syntax_t re_syntax_options;
Packit 6f02de

Packit 6f02de
/* Define combinations of the above bits for the standard possibilities.
Packit 6f02de
   (The [[[ comments delimit what gets put into the Texinfo file, so
Packit 6f02de
   don't delete them!)  */
Packit 6f02de
/* [[[begin syntaxes]]] */
Packit 6f02de
#define RE_SYNTAX_EMACS 0
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_AWK							\
Packit 6f02de
  (RE_BACKSLASH_ESCAPE_IN_LISTS   | RE_DOT_NOT_NULL			\
Packit 6f02de
   | RE_NO_BK_PARENS              | RE_NO_BK_REFS			\
Packit 6f02de
   | RE_NO_BK_VBAR                | RE_NO_EMPTY_RANGES			\
Packit 6f02de
   | RE_DOT_NEWLINE		  | RE_CONTEXT_INDEP_ANCHORS		\
Packit 6f02de
   | RE_UNMATCHED_RIGHT_PAREN_ORD | RE_NO_GNU_OPS)
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_GNU_AWK						\
Packit 6f02de
  ((RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS | RE_DEBUG)	\
Packit 6f02de
   & ~(RE_DOT_NOT_NULL | RE_INTERVALS | RE_CONTEXT_INDEP_OPS))
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_POSIX_AWK 						\
Packit 6f02de
  (RE_SYNTAX_POSIX_EXTENDED | RE_BACKSLASH_ESCAPE_IN_LISTS		\
Packit 6f02de
   | RE_INTERVALS	    | RE_NO_GNU_OPS)
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_GREP							\
Packit 6f02de
  (RE_BK_PLUS_QM              | RE_CHAR_CLASSES				\
Packit 6f02de
   | RE_HAT_LISTS_NOT_NEWLINE | RE_INTERVALS				\
Packit 6f02de
   | RE_NEWLINE_ALT)
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_EGREP							\
Packit 6f02de
  (RE_CHAR_CLASSES        | RE_CONTEXT_INDEP_ANCHORS			\
Packit 6f02de
   | RE_CONTEXT_INDEP_OPS | RE_HAT_LISTS_NOT_NEWLINE			\
Packit 6f02de
   | RE_NEWLINE_ALT       | RE_NO_BK_PARENS				\
Packit 6f02de
   | RE_NO_BK_VBAR)
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_POSIX_EGREP						\
Packit 6f02de
  (RE_SYNTAX_EGREP | RE_INTERVALS | RE_NO_BK_BRACES)
Packit 6f02de
Packit 6f02de
/* P1003.2/D11.2, section 4.20.7.1, lines 5078ff.  */
Packit 6f02de
#define RE_SYNTAX_ED RE_SYNTAX_POSIX_BASIC
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_SED RE_SYNTAX_POSIX_BASIC
Packit 6f02de
Packit 6f02de
/* Syntax bits common to both basic and extended POSIX regex syntax.  */
Packit 6f02de
#define _RE_SYNTAX_POSIX_COMMON						\
Packit 6f02de
  (RE_CHAR_CLASSES | RE_DOT_NEWLINE      | RE_DOT_NOT_NULL		\
Packit 6f02de
   | RE_INTERVALS  | RE_NO_EMPTY_RANGES)
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_POSIX_BASIC						\
Packit 6f02de
  (_RE_SYNTAX_POSIX_COMMON | RE_BK_PLUS_QM)
Packit 6f02de
Packit 6f02de
/* Differs from ..._POSIX_BASIC only in that RE_BK_PLUS_QM becomes
Packit 6f02de
   RE_LIMITED_OPS, i.e., \? \+ \| are not recognized.  Actually, this
Packit 6f02de
   isn't minimal, since other operators, such as \`, aren't disabled.  */
Packit 6f02de
#define RE_SYNTAX_POSIX_MINIMAL_BASIC					\
Packit 6f02de
  (_RE_SYNTAX_POSIX_COMMON | RE_LIMITED_OPS)
Packit 6f02de
Packit 6f02de
#define RE_SYNTAX_POSIX_EXTENDED					\
Packit 6f02de
  (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS			\
Packit 6f02de
   | RE_CONTEXT_INDEP_OPS   | RE_NO_BK_BRACES				\
Packit 6f02de
   | RE_NO_BK_PARENS        | RE_NO_BK_VBAR				\
Packit 6f02de
   | RE_CONTEXT_INVALID_OPS | RE_UNMATCHED_RIGHT_PAREN_ORD)
Packit 6f02de
Packit 6f02de
/* Differs from ..._POSIX_EXTENDED in that RE_CONTEXT_INDEP_OPS is
Packit 6f02de
   removed and RE_NO_BK_REFS is added.  */
Packit 6f02de
#define RE_SYNTAX_POSIX_MINIMAL_EXTENDED				\
Packit 6f02de
  (_RE_SYNTAX_POSIX_COMMON  | RE_CONTEXT_INDEP_ANCHORS			\
Packit 6f02de
   | RE_CONTEXT_INVALID_OPS | RE_NO_BK_BRACES				\
Packit 6f02de
   | RE_NO_BK_PARENS        | RE_NO_BK_REFS				\
Packit 6f02de
   | RE_NO_BK_VBAR	    | RE_UNMATCHED_RIGHT_PAREN_ORD)
Packit 6f02de
/* [[[end syntaxes]]] */
Packit 6f02de

Packit 6f02de
/* Maximum number of duplicates an interval can allow.  Some systems
Packit 6f02de
   (erroneously) define this in other header files, but we want our
Packit 6f02de
   value, so remove any previous define.  */
Packit 6f02de
#ifdef RE_DUP_MAX
Packit 6f02de
# undef RE_DUP_MAX
Packit 6f02de
#endif
Packit 6f02de
/* If sizeof(int) == 2, then ((1 << 15) - 1) overflows.  */
Packit 6f02de
#define RE_DUP_MAX (0x7fff)
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* POSIX `cflags' bits (i.e., information for `regcomp').  */
Packit 6f02de
Packit 6f02de
/* If this bit is set, then use extended regular expression syntax.
Packit 6f02de
   If not set, then use basic regular expression syntax.  */
Packit 6f02de
#define REG_EXTENDED 1
Packit 6f02de
Packit 6f02de
/* If this bit is set, then ignore case when matching.
Packit 6f02de
   If not set, then case is significant.  */
Packit 6f02de
#define REG_ICASE (REG_EXTENDED << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then anchors do not match at newline
Packit 6f02de
     characters in the string.
Packit 6f02de
   If not set, then anchors do match at newlines.  */
Packit 6f02de
#define REG_NEWLINE (REG_ICASE << 1)
Packit 6f02de
Packit 6f02de
/* If this bit is set, then report only success or fail in regexec.
Packit 6f02de
   If not set, then returns differ between not matching and errors.  */
Packit 6f02de
#define REG_NOSUB (REG_NEWLINE << 1)
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* POSIX `eflags' bits (i.e., information for regexec).  */
Packit 6f02de
Packit 6f02de
/* If this bit is set, then the beginning-of-line operator doesn't match
Packit 6f02de
     the beginning of the string (presumably because it's not the
Packit 6f02de
     beginning of a line).
Packit 6f02de
   If not set, then the beginning-of-line operator does match the
Packit 6f02de
     beginning of the string.  */
Packit 6f02de
#define REG_NOTBOL 1
Packit 6f02de
Packit 6f02de
/* Like REG_NOTBOL, except for the end-of-line.  */
Packit 6f02de
#define REG_NOTEOL (1 << 1)
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* If any error codes are removed, changed, or added, update the
Packit 6f02de
   `re_error_msg' table in regex.c.  */
Packit 6f02de
typedef enum
Packit 6f02de
{
Packit 6f02de
#ifdef _XOPEN_SOURCE
Packit 6f02de
  REG_ENOSYS = -1,	/* This will never happen for this implementation.  */
Packit 6f02de
#endif
Packit 6f02de
Packit 6f02de
  REG_NOERROR = 0,	/* Success.  */
Packit 6f02de
  REG_NOMATCH,		/* Didn't find a match (for regexec).  */
Packit 6f02de
Packit 6f02de
  /* POSIX regcomp return error codes.  (In the order listed in the
Packit 6f02de
     standard.)  */
Packit 6f02de
  REG_BADPAT,		/* Invalid pattern.  */
Packit 6f02de
  REG_ECOLLATE,		/* Not implemented.  */
Packit 6f02de
  REG_ECTYPE,		/* Invalid character class name.  */
Packit 6f02de
  REG_EESCAPE,		/* Trailing backslash.  */
Packit 6f02de
  REG_ESUBREG,		/* Invalid back reference.  */
Packit 6f02de
  REG_EBRACK,		/* Unmatched left bracket.  */
Packit 6f02de
  REG_EPAREN,		/* Parenthesis imbalance.  */
Packit 6f02de
  REG_EBRACE,		/* Unmatched \{.  */
Packit 6f02de
  REG_BADBR,		/* Invalid contents of \{\}.  */
Packit 6f02de
  REG_ERANGE,		/* Invalid range end.  */
Packit 6f02de
  REG_ESPACE,		/* Ran out of memory.  */
Packit 6f02de
  REG_BADRPT,		/* No preceding re for repetition op.  */
Packit 6f02de
Packit 6f02de
  /* Error codes we've added.  */
Packit 6f02de
  REG_EEND,		/* Premature end.  */
Packit 6f02de
  REG_ESIZE,		/* Compiled pattern bigger than 2^16 bytes.  */
Packit 6f02de
  REG_ERPAREN		/* Unmatched ) or \); not returned from regcomp. */
Packit 6f02de
} reg_errcode_t;
Packit 6f02de

Packit 6f02de
/* This data structure represents a compiled pattern.  Before calling
Packit 6f02de
   the pattern compiler, the fields `buffer', `allocated', `fastmap',
Packit 6f02de
   `translate', and `no_sub' can be set.  After the pattern has been
Packit 6f02de
   compiled, the `re_nsub' field is available.  All other fields are
Packit 6f02de
   private to the regex routines.  */
Packit 6f02de
Packit 6f02de
#ifndef RE_TRANSLATE_TYPE
Packit 6f02de
# define RE_TRANSLATE_TYPE char *
Packit 6f02de
#endif
Packit 6f02de
Packit 6f02de
struct re_pattern_buffer
Packit 6f02de
{
Packit 6f02de
/* [[[begin pattern_buffer]]] */
Packit 6f02de
	/* Space that holds the compiled pattern.  It is declared as
Packit 6f02de
          `unsigned char *' because its elements are
Packit 6f02de
           sometimes used as array indexes.  */
Packit 6f02de
  unsigned char *buffer;
Packit 6f02de
Packit 6f02de
	/* Number of bytes to which `buffer' points.  */
Packit 6f02de
  unsigned long int allocated;
Packit 6f02de
Packit 6f02de
	/* Number of bytes actually used in `buffer'.  */
Packit 6f02de
  unsigned long int used;
Packit 6f02de
Packit 6f02de
        /* Syntax setting with which the pattern was compiled.  */
Packit 6f02de
  reg_syntax_t syntax;
Packit 6f02de
Packit 6f02de
        /* Pointer to a fastmap, if any, otherwise zero.  re_search uses
Packit 6f02de
           the fastmap, if there is one, to skip over impossible
Packit 6f02de
           starting points for matches.  */
Packit 6f02de
  char *fastmap;
Packit 6f02de
Packit 6f02de
        /* Either a translate table to apply to all characters before
Packit 6f02de
           comparing them, or zero for no translation.  The translation
Packit 6f02de
           is applied to a pattern when it is compiled and to a string
Packit 6f02de
           when it is matched.  */
Packit 6f02de
  RE_TRANSLATE_TYPE translate;
Packit 6f02de
Packit 6f02de
	/* Number of subexpressions found by the compiler.  */
Packit 6f02de
  size_t re_nsub;
Packit 6f02de
Packit 6f02de
        /* Zero if this pattern cannot match the empty string, one else.
Packit 6f02de
           Well, in truth it's used only in `re_search_2', to see
Packit 6f02de
           whether or not we should use the fastmap, so we don't set
Packit 6f02de
           this absolutely perfectly; see `re_compile_fastmap' (the
Packit 6f02de
           `duplicate' case).  */
Packit 6f02de
  unsigned can_be_null : 1;
Packit 6f02de
Packit 6f02de
        /* If REGS_UNALLOCATED, allocate space in the `regs' structure
Packit 6f02de
             for `max (RE_NREGS, re_nsub + 1)' groups.
Packit 6f02de
           If REGS_REALLOCATE, reallocate space if necessary.
Packit 6f02de
           If REGS_FIXED, use what's there.  */
Packit 6f02de
#define REGS_UNALLOCATED 0
Packit 6f02de
#define REGS_REALLOCATE 1
Packit 6f02de
#define REGS_FIXED 2
Packit 6f02de
  unsigned regs_allocated : 2;
Packit 6f02de
Packit 6f02de
        /* Set to zero when `regex_compile' compiles a pattern; set to one
Packit 6f02de
           by `re_compile_fastmap' if it updates the fastmap.  */
Packit 6f02de
  unsigned fastmap_accurate : 1;
Packit 6f02de
Packit 6f02de
        /* If set, `re_match_2' does not return information about
Packit 6f02de
           subexpressions.  */
Packit 6f02de
  unsigned no_sub : 1;
Packit 6f02de
Packit 6f02de
        /* If set, a beginning-of-line anchor doesn't match at the
Packit 6f02de
           beginning of the string.  */
Packit 6f02de
  unsigned not_bol : 1;
Packit 6f02de
Packit 6f02de
        /* Similarly for an end-of-line anchor.  */
Packit 6f02de
  unsigned not_eol : 1;
Packit 6f02de
Packit 6f02de
        /* If true, an anchor at a newline matches.  */
Packit 6f02de
  unsigned newline_anchor : 1;
Packit 6f02de
Packit 6f02de
/* [[[end pattern_buffer]]] */
Packit 6f02de
};
Packit 6f02de
Packit 6f02de
typedef struct re_pattern_buffer regex_t;
Packit 6f02de

Packit 6f02de
/* Type for byte offsets within the string.  POSIX mandates this.  */
Packit 6f02de
typedef int regoff_t;
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* This is the structure we store register match data in.  See
Packit 6f02de
   regex.texinfo for a full description of what registers match.  */
Packit 6f02de
struct re_registers
Packit 6f02de
{
Packit 6f02de
  unsigned num_regs;
Packit 6f02de
  regoff_t *start;
Packit 6f02de
  regoff_t *end;
Packit 6f02de
};
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* If `regs_allocated' is REGS_UNALLOCATED in the pattern buffer,
Packit 6f02de
   `re_match_2' returns information about at least this many registers
Packit 6f02de
   the first time a `regs' structure is passed.  */
Packit 6f02de
#ifndef RE_NREGS
Packit 6f02de
# define RE_NREGS 30
Packit 6f02de
#endif
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* POSIX specification for registers.  Aside from the different names than
Packit 6f02de
   `re_registers', POSIX uses an array of structures, instead of a
Packit 6f02de
   structure of arrays.  */
Packit 6f02de
typedef struct
Packit 6f02de
{
Packit 6f02de
  regoff_t rm_so;  /* Byte offset from string's start to substring's start.  */
Packit 6f02de
  regoff_t rm_eo;  /* Byte offset from string's start to substring's end.  */
Packit 6f02de
} regmatch_t;
Packit 6f02de

Packit 6f02de
/* Declarations for routines.  */
Packit 6f02de
Packit 6f02de
/* To avoid duplicating every routine declaration -- once with a
Packit 6f02de
   prototype (if we are ANSI), and once without (if we aren't) -- we
Packit 6f02de
   use the following macro to declare argument types.  This
Packit 6f02de
   unfortunately clutters up the declarations a bit, but I think it's
Packit 6f02de
   worth it.  */
Packit 6f02de
Packit 6f02de
#if __STDC__
Packit 6f02de
Packit 6f02de
# define _RE_ARGS(args) args
Packit 6f02de
Packit 6f02de
#else /* not __STDC__ */
Packit 6f02de
Packit 6f02de
# define _RE_ARGS(args) ()
Packit 6f02de
Packit 6f02de
#endif /* not __STDC__ */
Packit 6f02de
Packit 6f02de
/* Sets the current default syntax to SYNTAX, and return the old syntax.
Packit 6f02de
   You can also simply assign to the `re_syntax_options' variable.  */
Packit 6f02de
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
Packit 6f02de
Packit 6f02de
/* Compile the regular expression PATTERN, with length LENGTH
Packit 6f02de
   and syntax given by the global `re_syntax_options', into the buffer
Packit 6f02de
   BUFFER.  Return NULL if successful, and an error string if not.  */
Packit 6f02de
extern const char *re_compile_pattern
Packit 6f02de
  _RE_ARGS ((const char *pattern, size_t length,
Packit 6f02de
             struct re_pattern_buffer *buffer));
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* Compile a fastmap for the compiled pattern in BUFFER; used to
Packit 6f02de
   accelerate searches.  Return 0 if successful and -2 if was an
Packit 6f02de
   internal error.  */
Packit 6f02de
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* Search in the string STRING (with length LENGTH) for the pattern
Packit 6f02de
   compiled into BUFFER.  Start searching at position START, for RANGE
Packit 6f02de
   characters.  Return the starting position of the match, -1 for no
Packit 6f02de
   match, or -2 for an internal error.  Also return register
Packit 6f02de
   information in REGS (if REGS and BUFFER->no_sub are nonzero).  */
Packit 6f02de
extern int re_search
Packit 6f02de
  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
Packit 6f02de
            int length, int start, int range, struct re_registers *regs));
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* Like `re_search', but search in the concatenation of STRING1 and
Packit 6f02de
   STRING2.  Also, stop searching at index START + STOP.  */
Packit 6f02de
extern int re_search_2
Packit 6f02de
  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
Packit 6f02de
             int length1, const char *string2, int length2,
Packit 6f02de
             int start, int range, struct re_registers *regs, int stop));
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* Like `re_search', but return how many characters in STRING the regexp
Packit 6f02de
   in BUFFER matched, starting at position START.  */
Packit 6f02de
extern int re_match
Packit 6f02de
  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
Packit 6f02de
             int length, int start, struct re_registers *regs));
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* Relates to `re_match' as `re_search_2' relates to `re_search'.  */
Packit 6f02de
extern int re_match_2
Packit 6f02de
  _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
Packit 6f02de
             int length1, const char *string2, int length2,
Packit 6f02de
             int start, struct re_registers *regs, int stop));
Packit 6f02de
Packit 6f02de
Packit 6f02de
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and
Packit 6f02de
   ENDS.  Subsequent matches using BUFFER and REGS will use this memory
Packit 6f02de
   for recording register information.  STARTS and ENDS must be
Packit 6f02de
   allocated with malloc, and must each be at least `NUM_REGS * sizeof
Packit 6f02de
   (regoff_t)' bytes long.
Packit 6f02de
Packit 6f02de
   If NUM_REGS == 0, then subsequent matches should allocate their own
Packit 6f02de
   register data.
Packit 6f02de
Packit 6f02de
   Unless this function is called, the first search or match using
Packit 6f02de
   PATTERN_BUFFER will allocate its own register data, without
Packit 6f02de
   freeing the old data.  */
Packit 6f02de
extern void re_set_registers
Packit 6f02de
  _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
Packit 6f02de
             unsigned num_regs, regoff_t *starts, regoff_t *ends));
Packit 6f02de
Packit 6f02de
#if defined _REGEX_RE_COMP || defined _LIBC
Packit 6f02de
# ifndef _CRAY
Packit 6f02de
/* 4.2 bsd compatibility.  */
Packit 6f02de
extern char *re_comp _RE_ARGS ((const char *));
Packit 6f02de
extern int re_exec _RE_ARGS ((const char *));
Packit 6f02de
# endif
Packit 6f02de
#endif
Packit 6f02de
Packit 6f02de
/* GCC 2.95 and later have "__restrict"; C99 compilers have
Packit 6f02de
   "restrict", and "configure" may have defined "restrict".  */
Packit 6f02de
#ifndef __restrict
Packit 6f02de
# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
Packit 6f02de
#  if defined restrict || 199901L <= __STDC_VERSION__
Packit 6f02de
#   define __restrict restrict
Packit 6f02de
#  else
Packit 6f02de
#   define __restrict
Packit 6f02de
#  endif
Packit 6f02de
# endif
Packit 6f02de
#endif
Packit 6f02de
/* For now unconditionally define __restrict_arr to expand to nothing.
Packit 6f02de
   Ideally we would have a test for the compiler which allows defining
Packit 6f02de
   it to restrict.  */
Packit 6f02de
#define __restrict_arr
Packit 6f02de
Packit 6f02de
/* POSIX compatibility.  */
Packit 6f02de
extern int regcomp _RE_ARGS ((regex_t *__restrict __preg,
Packit 6f02de
			      const char *__restrict __pattern,
Packit 6f02de
			      int __cflags));
Packit 6f02de
Packit 6f02de
extern int regexec _RE_ARGS ((const regex_t *__restrict __preg,
Packit 6f02de
			      const char *__restrict __string, size_t __nmatch,
Packit 6f02de
			      regmatch_t __pmatch[__restrict_arr],
Packit 6f02de
			      int __eflags));
Packit 6f02de
Packit 6f02de
extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
Packit 6f02de
				  char *__errbuf, size_t __errbuf_size));
Packit 6f02de
Packit 6f02de
extern void regfree _RE_ARGS ((regex_t *__preg));
Packit 6f02de
Packit 6f02de
#ifdef __cplusplus
Packit 6f02de
}
Packit 6f02de
#endif	/* C++ */
Packit 6f02de
Packit 6f02de
#endif /* regex.h */
Packit 6f02de

Packit 6f02de
/*
Packit 6f02de
Local variables:
Packit 6f02de
make-backup-files: t
Packit 6f02de
version-control: t
Packit 6f02de
trim-versions-without-asking: nil
Packit 6f02de
End:
Packit 6f02de
*/
Packit 6f02de
Packit 6f02de
#else	/* !defined(USE_LIB_REGEX) */
Packit 6f02de
#include <regex.h>
Packit 6f02de
#endif	/* defined(USE_LIB_REGEX) */