From: Laurent Mazet Date: Sun, 9 Jun 2024 17:10:02 +0000 (+0200) Subject: new parameter: number of players X-Git-Tag: v1.0~32 X-Git-Url: https://secure.softndesign.org/git/?a=commitdiff_plain;h=cbfaadc8e2c5c49bb5efedafb6609916ac4c541d;p=scrabble.git new parameter: number of players --- diff --git a/scrabble.c b/scrabble.c index a130392..e62c281 100644 --- a/scrabble.c +++ b/scrabble.c @@ -25,6 +25,7 @@ char *version = "0.1"; char *boardname = "15x15-7"; char *language = "fr"; +int nbplayers = 2; int xoffset = 4; int yoffset = 3; @@ -47,10 +48,11 @@ char *help = int usage (int ret) { FILE *fd = ret ? stderr : stdout; - fprintf (fd, "usage: %s [-b board] [-h] [-l lang] [-v level]\n", progname); + fprintf (fd, "usage: %s [-b board] [-h] [-l lang] [-n nb] [-v level]\n", progname); fprintf (fd, " -b: board (%s)\n", boardname); fprintf (fd, " -h: help message\n"); fprintf (fd, " -l: language (%s)\n", language); + fprintf (fd, " -n: number of players (%d)\n", nbplayers); fprintf (fd, " -v: verbose level (%d)\n", verbose); fprintf (fd, "%s version %s\n", progname, version); @@ -97,6 +99,14 @@ int main (int argc, char *argv[]) return usage (1); } break; + case 'n': + arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; + if (arg == NULL) { + VERBOSE (ERROR, fprintf (stderr, "%s: no number of players\n", progname)); + return usage (1); + } + nbplayers = atoi (arg); + break; case 'v': arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL; if (arg == NULL) { @@ -121,6 +131,10 @@ int main (int argc, char *argv[]) VERBOSE (ERROR, fprintf (stderr, "language not found\n")); return 1; } + if ((nbplayers < 1) || (nbplayers > 4)) { + VERBOSE (ERROR, fprintf (stderr, "incorrect number of player [1, 4] (%d)\n", nbplayers)); + return 1; + } srand (time (NULL)); @@ -274,6 +288,8 @@ int main (int argc, char *argv[]) /* test: scrabble.exe -h | grep usage */ /* test: scrabble.exe -l 2>&1 | grep 'no language' */ /* test: scrabble.exe -l aa 2>&1 | grep 'not found' */ +/* test: scrabble.exe -n 2>&1 | grep 'no number' */ +/* test: scrabble.exe -n 5 2>&1 | grep 'incorrect' */ /* test: scrabble.exe -v 2>&1 | grep missing */ /* test: scrabble.exe _ 2>&1 | grep invalid */ /* test: echo vlvjxdvjvjvcivkkvkvctJcLccLLLLLLLLJJJJJJJJq | scrabble.exe */