summaryrefslogtreecommitdiffstats
path: root/util/parse_news.c
diff options
context:
space:
mode:
authorin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-07 23:13:44 +0800
committerin2 <in2@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2002-03-07 23:13:44 +0800
commitae31e19f92e717919ac8e3db9039eb38d2b89aae (patch)
treec70164d6a1852344f44b04a653ae2815043512af /util/parse_news.c
downloadpttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.gz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.bz2
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.lz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.xz
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.tar.zst
pttbbs-ae31e19f92e717919ac8e3db9039eb38d2b89aae.zip
Initial revision
git-svn-id: http://opensvn.csie.org/pttbbs/pttbbs/trunk/pttbbs@1 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'util/parse_news.c')
-rw-r--r--util/parse_news.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/util/parse_news.c b/util/parse_news.c
new file mode 100644
index 00000000..bebed3f4
--- /dev/null
+++ b/util/parse_news.c
@@ -0,0 +1,78 @@
+/* $Id: parse_news.c,v 1.1 2002/03/07 15:13:46 in2 Exp $ */
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include "config.h"
+#include "pttstruct.h"
+#include "util.h"
+
+#define NEWSDIRECT BBSHOME "/boards/newspaper"
+#define MOVIEDIRECT BBSHOME "/etc/NEWS"
+
+int main() {
+ int fd;
+ fileheader_t fh, news;
+ struct stat st;
+ register int numfiles, n;
+ FILE *fp = NULL;
+ char buf[200];
+
+ if (stat(NEWSDIRECT "/.DIR", &st) < 0)
+ return 0;
+
+ system("rm -f " MOVIEDIRECT "/*");
+ system("rm -f " MOVIEDIRECT "/.DIR");
+
+ numfiles = st.st_size / sizeof(fileheader_t);
+ n = 0;
+ if ((fd = open(NEWSDIRECT "/.DIR", O_RDONLY)) > 0)
+ {
+ lseek(fd, st.st_size - sizeof(fileheader_t), SEEK_SET);
+ while (numfiles-- && n < 100)
+ {
+ read(fd, &fh, sizeof(fileheader_t));
+ if (!strcmp(fh.owner, "CNA-News."))
+ {
+ if (!strstr(fh.title, "活動預告") && !strstr(fh.title, "中央氣象局")
+ && !strstr(fh.title, "歷史上的今天") && !strstr(fh.title, "頭條新聞標題")
+ && !strstr(fh.title, "Summary") && !strstr(fh.title, "全球氣象一覽")
+ && !strstr(fh.title, "校正公電"))
+ {
+ if (!(n % 10))
+ {
+ if (n)
+ {
+ fclose(fp);
+ append_record(MOVIEDIRECT "/.DIR", &news, sizeof(news));
+ }
+ strcpy(buf, MOVIEDIRECT);
+ stampfile(buf, &news);
+ sprintf(news.title, "中央社即時新聞 %s", fh.date);
+ strcpy(news.owner, "CNA-News.");
+ news.savemode = 0;
+ if (!(fp = fopen(buf, "w")))
+ return (0);
+ fprintf(fp, " ───────── 中央社即時新聞 (%s)──────────\n",
+ fh.date);
+ }
+ fprintf(fp, " ─────◇ [1;3%dm%s %.*s\n",
+ (n % 6 + 4) % 7 + 1, fh.title,
+ (int)(46 - strlen(fh.title)),
+ "───────────────────");
+ n++;
+ printf("[%d]\n", n);
+
+ }
+ }
+ lseek(fd, -(off_t) 2 * sizeof(fileheader_t), SEEK_CUR);
+ }
+ close(fd);
+ fclose(fp);
+ append_record(MOVIEDIRECT "/.DIR", &news, sizeof(news));
+ }
+ return 0;
+}