summaryrefslogtreecommitdiffstats
path: root/src/food.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/food.c
parentf20c12dd9f920eee1f50f99c8a4c86730e40432c (diff)
downloadfoodtools-9650bc35b4aa4ffc35cf99d0e1db64dda5d801c8.tar.gz
foodtools-9650bc35b4aa4ffc35cf99d0e1db64dda5d801c8.tar.bz2
foodtools-9650bc35b4aa4ffc35cf99d0e1db64dda5d801c8.zip
Move from getopt to foodopts
Diffstat (limited to 'src/food.c')
-rw-r--r--src/food.c55
1 files changed, 23 insertions, 32 deletions
diff --git a/src/food.c b/src/food.c
index e4bc981..02cd280 100644
--- a/src/food.c
+++ b/src/food.c
@@ -1,8 +1,9 @@
-#include <getopt.h>
+//#include <getopt.h>
#include "util.h"
#include "parser.h"
#include "search.h"
+#include "foodopts.h"
#include "eval.h"
#include "lib.h"
@@ -66,33 +67,28 @@ main(int argc, char * argv[])
int c;
+ struct foodoption long_options[] =
+ {/* name, has_arg, flag, val, help, arg */
+ {"help", no_argument, 0, 'h', "Print this help", 0},
+ {"no-eval", no_argument, 0, 'n', "Don't evaluate recipes", 0},
+ {"to-json", no_argument, 0, 'j', "Format recipe to json", 0},
+ {"to-html", no_argument, 0, 'w', "Format recipe to html", 0},
+ {"to-rcp", no_argument, 0, 'r', "Format recipe to rcp", 0},
+ {"add-item", required_argument, 0, 'a', "Add item to matched recipes", "ITEM"},
+ //{"add-step", required_argument, 0, 'o'},, 0
+ {"format", required_argument, 0, 'f', "Select recipe formatting", "{json,html,rcp}"},
+ {"include", required_argument, 0, 'I', "Path to recipe library, can be passed many times", "PATH"},
+ {"search", required_argument, 0, 's', "Return recipes matching QUERY", "QUERY"},
+ {"title", required_argument, 0, 't', "Return recipes matching TITLE", "TITLE"},
+ {"strict", required_argument, 0, 'S', "Return recipes matching QUERY, exaclty", "QUERY"},
+ {"hash", required_argument, 0, 'H', "Return recipes by HASH", "HASH"},
+ {"list-ingredients", no_argument, 0, 'l', "List ingredients for matched recipes", 0},
+ {0, 0, 0, 0, 0}
+ };
while (1) {
- static struct option long_options[] =
- {
- /* <span class="roman">These options set a flag.</span> */
- // {"verbose", no_argument, &verbose_flag, 1},
- // {"brief", no_argument, &verbose_flag, 0},
- {"help", no_argument, 0, 'h'},
- {"no-eval", no_argument, 0, 'n'},
- {"to-json", no_argument, 0, 'j'},
- {"to-html", no_argument, 0, 'w'},
- {"to-rcp", no_argument, 0, 'r'},
- {"add-item", required_argument, 0, 'a'},
- //{"add-step", required_argument, 0, 'o'},
- {"format", required_argument, 0, 'f'},
- {"include", required_argument, 0, 'I'},
- {"search", required_argument, 0, 's'},
- {"title", required_argument, 0, 't'},
- {"strict", required_argument, 0, 'S'},
- {"hash", required_argument, 0, 'H'},
- {"list-ingredients", no_argument, 0, 'l'},
- // {"to-rcp", required_argument, 0, 'r'},
- {0, 0, 0, 0}
- };
-
int option_index = 0;
- c = getopt_long (argc, argv, "jnlhrwf:s:S:t:H:I:a:",
+ c = get_foodopt (argc, argv, "jnlhrwf:s:S:t:H:I:a:",
long_options, &option_index);
if (c == -1)
@@ -100,12 +96,7 @@ main(int argc, char * argv[])
switch (c) {
case 0:
- if (long_options[option_index].flag != 0)
- break;
- printf ("option %s", long_options[option_index].name);
- if (optarg)
- printf (" with arg %s", optarg);
- printf ("\n");
+ printf("Flag setting\n");
break;
case 'f':
if (!strcmp(optarg, "json"))
@@ -168,7 +159,7 @@ main(int argc, char * argv[])
}
if (opt.help) {
- print_help(argv[0]);
+ foodopt_help(argv[0], long_options);
return 0;
}