]> git.mdlowis.com Git - proto/aos.git/commitdiff
tweaked user hook for option parsing
authorMichael D. Lowis <mike@mdlowis.com>
Sat, 19 Dec 2020 01:41:50 +0000 (20:41 -0500)
committerMichael D. Lowis <mike@mdlowis.com>
Sat, 19 Dec 2020 01:41:50 +0000 (20:41 -0500)
inc/liba.h
lib/a/opts_parse.c
lib/a/set_option.c [new file with mode: 0644]

index dfb52d1f56d944afdf4c37f8d0e2cb67b0138821..f417a7c44726d900a5c2c358e07613ce350891af 100644 (file)
         (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[];
index 6f88b2724f3b9e7ee559b8b3d5140881ae91132b..91db57c8500327a43ab3d3d5f7cd602ee351de7f 100644 (file)
@@ -1,6 +1,6 @@
 #include <liba.h>
 
-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 (file)
index 0000000..7d7df2f
--- /dev/null
@@ -0,0 +1,8 @@
+#include <liba.h>
+
+void set_option(int sname, char* lname, char* arg)
+{
+    (void)sname;
+    (void)lname;
+    (void)arg;
+}