ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
init.c File Reference

WASM initialization helpers implementation. More...

Go to the source code of this file.

Functions

int wasm_parse_args (const char *args_str, char **argv, int max_args, char **out_args_copy)
 

Detailed Description

WASM initialization helpers implementation.

Shared initialization utilities compiled into both WASM modules.

Definition in file src/web/common/init.c.

Function Documentation

◆ wasm_parse_args()

int wasm_parse_args ( const char *  args_str,
char **  argv,
int  max_args,
char **  out_args_copy 
)

Parse space-separated args_str into argv[] Sets *out_args_copy to the strdup'd buffer that must be freed by the caller AFTER argv is no longer needed (since argv points into args_copy).

Parameters
args_strSpace-separated argument string
argvOutput array to store argument pointers (at least max_args elements)
max_argsMaximum number of arguments to parse
out_args_copyOutput buffer for the strdup'd args_str
Returns
argc (number of arguments parsed), or -1 on allocation failure

Definition at line 25 of file src/web/common/init.c.

25 {
26 if (!args_str || !argv || !out_args_copy || max_args < 1) {
27 return -1;
28 }
29
30 // Duplicate the input string (strtok modifies the string)
31 char *args_copy = strdup(args_str);
32 if (!args_copy) {
33 return -1;
34 }
35
36 *out_args_copy = args_copy;
37
38 // Parse space-separated arguments
39 int argc = 0;
40 char *token = strtok(args_copy, " ");
41 while (token != NULL && argc < (max_args - 1)) {
42 argv[argc++] = token;
43 token = strtok(NULL, " ");
44 }
45 argv[argc] = NULL;
46
47 // Log for debugging
48 fprintf(stderr, "[wasm_parse_args] Parsed input: %s\n", args_str);
49 fprintf(stderr, "[wasm_parse_args] argc=%d\n", argc);
50 for (int i = 0; i < argc; i++) {
51 fprintf(stderr, "[wasm_parse_args] argv[%d]=%s\n", i, argv[i]);
52 }
53
54 return argc;
55}

Referenced by client_init_with_args(), and mirror_init_with_args().