summaryrefslogtreecommitdiff
path: root/kwset.c
diff options
context:
space:
mode:
authorFredrik Kuivinen <frekui@gmail.com>2011-08-21 00:41:41 +0200
committerJunio C Hamano <gitster@pobox.com>2011-08-20 22:33:57 -0700
commitfca65d4b260912448c4f103ab3321fa2b82bf907 (patch)
tree15351e5a8ebcea875f482b118b64c53245426027 /kwset.c
parent05f3dbba67ac15952e1bf005ee9fd8be3428831f (diff)
downloadgit-fca65d4b260912448c4f103ab3321fa2b82bf907.tar.gz
Adapt the kwset code to Git
Signed-off-by: Fredrik Kuivinen <frekui@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'kwset.c')
-rw-r--r--kwset.c33
1 files changed, 13 insertions, 20 deletions
diff --git a/kwset.c b/kwset.c
index e66193b95f..fd4515a44c 100644
--- a/kwset.c
+++ b/kwset.c
@@ -1,3 +1,9 @@
+/*
+ * This file has been copied from commit e7ac713d^ in the GNU grep git
+ * repository. A few small changes have been made to adapt the code to
+ * Git.
+ */
+
/* kwset.c - search for any of a set of keywords.
Copyright 1989, 1998, 2000, 2005 Free Software Foundation, Inc.
@@ -28,22 +34,13 @@
String Matching: An Aid to Bibliographic Search," CACM June 1975,
Vol. 18, No. 6, which describes the failure function used below. */
-#ifdef HAVE_CONFIG_H
-# include <config.h>
-#endif
-#include <sys/types.h>
-#include "system.h"
+#include "cache.h"
+
#include "kwset.h"
#include "obstack.h"
-#ifdef GREP
-extern char *xmalloc();
-# undef malloc
-# define malloc xmalloc
-#endif
-
#define NCHAR (UCHAR_MAX + 1)
-#define obstack_chunk_alloc malloc
+#define obstack_chunk_alloc xmalloc
#define obstack_chunk_free free
#define U(c) ((unsigned char) (c))
@@ -93,9 +90,7 @@ kwsalloc (char const *trans)
{
struct kwset *kwset;
- kwset = (struct kwset *) malloc(sizeof (struct kwset));
- if (!kwset)
- return NULL;
+ kwset = (struct kwset *) xmalloc(sizeof (struct kwset));
obstack_init(&kwset->obstack);
kwset->words = 0;
@@ -174,7 +169,7 @@ kwsincr (kwset_t kws, char const *text, size_t len)
link = (struct tree *) obstack_alloc(&kwset->obstack,
sizeof (struct tree));
if (!link)
- return _("memory exhausted");
+ return "memory exhausted";
link->llink = NULL;
link->rlink = NULL;
link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
@@ -182,7 +177,7 @@ kwsincr (kwset_t kws, char const *text, size_t len)
if (!link->trie)
{
obstack_free(&kwset->obstack, link);
- return _("memory exhausted");
+ return "memory exhausted";
}
link->trie->accepting = 0;
link->trie->links = NULL;
@@ -405,7 +400,7 @@ kwsprep (kwset_t kws)
/* Looking for just one string. Extract it from the trie. */
kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
if (!kwset->target)
- return _("memory exhausted");
+ return "memory exhausted";
for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
{
kwset->target[i] = curr->links->label;
@@ -597,9 +592,7 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
register struct tree const *tree;
register char const *trans;
-#ifdef lint
accept = NULL;
-#endif
/* Initialize register copies and look for easy ways out. */
kwset = (struct kwset *) kws;