libk  Diff

Differences From Artifact [1d4ed1c3cd]:

To Artifact [ff83a12d45]:


     1      1   #include <k/cli.h>
     2      2   
     3      3   kcli_cond
     4      4   kcli_parse(kcli_set prg) {
            5  +	bool no_more_opts = false;
            6  +	const kcli_param* param = prg.params;
            7  +
            8  +	for (sz i = 0; (i < prg.argc) && (prg.args[i] != null); ++i) {
            9  +		if (no_more_opts) goto is_param;
           10  +
           11  +		const char* const arg = prg.args[i];
           12  +		if (arg[0] == '-') {
           13  +			if(arg[1] == '-') {
           14  +				if (arg[2] == 0) { no_more_opts = true; continue; }
           15  +				else if (arg[2] == '@') {
           16  +					// TODO: implement reading parameters from files
           17  +					continue;
           18  +				} else goto is_long_opt;
           19  +			} else if (arg[1] == '@') {
           20  +				// TODO: implement newline-separated file reading behavior
           21  +				continue;
           22  +			} else if (arg[1] == 0) {
           23  +				goto is_param;
           24  +			} else {
           25  +				goto is_short_opt;
           26  +			}
           27  +		} else if (arg[0] == '@') {
           28  +			// TODO: implement parsing file for options and parameters
           29  +			continue;
           30  +		} else {
           31  +			goto is_param;
           32  +		}
     5     33   
           34  +		is_short_opt: {
           35  +			continue;
           36  +		}
           37  +		is_long_opt: {
           38  +			continue;
           39  +		}
           40  +		is_param: {
           41  +			void* val = param -> val;
           42  +			if (param -> kind & kcli_param_int) {
           43  +				ubyte base = param->kind & ~kcli_param_int;
           44  +				/* TODO: parse integer */
           45  +			} else switch (param -> kind) {
           46  +				case kcli_param_none: continue;
           47  +				case kcli_param_string: *(char const**)val = arg; break;
           48  +				case kcli_param_enum: /* TODO */ break;
           49  +				default: return kcli_cond_spec;
           50  +			}
           51  +		}
           52  +	}
     6     53   }