G:/ScriptBasic/source/extensions/re/regcomp.c File Reference

#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include "regex.h"
#include "utils.h"
#include "regex2.h"
#include "cclass.h"
#include "cname.h"

Go to the source code of this file.

Data Structures

struct  parse

Defines

#define NPAREN   10
#define PEEK()   (*p->next)
#define PEEK2()   (*(p->next+1))
#define MORE()   (p->next < p->end)
#define MORE2()   (p->next+1 < p->end)
#define SEE(c)   (MORE() && PEEK() == (c))
#define SEETWO(a, b)   (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
#define EAT(c)   ((SEE(c)) ? (NEXT(), 1) : 0)
#define EATTWO(a, b)   ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
#define NEXT()   (p->next++)
#define NEXT2()   (p->next += 2)
#define NEXTn(n)   (p->next += (n))
#define GETNEXT()   (*p->next++)
#define SETERROR(e)   seterr(p, (e))
#define REQUIRE(co, e)   ((co) || SETERROR(e))
#define MUSTSEE(c, e)   (REQUIRE(MORE() && PEEK() == (c), e))
#define MUSTEAT(c, e)   (REQUIRE(MORE() && GETNEXT() == (c), e))
#define MUSTNOTSEE(c, e)   (REQUIRE(!MORE() || PEEK() != (c), e))
#define EMIT(op, sopnd)   doemit(p, (sop)(op), (size_t)(sopnd))
#define INSERT(op, pos)   doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
#define AHEAD(pos)   dofwd(p, pos, HERE()-(pos))
#define ASTERN(sop, pos)   EMIT(sop, HERE()-pos)
#define HERE()   (p->slen)
#define THERE()   (p->slen - 1)
#define THERETHERE()   (p->slen - 2)
#define DROP(n)   (p->slen -= (n))
#define never   0
#define GOODFLAGS(f)   ((f)&~REG_DUMP)
#define BACKSL   (1<<CHAR_BIT)
#define N   2
#define INF   3
#define REP(f, t)   ((f)*8 + (t))
#define MAP(n)   (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)

Functions

static void p_ere __P ((struct parse *p, int stop))
static void p_ere_exp __P ((struct parse *p))
static void p_bre __P ((struct parse *p, int end1, int end2))
static int p_simp_re __P ((struct parse *p, int starordinary))
static void p_b_term __P ((struct parse *p, cset *cs))
static char p_b_coll_elem __P ((struct parse *p, int endc))
static char othercase __P ((int ch))
static void bothcases __P ((struct parse *p, int ch))
static void repeat __P ((struct parse *p, sopno start, int from, int to))
static int seterr __P ((struct parse *p, int e))
static void mcadd __P ((struct parse *p, cset *cs, char *cp))
static void mcsub __P ((cset *cs, char *cp))
static int isinsets __P ((struct re_guts *g, int c))
static int samesets __P ((struct re_guts *g, int c1, int c2))
static void categorize __P ((struct parse *p, struct re_guts *g))
static sopno dupl __P ((struct parse *p, sopno start, sopno finish))
static void doemit __P ((struct parse *p, sop op, size_t opnd))
static void doinsert __P ((struct parse *p, sop op, size_t opnd, sopno pos))
static void dofwd __P ((struct parse *p, sopno pos, sop value))
static void enlarge __P ((struct parse *p, sopno size))
int __stdcall regcomp (regex_t *preg, const char *pattern, int cflags)
static void p_ere (struct parse *p, int stop)
static void p_ere_exp (struct parse *p)
static void p_str (struct parse *p)
static void p_bre (struct parse *p, int end1, int end2)
static int p_simp_re (struct parse *p, int starordinary)
static int p_count (struct parse *p)
static void p_bracket (struct parse *p)
static void p_b_term (struct parse *p, cset *cs)
static void p_b_cclass (struct parse *p, cset *cs)
static void p_b_eclass (struct parse *p, cset *cs)
static char p_b_symbol (struct parse *p)
static char p_b_coll_elem (struct parse *p, int endc)
static char othercase (int ch)
static void bothcases (struct parse *p, int ch)
static void ordinary (struct parse *p, int ch)
static void nonnewline (struct parse *p)
static void repeat (struct parse *p, sopno start, int from, int to)
static int seterr (struct parse *p, int e)
static csetallocset (struct parse *p)
static void freeset (struct parse *p, cset *cs)
static int freezeset (struct parse *p, cset *cs)
static int firstch (struct parse *p, cset *cs)
static int nch (struct parse *p, cset *cs)
static void mcadd (struct parse *p, cset *cs, char *cp)
static void mcsub (cset *cs, char *cp)
static int mcin (cset *cs, char *cp)
static char * mcfind (cset *cs, char *cp)
static void mcinvert (struct parse *p, cset *cs)
static void mccase (struct parse *p, cset *cs)
static int isinsets (struct re_guts *g, int c)
static int samesets (struct re_guts *g, int c1, int c2)
static void categorize (struct parse *p, struct re_guts *g)
static sopno dupl (struct parse *p, sopno start, sopno finish)
static void doemit (struct parse *p, sop op, size_t opnd)
static void doinsert (struct parse *p, sop op, size_t opnd, sopno pos)
static void dofwd (struct parse *p, sopno pos, sop value)
static void enlarge (struct parse *p, sopno size)
static void stripsnug (struct parse *p, struct re_guts *g)
static void findmust (struct parse *p, struct re_guts *g)
static sopno pluscount (struct parse *p, struct re_guts *g)

