From fba725092a4b51783e73075c60a15c544e82fb80 Mon Sep 17 00:00:00 2001 From: Hampus Date: Thu, 7 Jan 2021 22:11:34 +0100 Subject: refactor: improve width & height argument parsing --- mazerator.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/mazerator.c b/mazerator.c index 6c24ec0..9b2e434 100644 --- a/mazerator.c +++ b/mazerator.c @@ -123,20 +123,15 @@ int main(int argc, char *argv[]) while((c = getopt_long(argc, argv, "w:h:W:s:", options, NULL)) != -1) { switch(c){ case 'w': - // Set Width - if(is_number(optarg) && atoi(optarg) >= 1 && atoi(optarg) <= 255) - maze_width = atoi(optarg); - else{ - printf("Invalid option argument for -w/--width!\n"); - exit(1); - } - break; case 'h': - // Set heigth + // Set heigth or width if(is_number(optarg) && atoi(optarg) >= 1 && atoi(optarg) <= 255) - maze_heigth = atoi(optarg); + switch(c){ + case 'h': maze_heigth = atoi(optarg); + case 'w': maze_width = atoi(optarg); + } else{ - printf("Invalid option argument for -h/--heigth!\n"); + printf("Invalid option argument for -%c!\n", c); exit(1); } break; -- cgit v1.2.3-18-g5258