diff options
author | Markus Uhlin <markus@nifty-networks.net> | 2024-04-02 18:27:14 +0200 |
---|---|---|
committer | Markus Uhlin <markus@nifty-networks.net> | 2024-04-02 18:27:14 +0200 |
commit | 6486ebbd5c1ccd3c7734329f1f09c4510d851bf5 (patch) | |
tree | 603b2f9dbe48ec662aa266ee7acce43b2e7cddf2 /FICS | |
parent | b0c0dbb3c9a14c383d4243dbfb93d32c7a5e880e (diff) |
Reformatted ShowRankEntry()
Diffstat (limited to 'FICS')
-rw-r--r-- | FICS/ratings.c | 121 |
1 files changed, 68 insertions, 53 deletions
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 |