Debian Codegraph @

lib/scanner.c

raw symbols SCIP
1 /*
2 Copyright(C) 2015 Brazil
3 Copyright(C) 2021 Sutou Kouhei <[email protected]>
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20 #include "grn_scanner.h"
21
22 grn_scanner *
23 grn_scanner_open(grn_ctx *ctx,
24 grn_obj *expr,
25 grn_operator op,
26 bool record_exist)
27 {
28 grn_scanner *scanner;
29
30 scanner = GRN_CALLOC(sizeof(grn_scanner));
31 if (!scanner) {
32 return NULL;
33 }
34
35 scanner->source_expr = expr;
36 scanner->expr = grn_expr_rewrite(ctx, expr);
37 if (!scanner->expr) {
38 scanner->expr = expr;
39 }
40
41 scanner->sis = grn_scan_info_build(ctx,
42 scanner->expr,
43 &(scanner->n_sis),
44 op,
45 record_exist);
46 if (!scanner->sis) {
47 grn_scanner_close(ctx, scanner);
48 return NULL;
49 }
50
51 return scanner;
52 }
53
54 void
55 grn_scanner_close(grn_ctx *ctx, grn_scanner *scanner)
56 {
57 if (!scanner) {
58 return;
59 }
60
61 if (scanner->sis) {
62 uint32_t i;
63 for (i = 0; i < scanner->n_sis; i++) {
64 grn_scan_info_close(ctx, scanner->sis[i]);
65 }
66 GRN_FREE(scanner->sis);
67 }
68
69 if (scanner->expr != scanner->source_expr) {
70 grn_obj_close(ctx, scanner->expr);
71 }
72
73 GRN_FREE(scanner);
74 }