forked from WojciechMula/pyahocorasick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyahocorasick.c
113 lines (88 loc) · 2.4 KB
/
pyahocorasick.c
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
This is part of pyahocorasick Python module.
Python module.
This file include all code from *.c files.
Author : Wojciech Muła, [email protected]
WWW : http://0x80.pl
License : BSD-3-Clause (see LICENSE)
*/
#include "common.h"
#include "slist.h"
#include "trienode.h"
#include "trie.h"
#include "Automaton.h"
#include "AutomatonSearchIter.h"
#include "AutomatonItemsIter.h"
/* code */
#include "utils.c"
#include "trienode.c"
#include "trie.c"
#include "slist.c"
#include "Automaton.c"
#include "AutomatonItemsIter.c"
#include "AutomatonSearchIter.c"
#define ahocorasick_doc \
"pyahocorasick is a fast and memory efficient library for exact or approximate\n" \
"multi-pattern string search meaning that you can find multiple key strings\n" \
"occurrences at once in some input text."
static
PyMethodDef
ahocorasick_module_methods[] = {
{NULL, NULL, 0, NULL}
};
#ifdef PY3K
static
PyModuleDef ahocorasick_module = {
PyModuleDef_HEAD_INIT,
"ahocorasick",
"ahocorasick module",
-1,
ahocorasick_module_methods
};
#endif
#ifdef PY3K
#define init_function PyInit_ahocorasick
#define init_return(value) return (value)
#else
#define init_function initahocorasick
#define init_return(unused) return
#endif
PyMODINIT_FUNC
init_function(void) {
PyObject* module;
automaton_as_sequence.sq_length = automaton_len;
automaton_as_sequence.sq_contains = automaton_contains;
automaton_type.tp_as_sequence = &automaton_as_sequence;
#ifdef PY3K
module = PyModule_Create(&ahocorasick_module);
#else
module = Py_InitModule3("ahocorasick", ahocorasick_module_methods, ahocorasick_doc);
#endif
if (module == NULL)
init_return(NULL);
if (PyType_Ready(&automaton_type) < 0) {
Py_DECREF(module);
init_return(NULL);
}
else
PyModule_AddObject(module, "Automaton", (PyObject*)&automaton_type);
#define add_enum_const(name) PyModule_AddIntConstant(module, #name, name)
add_enum_const(TRIE);
add_enum_const(AHOCORASICK);
add_enum_const(EMPTY);
add_enum_const(STORE_LENGTH);
add_enum_const(STORE_INTS);
add_enum_const(STORE_ANY);
add_enum_const(KEY_STRING);
add_enum_const(KEY_SEQUENCE);
add_enum_const(MATCH_EXACT_LENGTH);
add_enum_const(MATCH_AT_MOST_PREFIX);
add_enum_const(MATCH_AT_LEAST_PREFIX);
#undef add_enum_const
#ifdef AHOCORASICK_UNICODE
PyModule_AddIntConstant(module, "unicode", 1);
#else
PyModule_AddIntConstant(module, "unicode", 0);
#endif
init_return(module);
}