Variables

static char nuls [10]


Define Documentation

#define AHEAD pos   )     dofwd(p, pos, HERE()-(pos))
 

Definition at line 153 of file regcomp.c.

Referenced by p_ere(), p_ere_exp(), and repeat().

#define ASTERN sop,
pos   )     EMIT(sop, HERE()-pos)
 

Definition at line 154 of file regcomp.c.

Referenced by p_ere(), p_ere_exp(), p_simp_re(), and repeat().

#define BACKSL   (1<<CHAR_BIT)
 

Referenced by p_simp_re().

#define DROP  )     (p->slen -= (n))
 

Definition at line 158 of file regcomp.c.

Referenced by p_bre(), and repeat().

#define EAT  )     ((SEE(c)) ? (NEXT(), 1) : 0)
 

Definition at line 140 of file regcomp.c.

Referenced by p_b_term(), p_bracket(), p_bre(), p_ere(), p_ere_exp(), and p_simp_re().

#define EATTWO a,
 )     ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
 

Definition at line 141 of file regcomp.c.

Referenced by p_b_symbol(), p_b_term(), and p_simp_re().

#define EMIT op,
sopnd   )     doemit(p, (sop)(op), (size_t)(sopnd))
 

Definition at line 151 of file regcomp.c.

Referenced by doinsert(), isapi_report(), ordinary(), p_bracket(), p_bre(), p_ere(), p_ere_exp(), p_simp_re(), and repeat().

 
#define GETNEXT  )     (*p->next++)
 

Definition at line 145 of file regcomp.c.

Referenced by p_b_symbol(), p_count(), p_ere_exp(), p_simp_re(), and p_str().

#define GOODFLAGS  )     ((f)&~REG_DUMP)
 

Referenced by regcomp(), and regexec().

 
#define HERE  )     (p->slen)
 

Definition at line 155 of file regcomp.c.

Referenced by doinsert(), dupl(), p_bre(), p_ere(), p_ere_exp(), p_simp_re(), and repeat().

#define INF   3
 

Referenced by repeat().

#define INSERT op,
pos   )     doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
 

Definition at line 152 of file regcomp.c.

Referenced by p_ere(), p_ere_exp(), p_simp_re(), and repeat().

#define MAP  )     (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
 

Referenced by repeat().

 
#define MORE  )     (p->next < p->end)
 

Definition at line 136 of file regcomp.c.

Referenced by p_b_cclass(), p_b_coll_elem(), p_b_symbol(), p_b_term(), p_bracket(), p_bre(), p_count(), p_ere(), p_ere_exp(), p_simp_re(), and p_str().

 
#define MORE2  )     (p->next+1 < p->end)
 

