Elia Pinto | 46efd28 | 2019-11-07 10:12:43 +0000 | [diff] [blame] | 1 | #ifndef KWSET_H |
| 2 | #define KWSET_H |
| 3 | |
Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 4 | /* This file has been copied from commit e7ac713d^ in the GNU grep git |
| 5 | * repository. A few small changes have been made to adapt the code to |
| 6 | * Git. |
| 7 | */ |
| 8 | |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 9 | /* kwset.h - header declaring the keyword set library. |
| 10 | Copyright (C) 1989, 1998, 2005 Free Software Foundation, Inc. |
| 11 | |
| 12 | This program is free software; you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation; either version 2, or (at your option) |
| 15 | any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
Todd Zullinger | 4842579 | 2017-11-07 00:39:33 -0500 | [diff] [blame] | 23 | along with this program; if not, see <http://www.gnu.org/licenses/>. */ |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 24 | |
| 25 | /* Written August 1989 by Mike Haertel. |
| 26 | The author may be reached (Email) at the address mike@ai.mit.edu, |
| 27 | or (US mail) as Mike Haertel c/o Free Software Foundation. */ |
| 28 | |
| 29 | struct kwsmatch |
| 30 | { |
| 31 | int index; /* Index number of matching keyword. */ |
| 32 | size_t offset[1]; /* Offset of each submatch. */ |
| 33 | size_t size[1]; /* Length of each submatch. */ |
| 34 | }; |
| 35 | |
Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 36 | struct kwset_t; |
| 37 | typedef struct kwset_t* kwset_t; |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 38 | |
| 39 | /* Return an opaque pointer to a newly allocated keyword set, or NULL |
| 40 | if enough memory cannot be obtained. The argument if non-NULL |
| 41 | specifies a table of character translations to be applied to all |
| 42 | pattern and search text. */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 43 | kwset_t kwsalloc(unsigned char const *); |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 44 | |
| 45 | /* Incrementally extend the keyword set to include the given string. |
| 46 | Return NULL for success, or an error message. Remember an index |
| 47 | number for each keyword included in the set. */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 48 | const char *kwsincr(kwset_t, char const *, size_t); |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 49 | |
| 50 | /* When the keyword set has been completely built, prepare it for |
| 51 | use. Return NULL for success, or an error message. */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 52 | const char *kwsprep(kwset_t); |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 53 | |
| 54 | /* Search through the given buffer for a member of the keyword set. |
| 55 | Return a pointer to the leftmost longest match found, or NULL if |
| 56 | no match is found. If foundlen is non-NULL, store the length of |
| 57 | the matching substring in the integer it points to. Similarly, |
| 58 | if foundindex is non-NULL, store the index of the particular |
| 59 | keyword found therein. */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 60 | size_t kwsexec(kwset_t, char const *, size_t, struct kwsmatch *); |
Fredrik Kuivinen | 05f3dbb | 2011-08-21 00:41:11 +0200 | [diff] [blame] | 61 | |
| 62 | /* Deallocate the given keyword set and all its associated storage. */ |
Denton Liu | 5545442 | 2019-04-29 04:28:14 -0400 | [diff] [blame] | 63 | void kwsfree(kwset_t); |
Fredrik Kuivinen | fca65d4 | 2011-08-21 00:41:41 +0200 | [diff] [blame] | 64 | |
Elia Pinto | 46efd28 | 2019-11-07 10:12:43 +0000 | [diff] [blame] | 65 | #endif /* KWSET_H */ |