]> git.mdlowis.com Git - proto/sclpl.git/commitdiff
Update libopts with function for printing options
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 31 Oct 2014 15:07:00 +0000 (11:07 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 31 Oct 2014 15:07:00 +0000 (11:07 -0400)
modules/libopts
source/sclpl/main.c

index 86210d19fd6028f4954c4278dbef620734a896e1..3d9169274240cb0edd16aea0d374c63c49d86eab 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 86210d19fd6028f4954c4278dbef620734a896e1
+Subproject commit 3d9169274240cb0edd16aea0d374c63c49d86eab
index 91aef7627d698d08419334d11b33f36fe42a1bb9..1149fe3ba51f8aceda9390f64e331f1c7a36eb27 100644 (file)
@@ -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);
 }