Definition at line 137 of file regcomp.c.

Referenced by p_b_term(), and p_ere_exp().

#define MUSTEAT c,
 )     (REQUIRE(MORE() && GETNEXT() == (c), e))
 

Definition at line 149 of file regcomp.c.

Referenced by p_bracket(), and p_ere_exp().

#define MUSTNOTSEE c,
 )     (REQUIRE(!MORE() || PEEK() != (c), e))
 

Definition at line 150 of file regcomp.c.

#define MUSTSEE c,
 )     (REQUIRE(MORE() && PEEK() == (c), e))
 

Definition at line 148 of file regcomp.c.

#define N   2
 

Referenced by repeat().

#define never   0
 

Definition at line 163 of file regcomp.c.

Referenced by firstch().

 
#define NEXT  )     (p->next++)
 

Definition at line 142 of file regcomp.c.

Referenced by p_b_cclass(), p_b_coll_elem(), p_b_term(), p_ere_exp(), and p_simp_re().

 
#define NEXT2  )     (p->next += 2)
 

Definition at line 143 of file regcomp.c.

Referenced by p_b_term().

#define NEXTn  )     (p->next += (n))
 

Definition at line 144 of file regcomp.c.

Referenced by p_bracket().

#define NPAREN   10
 

Definition at line 71 of file regcomp.c.

Referenced by doinsert(), p_ere_exp(), p_simp_re(), and regcomp().

 
#define PEEK  )     (*p->next)
 

Definition at line 134 of file regcomp.c.

Referenced by p_b_cclass(), p_b_term(), p_bracket(), p_count(), p_ere(), p_ere_exp(), and p_simp_re().

 
#define PEEK2  )     (*(p->next+1))
 

Definition at line 135 of file regcomp.c.

Referenced by p_b_term(), and p_ere_exp().

#define REP f,
 )     ((f)*8 + (t))
 

Referenced by repeat().

#define REQUIRE co,
 )     ((co) || SETERROR(e))
 

Definition at line 147 of file regcomp.c.

Referenced by p_b_symbol(), p_b_term(), p_bre(), p_count(), p_ere(), p_ere_exp(), p_simp_re(), and p_str().

#define SEE  )     (MORE() && PEEK() == (c))
 

Definition at line 138 of file regcomp.c.

Referenced by p_b_term(), and p_ere_exp().

#define SEETWO a,
 )     (MORE() && MORE2() && PEEK() == (a) && PEEK2() == (b))
 

Definition at line 139 of file regcomp.c.

Referenced by p_b_coll_elem(), p_bracket(), p_bre(), and p_simp_re().

#define SETERROR  )     seterr(p, (e))
 

Definition at line 146 of file regcomp.c.

Referenced by allocset(), enlarge(), mcadd(), p_b_cclass(), p_b_coll_elem(), p_b_term(), p_ere_exp(), p_simp_re(), repeat(), and stripsnug().

 
#define THERE  )     (p->slen - 1)
 

Definition at line 156 of file regcomp.c.

Referenced by p_ere(), p_ere_exp(), and repeat().

 
#define THERETHERE  )     (p->slen - 2)
 

Definition at line 157 of file regcomp.c.

Referenced by p_ere_exp(), and repeat().


Function Documentation

static void enlarge __P (struct parse *p, sopno size  )  [static]
 

static void dofwd __P (struct parse *p, sopno pos, sop value)   )  [static]
 

static void doinsert __P (struct parse *p, sop op, size_t opnd, sopno pos)   )  [static]
 

static void doemit __P (struct parse *p, sop op, size_t opnd)   )  [static]
 

static sopno dupl __P (struct parse *p, sopno start, sopno finish)   )  [static]
 

static sopno pluscount __P (struct parse *p, struct re_guts *g)   )  [static]
 

static int samesets __P (struct re_guts *g, int c1, int c2)   )  [static]
 

static int isinsets __P (struct re_guts *g, int c)   )  [static]
 

