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