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