From 6486ebbd5c1ccd3c7734329f1f09c4510d851bf5 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Tue, 2 Apr 2024 18:27:14 +0200 Subject: Reformatted ShowRankEntry() --- FICS/ratings.c | 121 ++++++++++++++++++++++++++++++++------------------------- 1 file changed, 68 insertions(+), 53 deletions(-) (limited to 'FICS') diff --git a/FICS/ratings.c b/FICS/ratings.c index 143793f..5ea446f 100644 --- a/FICS/ratings.c +++ b/FICS/ratings.c @@ -1105,61 +1105,76 @@ PRIVATE void PositionFilePtr(FILE * fp, int count, int *last, } } -PRIVATE int ShowRankEntry(int p, FILE * fp, int count, int comp, - char *target, int *lastRating, int *nTied) +PRIVATE int +ShowRankEntry(int p, FILE *fp, int count, int comp, char *target, + int *lastRating, int *nTied) { - char newLine[MAX_RANK_LINE]; - char login[MAX_LOGIN_NAME]; - int rating, findable, nGames, is_comp; + char login[MAX_LOGIN_NAME] = { '\0' }; + char newLine[MAX_RANK_LINE] = { '\0' }; + int rating, findable, nGames, is_comp; + + findable = (count > 0 && !feof(fp)); + + if (findable) { + do { + fgets(newLine, MAX_RANK_LINE - 1, fp); + + if (feof(fp)) { + findable = 0; + } else if (newLine[0] != '\0') { + sscanf(newLine, "%s %d %d %d", login, &rating, + &nGames, &is_comp); + } else { + login[0] = '\0'; + } + } while (!CountRankLine(comp, login, nGames, is_comp) && + findable && + strcasecmp(login, target)); + } - findable = (count > 0) && !feof(fp); - if (findable) { - do { - fgets(newLine, MAX_RANK_LINE - 1, fp); - if (feof(fp)) - findable = 0; - else if (newLine[0] != '\0') - sscanf(newLine, "%s %d %d %d", - login, &rating, &nGames, &is_comp); - else - login[0] = '\0'; - } while (!CountRankLine(comp, login, nGames, is_comp) && findable - && strcasecmp(login, target)); - } - if (findable) { - if (!strcasecmp(login, target) - && !CountRankLine(comp, login, nGames, is_comp)) { - pprintf_highlight(p, "---- %-12.12s %4s", login, ratstr(rating)); - pprintf(p, " "); - return 0; - } else if (*lastRating == rating && *nTied < 1) { - pprintf(p, " "); - if (!strcasecmp(login, target)) - pprintf_highlight(p, "%-12.12s %4s", login, ratstr(rating)); - else - pprintf(p, "%-12.12s %4s", login, ratstr(rating)); - pprintf(p, " "); - return 1; - } else { - if (*nTied >= 1) { - if (*lastRating == rating) - count -= *nTied; - *nTied = -1; - } - if (!strcasecmp(login, target)) - pprintf_highlight(p, "%4d. %-12.12s %4s", - count, login, ratstr(rating)); - else - pprintf(p, "%4d. %-12.12s %4s", - count, login, ratstr(rating)); - pprintf(p, " "); - *lastRating = rating; - return 1; - } - } else { - pprintf(p, "%25s", ""); - return 1; - } + if (findable) { + if (!strcasecmp(login, target) && !CountRankLine(comp, login, + nGames, is_comp)) { + pprintf_highlight(p, "---- %-12.12s %4s", login, + ratstr(rating)); + pprintf(p, " "); + return 0; + } else if (*lastRating == rating && *nTied < 1) { + pprintf(p, " "); + + if (!strcasecmp(login, target)) { + pprintf_highlight(p, "%-12.12s %4s", login, + ratstr(rating)); + } else { + pprintf(p, "%-12.12s %4s", login, + ratstr(rating)); + } + + pprintf(p, " "); + return 1; + } else { + if (*nTied >= 1) { + if (*lastRating == rating) + count -= *nTied; + *nTied = -1; + } + + if (!strcasecmp(login, target)) { + pprintf_highlight(p, "%4d. %-12.12s %4s", count, + login, ratstr(rating)); + } else { + pprintf(p, "%4d. %-12.12s %4s", count, login, + ratstr(rating)); + } + + pprintf(p, " "); + *lastRating = rating; + return 1; + } + } else { + pprintf(p, "%25s", ""); + return 1; + } } PRIVATE int -- cgit v1.2.3