From 66a86d1b20a1e97b2d008e73db7557887fc44edf Mon Sep 17 00:00:00 2001 From: gramanas Date: Sat, 6 Nov 2021 13:01:47 +0200 Subject: Progress --- main.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 112 insertions(+), 3 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 3431ba8..5012bb2 100644 --- a/main.c +++ b/main.c @@ -1,14 +1,123 @@ +#include "getopt.h" + #include "util.h" #include "parser.h" recipe ** cookbook; +static struct opts { + int json; + int html; + int rcp; + char *query; + int help; +} opt = { + .json = 0, + .html = 0, + .rcp = 0, + .query = NULL, + .help = 0, +}; + +void +print_help() { + printf("Help!\n"); + +} + int main(int argc, char * argv[]) { fdebug("--- Debug mode is on ---\n"); - recipe * r = parse(argv[1], NULL); - if (r) tojson(r); - free_recipe(r); + + int c; + + while (1) { + static struct option long_options[] = + { + /* These options set a flag. */ + // {"verbose", no_argument, &verbose_flag, 1}, + // {"brief", no_argument, &verbose_flag, 0}, + {"help", no_argument, 0, 'h'}, + {"to-json", no_argument, 0, 'j'}, + {"to-html", no_argument, 0, 'w'}, + {"to-rcp", no_argument, 0, 'r'}, + {"format", required_argument, 0, 'f'}, + // {"to-rcp", required_argument, 0, 'r'}, + {0, 0, 0, 0} + }; + + int option_index = 0; + + c = getopt_long (argc, argv, "jhrwf:", + long_options, &option_index); + + if (c == -1) + break; + + 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"); + break; + case 'f': + if (!strcmp(optarg, "json")) + opt.json = 1; + else if (!strcmp(optarg, "rcp")) + opt.rcp = 1; + else if (!strcmp(optarg, "html")) + opt.html = 1; + else + fprintf(stderr, "invalid format: %s\n", optarg); + break; + case 'j': + opt.json = 1; + break; + case 'w': + opt.html = 1; + break; + case 'r': + opt.rcp = 1; + break; + case 'h': + opt.help = 1; + break; + case '?': + return -1; + break; + default: + abort (); + } + } + + if (opt.help) { + print_help(); + return 0; + } + + if (optind < argc) { + while (optind < argc) { + recipe * r = parse(argv[optind++], NULL); + if (r) { + if (opt.json) tojson(r); + if (opt.html) tohtml(r); + if (opt.rcp) torcp(r); + } + free_recipe(r); + } + } else { + fprintf(stderr, "Specify filenames\n"); + } + return 0; } + + + + + + -- cgit v1.2.3