X-Git-Url: https://git.cameronkatri.com/bsdgames-darwin.git/blobdiff_plain/416d932935b8a3171ac05bfa2c147bcef759d6f3..087b6e7b7c1861c118eb976452acc50a866f916f:/quiz/rxp.c?ds=sidebyside diff --git a/quiz/rxp.c b/quiz/rxp.c index 4b6a74f7..015d8a51 100644 --- a/quiz/rxp.c +++ b/quiz/rxp.c @@ -1,3 +1,5 @@ +/* $NetBSD: rxp.c,v 1.13 2009/08/27 00:31:12 dholland Exp $ */ + /*- * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. @@ -14,11 +16,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -35,8 +33,13 @@ * SUCH DAMAGE. */ +#include #ifndef lint +#if 0 static char sccsid[] = "@(#)rxp.c 8.1 (Berkeley) 5/31/93"; +#else +__RCSID("$NetBSD: rxp.c,v 1.13 2009/08/27 00:31:12 dholland Exp $"); +#endif #endif /* not lint */ /* @@ -61,6 +64,7 @@ static char sccsid[] = "@(#)rxp.c 8.1 (Berkeley) 5/31/93"; */ #include +#include #include #include "quiz.h" /* regexp tokens, arg */ @@ -78,24 +82,21 @@ typedef short Rxp_t; /* type for regexp tokens */ static Rxp_t rxpbuf[RXP_LINE_SZ]; /* compiled regular expression buffer */ char rxperr[128]; /* parser error message */ -static int rxp__compile __P((char *, int)); -static char *rxp__expand __P((int)); -static int rxp__match __P((char *, int, Rxp_t *, Rxp_t *, char *)); +static int rxp__compile(const char *, int); +static char *rxp__expand(int); +static int rxp__match(const char *, int, Rxp_t *, Rxp_t *, const char *); int -rxp_compile(s) - register char * s; +rxp_compile(const char *s) { return (rxp__compile(s, TRUE)); } static int -rxp__compile(s, first) - register char *s; - int first; +rxp__compile(const char *s, int first) { static Rxp_t *rp; - static char *sp; + static const char *sp; Rxp_t *grp_ptr; Rxp_t *alt_ptr; int esc, err; @@ -188,25 +189,22 @@ rxp__compile(s, first) * match string against compiled regular expression */ int -rxp_match(s) - register char * s; +rxp_match(const char *s) { return (rxp__match(s, TRUE, NULL, NULL, NULL)); } static int -rxp__match(s, first, j_succ, j_fail, sp_fail) - char *s; - int first; - Rxp_t *j_succ; /* jump here on successful alt match */ - Rxp_t *j_fail; /* jump here on failed match */ - char *sp_fail; /* reset sp to here on failed match */ +rxp__match(const char *s, + int first, + Rxp_t *j_succ, /* jump here on successful alt match */ + Rxp_t *j_fail, /* jump here on failed match */ + const char *sp_fail) /* reset sp to here on failed match */ { static Rxp_t *rp; - static char *sp; - register int ch; - Rxp_t *grp_end; - int err; + static const char *sp; + int ch; + Rxp_t *grp_end = NULL; if (first) { rp = rxpbuf; @@ -220,7 +218,7 @@ rxp__match(s, first, j_succ, j_fail, sp_fail) if (ch != *sp++) { rp = j_fail; sp = sp_fail; - return (TRUE); + return (FALSE); } rp++; break; @@ -240,16 +238,17 @@ rxp__match(s, first, j_succ, j_fail, sp_fail) break; case ALT_S: rp++; - if ((err = rxp__match(sp, - FALSE, grp_end, rxpbuf + *rp++, sp)) != TRUE) - return (err); + rxp__match(sp, FALSE, grp_end, rxpbuf + *rp++, sp); break; case ALT_E: rp = j_succ; return (TRUE); case GRP_E: - default: + rp = j_fail; + sp = sp_fail; return (FALSE); + default: + abort(); } return (*rp != END ? FALSE : TRUE); } @@ -258,14 +257,13 @@ rxp__match(s, first, j_succ, j_fail, sp_fail) * Reverse engineer the regular expression, by picking first of all alternates. */ char * -rxp_expand() +rxp_expand(void) { return (rxp__expand(TRUE)); } static char * -rxp__expand(first) - int first; +rxp__expand(int first) { static char buf[RXP_LINE_SZ/2]; static Rxp_t *rp;