summaryrefslogtreecommitdiffstats
path: root/pttbbs/util/post.c
blob: c3af5269cc487b063b42029a95b07cab3eb82e71 (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
/* $Id$ */
#include "bbs.h"

void keeplog(FILE *fin, char *fpath, char *board, char *title, char *owner) {
    fileheader_t fhdr;
    char genbuf[256], buf[512];
    FILE *fout;
    int bid;
    
    sprintf(genbuf, BBSHOME "/boards/%c/%s", board[0], board);
    stampfile(genbuf, &fhdr);
    
    if(!(fout = fopen(genbuf, "w"))) {
    perror(genbuf);
    return;
    }
    
    while(fgets(buf, 512, fin))
    fputs(buf, fout);
    
    fclose(fin);
    fclose(fout);
    
    strncpy(fhdr.title, title, sizeof(fhdr.title) - 1);
    fhdr.title[sizeof(fhdr.title) - 1] = '\0';
    
    strcpy(fhdr.owner, owner);
    sprintf(genbuf, BBSHOME "/boards/%c/%s/.DIR", board[0], board);
    append_record(genbuf, &fhdr, sizeof(fhdr));
    /* XXX: bid of cache.c's getbnum starts from 1 */
    if((bid = getbnum(board)) > 0)
    touchbtotal(bid);

}

int main(int argc, char **argv)
{
    FILE *fp;

    attach_SHM();
    resolve_boards();
    if(argc != 5) {
    printf("usage: %s <board name> <title> <owner> <file>\n", argv[0]);
    return 0;
    }
    
    if(strcmp(argv[4], "-") == 0)
    fp = stdin;
    else {
    fp = fopen(argv[4], "r");
    if(!fp) {
        perror(argv[4]);
        return 1;
    }
    }
    keeplog(fp, argv[4], argv[1], argv[2], argv[3]);
    return 0;
}