summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/grep/kwset.c
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>1999-11-20 23:41:24 +0000
committerobrien <obrien@FreeBSD.org>1999-11-20 23:41:24 +0000
commit6cd485fb34312dca9e8429f8304276869c58e123 (patch)
tree257eeeed86869d1dd749ec35f674bf3e9ecbe783 /gnu/usr.bin/grep/kwset.c
parentfa896584804f4ad0ece625df1e5e8c7e0ca8188b (diff)
downloadFreeBSD-src-6cd485fb34312dca9e8429f8304276869c58e123.zip
FreeBSD-src-6cd485fb34312dca9e8429f8304276869c58e123.tar.gz
This is the stock 2.3 file (+ FreeBSD id). Since someone majorly SPAMMED
the repository by NOT vendor importing the virgin 2.0 sources, CVS had no idea what to do here.
Diffstat (limited to 'gnu/usr.bin/grep/kwset.c')
-rw-r--r--gnu/usr.bin/grep/kwset.c75
1 files changed, 36 insertions, 39 deletions
diff --git a/gnu/usr.bin/grep/kwset.c b/gnu/usr.bin/grep/kwset.c
index 68871cb..adde8a7 100644
--- a/gnu/usr.bin/grep/kwset.c
+++ b/gnu/usr.bin/grep/kwset.c
@@ -1,10 +1,9 @@
/* kwset.c - search for any of a set of keywords.
- Copyright 1989 Free Software Foundation
- Written August 1989 by Mike Haertel.
+ Copyright (C) 1989, 1998 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 1, or (at your option)
+ the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
@@ -14,11 +13,15 @@
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA. */
+/* Written August 1989 by Mike Haertel.
The author may be reached (Email) at the address mike@ai.mit.edu,
or (US mail) as Mike Haertel c/o Free Software Foundation. */
+/* $FreeBSD$ */
+
/* The algorithm implemented by these routines bears a startling resemblence
to one discovered by Beate Commentz-Walter, although it is not identical.
See "A String Matching Algorithm Fast on the Average," Technical Report,
@@ -27,45 +30,20 @@
String Matching: An Aid to Bibliographic Search," CACM June 1975,
Vol. 18, No. 6, which describes the failure function used below. */
-/* $FreeBSD$ */
-
-
-#ifdef STDC_HEADERS
-#include <limits.h>
-#include <stdlib.h>
-#else
-#define INT_MAX 2147483647
-#define UCHAR_MAX 255
-#ifdef __STDC__
-#include <stddef.h>
-#else
-#include <sys/types.h>
-#endif
-extern char *malloc();
-extern void free();
-#endif
-
-#ifdef HAVE_MEMCHR
-#include <string.h>
-#ifdef NEED_MEMORY_H
-#include <memory.h>
-#endif
-#else
-#ifdef __STDC__
-extern void *memchr();
-#else
-extern char *memchr();
-#endif
+#ifdef HAVE_CONFIG_H
+# include <config.h>
#endif
+#include <sys/types.h>
+#include "system.h"
+#include "kwset.h"
+#include "obstack.h"
#ifdef GREP
extern char *xmalloc();
-#define malloc xmalloc
+# undef malloc
+# define malloc xmalloc
#endif
-#include "kwset.h"
-#include "obstack.h"
-
#define NCHAR (UCHAR_MAX + 1)
#define obstack_chunk_alloc malloc
#define obstack_chunk_free free
@@ -108,6 +86,15 @@ struct kwset
char *trans; /* Character translation table. */
};
+/* prototypes */
+static void enqueue PARAMS((struct tree *, struct trie **));
+static void treefails PARAMS((register struct tree *, struct trie *, struct trie *));
+static void treedelta PARAMS((register struct tree *,register unsigned int, unsigned char *));
+static int hasevery PARAMS((register struct tree *, register struct tree *));
+static void treenext PARAMS((struct tree *, struct trie **));
+static char * bmexec PARAMS((kwset_t, char *, size_t));
+static char * cwexec PARAMS((kwset_t, char *, size_t, struct kwsmatch *));
+
/* Allocate and initialize a keyword set object, returning an opaque
pointer to it. Return NULL if memory is not available. */
kwset_t
@@ -196,13 +183,13 @@ kwsincr(kws, text, len)
link = (struct tree *) obstack_alloc(&kwset->obstack,
sizeof (struct tree));
if (!link)
- return "memory exhausted";
+ return _("memory exhausted");
link->llink = 0;
link->rlink = 0;
link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
sizeof (struct trie));
if (!link->trie)
- return "memory exhausted";
+ return _("memory exhausted");
link->trie->accepting = 0;
link->trie->links = 0;
link->trie->parent = trie;
@@ -251,6 +238,8 @@ kwsincr(kws, text, len)
r->balance = t->balance != (char) -1 ? 0 : 1;
t->balance = 0;
break;
+ default:
+ abort ();
}
break;
case 2:
@@ -269,8 +258,12 @@ kwsincr(kws, text, len)
r->balance = t->balance != (char) -1 ? 0 : 1;
t->balance = 0;
break;
+ default:
+ abort ();
}
break;
+ default:
+ abort ();
}
if (dirs[depth - 1] == L)
@@ -623,6 +616,10 @@ cwexec(kws, text, len, kwsmatch)
register struct tree *tree;
register char *trans;
+#ifdef lint
+ accept = NULL;
+#endif
+
/* Initialize register copies and look for easy ways out. */
kwset = (struct kwset *) kws;
if (len < kwset->mind)
OpenPOWER on IntegriCloud