]> git.mdlowis.com Git - proto/aos.git/commitdiff
update option parsing api
authorMichael D. Lowis <mike.lowis@gentex.com>
Wed, 15 Dec 2021 19:16:10 +0000 (14:16 -0500)
committerMichael D. Lowis <mike.lowis@gentex.com>
Wed, 15 Dec 2021 19:16:10 +0000 (14:16 -0500)
inc/liba.h
lib/a/gc.c
lib/a/opts_parse.c

index 3e9fbd1c4e1867169a4df28077102de1e5c88ff9..39afaa909fbbaf0fa72ad9b11bc0b1aca6c37ff4 100644 (file)
@@ -47,13 +47,8 @@ typedef struct {
     int a : 1;
 } Option_T;
 
-void opts_parse(int argc, char** argv);
-void opts_parsespec(char* spec, Option_T* opt);
-void opts_printhelp(void);
-
-//void Options_Parse(int argc, char** argv);
-//void Options_ParseSpec(char* spec, Option_T* opt);
-//void Options_PrintHelp(void);
+void Options_Parse(int argc, char** argv);
+void Options_PrintHelp(void);
 
 /*
     Standard Library Helpers
index c2937106dd68318d074066595b2fe096f7d921c0..b8a1362560e514046a40733078352766971e3bb9 100644 (file)
@@ -86,7 +86,7 @@ void gc_delref(void* p)
 
 int main(int argc, char** argv)
 {
-    opts_parse(argc, argv);
+    Options_Parse(argc, argv);
     Stack_Bot = &(intptr_t){0};
     Log.index = 0;
     hash_init(&ZCT,0);
index 942ffa9d88ff6c6f2dcb5102e943b85f02ff7357..4519d6e239710e4043f3f4eb06c7ab175dd3e0f4 100644 (file)
@@ -1,10 +1,10 @@
 #include <liba.h>
 
-static void handle_option(int s, char* l, char* arg)
+static void HandleOption(int s, char* l, char* arg)
 {
     if (s == 'h')
     {
-        opts_printhelp();
+        Options_PrintHelp();
         exit(1);
     }
     else
@@ -14,7 +14,7 @@ static void handle_option(int s, char* l, char* arg)
     }
 }
 
-static Option_T* lookup_opt(char* flag)
+static Option_T* LookupOption(char* flag)
 {
     Option_T* opt = NULL;
 
@@ -34,7 +34,7 @@ static Option_T* lookup_opt(char* flag)
     return opt;
 }
 
-static inline void parse_longopt(int* currp, char** argv)
+static inline void ParseLongOption(int* currp, char** argv)
 {
     /* get the option and the arg if there is one */
     char* flag = argv[*currp] + 2;
@@ -46,7 +46,7 @@ static inline void parse_longopt(int* currp, char** argv)
         arg = split+1;
     }
 
-    Option_T* od = lookup_opt(flag);
+    Option_T* od = LookupOption(flag);
     if (!od)
     {
         fatal("unknown option: '%s'", flag);
@@ -67,7 +67,7 @@ static inline void parse_longopt(int* currp, char** argv)
             }
         }
         printf("handled option: '--%s=%s'\n", flag, arg);
-        handle_option(od->s, od->l, arg);
+        HandleOption(od->s, od->l, arg);
     }
 
     /* now repair the split if we made one */
@@ -78,7 +78,7 @@ static inline void parse_longopt(int* currp, char** argv)
     *currp += 1;
 }
 
-static inline void parse_shortopt(int* currp, char** argv)
+static inline void ParseShortOption(int* currp, char** argv)
 {
     char* argstr = argv[*currp]+1;
     char flag[] = "\0\0";
@@ -86,7 +86,7 @@ static inline void parse_shortopt(int* currp, char** argv)
     {
         /* get the flag and the possible argument */
         flag[0] = *argstr;
-        Option_T* od = lookup_opt(flag);
+        Option_T* od = LookupOption(flag);
         if (!od)
         {
             fatal("unknown option: '%s'", flag);
@@ -97,7 +97,7 @@ static inline void parse_shortopt(int* currp, char** argv)
             if (*arg != '\0')
             {
                 arg += (*arg == '=' ? 1 : 0);
-                handle_option(od->s, od->l, arg);
+                HandleOption(od->s, od->l, arg);
                 break;
             }
             else if (!*arg)
@@ -107,7 +107,7 @@ static inline void parse_shortopt(int* currp, char** argv)
                 {
                     fatal("expected argument for option: '%s'", flag);
                 }
-                handle_option(od->s, od->l, arg);
+                HandleOption(od->s, od->l, arg);
                 *currp += 1;
                 break;
             }
@@ -118,13 +118,13 @@ static inline void parse_shortopt(int* currp, char** argv)
         }
         else
         {
-            handle_option(od->s, od->l, NULL);
+            HandleOption(od->s, od->l, NULL);
         }
     }
     *currp += 1;
 }
 
-void opts_parse(int argc, char** argv)
+void Options_Parse(int argc, char** argv)
 {
     /* Record the program name */
     ARGV0 = argv[0];
@@ -134,11 +134,11 @@ void opts_parse(int argc, char** argv)
     {
         if (argv[i][0] == '-' && argv[i][1] == '-')
         {
-            parse_longopt(&i, argv);
+            ParseLongOption(&i, argv);
         }
         else if (argv[i][0] == '-')
         {
-            parse_shortopt(&i, argv);
+            ParseShortOption(&i, argv);
         }
         else
         {
@@ -148,7 +148,7 @@ void opts_parse(int argc, char** argv)
     }
 }
 
-void opts_printhelp(void)
+void Options_PrintHelp(void)
 {
     /* calculate padding */
     size_t padding = 0;