libk  Diff

Differences From Artifact [1d4ed1c3cd]:

To Artifact [ff83a12d45]:


1
2
3
4


5


6











































#include <k/cli.h>

kcli_cond
kcli_parse(kcli_set prg) {





}















































>
>

>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <k/cli.h>

kcli_cond
kcli_parse(kcli_set prg) {
	bool no_more_opts = false;
	const kcli_param* param = prg.params;

	for (sz i = 0; (i < prg.argc) && (prg.args[i] != null); ++i) {
		if (no_more_opts) goto is_param;

		const char* const arg = prg.args[i];
		if (arg[0] == '-') {
			if(arg[1] == '-') {
				if (arg[2] == 0) { no_more_opts = true; continue; }
				else if (arg[2] == '@') {
					// TODO: implement reading parameters from files
					continue;
				} else goto is_long_opt;
			} else if (arg[1] == '@') {
				// TODO: implement newline-separated file reading behavior
				continue;
			} else if (arg[1] == 0) {
				goto is_param;
			} else {
				goto is_short_opt;
			}
		} else if (arg[0] == '@') {
			// TODO: implement parsing file for options and parameters
			continue;
		} else {
			goto is_param;
		}

		is_short_opt: {
			continue;
		}
		is_long_opt: {
			continue;
		}
		is_param: {
			void* val = param -> val;
			if (param -> kind & kcli_param_int) {
				ubyte base = param->kind & ~kcli_param_int;
				/* TODO: parse integer */
			} else switch (param -> kind) {
				case kcli_param_none: continue;
				case kcli_param_string: *(char const**)val = arg; break;
				case kcli_param_enum: /* TODO */ break;
				default: return kcli_cond_spec;
			}
		}
	}
}