From 6d2b6ffccafe08bd1c28a03860cd891a0064ac59 Mon Sep 17 00:00:00 2001 From: Kied Llaentenn <32681240+Kiedtl@users.noreply.github.com> Date: Thu, 12 Dec 2019 22:39:35 -0500 Subject: [PATCH] argument parsing --- args.h | 5 +---- main.c | 23 +++++++++++++++++++++-- output.h | 1 + 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/args.h b/args.h index e7091d2..2809697 100644 --- a/args.h +++ b/args.h @@ -19,10 +19,7 @@ extern char *argv0; typedef struct Options { - bool perf_opt1; - bool perf_opt2; - bool perf_opt3; - bool verbose; + bool stub; // no real options... yet } Options; /* use main(int argc, char *argv[]) */ diff --git a/main.c b/main.c index 0836aa3..f61bf99 100644 --- a/main.c +++ b/main.c @@ -7,13 +7,32 @@ #include "termbox.h" #include "args.h" +#define VERSION "0.1.0" + // argument parsing (args.h) char *argv0; struct Options *opts; int -main ( void ) +main ( int argc, char *argv[] ) { + // argument parsing + argv0 = argv[0]; + + ARGBEGIN { + case 'V': + PRINT("%s %s\n", argv0, VERSION); + exit(0); + case 'h': + default: + PRINT("fire %s\n(c) Kied Llaentenn and contributors\n", VERSION); + PRINT("https://github.com/lptstr/fire\n"); + PRINT("\nUSAGE:\n\t$ fire\n\n"); + PRINT("OPTIONS:\n\t-V\tshow version and exit.\n"); + PRINT("\t-h\tshow this help message and exit.\n\n"); + exit(1); + } ARGEND + // initialize termbox tb_init(); tb_select_output_mode(TB_OUTPUT_NORMAL); @@ -40,7 +59,7 @@ main ( void ) tb_shutdown(); // cleanup framebuffer - free(buf.tmp_buf); + free(buf.buf); return 0; } diff --git a/output.h b/output.h index c93af7a..d2c0d03 100644 --- a/output.h +++ b/output.h @@ -1,5 +1,6 @@ #ifndef OUTP_H #define OUTP_H +#include #define PRINT(...) fprintf(stderr, __VA_ARGS__);