|
| 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 | + |
1 | 7 | /* kwset.c - search for any of a set of keywords.
|
2 | 8 | Copyright 1989, 1998, 2000, 2005 Free Software Foundation, Inc.
|
3 | 9 |
|
|
28 | 34 | String Matching: An Aid to Bibliographic Search," CACM June 1975,
|
29 | 35 | Vol. 18, No. 6, which describes the failure function used below. */
|
30 | 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 | + |
36 | 39 | #include "kwset.h"
|
37 | 40 | #include "obstack.h"
|
38 | 41 |
|
39 |
| -#ifdef GREP |
40 |
| -extern char *xmalloc(); |
41 |
| -# undef malloc |
42 |
| -# define malloc xmalloc |
43 |
| -#endif |
44 |
| - |
45 | 42 | #define NCHAR (UCHAR_MAX + 1)
|
46 |
| -#define obstack_chunk_alloc malloc |
| 43 | +#define obstack_chunk_alloc xmalloc |
47 | 44 | #define obstack_chunk_free free
|
48 | 45 |
|
49 | 46 | #define U(c) ((unsigned char) (c))
|
@@ -93,9 +90,7 @@ kwsalloc (char const *trans)
|
93 | 90 | {
|
94 | 91 | struct kwset *kwset;
|
95 | 92 |
|
96 |
| - kwset = (struct kwset *) malloc(sizeof (struct kwset)); |
97 |
| - if (!kwset) |
98 |
| - return NULL; |
| 93 | + kwset = (struct kwset *) xmalloc(sizeof (struct kwset)); |
99 | 94 |
|
100 | 95 | obstack_init(&kwset->obstack);
|
101 | 96 | kwset->words = 0;
|
@@ -174,15 +169,15 @@ kwsincr (kwset_t kws, char const *text, size_t len)
|
174 | 169 | link = (struct tree *) obstack_alloc(&kwset->obstack,
|
175 | 170 | sizeof (struct tree));
|
176 | 171 | if (!link)
|
177 |
| - return _("memory exhausted"); |
| 172 | + return "memory exhausted"; |
178 | 173 | link->llink = NULL;
|
179 | 174 | link->rlink = NULL;
|
180 | 175 | link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
|
181 | 176 | sizeof (struct trie));
|
182 | 177 | if (!link->trie)
|
183 | 178 | {
|
184 | 179 | obstack_free(&kwset->obstack, link);
|
185 |
| - return _("memory exhausted"); |
| 180 | + return "memory exhausted"; |
186 | 181 | }
|
187 | 182 | link->trie->accepting = 0;
|
188 | 183 | link->trie->links = NULL;
|
@@ -405,7 +400,7 @@ kwsprep (kwset_t kws)
|
405 | 400 | /* Looking for just one string. Extract it from the trie. */
|
406 | 401 | kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
|
407 | 402 | if (!kwset->target)
|
408 |
| - return _("memory exhausted"); |
| 403 | + return "memory exhausted"; |
409 | 404 | for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
|
410 | 405 | {
|
411 | 406 | kwset->target[i] = curr->links->label;
|
@@ -597,9 +592,7 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
|
597 | 592 | register struct tree const *tree;
|
598 | 593 | register char const *trans;
|
599 | 594 |
|
600 |
| -#ifdef lint |
601 | 595 | accept = NULL;
|
602 |
| -#endif |
603 | 596 |
|
604 | 597 | /* Initialize register copies and look for easy ways out. */
|
605 | 598 | kwset = (struct kwset *) kws;
|
|
0 commit comments