static char *mcfind __P (cset *cs, char *cp)   )  [static]
 

static void mcadd __P (struct parse *p, cset *cs, char *cp)   )  [static]
 

static int seterr __P (struct parse *p, int e)   )  [static]
 

static void repeat __P (struct parse *p, sopno start, int from, int to)   )  [static]
 

static void ordinary __P (struct parse *p, int ch  )  [static]
 

static char othercase __P (int ch  )  [static]
 

static char p_b_coll_elem __P (struct parse *p, int endc)   )  [static]
 

static void mccase __P (struct parse *p, cset *cs)   )  [static]
 

static int p_simp_re __P (struct parse *p, int starordinary)   )  [static]
 

static void p_bre __P (struct parse *p, int end1, int end2)   )  [static]
 

static cset *allocset __P (struct parse *p  )  [static]
 

static void p_ere __P (struct parse *p, int stop)   )  [static]
 

static cset* allocset struct parse p  )  [static]
 

Definition at line 1093 of file regcomp.c.

References assert, i, if(), memset(), NULL, REG_ESPACE, and SETERROR.

Referenced by p_bracket().

static void bothcases struct parse p,
int  ch
[static]
 

Definition at line 934 of file regcomp.c.

References assert, othercase(), and p_bracket().

Referenced by ordinary().

static void categorize struct parse p,
struct re_guts g
[static]
 

Definition at line 1402 of file regcomp.c.

References for(), isinsets(), and samesets().

static void doemit struct parse p,
sop  op,
size_t  opnd
[static]
 

Definition at line 1458 of file regcomp.c.

References assert, enlarge(), OPSHIFT, and SOP.

static void dofwd struct parse p,
sopno  pos,
sop  value
[static]
 

Definition at line 1524 of file regcomp.c.

References assert, OP, and OPSHIFT.

static void doinsert struct parse p,
sop  op,
size_t  opnd,
sopno  pos
[static]
 

Definition at line 1484 of file regcomp.c.

References assert, EMIT, HERE, i, NPAREN, and s.

static sopno dupl struct parse p,
sopno  start,
sopno  finish
[static]
 

Definition at line 1430 of file regcomp.c.

References assert, enlarge(), HERE, len, memcpy(), and ret.

Referenced by p_simp_re(), and repeat().

static void enlarge struct parse p,
sopno  size
[static]
 

Definition at line 1542 of file regcomp.c.

References NULL, REG_ESPACE, and SETERROR.

Referenced by doemit(), and dupl().

static void findmust struct parse p,
struct re_guts g
[static]
 

Definition at line 1588 of file regcomp.c.

References assert, BAD, i, NULL, O_CH, O_QUEST, OCH_, OCHAR, OEND, OLPAREN, OOR2, OP, OPLUS_, OPND, OQUEST_, ORPAREN, and s.

static int firstch struct parse p,
cset cs
[static]
 

Definition at line 1207 of file regcomp.c.

References assert, CHIN, for(), i, and never.

Referenced by p_bracket().

static void freeset struct parse p,
cset cs
[static]
 

Definition at line 1148 of file regcomp.c.

References CHsub, for(), and i.

Referenced by freezeset(), and p_bracket().

static int freezeset struct parse p,
cset cs
[static]
 

Definition at line 1173 of file regcomp.c.

References CHIN, for(), freeset(), cset::hash, and i.

Referenced by p_bracket().

static int isinsets struct re_guts g,
int  c
[static]
 

Definition at line 1360 of file regcomp.c.

References i.

Referenced by categorize().

static void mcadd struct parse p,
cset cs,
char *  cp
[static]
 

Definition at line 1246 of file regcomp.c.

References NULL, REG_ESPACE, SETERROR, and strcpy().

static void mccase struct parse p,
cset cs
[static]
 

Definition at line 1348 of file regcomp.c.

References assert, and NULL.

Referenced by p_bracket().

static char* mcfind cset cs,
char *  cp
[static]
 

Definition at line 1311 of file regcomp.c.

References NULL, and p.

Referenced by mcin(), and mcsub().

