summaryrefslogtreecommitdiffstats
path: root/util/parse_news.c
blob: b1f0ad252587d02de408189cac9ca7c0ba611815 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* $Id: parse_news.c,v 1.5 2003/07/20 00:55:34 in2 Exp $ */
#include "bbs.h"

#define NEWSDIRECT  BBSHOME "/boards/n/newspaper"
#define MOVIEDIRECT BBSHOME "/etc/NEWS"

int main(int argc, char **argv)
{
    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.");
            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;
}