src/main.c

changeset 50
41017d0a72c5
parent 47
d726e4b46c33
child 51
84f2e380a434
     1.1 --- a/src/main.c	Wed Jun 11 16:54:20 2014 +0200
     1.2 +++ b/src/main.c	Mon Jun 16 13:45:31 2014 +0200
     1.3 @@ -41,7 +41,7 @@
     1.4      uint8_t timeunit = 60;
     1.5      size_t len;
     1.6      
     1.7 -    for (int opt ; (opt = getopt(argc, argv, "a:bc:hp:rst:")) != -1 ;) {
     1.8 +    for (int opt ; (opt = getopt(argc, argv, "a:bc:hp:rsS:t:")) != -1 ;) {
     1.9          switch (opt) {
    1.10          case 'c':
    1.11              settings->continuepgn = optarg;
    1.12 @@ -55,6 +55,9 @@
    1.13          case 's':
    1.14              settings->singlemachine = 1;
    1.15              break;
    1.16 +        case 'S':
    1.17 +            settings->analyzepgn = optarg;
    1.18 +            break;
    1.19          case 't':
    1.20          case 'a':
    1.21              len = strlen(optarg);
    1.22 @@ -103,6 +106,24 @@
    1.23          return 1;
    1.24      }
    1.25      
    1.26 +        
    1.27 +    if (settings->continuepgn) {
    1.28 +        if (settings->serverhost) {
    1.29 +            fprintf(stderr, "Can't continue a game when joining a server.\n");
    1.30 +            return 1;
    1.31 +        }
    1.32 +        if (settings->analyzepgn) {
    1.33 +            fprintf(stderr, "The options -c and -S are mutually exclusive\n");
    1.34 +            return 1;
    1.35 +        }
    1.36 +        // TODO: implement
    1.37 +        if (!settings->singlemachine) {
    1.38 +            fprintf(stderr, "Game continuation currently not supported for "
    1.39 +                "network games.\n");
    1.40 +            return 1;
    1.41 +        }
    1.42 +    }
    1.43 +    
    1.44      return 0;
    1.45  }
    1.46  
    1.47 @@ -111,7 +132,6 @@
    1.48      memset(&settings, 0, sizeof(Settings));
    1.49      settings.gameinfo.servercolor = WHITE;
    1.50      settings.port = "27015";
    1.51 -    settings.continuepgn = NULL;
    1.52      return settings;
    1.53  }
    1.54  
    1.55 @@ -154,17 +174,16 @@
    1.56  "Usage: terminal-chess [OPTION]... [HOST]\n"
    1.57  "Starts/joins a network chess game\n"
    1.58  "\nGeneral options\n"
    1.59 +"  -c <PGN file> Continue the specified game\n"
    1.60  "  -h            This help page\n"
    1.61  "  -p            TCP port to use (default: 27015)\n"
    1.62 +// TODO: implement and activate feature
    1.63 +//"  -S <PGN file> Compute and print statistics for the specified game\n"
    1.64  "\nServer options\n"
    1.65  "  -a <time>     Specifies the time to add after each move\n"
    1.66  "  -b            Server plays black pieces (default: white)\n"
    1.67 -// TODO: implement and activate feature
    1.68 -//"  -c <PGN file> Continue the specified game\n"
    1.69  "  -r            Distribute color randomly\n"
    1.70  "  -s            Single machine mode\n"
    1.71 -// TODO: implement and activate feature
    1.72 -//"  -S <PGN file> Compute and print statistics for the specified game\n"
    1.73  "  -t <time>     Specifies time limit (default: no limit)\n"
    1.74  "\nNotes\n"
    1.75  "The time unit for -a is seconds and for -t minutes by default. To "
    1.76 @@ -192,6 +211,9 @@
    1.77      if (settings.singlemachine) {
    1.78          game_start_singlemachine(&settings);
    1.79          exitcode = EXIT_SUCCESS;
    1.80 +    } else if (settings.analyzepgn) {
    1.81 +        printw("Not implemented yet.\n");
    1.82 +        exitcode = EXIT_SUCCESS;
    1.83      } else {
    1.84          exitcode = is_server(&settings) ?
    1.85              server_run(&settings) : client_run(&settings);
    1.86 @@ -199,6 +221,7 @@
    1.87      
    1.88      mvaddstr(getmaxy(stdscr)-1, 0,
    1.89          "Game has ended. Press any key to leave...");
    1.90 +    clrtoeol();
    1.91      refresh();
    1.92      cbreak();
    1.93      flushinp();

mercurial