-/*
+/*
Copyright (c) 1995-1998 by Cisco systems, Inc.
Permission to use, copy, modify, and distribute this software for
* precedence is structured in regular expressions. Serious changes in
* regular-expression syntax might require a total rethink.
*/
+
+
+#include "tac_plus.h"
+
+#ifdef WITH_INCLUDED_REGEX
+
#include <stdio.h>
-#include "regexp.h"
-#include "regmagic.h"
+#include <string.h>
+#include <stdlib.h> /* malloc() can be found in <stdlib.h> OR <malloc.h> */
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
+
+#include "tac_regexp.h"
+#include "tac_regmagic.h"
+#include "report.h" /* for regerror() */
+
/*
* The "internal use only" fields in regexp.h are present to pass info from
#define UCHARAT(p) ((int)*(p)&CHARBITS)
#endif
-#define FAIL(m) { regerror(m); return(NULL); }
+#define FAIL(m) { tac_regerror(m); return(NULL); }
#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?')
#define META "^$.[()|?+*\\"
/*
* Global work variables for regcomp().
*/
-static char *regparse; /* Input-scan pointer. */
+static const char *regparse; /* Input-scan pointer. */
static int regnpar; /* () count. */
static char regdummy;
static char *regcode; /* Code-emit pointer; ®dummy = don't. */
/*
* Forward declarations for regcomp()'s friends.
*/
-#ifndef STATIC
-#define STATIC static
-#endif
-STATIC char *reg();
-STATIC char *regbranch();
-STATIC char *regpiece();
-STATIC char *regatom();
-STATIC char *regnode();
-STATIC char *regnext();
-STATIC void regc();
-STATIC void reginsert();
-STATIC void regtail();
-STATIC void regoptail();
-#ifdef STRCSPN
-STATIC int strcspn();
+static char *reg TAC_ARGS((int paren, int *flagp));
+static char *regbranch TAC_ARGS((int *flagp));
+static char *regpiece TAC_ARGS((int *flagp));
+static char *regatom TAC_ARGS((int *flagp));
+static char *regnode TAC_ARGS((int op));
+static void regc TAC_ARGS((int b));
+static void reginsert TAC_ARGS((int op, char *opnd));
+static void regtail TAC_ARGS((char *p, char *val));
+static void regoptail TAC_ARGS((char *p, char *val));
+static int regtry TAC_ARGS((tac_regexp *prog, const char *string));
+static int regmatch TAC_ARGS((char *prog));
+static int regrepeat TAC_ARGS((char *p));
+static char *regnext TAC_ARGS((register char *p));
+#ifndef HAVE_STRCSPN
+static int strcspn TAC_ARGS((char *s1, char *s2));
#endif
+
/*
- regcomp - compile a regular expression into internal code
*
* Beware that the optimization-preparation code in here knows about some
* of the structure of the compiled regexp.
*/
-regexp *
-regcomp(exp)
-char *exp;
+
+tac_regexp *tac_regcomp TAC_ARGS((const char *exp));
+
+tac_regexp *
+tac_regcomp(exp)
+const char *exp;
{
- register regexp *r;
+ register tac_regexp *r;
register char *scan;
register char *longest;
register int len;
int flags;
- extern char *malloc();
if (exp == NULL)
FAIL("NULL argument");
FAIL("regexp too big");
/* Allocate space. */
- r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize);
+ r = (tac_regexp *)malloc(sizeof(tac_regexp) + (unsigned)regsize);
if (r == NULL)
FAIL("out of space");
longest = NULL;
len = 0;
for (; scan != NULL; scan = regnext(scan))
- if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
+ if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= (unsigned)len) {
longest = OPERAND(scan);
len = strlen(OPERAND(scan));
}
* is a trifle forced, but the need to tie the tails of the branches to what
* follows makes it hard to avoid.
*/
+
+static char *reg TAC_ARGS((int paren, int *flagp));
+
static char *
reg(paren, flagp)
int paren; /* Parenthesized? */
register char *ret;
register char *br;
register char *ender;
- register int parno;
+ register int parno = 0 /* GCC paranoia */;
int flags;
*flagp = HASWIDTH; /* Tentatively. */
}
/* Make a closing node, and hook it on the end. */
- ender = regnode((paren) ? CLOSE+parno : END);
+ ender = regnode((paren) ? CLOSE+parno : END);
regtail(ret, ender);
/* Hook the tails of the branches to the closing node. */
*
* Implements the concatenation operator.
*/
+
+static char *regbranch TAC_ARGS((int *flagp));
+
static char *
regbranch(flagp)
int *flagp;
* It might seem that this node could be dispensed with entirely, but the
* endmarker role is not redundant.
*/
+
+static char *regpiece TAC_ARGS((int *flagp));
+
static char *
regpiece(flagp)
int *flagp;
* faster to run. Backslashed characters are exceptions, each becoming a
* separate node; the code is simpler that way and it's not worth fixing.
*/
+
+static char *regatom TAC_ARGS((int *flagp));
+
static char *
regatom(flagp)
int *flagp;
/*
- regnode - emit a node
*/
+
+static char *regnode TAC_ARGS((int op));
+
static char * /* Location. */
regnode(op)
-char op;
+int op; /* promoted "char" type */
{
register char *ret;
register char *ptr;
/*
- regc - emit (if appropriate) a byte of code
*/
+
+static void regc TAC_ARGS((int b));
+
static void
regc(b)
-char b;
+int b; /* promoted "char" type */
{
if (regcode != ®dummy)
*regcode++ = b;
*
* Means relocating the operand.
*/
+
+static void reginsert TAC_ARGS((int op, char *opnd));
+
static void
reginsert(op, opnd)
-char op;
+int op; /* promoted "char" type */
char *opnd;
{
register char *src;
/*
- regtail - set the next-pointer at the end of a node chain
*/
+
+static void regtail TAC_ARGS((char *p, char *val));
+
static void
regtail(p, val)
char *p;
/*
- regoptail - regtail on operand of first argument; nop if operandless
*/
+
+static void regoptail TAC_ARGS((char *p, char *val));
+
static void
regoptail(p, val)
char *p;
/*
* Global work variables for regexec().
*/
-static char *reginput; /* String-input pointer. */
-static char *regbol; /* Beginning of input, for ^ check. */
-static char **regstartp; /* Pointer to startp array. */
-static char **regendp; /* Ditto for endp. */
+static const char *reginput; /* String-input pointer. */
+static const char *regbol; /* Beginning of input, for ^ check. */
+static const char **regstartp; /* Pointer to startp array. */
+static const char **regendp; /* Ditto for endp. */
-/*
- * Forwards.
- */
-STATIC int regtry();
-STATIC int regmatch();
-STATIC int regrepeat();
#ifdef DEBUG
int regnarrate = 0;
-void regdump();
-STATIC char *regprop();
+static char *regprop TAC_ARGS((char *op));
+static void regdump TAC_ARGS((tac_regexp *r));
#endif
/*
- regexec - match a regexp against a string
*/
+
+int tac_regexec TAC_ARGS((register tac_regexp *prog, register const char *string));
+
int
-regexec(prog, string)
-register regexp *prog;
-register char *string;
+tac_regexec(prog, string)
+register tac_regexp *prog;
+register const char *string;
{
- register char *s;
- extern char *strchr();
+ register const char *s;
/* Be paranoid... */
if (prog == NULL || string == NULL) {
- regerror("NULL parameter");
+ tac_regerror("NULL parameter");
return(0);
}
/* Check validity of program. */
if (UCHARAT(prog->program) != MAGIC) {
- regerror("corrupted program");
+ tac_regerror("corrupted program");
return(0);
}
/*
- regtry - try match at specific point
*/
+
+static int regtry TAC_ARGS((tac_regexp *prog, const char *string));
+
static int /* 0 failure, 1 success */
regtry(prog, string)
-regexp *prog;
-char *string;
+tac_regexp *prog;
+const char *string;
{
register int i;
- register char **sp;
- register char **ep;
+ register const char **sp;
+ register const char **ep;
reginput = string;
regstartp = prog->startp;
* need to know whether the rest of the match failed) by a loop instead of
* by recursion.
*/
+
+static int regmatch TAC_ARGS((char *prog));
+
static int /* 0 failure, 1 success */
regmatch(prog)
char *prog;
{
register char *scan; /* Current node. */
char *next; /* Next node. */
- extern char *strchr();
scan = prog;
#ifdef DEBUG
case OPEN+8:
case OPEN+9: {
register int no;
- register char *save;
+ register const char *save;
no = OP(scan) - OPEN;
save = reginput;
case CLOSE+8:
case CLOSE+9: {
register int no;
- register char *save;
+ register const char *save;
no = OP(scan) - CLOSE;
save = reginput;
}
break;
case BRANCH: {
- register char *save;
+ register const char *save;
if (OP(next) != BRANCH) /* No choice. */
next = OPERAND(scan); /* Avoid recursion. */
case PLUS: {
register char nextch;
register int no;
- register char *save;
+ register const char *save;
register int min;
/*
return(1); /* Success! */
break;
default:
- regerror("memory corruption");
+ tac_regerror("memory corruption");
return(0);
break;
}
* We get here only if there's trouble -- normally "case END" is
* the terminating point.
*/
- regerror("corrupted pointers");
+ tac_regerror("corrupted pointers");
return(0);
}
/*
- regrepeat - repeatedly match something simple, report how many
*/
+
+static int regrepeat TAC_ARGS((char *p));
+
static int
regrepeat(p)
char *p;
{
register int count = 0;
- register char *scan;
+ register const char *scan;
register char *opnd;
- extern char *strchr();
scan = reginput;
opnd = OPERAND(p);
}
break;
default: /* Oh dear. Called inappropriately. */
- regerror("internal foulup");
+ tac_regerror("internal foulup");
count = 0; /* Best compromise. */
break;
}
/*
- regnext - dig the "next" pointer out of a node
*/
+
+static char *regnext TAC_ARGS((register char *p));
+
static char *
regnext(p)
register char *p;
#ifdef DEBUG
-STATIC char *regprop();
-
/*
- regdump - dump a regexp onto stdout in vaguely comprehensible form
*/
-void
+
+static void regdump TAC_ARGS((tac_regexp *r));
+
+static void
regdump(r)
-regexp *r;
+tac_regexp *r;
{
register char *s;
register char op = EXACTLY; /* Arbitrary non-END op. */
register char *next;
- extern char *strchr();
s = r->program + 1;
next = regnext(s);
if (next == NULL) /* Next ptr. */
printf("(0)");
- else
+ else
printf("(%d)", (s-r->program)+(next-s));
s += 3;
if (op == ANYOF || op == ANYBUT || op == EXACTLY) {
/*
- regprop - printable representation of opcode
*/
+
+static char *regprop TAC_ARGS((char *op));
+
static char *
regprop(op)
char *op;
p = "PLUS";
break;
default:
- regerror("corrupted opcode");
+ tac_regerror("corrupted opcode");
break;
}
if (p != NULL)
* about it; at least one public-domain implementation of those (highly
* useful) string routines has been published on Usenet.
*/
-#ifdef STRCSPN
+#ifndef HAVE_STRCSPN
/*
* strcspn - find length of initial segment of s1 consisting entirely
* of characters not from s2
*/
+static int strcspn TAC_ARGS((char *s1, char *s2));
+
static int
strcspn(s1, s2)
char *s1;
}
return(count);
}
-#endif
+#endif /* HAVE_STRCSPN */
+
+#else /* WITH_INCLUDED_REGEX */
+
+TAC_SOURCEFILE_EMPTY
+
+#endif /* WITH_INCLUDED_REGEX */