Debian Codegraph @

src/cli.c

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
1 /*
2 * Copyright (c) 2014-2022 Joris Vink <[email protected]>
3 *
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17 #include <sys/param.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 #include <sys/queue.h>
21 #include <sys/wait.h>
22 #include <sys/mman.h>
23 #include <sys/time.h>
24
25 #if !defined(KODEV_MINIMAL)
26 #include <openssl/err.h>
27 #include <openssl/pem.h>
28 #include <openssl/x509v3.h>
29 #endif
30
31 #include <ctype.h>
32 #include <errno.h>
33 #include <dirent.h>
34 #include <libgen.h>
35 #include <inttypes.h>
36 #include <fcntl.h>
37 #include <time.h>
38 #include <stdarg.h>
39 #include <signal.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <unistd.h>
44 #include <utime.h>
45
•46 /*
47 * Turn off deprecated function warnings when building against OpenSSL 3.
48 *
49 * The OpenSSL 3 library deprecated most low-level functions in favour
50 * for their higher level APIs.
51 *
52 * I am planning a replacement, but for now we can still make it build
53 * and function by ignoring these warnings completely.
54 *
55 * The functions in question are:
56 * - SHA256_Init, SHA256_Update, SHA256_Final
57 * - RSA_new, RSA_generate_key_ex
58 * - EVP_PKEY_assign
59 */
60 #if defined(OPENSSL_VERSION_MAJORcxx . . $ `<external>/4166512202731279593/opensslv.h:31:10`!) && OPENSSL_VERSION_MAJORcxx . . $ `<external>/4166512202731279593/opensslv.h:31:10`! >= 3
61 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
62 #endif
63
64 #define errno_scxx . . $ `src/cli.c:64:9`! strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!)
65 #define ssl_errno_scxx . . $ `src/cli.c:65:9`! ERR_error_string(ERR_get_error(), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
66
67 #define LD_FLAGS_MAXcxx . . $ `src/cli.c:67:9`! 300
68 #define CFLAGS_MAXcxx . . $ `src/cli.c:68:9`! 300
69 #define CXXFLAGS_MAXcxx . . $ `src/cli.c:69:9`! CFLAGS_MAXcxx . . $ `src/cli.c:68:9`!
70
71 #define BUILD_NOBUILDcxx . . $ `src/cli.c:71:9`! 0
72 #define BUILD_Ccxx . . $ `src/cli.c:72:9`! 1
73 #define BUILD_CXXcxx . . $ `src/cli.c:73:9`! 2
74
75 struct cli_bufcxx . . $ cli_buf# {
76 u_int8_tcxx . . $ u_int8_t# *datacxx . . $ cli_buf#data.;
77 size_t lengthcxx . . $ cli_buf#length.;
78 size_t offsetcxx . . $ cli_buf#offset.;
79 };
80
81 struct mime_typecxx . . $ mime_type# {
82 char *extcxx . . $ mime_type#ext.;
83 char *typecxx . . $ mime_type#type.;
84 TAILQ_ENTRYcxx . . $ `<external>/2546723208511035544/queue.h:382:9`!(mime_type) listcxx . . $ mime_type#list.;
85 };
86
87 TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(mime_list, mime_type);
88
89 struct buildoptcxx . . $ buildopt# {
90 char *namecxx . . $ buildopt#name.;
91 char *kore_sourcecxx . . $ buildopt#kore_source.;
92 char *kore_flavorcxx . . $ buildopt#kore_flavor.;
93 int flavor_nohttpcxx . . $ buildopt#flavor_nohttp.;
94 int single_binarycxx . . $ buildopt#single_binary.;
95 struct cli_bufcxx . . $ cli_buf# *cflagscxx . . $ buildopt#cflags.;
96 struct cli_bufcxx . . $ cli_buf# *cxxflagscxx . . $ buildopt#cxxflags.;
97 struct cli_bufcxx . . $ cli_buf# *ldflagscxx . . $ buildopt#ldflags.;
98 TAILQ_ENTRYcxx . . $ `<external>/2546723208511035544/queue.h:382:9`!(buildopt) listcxx . . $ buildopt#list.;
99 };
100
101 TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(buildopt_list, buildopt);
102
103 struct cmdcxx . . $ cmd# {
104 const char *namecxx . . $ cmd#name.;
105 const char *descrcxx . . $ cmd#descr.;
106 void (*cbcxx . . $ cmd#cb.)(int, char **);
107 };
108
109 struct filegencxx . . $ filegen# {
110 void (*cbcxx . . $ filegen#cb.)(void);
111 };
112
113 struct cfilecxx . . $ cfile# {
114 struct statcxx . . $ stat# stcxx . . $ cfile#st.;
115 int buildcxx . . $ cfile#build.;
116 char *namecxx . . $ cfile#name.;
117 char *fpathcxx . . $ cfile#fpath.;
118 char *opathcxx . . $ cfile#opath.;
119 TAILQ_ENTRYcxx . . $ `<external>/2546723208511035544/queue.h:382:9`!(cfile) listcxx . . $ cfile#list.;
120 };
121
122 TAILQ_HEADcxx . . $ `<external>/2546723208511035544/queue.h:372:9`!(cfile_list, cfile);
123
124 static struct cli_bufcxx . . $ cli_buf# *cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(size_t);
125 static void cli_buf_freecxx . . $ cli_buf_free(d5b55d6d3363602b).(struct cli_bufcxx . . $ cli_buf# *);
126 static char *cli_buf_stringifycxx . . $ cli_buf_stringify(9f2dd2ca3f41a58f).(struct cli_bufcxx . . $ cli_buf# *, size_t *);
127 static void cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(struct cli_bufcxx . . $ cli_buf# *, const void *, size_t);
128 static void cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(struct cli_bufcxx . . $ cli_buf# *, const char *, ...)
129 __attribute__((format (printf, 2, 3)));
130 static void cli_buf_appendvcxx . . $ cli_buf_appendv(38140e4e3631ec2c).(struct cli_bufcxx . . $ cli_buf# *, const char *,
131 va_listcxx . . $ va_list#) __attribute__((format (printf, 2, 0)));
132
133 static void *cli_malloccxx . . $ cli_malloc(bfcfa4d6b7f7ef64).(size_t);
134 static char *cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(const char *);
135 static void *cli_realloccxx . . $ cli_realloc(417ab160f6baadc6).(void *, size_t);
136
137 static char *cli_text_trimcxx . . $ cli_text_trim(dff97f9eb74e1544).(char *, size_t);
138 static char *cli_read_linecxx . . $ cli_read_line(8c0cb784ce79381a).(FILEcxx . . $ FILE# *, char *, size_t);
139 static long long cli_strtonumcxx . . $ cli_strtonum(f0816a4ef2da3e2).(const char *, long long, long long);
140 static int cli_split_stringcxx . . $ cli_split_string(87b756e43bd5489c).(char *, const char *, char **, size_t);
141
142 static void usagecxx . . $ usage(8df32a62017fbbf6).(void) __attribute__((noreturn));
143 static void fatalcxx . . $ fatal(f6bc48f0426f26ee).(const char *, ...) __attribute__((noreturn))
144 __attribute__((format (printf, 1, 2)));
145
146 static void cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(int);
147 static void cli_run_korecxx . . $ cli_run_kore(49f6e7a06ebc5aa8).(void);
148 static void cli_run_kore_pythoncxx . . $ cli_run_kore_python(49f6e7a06ebc5aa8).(void);
149 static void cli_compile_korecxx . . $ cli_compile_kore(5d22bdacc48458e8).(void *);
150 static void cli_link_applicationcxx . . $ cli_link_application(5d22bdacc48458e8).(void *);
151 static void cli_compile_source_filecxx . . $ cli_compile_source_file(5d22bdacc48458e8).(void *);
152 static void cli_mkdircxx . . $ cli_mkdir(34d26762b42c433a).(const char *, int);
153 static int cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).(const char *);
154 static int cli_file_existscxx . . $ cli_file_exists(5c4306d8553b3696).(const char *);
155 static void cli_cleanup_filescxx . . $ cli_cleanup_files(85c52e162fed56f9).(const char *);
156 static void cli_build_cflagscxx . . $ cli_build_cflags(54061a8567f96e74).(struct buildoptcxx . . $ buildopt# *);
157 static void cli_build_cxxflagscxx . . $ cli_build_cxxflags(54061a8567f96e74).(struct buildoptcxx . . $ buildopt# *);
158 static void cli_build_ldflagscxx . . $ cli_build_ldflags(54061a8567f96e74).(struct buildoptcxx . . $ buildopt# *);
159 static void cli_file_readcxx . . $ cli_file_read(2a5d023f7acf84ed).(int, char **, size_t *);
160 static void cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(int, const char *, ...)
161 __attribute__((format (printf, 2, 3)));
162 static void cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(const char *, int, int *);
163 static void cli_file_removecxx . . $ cli_file_remove(9f788ba9b5df10c4).(char *, struct direntcxx . . $ dirent# *);
164 static void cli_build_assetcxx . . $ cli_build_asset(9f788ba9b5df10c4).(char *, struct direntcxx . . $ dirent# *);
165 static void cli_file_writecxx . . $ cli_file_write(b0323033f2ee8f70).(int, const void *, size_t);
166 static int cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(char **, const char *, ...)
167 __attribute__((format (printf, 2, 3)));
168 static void cli_spawn_proccxx . . $ cli_spawn_proc(97a347b124788245).(void (*cb)(void *), void *);
169 static void cli_write_assetcxx . . $ cli_write_asset(26204e3dd21c9412).(const char *, const char *,
170 struct buildoptcxx . . $ buildopt# *);
171 static void cli_register_kore_filecxx . . $ cli_register_kore_file(9f788ba9b5df10c4).(char *, struct direntcxx . . $ dirent# *);
172 static void cli_register_source_filecxx . . $ cli_register_source_file(9f788ba9b5df10c4).(char *, struct direntcxx . . $ dirent# *);
173 static int cli_file_requires_buildcxx . . $ cli_file_requires_build(7a8b711032b90e60).(struct statcxx . . $ stat# *, const char *);
174 static void cli_find_filescxx . . $ cli_find_files(b304834a9fe4a1c9).(const char *,
175 void (*cb)(char *, struct direntcxx . . $ dirent# *));
176 static void cli_add_source_filecxx . . $ cli_add_source_file(559b971b9c7206c1).(char *, char *, char *,
177 struct statcxx . . $ stat# *, int);
178
179 static struct buildoptcxx . . $ buildopt# *cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).(void);
180 static struct buildoptcxx . . $ buildopt# *cli_buildopt_newcxx . . $ cli_buildopt_new(dd450b94293e0318).(const char *);
181 static struct buildoptcxx . . $ buildopt# *cli_buildopt_findcxx . . $ cli_buildopt_find(dd450b94293e0318).(const char *);
182 static void cli_buildopt_cleanupcxx . . $ cli_buildopt_cleanup(49f6e7a06ebc5aa8).(void);
183 static void cli_buildopt_parsecxx . . $ cli_buildopt_parse(85c52e162fed56f9).(const char *);
184 static void cli_buildopt_cflagscxx . . $ cli_buildopt_cflags(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *, const char *);
185 static void cli_buildopt_cxxflagscxx . . $ cli_buildopt_cxxflags(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *, const char *);
186 static void cli_buildopt_ldflagscxx . . $ cli_buildopt_ldflags(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *, const char *);
187 static void cli_buildopt_single_binarycxx . . $ cli_buildopt_single_binary(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *,
188 const char *);
189 static void cli_buildopt_kore_sourcecxx . . $ cli_buildopt_kore_source(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *,
190 const char *);
191 static void cli_buildopt_kore_flavorcxx . . $ cli_buildopt_kore_flavor(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *,
192 const char *);
193 static void cli_buildopt_mimecxx . . $ cli_buildopt_mime(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *, const char *);
194
195 static void cli_build_flags_commoncxx . . $ cli_build_flags_common(28dfde3d75c7a877).(struct buildoptcxx . . $ buildopt# *,
196 struct cli_bufcxx . . $ cli_buf# *);
197
198 static void cli_flavor_loadcxx . . $ cli_flavor_load(49f6e7a06ebc5aa8).(void);
199 static void cli_flavor_changecxx . . $ cli_flavor_change(85c52e162fed56f9).(const char *);
200 static void cli_kore_load_filecxx . . $ cli_kore_load_file(e1272f335b4a478d).(const char *, struct buildoptcxx . . $ buildopt# *,
201 char **, size_t *);
202
203 static void cli_runcxx . . $ cli_run(c759356ac01a31e7).(int, char **);
204 static void cli_helpcxx . . $ cli_help(c759356ac01a31e7).(int, char **);
205 static void cli_infocxx . . $ cli_info(c759356ac01a31e7).(int, char **);
206 static void cli_buildcxx . . $ cli_build(c759356ac01a31e7).(int, char **);
207 static void cli_cleancxx . . $ cli_clean(c759356ac01a31e7).(int, char **);
208 static void cli_sourcecxx . . $ cli_source(c759356ac01a31e7).(int, char **);
209 static void cli_reloadcxx . . $ cli_reload(c759356ac01a31e7).(int, char **);
210 static void cli_flavorcxx . . $ cli_flavor(c759356ac01a31e7).(int, char **);
211 static void cli_cflagscxx . . $ cli_cflags(c759356ac01a31e7).(int, char **);
212 static void cli_ldflagscxx . . $ cli_ldflags(c759356ac01a31e7).(int, char **);
213 static void cli_genassetcxx . . $ cli_genasset(c759356ac01a31e7).(int, char **);
214 static void cli_genasset_helpcxx . . $ cli_genasset_help(49f6e7a06ebc5aa8).(void);
215
216 #if !defined(KODEV_MINIMAL)
217 static void cli_createcxx . . $ cli_create(c759356ac01a31e7).(int, char **);
218 static void cli_create_helpcxx . . $ cli_create_help(49f6e7a06ebc5aa8).(void);
219
220 static void file_create_srccxx . . $ file_create_src(49f6e7a06ebc5aa8).(void);
221 static void file_create_configcxx . . $ file_create_config(49f6e7a06ebc5aa8).(void);
222 static void file_create_gitignorecxx . . $ file_create_gitignore(49f6e7a06ebc5aa8).(void);
223 static void file_create_python_srccxx . . $ file_create_python_src(49f6e7a06ebc5aa8).(void);
224
225 static void cli_generate_certscxx . . $ cli_generate_certs(49f6e7a06ebc5aa8).(void);
226 static void cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).(const char *, const char *, size_t);
227 #endif
228
229 static struct cmdcxx . . $ cmd# cmdscxx . . $ cmds.[] = {
230 { "help", "this help text", cli_helpcxx . . $ cli_help(c759356ac01a31e7). },
231 { "run", "run an application (-fnr implied)", cli_runcxx . . $ cli_run(c759356ac01a31e7). },
232 { "gen", "generate asset file for compilation", cli_genassetcxx . . $ cli_genasset(c759356ac01a31e7). },
233 { "reload", "reload the application (SIGHUP)", cli_reloadcxx . . $ cli_reload(c759356ac01a31e7). },
234 { "info", "show info on kore on this system", cli_infocxx . . $ cli_info(c759356ac01a31e7). },
235 { "build", "build an application", cli_buildcxx . . $ cli_build(c759356ac01a31e7). },
236 { "clean", "cleanup the build files", cli_cleancxx . . $ cli_clean(c759356ac01a31e7). },
237 { "source", "print the path to kore sources", cli_sourcecxx . . $ cli_source(c759356ac01a31e7). },
238 #if !defined(KODEV_MINIMAL)
239 { "create", "create a new application skeleton", cli_createcxx . . $ cli_create(c759356ac01a31e7). },
240 #endif
241 { "flavor", "switch between build flavors", cli_flavorcxx . . $ cli_flavor(c759356ac01a31e7). },
242 { "cflags", "show kore CFLAGS", cli_cflagscxx . . $ cli_cflags(c759356ac01a31e7). },
243 { "ldflags", "show kore LDFLAGS", cli_ldflagscxx . . $ cli_ldflags(c759356ac01a31e7). },
244 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! }
245 };
246
247 #if !defined(KODEV_MINIMAL)
248 static struct filegencxx . . $ filegen# gen_filescxx . . $ gen_files.[] = {
249 { file_create_srccxx . . $ file_create_src(49f6e7a06ebc5aa8). },
250 { file_create_configcxx . . $ file_create_config(49f6e7a06ebc5aa8). },
251 { file_create_gitignorecxx . . $ file_create_gitignore(49f6e7a06ebc5aa8). },
252 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! }
253 };
254
255 static const char *gen_dirscxx . . $ gen_dirs.[] = {
256 "src",
257 "cert",
258 "conf",
259 "assets",
260 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!
261 };
262
263 static const char *python_gen_dirscxx . . $ python_gen_dirs.[] = {
264 "cert",
265 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!
266 };
267
268 static struct filegencxx . . $ filegen# python_gen_filescxx . . $ python_gen_files.[] = {
269 { file_create_python_srccxx . . $ file_create_python_src(49f6e7a06ebc5aa8). },
270 { file_create_gitignorecxx . . $ file_create_gitignore(49f6e7a06ebc5aa8). },
271 { NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! }
272 };
273
274 static const char *http_serveable_functioncxx . . $ http_serveable_function. =
275 "int\n"
276 "asset_serve_%s_%s(struct http_request *req)\n"
277 "{\n"
278 " http_serveable(req, asset_%s_%s, asset_len_%s_%s,\n"
279 " asset_sha256_%s_%s, \"%s\");\n"
280 " return (KORE_RESULT_OK);\n"
281 "}\n";
282
283 static const char *src_datacxx . . $ src_data. =
284 "#include <kore/kore.h>\n"
285 "#include <kore/http.h>\n"
286 "\n"
287 "int\t\tpage(struct http_request *);\n"
288 "\n"
289 "int\n"
290 "page(struct http_request *req)\n"
291 "{\n"
292 "\thttp_response(req, 200, NULL, 0);\n"
293 "\treturn (KORE_RESULT_OK);\n"
294 "}\n";
295
296 static const char *config_datacxx . . $ config_data. =
297 "# %s configuration\n"
298 "\n"
299 "server tls {\n"
300 "\tbind 127.0.0.1 8888\n"
301 "}\n"
302 "\n"
303 "load\t\t./%s.so\n"
304 "\n"
305 "domain * {\n"
306 "\tattach\t\ttls\n"
307 "\n"
308 "\tcertfile\tcert/server.pem\n"
309 "\tcertkey\t\tcert/key.pem\n"
310 "\n"
311 "\troute / {\n"
312 "\t\thandler page\n"
313 "\t}\n"
314 "\n"
315 "}\n";
316
317 static const char *build_datacxx . . $ build_data. =
318 "# %s build config\n"
319 "# You can switch flavors using: kodev flavor [newflavor]\n"
320 "\n"
321 "# Set to yes if you wish to produce a single binary instead\n"
322 "# of a dynamic library. If you set this to yes you must also\n"
323 "# set kore_source together with kore_flavor.\n"
324 "#single_binary=no\n"
325 "#kore_source=/home/joris/src/kore\n"
326 "#kore_flavor=\n"
327 "\n"
328 "# The flags below are shared between flavors\n"
329 "cflags=-Wall -Wmissing-declarations -Wshadow\n"
330 "cflags=-Wstrict-prototypes -Wmissing-prototypes\n"
331 "cflags=-Wpointer-arith -Wcast-qual -Wsign-compare\n"
332 "\n"
333 "cxxflags=-Wall -Wmissing-declarations -Wshadow\n"
334 "cxxflags=-Wpointer-arith -Wcast-qual -Wsign-compare\n"
335 "\n"
336 "# Mime types for assets served via the builtin asset_serve_*\n"
337 "#mime_add=txt:text/plain; charset=utf-8\n"
338 "#mime_add=png:image/png\n"
339 "#mime_add=html:text/html; charset=utf-8\n"
340 "\n"
341 "dev {\n"
342 " # These flags are added to the shared ones when\n"
343 " # you build the \"dev\" flavor.\n"
344 " cflags=-g\n"
345 " cxxflags=-g\n"
346 "}\n"
347 "\n"
348 "#prod {\n"
349 "# You can specify additional flags here which are only\n"
350 "# included if you build with the \"prod\" flavor.\n"
351 "#}\n";
352
353 static const char *python_init_datacxx . . $ python_init_data. =
354 "from .app import koreapp\n";
355
356 static const char *python_app_datacxx . . $ python_app_data. =
357 "import kore\n"
358 "\n"
359 "class KoreApp:\n"
360 " def configure(self, args):\n"
361 " kore.config.deployment = \"development\"\n"
362 " kore.server(\"default\", ip=\"127.0.0.1\", port=\"8888\")\n"
363 "\n"
364 " d = kore.domain(\"*\",\n"
365 " attach=\"default\",\n"
366 " key=\"cert/key.pem\",\n"
367 " cert=\"cert/server.pem\",\n"
368 " )\n"
369 "\n"
370 " d.route(\"/\", self.index, methods=[\"get\"])\n"
371 "\n"
372 " async def index(self, req):\n"
373 " req.response(200, b'')\n"
374 "\n"
375 "koreapp = KoreApp()";
376
377 static const char *gitignorecxx . . $ gitignore. = "*.o\n.flavor\n.objs\n%s.so\nassets.h\ncert\n";
378
379 #endif /* !KODEV_MINIMAL */
380
381 static int s_fdcxx . . $ s_fd. = -1;
382 static char *applcxx . . $ appl. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
383 static int run_aftercxx . . $ run_after. = 0;
384 static char *compiler_ccxx . . $ compiler_c. = "cc";
385 static char *compiler_cppcxx . . $ compiler_cpp. = "c++";
386 static char *compiler_ldcxx . . $ compiler_ld. = "cc";
387 static const char *prefixcxx . . $ prefix. = PREFIXcxx . . $ `<built-in>:415:9`!;
388 static struct mime_listcxx . . $ mime_list# mime_typescxx . . $ mime_types.;
389 static struct cfile_listcxx . . $ cfile_list# source_filescxx . . $ source_files.;
390 static struct buildopt_listcxx . . $ buildopt_list# build_optionscxx . . $ build_options.;
391 static int source_files_countcxx . . $ source_files_count.;
392 static int cxx_files_countcxx . . $ cxx_files_count.;
393 static struct cmdcxx . . $ cmd# *commandcxx . . $ command. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
394 static int cflags_countcxx . . $ cflags_count. = 0;
395 static int genasset_cmdcxx . . $ genasset_cmd. = 0;
396 static int cxxflags_countcxx . . $ cxxflags_count. = 0;
397 static int ldflags_countcxx . . $ ldflags_count. = 0;
398 static char *flavorcxx . . $ flavor. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
399 static char *out_dircxx . . $ out_dir. = ".";
400 static char *object_dircxx . . $ object_dir. = ".objs";
401 static char *cflagscxx . . $ cflags.[CFLAGS_MAXcxx . . $ `src/cli.c:68:9`!];
402 static char *cxxflagscxx . . $ cxxflags.[CXXFLAGS_MAXcxx . . $ `src/cli.c:69:9`!];
403 static char *ldflagscxx . . $ ldflags.[LD_FLAGS_MAXcxx . . $ `src/cli.c:67:9`!];
404
405 static void
406 usagecxx . . $ usage(8df32a62017fbbf6).(void)
407 {
408 int i;
409
410 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Usage: kodev [command]\n");
411 #if defined(KODEV_MINIMAL)
412 fprintf(stderr, "minimal (only build commands supported)\n");
413 #endif
414 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\nAvailable commands:\n");
415
416 for (i = 0; cmdscxx . . $ cmds.[i].namecxx . . $ cmd#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; i++)
417 printfcxx . . $ printf(581fddd72a8db8fc).("\t%s\t%s\n", cmdscxx . . $ cmds.[i].namecxx . . $ cmd#name., cmdscxx . . $ cmds.[i].descrcxx . . $ cmd#descr.);
418
419 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\nFind more information on https://kore.io\n");
420 exitcxx . . $ exit(3ca292c338df9bb3).(1);
421 }
422
423 int
424 maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv)
425 {
426 int i;
427 char *env;
428
429 if (argc < 2)
430 usagecxx . . $ usage(8df32a62017fbbf6).();
431
432 argc--;
433 argv++;
434
435 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("KORE_PREFIX")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
436 prefixcxx . . $ prefix. = env;
437
438 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("KORE_OBJDIR")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
439 object_dircxx . . $ object_dir. = env;
440
441 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("KODEV_OUTPUT")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
442 out_dircxx . . $ out_dir. = env;
443
444 (void)umaskcxx . . $ umask(2141b656ce2cc063).(S_IWGRPcxx . . $ `<external>/14710646456994434043/fcntl.h:112:10`! | S_IWOTHcxx . . $ `<external>/14710646456994434043/fcntl.h:118:10`!);
445
446 for (i = 0; cmdscxx . . $ cmds.[i].namecxx . . $ cmd#name. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; i++) {
447 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[0], cmdscxx . . $ cmds.[i].namecxx . . $ cmd#name.)) {
448 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[0], "create")) {
449 argc--;
450 argv++;
451 }
452 commandcxx . . $ command. = &cmdscxx . . $ cmds.[i];
453 cmdscxx . . $ cmds.[i].cbcxx . . $ cmd#cb.(argc, argv);
454 break;
455 }
456 }
457
458 if (cmdscxx . . $ cmds.[i].namecxx . . $ cmd#name. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
459 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "unknown command: %s\n", argv[0]);
460 usagecxx . . $ usage(8df32a62017fbbf6).();
461 }
462
463 return (0);
464 }
465
466 static void
467 cli_helpcxx . . $ cli_help(c759356ac01a31e7).(int argc, char **argv)
468 {
469 usagecxx . . $ usage(8df32a62017fbbf6).();
470 }
471
472 #if !defined(KODEV_MINIMAL)
473 static void
474 cli_create_helpcxx . . $ cli_create_help(49f6e7a06ebc5aa8).(void)
475 {
476 printfcxx . . $ printf(581fddd72a8db8fc).("Usage: kodev create [-p] [name]\n");
477 printfcxx . . $ printf(581fddd72a8db8fc).("Synopsis:\n");
478 printfcxx . . $ printf(581fddd72a8db8fc).(" Create a new application skeleton directory structure.\n");
479 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
480 printfcxx . . $ printf(581fddd72a8db8fc).(" Optional flags:\n");
481 printfcxx . . $ printf(581fddd72a8db8fc).("\t-p = generate a python application skeleton\n");
482
483 exitcxx . . $ exit(3ca292c338df9bb3).(1);
484 }
485
486 static void
487 cli_createcxx . . $ cli_create(c759356ac01a31e7).(int argc, char **argv)
488 {
489 char *fpath;
490 const char **dirs;
491 struct filegencxx . . $ filegen# *files;
492 int i, ch, python;
493
494 python = 0;
495
496 while ((ch = getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, "hp")) != -1) {
497 switch (ch) {
498 case 'h':
499 cli_create_helpcxx . . $ cli_create_help(49f6e7a06ebc5aa8).();
500 break;
501 case 'p':
502 python = 1;
503 break;
504 default:
505 cli_create_helpcxx . . $ cli_create_help(49f6e7a06ebc5aa8).();
506 break;
507 }
508 }
509
510 argc -= optindcxx . . $ optind.;
511 argv += optindcxx . . $ optind.;
512
513 if (argc != 1)
514 cli_create_helpcxx . . $ cli_create_help(49f6e7a06ebc5aa8).();
515
516 applcxx . . $ appl. = argv[0];
517 cli_mkdircxx . . $ cli_mkdir(34d26762b42c433a).(applcxx . . $ appl., 0755);
518
519 if (python) {
520 dirs = python_gen_dirscxx . . $ python_gen_dirs.;
521 files = python_gen_filescxx . . $ python_gen_files.;
522 } else {
523 dirs = gen_dirscxx . . $ gen_dirs.;
524 files = gen_filescxx . . $ gen_files.;
525 }
526
527 for (i = 0; dirs[i] != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; i++) {
528 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&fpath, "%s/%s", applcxx . . $ appl., dirs[i]);
529 cli_mkdircxx . . $ cli_mkdir(34d26762b42c433a).(fpath, 0755);
530 freecxx . . $ free(5d22bdacc48458e8).(fpath);
531 }
532
533 for (i = 0; files[i].cbcxx . . $ filegen#cb. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; i++)
534 files[i].cbcxx . . $ filegen#cb.();
535
536 if (chdircxx . . $ chdir(5c4306d8553b3696).(applcxx . . $ appl.) == -1)
537 fatalcxx . . $ fatal(f6bc48f0426f26ee).("chdir(%s): %s", applcxx . . $ appl., errno_scxx . . $ `src/cli.c:64:9`!);
538
539 cli_generate_certscxx . . $ cli_generate_certs(49f6e7a06ebc5aa8).();
540
541 printfcxx . . $ printf(581fddd72a8db8fc).("%s created successfully!\n", applcxx . . $ appl.);
542 printfcxx . . $ printf(581fddd72a8db8fc).("WARNING: DO NOT USE THE GENERATED CERTIFICATE IN PRODUCTION\n");
543 }
544 #endif
545
546 static void
547 cli_flavorcxx . . $ cli_flavor(c759356ac01a31e7).(int argc, char **argv)
548 {
549 struct buildoptcxx . . $ buildopt# *bopt;
550 char pwd[MAXPATHLENcxx . . $ `<external>/1231830743887005719/param.h:48:10`!], *conf;
551
552 if (getcwdcxx . . $ getcwd(dff97f9eb74e1544).(pwd, sizeof(pwd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
553 fatalcxx . . $ fatal(f6bc48f0426f26ee).("could not get cwd: %s", errno_scxx . . $ `src/cli.c:64:9`!);
554
555 applcxx . . $ appl. = basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(pwd);
556 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&conf, "conf/%s.conf", applcxx . . $ appl.);
557 if (!cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).("conf") || !cli_file_existscxx . . $ cli_file_exists(5c4306d8553b3696).(conf))
558 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s doesn't appear to be a kore app", applcxx . . $ appl.);
559 freecxx . . $ free(5d22bdacc48458e8).(conf);
560
561 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&build_options);
562 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&mime_types);
563 (void)cli_buildopt_newcxx . . $ cli_buildopt_new(dd450b94293e0318).("_default");
564 cli_buildopt_parsecxx . . $ cli_buildopt_parse(85c52e162fed56f9).("conf/build.conf");
565
566 if (argc == 0) {
567 cli_flavor_loadcxx . . $ cli_flavor_load(49f6e7a06ebc5aa8).();
568 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(bopt, &build_options, list) {
569 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(bopt->namecxx . . $ buildopt#name., "_default"))
570 continue;
571 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(bopt->namecxx . . $ buildopt#name., flavorcxx . . $ flavor.)) {
572 printfcxx . . $ printf(581fddd72a8db8fc).("* %s\n", bopt->namecxx . . $ buildopt#name.);
573 } else {
574 printfcxx . . $ printf(581fddd72a8db8fc).(" %s\n", bopt->namecxx . . $ buildopt#name.);
575 }
576 }
577 } else {
578 cli_flavor_changecxx . . $ cli_flavor_change(85c52e162fed56f9).(argv[0]);
579 printfcxx . . $ printf(581fddd72a8db8fc).("changed build flavor to: %s\n", argv[0]);
580 }
581
582 cli_buildopt_cleanupcxx . . $ cli_buildopt_cleanup(49f6e7a06ebc5aa8).();
583 }
584
585 static void
586 cli_buildcxx . . $ cli_build(c759356ac01a31e7).(int argc, char **argv)
587 {
588 #if !defined(KODEV_MINIMAL)
589 int l;
590 char *data;
591 #endif
592 struct direntcxx . . $ dirent# dp;
593 struct cfilecxx . . $ cfile# *cf;
594 struct buildoptcxx . . $ buildopt# *bopt;
595 struct timevalcxx . . $ timeval# times[2];
596 char *build_path;
597 char *vsrc, *vobj;
598 int requires_relink;
599 char *sofile, *config;
600 char *assets_path, *p, *src_path;
601 char pwd[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!], *assets_header;
602
603 if (getcwdcxx . . $ getcwd(dff97f9eb74e1544).(pwd, sizeof(pwd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
604 fatalcxx . . $ fatal(f6bc48f0426f26ee).("could not get cwd: %s", errno_scxx . . $ `src/cli.c:64:9`!);
605
606 applcxx . . $ appl. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(pwd));
607
608 if ((p = getenvcxx . . $ getenv(a8b8e32347182212).("CC")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
609 compiler_ccxx . . $ compiler_c. = p;
610 compiler_ldcxx . . $ compiler_ld. = p;
611 }
612
613 if ((p = getenvcxx . . $ getenv(a8b8e32347182212).("CXX")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
614 compiler_cppcxx . . $ compiler_cpp. = p;
615 compiler_ldcxx . . $ compiler_ld. = p;
616 }
617
618 source_files_countcxx . . $ source_files_count. = 0;
619 cxx_files_countcxx . . $ cxx_files_count. = 0;
620 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&source_files);
621 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&build_options);
622 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&mime_types);
623
624 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&src_path, "src");
625 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&assets_path, "assets");
626 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&config, "conf/%s.conf", applcxx . . $ appl.);
627 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&build_path, "conf/build.conf");
628 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&assets_header, "%s/assets.h", object_dircxx . . $ object_dir.);
629
630 if (!cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).(src_path) || !cli_file_existscxx . . $ cli_file_exists(5c4306d8553b3696).(config))
631 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s doesn't appear to be a kore app", applcxx . . $ appl.);
632
633 cli_flavor_loadcxx . . $ cli_flavor_load(49f6e7a06ebc5aa8).();
634 bopt = cli_buildopt_newcxx . . $ cli_buildopt_new(dd450b94293e0318).("_default");
635
636 #if !defined(KODEV_MINIMAL)
637 if (!cli_file_existscxx . . $ cli_file_exists(5c4306d8553b3696).(build_path)) {
638 l = cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&data, build_datacxx . . $ build_data., applcxx . . $ appl.);
639 cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).("conf/build.conf", data, l);
640 freecxx . . $ free(5d22bdacc48458e8).(data);
641 }
642 #endif
643
644 cli_find_filescxx . . $ cli_find_files(b304834a9fe4a1c9).(src_path, cli_register_source_filecxx . . $ cli_register_source_file(9f788ba9b5df10c4).);
645 freecxx . . $ free(5d22bdacc48458e8).(src_path);
646
647 cli_buildopt_parsecxx . . $ cli_buildopt_parse(85c52e162fed56f9).(build_path);
648 freecxx . . $ free(5d22bdacc48458e8).(build_path);
649
650 if (!cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).(object_dircxx . . $ object_dir.))
651 cli_mkdircxx . . $ cli_mkdir(34d26762b42c433a).(object_dircxx . . $ object_dir., 0755);
652
653 if (bopt->single_binarycxx . . $ buildopt#single_binary.) {
654 if (bopt->kore_sourcecxx . . $ buildopt#kore_source. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
655 fatalcxx . . $ fatal(f6bc48f0426f26ee).("single_binary set but not kore_source");
656
657 printfcxx . . $ printf(581fddd72a8db8fc).("building kore (%s)\n", bopt->kore_sourcecxx . . $ buildopt#kore_source.);
658 cli_spawn_proccxx . . $ cli_spawn_proc(97a347b124788245).(cli_compile_korecxx . . $ cli_compile_kore(5d22bdacc48458e8)., bopt);
659
660 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&src_path, "%s/src", bopt->kore_sourcecxx . . $ buildopt#kore_source.);
661 cli_find_filescxx . . $ cli_find_files(b304834a9fe4a1c9).(src_path, cli_register_kore_filecxx . . $ cli_register_kore_file(9f788ba9b5df10c4).);
662 freecxx . . $ free(5d22bdacc48458e8).(src_path);
663
664 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&vsrc, "%s/version.c", object_dircxx . . $ object_dir.);
665 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&vobj, "%s/version.o", object_dircxx . . $ object_dir.);
666
667 cli_add_source_filecxx . . $ cli_add_source_file(559b971b9c7206c1).("version.c",
668 vsrc, vobj, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, BUILD_NOBUILDcxx . . $ `src/cli.c:71:9`!);
669 }
670
671 printfcxx . . $ printf(581fddd72a8db8fc).("building %s (%s)\n", applcxx . . $ appl., flavorcxx . . $ flavor.);
672
673 cli_build_cflagscxx . . $ cli_build_cflags(54061a8567f96e74).(bopt);
674 cli_build_cxxflagscxx . . $ cli_build_cxxflags(54061a8567f96e74).(bopt);
675 cli_build_ldflagscxx . . $ cli_build_ldflags(54061a8567f96e74).(bopt);
676
677 (void)unlinkcxx . . $ unlink(5c4306d8553b3696).(assets_header);
678
679 /* Generate the assets. */
680 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(assets_header, O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! | O_TRUNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:56:10`! | O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!, &s_fdcxx . . $ s_fd.);
681 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "#ifndef __H_KORE_ASSETS_H\n");
682 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "#define __H_KORE_ASSETS_H\n");
683
684 if (cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).(assets_path))
685 cli_find_filescxx . . $ cli_find_files(b304834a9fe4a1c9).(assets_path, cli_build_assetcxx . . $ cli_build_asset(9f788ba9b5df10c4).);
686
687 if (bopt->single_binarycxx . . $ buildopt#single_binary.) {
688 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&dp, 0, sizeof(dp));
689 dp.d_typecxx . . $ dirent#d_type. = DT_REGcxx . . $ `<external>/7464718065909436613/dirent.h:110:10`!;
690 printfcxx . . $ printf(581fddd72a8db8fc).("adding config %s\n", config);
691 (void)snprintfcxx . . $ snprintf(ea502d73e74c754c).(dp.d_namecxx . . $ dirent#d_name.,
692 sizeof(dp.d_namecxx . . $ dirent#d_name.), "builtin_kore.conf");
693 cli_build_assetcxx . . $ cli_build_asset(9f788ba9b5df10c4).(config, &dp);
694 }
695
696 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "\n#endif\n");
697 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(s_fdcxx . . $ s_fd.);
698
699 freecxx . . $ free(5d22bdacc48458e8).(assets_path);
700 freecxx . . $ free(5d22bdacc48458e8).(config);
701
702 if (cxx_files_countcxx . . $ cxx_files_count. > 0)
703 compiler_ldcxx . . $ compiler_ld. = compiler_cppcxx . . $ compiler_cpp.;
704
705 requires_relink = 0;
706 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(cf, &source_files, list) {
707 if (cf->buildcxx . . $ cfile#build. == BUILD_NOBUILDcxx . . $ `src/cli.c:71:9`!)
708 continue;
709
710 printfcxx . . $ printf(581fddd72a8db8fc).("compiling %s\n", cf->namecxx . . $ cfile#name.);
711 cli_spawn_proccxx . . $ cli_spawn_proc(97a347b124788245).(cli_compile_source_filecxx . . $ cli_compile_source_file(5d22bdacc48458e8)., cf);
712
713 times[0].tv_useccxx . . $ timeval#tv_usec. = 0;
714 times[0].tv_seccxx . . $ timeval#tv_sec. = cf->stcxx . . $ cfile#st..st_mtimecxx . . $ `<external>/16045971866008360577/struct_stat.h:78:11`!;
715 times[1] = times[0];
716
717 if (utimescxx . . $ utimes(6ed4149773030879).(cf->opathcxx . . $ cfile#opath., times) == -1)
718 printfcxx . . $ printf(581fddd72a8db8fc).("utime(%s): %s\n", cf->opathcxx . . $ cfile#opath., errno_scxx . . $ `src/cli.c:64:9`!);
719
720 requires_relink++;
721 }
722
723 freecxx . . $ free(5d22bdacc48458e8).(assets_header);
724
725 #if !defined(KODEV_MINIMAL)
726 if (bopt->kore_flavorcxx . . $ buildopt#kore_flavor. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ||
727 !strstrcxx . . $ strstr(a713fe7b9a57cf96).(bopt->kore_flavorcxx . . $ buildopt#kore_flavor., "NOTLS=1")) {
728 if (!cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).("cert")) {
729 cli_mkdircxx . . $ cli_mkdir(34d26762b42c433a).("cert", 0700);
730 cli_generate_certscxx . . $ cli_generate_certs(49f6e7a06ebc5aa8).();
731 }
732 }
733 #endif
734
735 if (bopt->single_binarycxx . . $ buildopt#single_binary.) {
736 requires_relink++;
737 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&sofile, "%s/%s", out_dircxx . . $ out_dir., applcxx . . $ appl.);
738 } else {
739 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&sofile, "%s/%s.so", out_dircxx . . $ out_dir., applcxx . . $ appl.);
740 }
741
742 if (!cli_file_existscxx . . $ cli_file_exists(5c4306d8553b3696).(sofile) && source_files_countcxx . . $ source_files_count. > 0)
743 requires_relink++;
744
745 freecxx . . $ free(5d22bdacc48458e8).(sofile);
746
747 if (requires_relink) {
748 cli_spawn_proccxx . . $ cli_spawn_proc(97a347b124788245).(cli_link_applicationcxx . . $ cli_link_application(5d22bdacc48458e8)., bopt);
749 printfcxx . . $ printf(581fddd72a8db8fc).("%s built successfully!\n", applcxx . . $ appl.);
750 } else {
751 printfcxx . . $ printf(581fddd72a8db8fc).("nothing to be done!\n");
752 }
753
754 if (run_aftercxx . . $ run_after. == 0)
755 cli_buildopt_cleanupcxx . . $ cli_buildopt_cleanup(49f6e7a06ebc5aa8).();
756 }
757
758 static void
759 cli_sourcecxx . . $ cli_source(c759356ac01a31e7).(int argc, char **argv)
760 {
761 printfcxx . . $ printf(581fddd72a8db8fc).("%s/share/kore/\n", prefixcxx . . $ prefix.);
762 }
763
764 static void
765 cli_cleancxx . . $ cli_clean(c759356ac01a31e7).(int argc, char **argv)
766 {
767 struct buildoptcxx . . $ buildopt# *bopt;
768 char pwd[PATH_MAXcxx . . $ `<external>/6347054901304145714/limits.h:13:9`!], *bin;
769
770 if (cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).(object_dircxx . . $ object_dir.))
771 cli_cleanup_filescxx . . $ cli_cleanup_files(85c52e162fed56f9).(object_dircxx . . $ object_dir.);
772
773 if (getcwdcxx . . $ getcwd(dff97f9eb74e1544).(pwd, sizeof(pwd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
774 fatalcxx . . $ fatal(f6bc48f0426f26ee).("could not get cwd: %s", errno_scxx . . $ `src/cli.c:64:9`!);
775
776 applcxx . . $ appl. = basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(pwd);
777
778 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&mime_types);
779 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&build_options);
780
781 cli_flavor_loadcxx . . $ cli_flavor_load(49f6e7a06ebc5aa8).();
782 bopt = cli_buildopt_newcxx . . $ cli_buildopt_new(dd450b94293e0318).("_default");
783 cli_buildopt_parsecxx . . $ cli_buildopt_parse(85c52e162fed56f9).("conf/build.conf");
784
785 if (bopt->single_binarycxx . . $ buildopt#single_binary.)
786 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&bin, "%s/%s", out_dircxx . . $ out_dir., applcxx . . $ appl.);
787 else
788 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&bin, "%s/%s.so", out_dircxx . . $ out_dir., applcxx . . $ appl.);
789
790 if (unlinkcxx . . $ unlink(5c4306d8553b3696).(bin) == -1 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!)
791 printfcxx . . $ printf(581fddd72a8db8fc).("couldn't unlink %s: %s", bin, errno_scxx . . $ `src/cli.c:64:9`!);
792
793 freecxx . . $ free(5d22bdacc48458e8).(bin);
794 }
795
796 static void
797 cli_runcxx . . $ cli_run(c759356ac01a31e7).(int argc, char **argv)
798 {
799 if (cli_file_existscxx . . $ cli_file_exists(5c4306d8553b3696).("__init__.py")) {
800 cli_run_kore_pythoncxx . . $ cli_run_kore_python(49f6e7a06ebc5aa8).();
801 return;
802 }
803
804 run_aftercxx . . $ run_after. = 1;
805 cli_buildcxx . . $ cli_build(c759356ac01a31e7).(argc, argv);
806
807 /*
808 * We are exec()'ing kore again, while we could technically set
809 * the right cli options manually and just continue running.
810 */
811 cli_run_korecxx . . $ cli_run_kore(49f6e7a06ebc5aa8).();
812 }
813
814 static void
815 cli_reloadcxx . . $ cli_reload(c759356ac01a31e7).(int argc, char **argv)
816 {
817 int fd;
818 size_t len;
819 pid_tcxx . . $ pid_t# pid;
820 char *buf;
821
822 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).("kore.pid", O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!, &fd);
823 cli_file_readcxx . . $ cli_file_read(2a5d023f7acf84ed).(fd, &buf, &len);
824 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(fd);
825
826 if (len == 0)
827 fatalcxx . . $ fatal(f6bc48f0426f26ee).("reload: pid file is empty");
828
829 buf[len - 1] = '\0';
830
831 pid = cli_strtonumcxx . . $ cli_strtonum(f0816a4ef2da3e2).(buf, 0, UINT_MAXcxx . . $ `<external>/67164224788392828/limits.h:124:9`!);
832
833 if (killcxx . . $ kill(9b79fb6aee4c0440).(pid, SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!) == -1)
834 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to reload: %s", errno_scxx . . $ `src/cli.c:64:9`!);
835
836 printfcxx . . $ printf(581fddd72a8db8fc).("reloaded application\n");
837 }
838
839 static void
840 cli_infocxx . . $ cli_info(c759356ac01a31e7).(int argc, char **argv)
841 {
842 size_t len;
843 struct buildoptcxx . . $ buildopt# *bopt;
844 char *features;
845
846 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&mime_types);
847 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&build_options);
848
849 cli_flavor_loadcxx . . $ cli_flavor_load(49f6e7a06ebc5aa8).();
850 bopt = cli_buildopt_newcxx . . $ cli_buildopt_new(dd450b94293e0318).("_default");
851 cli_buildopt_parsecxx . . $ cli_buildopt_parse(85c52e162fed56f9).("conf/build.conf");
852
853 printfcxx . . $ printf(581fddd72a8db8fc).("active flavor\t %s\n", flavorcxx . . $ flavor.);
854 printfcxx . . $ printf(581fddd72a8db8fc).("output type \t %s\n",
855 (bopt->single_binarycxx . . $ buildopt#single_binary.) ? "binary" : "dso");
856
857 if (bopt->single_binarycxx . . $ buildopt#single_binary.) {
858 printfcxx . . $ printf(581fddd72a8db8fc).("kore features\t %s\n", bopt->kore_flavorcxx . . $ buildopt#kore_flavor.);
859 printfcxx . . $ printf(581fddd72a8db8fc).("kore source \t %s\n", bopt->kore_sourcecxx . . $ buildopt#kore_source.);
860 } else {
861 cli_kore_load_filecxx . . $ cli_kore_load_file(e1272f335b4a478d).("features", bopt, &features, &len);
862 printfcxx . . $ printf(581fddd72a8db8fc).("kore binary \t %s/bin/kore\n", prefixcxx . . $ prefix.);
863 printfcxx . . $ printf(581fddd72a8db8fc).("kore features\t %.*s\n", (int)len, features);
864 freecxx . . $ free(5d22bdacc48458e8).(features);
865 }
866 }
867
868 static void
869 cli_cflagscxx . . $ cli_cflags(c759356ac01a31e7).(int argc, char **argv)
870 {
871 struct cli_bufcxx . . $ cli_buf# *buf;
872
873 buf = cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(128);
874 cli_build_flags_commoncxx . . $ cli_build_flags_common(28dfde3d75c7a877).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, buf);
875 printfcxx . . $ printf(581fddd72a8db8fc).("%.*s\n", (int)buf->offsetcxx . . $ cli_buf#offset., buf->datacxx . . $ cli_buf#data.);
876 cli_buf_freecxx . . $ cli_buf_free(d5b55d6d3363602b).(buf);
877 }
878
879 static void
880 cli_ldflagscxx . . $ cli_ldflags(c759356ac01a31e7).(int argc, char **argv)
881 {
882 char *p;
883 size_t len;
884
885 cli_kore_load_filecxx . . $ cli_kore_load_file(e1272f335b4a478d).("linker", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &p, &len);
886 printfcxx . . $ printf(581fddd72a8db8fc).("%.*s ", (int)len, p);
887
888 #if defined(__MACH__)
889 printf("-dynamiclib -undefined suppress -flat_namespace ");
890 #else
891 printfcxx . . $ printf(581fddd72a8db8fc).("-shared ");
892 #endif
893 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
894
895 freecxx . . $ free(5d22bdacc48458e8).(p);
896 }
897
898 static void
899 cli_genassetcxx . . $ cli_genasset(c759356ac01a31e7).(int argc, char **argv)
900 {
901 struct statcxx . . $ stat# st;
902 struct direntcxx . . $ dirent# dp;
903 char *hdr;
904
905 genasset_cmdcxx . . $ genasset_cmd. = 1;
906 TAILQ_INITcxx . . $ `<external>/2546723208511035544/queue.h:387:9`!(&build_options);
907 (void)cli_buildopt_newcxx . . $ cli_buildopt_new(dd450b94293e0318).("_default");
908
909 if (getenvcxx . . $ getenv(a8b8e32347182212).("KORE_OBJDIR") == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
910 object_dircxx . . $ object_dir. = out_dircxx . . $ out_dir.;
911
912 if (argv[0] == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
913 cli_genasset_helpcxx . . $ cli_genasset_help(49f6e7a06ebc5aa8).();
914
915 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&hdr, "%s/assets.h", out_dircxx . . $ out_dir.);
916 (void)unlinkcxx . . $ unlink(5c4306d8553b3696).(hdr);
917
918 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(hdr, O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! | O_TRUNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:56:10`! | O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!, &s_fdcxx . . $ s_fd.);
919 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "#ifndef __H_KORE_ASSETS_H\n");
920 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "#define __H_KORE_ASSETS_H\n");
921
922 if (statcxx . . $ stat(a9cd1e23e96f423c).(argv[0], &st) == -1)
923 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s: %s", argv[0], errno_scxx . . $ `src/cli.c:64:9`!);
924
925 if (S_ISDIRcxx . . $ `<external>/531885356569766532/stat.h:125:9`!(st.st_mode)) {
926 if (cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).(argv[0]))
927 cli_find_filescxx . . $ cli_find_files(b304834a9fe4a1c9).(argv[0], cli_build_assetcxx . . $ cli_build_asset(9f788ba9b5df10c4).);
928 } else if (S_ISREGcxx . . $ `<external>/531885356569766532/stat.h:128:9`!(st.st_mode)) {
929 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&dp, 0, sizeof(dp));
930 dp.d_typecxx . . $ dirent#d_type. = DT_REGcxx . . $ `<external>/7464718065909436613/dirent.h:110:10`!;
931 (void)snprintfcxx . . $ snprintf(ea502d73e74c754c).(dp.d_namecxx . . $ dirent#d_name., sizeof(dp.d_namecxx . . $ dirent#d_name.), "%s",
932 basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(argv[0]));
933 cli_build_assetcxx . . $ cli_build_asset(9f788ba9b5df10c4).(argv[0], &dp);
934 } else {
935 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s is not a directory or regular file", argv[0]);
936 }
937
938 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "\n#endif\n");
939 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(s_fdcxx . . $ s_fd.);
940 }
941
942 static void
943 cli_genasset_helpcxx . . $ cli_genasset_help(49f6e7a06ebc5aa8).(void)
944 {
945 printfcxx . . $ printf(581fddd72a8db8fc).("Usage: kodev genasset [source]\n");
946 printfcxx . . $ printf(581fddd72a8db8fc).("Synopsis:\n");
947 printfcxx . . $ printf(581fddd72a8db8fc).(" Generates asset file(s) to be used for compilation.\n");
948 printfcxx . . $ printf(581fddd72a8db8fc).(" The source can be a single file or directory.\n");
949 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
950 printfcxx . . $ printf(581fddd72a8db8fc).("This command honors the KODEV_OUTPUT environment variable.\n");
951 printfcxx . . $ printf(581fddd72a8db8fc).("This command honors the KORE_OBJDIR environment variable.\n");
952
953 exitcxx . . $ exit(3ca292c338df9bb3).(1);
954 }
955
956 #if !defined(KODEV_MINIMAL)
957 static void
958 file_create_python_srccxx . . $ file_create_python_src(49f6e7a06ebc5aa8).(void)
959 {
960 char *name;
961
962 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&name, "%s/__init__.py", applcxx . . $ appl.);
963 cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).(name, python_init_datacxx . . $ python_init_data., strlencxx . . $ strlen(751346f8406fd082).(python_init_datacxx . . $ python_init_data.));
964 freecxx . . $ free(5d22bdacc48458e8).(name);
965
966 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&name, "%s/app.py", applcxx . . $ appl.);
967 cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).(name, python_app_datacxx . . $ python_app_data., strlencxx . . $ strlen(751346f8406fd082).(python_app_datacxx . . $ python_app_data.));
968 freecxx . . $ free(5d22bdacc48458e8).(name);
969 }
970
971 static void
972 file_create_srccxx . . $ file_create_src(49f6e7a06ebc5aa8).(void)
973 {
974 char *name;
975
976 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&name, "%s/src/%s.c", applcxx . . $ appl., applcxx . . $ appl.);
977 cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).(name, src_datacxx . . $ src_data., strlencxx . . $ strlen(751346f8406fd082).(src_datacxx . . $ src_data.));
978 freecxx . . $ free(5d22bdacc48458e8).(name);
979 }
980
981 static void
982 file_create_configcxx . . $ file_create_config(49f6e7a06ebc5aa8).(void)
983 {
984 int l;
985 char *name, *data;
986
987 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&name, "%s/conf/%s.conf", applcxx . . $ appl., applcxx . . $ appl.);
988 l = cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&data, config_datacxx . . $ config_data., applcxx . . $ appl., applcxx . . $ appl.);
989 cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).(name, data, l);
990 freecxx . . $ free(5d22bdacc48458e8).(name);
991 freecxx . . $ free(5d22bdacc48458e8).(data);
992
993 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&name, "%s/conf/build.conf", applcxx . . $ appl.);
994 l = cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&data, build_datacxx . . $ build_data., applcxx . . $ appl.);
995 cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).(name, data, l);
996 freecxx . . $ free(5d22bdacc48458e8).(name);
997 freecxx . . $ free(5d22bdacc48458e8).(data);
998 }
999
1000 static void
1001 file_create_gitignorecxx . . $ file_create_gitignore(49f6e7a06ebc5aa8).(void)
1002 {
1003 int l;
1004 char *name, *data;
1005
1006 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&name, "%s/.gitignore", applcxx . . $ appl.);
1007 l = cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&data, gitignorecxx . . $ gitignore., applcxx . . $ appl.);
1008 cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).(name, data, l);
1009 freecxx . . $ free(5d22bdacc48458e8).(name);
1010 freecxx . . $ free(5d22bdacc48458e8).(data);
1011 }
1012 #endif
1013
1014 static void
1015 cli_mkdircxx . . $ cli_mkdir(34d26762b42c433a).(const char *fpath, int mode)
1016 {
1017 if (mkdircxx . . $ mkdir(1df18506ef0a631b).(fpath, mode) == -1)
1018 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_mkdir(%s): %s", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1019 }
1020
1021 static int
1022 cli_file_existscxx . . $ cli_file_exists(5c4306d8553b3696).(const char *fpath)
1023 {
1024 struct statcxx . . $ stat# st;
1025
1026 if (statcxx . . $ stat(a9cd1e23e96f423c).(fpath, &st) == -1)
1027 return (0);
1028
1029 if (!S_ISREGcxx . . $ `<external>/531885356569766532/stat.h:128:9`!(st.st_mode))
1030 return (0);
1031
1032 return (1);
1033 }
1034
1035 static int
1036 cli_file_requires_buildcxx . . $ cli_file_requires_build(7a8b711032b90e60).(struct statcxx . . $ stat# *fst, const char *opath)
1037 {
1038 struct statcxx . . $ stat# ost;
1039
1040 if (statcxx . . $ stat(a9cd1e23e96f423c).(opath, &ost) == -1) {
1041 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!)
1042 return (1);
1043 fatalcxx . . $ fatal(f6bc48f0426f26ee).("stat(%s): %s", opath, errno_scxx . . $ `src/cli.c:64:9`!);
1044 }
1045
1046 return (fst->st_mtimecxx . . $ `<external>/16045971866008360577/struct_stat.h:78:11`! != ost.st_mtimecxx . . $ `<external>/16045971866008360577/struct_stat.h:78:11`!);
1047 }
1048
1049 static int
1050 cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).(const char *fpath)
1051 {
1052 struct statcxx . . $ stat# st;
1053
1054 if (statcxx . . $ stat(a9cd1e23e96f423c).(fpath, &st) == -1)
1055 return (0);
1056
1057 if (!S_ISDIRcxx . . $ `<external>/531885356569766532/stat.h:125:9`!(st.st_mode))
1058 return (0);
1059
1060 return (1);
1061 }
1062
1063 static void
1064 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(const char *fpath, int flags, int *fd)
1065 {
1066 if ((*fd = opencxx . . $ open(ac5e327aedb29b06).(fpath, flags, 0644)) == -1)
1067 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_file_open(%s): %s", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1068 }
1069
1070 static void
1071 cli_file_readcxx . . $ cli_file_read(2a5d023f7acf84ed).(int fd, char **buf, size_t *len)
1072 {
1073 struct statcxx . . $ stat# st;
1074 char *p;
1075 ssize_tcxx . . $ ssize_t# ret;
1076 size_t offset, bytes;
1077
1078 if (fstatcxx . . $ fstat(a43660ce2f600cb5).(fd, &st) == -1)
1079 fatalcxx . . $ fatal(f6bc48f0426f26ee).("fstat(): %s", errno_scxx . . $ `src/cli.c:64:9`!);
1080
1081 if (st.st_sizecxx . . $ stat#st_size. > USHRT_MAXcxx . . $ `<external>/67164224788392828/limits.h:113:10`!)
1082 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_file_read: way too big");
1083
1084 offset = 0;
1085 bytes = st.st_sizecxx . . $ stat#st_size.;
1086 p = cli_malloccxx . . $ cli_malloc(bfcfa4d6b7f7ef64).(bytes);
1087
1088 while (offset != bytes) {
1089 ret = readcxx . . $ read(7e34d0a36f355389).(fd, p + offset, bytes - offset);
1090 if (ret == -1) {
1091 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!)
1092 continue;
1093 fatalcxx . . $ fatal(f6bc48f0426f26ee).("read(): %s", errno_scxx . . $ `src/cli.c:64:9`!);
1094 }
1095
1096 if (ret == 0)
1097 fatalcxx . . $ fatal(f6bc48f0426f26ee).("unexpected EOF");
1098
1099 offset += (size_t)ret;
1100 }
1101
1102 *buf = p;
1103 *len = bytes;
1104 }
1105
1106 static void
1107 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(int fd)
1108 {
1109 if (closecxx . . $ close(7864480464b09eea).(fd) == -1)
1110 printfcxx . . $ printf(581fddd72a8db8fc).("warning: close() %s\n", errno_scxx . . $ `src/cli.c:64:9`!);
1111 }
1112
1113 static void
1114 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(int fd, const char *fmt, ...)
1115 {
1116 int l;
1117 char *buf;
1118 va_listcxx . . $ va_list# args;
1119
1120 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, fmt);
1121 l = vasprintfcxx . . $ vasprintf(592150f15fbaad71).(&buf, fmt, args);
1122 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args);
1123
1124 if (l == -1)
1125 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_file_writef");
1126
1127 cli_file_writecxx . . $ cli_file_write(b0323033f2ee8f70).(fd, buf, l);
1128 freecxx . . $ free(5d22bdacc48458e8).(buf);
1129 }
1130
1131 static void
1132 cli_file_writecxx . . $ cli_file_write(b0323033f2ee8f70).(int fd, const void *buf, size_t len)
1133 {
1134 ssize_tcxx . . $ ssize_t# r;
1135 const u_int8_tcxx . . $ u_int8_t# *d;
1136 size_t written;
1137
1138 d = buf;
1139 written = 0;
1140 while (written != len) {
1141 r = writecxx . . $ write(41184a59d38b4f65).(fd, d + written, len - written);
1142 if (r == -1) {
1143 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!)
1144 continue;
1145 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_file_write: %s", errno_scxx . . $ `src/cli.c:64:9`!);
1146 }
1147
1148 written += r;
1149 }
1150 }
1151
1152 #if !defined(KODEV_MINIMAL)
1153 static void
1154 cli_file_createcxx . . $ cli_file_create(2ed9965f6227ab92).(const char *name, const char *data, size_t len)
1155 {
1156 int fd;
1157
1158 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(name, O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! | O_TRUNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:56:10`! | O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!, &fd);
1159 cli_file_writecxx . . $ cli_file_write(b0323033f2ee8f70).(fd, data, len);
1160 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(fd);
1161
1162 printfcxx . . $ printf(581fddd72a8db8fc).("created %s\n", name);
1163 }
1164 #endif
1165
1166 static void
1167 cli_write_assetcxx . . $ cli_write_asset(26204e3dd21c9412).(const char *n, const char *e, struct buildoptcxx . . $ buildopt# *bopt)
1168 {
1169 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "extern const u_int8_t asset_%s_%s[];\n", n, e);
1170 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "extern const u_int32_t asset_len_%s_%s;\n", n, e);
1171 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "extern const time_t asset_mtime_%s_%s;\n", n, e);
1172
1173 #if !defined(KODEV_MINIMAL)
1174 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd., "extern const char *asset_sha256_%s_%s;\n", n, e);
1175 #endif
1176
1177 if (bopt->flavor_nohttpcxx . . $ buildopt#flavor_nohttp. == 0) {
1178 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(s_fdcxx . . $ s_fd.,
1179 "int asset_serve_%s_%s(struct http_request *);\n", n, e);
1180 }
1181 }
1182
1183 static void
1184 cli_build_assetcxx . . $ cli_build_asset(9f788ba9b5df10c4).(char *fpath, struct direntcxx . . $ dirent# *dp)
1185 {
1186 u_int8_tcxx . . $ u_int8_t# *d;
1187 struct statcxx . . $ stat# st;
1188 #if !defined(KODEV_MINIMAL)
1189 SHA256_CTXcxx . . $ SHA256_CTX# sctx;
1190 int i, len;
1191 struct mime_typecxx . . $ mime_type# *mime;
1192 const char *mime_type;
1193 u_int8_tcxx . . $ u_int8_t# digest[SHA256_DIGEST_LENGTHcxx . . $ `<external>/1304733114006737056/sha.h:86:9`!];
1194 char hash[(SHA256_DIGEST_LENGTHcxx . . $ `<external>/1304733114006737056/sha.h:86:9`! * 2) + 1];
1195 #endif
1196 off_tcxx . . $ off_t# off;
1197 void *base;
1198 struct buildoptcxx . . $ buildopt# *bopt;
1199 int in, out;
1200 char *cpath, *ext, *opath, *p, *name;
1201
1202 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1203
1204 /* Ignore hidden files and some editor files */
1205 if (dp->d_namecxx . . $ dirent#d_name.[0] == '.' ||
1206 strrchrcxx . . $ strrchr(2050848944e00d54).(dp->d_namecxx . . $ dirent#d_name., '~') || strrchrcxx . . $ strrchr(2050848944e00d54).(dp->d_namecxx . . $ dirent#d_name., '#')) {
1207 return;
1208 }
1209
1210 name = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(dp->d_namecxx . . $ dirent#d_name.);
1211
1212 /* Grab the extension as we're using it in the symbol name. */
1213 if ((ext = strrchrcxx . . $ strrchr(2050848944e00d54).(name, '.')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1214 fatalcxx . . $ fatal(f6bc48f0426f26ee).("couldn't find ext in %s", name);
1215
1216 /* Replace dots, spaces, etc etc with underscores. */
1217 for (p = name; *p != '\0'; p++) {
1218 if (*p == '.' || isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!((unsigned char)*p) || *p == '-')
1219 *p = '_';
1220 }
1221
1222 /* Grab inode information. */
1223 if (statcxx . . $ stat(a9cd1e23e96f423c).(fpath, &st) == -1)
1224 fatalcxx . . $ fatal(f6bc48f0426f26ee).("stat: %s %s", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1225
1226 /* If this file was empty, skip it. */
1227 if (st.st_sizecxx . . $ stat#st_size. == 0) {
1228 printfcxx . . $ printf(581fddd72a8db8fc).("skipping empty asset %s\n", name);
1229 freecxx . . $ free(5d22bdacc48458e8).(name);
1230 return;
1231 }
1232
1233 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&opath, "%s/%s.o", object_dircxx . . $ object_dir., name);
1234 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&cpath, "%s/%s.c", object_dircxx . . $ object_dir., name);
1235
1236 /* Check if the file needs to be built. */
1237 if (!cli_file_requires_buildcxx . . $ cli_file_requires_build(7a8b711032b90e60).(&st, opath)) {
1238 *(ext)++ = '\0';
1239 cli_write_assetcxx . . $ cli_write_asset(26204e3dd21c9412).(name, ext, bopt);
1240 *ext = '_';
1241
1242 cli_add_source_filecxx . . $ cli_add_source_file(559b971b9c7206c1).(name, cpath, opath, &st, BUILD_NOBUILDcxx . . $ `src/cli.c:71:9`!);
1243 freecxx . . $ free(5d22bdacc48458e8).(name);
1244 return;
1245 }
1246
1247 /* Open the file we're converting. */
1248 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(fpath, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!, &in);
1249
1250 /* mmap our in file. */
1251 if ((base = mmapcxx . . $ mmap(ff06c1c904cdf0e2).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, st.st_sizecxx . . $ stat#st_size.,
1252 PROT_READcxx . . $ `<external>/17226767460805440860/mman-linux.h:32:9`!, MAP_PRIVATEcxx . . $ `<external>/17226767460805440860/mman-linux.h:43:9`!, in, 0)) == MAP_FAILEDcxx . . $ `<external>/6724834311684550606/mman.h:44:9`!)
1253 fatalcxx . . $ fatal(f6bc48f0426f26ee).("mmap: %s %s", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1254
1255 /* Create the c file where we will write too. */
1256 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(cpath, O_CREATcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:47:10`! | O_TRUNCcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:56:10`! | O_WRONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:44:9`!, &out);
1257
1258 /* No longer need name so cut off the extension. */
1259 printfcxx . . $ printf(581fddd72a8db8fc).("building asset %s\n", dp->d_namecxx . . $ dirent#d_name.);
1260 *(ext)++ = '\0';
1261
1262 /* Start generating the file. */
1263 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "/* Auto generated */\n");
1264 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "#include <sys/types.h>\n\n");
1265 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "#include <kore/kore.h>\n");
1266 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "#include <kore/http.h>\n\n");
1267 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "#include \"assets.h\"\n\n");
1268
1269 /* Write the file data as a byte array. */
1270 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "const u_int8_t asset_%s_%s[] = {\n", name, ext);
1271 d = base;
1272 for (off = 0; off < st.st_sizecxx . . $ stat#st_size.; off++)
1273 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "0x%02x,", *d++);
1274
1275 /*
1276 * Always NUL-terminate the asset, even if this NUL is not included in
1277 * the actual length. This way assets can be cast to char * without
1278 * any additional thinking for the developer.
1279 */
1280 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "0x00");
1281
1282 #if !defined(KODEV_MINIMAL)
1283 /* Calculate the SHA256 digest of the contents. */
1284 (void)SHA256_Initcxx . . $ SHA256_Init(99e938220a9e7d0d).(&sctx);
1285 (void)SHA256_Updatecxx . . $ SHA256_Update(977605c910b800f3).(&sctx, base, st.st_sizecxx . . $ stat#st_size.);
1286 (void)SHA256_Finalcxx . . $ SHA256_Final(6f3c5c6c51248622).(digest, &sctx);
1287
1288 for (i = 0; i < (int)sizeof(digest); i++) {
1289 len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(hash + (i * 2), sizeof(hash) - (i * 2),
1290 "%02x", digest[i]);
1291 if (len == -1 || (size_t)len >= sizeof(hash))
1292 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to convert SHA256 digest to hex");
1293 }
1294
1295 mime = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1296 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(mime, &mime_types, list) {
1297 if (!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(mime->extcxx . . $ mime_type#ext., ext))
1298 break;
1299 }
1300
1301 if (mime != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1302 mime_type = mime->typecxx . . $ mime_type#type.;
1303 else
1304 mime_type = "text/plain";
1305 #endif
1306
1307 /* Add the meta data. */
1308 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "};\n\n");
1309 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, "const u_int32_t asset_len_%s_%s = %" PRIu32cxx . . $ `<external>/15933738808807975373/inttypes.h:104:10`! ";\n",
1310 name, ext, (u_int32_tcxx . . $ u_int32_t#)st.st_sizecxx . . $ stat#st_size.);
1311 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out,
1312 "const time_t asset_mtime_%s_%s = %" PRId64cxx . . $ `<external>/15933738808807975373/inttypes.h:57:10`! ";\n",
1313 name, ext, (int64_tcxx . . $ int64_t#)st.st_mtimecxx . . $ `<external>/16045971866008360577/struct_stat.h:78:11`!);
1314
1315 #if !defined(KODEV_MINIMAL)
1316 if (bopt->flavor_nohttpcxx . . $ buildopt#flavor_nohttp. == 0) {
1317 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out,
1318 "const char *asset_sha256_%s_%s = \"\\\"%s\\\"\";\n",
1319 name, ext, hash);
1320 cli_file_writefcxx . . $ cli_file_writef(afcfcee7634adf7d).(out, http_serveable_functioncxx . . $ http_serveable_function.,
1321 name, ext, name, ext, name, ext, name, ext, mime_type);
1322 }
1323 #endif
1324
1325 /* Write the file symbols into assets.h so they can be used. */
1326 cli_write_assetcxx . . $ cli_write_asset(26204e3dd21c9412).(name, ext, bopt);
1327
1328 /* Cleanup static file source. */
1329 if (munmapcxx . . $ munmap(c0a5f96701d3f89).(base, st.st_sizecxx . . $ stat#st_size.) == -1)
1330 fatalcxx . . $ fatal(f6bc48f0426f26ee).("munmap: %s %s", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1331
1332 /* Cleanup fds */
1333 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(in);
1334 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(out);
1335
1336 /* Restore the original name */
1337 *--ext = '.';
1338
1339 /* Register the .c file now (cpath is free'd later). */
1340 if (genasset_cmdcxx . . $ genasset_cmd. == 0)
1341 cli_add_source_filecxx . . $ cli_add_source_file(559b971b9c7206c1).(name, cpath, opath, &st, BUILD_Ccxx . . $ `src/cli.c:72:9`!);
1342
1343 freecxx . . $ free(5d22bdacc48458e8).(name);
1344 }
1345
1346 static void
1347 cli_add_source_filecxx . . $ cli_add_source_file(559b971b9c7206c1).(char *name, char *fpath, char *opath, struct statcxx . . $ stat# *st,
1348 int build)
1349 {
1350 struct cfilecxx . . $ cfile# *cf;
1351
1352 source_files_countcxx . . $ source_files_count.++;
1353 cf = cli_malloccxx . . $ cli_malloc(bfcfa4d6b7f7ef64).(sizeof(*cf));
1354
1355 if (st != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1356 cf->stcxx . . $ cfile#st. = *st;
1357 else
1358 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&cf->stcxx . . $ cfile#st., 0, sizeof(cf->stcxx . . $ cfile#st.));
1359
1360 cf->buildcxx . . $ cfile#build. = build;
1361 cf->fpathcxx . . $ cfile#fpath. = fpath;
1362 cf->opathcxx . . $ cfile#opath. = opath;
1363 cf->namecxx . . $ cfile#name. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(name);
1364
1365 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&source_files, cf, list);
1366 }
1367
1368 static void
1369 cli_register_source_filecxx . . $ cli_register_source_file(9f788ba9b5df10c4).(char *fpath, struct direntcxx . . $ dirent# *dp)
1370 {
1371 struct statcxx . . $ stat# st;
1372 char *ext, *opath;
1373 int build;
1374
1375 if ((ext = strrchrcxx . . $ strrchr(2050848944e00d54).(fpath, '.')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ||
1376 (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(ext, ".c") && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(ext, ".cpp")))
1377 return;
1378
1379 if (statcxx . . $ stat(a9cd1e23e96f423c).(fpath, &st) == -1)
1380 fatalcxx . . $ fatal(f6bc48f0426f26ee).("stat(%s): %s", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1381
1382 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(ext, ".cpp"))
1383 cxx_files_countcxx . . $ cxx_files_count.++;
1384
1385 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&opath, "%s/%s.o", object_dircxx . . $ object_dir., dp->d_namecxx . . $ dirent#d_name.);
1386 if (!cli_file_requires_buildcxx . . $ cli_file_requires_build(7a8b711032b90e60).(&st, opath)) {
1387 build = BUILD_NOBUILDcxx . . $ `src/cli.c:71:9`!;
1388 } else if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(ext, ".cpp")) {
1389 build = BUILD_CXXcxx . . $ `src/cli.c:73:9`!;
1390 } else {
1391 build = BUILD_Ccxx . . $ `src/cli.c:72:9`!;
1392 }
1393
1394 cli_add_source_filecxx . . $ cli_add_source_file(559b971b9c7206c1).(dp->d_namecxx . . $ dirent#d_name., fpath, opath, &st, build);
1395 }
1396
1397 static void
1398 cli_register_kore_filecxx . . $ cli_register_kore_file(9f788ba9b5df10c4).(char *fpath, struct direntcxx . . $ dirent# *dp)
1399 {
1400 struct statcxx . . $ stat# st, ost;
1401 char *opath, *ext, *fname;
1402
1403 if ((ext = strrchrcxx . . $ strrchr(2050848944e00d54).(fpath, '.')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || strcmpcxx . . $ strcmp(5ae29d726ae57f88).(ext, ".c"))
1404 return;
1405
1406 if (statcxx . . $ stat(a9cd1e23e96f423c).(fpath, &st) == -1)
1407 fatalcxx . . $ fatal(f6bc48f0426f26ee).("stat(%s): %s", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1408
1409 *ext = '\0';
1410 if ((fname = basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(fpath)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1411 fatalcxx . . $ fatal(f6bc48f0426f26ee).("basename failed");
1412
1413 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&opath, "%s/%s.o", object_dircxx . . $ object_dir., fname);
1414
1415 /* Silently ignore non existing object files for kore source files. */
1416 if (statcxx . . $ stat(a9cd1e23e96f423c).(opath, &ost) == -1) {
1417 freecxx . . $ free(5d22bdacc48458e8).(opath);
1418 return;
1419 }
1420
1421 cli_add_source_filecxx . . $ cli_add_source_file(559b971b9c7206c1).(dp->d_namecxx . . $ dirent#d_name., fpath, opath, &st, BUILD_NOBUILDcxx . . $ `src/cli.c:71:9`!);
1422 }
1423
1424 static void
1425 cli_file_removecxx . . $ cli_file_remove(9f788ba9b5df10c4).(char *fpath, struct direntcxx . . $ dirent# *dp)
1426 {
1427 if (unlinkcxx . . $ unlink(5c4306d8553b3696).(fpath) == -1)
1428 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "couldn't unlink %s: %s", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1429 }
1430
1431 static void
1432 cli_find_filescxx . . $ cli_find_files(b304834a9fe4a1c9).(const char *path, void (*cb)(char *, struct direntcxx . . $ dirent# *))
1433 {
1434 DIRcxx . . $ DIR# *d;
1435 struct statcxx . . $ stat# st;
1436 struct direntcxx . . $ dirent# *dp;
1437 char *fpath;
1438
1439 if ((d = opendircxx . . $ opendir(f465d4b65cec8dd2).(path)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1440 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_find_files: opendir(%s): %s", path, errno_scxx . . $ `src/cli.c:64:9`!);
1441
1442 while ((dp = readdircxx . . $ readdir(ffbaae344e1a615a).(d)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
1443 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(dp->d_namecxx . . $ dirent#d_name., ".") ||
1444 !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(dp->d_namecxx . . $ dirent#d_name., ".."))
1445 continue;
1446
1447 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&fpath, "%s/%s", path, dp->d_namecxx . . $ dirent#d_name.);
1448 if (statcxx . . $ stat(a9cd1e23e96f423c).(fpath, &st) == -1) {
1449 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "stat(%s): %s\n", fpath, errno_scxx . . $ `src/cli.c:64:9`!);
1450 freecxx . . $ free(5d22bdacc48458e8).(fpath);
1451 continue;
1452 }
1453
1454 if (S_ISDIRcxx . . $ `<external>/531885356569766532/stat.h:125:9`!(st.st_mode)) {
1455 cli_find_filescxx . . $ cli_find_files(b304834a9fe4a1c9).(fpath, cb);
1456 freecxx . . $ free(5d22bdacc48458e8).(fpath);
1457 } else if (S_ISREGcxx . . $ `<external>/531885356569766532/stat.h:128:9`!(st.st_mode)) {
1458 cb(fpath, dp);
1459 } else {
1460 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "ignoring %s\n", fpath);
1461 freecxx . . $ free(5d22bdacc48458e8).(fpath);
1462 }
1463 }
1464
1465 closedircxx . . $ closedir(ac30a447bc7c2f80).(d);
1466 }
1467
1468 #if !defined(KODEV_MINIMAL)
1469 static void
1470 cli_generate_certscxx . . $ cli_generate_certs(49f6e7a06ebc5aa8).(void)
1471 {
1472 BIGNUMcxx . . $ BIGNUM# *e;
1473 FILEcxx . . $ FILE# *fp;
1474 time_tcxx . . $ time_t# now;
1475 X509_NAMEcxx . . $ X509_NAME# *name;
1476 EVP_PKEYcxx . . $ EVP_PKEY# *pkey;
1477 X509cxx . . $ X509# *x509;
1478 RSAcxx . . $ RSA# *kpair;
1479 char issuer[64];
1480
1481 /* Create new certificate. */
1482 if ((x509 = X509_newcxx . . $ X509_new(93b0c55b64f6b06f).()) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1483 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_new(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1484
1485 /* Generate version 3. */
1486 if (!X509_set_versioncxx . . $ X509_set_version(c03664caa7dfac34).(x509, 2))
1487 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_set_version(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1488
1489 /* Generate RSA keys. */
1490 if ((pkey = EVP_PKEY_newcxx . . $ EVP_PKEY_new(329d513567cbda88).()) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1491 fatalcxx . . $ fatal(f6bc48f0426f26ee).("EVP_PKEY_new(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1492 if ((kpair = RSA_newcxx . . $ RSA_new(88f934d4dfdd44e4).()) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1493 fatalcxx . . $ fatal(f6bc48f0426f26ee).("RSA_new(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1494 if ((e = BN_newcxx . . $ BN_new(553d6a0a639cd466).()) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1495 fatalcxx . . $ fatal(f6bc48f0426f26ee).("BN_new(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1496
1497 if (!BN_set_wordcxx . . $ BN_set_word(ab807cbb0a418199).(e, 65537))
1498 fatalcxx . . $ fatal(f6bc48f0426f26ee).("BN_set_word(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1499 if (!RSA_generate_key_excxx . . $ RSA_generate_key_ex(4d3494de2fafc009).(kpair, 2048, e, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!))
1500 fatalcxx . . $ fatal(f6bc48f0426f26ee).("RSA_generate_key_ex(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1501
1502 BN_freecxx . . $ BN_free(e4941127fbd70553).(e);
1503
1504 if (!EVP_PKEY_assign_RSAcxx . . $ `<external>/2497497914425334111/evp.h:510:9`!(pkey, kpair))
1505 fatalcxx . . $ fatal(f6bc48f0426f26ee).("EVP_PKEY_assign_RSA(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1506
1507 /* Set serial number to current timestamp. */
1508 timecxx . . $ time(7f38134db6521d23).(&now);
1509 if (!ASN1_INTEGER_setcxx . . $ ASN1_INTEGER_set(6d26c6b3ba04ccd7).(X509_get_serialNumbercxx . . $ X509_get_serialNumber(65bcaea288a5f2b3).(x509), now))
1510 fatalcxx . . $ fatal(f6bc48f0426f26ee).("ASN1_INTEGER_set(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1511
1512 /* Not before and not after dates. */
1513 if (!X509_gmtime_adjcxx . . $ X509_gmtime_adj(4f5a46244876ddae).(X509_get_notBeforecxx . . $ `<external>/1406364094028619707/x509.h:869:9`!(x509), 0))
1514 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_gmtime_adj(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1515 if (!X509_gmtime_adjcxx . . $ X509_gmtime_adj(4f5a46244876ddae).(X509_get_notAftercxx . . $ `<external>/1406364094028619707/x509.h:870:9`!(x509),
1516 (long)60 * 60 * 24 * 3000))
1517 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_gmtime_adj(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1518
1519 /* Attach the pkey to the certificate. */
1520 if (!X509_set_pubkeycxx . . $ X509_set_pubkey(e708c4e1951afc21).(x509, pkey))
1521 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_set_pubkey(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1522
1523 /* Set certificate information. */
1524 if ((name = X509_get_subject_namecxx . . $ X509_get_subject_name(38fd56961e51b042).(x509)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1525 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_get_subject_name(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1526
1527 (void)snprintfcxx . . $ snprintf(ea502d73e74c754c).(issuer, sizeof(issuer), "kore autogen: %s", applcxx . . $ appl.);
1528 if (!X509_NAME_add_entry_by_txtcxx . . $ X509_NAME_add_entry_by_txt(54f89878f7bb06f7).(name, "C",
1529 MBSTRING_ASCcxx . . $ `<external>/12324823171055860766/asn1.h:126:9`!, (const unsigned char *)"SE", -1, -1, 0))
1530 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_NAME_add_entry_by_txt(): C %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1531 if (!X509_NAME_add_entry_by_txtcxx . . $ X509_NAME_add_entry_by_txt(54f89878f7bb06f7).(name, "O",
1532 MBSTRING_ASCcxx . . $ `<external>/12324823171055860766/asn1.h:126:9`!, (const unsigned char *)issuer, -1, -1, 0))
1533 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_NAME_add_entry_by_txt(): O %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1534 if (!X509_NAME_add_entry_by_txtcxx . . $ X509_NAME_add_entry_by_txt(54f89878f7bb06f7).(name, "CN",
1535 MBSTRING_ASCcxx . . $ `<external>/12324823171055860766/asn1.h:126:9`!, (const unsigned char *)"localhost", -1, -1, 0))
1536 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_NAME_add_entry_by_txt(): CN %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1537
1538 if (!X509_set_issuer_namecxx . . $ X509_set_issuer_name(ba4f33e2870cdb31).(x509, name))
1539 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_set_issuer_name(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1540
1541 if (!X509_signcxx . . $ X509_sign(417197ead1ef8602).(x509, pkey, EVP_sha256cxx . . $ EVP_sha256(5215674ec9154785).()))
1542 fatalcxx . . $ fatal(f6bc48f0426f26ee).("X509_sign(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1543
1544 if ((fp = fopencxx . . $ fopen(82ec0787cd37e0a3).("cert/key.pem", "w")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1545 fatalcxx . . $ fatal(f6bc48f0426f26ee).("fopen(cert/key.pem): %s", errno_scxx . . $ `src/cli.c:64:9`!);
1546 if (!PEM_write_PrivateKeycxx . . $ PEM_write_PrivateKey(2bcb0dc1c6398047).(fp, pkey, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!))
1547 fatalcxx . . $ fatal(f6bc48f0426f26ee).("PEM_write_PrivateKey(): %s", ssl_errno_scxx . . $ `src/cli.c:65:9`!);
1548 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
1549
1550 if ((fp = fopencxx . . $ fopen(82ec0787cd37e0a3).("cert/server.pem", "w")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1551 fatalcxx . . $ fatal(f6bc48f0426f26ee).("fopen(cert/server.pem): %s", errno_scxx . . $ `src/cli.c:64:9`!);
1552 if (!PEM_write_X509cxx . . $ PEM_write_X509(4c747a09317497ae).(fp, x509))
1553 fatalcxx . . $ fatal(f6bc48f0426f26ee).("PEM_write_X509(%s)", errno_scxx . . $ `src/cli.c:64:9`!);
1554 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
1555
1556 EVP_PKEY_freecxx . . $ EVP_PKEY_free(a36cc1e96a19ea9b).(pkey);
1557 X509_freecxx . . $ X509_free(6d28345afe631eba).(x509);
1558 }
1559 #endif
1560
1561 static void
1562 cli_compile_source_filecxx . . $ cli_compile_source_file(5d22bdacc48458e8).(void *arg)
1563 {
1564 struct cfilecxx . . $ cfile# *cf;
1565 int idx, i;
1566 char **flags;
1567 char *compiler;
1568 int flags_count;
1569 char *args[34 + CFLAGS_MAXcxx . . $ `src/cli.c:68:9`!];
1570
1571 cf = arg;
1572
1573 switch (cf->buildcxx . . $ cfile#build.) {
1574 case BUILD_Ccxx . . $ `src/cli.c:72:9`!:
1575 compiler = compiler_ccxx . . $ compiler_c.;
1576 flags = cflagscxx . . $ cflags.;
1577 flags_count = cflags_countcxx . . $ cflags_count.;
1578 break;
1579 case BUILD_CXXcxx . . $ `src/cli.c:73:9`!:
1580 compiler = compiler_cppcxx . . $ compiler_cpp.;
1581 flags = cxxflagscxx . . $ cxxflags.;
1582 flags_count = cxxflags_countcxx . . $ cxxflags_count.;
1583 break;
1584 default:
1585 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_compile_file: unexpected file type: %d",
1586 cf->buildcxx . . $ cfile#build.);
1587 break;
1588 }
1589
1590 idx = 0;
1591 args[idx++] = compiler;
1592
1593 for (i = 0; i < flags_count; i++)
1594 args[idx++] = flags[i];
1595
1596 args[idx++] = "-I";
1597 args[idx++] = object_dircxx . . $ object_dir.;
1598 args[idx++] = "-c";
1599 args[idx++] = cf->fpathcxx . . $ cfile#fpath.;
1600 args[idx++] = "-o";
1601 args[idx++] = cf->opathcxx . . $ cfile#opath.;
1602 args[idx] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1603
1604 execvpcxx . . $ execvp(8a4102a9cf05ffcd).(compiler, args);
1605 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to start '%s': %s", compiler, errno_scxx . . $ `src/cli.c:64:9`!);
1606 }
1607
1608 static void
1609 cli_link_applicationcxx . . $ cli_link_application(5d22bdacc48458e8).(void *arg)
1610 {
1611 struct cfilecxx . . $ cfile# *cf;
1612 struct buildoptcxx . . $ buildopt# *bopt;
1613 int idx, i;
1614 char *output;
1615 char *args[source_files_countcxx . . $ source_files_count. + 11 + LD_FLAGS_MAXcxx . . $ `src/cli.c:67:9`!];
1616
1617 bopt = arg;
1618
1619 if (bopt->single_binarycxx . . $ buildopt#single_binary.)
1620 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&output, "%s/%s", out_dircxx . . $ out_dir., applcxx . . $ appl.);
1621 else
1622 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&output, "%s/%s.so", out_dircxx . . $ out_dir., applcxx . . $ appl.);
1623
1624 idx = 0;
1625 args[idx++] = compiler_ldcxx . . $ compiler_ld.;
1626
1627 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(cf, &source_files, list)
1628 args[idx++] = cf->opathcxx . . $ cfile#opath.;
1629
1630 for (i = 0; i < ldflags_countcxx . . $ ldflags_count.; i++)
1631 args[idx++] = ldflagscxx . . $ ldflags.[i];
1632
1633 args[idx++] = "-o";
1634 args[idx++] = output;
1635 args[idx] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1636
1637 execvpcxx . . $ execvp(8a4102a9cf05ffcd).(compiler_ldcxx . . $ compiler_ld., args);
1638 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to start '%s': %s", compiler_ldcxx . . $ compiler_ld., errno_scxx . . $ `src/cli.c:64:9`!);
1639 }
1640
1641 static void
1642 cli_compile_korecxx . . $ cli_compile_kore(5d22bdacc48458e8).(void *arg)
1643 {
1644 struct buildoptcxx . . $ buildopt# *bopt = arg;
1645 int idx, i, fcnt;
1646 char pwd[MAXPATHLENcxx . . $ `<external>/1231830743887005719/param.h:48:10`!], *obj, *args[20], *flavors[7];
1647
1648 if (object_dircxx . . $ object_dir.[0] != '/') {
1649 if (getcwdcxx . . $ getcwd(dff97f9eb74e1544).(pwd, sizeof(pwd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1650 fatalcxx . . $ fatal(f6bc48f0426f26ee).("could not get cwd: %s", errno_scxx . . $ `src/cli.c:64:9`!);
1651 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&obj, "OBJDIR=%s/%s", pwd, object_dircxx . . $ object_dir.);
1652 } else {
1653 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&obj, "OBJDIR=%s", object_dircxx . . $ object_dir.);
1654 }
1655
1656 if (putenvcxx . . $ putenv(1ef8e6ec083aabb9).(obj) != 0)
1657 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cannot set OBJDIR for building kore");
1658
1659 fcnt = cli_split_stringcxx . . $ cli_split_string(87b756e43bd5489c).(bopt->kore_flavorcxx . . $ buildopt#kore_flavor., " ", flavors, 7);
1660
1661 #if defined(OpenBSD) || defined(__FreeBSD_version) || \
1662 defined(NetBSD) || defined(__DragonFly_version)
1663 args[0] = "gmake";
1664 #else
1665 args[0] = "make";
1666 #endif
1667
1668 args[1] = "-s";
1669 args[2] = "-C";
1670 args[3] = bopt->kore_sourcecxx . . $ buildopt#kore_source.;
1671 args[4] = "objects";
1672
1673 idx = 5;
1674 for (i = 0; i < fcnt; i++) {
1675 printfcxx . . $ printf(581fddd72a8db8fc).("using flavor %s\n", flavors[i]);
1676 args[idx++] = flavors[i];
1677 }
1678
1679 args[idx++] = "KORE_SINGLE_BINARY=1";
1680 args[idx] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1681
1682 execvpcxx . . $ execvp(8a4102a9cf05ffcd).(args[0], args);
1683 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to start '%s': %s", args[0], errno_scxx . . $ `src/cli.c:64:9`!);
1684 }
1685
1686 static void
1687 cli_run_kore_pythoncxx . . $ cli_run_kore_python(49f6e7a06ebc5aa8).(void)
1688 {
1689 char *args[5], *cmd;
1690 char pwd[MAXPATHLENcxx . . $ `<external>/1231830743887005719/param.h:48:10`!];
1691
1692 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&cmd, "%s/bin/kore", prefixcxx . . $ prefix.);
1693
1694 if (getcwdcxx . . $ getcwd(dff97f9eb74e1544).(pwd, sizeof(pwd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1695 fatalcxx . . $ fatal(f6bc48f0426f26ee).("could not get cwd: %s", errno_scxx . . $ `src/cli.c:64:9`!);
1696
1697 args[0] = cmd;
1698 args[1] = pwd;
1699 args[2] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1700
1701 execvpcxx . . $ execvp(8a4102a9cf05ffcd).(args[0], args);
1702 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to start '%s': %s", args[0], errno_scxx . . $ `src/cli.c:64:9`!);
1703
1704 }
1705
1706 static void
1707 cli_run_korecxx . . $ cli_run_kore(49f6e7a06ebc5aa8).(void)
1708 {
1709 struct buildoptcxx . . $ buildopt# *bopt;
1710 char *args[4], *cpath, *cmd, *flags;
1711
1712 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1713
1714 if (bopt->single_binarycxx . . $ buildopt#single_binary.) {
1715 cpath = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1716 flags = "-fnr";
1717 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&cmd, "./%s", applcxx . . $ appl.);
1718 } else {
1719 flags = "-fnrc";
1720 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&cmd, "%s/bin/kore", prefixcxx . . $ prefix.);
1721 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&cpath, "conf/%s.conf", applcxx . . $ appl.);
1722 }
1723
1724 args[0] = cmd;
1725 args[1] = flags;
1726
1727 if (cpath != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
1728 args[2] = cpath;
1729 args[3] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1730 } else {
1731 args[2] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1732 }
1733
1734 execvpcxx . . $ execvp(8a4102a9cf05ffcd).(args[0], args);
1735 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to start '%s': %s", args[0], errno_scxx . . $ `src/cli.c:64:9`!);
1736 }
1737
1738 static void
1739 cli_buildopt_parsecxx . . $ cli_buildopt_parse(85c52e162fed56f9).(const char *path)
1740 {
1741 FILEcxx . . $ FILE# *fp;
1742 const char *env;
1743 struct buildoptcxx . . $ buildopt# *bopt;
1744 char buf[BUFSIZcxx . . $ `<external>/232824719582829767/stdio.h:100:9`!], *p, *t;
1745
1746 if ((fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(path, "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1747 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_buildopt_parse: fopen(%s): %s", path, errno_scxx . . $ `src/cli.c:64:9`!);
1748
1749 bopt = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1750
1751 while ((p = cli_read_linecxx . . $ cli_read_line(8c0cb784ce79381a).(fp, buf, sizeof(buf))) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
1752 if (strlencxx . . $ strlen(751346f8406fd082).(p) == 0)
1753 continue;
1754
1755 if (bopt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && !strcmpcxx . . $ strcmp(5ae29d726ae57f88).(p, "}")) {
1756 bopt = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1757 continue;
1758 }
1759
1760 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
1761 if ((t = strchrcxx . . $ strchr(2050848944e00d54).(p, '=')) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1762 goto parse_option;
1763 if ((t = strchrcxx . . $ strchr(2050848944e00d54).(p, ' ')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1764 fatalcxx . . $ fatal(f6bc48f0426f26ee).("unexpected '%s'", p);
1765 *(t)++ = '\0';
1766 if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(t, "{"))
1767 fatalcxx . . $ fatal(f6bc48f0426f26ee).("expected '{', got '%s'", t);
1768 bopt = cli_buildopt_newcxx . . $ cli_buildopt_new(dd450b94293e0318).(p);
1769 continue;
1770 }
1771
1772 if ((t = strchrcxx . . $ strchr(2050848944e00d54).(p, '=')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
1773 printfcxx . . $ printf(581fddd72a8db8fc).("bad buildopt line: '%s'\n", p);
1774 continue;
1775 }
1776
1777 parse_option:
1778 *(t)++ = '\0';
1779
1780 p = cli_text_trimcxx . . $ cli_text_trim(dff97f9eb74e1544).(p, strlencxx . . $ strlen(751346f8406fd082).(p));
1781 t = cli_text_trimcxx . . $ cli_text_trim(dff97f9eb74e1544).(t, strlencxx . . $ strlen(751346f8406fd082).(t));
1782
1783 if (!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(p, "cflags")) {
1784 cli_buildopt_cflagscxx . . $ cli_buildopt_cflags(3ce0f79f9cc72e16).(bopt, t);
1785 } else if (!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(p, "cxxflags")) {
1786 cli_buildopt_cxxflagscxx . . $ cli_buildopt_cxxflags(3ce0f79f9cc72e16).(bopt, t);
1787 } else if (!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(p, "ldflags")) {
1788 cli_buildopt_ldflagscxx . . $ cli_buildopt_ldflags(3ce0f79f9cc72e16).(bopt, t);
1789 } else if (!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(p, "single_binary")) {
1790 cli_buildopt_single_binarycxx . . $ cli_buildopt_single_binary(3ce0f79f9cc72e16).(bopt, t);
1791 } else if (!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(p, "kore_source")) {
1792 cli_buildopt_kore_sourcecxx . . $ cli_buildopt_kore_source(3ce0f79f9cc72e16).(bopt, t);
1793 } else if (!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(p, "kore_flavor")) {
1794 cli_buildopt_kore_flavorcxx . . $ cli_buildopt_kore_flavor(3ce0f79f9cc72e16).(bopt, t);
1795 } else if (!strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(p, "mime_add")) {
1796 cli_buildopt_mimecxx . . $ cli_buildopt_mime(3ce0f79f9cc72e16).(bopt, t);
1797 } else {
1798 printfcxx . . $ printf(581fddd72a8db8fc).("ignoring unknown option '%s'\n", p);
1799 }
1800 }
1801
1802 fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
1803
1804 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("KORE_SOURCE")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1805 cli_buildopt_kore_sourcecxx . . $ cli_buildopt_kore_source(3ce0f79f9cc72e16).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, env);
1806
1807 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("KORE_FLAVOR")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1808 cli_buildopt_kore_flavorcxx . . $ cli_buildopt_kore_flavor(3ce0f79f9cc72e16).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, env);
1809 }
1810
1811 static struct buildoptcxx . . $ buildopt# *
1812 cli_buildopt_newcxx . . $ cli_buildopt_new(dd450b94293e0318).(const char *name)
1813 {
1814 struct buildoptcxx . . $ buildopt# *bopt;
1815
1816 bopt = cli_malloccxx . . $ cli_malloc(bfcfa4d6b7f7ef64).(sizeof(*bopt));
1817 bopt->cflagscxx . . $ buildopt#cflags. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1818 bopt->cxxflagscxx . . $ buildopt#cxxflags. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1819 bopt->ldflagscxx . . $ buildopt#ldflags. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1820 bopt->flavor_nohttpcxx . . $ buildopt#flavor_nohttp. = 0;
1821 bopt->single_binarycxx . . $ buildopt#single_binary. = 0;
1822 bopt->kore_flavorcxx . . $ buildopt#kore_flavor. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
1823 bopt->namecxx . . $ buildopt#name. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(name);
1824
1825 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&bopt->kore_sourcecxx . . $ buildopt#kore_source., "%s/share/kore/", prefixcxx . . $ prefix.);
1826
1827 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&build_options, bopt, list);
1828 return (bopt);
1829 }
1830
1831 static struct buildoptcxx . . $ buildopt# *
1832 cli_buildopt_findcxx . . $ cli_buildopt_find(dd450b94293e0318).(const char *name)
1833 {
1834 struct buildoptcxx . . $ buildopt# *bopt;
1835
1836 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(bopt, &build_options, list) {
1837 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(bopt->namecxx . . $ buildopt#name., name))
1838 return (bopt);
1839 }
1840
1841 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
1842 }
1843
1844 static struct buildoptcxx . . $ buildopt# *
1845 cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).(void)
1846 {
1847 struct buildoptcxx . . $ buildopt# *bopt;
1848
1849 if ((bopt = cli_buildopt_findcxx . . $ cli_buildopt_find(dd450b94293e0318).("_default")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1850 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no _default buildopt options");
1851
1852 return (bopt);
1853 }
1854
1855 static void
1856 cli_buildopt_cleanupcxx . . $ cli_buildopt_cleanup(49f6e7a06ebc5aa8).(void)
1857 {
1858 struct buildoptcxx . . $ buildopt# *bopt, *next;
1859 struct mime_typecxx . . $ mime_type# *mime, *mnext;
1860
1861 for (bopt = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&build_options); bopt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; bopt = next) {
1862 next = TAILQ_NEXTcxx . . $ `<external>/2546723208511035544/queue.h:459:9`!(bopt, list);
1863 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&build_options, bopt, list);
1864
1865 if (bopt->cflagscxx . . $ buildopt#cflags. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1866 cli_buf_freecxx . . $ cli_buf_free(d5b55d6d3363602b).(bopt->cflagscxx . . $ buildopt#cflags.);
1867 if (bopt->cxxflagscxx . . $ buildopt#cxxflags. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1868 cli_buf_freecxx . . $ cli_buf_free(d5b55d6d3363602b).(bopt->cxxflagscxx . . $ buildopt#cxxflags.);
1869 if (bopt->ldflagscxx . . $ buildopt#ldflags. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1870 cli_buf_freecxx . . $ cli_buf_free(d5b55d6d3363602b).(bopt->ldflagscxx . . $ buildopt#ldflags.);
1871 if (bopt->kore_sourcecxx . . $ buildopt#kore_source. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1872 freecxx . . $ free(5d22bdacc48458e8).(bopt->kore_sourcecxx . . $ buildopt#kore_source.);
1873 if (bopt->kore_flavorcxx . . $ buildopt#kore_flavor. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1874 freecxx . . $ free(5d22bdacc48458e8).(bopt->kore_flavorcxx . . $ buildopt#kore_flavor.);
1875 freecxx . . $ free(5d22bdacc48458e8).(bopt);
1876 }
1877
1878 for (mime = TAILQ_FIRSTcxx . . $ `<external>/2546723208511035544/queue.h:458:9`!(&mime_types); mime != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; mime = mnext) {
1879 mnext = TAILQ_NEXTcxx . . $ `<external>/2546723208511035544/queue.h:459:9`!(mime, list);
1880 TAILQ_REMOVEcxx . . $ `<external>/2546723208511035544/queue.h:426:9`!(&mime_types, mime, list);
1881 freecxx . . $ free(5d22bdacc48458e8).(mime->typecxx . . $ mime_type#type.);
1882 freecxx . . $ free(5d22bdacc48458e8).(mime->extcxx . . $ mime_type#ext.);
1883 freecxx . . $ free(5d22bdacc48458e8).(mime);
1884 }
1885 }
1886
1887 static void
1888 cli_buildopt_cflagscxx . . $ cli_buildopt_cflags(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *bopt, const char *string)
1889 {
1890 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1891 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1892
1893 if (bopt->cflagscxx . . $ buildopt#cflags. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1894 bopt->cflagscxx . . $ buildopt#cflags. = cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(128);
1895
1896 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->cflagscxx . . $ buildopt#cflags., "%s ", string);
1897 }
1898
1899 static void
1900 cli_buildopt_cxxflagscxx . . $ cli_buildopt_cxxflags(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *bopt, const char *string)
1901 {
1902 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1903 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1904
1905 if (bopt->cxxflagscxx . . $ buildopt#cxxflags. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1906 bopt->cxxflagscxx . . $ buildopt#cxxflags. = cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(128);
1907
1908 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->cxxflagscxx . . $ buildopt#cxxflags., "%s ", string);
1909 }
1910
1911 static void
1912 cli_buildopt_ldflagscxx . . $ cli_buildopt_ldflags(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *bopt, const char *string)
1913 {
1914 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1915 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1916
1917 if (bopt->ldflagscxx . . $ buildopt#ldflags. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1918 bopt->ldflagscxx . . $ buildopt#ldflags. = cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(128);
1919
1920 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->ldflagscxx . . $ buildopt#ldflags., "%s ", string);
1921 }
1922
1923 static void
1924 cli_buildopt_single_binarycxx . . $ cli_buildopt_single_binary(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *bopt, const char *string)
1925 {
1926 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1927 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1928 else
1929 fatalcxx . . $ fatal(f6bc48f0426f26ee).("single_binary only supported in global context");
1930
1931 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(string, "yes"))
1932 bopt->single_binarycxx . . $ buildopt#single_binary. = 1;
1933 else
1934 bopt->single_binarycxx . . $ buildopt#single_binary. = 0;
1935 }
1936
1937 static void
1938 cli_buildopt_kore_sourcecxx . . $ cli_buildopt_kore_source(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *bopt, const char *string)
1939 {
1940 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1941 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1942 else
1943 fatalcxx . . $ fatal(f6bc48f0426f26ee).("kore_source only supported in global context");
1944
1945 if (bopt->kore_sourcecxx . . $ buildopt#kore_source. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1946 freecxx . . $ free(5d22bdacc48458e8).(bopt->kore_sourcecxx . . $ buildopt#kore_source.);
1947
1948 bopt->kore_sourcecxx . . $ buildopt#kore_source. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(string);
1949 }
1950
1951 static void
1952 cli_buildopt_kore_flavorcxx . . $ cli_buildopt_kore_flavor(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *bopt, const char *string)
1953 {
1954 int cnt, i;
1955 char *p, *copy, *flavors[10];
1956
1957 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1958 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1959 else
1960 fatalcxx . . $ fatal(f6bc48f0426f26ee).("kore_flavor only supported in global context");
1961
1962 if (bopt->kore_flavorcxx . . $ buildopt#kore_flavor. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1963 freecxx . . $ free(5d22bdacc48458e8).(bopt->kore_flavorcxx . . $ buildopt#kore_flavor.);
1964
1965 copy = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(string);
1966 cnt = cli_split_stringcxx . . $ cli_split_string(87b756e43bd5489c).(copy, " ", flavors, 10);
1967
1968 for (i = 0; i < cnt; i++) {
1969 if ((p = strchrcxx . . $ strchr(2050848944e00d54).(flavors[i], '=')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1970 fatalcxx . . $ fatal(f6bc48f0426f26ee).("invalid flavor %s", string);
1971
1972 *p = '\0';
1973
1974 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(flavors[i], "NOHTTP"))
1975 bopt->flavor_nohttpcxx . . $ buildopt#flavor_nohttp. = 1;
1976 }
1977
1978 bopt->kore_flavorcxx . . $ buildopt#kore_flavor. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(string);
1979 freecxx . . $ free(5d22bdacc48458e8).(copy);
1980 }
1981
1982 static void
1983 cli_buildopt_mimecxx . . $ cli_buildopt_mime(3ce0f79f9cc72e16).(struct buildoptcxx . . $ buildopt# *bopt, const char *ext)
1984 {
1985 struct mime_typecxx . . $ mime_type# *mime;
1986 char *type;
1987
1988 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1989 bopt = cli_buildopt_defaultcxx . . $ cli_buildopt_default(da2029912e1f0661).();
1990 else
1991 fatalcxx . . $ fatal(f6bc48f0426f26ee).("mime_add only supported in global context");
1992
1993 if ((type = strchrcxx . . $ strchr(2050848944e00d54).(ext, ':')) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
1994 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no type given in %s", ext);
1995
1996 *(type)++ = '\0';
1997 TAILQ_FOREACHcxx . . $ `<external>/2546723208511035544/queue.h:435:9`!(mime, &mime_types, list) {
1998 if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(mime->extcxx . . $ mime_type#ext., ext))
1999 fatalcxx . . $ fatal(f6bc48f0426f26ee).("duplicate extension %s found", ext);
2000 }
2001
2002 mime = cli_malloccxx . . $ cli_malloc(bfcfa4d6b7f7ef64).(sizeof(*mime));
2003 mime->extcxx . . $ mime_type#ext. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(ext);
2004 mime->typecxx . . $ mime_type#type. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(type);
2005
2006 TAILQ_INSERT_TAILcxx . . $ `<external>/2546723208511035544/queue.h:402:9`!(&mime_types, mime, list);
2007 }
2008
2009 static void
2010 cli_build_flags_commoncxx . . $ cli_build_flags_common(28dfde3d75c7a877).(struct buildoptcxx . . $ buildopt# *bopt, struct cli_bufcxx . . $ cli_buf# *buf)
2011 {
2012 size_t len;
2013 char *data;
2014
2015 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(buf, "-fPIC ");
2016
2017 if (bopt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2018 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(buf, "-Isrc -Isrc/includes ");
2019
2020 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || bopt->single_binarycxx . . $ buildopt#single_binary. == 0)
2021 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(buf, "-I%s/include ", prefixcxx . . $ prefix.);
2022 else
2023 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(buf, "-I%s/include ", bopt->kore_sourcecxx . . $ buildopt#kore_source.);
2024
2025 if (bopt == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || bopt->single_binarycxx . . $ buildopt#single_binary. == 0) {
2026 cli_kore_load_filecxx . . $ cli_kore_load_file(e1272f335b4a478d).("features", bopt, &data, &len);
2027 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(buf, data, len);
2028 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(buf, " ");
2029 freecxx . . $ free(5d22bdacc48458e8).(data);
2030 }
2031 }
2032
2033 static void
2034 cli_build_cflagscxx . . $ cli_build_cflags(54061a8567f96e74).(struct buildoptcxx . . $ buildopt# *bopt)
2035 {
2036 size_t len;
2037 struct buildoptcxx . . $ buildopt# *obopt;
2038 char *string, *buf, *env;
2039
2040 if ((obopt = cli_buildopt_findcxx . . $ cli_buildopt_find(dd450b94293e0318).(flavorcxx . . $ flavor.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2041 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no such build flavor: %s", flavorcxx . . $ flavor.);
2042
2043 if (bopt->cflagscxx . . $ buildopt#cflags. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2044 bopt->cflagscxx . . $ buildopt#cflags. = cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(128);
2045
2046 cli_build_flags_commoncxx . . $ cli_build_flags_common(28dfde3d75c7a877).(bopt, bopt->cflagscxx . . $ buildopt#cflags.);
2047
2048 if (obopt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && obopt->cflagscxx . . $ buildopt#cflags. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
2049 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(bopt->cflagscxx . . $ buildopt#cflags., obopt->cflagscxx . . $ buildopt#cflags.->datacxx . . $ cli_buf#data.,
2050 obopt->cflagscxx . . $ buildopt#cflags.->offsetcxx . . $ cli_buf#offset.);
2051 }
2052
2053 if (bopt->single_binarycxx . . $ buildopt#single_binary.) {
2054 cli_kore_load_filecxx . . $ cli_kore_load_file(e1272f335b4a478d).("features", bopt, &buf, &len);
2055 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(bopt->cflagscxx . . $ buildopt#cflags., buf, len);
2056 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->cflagscxx . . $ buildopt#cflags., " ");
2057 freecxx . . $ free(5d22bdacc48458e8).(buf);
2058 }
2059
2060 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("CFLAGS")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2061 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->cflagscxx . . $ buildopt#cflags., "%s", env);
2062
2063 string = cli_buf_stringifycxx . . $ cli_buf_stringify(9f2dd2ca3f41a58f).(bopt->cflagscxx . . $ buildopt#cflags., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
2064 printfcxx . . $ printf(581fddd72a8db8fc).("CFLAGS=%s\n", string);
2065 cflags_countcxx . . $ cflags_count. = cli_split_stringcxx . . $ cli_split_string(87b756e43bd5489c).(string, " ", cflagscxx . . $ cflags., CFLAGS_MAXcxx . . $ `src/cli.c:68:9`!);
2066 }
2067
2068 static void
2069 cli_build_cxxflagscxx . . $ cli_build_cxxflags(54061a8567f96e74).(struct buildoptcxx . . $ buildopt# *bopt)
2070 {
2071 struct buildoptcxx . . $ buildopt# *obopt;
2072 char *string, *env;
2073
2074 if ((obopt = cli_buildopt_findcxx . . $ cli_buildopt_find(dd450b94293e0318).(flavorcxx . . $ flavor.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2075 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no such build flavor: %s", flavorcxx . . $ flavor.);
2076
2077 if (bopt->cxxflagscxx . . $ buildopt#cxxflags. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2078 bopt->cxxflagscxx . . $ buildopt#cxxflags. = cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(128);
2079
2080 cli_build_flags_commoncxx . . $ cli_build_flags_common(28dfde3d75c7a877).(bopt, bopt->cxxflagscxx . . $ buildopt#cxxflags.);
2081
2082 if (obopt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && obopt->cxxflagscxx . . $ buildopt#cxxflags. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
2083 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(bopt->cxxflagscxx . . $ buildopt#cxxflags., obopt->cxxflagscxx . . $ buildopt#cxxflags.->datacxx . . $ cli_buf#data.,
2084 obopt->cxxflagscxx . . $ buildopt#cxxflags.->offsetcxx . . $ cli_buf#offset.);
2085 }
2086
2087 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("CXXFLAGS")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2088 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->cxxflagscxx . . $ buildopt#cxxflags., "%s", env);
2089
2090 string = cli_buf_stringifycxx . . $ cli_buf_stringify(9f2dd2ca3f41a58f).(bopt->cxxflagscxx . . $ buildopt#cxxflags., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
2091 if (cxx_files_countcxx . . $ cxx_files_count. > 0)
2092 printfcxx . . $ printf(581fddd72a8db8fc).("CXXFLAGS=%s\n", string);
2093 cxxflags_countcxx . . $ cxxflags_count. = cli_split_stringcxx . . $ cli_split_string(87b756e43bd5489c).(string, " ", cxxflagscxx . . $ cxxflags., CXXFLAGS_MAXcxx . . $ `src/cli.c:69:9`!);
2094 }
2095
2096 static void
2097 cli_build_ldflagscxx . . $ cli_build_ldflags(54061a8567f96e74).(struct buildoptcxx . . $ buildopt# *bopt)
2098 {
2099 int fd;
2100 size_t len;
2101 struct buildoptcxx . . $ buildopt# *obopt;
2102 char *string, *buf, *env, *path;
2103
2104 if ((obopt = cli_buildopt_findcxx . . $ cli_buildopt_find(dd450b94293e0318).(flavorcxx . . $ flavor.)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2105 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no such build flavor: %s", flavorcxx . . $ flavor.);
2106
2107 if (bopt->ldflagscxx . . $ buildopt#ldflags. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2108 bopt->ldflagscxx . . $ buildopt#ldflags. = cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(128);
2109
2110 if (bopt->single_binarycxx . . $ buildopt#single_binary. == 0) {
2111 #if defined(__MACH__)
2112 cli_buf_appendf(bopt->ldflags,
2113 "-dynamiclib -undefined suppress -flat_namespace ");
2114 #else
2115 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->ldflagscxx . . $ buildopt#ldflags., "-shared ");
2116 #endif
2117 } else {
2118 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&path, "%s/ldflags", object_dircxx . . $ object_dir.);
2119 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(path, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!, &fd);
2120 cli_file_readcxx . . $ cli_file_read(2a5d023f7acf84ed).(fd, &buf, &len);
2121 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(fd);
2122 if (len == 0)
2123 fatalcxx . . $ fatal(f6bc48f0426f26ee).("ldflags is empty");
2124 len--;
2125
2126 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(bopt->ldflagscxx . . $ buildopt#ldflags., buf, len);
2127 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->ldflagscxx . . $ buildopt#ldflags., " ");
2128 freecxx . . $ free(5d22bdacc48458e8).(buf);
2129 }
2130
2131 if (obopt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && obopt->ldflagscxx . . $ buildopt#ldflags. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
2132 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(bopt->ldflagscxx . . $ buildopt#ldflags., obopt->ldflagscxx . . $ buildopt#ldflags.->datacxx . . $ cli_buf#data.,
2133 obopt->ldflagscxx . . $ buildopt#ldflags.->offsetcxx . . $ cli_buf#offset.);
2134 }
2135
2136 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("LDFLAGS")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2137 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(bopt->ldflagscxx . . $ buildopt#ldflags., "%s", env);
2138
2139 string = cli_buf_stringifycxx . . $ cli_buf_stringify(9f2dd2ca3f41a58f).(bopt->ldflagscxx . . $ buildopt#ldflags., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
2140 printfcxx . . $ printf(581fddd72a8db8fc).("LDFLAGS=%s\n", string);
2141 ldflags_countcxx . . $ ldflags_count. = cli_split_stringcxx . . $ cli_split_string(87b756e43bd5489c).(string, " ", ldflagscxx . . $ ldflags., LD_FLAGS_MAXcxx . . $ `src/cli.c:67:9`!);
2142 }
2143
2144 static void
2145 cli_flavor_loadcxx . . $ cli_flavor_load(49f6e7a06ebc5aa8).(void)
2146 {
2147 FILEcxx . . $ FILE# *fp;
2148 char buf[BUFSIZcxx . . $ `<external>/232824719582829767/stdio.h:100:9`!], pwd[MAXPATHLENcxx . . $ `<external>/1231830743887005719/param.h:48:10`!], *p, *conf, *env;
2149
2150 if ((env = getenvcxx . . $ getenv(a8b8e32347182212).("KORE_BUILD_FLAVOR")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
2151 flavorcxx . . $ flavor. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(env);
2152 return;
2153 }
2154
2155 if (getcwdcxx . . $ getcwd(dff97f9eb74e1544).(pwd, sizeof(pwd)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2156 fatalcxx . . $ fatal(f6bc48f0426f26ee).("could not get cwd: %s", errno_scxx . . $ `src/cli.c:64:9`!);
2157
2158 applcxx . . $ appl. = basenamecxx . . $ `<external>/6296865783241590524/libgen.h:35:9`!(pwd);
2159 if (applcxx . . $ appl. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2160 fatalcxx . . $ fatal(f6bc48f0426f26ee).("basename: %s", errno_scxx . . $ `src/cli.c:64:9`!);
2161 applcxx . . $ appl. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(applcxx . . $ appl.);
2162 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&conf, "conf/%s.conf", applcxx . . $ appl.);
2163
2164 if (!cli_dir_existscxx . . $ cli_dir_exists(5c4306d8553b3696).("conf") || !cli_file_existscxx . . $ cli_file_exists(5c4306d8553b3696).(conf))
2165 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s doesn't appear to be a kore app", applcxx . . $ appl.);
2166 freecxx . . $ free(5d22bdacc48458e8).(conf);
2167
2168 if ((fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(".flavor", "r")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
2169 flavorcxx . . $ flavor. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).("dev");
2170 return;
2171 }
2172
2173 if (fgetscxx . . $ fgets(efb0aaba7ac866ae).(buf, sizeof(buf), fp) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2174 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to read flavor from file");
2175
2176 if ((p = strchrcxx . . $ strchr(2050848944e00d54).(buf, '\n')) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2177 *p = '\0';
2178
2179 flavorcxx . . $ flavor. = cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(buf);
2180 (void)fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
2181 }
2182
2183 static void
2184 cli_kore_load_filecxx . . $ cli_kore_load_file(e1272f335b4a478d).(const char *name, struct buildoptcxx . . $ buildopt# *bopt,
2185 char **out, size_t *outlen)
2186 {
2187 int fd;
2188 size_t len;
2189 char *path, *data;
2190
2191 if (bopt != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && bopt->single_binarycxx . . $ buildopt#single_binary.) {
2192 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&path, "%s/%s", object_dircxx . . $ object_dir., name);
2193 } else {
2194 (void)cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(&path, "%s/share/kore/%s", prefixcxx . . $ prefix., name);
2195 }
2196
2197 cli_file_opencxx . . $ cli_file_open(3a8dabde7661a86a).(path, O_RDONLYcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:43:9`!, &fd);
2198 cli_file_readcxx . . $ cli_file_read(2a5d023f7acf84ed).(fd, &data, &len);
2199 cli_file_closecxx . . $ cli_file_close(d4f767463ce0a6b3).(fd);
2200 freecxx . . $ free(5d22bdacc48458e8).(path);
2201
2202 if (len == 0)
2203 fatalcxx . . $ fatal(f6bc48f0426f26ee).("%s is empty", name);
2204
2205 len--;
2206
2207 *out = data;
2208 *outlen = len;
2209 }
2210
2211 static void
2212 cli_flavor_changecxx . . $ cli_flavor_change(85c52e162fed56f9).(const char *name)
2213 {
2214 FILEcxx . . $ FILE# *fp;
2215 int ret;
2216 struct buildoptcxx . . $ buildopt# *bopt;
2217
2218 if ((bopt = cli_buildopt_findcxx . . $ cli_buildopt_find(dd450b94293e0318).(name)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2219 fatalcxx . . $ fatal(f6bc48f0426f26ee).("no such flavor: %s", name);
2220
2221 if ((fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(".flavor.tmp", "w")) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2222 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to open temporary file to save flavor");
2223
2224 ret = fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(fp, "%s\n", name);
2225 if (ret == -1 || (size_t)ret != (strlencxx . . $ strlen(751346f8406fd082).(name) + 1))
2226 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to write new build flavor");
2227
2228 (void)fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp);
2229
2230 if (renamecxx . . $ rename(5ae29d726ae57f88).(".flavor.tmp", ".flavor") == -1)
2231 fatalcxx . . $ fatal(f6bc48f0426f26ee).("failed to replace build flavor");
2232
2233 cli_cleancxx . . $ cli_clean(c759356ac01a31e7).(0, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
2234 }
2235
2236 static void
2237 cli_spawn_proccxx . . $ cli_spawn_proc(97a347b124788245).(void (*cb)(void *), void *arg)
2238 {
2239 pid_tcxx . . $ pid_t# pid;
2240 int status;
2241
2242 pid = forkcxx . . $ fork(b126dc7c1de90089).();
2243 switch (pid) {
2244 case -1:
2245 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_compile_cfile: fork() %s", errno_scxx . . $ `src/cli.c:64:9`!);
2246 /* NOTREACHED */
2247 case 0:
2248 cb(arg);
2249 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_spawn_proc: %s", errno_scxx . . $ `src/cli.c:64:9`!);
2250 /* NOTREACHED */
2251 default:
2252 break;
2253 }
2254
2255 if (waitpidcxx . . $ waitpid(1df93256b606fe1f).(pid, &status, 0) == -1)
2256 fatalcxx . . $ fatal(f6bc48f0426f26ee).("couldn't wait for child %d", pid);
2257
2258 if (WEXITSTATUScxx . . $ `<external>/3791503621068212355/wait.h:54:10`!(status) || WTERMSIGcxx . . $ `<external>/3791503621068212355/wait.h:55:10`!(status) || WCOREDUMPcxx . . $ `<external>/3791503621068212355/wait.h:67:10`!(status))
2259 fatalcxx . . $ fatal(f6bc48f0426f26ee).("subprocess trouble, check output");
2260 }
2261
2262 static int
2263 cli_vasprintfcxx . . $ cli_vasprintf(70ad09b5e10823c4).(char **out, const char *fmt, ...)
2264 {
2265 int l;
2266 va_listcxx . . $ va_list# args;
2267
2268 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, fmt);
2269 l = vasprintfcxx . . $ vasprintf(592150f15fbaad71).(out, fmt, args);
2270 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args);
2271
2272 if (l == -1)
2273 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_vasprintf");
2274
2275 return (l);
2276 }
2277
2278 static void
2279 cli_cleanup_filescxx . . $ cli_cleanup_files(85c52e162fed56f9).(const char *spath)
2280 {
2281 cli_find_filescxx . . $ cli_find_files(b304834a9fe4a1c9).(spath, cli_file_removecxx . . $ cli_file_remove(9f788ba9b5df10c4).);
2282
2283 if (rmdircxx . . $ rmdir(5c4306d8553b3696).(spath) == -1 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!)
2284 printfcxx . . $ printf(581fddd72a8db8fc).("couldn't rmdir %s\n", spath);
2285 }
2286
2287 static void *
2288 cli_malloccxx . . $ cli_malloc(bfcfa4d6b7f7ef64).(size_t len)
2289 {
2290 void *ptr;
2291
2292 if ((ptr = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, len)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2293 fatalcxx . . $ fatal(f6bc48f0426f26ee).("calloc: %s", errno_scxx . . $ `src/cli.c:64:9`!);
2294
2295 return (ptr);
2296 }
2297
2298 static void *
2299 cli_realloccxx . . $ cli_realloc(417ab160f6baadc6).(void *ptr, size_t len)
2300 {
2301 void *nptr;
2302
2303 if ((nptr = realloccxx . . $ realloc(417ab160f6baadc6).(ptr, len)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2304 fatalcxx . . $ fatal(f6bc48f0426f26ee).("realloc: %s", errno_scxx . . $ `src/cli.c:64:9`!);
2305
2306 return (nptr);
2307 }
2308
2309 static char *
2310 cli_strdupcxx . . $ cli_strdup(a8b8e32347182212).(const char *string)
2311 {
2312 char *copy;
2313
2314 if ((copy = strdupcxx . . $ strdup(a8b8e32347182212).(string)) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2315 fatalcxx . . $ fatal(f6bc48f0426f26ee).("strdup: %s", errno_scxx . . $ `src/cli.c:64:9`!);
2316
2317 return (copy);
2318 }
2319
2320 struct cli_bufcxx . . $ cli_buf# *
2321 cli_buf_alloccxx . . $ cli_buf_alloc(ad49c8d887c59fc2).(size_t initial)
2322 {
2323 struct cli_bufcxx . . $ cli_buf# *buf;
2324
2325 buf = cli_malloccxx . . $ cli_malloc(bfcfa4d6b7f7ef64).(sizeof(*buf));
2326
2327 if (initial > 0)
2328 buf->datacxx . . $ cli_buf#data. = cli_malloccxx . . $ cli_malloc(bfcfa4d6b7f7ef64).(initial);
2329 else
2330 buf->datacxx . . $ cli_buf#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
2331
2332 buf->lengthcxx . . $ cli_buf#length. = initial;
2333 buf->offsetcxx . . $ cli_buf#offset. = 0;
2334
2335 return (buf);
2336 }
2337
2338 void
2339 cli_buf_freecxx . . $ cli_buf_free(d5b55d6d3363602b).(struct cli_bufcxx . . $ cli_buf# *buf)
2340 {
2341 freecxx . . $ free(5d22bdacc48458e8).(buf->datacxx . . $ cli_buf#data.);
2342 buf->datacxx . . $ cli_buf#data. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
2343 buf->offsetcxx . . $ cli_buf#offset. = 0;
2344 buf->lengthcxx . . $ cli_buf#length. = 0;
2345 freecxx . . $ free(5d22bdacc48458e8).(buf);
2346 }
2347
2348 void
2349 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(struct cli_bufcxx . . $ cli_buf# *buf, const void *d, size_t len)
2350 {
2351 if ((buf->offsetcxx . . $ cli_buf#offset. + len) < len)
2352 fatalcxx . . $ fatal(f6bc48f0426f26ee).("overflow in cli_buf_append");
2353
2354 if ((buf->offsetcxx . . $ cli_buf#offset. + len) > buf->lengthcxx . . $ cli_buf#length.) {
2355 buf->lengthcxx . . $ cli_buf#length. += len;
2356 buf->datacxx . . $ cli_buf#data. = cli_realloccxx . . $ cli_realloc(417ab160f6baadc6).(buf->datacxx . . $ cli_buf#data., buf->lengthcxx . . $ cli_buf#length.);
2357 }
2358
2359 memcpycxx . . $ memcpy(cc817cb175f282d).((buf->datacxx . . $ cli_buf#data. + buf->offsetcxx . . $ cli_buf#offset.), d, len);
2360 buf->offsetcxx . . $ cli_buf#offset. += len;
2361 }
2362
2363 void
2364 cli_buf_appendvcxx . . $ cli_buf_appendv(38140e4e3631ec2c).(struct cli_bufcxx . . $ cli_buf# *buf, const char *fmt, va_listcxx . . $ va_list# args)
2365 {
2366 int l;
2367 va_listcxx . . $ va_list# copy;
2368 char *b, sb[BUFSIZcxx . . $ `<external>/232824719582829767/stdio.h:100:9`!];
2369
2370 va_copycxx . . $ `<external>/8105065126723003039/stdarg.h:56:9`!(copy, args);
2371
2372 l = vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(sb, sizeof(sb), fmt, args);
2373 if (l == -1)
2374 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_buf_appendv(): vsnprintf error");
2375
2376 if ((size_t)l >= sizeof(sb)) {
2377 l = vasprintfcxx . . $ vasprintf(592150f15fbaad71).(&b, fmt, copy);
2378 if (l == -1)
2379 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_buf_appendv(): error or truncation");
2380 } else {
2381 b = sb;
2382 }
2383
2384 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(buf, b, l);
2385 if (b != sb)
2386 freecxx . . $ free(5d22bdacc48458e8).(b);
2387
2388 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(copy);
2389 }
2390
2391 void
2392 cli_buf_appendfcxx . . $ cli_buf_appendf(36f7cd1153ab8c4a).(struct cli_bufcxx . . $ cli_buf# *buf, const char *fmt, ...)
2393 {
2394 va_listcxx . . $ va_list# args;
2395
2396 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, fmt);
2397 cli_buf_appendvcxx . . $ cli_buf_appendv(38140e4e3631ec2c).(buf, fmt, args);
2398 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args);
2399 }
2400
2401 char *
2402 cli_buf_stringifycxx . . $ cli_buf_stringify(9f2dd2ca3f41a58f).(struct cli_bufcxx . . $ cli_buf# *buf, size_t *len)
2403 {
2404 char c;
2405
2406 if (len != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2407 *len = buf->offsetcxx . . $ cli_buf#offset.;
2408
2409 c = '\0';
2410 cli_buf_appendcxx . . $ cli_buf_append(8c23a71c18cb9b09).(buf, &c, sizeof(c));
2411
2412 return ((char *)buf->datacxx . . $ cli_buf#data.);
2413 }
2414
2415 static int
2416 cli_split_stringcxx . . $ cli_split_string(87b756e43bd5489c).(char *input, const char *delim, char **out, size_t ele)
2417 {
2418 int count;
2419 char **ap;
2420
2421 if (ele == 0)
2422 return (0);
2423
2424 count = 0;
2425 for (ap = out; ap < &out[ele - 1] &&
2426 (*ap = strsepcxx . . $ strsep(f4782bac5b8a260e).(&input, delim)) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;) {
2427 if (**ap != '\0') {
2428 ap++;
2429 count++;
2430 }
2431 }
2432
2433 *ap = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
2434 return (count);
2435 }
2436
2437 static char *
2438 cli_read_linecxx . . $ cli_read_line(8c0cb784ce79381a).(FILEcxx . . $ FILE# *fp, char *in, size_t len)
2439 {
2440 char *p, *t;
2441
2442 if (fgetscxx . . $ fgets(efb0aaba7ac866ae).(in, len, fp) == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2443 return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
2444
2445 p = in;
2446 in[strcspncxx . . $ strcspn(335c1dc86f5c867f).(in, "\n")] = '\0';
2447
2448 while (isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*(unsigned char *)p))
2449 p++;
2450
2451 if (p[0] == '#' || p[0] == '\0') {
2452 p[0] = '\0';
2453 return (p);
2454 }
2455
2456 for (t = p; *t != '\0'; t++) {
2457 if (*t == '\t')
2458 *t = ' ';
2459 }
2460
2461 return (p);
2462 }
2463
2464 static char *
2465 cli_text_trimcxx . . $ cli_text_trim(dff97f9eb74e1544).(char *string, size_t len)
2466 {
2467 char *end;
2468
2469 if (len == 0)
2470 return (string);
2471
2472 end = (string + len) - 1;
2473 while (isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*(unsigned char *)string) && string < end)
2474 string++;
2475
2476 while (isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*(unsigned char *)end) && end > string)
2477 *(end)-- = '\0';
2478
2479 return (string);
2480 }
2481
2482 static long long
2483 cli_strtonumcxx . . $ cli_strtonum(f0816a4ef2da3e2).(const char *str, long long min, long long max)
2484 {
2485 long long l;
2486 char *ep;
2487
2488 if (min > max)
2489 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_strtonum: min > max");
2490
2491 errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = 0;
2492 l = strtollcxx . . $ strtoll(c50972e7488cbac6).(str, &ep, 10);
2493 if (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! != 0 || str == ep || *ep != '\0')
2494 fatalcxx . . $ fatal(f6bc48f0426f26ee).("strtoll(): %s", errno_scxx . . $ `src/cli.c:64:9`!);
2495
2496 if (l < min)
2497 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_strtonum: value < min");
2498
2499 if (l > max)
2500 fatalcxx . . $ fatal(f6bc48f0426f26ee).("cli_strtonum: value > max");
2501
2502 return (l);
2503 }
2504
2505 static void
2506 fatalcxx . . $ fatal(f6bc48f0426f26ee).(const char *fmt, ...)
2507 {
2508 va_listcxx . . $ va_list# args;
2509 char buf[2048];
2510
2511 va_startcxx . . $ `<external>/8105065126723003039/stdarg.h:50:9`!(args, fmt);
2512 (void)vsnprintfcxx . . $ vsnprintf(a85eea89d1bd834f).(buf, sizeof(buf), fmt, args);
2513 va_endcxx . . $ `<external>/8105065126723003039/stdarg.h:52:9`!(args);
2514
2515 if (commandcxx . . $ command. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
2516 printfcxx . . $ printf(581fddd72a8db8fc).("kore %s: %s\n", commandcxx . . $ command.->namecxx . . $ cmd#name., buf);
2517 else
2518 printfcxx . . $ printf(581fddd72a8db8fc).("kore: %s\n", buf);
2519
2520 exitcxx . . $ exit(3ca292c338df9bb3).(1);
2521 }