2019-11-07 11:12:43 +01:00
|
|
|
#ifndef KWSET_H
|
|
|
|
#define KWSET_H
|
|
|
|
|
2011-08-21 00:41:41 +02:00
|
|
|
/* This file has been copied from commit e7ac713d^ in the GNU grep git
|
|
|
|
* repository. A few small changes have been made to adapt the code to
|
|
|
|
* Git.
|
|
|
|
*/
|
|
|
|
|
2011-08-21 00:41:11 +02:00
|
|
|
/* kwset.h - header declaring the keyword set library.
|
|
|
|
Copyright (C) 1989, 1998, 2005 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2017-11-07 06:39:33 +01:00
|
|
|
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
2011-08-21 00:41:11 +02:00
|
|
|
|
|
|
|
/* Written August 1989 by Mike Haertel.
|
|
|
|
The author may be reached (Email) at the address mike@ai.mit.edu,
|
|
|
|
or (US mail) as Mike Haertel c/o Free Software Foundation. */
|
|
|
|
|
|
|
|
struct kwsmatch
|
|
|
|
{
|
|
|
|
int index; /* Index number of matching keyword. */
|
|
|
|
size_t offset[1]; /* Offset of each submatch. */
|
|
|
|
size_t size[1]; /* Length of each submatch. */
|
|
|
|
};
|
|
|
|
|
2011-08-21 00:41:41 +02:00
|
|
|
struct kwset_t;
|
|
|
|
typedef struct kwset_t* kwset_t;
|
2011-08-21 00:41:11 +02:00
|
|
|
|
|
|
|
/* Return an opaque pointer to a newly allocated keyword set, or NULL
|
|
|
|
if enough memory cannot be obtained. The argument if non-NULL
|
|
|
|
specifies a table of character translations to be applied to all
|
|
|
|
pattern and search text. */
|
2019-04-29 10:28:14 +02:00
|
|
|
kwset_t kwsalloc(unsigned char const *);
|
2011-08-21 00:41:11 +02:00
|
|
|
|
|
|
|
/* Incrementally extend the keyword set to include the given string.
|
|
|
|
Return NULL for success, or an error message. Remember an index
|
|
|
|
number for each keyword included in the set. */
|
2019-04-29 10:28:14 +02:00
|
|
|
const char *kwsincr(kwset_t, char const *, size_t);
|
2011-08-21 00:41:11 +02:00
|
|
|
|
|
|
|
/* When the keyword set has been completely built, prepare it for
|
|
|
|
use. Return NULL for success, or an error message. */
|
2019-04-29 10:28:14 +02:00
|
|
|
const char *kwsprep(kwset_t);
|
2011-08-21 00:41:11 +02:00
|
|
|
|
|
|
|
/* Search through the given buffer for a member of the keyword set.
|
|
|
|
Return a pointer to the leftmost longest match found, or NULL if
|
|
|
|
no match is found. If foundlen is non-NULL, store the length of
|
|
|
|
the matching substring in the integer it points to. Similarly,
|
|
|
|
if foundindex is non-NULL, store the index of the particular
|
|
|
|
keyword found therein. */
|
2019-04-29 10:28:14 +02:00
|
|
|
size_t kwsexec(kwset_t, char const *, size_t, struct kwsmatch *);
|
2011-08-21 00:41:11 +02:00
|
|
|
|
|
|
|
/* Deallocate the given keyword set and all its associated storage. */
|
2019-04-29 10:28:14 +02:00
|
|
|
void kwsfree(kwset_t);
|
2011-08-21 00:41:41 +02:00
|
|
|
|
2019-11-07 11:12:43 +01:00
|
|
|
#endif /* KWSET_H */
|