add list for boards and languages
authorLaurent Mazet <mazet@softndesign.org>
Fri, 28 Jun 2024 05:45:10 +0000 (07:45 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 28 Jun 2024 05:45:10 +0000 (07:45 +0200)
constant.c
scrabble.c

index 0e0b000fa537bb7e892fbdfdc44de3f75d768536..8ab8c1c577efadd8a1cd154238c08581b29a5130 100644 (file)
@@ -1,3 +1,4 @@
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 
@@ -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;
index fecb450a779ec539d4a5e9b8b06bbc99d27cfba2..10d2dca52d4a577282bc766b7a12ffd549db89e2 100644 (file)
@@ -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' */