1999-08-24 12:21:56 +04:00
|
|
|
/* Definitions for data structures and routines for the regular
|
|
|
|
expression library, version 0.12.
|
|
|
|
Copyright (C) 1985,89,90,91,92,93,95,96,97,98 Free Software Foundation, Inc.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
This file is part of the GNU C Library. Its master source is NOT part of
|
|
|
|
the C library, however. The master source lives in /gd/gnu/lib.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Library General Public License as
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
License, or (at your option) any later version.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
1998-01-16 15:13:05 +03:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
1999-08-24 12:21:56 +04:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Library General Public License for more details.
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-24 12:21:56 +04:00
|
|
|
You should have received a copy of the GNU Library General Public
|
2001-07-11 23:25:52 +04:00
|
|
|
License along with the GNU C Library; see the file LGPL. If not,
|
1999-08-24 12:21:56 +04:00
|
|
|
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
Boston, MA 02111-1307, USA. */
|
1998-01-16 15:13:05 +03:00
|
|
|
/* Multi-byte extension added May, 1993 by t^2 (Takahiro Tanimoto)
|
|
|
|
Last change: May 21, 1993 by t^2 */
|
1999-08-13 09:45:20 +04:00
|
|
|
/* modified for Ruby by matz@netlab.co.jp */
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
#ifndef REGEX_H
|
|
|
|
#define REGEX_H
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
/* symbol mangling for ruby */
|
|
|
|
#ifdef RUBY
|
1999-12-14 09:50:43 +03:00
|
|
|
# define re_adjust_startpos ruby_re_adjust_startpos
|
1999-08-13 09:45:20 +04:00
|
|
|
# define re_compile_fastmap ruby_re_compile_fastmap
|
|
|
|
# define re_compile_pattern ruby_re_compile_pattern
|
|
|
|
# define re_copy_registers ruby_re_copy_registers
|
|
|
|
# define re_free_pattern ruby_re_free_pattern
|
|
|
|
# define re_free_registers ruby_re_free_registers
|
|
|
|
# define re_match ruby_re_match
|
|
|
|
# define re_mbcinit ruby_re_mbcinit
|
|
|
|
# define re_search ruby_re_search
|
|
|
|
# define re_set_casetable ruby_re_set_casetable
|
|
|
|
# define register_info_type ruby_register_info_type
|
|
|
|
#endif
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
#include <stddef.h>
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/* Define number of parens for which we record the beginnings and ends.
|
|
|
|
This affects how much space the `struct re_registers' type takes up. */
|
|
|
|
#ifndef RE_NREGS
|
|
|
|
#define RE_NREGS 10
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define BYTEWIDTH 8
|
|
|
|
|
1998-01-16 15:19:22 +03:00
|
|
|
#define RE_REG_MAX ((1<<BYTEWIDTH)-1)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/* Maximum number of duplicates an interval can allow. */
|
|
|
|
#ifndef RE_DUP_MAX
|
|
|
|
#define RE_DUP_MAX ((1 << 15) - 1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
/* If this bit is set, then character classes are supported; they are:
|
|
|
|
[:alpha:], [:upper:], [:lower:], [:digit:], [:alnum:], [:xdigit:],
|
|
|
|
[:space:], [:print:], [:punct:], [:graph:], and [:cntrl:].
|
|
|
|
If not set, then character classes are not supported. */
|
|
|
|
#define RE_CHAR_CLASSES (1L << 9)
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
/* match will be done case insensetively */
|
|
|
|
#define RE_OPTION_IGNORECASE (1L)
|
|
|
|
/* perl-style extended pattern available */
|
|
|
|
#define RE_OPTION_EXTENDED (RE_OPTION_IGNORECASE<<1)
|
2000-05-17 10:33:50 +04:00
|
|
|
/* newline will be included for . */
|
2000-05-24 08:34:26 +04:00
|
|
|
#define RE_OPTION_MULTILINE (RE_OPTION_EXTENDED<<1)
|
|
|
|
/* ^ and $ ignore newline */
|
|
|
|
#define RE_OPTION_SINGLELINE (RE_OPTION_MULTILINE<<1)
|
1999-08-13 09:45:20 +04:00
|
|
|
/* search for longest match, in accord with POSIX regexp */
|
2000-05-25 09:55:12 +04:00
|
|
|
#define RE_OPTION_LONGEST (RE_OPTION_SINGLELINE<<1)
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
#define RE_MAY_IGNORECASE (RE_OPTION_LONGEST<<1)
|
|
|
|
#define RE_OPTIMIZE_ANCHOR (RE_MAY_IGNORECASE<<1)
|
|
|
|
#define RE_OPTIMIZE_EXACTN (RE_OPTIMIZE_ANCHOR<<1)
|
|
|
|
#define RE_OPTIMIZE_NO_BM (RE_OPTIMIZE_EXACTN<<1)
|
1999-12-06 12:04:03 +03:00
|
|
|
#define RE_OPTIMIZE_BMATCH (RE_OPTIMIZE_NO_BM<<1)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/* For multi-byte char support */
|
1999-01-20 07:59:39 +03:00
|
|
|
#define MBCTYPE_ASCII 0
|
|
|
|
#define MBCTYPE_EUC 1
|
|
|
|
#define MBCTYPE_SJIS 2
|
|
|
|
#define MBCTYPE_UTF8 3
|
1998-01-16 15:13:05 +03:00
|
|
|
|
2000-06-07 19:49:37 +04:00
|
|
|
#if defined IMPORT || defined USEIMPORTLIB
|
2000-05-30 08:24:17 +04:00
|
|
|
extern __declspec(dllimport)
|
|
|
|
#elif defined EXPORT
|
|
|
|
extern __declspec(dllexport)
|
|
|
|
#else
|
|
|
|
extern
|
|
|
|
#endif
|
|
|
|
const unsigned char *re_mbctab;
|
1999-08-13 09:45:20 +04:00
|
|
|
#if defined(__STDC__)
|
1999-01-20 07:59:39 +03:00
|
|
|
void re_mbcinit (int);
|
1998-01-16 15:13:05 +03:00
|
|
|
#else
|
1999-01-20 07:59:39 +03:00
|
|
|
void re_mbcinit ();
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#undef ismbchar
|
1999-01-20 07:59:39 +03:00
|
|
|
#define ismbchar(c) re_mbctab[(unsigned char)(c)]
|
|
|
|
#define mbclen(c) (re_mbctab[(unsigned char)(c)]+1)
|
1998-01-16 15:13:05 +03:00
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
/* Structure used in re_match() */
|
|
|
|
|
|
|
|
typedef union
|
|
|
|
{
|
|
|
|
unsigned char *word;
|
|
|
|
struct {
|
|
|
|
unsigned is_active : 1;
|
|
|
|
unsigned matched_something : 1;
|
|
|
|
} bits;
|
|
|
|
} register_info_type;
|
|
|
|
|
1998-01-16 15:13:05 +03:00
|
|
|
/* This data structure is used to represent a compiled pattern. */
|
|
|
|
|
|
|
|
struct re_pattern_buffer
|
|
|
|
{
|
|
|
|
char *buffer; /* Space holding the compiled pattern commands. */
|
1999-08-13 09:45:20 +04:00
|
|
|
int allocated; /* Size of space that `buffer' points to. */
|
|
|
|
int used; /* Length of portion of buffer actually occupied */
|
1998-01-16 15:13:05 +03:00
|
|
|
char *fastmap; /* Pointer to fastmap, if any, or zero if none. */
|
|
|
|
/* re_search uses the fastmap, if there is one,
|
|
|
|
to skip over totally implausible characters. */
|
1998-01-16 15:19:22 +03:00
|
|
|
char *must; /* Pointer to exact pattern which strings should have
|
|
|
|
to be matched. */
|
1999-01-20 07:59:39 +03:00
|
|
|
int *must_skip; /* Pointer to exact pattern skip table for bm_search */
|
|
|
|
long options; /* Flags for options such as extended_pattern. */
|
1998-01-16 15:13:05 +03:00
|
|
|
long re_nsub; /* Number of subexpressions found by the compiler. */
|
|
|
|
char fastmap_accurate;
|
|
|
|
/* Set to zero when a new pattern is stored,
|
|
|
|
set to one when the fastmap is updated from it. */
|
|
|
|
char can_be_null; /* Set to one by compiling fastmap
|
|
|
|
if this pattern might match the null string.
|
|
|
|
It does not necessarily match the null string
|
|
|
|
in that case, but if this is zero, it cannot.
|
|
|
|
2 as value means can match null string
|
|
|
|
but at end of range or before a character
|
|
|
|
listed in the fastmap. */
|
1999-08-13 09:45:20 +04:00
|
|
|
|
|
|
|
/* stack & working area for re_match() */
|
|
|
|
unsigned char **regstart;
|
|
|
|
unsigned char **regend;
|
|
|
|
unsigned char **old_regstart;
|
|
|
|
unsigned char **old_regend;
|
|
|
|
register_info_type *reg_info;
|
|
|
|
unsigned char **best_regstart;
|
|
|
|
unsigned char **best_regend;
|
1998-01-16 15:13:05 +03:00
|
|
|
};
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
typedef struct re_pattern_buffer regex_t;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
/* Structure 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. */
|
|
|
|
|
|
|
|
struct re_registers
|
|
|
|
{
|
1999-08-13 09:45:20 +04:00
|
|
|
int allocated;
|
|
|
|
int num_regs;
|
1998-01-16 15:13:05 +03:00
|
|
|
int *beg;
|
|
|
|
int *end;
|
|
|
|
};
|
|
|
|
|
1999-01-20 07:59:39 +03:00
|
|
|
/* Type for byte offsets within the string. POSIX mandates this. */
|
|
|
|
typedef size_t regoff_t;
|
|
|
|
|
|
|
|
/* POSIX specification for registers. Aside from the different names than
|
|
|
|
`re_registers', POSIX uses an array of structures, instead of a
|
|
|
|
structure of arrays. */
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
regoff_t rm_so; /* Byte offset from string's start to substring's start. */
|
|
|
|
regoff_t rm_eo; /* Byte offset from string's start to substring's end. */
|
|
|
|
} regmatch_t;
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#ifdef __STDC__
|
|
|
|
|
1999-08-13 09:45:20 +04:00
|
|
|
extern char *re_compile_pattern (const char *, int, struct re_pattern_buffer *);
|
1999-01-20 07:59:39 +03:00
|
|
|
void re_free_pattern (struct re_pattern_buffer *);
|
1998-01-16 15:13:05 +03:00
|
|
|
/* Is this really advertised? */
|
1999-12-14 09:50:43 +03:00
|
|
|
extern int re_adjust_startpos (struct re_pattern_buffer *, const char*, int, int, int);
|
1998-01-16 15:13:05 +03:00
|
|
|
extern void re_compile_fastmap (struct re_pattern_buffer *);
|
1999-08-13 09:45:20 +04:00
|
|
|
extern int re_search (struct re_pattern_buffer *, const char*, int, int, int,
|
1998-01-16 15:13:05 +03:00
|
|
|
struct re_registers *);
|
1999-08-13 09:45:20 +04:00
|
|
|
extern int re_match (struct re_pattern_buffer *, const char *, int, int,
|
1998-01-16 15:13:05 +03:00
|
|
|
struct re_registers *);
|
1999-08-13 09:45:20 +04:00
|
|
|
extern void re_set_casetable (const char *table);
|
1998-01-16 15:13:05 +03:00
|
|
|
extern void re_copy_registers (struct re_registers*, struct re_registers*);
|
1999-01-20 07:59:39 +03:00
|
|
|
extern void re_free_registers (struct re_registers*);
|
1998-01-16 15:13:05 +03:00
|
|
|
|
|
|
|
#ifndef RUBY
|
|
|
|
/* 4.2 bsd compatibility. */
|
1999-08-13 09:45:20 +04:00
|
|
|
extern char *re_comp (const char *);
|
|
|
|
extern int re_exec (const char *);
|
1998-01-16 15:13:05 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#else /* !__STDC__ */
|
|
|
|
|
|
|
|
extern char *re_compile_pattern ();
|
1999-01-20 07:59:39 +03:00
|
|
|
void re_free_regexp ();
|
1998-01-16 15:13:05 +03:00
|
|
|
/* Is this really advertised? */
|
1999-12-14 09:50:43 +03:00
|
|
|
extern int re_adjust_startpos ();
|
1998-01-16 15:13:05 +03:00
|
|
|
extern void re_compile_fastmap ();
|
|
|
|
extern int re_search ();
|
|
|
|
extern int re_match ();
|
1999-01-20 07:59:39 +03:00
|
|
|
extern void re_set_casetable ();
|
1998-01-16 15:13:05 +03:00
|
|
|
extern void re_copy_registers ();
|
|
|
|
extern void re_free_registers ();
|
|
|
|
|
|
|
|
#endif /* __STDC__ */
|
|
|
|
|
2002-04-24 08:54:16 +04:00
|
|
|
#endif /* !REGEX_H */
|