diff options
Diffstat (limited to 'lib/libc/regex/regcomp.c')
-rw-r--r-- | lib/libc/regex/regcomp.c | 135 |
1 files changed, 38 insertions, 97 deletions
diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index 078be76265a..ad90f1975c7 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)regcomp.c 8.5 (Berkeley) 3/20/94"; #else -static char rcsid[] = "$OpenBSD: regcomp.c,v 1.13 2004/10/17 17:58:54 otto Exp $"; +static char rcsid[] = "$OpenBSD: regcomp.c,v 1.14 2004/11/30 17:04:23 otto Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -73,54 +73,43 @@ struct parse { sopno pend[NPAREN]; /* -> ) ([0] unused) */ }; -/* ========= begin header generated by ./mkh ========= */ -#ifdef __cplusplus -extern "C" { -#endif - -/* === regcomp.c === */ -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 cset *allocset(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 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); - -#ifdef __cplusplus -} -#endif -/* ========= end header generated by ./mkh ========= */ +static void p_ere(struct parse *, int); +static void p_ere_exp(struct parse *); +static void p_str(struct parse *); +static void p_bre(struct parse *, int, int); +static int p_simp_re(struct parse *, int); +static int p_count(struct parse *); +static void p_bracket(struct parse *); +static void p_b_term(struct parse *, cset *); +static void p_b_cclass(struct parse *, cset *); +static void p_b_eclass(struct parse *, cset *); +static char p_b_symbol(struct parse *); +static char p_b_coll_elem(struct parse *, int); +static char othercase(int); +static void bothcases(struct parse *, int); +static void ordinary(struct parse *, int); +static void nonnewline(struct parse *); +static void repeat(struct parse *, sopno, int, int); +static int seterr(struct parse *, int); +static cset *allocset(struct parse *); +static void freeset(struct parse *, cset *); +static int freezeset(struct parse *, cset *); +static int firstch(struct parse *, cset *); +static int nch(struct parse *, cset *); +static void mcadd(struct parse *, cset *, char *); +static void mcinvert(struct parse *, cset *); +static void mccase(struct parse *, cset *); +static int isinsets(struct re_guts *, int); +static int samesets(struct re_guts *, int, int); +static void categorize(struct parse *, struct re_guts *); +static sopno dupl(struct parse *, sopno, sopno); +static void doemit(struct parse *, sop, size_t); +static void doinsert(struct parse *, sop, size_t, sopno); +static void dofwd(struct parse *, sopno, sop); +static void enlarge(struct parse *, sopno); +static void stripsnug(struct parse *, struct re_guts *); +static void findmust(struct parse *, struct re_guts *); +static sopno pluscount(struct parse *, struct re_guts *); static char nuls[10]; /* place to point scanner in event of error */ @@ -162,15 +151,6 @@ static int never = 0; /* for use in asserts; shuts lint up */ /* - regcomp - interface for parser and compilation - = extern int regcomp(regex_t *, const char *, int); - = #define REG_BASIC 0000 - = #define REG_EXTENDED 0001 - = #define REG_ICASE 0002 - = #define REG_NOSUB 0004 - = #define REG_NEWLINE 0010 - = #define REG_NOSPEC 0020 - = #define REG_PEND 0040 - = #define REG_DUMP 0200 */ int /* 0 success, otherwise REG_something */ regcomp(regex_t *preg, const char *pattern, int cflags) @@ -271,7 +251,6 @@ regcomp(regex_t *preg, const char *pattern, int cflags) /* - p_ere - ERE parser top level, concatenation and alternation - == static void p_ere(struct parse *p, int stop); */ static void p_ere(struct parse *p, int stop) /* character this ERE should end at */ @@ -315,7 +294,6 @@ p_ere(struct parse *p, int stop) /* character this ERE should end at */ /* - p_ere_exp - parse one subERE, an atom possibly followed by a repetition op - == static void p_ere_exp(struct parse *p); */ static void p_ere_exp(struct parse *p) @@ -463,7 +441,6 @@ p_ere_exp(struct parse *p) /* - p_str - string (no metacharacters) "parser" - == static void p_str(struct parse *p); */ static void p_str(struct parse *p) @@ -475,8 +452,6 @@ p_str(struct parse *p) /* - p_bre - BRE parser top level, anchoring and concatenation - == static void p_bre(struct parse *p, int end1, \ - == int end2); * Giving end1 as OUT essentially eliminates the end1/end2 check. * * This implementation is a bit of a kludge, in that a trailing $ is first @@ -515,7 +490,6 @@ p_bre(struct parse *p, /* - p_simp_re - parse a simple RE, an atom possibly followed by a repetition - == static int p_simp_re(struct parse *p, int starordinary); */ static int /* was the simple RE an unbackslashed $? */ p_simp_re(struct parse *p, @@ -632,7 +606,6 @@ p_simp_re(struct parse *p, /* - p_count - parse a repetition count - == static int p_count(struct parse *p); */ static int /* the value */ p_count(struct parse *p) @@ -651,7 +624,6 @@ p_count(struct parse *p) /* - p_bracket - parse a bracketed character list - == static void p_bracket(struct parse *p); * * Note a significant property of this code: if the allocset() did SETERROR, * no set operations are done. @@ -731,7 +703,6 @@ p_bracket(struct parse *p) /* - p_b_term - parse one term of a bracketed character list - == static void p_b_term(struct parse *p, cset *cs); */ static void p_b_term(struct parse *p, cset *cs) @@ -795,7 +766,6 @@ p_b_term(struct parse *p, cset *cs) /* - p_b_cclass - parse a character-class name and deal with it - == static void p_b_cclass(struct parse *p, cset *cs); */ static void p_b_cclass(struct parse *p, cset *cs) @@ -827,7 +797,6 @@ p_b_cclass(struct parse *p, cset *cs) /* - p_b_eclass - parse an equivalence-class name and deal with it - == static void p_b_eclass(struct parse *p, cset *cs); * * This implementation is incomplete. xxx */ @@ -842,7 +811,6 @@ p_b_eclass(struct parse *p, cset *cs) /* - p_b_symbol - parse a character or [..]ed multicharacter collating symbol - == static char p_b_symbol(struct parse *p); */ static char /* value of symbol */ p_b_symbol(struct parse *p) @@ -861,7 +829,6 @@ p_b_symbol(struct parse *p) /* - p_b_coll_elem - parse a collating-element name and look it up - == static char p_b_coll_elem(struct parse *p, int endc); */ static char /* value of collating element */ p_b_coll_elem(struct parse *p, @@ -889,7 +856,6 @@ p_b_coll_elem(struct parse *p, /* - othercase - return the case counterpart of an alphabetic - == static char othercase(int ch); */ static char /* if no counterpart, return ch */ othercase(int ch) @@ -906,7 +872,6 @@ othercase(int ch) /* - bothcases - emit a dualcase version of a two-case character - == static void bothcases(struct parse *p, int ch); * * Boy, is this implementation ever a kludge... */ @@ -932,7 +897,6 @@ bothcases(struct parse *p, int ch) /* - ordinary - emit an ordinary character - == static void ordinary(struct parse *p, int ch); */ static void ordinary(struct parse *p, int ch) @@ -950,7 +914,6 @@ ordinary(struct parse *p, int ch) /* - nonnewline - emit REG_NEWLINE version of OANY - == static void nonnewline(struct parse *p); * * Boy, is this implementation ever a kludge... */ @@ -975,7 +938,6 @@ nonnewline(struct parse *p) /* - repeat - generate code for a bounded repetition, recursively if needed - == static void repeat(struct parse *p, sopno start, int from, int to); */ static void repeat(struct parse *p, @@ -1046,7 +1008,6 @@ repeat(struct parse *p, /* - seterr - set an error condition - == static int seterr(struct parse *p, int e); */ static int /* useless but makes type checking happy */ seterr(struct parse *p, int e) @@ -1060,7 +1021,6 @@ seterr(struct parse *p, int e) /* - allocset - allocate a set of characters for [] - == static cset *allocset(struct parse *p); */ static cset * allocset(struct parse *p) @@ -1135,7 +1095,6 @@ nomem: /* - freeset - free a now-unused set - == static void freeset(struct parse *p, cset *cs); */ static void freeset(struct parse *p, cset *cs) @@ -1152,7 +1111,6 @@ freeset(struct parse *p, cset *cs) /* - freezeset - final processing on a set of characters - == static int freezeset(struct parse *p, cset *cs); * * The main task here is merging identical sets. This is usually a waste * of time (although the hash code minimizes the overhead), but can win @@ -1190,7 +1148,6 @@ freezeset(struct parse *p, cset *cs) /* - firstch - return first character in a set (which must have at least one) - == static int firstch(struct parse *p, cset *cs); */ static int /* character; there is no "none" value */ firstch(struct parse *p, cset *cs) @@ -1207,7 +1164,6 @@ firstch(struct parse *p, cset *cs) /* - nch - number of characters in a set - == static int nch(struct parse *p, cset *cs); */ static int nch(struct parse *p, cset *cs) @@ -1224,8 +1180,6 @@ nch(struct parse *p, cset *cs) /* - mcadd - add a collating element to a cset - == static void mcadd(struct parse *p, cset *cs, \ - == char *cp); */ static void mcadd( struct parse *p, cset *cs, char *cp) @@ -1252,7 +1206,6 @@ mcadd( struct parse *p, cset *cs, char *cp) /* - mcinvert - invert the list of collating elements in a cset - == static void mcinvert(struct parse *p, cset *cs); * * This would have to know the set of possibilities. Implementation * is deferred. @@ -1266,7 +1219,6 @@ mcinvert(struct parse *p, cset *cs) /* - mccase - add case counterparts of the list of collating elements in a cset - == static void mccase(struct parse *p, cset *cs); * * This would have to know the set of possibilities. Implementation * is deferred. @@ -1280,7 +1232,6 @@ mccase(struct parse *p, cset *cs) /* - isinsets - is this character in any sets? - == static int isinsets(struct re_guts *g, int c); */ static int /* predicate */ isinsets(struct re_guts *g, int c) @@ -1298,7 +1249,6 @@ isinsets(struct re_guts *g, int c) /* - samesets - are these two characters in exactly the same sets? - == static int samesets(struct re_guts *g, int c1, int c2); */ static int /* predicate */ samesets(struct re_guts *g, int c1, int c2) @@ -1317,7 +1267,6 @@ samesets(struct re_guts *g, int c1, int c2) /* - categorize - sort out character categories - == static void categorize(struct parse *p, struct re_guts *g); */ static void categorize(struct parse *p, struct re_guts *g) @@ -1343,7 +1292,6 @@ categorize(struct parse *p, struct re_guts *g) /* - dupl - emit a duplicate of a bunch of sops - == static sopno dupl(struct parse *p, sopno start, sopno finish); */ static sopno /* start of duplicate */ dupl(struct parse *p, @@ -1366,7 +1314,6 @@ dupl(struct parse *p, /* - doemit - emit a strip operator - == static void doemit(struct parse *p, sop op, size_t opnd); * * It might seem better to implement this as a macro with a function as * hard-case backup, but it's just too big and messy unless there are @@ -1393,7 +1340,6 @@ doemit(struct parse *p, sop op, size_t opnd) /* - doinsert - insert a sop into the strip - == static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos); */ static void doinsert(struct parse *p, sop op, size_t opnd, sopno pos) @@ -1429,7 +1375,6 @@ doinsert(struct parse *p, sop op, size_t opnd, sopno pos) /* - dofwd - complete a forward reference - == static void dofwd(struct parse *p, sopno pos, sop value); */ static void dofwd(struct parse *p, sopno pos, sop value) @@ -1444,7 +1389,6 @@ dofwd(struct parse *p, sopno pos, sop value) /* - enlarge - enlarge the strip - == static void enlarge(struct parse *p, sopno size); */ static void enlarge(struct parse *p, sopno size) @@ -1465,7 +1409,6 @@ enlarge(struct parse *p, sopno size) /* - stripsnug - compact the strip - == static void stripsnug(struct parse *p, struct re_guts *g); */ static void stripsnug(struct parse *p, struct re_guts *g) @@ -1480,7 +1423,6 @@ stripsnug(struct parse *p, struct re_guts *g) /* - findmust - fill in must and mlen with longest mandatory literal string - == static void findmust(struct parse *p, struct re_guts *g); * * This algorithm could do fancy things like analyzing the operands of | * for common subsequences. Someday. This code is simple and finds most @@ -1565,7 +1507,6 @@ findmust(struct parse *p, struct re_guts *g) /* - pluscount - count + nesting - == static sopno pluscount(struct parse *p, struct re_guts *g); */ static sopno /* nesting depth */ pluscount(struct parse *p, struct re_guts *g) |