-
Notifications
You must be signed in to change notification settings - Fork 41
/
acism.h
92 lines (74 loc) · 2.81 KB
/
acism.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*
** Copyright (C) 2009-2014 Mischa Sandberg <mischasan@gmail.com>
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as
** published by the Free Software Foundation. You may not use, modify or
** distribute this program under any other version of the GNU Lesser General
** Public License.
**
** 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 Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef ACISM_H
#define ACISM_H
#ifdef __cplusplus
# define ENTER_C extern "C" {
# define LEAVE_C }
#else
# define ENTER_C
# define LEAVE_C
#endif
ENTER_C
// VS2013 does not have "inline". Per https://github.com/PerMagnusH
# undef INLINE_
#ifdef _MSC_VER
# define INLINE_ __inline
#else
# define INLINE_ inline
#endif//_MSC_VER
// "acism" uses MEMREF {ptr,len} bytevec structs for "string" args,
// rather than NUL-terminated "C" strings.
#ifndef MSUTIL_H
#include <stdio.h>
typedef struct { char const *ptr; size_t len; } MEMREF;
#endif
typedef struct acism ACISM;
ACISM* acism_create(MEMREF const *strv, int nstrs);
void acism_destroy(ACISM*);
// For each match, acism_scan calls its ACISM_ACTION fn,
// giving it the strv[] index of the matched string,
// and the text[] offset of the byte PAST the end of the string.
// If ACISM_ACTION returns 0, search continues; otherwise,
// acism_more returns that nonzero value immediately.
typedef int (ACISM_ACTION)(int strnum, int textpos, void *context);
// If sequential blocks of (text) are passed to repeated acism_more calls,
// then search continues where the previous acism_more left off --
// string matches can cross block boundaries.
// *state should initially be (0).
int acism_more(ACISM const*, MEMREF const text,
ACISM_ACTION *fn, void *fndata, int *state);
static INLINE_ int acism_scan(ACISM const*psp, MEMREF const text,
ACISM_ACTION *fn, void *fndata)
{
int state = 0;
return acism_more(psp, text, fn, fndata, &state);
}
void acism_save(FILE*, ACISM const*);
ACISM* acism_load(FILE*);
ACISM* acism_mmap(FILE*);
// diagnostics
typedef enum {
PS_STATS=1, PS_TRAN=2, PS_HASH=4, PS_TREE=8, PS_ALL=-1
} PS_DUMP_TYPE;
// If (pattv) is not NULL, dump output includes strings.
void acism_dump(ACISM const*, PS_DUMP_TYPE, FILE*, MEMREF const*pattv);
#define ACISM_STATS 1 // Collect perf stats during acism_create (see acism_dump).
LEAVE_C
#endif//ACISM_H