Print sensible window title during tourneys
[xboard.git] / backend.c
index 2ed15a3..93f79d3 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -1410,7 +1410,7 @@ MatchEvent(int mode)
 //         return;
 //     }
        abortMatch = FALSE;
-       appData.matchGames = appData.defaultMatchGames;
+       if(mode == 2) appData.matchGames = appData.defaultMatchGames;
        /* Set up machine vs. machine match */
        nextGame = 0;
        NextTourneyGame(-1, &dummy); // sets appData.matchGames if this is tourney, to make sure ReserveGame knows it
@@ -9553,6 +9553,35 @@ TwoMachinesEventIfReady P((void))
   TwoMachinesEvent();
 }
 
+char *
+MakeName(char *template)
+{
+    time_t clock;
+    struct tm *tm;
+    static char buf[MSG_SIZ];
+    char *p = buf;
+    int i;
+
+    clock = time((time_t *)NULL);
+    tm = localtime(&clock);
+
+    while(*p++ = *template++) if(p[-1] == '%') {
+       switch(*template++) {
+         case 0:   *p = 0; return buf;
+         case 'Y': i = tm->tm_year+1900; break;
+         case 'y': i = tm->tm_year-100; break;
+         case 'M': i = tm->tm_mon+1; break;
+         case 'd': i = tm->tm_mday; break;
+         case 'h': i = tm->tm_hour; break;
+         case 'm': i = tm->tm_min; break;
+         case 's': i = tm->tm_sec; break;
+         default:  i = 0;
+       }
+       snprintf(p-1, MSG_SIZ-10 - (p - buf), "%02d", i); p += strlen(p);
+    }
+    return buf;
+}
+
 int
 CountPlayers(char *p)
 {
@@ -9596,17 +9625,21 @@ CreateTourney(char *name)
 {
        FILE *f;
        if(name[0] == NULLCHAR) {
-           DisplayError(_("You must supply a tournament file,\nfor storing the tourney progress"), 0);
+           if(appData.participants[0])
+               DisplayError(_("You must supply a tournament file,\nfor storing the tourney progress"), 0);
            return 0;
        }
-       f = fopen(appData.tourneyFile, "r");
+       f = fopen(name, "r");
        if(f) { // file exists
+           ASSIGN(appData.tourneyFile, name);
            ParseArgsFromFile(f); // parse it
        } else {
-           if(CountPlayers(appData.participants) < appData.tourneyType + (!appData.tourneyType) + 1) {
+           if(!appData.participants[0]) return 0; // ignore tourney file if non-existing & no participants
+           if(CountPlayers(appData.participants) < (appData.tourneyType>0 ? appData.tourneyType+1 : 2)) {
                DisplayError(_("Not enough participants"), 0);
                return 0;
            }
+           ASSIGN(appData.tourneyFile, name);
            if((f = WriteTourneyFile("")) == NULL) return 0;
        }
        fclose(f);
@@ -12658,6 +12691,12 @@ DisplayTwoMachinesTitle()
 {
     char buf[MSG_SIZ];
     if (appData.matchGames > 0) {
+        if(appData.tourneyFile[0]) {
+         snprintf(buf, MSG_SIZ, "%s vs. %s (%d/%d%s)",
+                  gameInfo.white, gameInfo.black,
+                  nextGame+1, appData.matchGames+1,
+                  appData.tourneyType>0 ? "gt" : appData.tourneyType<0 ? "sw" : "rr");
+        } else 
         if (first.twoMachinesColor[0] == 'w') {
          snprintf(buf, MSG_SIZ, "%s vs. %s (%d-%d-%d)",
                   gameInfo.white, gameInfo.black,