Adapt the kwset code to Git
Signed-off-by: Fredrik Kuivinen <frekui@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Fredrik Kuivinen committed
Aug 21, 2011 at 00:41 UTC
fca65d4b260912448c4f103ab3321fa2b82bf907
2 files changed
+26
-26
kwset.c
+13
-20
@@ -1,3 +1,9 @@
1
+/*
2
+ * This file has been copied from commit e7ac713d^ in the GNU grep git
3
+ * repository. A few small changes have been made to adapt the code to
4
+ * Git.
5
+ */
6
+
7
/* kwset.c - search for any of a set of keywords.
8
Copyright 1989, 1998, 2000, 2005 Free Software Foundation, Inc.
9
@@ -28,22 +34,13 @@
34
String Matching: An Aid to Bibliographic Search," CACM June 1975,
35
Vol. 18, No. 6, which describes the failure function used below. */
36
31
-#ifdef HAVE_CONFIG_H
32
-# include <config.h>
33
-#endif
34
-#include <sys/types.h>
35
-#include "system.h"
37
+#include "cache.h"
38
+
39
#include "kwset.h"
40
#include "obstack.h"
41
39
-#ifdef GREP
40
-extern char *xmalloc();
41
-# undef malloc
42
-# define malloc xmalloc
43
-#endif
44
-
42
#define NCHAR (UCHAR_MAX + 1)
46
-#define obstack_chunk_alloc malloc
43
+#define obstack_chunk_alloc xmalloc
44
#define obstack_chunk_free free
45
46
#define U(c) ((unsigned char) (c))
@@ -93,9 +90,7 @@ kwsalloc (char const *trans)
90
{
91
struct kwset *kwset;
92
96
- kwset = (struct kwset *) malloc(sizeof (struct kwset));
97
- if (!kwset)
98
- return NULL;
93
+ kwset = (struct kwset *) xmalloc(sizeof (struct kwset));
94
95
obstack_init(&kwset->obstack);
96
kwset->words = 0;
@@ -174,7 +169,7 @@ kwsincr (kwset_t kws, char const *text, size_t len)
169
link = (struct tree *) obstack_alloc(&kwset->obstack,
170
sizeof (struct tree));
171
if (!link)
177
- return _("memory exhausted");
172
+ return "memory exhausted";
173
link->llink = NULL;
174
link->rlink = NULL;
175
link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
@@ -182,7 +177,7 @@ kwsincr (kwset_t kws, char const *text, size_t len)
177
if (!link->trie)
178
{
179
obstack_free(&kwset->obstack, link);
185
- return _("memory exhausted");
180
+ return "memory exhausted";
181
}
182
link->trie->accepting = 0;
183
link->trie->links = NULL;
@@ -405,7 +400,7 @@ kwsprep (kwset_t kws)
400
/* Looking for just one string. Extract it from the trie. */
401
kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
402
if (!kwset->target)
408
- return _("memory exhausted");
403
+ return "memory exhausted";
404
for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
405
{
406
kwset->target[i] = curr->links->label;
@@ -597,9 +592,7 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
592
register struct tree const *tree;
593
register char const *trans;
594
600
-#ifdef lint
595
accept = NULL;
602
-#endif
596
597
/* Initialize register copies and look for easy ways out. */
598
kwset = (struct kwset *) kws;
kwset.h
+13
-6
@@ -1,3 +1,8 @@
1
+/* This file has been copied from commit e7ac713d^ in the GNU grep git
2
+ * repository. A few small changes have been made to adapt the code to
3
+ * Git.
4
+ */
5
+
6
/* kwset.h - header declaring the keyword set library.
7
Copyright (C) 1989, 1998, 2005 Free Software Foundation, Inc.
8
@@ -27,22 +32,23 @@ struct kwsmatch
32
size_t size[1]; /* Length of each submatch. */
33
};
34
30
-typedef ptr_t kwset_t;
35
+struct kwset_t;
36
+typedef struct kwset_t* kwset_t;
37
38
/* Return an opaque pointer to a newly allocated keyword set, or NULL
39
if enough memory cannot be obtained. The argument if non-NULL
40
specifies a table of character translations to be applied to all
41
pattern and search text. */
36
-extern kwset_t kwsalloc PARAMS((char const *));
42
+extern kwset_t kwsalloc(char const *);
43
44
/* Incrementally extend the keyword set to include the given string.
45
Return NULL for success, or an error message. Remember an index
46
number for each keyword included in the set. */
41
-extern const char *kwsincr PARAMS((kwset_t, char const *, size_t));
47
+extern const char *kwsincr(kwset_t, char const *, size_t);
48
49
/* When the keyword set has been completely built, prepare it for
50
use. Return NULL for success, or an error message. */
45
-extern const char *kwsprep PARAMS((kwset_t));
51
+extern const char *kwsprep(kwset_t);
52
53
/* Search through the given buffer for a member of the keyword set.
54
Return a pointer to the leftmost longest match found, or NULL if
@@ -50,7 +56,8 @@ extern const char *kwsprep PARAMS((kwset_t));
56
the matching substring in the integer it points to. Similarly,
57
if foundindex is non-NULL, store the index of the particular
58
keyword found therein. */
53
-extern size_t kwsexec PARAMS((kwset_t, char const *, size_t, struct kwsmatch *));
59
+extern size_t kwsexec(kwset_t, char const *, size_t, struct kwsmatch *);
60
61
/* Deallocate the given keyword set and all its associated storage. */
56
-extern void kwsfree PARAMS((kwset_t));
62
+extern void kwsfree(kwset_t);
63
+