From: Michael D. Lowis Date: Fri, 31 Oct 2014 15:07:00 +0000 (-0400) Subject: Update libopts with function for printing options X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=d3c5bf07d1e82a09dcd91ab467b9af9662dba3a0;p=proto%2Fsclpl.git Update libopts with function for printing options --- diff --git a/modules/libopts b/modules/libopts index 86210d1..3d91692 160000 --- a/modules/libopts +++ b/modules/libopts @@ -1 +1 @@ -Subproject commit 86210d19fd6028f4954c4278dbef620734a896e1 +Subproject commit 3d9169274240cb0edd16aea0d374c63c49d86eab diff --git a/source/sclpl/main.c b/source/sclpl/main.c index 91aef76..1149fe3 100644 --- a/source/sclpl/main.c +++ b/source/sclpl/main.c @@ -29,37 +29,8 @@ opts_cfg_t Options_Config[] = { }; void print_usage(void) { - opts_cfg_t* opts = &Options_Config[0]; - bool opts_have_args = false; - size_t sz = 0; - /* Figure out the longest option name */ - while (NULL != opts->name) { - size_t name_sz = strlen(opts->name); - if (name_sz > sz) { - sz = name_sz; - } - if (opts->has_arg) { - opts_have_args = true; - } - opts++; - } - - /* Print the usage and option list */ puts(Usage); - int padding = sz + 4 + ((opts_have_args) ? 4 : 0); - char* buffer = (char*)malloc(padding+1); - opts = &Options_Config[0]; - while (NULL != opts->name) { - if (1 == strlen(opts->name)) - sprintf(buffer, " -%s", opts->name); - else - sprintf(buffer, " --%s", opts->name); - if (opts->has_arg) sprintf(&buffer[strlen(buffer)], "=ARG "); - printf("%-*s%s\n", padding, buffer, opts->desc); - opts++; - } - free(buffer); - + opts_print_help(stdout, Options_Config); exit(1); }