opt.h (559B)
1 #pragma once 2 3 #include <stdbool.h> 4 5 /* TODO: this isn't very easy to use; a declarative-style option parser would 6 * be better */ 7 8 typedef struct opt_ctx { 9 char s, *l; /* Short/long opt; l is "" if s != 0 */ 10 bool avail; /* Argument for option is available */ 11 bool attached; /* Argument for option of form "-oARG" or "--opt=ARG" */ 12 13 /* Internal */ 14 char *arg; 15 bool arg_used; 16 char *cluster; 17 int *argc; 18 char **o; 19 char **a; 20 } opt_ctx; 21 22 void opt_init(opt_ctx *opt, int *argc, char **argv); 23 bool opt_parse(opt_ctx *opt); 24 char *opt_arg(opt_ctx *opt);