From 9c336eed8ce72bdcd42aaebcb4761e2668e75bed Mon Sep 17 00:00:00 2001 From: tTh Date: Thu, 27 Apr 2023 23:59:59 +0200 Subject: [PATCH] adding command line options --- tools/read_obj.c | 42 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/tools/read_obj.c b/tools/read_obj.c index 10a5197..a16a659 100644 --- a/tools/read_obj.c +++ b/tools/read_obj.c @@ -5,6 +5,7 @@ #include #include #include // for basename(3) +#include #include "../bubulles.h" #include "../edges.h" @@ -13,22 +14,51 @@ int verbosity = 0; +/* --------------------------------------------------------------------- */ +void help(void) +{ +printf("nothing to say...\n"); +exit(0); +} +/* --------------------------------------------------------------------- */ + int main(int argc, char *argv[]) { -int foo; -char *fname; /* see manpage basename(3) */ +int foo, opt; +// char *fname; /* see manpage basename(3) */ fprintf(stderr, "\n### READ_OBJ compiled %s at %s\n", __DATE__, __TIME__); -if (2 != argc) { +if (1 == argc) { bubulles_version(1); exit(0); } -verbosity = 0; +while ((opt = getopt(argc, argv, "hv")) != -1) { + switch(opt) { + case 'h': + help(); break; + case 'v': + verbosity++; break; + default: + exit(1); + break; + } + } -foo = try_to_read_an_OBJ_file(argv[1], 0); -fprintf(stderr, "try to read '%s' -> %d\n", argv [1], foo); + +if (optind < argc) { + // fprintf(stderr, "ARG = %s\n", argv[optind]); + foo = try_to_read_an_OBJ_file(argv[optind], 0); + if (foo) { + fprintf(stderr, "Error number %d on '%s'\n", foo, argv[optind]); + exit(1); + } + } +else { + fprintf(stderr, "%s need a input filename\n", argv[0]); + exit(1); + } return 0; }