From d13e112080cbbd77d845c1b75cf6642953c51be2 Mon Sep 17 00:00:00 2001 From: Laurent Mazet Date: Fri, 28 Jun 2024 07:45:10 +0200 Subject: [PATCH] add list for boards and languages --- constant.c | 7 +++++++ scrabble.c | 14 ++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/constant.c b/constant.c index 0e0b000..8ab8c1c 100644 --- a/constant.c +++ b/constant.c @@ -1,3 +1,4 @@ +#include #include #include @@ -22,6 +23,9 @@ board_t *getboard (char *name) pt = &_board_15x15_7; } else if (strcmp (name, "22x22-7") == 0) { pt = &_board_22x22_7; + } else if (strcmp (name, "list") == 0) { + printf ("board: 8x8-7 8x15-7 15x15-7 22x22-7\n"); + pt = (board_t *)(-1); } return pt; @@ -76,6 +80,9 @@ bag_t *getbag (char *lang) pt->tiles = _tiles_nl; pt->nbletters = NB_LETTERVALUES_NL; pt->lettervalues = _lettervalues_nl; + } else if (strcmp (lang, "list") == 0) { + printf ("language: de en es fr it nl\n"); + pt = (bag_t *)(-1); } return pt; diff --git a/scrabble.c b/scrabble.c index fecb450..10d2dca 100644 --- a/scrabble.c +++ b/scrabble.c @@ -55,11 +55,11 @@ int usage (int ret) { FILE *fd = ret ? stderr : stdout; fprintf (fd, "usage: %s [-b board] [-c] [-d dict] [-h] [-l lang] [-n nb] [-r file] [-s pattern] [-v level]\n", progname); - fprintf (fd, " -b: board (%s)\n", boardname); + fprintf (fd, " -b: board (%s|list)\n", boardname); fprintf (fd, " -c: cache dictionary\n"); fprintf (fd, " -d: dictionary (%s)\n", (dict) ? dict : "none"); fprintf (fd, " -h: help message\n"); - fprintf (fd, " -l: language (%s)\n", language); + fprintf (fd, " -l: language (%s|list)\n", language); fprintf (fd, " -n: number of players (%d)\n", nbplayers); fprintf (fd, " -r: restore game (%s)\n", (file) ? file : "none"); fprintf (fd, " -s: save pattern (%s)\n", (pattern) ? pattern : "none"); @@ -158,12 +158,16 @@ int main (int argc, char *argv[]) } board_t *board = getboard (boardname); - if (!board) { + if (board == (board_t *)(-1)) { + return 0; + } else if (!board) { VERBOSE (ERROR, fprintf (stderr, "board not found\n")); return 1; } bag_t *bag = getbag (language); - if (!bag) { + if (bag == (bag_t *)(-1)) { + return 0; + } else if (!bag) { VERBOSE (ERROR, fprintf (stderr, "language not found\n")); return 1; } @@ -412,11 +416,13 @@ int main (int argc, char *argv[]) /* test: scrabble.exe -b 2>&1 | grep 'no board' */ /* test: scrabble.exe -b 6x6-7i 2>&1 | grep 'not found' */ +/* test: scrabble.exe -b list | grep 'board:' */ /* test: scrabble.exe -d 2>&1 | grep 'no dictionary' */ /* test: scrabble.exe -d none.dict 2>&1 | grep 'not found' */ /* 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 -l list | grep 'language:' */ /* test: scrabble.exe -n 2>&1 | grep 'no number' */ /* test: scrabble.exe -n 5 2>&1 | grep 'incorrect' */ /* test: scrabble.exe -r 2>&1 | grep 'missing file name' */ -- 2.30.2