aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-19 23:18:56 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-19 23:18:56 +0100
commitd1803976d56f185ea0f9ed80cf2dabeb160dab83 (patch)
treec7406c7403d6e1f503c0d3b6a940fe2d85bef2e0
parent7c1aa55d7dd10c1c66ac0805cec26a92e5ff4beb (diff)
Reformatted check_news() plus 'time_t' fixes
-rw-r--r--FICS/command.c144
1 files changed, 80 insertions, 64 deletions
diff --git a/FICS/command.c b/FICS/command.c
index 753ae9d..674c9f1 100644
--- a/FICS/command.c
+++ b/FICS/command.c
@@ -542,80 +542,96 @@ PUBLIC void rscan_news(FILE *fp, int p, int lc) {
}
}
-PRIVATE void check_news(int p, int admin)
+PRIVATE void
+check_news(int p, int admin)
{
- FILE *fp;
- char filename[MAX_FILENAME_SIZE];
- char junk[MAX_LINE_SIZE];
- char *junkp;
- int crtime;
- int lc = player_lastconnect(p);
- char count[10];
+ FILE *fp;
+ char count[10];
+ char filename[MAX_FILENAME_SIZE];
+ char junk[MAX_LINE_SIZE];
+ char *junkp;
+ long int lval;
+ time_t crtime;
+ time_t lc = player_lastconnect(p);
+
+ if (admin) {
+ sprintf(filename, "%s/newadminnews.index", news_dir);
+
+ if ((fp = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "Can't find admin news index.\n");
+ return;
+ }
- if (admin) {
+ if (num_anews == -1) {
+ num_anews = count_lines(fp);
+ fclose(fp);
+ fp = fopen(filename, "r");
+ }
- sprintf(filename, "%s/newadminnews.index", news_dir);
- fp = fopen(filename, "r");
- if (!fp) {
- fprintf(stderr, "Can't find admin news index.\n");
- return;
- }
+ fgets(junk, MAX_LINE_SIZE, fp);
+ sscanf(junk, "%ld %s", &lval, count);
+ crtime = lval;
- if (num_anews == -1) {
- num_anews = count_lines(fp);
- fclose(fp);
- fp = fopen(filename, "r");
- }
+ if ((crtime - lc) < 0) {
+ pprintf(p, "There are no new admin news items since "
+ "your last login.\n\n");
+ fclose(fp);
+ return;
+ } else {
+ pprintf(p, "Index of new admin news items:\n");
+ rscan_news(fp, p, lc);
- fgets(junk, MAX_LINE_SIZE, fp);
- sscanf(junk, "%d %s", &crtime, count);
- if ((crtime - lc) < 0) {
- pprintf(p, "There are no new admin news items since your last login.\n\n");
- fclose(fp);
- return;
- } else {
- pprintf(p, "Index of new admin news items:\n");
- rscan_news(fp, p, lc);
- junkp = junk;
- junkp = nextword(junkp);
- junkp = nextword(junkp);
- pprintf(p, "%3s (%s) %s", count, fix_time(strltime(&crtime)), junkp);
- pprintf(p, "(\"anews %d\" will display the most recent admin news file)\n", num_anews);
- }
+ junkp = junk;
+ junkp = nextword(junkp);
+ junkp = nextword(junkp);
- } else {
+ pprintf(p, "%3s (%s) %s", count,
+ fix_time(strltime(&crtime)), junkp);
+ pprintf(p, "(\"anews %d\" will display the most recent "
+ "admin news file)\n", num_anews);
+ }
+ } else {
+ sprintf(filename, "%s/newnews.index", news_dir);
- sprintf(filename, "%s/newnews.index", news_dir);
- fp = fopen(filename, "r");
- if (!fp) {
- fprintf(stderr, "Can't find news index.\n");
- return;
- }
+ if ((fp = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "Can't find news index.\n");
+ return;
+ }
- if (num_news == -1) {
- num_news = count_lines(fp);
- fclose(fp);
- fp = fopen(filename, "r");
- }
+ if (num_news == -1) {
+ num_news = count_lines(fp);
+ fclose(fp);
+ if ((fp = fopen(filename, "r")) == NULL) {
+ fprintf(stderr, "Can't find news index.\n");
+ return;
+ }
+ }
- fgets(junk, MAX_LINE_SIZE, fp);
- sscanf(junk, "%d %s", &crtime, count);
- if ((crtime - lc) < 0) {
- pprintf(p, "There are no new news items since your last login (%s).\n", strltime(&lc));
- fclose(fp);
- return;
- } else {
- pprintf(p, "Index of new news items:\n");
- rscan_news(fp, p, lc);
- junkp = junk;
- junkp = nextword(junkp);
- junkp = nextword(junkp);
- pprintf(p, "%3s (%s) %s", count, fix_time(strltime(&crtime)), junkp);
- pprintf(p, "(\"news %d\" will display the most recent admin news file)\n", num_news);
- }
- }
+ fgets(junk, MAX_LINE_SIZE, fp);
+ sscanf(junk, "%ld %s", &lval, count);
+ crtime = lval;
- fclose(fp);
+ if ((crtime - lc) < 0) {
+ pprintf(p, "There are no new news items since your "
+ "last login (%s).\n", strltime(&lc));
+ fclose(fp);
+ return;
+ } else {
+ pprintf(p, "Index of new news items:\n");
+ rscan_news(fp, p, lc);
+
+ junkp = junk;
+ junkp = nextword(junkp);
+ junkp = nextword(junkp);
+
+ pprintf(p, "%3s (%s) %s", count,
+ fix_time(strltime(&crtime)), junkp);
+ pprintf(p, "(\"news %d\" will display the most recent "
+ "admin news file)\n", num_news);
+ }
+ }
+
+ fclose(fp);
}
PRIVATE int