summaryrefslogtreecommitdiffstats
path: root/src/foodopts.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2022-06-08 13:54:49 +0300
committergramanas <anastasis.gramm2@gmail.com>2022-06-08 13:54:49 +0300
commit9650bc35b4aa4ffc35cf99d0e1db64dda5d801c8 (patch)
tree1d3c373f141324141d2293dcff3c64a29c9d9de9 /src/foodopts.c
parentf20c12dd9f920eee1f50f99c8a4c86730e40432c (diff)
downloadfoodtools-9650bc35b4aa4ffc35cf99d0e1db64dda5d801c8.tar.gz
foodtools-9650bc35b4aa4ffc35cf99d0e1db64dda5d801c8.tar.bz2
foodtools-9650bc35b4aa4ffc35cf99d0e1db64dda5d801c8.zip
Move from getopt to foodopts
Diffstat (limited to 'src/foodopts.c')
-rw-r--r--src/foodopts.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/foodopts.c b/src/foodopts.c
index e69de29..7a4cbbd 100644
--- a/src/foodopts.c
+++ b/src/foodopts.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include "foodopts.h"
+
+int
+get_foodopt(int argc, char *const argv[],
+ const char *optstring,
+ const struct foodoption *longopts,
+ int *longindex)
+{
+ return getopt_long(argc, argv, optstring,
+ (struct option *)longopts, longindex);
+}
+
+void
+foodopt_help(char * argv0,
+ const struct foodoption *longopts)
+{
+ fprintf(stderr, "%s [OPTION ...] FILE ...\n", argv0);
+ fprintf(stderr, "\nOPTIONS:\n");
+
+
+ int i = 0;
+ while ((longopts[i].name)
+ && (longopts[i].val)) {
+ fprintf(stderr, "-%c, --%s%s%s: %s\n",
+ longopts[i].val,
+ longopts[i].name,
+ longopts[i].has_arg == required_argument ? " " : "",
+ longopts[i].has_arg == required_argument ? longopts[i].arg : "",
+ longopts[i].help);
+ i++;
+ }
+}