aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/playerdb.c
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2024-08-13 00:24:09 +0200
committerMarkus Uhlin <markus@nifty-networks.net>2024-08-13 00:24:09 +0200
commit38133f9624d11b5435c3f54bf613196e38ca57dd (patch)
tree93eda881e6e6abaefe702aa6ad4153080443841c /FICS/playerdb.c
parentda2e07963b55e0c205f18e9cc346904cb14c3114 (diff)
Changed ReadV1PlayerFmt() and added and made use of add_to_list()
Diffstat (limited to 'FICS/playerdb.c')
-rw-r--r--FICS/playerdb.c54
1 files changed, 31 insertions, 23 deletions
diff --git a/FICS/playerdb.c b/FICS/playerdb.c
index 8e76a8f..589bf46 100644
--- a/FICS/playerdb.c
+++ b/FICS/playerdb.c
@@ -356,6 +356,22 @@ player_remove(int p)
return 0;
}
+PRIVATE int
+add_to_list(FILE *fp, enum ListWhich lw, int *size, int p)
+{
+ char buf[MAX_STRING_LENGTH] = { '\0' };
+
+ _Static_assert(1023 < ARRAY_SIZE(buf), "Buffer too small");
+
+#define SCAN_STR "%1023s"
+
+ if (*size <= 0)
+ return -2;
+ while ((*size)-- > 0 && fscanf(fp, SCAN_STR, buf) == 1)
+ list_add(p, lw, buf);
+ return (*size <= 0 ? 0 : -1);
+}
+
PRIVATE void
ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version)
{
@@ -585,29 +601,21 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version)
}
}
- _Static_assert(1023 < ARRAY_SIZE(tmp2), "Array too small");
-
-#define SCAN_STR "%1023s"
-
- while (size_cens--) {
- fscanf(fp, SCAN_STR, tmp2);
- list_add(p, L_CENSOR, tmp2);
- }
- while (size_not--) {
- fscanf(fp, SCAN_STR, tmp2);
- list_add(p, L_NOTIFY, tmp2);
- }
- while (size_noplay--) {
- fscanf(fp, SCAN_STR, tmp2);
- list_add(p, L_NOPLAY, tmp2);
- }
- while (size_gnot--) {
- fscanf(fp, SCAN_STR, tmp2);
- list_add(p, L_GNOTIFY, tmp2);
- }
- while (size_chan--) {
- fscanf(fp, SCAN_STR, tmp2);
- list_add(p, L_CHANNEL, tmp2);
+ if (add_to_list(fp, L_CENSOR, &size_cens, p) == -1) {
+ warnx("%s: add to list error (L_CENSOR): player: %s",
+ __func__, parray[p].name);
+ } else if (add_to_list(fp, L_NOTIFY, &size_not, p) == -1) {
+ warnx("%s: add to list error (L_NOTIFY): player: %s",
+ __func__, parray[p].name);
+ } else if (add_to_list(fp, L_NOPLAY, &size_noplay, p) == -1) {
+ warnx("%s: add to list error (L_NOPLAY): player: %s",
+ __func__, parray[p].name);
+ } else if (add_to_list(fp, L_GNOTIFY, &size_gnot, p) == -1) {
+ warnx("%s: add to list error (L_GNOTIFY): player: %s",
+ __func__, parray[p].name);
+ } else if (add_to_list(fp, L_CHANNEL, &size_chan, p) == -1) {
+ warnx("%s: add to list error (L_CHANNEL): player: %s",
+ __func__, parray[p].name);
}
}