static int mcin cset cs,
char *  cp
[static]
 

Definition at line 1299 of file regcomp.c.

References mcfind(), and NULL.

static void mcinvert struct parse p,
cset cs
[static]
 

Definition at line 1333 of file regcomp.c.

References assert, and NULL.

Referenced by p_bracket().

static void mcsub cset cs,
char *  cp
[static]
 

Definition at line 1272 of file regcomp.c.

References assert, fp, free(), len, mcfind(), and NULL.

static int nch struct parse p,
cset cs
[static]
 

Definition at line 1226 of file regcomp.c.

References CHIN, for(), and i.

Referenced by lex_ReadInput(), and p_bracket().

static void nonnewline struct parse p  )  [static]
 

Definition at line 981 of file regcomp.c.

References assert, and p_bracket().

Referenced by p_ere_exp(), and p_simp_re().

static void ordinary struct parse p,
int  ch
[static]
 

Definition at line 959 of file regcomp.c.

References bothcases(), EMIT, OCHAR, othercase(), and REG_ICASE.

Referenced by p_bracket(), p_ere_exp(), p_simp_re(), and p_str().

static char othercase int  ch  )  [static]
 

Definition at line 915 of file regcomp.c.

References assert.

Referenced by bothcases(), ordinary(), and p_bracket().

static void p_b_cclass struct parse p,
cset cs
[static]
 

Definition at line 814 of file regcomp.c.

References cclasses, if(), len, MORE, cclass::name, NEXT, NULL, PEEK, REG_ECTYPE, and SETERROR.

Referenced by p_b_term().

static char p_b_coll_elem struct parse p,
int  endc
[static]
 

Definition at line 885 of file regcomp.c.

References cnames, cname::code, if(), len, MORE, cname::name, NEXT, NULL, REG_EBRACK, REG_ECOLLATE, SEETWO, and SETERROR.

Referenced by p_b_eclass(), and p_b_symbol().

static void p_b_eclass struct parse p,
cset cs
[static]
 

Definition at line 850 of file regcomp.c.

References CHadd, and p_b_coll_elem().

Referenced by p_b_term().

static char p_b_symbol struct parse p  )  [static]
 

Definition at line 865 of file regcomp.c.

References EATTWO, GETNEXT, MORE, p_b_coll_elem(), REG_EBRACK, REG_ECOLLATE, and REQUIRE.

Referenced by p_b_term().

static void p_b_term struct parse p,
cset cs
[static]
 

Definition at line 748 of file regcomp.c.

References CHadd, EAT, EATTWO, i, MORE, MORE2, NEXT, NEXT2, p_b_cclass(), p_b_eclass(), p_b_symbol(), PEEK, PEEK2, REG_EBRACK, REG_ECOLLATE, REG_ECTYPE, REG_ERANGE, REQUIRE, SEE, and SETERROR.

Referenced by p_bracket().

static void p_bracket struct parse p  )  [static]
 

Definition at line 673 of file regcomp.c.

References allocset(), assert, CHadd, CHIN, CHsub, EAT, EMIT, firstch(), freeset(), freezeset(), i, mccase(), mcinvert(), MORE, cset::multis, MUSTEAT, nch(), NEXTn, NULL, OANYOF, OBOW, OEOW, ordinary(), othercase(), p_b_term(), PEEK, REG_EBRACK, REG_ICASE, REG_NEWLINE, and SEETWO.

Referenced by bothcases(), nonnewline(), p_ere_exp(), and p_simp_re().

static void p_bre struct parse p,
int  end1,
int  end2
[static]
 

Definition at line 499 of file regcomp.c.

References DROP, EAT, EMIT, HERE, MORE, OBOL, OEOL, p_simp_re(), REG_EMPTY, REQUIRE, SEETWO, USEBOL, and USEEOL.

Referenced by p_simp_re().

static int p_count struct parse p  )  [static]
 

Definition at line 650 of file regcomp.c.

References count, DUPMAX, GETNEXT, MORE, PEEK, REG_BADBR, and REQUIRE.

