summaryrefslogtreecommitdiffstats
path: root/src/foodopts.c
diff options
context:
space:
mode:
authorgramanas <anastasis.gramm2@gmail.com>2022-10-14 22:11:50 +0300
committergramanas <anastasis.gramm2@gmail.com>2022-10-14 22:11:50 +0300
commit7b7240d50dd5e418bc17beff48aa5681b398b980 (patch)
treeb521f1da139ce85974b71f1698cc140b1e7fed6c /src/foodopts.c
parent433ce0f6795a4db89921b26274dd0b18fcccbb21 (diff)
downloadfoodtools-7b7240d50dd5e418bc17beff48aa5681b398b980.tar.gz
foodtools-7b7240d50dd5e418bc17beff48aa5681b398b980.tar.bz2
foodtools-7b7240d50dd5e418bc17beff48aa5681b398b980.zip
More changes
Diffstat (limited to 'src/foodopts.c')
-rw-r--r--src/foodopts.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/foodopts.c b/src/foodopts.c
index 7a4cbbd..338b97e 100644
--- a/src/foodopts.c
+++ b/src/foodopts.c
@@ -11,6 +11,20 @@ get_foodopt(int argc, char *const argv[],
(struct option *)longopts, longindex);
}
+const char *
+get_argument(const char opt,
+ const struct foodoption *longopts)
+{
+ int i = 0;
+ while ((longopts[i].name)
+ && (longopts[i].val)) {
+ if (longopts[i].val == opt)
+ return longopts[i].arg;
+ i++;
+ }
+ return NULL;
+}
+
void
foodopt_help(char * argv0,
const struct foodoption *longopts)
@@ -22,11 +36,14 @@ foodopt_help(char * argv0,
int i = 0;
while ((longopts[i].name)
&& (longopts[i].val)) {
+ if (longopts[i].category) {
+ fprintf(stderr, "\n%s:\n", longopts[i].category);
+ }
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].has_arg == required_argument || longopts[i].has_arg == optional_argument) ? " " : "",
+ (longopts[i].has_arg == required_argument || longopts[i].has_arg == optional_argument) ? longopts[i].arg : "",
longopts[i].help);
i++;
}