From: Michael D. Lowis Date: Sat, 19 Dec 2020 01:41:50 +0000 (-0500) Subject: tweaked user hook for option parsing X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=b520fdf3a750c42741f1be91f28dc374b4e98208;p=proto%2Faos.git tweaked user hook for option parsing --- diff --git a/inc/liba.h b/inc/liba.h index dfb52d1..f417a7c 100644 --- a/inc/liba.h +++ b/inc/liba.h @@ -30,17 +30,6 @@ (type*)((uintptr_t)obj - offsetof(type, member)) #endif -/* - Basic Runtime Facilities -*/ - -/* rename user's main routine so GC is auto-initialized and options parsed */ -extern int user_main(int argc, char** argv); -#define main user_main - -extern void opts_setoption(int sname, char* lname, char* arg); - - /* Garbage Collector Interface */ @@ -83,6 +72,16 @@ char* estrdup(const char *s); int forkexec(char** cmd); char* strmcat(char* first, ...); +/* + Basic Runtime Facilities +*/ + +/* rename user's main routine so GC is auto-initialized and options parsed */ +#define main usermain + +extern int usermain(int argc, char** argv); +extern void set_option(int sname, char* lname, char* arg); + extern char* ARGV0; extern char* Usage; extern Option_T Options[]; diff --git a/lib/a/opts_parse.c b/lib/a/opts_parse.c index 6f88b27..91db57c 100644 --- a/lib/a/opts_parse.c +++ b/lib/a/opts_parse.c @@ -1,6 +1,6 @@ #include -extern void opts_setoption(int sname, char* lname, char* arg) +static void handle_option(int sname, char* lname, char* arg) { if (sname == 'h') { @@ -9,11 +9,10 @@ extern void opts_setoption(int sname, char* lname, char* arg) } else { - printf(" --%s=%s\n", lname, arg); + set_option(sname, lname, arg); } } - static OptionDescriptor_T* lookup_opt(int optc, OptionDescriptor_T* optv, char* flag) { OptionDescriptor_T* opt = NULL; @@ -67,7 +66,7 @@ static void parse_longopt(int optc, OptionDescriptor_T* optv, int* currp, char** } } printf("handled option: '--%s=%s'\n", flag, arg); - opts_setoption(od->sname, od->lname, arg); + handle_option(od->sname, od->lname, arg); } /* now repair the split if we made one */ @@ -97,7 +96,7 @@ static void parse_shortopt(int optc, OptionDescriptor_T* optv, int* currp, char* if (*arg != '\0') { arg += (*arg == '=' ? 1 : 0); - opts_setoption(od->sname, od->lname, arg); + handle_option(od->sname, od->lname, arg); break; } else if (!*arg) @@ -107,7 +106,7 @@ static void parse_shortopt(int optc, OptionDescriptor_T* optv, int* currp, char* { fatal("expected argument for option: '%s'", flag); } - opts_setoption(od->sname, od->lname, arg); + handle_option(od->sname, od->lname, arg); *currp += 1; break; } @@ -118,7 +117,7 @@ static void parse_shortopt(int optc, OptionDescriptor_T* optv, int* currp, char* } else { - opts_setoption(od->sname, od->lname, NULL); + handle_option(od->sname, od->lname, NULL); } } *currp += 1; diff --git a/lib/a/set_option.c b/lib/a/set_option.c new file mode 100644 index 0000000..7d7df2f --- /dev/null +++ b/lib/a/set_option.c @@ -0,0 +1,8 @@ +#include + +void set_option(int sname, char* lname, char* arg) +{ + (void)sname; + (void)lname; + (void)arg; +}