aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-13 23:42:52 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-13 23:42:52 +0100
commit66d2a91451739d81a59549a6fc7932be04b4b93f (patch)
tree310c30934e931ed01beb9cb125a7b253a3aa2f0e /FICS
parent25dfa4f1c56a19edc56d6b96e6d73d0619e3b335 (diff)
Revamped GetPlayerInfo()
Diffstat (limited to 'FICS')
-rw-r--r--FICS/makerank.c143
1 files changed, 86 insertions, 57 deletions
diff --git a/FICS/makerank.c b/FICS/makerank.c
index dd936fb..dc6ba7f 100644
--- a/FICS/makerank.c
+++ b/FICS/makerank.c
@@ -25,64 +25,93 @@ typedef struct _Entry {
ENTRY **list;
ENTRY **sortme;
-int GetPlayerInfo(char *fileName, ENTRY *e)
+static int
+GetPlayerInfo(char *fileName, ENTRY *e)
{
- FILE *fp;
- char line[100];
- char field[20];
- char NameWithCase[30];
- int i, done = 0;
-
- e->computer = 0;
- for (i = 0; i < 4; i++) {
- e->r[i].num = 0;
- e->r[i].rating = 0;
- }
-
- fp = fopen(fileName, "r");
- fgets(line, 99, fp);
- if (feof(fp))
- return(0);
- if (!strcmp(line, "v 1\n")) {
- fgets(line, 99, fp);
- sscanf(line, "%s", e->name);
- fgets(line, 99, fp);
- fgets(line, 99, fp);
- fgets(line, 99, fp);
- if (fscanf(fp, "%u %*u %*u %*u %u %*u %*u %*u %*u %u %*u %*u %*u %u %*u %*u %*u %*u %u %*u %*u %*u %u %*u %*u %*u %*u %u %*u %*u %*u %u %*u %*u %*u %*u", &(e->r[0].num), &(e->r[0].rating), &(e->r[1].num), &(e->r[1].rating), &(e->r[2].num), &(e->r[2].rating), &(e->r[3].num), &(e->r[3].rating)) != 8)
- fprintf(stderr, "OOPS: couldn't parse player file %s.\n", fileName);
- } else do {
- sscanf(line, "%s", field);
- if (!strcmp(field, "Name:")) {
- sscanf(line, "%*s %s", NameWithCase);
- if (strcasecmp(e->name, NameWithCase))
- printf("TROUBLE: %s's handle is listed as %s.\n",
- e->name, NameWithCase);
- else
- strcpy(e->name, NameWithCase);
- } else if (!strcmp(field, "S_NUM:")) {
- sscanf(line, "%*s %d", &(e->r[0].num));
- } else if (!strcmp(field, "B_NUM:")) {
- sscanf(line, "%*s %d", &(e->r[1].num));
- } else if (!strcmp(field, "W_NUM:")) {
- sscanf(line, "%*s %d", &(e->r[2].num));
- } else if (!strcmp(field, "L_NUM:")) {
- sscanf(line, "%*s %d", &(e->r[3].num));
- } else if (!strcmp(field, "S_RATING:")) {
- sscanf(line, "%*s %d", &(e->r[0].rating));
- } else if (!strcmp(field, "B_RATING:")) {
- sscanf(line, "%*s %d", &(e->r[1].rating));
- } else if (!strcmp(field, "W_RATING:")) {
- sscanf(line, "%*s %d", &(e->r[2].rating));
- } else if (!strcmp(field, "L_RATING:")) {
- sscanf(line, "%*s %d", &(e->r[3].rating));
- } else if (!strcmp(field, "Network:")) {
- done = 1;
- }
- fgets(line, 99, fp);
- } while (!done && !feof(fp));
- fclose(fp);
- return (1);
+ FILE *fp;
+ char NameWithCase[30];
+ char field[20];
+ char line[100];
+ int i, done = 0;
+
+ e->computer = 0;
+
+ for (i = 0; i < 4; i++) {
+ e->r[i].num = 0;
+ e->r[i].rating = 0;
+ }
+
+ if ((fp = fopen(fileName, "r")) == NULL)
+ return 0;
+
+ fgets(line, 99, fp);
+
+ if (feof(fp))
+ return 0;
+
+ if (!strcmp(line, "v 1\n")) {
+ fgets(line, 99, fp);
+
+ sscanf(line, "%s", e->name);
+
+ fgets(line, 99, fp);
+ fgets(line, 99, fp);
+ fgets(line, 99, fp);
+
+ if (fscanf(fp, "%u %*u %*u %*u %u %*u %*u %*u %*u %u %*u %*u "
+ "%*u %u %*u %*u %*u %*u %u %*u %*u %*u %u %*u %*u %*u %*u "
+ "%u %*u %*u %*u %u %*u %*u %*u %*u",
+ &(e->r[0].num),
+ &(e->r[0].rating),
+ &(e->r[1].num),
+ &(e->r[1].rating),
+ &(e->r[2].num),
+ &(e->r[2].rating),
+ &(e->r[3].num),
+ &(e->r[3].rating)) != 8) {
+ fprintf(stderr, "OOPS: couldn't parse player file %s."
+ "\n", fileName);
+ }
+ } else {
+ do {
+ sscanf(line, "%s", field);
+
+ if (!strcmp(field, "Name:")) {
+ sscanf(line, "%*s %s", NameWithCase);
+
+ if (strcasecmp(e->name, NameWithCase)) {
+ printf("TROUBLE: %s's handle is "
+ "listed as %s.\n", e->name,
+ NameWithCase);
+ } else
+ strcpy(e->name, NameWithCase);
+ } else if (!strcmp(field, "S_NUM:")) {
+ sscanf(line, "%*s %d", &(e->r[0].num));
+ } else if (!strcmp(field, "B_NUM:")) {
+ sscanf(line, "%*s %d", &(e->r[1].num));
+ } else if (!strcmp(field, "W_NUM:")) {
+ sscanf(line, "%*s %d", &(e->r[2].num));
+ } else if (!strcmp(field, "L_NUM:")) {
+ sscanf(line, "%*s %d", &(e->r[3].num));
+ } else if (!strcmp(field, "S_RATING:")) {
+ sscanf(line, "%*s %d", &(e->r[0].rating));
+ } else if (!strcmp(field, "B_RATING:")) {
+ sscanf(line, "%*s %d", &(e->r[1].rating));
+ } else if (!strcmp(field, "W_RATING:")) {
+ sscanf(line, "%*s %d", &(e->r[2].rating));
+ } else if (!strcmp(field, "L_RATING:")) {
+ sscanf(line, "%*s %d", &(e->r[3].rating));
+ } else if (!strcmp(field, "Network:")) {
+ done = 1;
+ }
+
+ fgets(line, 99, fp);
+
+ } while (!done && !feof(fp));
+ }
+
+ fclose(fp);
+ return 1;
}
static int