Referenced by p_ere_exp(), and p_simp_re().

static void p_ere struct parse p,
int  stop
[static]
 

Definition at line 283 of file regcomp.c.

References AHEAD, ASTERN, EAT, EMIT, HERE, INSERT, MORE, OCH_, OOR1, OOR2, p_ere_exp(), PEEK, REG_EMPTY, REQUIRE, and THERE.

Referenced by p_ere_exp().

static void p_ere_exp struct parse p  )  [static]
 

Definition at line 329 of file regcomp.c.

References AHEAD, assert, ASTERN, count, EAT, EMIT, GETNEXT, HERE, INFINITY, INSERT, MORE, MORE2, MUSTEAT, NEXT, nonnewline(), NPAREN, O_CH, O_PLUS, O_QUEST, OANY, OBOL, OCH_, OEOL, OLPAREN, OOR1, OOR2, OPLUS_, OQUEST_, ordinary(), ORPAREN, p_bracket(), p_count(), p_ere(), PEEK, PEEK2, REG_BADBR, REG_BADRPT, REG_EBRACE, REG_EESCAPE, REG_EMPTY, REG_EPAREN, REG_NEWLINE, repeat(), REQUIRE, SEE, SETERROR, THERE, THERETHERE, USEBOL, and USEEOL.

Referenced by p_ere().

static int p_simp_re struct parse p,
int  starordinary
[static]
 

Definition at line 532 of file regcomp.c.

References assert, ASTERN, BACKSL, count, dupl(), EAT, EATTWO, EMIT, GETNEXT, HERE, i, INFINITY, INSERT, MORE, NEXT, nonnewline(), NPAREN, O_BACK, O_PLUS, O_QUEST, OANY, OBACK_, OLPAREN, OP, OPLUS_, OQUEST_, ordinary(), ORPAREN, p_bracket(), p_bre(), p_count(), PEEK, REG_BADBR, REG_BADRPT, REG_EBRACE, REG_EESCAPE, REG_EPAREN, REG_ESUBREG, REG_NEWLINE, repeat(), REQUIRE, SEETWO, and SETERROR.

Referenced by p_bre().

static void p_str struct parse p  )  [static]
 

Definition at line 478 of file regcomp.c.

References GETNEXT, MORE, ordinary(), REG_EMPTY, and REQUIRE.

static sopno pluscount struct parse p,
struct re_guts g
[static]
 

Definition at line 1669 of file regcomp.c.

References BAD, O_PLUS, OEND, OP, OPLUS_, and s.

int __stdcall regcomp regex_t preg,
const char *  pattern,
int  cflags
 

Definition at line 179 of file regcomp.c.

References free(), parse::g, GOODFLAGS, i, len, NC, NPAREN, NULL, p, REG_ESPACE, REG_EXTENDED, REG_INVARG, REG_NOSPEC, and REG_PEND.

Referenced by main().

static void repeat struct parse p,
sopno  start,
int  from,
int  to
[static]
 

Definition at line 1005 of file regcomp.c.

References AHEAD, assert, ASTERN, DROP, dupl(), EMIT, HERE, INF, INSERT, MAP, N, O_CH, O_PLUS, OCH_, OOR1, OOR2, OPLUS_, REG_ASSERT, REP, SETERROR, THERE, and THERETHERE.

Referenced by p_ere_exp(), and p_simp_re().

static int samesets struct re_guts g,
int  c1,
int  c2
[static]
 

Definition at line 1380 of file regcomp.c.

References i.

Referenced by categorize().

static int seterr struct parse p,
int  e
[static]
 

Definition at line 1077 of file regcomp.c.

References nuls.

static void stripsnug struct parse p,
struct re_guts g
[static]
 

Definition at line 1565 of file regcomp.c.

References NULL, REG_ESPACE, and SETERROR.


Variable Documentation

char nuls[10] [static]
 

Definition at line 128 of file regcomp.c.

Referenced by seterr().


Generated on Sun Mar 12 23:56:37 2006 for ScriptBasic by  doxygen 1.4.6-NO