From 968d85f3179ebf1444231f1f70b7c0f93db7046e Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Tue, 23 Apr 2024 19:53:15 +0200 Subject: Revised FindHistory() --- FICS/obsproc.c | 57 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 26 deletions(-) (limited to 'FICS/obsproc.c') diff --git a/FICS/obsproc.c b/FICS/obsproc.c index cdd2a26..0ed9cac 100644 --- a/FICS/obsproc.c +++ b/FICS/obsproc.c @@ -748,34 +748,39 @@ PRIVATE void ExamineAdjourned(int p, int p1, int p2) return; } -PRIVATE char *FindHistory(int p, int p1, int game) +PRIVATE char * +FindHistory(int p, int p1, int game) { - FILE *fpHist; - static char fileName[MAX_FILENAME_SIZE]; - int index; - long when; - - sprintf(fileName, "%s/player_data/%c/%s.%s", stats_dir, - parray[p1].login[0], parray[p1].login, STATS_GAMES); - fpHist = fopen(fileName, "r"); - if (fpHist == NULL) { - pprintf(p, "No games in history for %s.\n", parray[p1].name); - return(NULL); - } - do { - fscanf(fpHist, "%d %*c %*d %*c %*d %*s %*s %*d %*d %*d %*d %*s %*s %ld", - &index, &when); - } while (!feof(fpHist) && index != game); - - if (feof(fpHist)) { - pprintf(p, "There is no history game %d for %s.\n", game, parray[p1].name); - fclose(fpHist); - return(NULL); - } - fclose(fpHist); + FILE *fpHist; + int index; + long int when; + static char fileName[MAX_FILENAME_SIZE]; + + msnprintf(fileName, sizeof fileName, "%s/player_data/%c/%s.%s", + stats_dir, parray[p1].login[0], parray[p1].login, STATS_GAMES); + + if ((fpHist = fopen(fileName, "r")) == NULL) { + pprintf(p, "No games in history for %s.\n", parray[p1].name); + return NULL; + } - sprintf(fileName, "%s/%ld/%ld", hist_dir, when % 100, when); - return(fileName); + do { + fscanf(fpHist, "%d %*c %*d %*c %*d %*s %*s %*d %*d %*d %*d " + "%*s %*s %ld", &index, &when); + } while (!feof(fpHist) && index != game); + + if (feof(fpHist)) { + pprintf(p, "There is no history game %d for %s.\n", game, + parray[p1].name); + fclose(fpHist); + return NULL; + } + + fclose(fpHist); + + msnprintf(fileName, sizeof fileName, "%s/%ld/%ld", hist_dir, + (when % 100), when); + return (&fileName[0]); } PRIVATE char * -- cgit v1.2.3