X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=backend.c;h=c73d6e7eff9b70bb985ad9d2080ff6ce12afa659;hb=407cd1126c6c24d890359f1fe1686f6d90c0ad61;hp=51f348e1da46af00d4e0cbb804dbed5551c09784;hpb=4b4ee0f5a685c7cca0c5f5b791f05ee157b4a219;p=xboard.git diff --git a/backend.c b/backend.c index 51f348e..c73d6e7 100644 --- a/backend.c +++ b/backend.c @@ -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);