Skip to content

Commit fca65d4

Browse files
frekuigitster
authored andcommitted
Adapt the kwset code to Git
Signed-off-by: Fredrik Kuivinen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 05f3dbb commit fca65d4

File tree

2 files changed

+26
-26
lines changed

2 files changed

+26
-26
lines changed

kwset.c

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
17
/* kwset.c - search for any of a set of keywords.
28
Copyright 1989, 1998, 2000, 2005 Free Software Foundation, Inc.
39
@@ -28,22 +34,13 @@
2834
String Matching: An Aid to Bibliographic Search," CACM June 1975,
2935
Vol. 18, No. 6, which describes the failure function used below. */
3036

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+
3639
#include "kwset.h"
3740
#include "obstack.h"
3841

39-
#ifdef GREP
40-
extern char *xmalloc();
41-
# undef malloc
42-
# define malloc xmalloc
43-
#endif
44-
4542
#define NCHAR (UCHAR_MAX + 1)
46-
#define obstack_chunk_alloc malloc
43+
#define obstack_chunk_alloc xmalloc
4744
#define obstack_chunk_free free
4845

4946
#define U(c) ((unsigned char) (c))
@@ -93,9 +90,7 @@ kwsalloc (char const *trans)
9390
{
9491
struct kwset *kwset;
9592

96-
kwset = (struct kwset *) malloc(sizeof (struct kwset));
97-
if (!kwset)
98-
return NULL;
93+
kwset = (struct kwset *) xmalloc(sizeof (struct kwset));
9994

10095
obstack_init(&kwset->obstack);
10196
kwset->words = 0;
@@ -174,15 +169,15 @@ kwsincr (kwset_t kws, char const *text, size_t len)
174169
link = (struct tree *) obstack_alloc(&kwset->obstack,
175170
sizeof (struct tree));
176171
if (!link)
177-
return _("memory exhausted");
172+
return "memory exhausted";
178173
link->llink = NULL;
179174
link->rlink = NULL;
180175
link->trie = (struct trie *) obstack_alloc(&kwset->obstack,
181176
sizeof (struct trie));
182177
if (!link->trie)
183178
{
184179
obstack_free(&kwset->obstack, link);
185-
return _("memory exhausted");
180+
return "memory exhausted";
186181
}
187182
link->trie->accepting = 0;
188183
link->trie->links = NULL;
@@ -405,7 +400,7 @@ kwsprep (kwset_t kws)
405400
/* Looking for just one string. Extract it from the trie. */
406401
kwset->target = obstack_alloc(&kwset->obstack, kwset->mind);
407402
if (!kwset->target)
408-
return _("memory exhausted");
403+
return "memory exhausted";
409404
for (i = kwset->mind - 1, curr = kwset->trie; i >= 0; --i)
410405
{
411406
kwset->target[i] = curr->links->label;
@@ -597,9 +592,7 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
597592
register struct tree const *tree;
598593
register char const *trans;
599594

600-
#ifdef lint
601595
accept = NULL;
602-
#endif
603596

604597
/* Initialize register copies and look for easy ways out. */
605598
kwset = (struct kwset *) kws;

kwset.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
16
/* kwset.h - header declaring the keyword set library.
27
Copyright (C) 1989, 1998, 2005 Free Software Foundation, Inc.
38
@@ -27,30 +32,32 @@ struct kwsmatch
2732
size_t size[1]; /* Length of each submatch. */
2833
};
2934

30-
typedef ptr_t kwset_t;
35+
struct kwset_t;
36+
typedef struct kwset_t* kwset_t;
3137

3238
/* Return an opaque pointer to a newly allocated keyword set, or NULL
3339
if enough memory cannot be obtained. The argument if non-NULL
3440
specifies a table of character translations to be applied to all
3541
pattern and search text. */
36-
extern kwset_t kwsalloc PARAMS((char const *));
42+
extern kwset_t kwsalloc(char const *);
3743

3844
/* Incrementally extend the keyword set to include the given string.
3945
Return NULL for success, or an error message. Remember an index
4046
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);
4248

4349
/* When the keyword set has been completely built, prepare it for
4450
use. Return NULL for success, or an error message. */
45-
extern const char *kwsprep PARAMS((kwset_t));
51+
extern const char *kwsprep(kwset_t);
4652

4753
/* Search through the given buffer for a member of the keyword set.
4854
Return a pointer to the leftmost longest match found, or NULL if
4955
no match is found. If foundlen is non-NULL, store the length of
5056
the matching substring in the integer it points to. Similarly,
5157
if foundindex is non-NULL, store the index of the particular
5258
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 *);
5460

5561
/* Deallocate the given keyword set and all its associated storage. */
56-
extern void kwsfree PARAMS((kwset_t));
62+
extern void kwsfree(kwset_t);
63+

0 commit comments

Comments
 (0)