🌐 AI搜索 & 代理 主页
blob: c722664e5a7eeef9900a86738a5553b3eace49fc [file] [log] [blame]
Elia Pinto46efd282019-11-07 10:12:431#ifndef KWSET_H
2#define KWSET_H
3
Fredrik Kuivinenfca65d42011-08-20 22:41:414/* 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 Kuivinen05f3dbb2011-08-20 22:41:119/* 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
Josh Sorefd05b08c2023-11-24 03:35:1323 along with this program; if not, see <https://www.gnu.org/licenses/>. */
Fredrik Kuivinen05f3dbb2011-08-20 22:41:1124
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
Calvin Wan28aed752023-07-05 17:09:2229extern const unsigned char tolower_trans_tbl[256];
30
Fredrik Kuivinen05f3dbb2011-08-20 22:41:1131struct kwsmatch
32{
33 int index; /* Index number of matching keyword. */
34 size_t offset[1]; /* Offset of each submatch. */
35 size_t size[1]; /* Length of each submatch. */
36};
37
Fredrik Kuivinenfca65d42011-08-20 22:41:4138struct kwset_t;
39typedef struct kwset_t* kwset_t;
Fredrik Kuivinen05f3dbb2011-08-20 22:41:1140
41/* Return an opaque pointer to a newly allocated keyword set, or NULL
42 if enough memory cannot be obtained. The argument if non-NULL
43 specifies a table of character translations to be applied to all
44 pattern and search text. */
Denton Liu55454422019-04-29 08:28:1445kwset_t kwsalloc(unsigned char const *);
Fredrik Kuivinen05f3dbb2011-08-20 22:41:1146
47/* Incrementally extend the keyword set to include the given string.
48 Return NULL for success, or an error message. Remember an index
49 number for each keyword included in the set. */
Denton Liu55454422019-04-29 08:28:1450const char *kwsincr(kwset_t, char const *, size_t);
Fredrik Kuivinen05f3dbb2011-08-20 22:41:1151
52/* When the keyword set has been completely built, prepare it for
53 use. Return NULL for success, or an error message. */
Denton Liu55454422019-04-29 08:28:1454const char *kwsprep(kwset_t);
Fredrik Kuivinen05f3dbb2011-08-20 22:41:1155
56/* Search through the given buffer for a member of the keyword set.
57 Return a pointer to the leftmost longest match found, or NULL if
58 no match is found. If foundlen is non-NULL, store the length of
59 the matching substring in the integer it points to. Similarly,
60 if foundindex is non-NULL, store the index of the particular
61 keyword found therein. */
Denton Liu55454422019-04-29 08:28:1462size_t kwsexec(kwset_t, char const *, size_t, struct kwsmatch *);
Fredrik Kuivinen05f3dbb2011-08-20 22:41:1163
64/* Deallocate the given keyword set and all its associated storage. */
Denton Liu55454422019-04-29 08:28:1465void kwsfree(kwset_t);
Fredrik Kuivinenfca65d42011-08-20 22:41:4166
Elia Pinto46efd282019-11-07 10:12:4367#endif /* KWSET_H */