summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.am3
-rw-r--r--src/cook.c121
2 files changed, 123 insertions, 1 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index e3645a9..802ba3f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
-bin_PROGRAMS = food cookbook
+bin_PROGRAMS = food cookbook cook
common_sources = eval.c \
eval.h \
@@ -21,3 +21,4 @@ common_sources = eval.c \
food_SOURCES = food.c $(common_sources)
cookbook_SOURCES = cookbook.c $(common_sources)
+cook_SOURCES = cook.c $(common_sources)
diff --git a/src/cook.c b/src/cook.c
new file mode 100644
index 0000000..74374f0
--- /dev/null
+++ b/src/cook.c
@@ -0,0 +1,121 @@
+#include "util.h"
+#include "parser.h"
+#include "search.h"
+#include "foodopts.h"
+#include "eval.h"
+#include "lib.h"
+
+static struct opts {
+ int new;
+ int change;
+ char title[2048];
+ char includes[100][2048];
+ int includes_n;
+ char ing[100][2048];
+ int ing_n;
+ char step[100][2048];
+ int step_n;
+ int help;
+} opt = {
+ .new = 0,
+ .change = 0,
+ .title = "",
+ .includes = {""},
+ .includes_n = 0,
+ .ing = {""},
+ .ing_n = 0,
+ .step = {""},
+ .step_n = 0,
+ .help = 0,
+};
+
+int
+main(int argc, char * argv[])
+{
+ fdebug("--- Debug mode is on ---\n");
+
+ int c;
+
+ struct foodoption long_options[] =
+ {/* name, has_arg, flag, val, help, arg */
+ {"help", no_argument, 0, 'h', "Print this help", 0, "General" },
+ {"include", required_argument, 0, 'I', "Path to recipe library, can be passed multiple times", "PATH", 0 },
+ {"new", no_argument, 0, 'n', "Create recipe", 0, "Commands" },
+ {"change", required_argument, 0, 'c', "Change recipe", "FILE", 0 },
+ {"title", required_argument, 0, 't', "Set recipe title", "TITLE", "Options" },
+ {"ingredient", required_argument, 0, 'i', "Add an ingredient", "INGREDIENT", 0 },
+ {"step", required_argument, 0, 's', "Add a step", "STEP", 0 },
+ {0, 0, 0, 0, 0}
+ };
+ while (1) {
+ int option_index = 0;
+
+ c = get_foodopt (argc, argv, "hI:nc:t:i:s:",
+ long_options, &option_index);
+
+ if (c == -1)
+ break;
+
+ switch (c) {
+ case 0:
+ break;
+ case 'I':
+ strcpy(opt.includes[opt.includes_n++], optarg);
+ break;
+ case 'i':
+ strcpy(opt.ing[opt.ing_n++], optarg);
+ break;
+ case 's':
+ strcpy(opt.step[opt.step_n++], optarg);
+ break;
+ case 't':
+ strcpy(opt.title, optarg);
+ break;
+ case 'h':
+ opt.help = 1;
+ break;
+ case 'n':
+ opt.new = 1;
+ break;
+ case 'c':
+ opt.change = 1;
+ break;
+ case '?':
+ fprintf(stderr, "%s: option '%c' not recognised, try -h for help\n", argv[0], optopt);
+ return -1;
+ break;
+ case ':':
+ switch (optopt) {
+ /* case 'l': */
+ /* opt.list = 1; */
+ /* strcpy(opt.listfmt, "DEFAULT"); */
+ /* break; */
+ default:
+ fprintf(stderr, "%s: missing argument %s for -%c\n", argv[0], get_argument(optopt, long_options), optopt);
+ return -1;
+ break;
+ }
+ break;
+ default:
+ abort ();
+ }
+ }
+
+ if (opt.help) {
+ foodopt_help(argv[0], long_options);
+ return 0;
+ }
+
+ if (opt.new) {
+ if (strcmp(opt.title, ""))
+ printf("@%s\n\n", opt.title);
+ for (int i = 0; i < opt.ing_n; i++)
+ printf("%s\n", opt.ing[i]);
+ if (opt.ing_n)
+ printf("\n---\n\n");
+ for (int i = 0; i < opt.step_n; i++)
+ printf("%s\n", opt.step[i]);
+ }
+
+ return 0;
+}