Debian Codegraph @

lib/command.c

raw symbols SCIP
1 /*
2 Copyright (C) 2015 Brazil
3 Copyright (C) 2022 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 <string.h>
21
22 #include "grn.h"cxx . . $ `<file>/lib/grn.h`/
23 #include "grn_db.h"cxx . . $ `<file>/lib/grn_db.h`/
24 #include "grn_ctx_impl.h"cxx . . $ `<file>/lib/grn_ctx_impl.h`/
25
26 struct _grn_command_inputcxx . . $ _grn_command_input# {
27 grn_objcxx . . $ grn_obj# *commandcxx . . $ _grn_command_input#command.;
28 grn_hashcxx . . $ grn_hash# *argumentscxx . . $ _grn_command_input#arguments.;
29 };
30
31 grn_command_inputcxx . . $ grn_command_input# *
32 grn_command_input_opencxx . . $ grn_command_input_open(5213854126a60847).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_objcxx . . $ grn_obj# *command)
33 {
34 grn_command_inputcxx . . $ grn_command_input# *input = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
35
36 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
37 input = GRN_CALLOCcxx . . $ `lib/grn_alloc.h:42:9`!(sizeof(grn_command_input));
38 if (!input) {
39 ERRcxx . . $ `lib/grn_error.h:156:9`!(GRN_NO_MEMORY_AVAILABLE,
40 "[command-input] failed to allocate grn_command_input");
41 goto exit;
42 }
43
44 input->commandcxx . . $ _grn_command_input#command. = command;
45 /* TODO: Allocate by self. */
46 {
47 uint32_tcxx . . $ uint32_t# n;
48 input->argumentscxx . . $ _grn_command_input#arguments. = grn_expr_get_varscxx . . $ grn_expr_get_vars(e36cbecf8e2560ff).(ctx, input->commandcxx . . $ _grn_command_input#command., &n);
49 }
50
51 exit :
52 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(input);
53 }
54
55 grn_rccxx . . $ grn_rc#
56 grn_command_input_closecxx . . $ grn_command_input_close(5e36403d68038792).(grn_ctxcxx . . $ grn_ctx# *ctx, grn_command_inputcxx . . $ grn_command_input# *input)
57 {
58 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
59
60 /* TODO: Free input->arguments by self. */
61 /* grn_expr_clear_vars(ctx, input->command); */
62 GRN_FREEcxx . . $ `lib/grn_alloc.h:49:9`!(input);
63
64 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
65 }
66
67 grn_objcxx . . $ grn_obj# *
68 grn_command_input_addcxx . . $ grn_command_input_add(d8d9010635dfca08).(grn_ctxcxx . . $ grn_ctx# *ctx,
69 grn_command_inputcxx . . $ grn_command_input# *input,
70 const char *name,
71 int name_size,
72 boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! *added)
73 {
74 grn_objcxx . . $ grn_obj# *argument = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
75 /* TODO: Use bool */
76 int internal_added = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!;
77
78 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
79
80 uint32_tcxx . . $ uint32_t# real_name_size;
81 if (name_size == -1) {
82 real_name_size = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(name);
83 } else {
84 real_name_size = (uint32_tcxx . . $ uint32_t#)name_size;
85 }
86 if (input->argumentscxx . . $ _grn_command_input#arguments.) {
87 grn_hash_addcxx . . $ grn_hash_add(251a256fc515235e).(ctx, input->argumentscxx . . $ _grn_command_input#arguments., name, real_name_size, (void **)&argument,
88 &internal_added);
89 if (internal_added) {
90 GRN_TEXT_INITcxx . . $ `include/groonga/groonga.h:2750:9`!(argument, 0);
91 }
92 }
93 if (added) {
94 *added = internal_added;
95 }
96
97 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(argument);
98 }
99
100 grn_objcxx . . $ grn_obj# *
101 grn_command_input_getcxx . . $ grn_command_input_get(ea13b77221054a20).(grn_ctxcxx . . $ grn_ctx# *ctx,
102 grn_command_inputcxx . . $ grn_command_input# *input,
103 const char *name,
104 int name_size)
105 {
106 grn_objcxx . . $ grn_obj# *argument = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
107
108 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
109
110 uint32_tcxx . . $ uint32_t# real_name_size;
111 if (name_size == -1) {
112 real_name_size = (uint32_tcxx . . $ uint32_t#)strlencxx . . $ strlen(751346f8406fd082).(name);
113 } else {
114 real_name_size = (uint32_tcxx . . $ uint32_t#)name_size;
115 }
116 if (input->argumentscxx . . $ _grn_command_input#arguments.) {
117 grn_hash_getcxx . . $ grn_hash_get(4e868e5367e71b67).(ctx,
118 input->argumentscxx . . $ _grn_command_input#arguments.,
119 name,
120 real_name_size,
121 (void **)&argument);
122 }
123
124 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(argument);
125 }
126
127 grn_objcxx . . $ grn_obj# *
128 grn_command_input_atcxx . . $ grn_command_input_at(be9816251692c17b).(grn_ctxcxx . . $ grn_ctx# *ctx,
129 grn_command_inputcxx . . $ grn_command_input# *input,
130 unsigned int offset)
131 {
132 grn_objcxx . . $ grn_obj# *argument = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!;
133
134 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
135 if (input->argumentscxx . . $ _grn_command_input#arguments.) {
136 argument = (grn_objcxx . . $ grn_obj# *)grn_hash_get_value_cxx . . $ grn_hash_get_value_(9e5907222c08364c).(ctx, input->argumentscxx . . $ _grn_command_input#arguments.,
137 offset + 1, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!);
138 }
139 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(argument);
140 }
141
142 grn_objcxx . . $ grn_obj# *
143 grn_command_input_get_argumentscxx . . $ grn_command_input_get_arguments(b3499d061eb55282).(grn_ctxcxx . . $ grn_ctx# *ctx,
144 grn_command_inputcxx . . $ grn_command_input# *input)
145 {
146 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
147 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!((grn_obj *)(input->arguments));
148 }
149
150 grn_rccxx . . $ grn_rc#
151 grn_command_registercxx . . $ grn_command_register(e1390d92f5785993).(grn_ctxcxx . . $ grn_ctx# *ctx,
152 const char *command_name,
153 int command_name_size,
154 grn_command_run_funccxx . . $ grn_command_run_func# *run,
155 grn_expr_varcxx . . $ grn_expr_var# *vars,
156 unsigned int n_vars,
157 void *user_data)
158 {
159 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
160
161 if (command_name_size == -1) {
162 command_name_size = (int)strlencxx . . $ strlen(751346f8406fd082).(command_name);
163 }
164
165 {
166 grn_objcxx . . $ grn_obj# *command_object;
167 command_object = grn_proc_createcxx . . $ grn_proc_create(195df001e5324f57).(ctx,
168 command_name,
169 command_name_size,
170 GRN_PROC_COMMANDcxx . . $ GRN_PROC_COMMAND.,
171 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, n_vars, vars);
172 if (!command_object) {
173 GRN_PLUGIN_ERRORcxx . . $ `include/groonga/plugin.h:145:9`!(ctx, GRN_COMMAND_ERROR,
174 "[command][%.*s] failed to grn_proc_create()",
175 command_name_size, command_name);
176 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
177 }
178
179 {
180 grn_proccxx . . $ grn_proc# *command = (grn_proccxx . . $ grn_proc# *)command_object;
181 command->callbackscxx . . $ _grn_proc#callbacks..commandcxx . . $ _grn_proc#$anonymous_type_5#command..runcxx . . $ _grn_proc#$anonymous_type_5#$anonymous_type_7#run. = run;
182 command->user_datacxx . . $ _grn_proc#user_data. = user_data;
183 }
184 }
185
186 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(GRN_SUCCESS);
187 }
188
189 grn_rccxx . . $ grn_rc#
190 grn_command_runcxx . . $ grn_command_run(49a6209fd189e21f).(grn_ctxcxx . . $ grn_ctx# *ctx,
191 grn_objcxx . . $ grn_obj# *command,
192 grn_command_inputcxx . . $ grn_command_input# *input)
193 {
194 grn_proccxx . . $ grn_proc# *proc;
195
196 GRN_API_ENTERcxx . . $ `lib/grn_ctx.h:41:9`!;
197
198 proc = (grn_proccxx . . $ grn_proc# *)command;
199 if (proc->callbackscxx . . $ _grn_proc#callbacks..commandcxx . . $ _grn_proc#$anonymous_type_5#command..runcxx . . $ _grn_proc#$anonymous_type_5#$anonymous_type_7#run.) {
200 proc->callbackscxx . . $ _grn_proc#callbacks..commandcxx . . $ _grn_proc#$anonymous_type_5#command..runcxx . . $ _grn_proc#$anonymous_type_5#$anonymous_type_7#run.(ctx, command, input, proc->user_datacxx . . $ _grn_proc#user_data.);
201 } else {
202 /* TODO: REMOVE ME. For backward compatibility. */
203 uint32_tcxx . . $ uint32_t# stack_curr = ctx->implcxx . . $ _grn_ctx#impl.->stack_currcxx . . $ _grn_ctx_impl#stack_curr.;
204 grn_proc_callcxx . . $ grn_proc_call(1b9fa3746cdeffe4).(ctx, command, 0, command);
205 if (ctx->implcxx . . $ _grn_ctx#impl.->stack_currcxx . . $ _grn_ctx_impl#stack_curr. > stack_curr) {
206 grn_ctx_popcxx . . $ grn_ctx_pop(ddec8e3b1327ceae).(ctx);
207 }
208 }
209
210 GRN_API_RETURNcxx . . $ `lib/grn_ctx.h:56:9`!(ctx->rc);
211 }