Merge branch 'ld/p4-multiple-shelves'
[git/raj.git] / kwset.h
blob583f6268ef0beb121e8b776f38b4169784caf7a8
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 */
6 /* kwset.h - header declaring the keyword set library.
7 Copyright (C) 1989, 1998, 2005 Free Software Foundation, Inc.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, see <http://www.gnu.org/licenses/>. */
22 /* Written August 1989 by Mike Haertel.
23 The author may be reached (Email) at the address mike@ai.mit.edu,
24 or (US mail) as Mike Haertel c/o Free Software Foundation. */
26 struct kwsmatch
28 int index; /* Index number of matching keyword. */
29 size_t offset[1]; /* Offset of each submatch. */
30 size_t size[1]; /* Length of each submatch. */
33 struct kwset_t;
34 typedef struct kwset_t* kwset_t;
36 /* Return an opaque pointer to a newly allocated keyword set, or NULL
37 if enough memory cannot be obtained. The argument if non-NULL
38 specifies a table of character translations to be applied to all
39 pattern and search text. */
40 extern kwset_t kwsalloc(unsigned char const *);
42 /* Incrementally extend the keyword set to include the given string.
43 Return NULL for success, or an error message. Remember an index
44 number for each keyword included in the set. */
45 extern const char *kwsincr(kwset_t, char const *, size_t);
47 /* When the keyword set has been completely built, prepare it for
48 use. Return NULL for success, or an error message. */
49 extern const char *kwsprep(kwset_t);
51 /* Search through the given buffer for a member of the keyword set.
52 Return a pointer to the leftmost longest match found, or NULL if
53 no match is found. If foundlen is non-NULL, store the length of
54 the matching substring in the integer it points to. Similarly,
55 if foundindex is non-NULL, store the index of the particular
56 keyword found therein. */
57 extern size_t kwsexec(kwset_t, char const *, size_t, struct kwsmatch *);
59 /* Deallocate the given keyword set and all its associated storage. */
60 extern void kwsfree(kwset_t);