Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 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 | |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 6 | /* kwset.h - header declaring the keyword set library. |
| 7 | Copyright (C) 1989, 1998, 2005 Free Software Foundation, Inc. |
| 8 | |
| 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. |
| 13 | |
| 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. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
| 22 | 02110-1301, USA. */ |
| 23 | |
| 24 | /* Written August 1989 by Mike Haertel. |
| 25 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 26 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| 27 | |
| 28 | struct kwsmatch |
| 29 | { |
| 30 | int index; /* Index number of matching keyword. */ |
| 31 | size_t offset[1]; /* Offset of each submatch. */ |
| 32 | size_t size[1]; /* Length of each submatch. */ |
| 33 | }; |
| 34 | |
Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 35 | struct kwset_t; |
| 36 | typedef struct kwset_t* kwset_t; |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 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. */ |
Ben Walton | 189c860 | 2015-03-02 19:22:31 +0000 | [diff] [blame] | 42 | extern kwset_t kwsalloc(unsigned char const *); |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 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. */ |
Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 47 | extern const char *kwsincr(kwset_t, char const *, size_t); |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 48 | |
| 49 | /* When the keyword set has been completely built, prepare it for |
| 50 | use. Return NULL for success, or an error message. */ |
Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 51 | extern const char *kwsprep(kwset_t); |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 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 |
| 55 | no match is found. If foundlen is non-NULL, store the length of |
| 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. */ |
Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 59 | extern size_t kwsexec(kwset_t, char const *, size_t, struct kwsmatch *); |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 60 | |
| 61 | /* Deallocate the given keyword set and all its associated storage. */ |
Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 62 | extern void kwsfree(kwset_t); |
| 63 | |