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