diff options
author | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-05-25 12:05:26 +0800 |
---|---|---|
committer | wens <wens@63ad8ddf-47c3-0310-b6dd-a9e9d9715204> | 2008-05-25 12:05:26 +0800 |
commit | ff7ae115c5db1fe56f3c6114bf08ed8ecf0c9847 (patch) | |
tree | d80531d82774d0c8d340f760968dba13a3d11d07 /trans/sob_trans.c | |
parent | 983c3a4eefe0366ac29cd0ad90a859774500302c (diff) | |
download | pttbbs-ff7ae115c5db1fe56f3c6114bf08ed8ecf0c9847.tar pttbbs-ff7ae115c5db1fe56f3c6114bf08ed8ecf0c9847.tar.gz pttbbs-ff7ae115c5db1fe56f3c6114bf08ed8ecf0c9847.tar.bz2 pttbbs-ff7ae115c5db1fe56f3c6114bf08ed8ecf0c9847.tar.lz pttbbs-ff7ae115c5db1fe56f3c6114bf08ed8ecf0c9847.tar.xz pttbbs-ff7ae115c5db1fe56f3c6114bf08ed8ecf0c9847.tar.zst pttbbs-ff7ae115c5db1fe56f3c6114bf08ed8ecf0c9847.zip |
Move transform programs to seperate directory.
Add transformation program for SOB
git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@4322 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'trans/sob_trans.c')
-rw-r--r-- | trans/sob_trans.c | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/trans/sob_trans.c b/trans/sob_trans.c new file mode 100644 index 00000000..bc92c095 --- /dev/null +++ b/trans/sob_trans.c @@ -0,0 +1,113 @@ +/* $Id$ */ +/* tool to convert sob bbs to ptt bbs, based on sob 20030803 pack */ + +#include "bbs.h" + +typedef struct { + char filename[32]; + char pad1[2]; + char owner[14]; + char date[6]; + char title[73]; + unsigned char filemode; +} sob_fileheader_t; + +#define SOB_FILE_MARKED 0x02 + +int convert(const char *oldpath, char *newpath) +{ + int fd; + char *p; + char buf[PATHLEN]; + sob_fileheader_t whdr; + fileheader_t fhdr; + + setadir(buf, oldpath); + + if ((fd = open(buf, O_RDONLY, 0)) == -1) + return -1; + + while (read(fd, &whdr, sizeof(whdr)) == sizeof(whdr)) { + snprintf(buf, sizeof(buf), "%s/%s", oldpath, whdr.filename); + + if (dashd(buf)) { + /* folder */ + stampdir(newpath, &fhdr); + + convert(whdr.filename, newpath); + } + else { + /* article */ + stampfile(newpath, &fhdr); + + fhdr.modified = dasht(buf); + if (whdr.filemode & SOB_FILE_MARKED) + fhdr.filemode | FILE_MARKED; + + copy_file(buf, newpath); + } + + p = strrchr(newpath, '/'); + *p = '\0'; + + strlcpy(fhdr.title, whdr.title, sizeof(fhdr.title)); + strlcpy(fhdr.owner, whdr.owner, sizeof(fhdr.owner)); + strlcpy(fhdr.date, whdr.date, sizeof(fhdr.date)); + + setadir(buf, newpath); + append_record(buf, &fhdr, sizeof(fhdr)); + } + + close(fd); + return 0; +} + +int main(int argc, char *argv[]) +{ + char buf[PATHLEN]; + char *path; + char *board; + int opt; + int trans_man = 0; + + while ((opt = getopt(argc, argv, "m")) != -1) { + switch (opt) { + case 'm': + trans_man = 1; + break; + default: + fprintf(stderr, "%s [-m] <path> <board>\n", argv[0]); + fprintf(stderr, " -m convert man (default is board)\n"); + } + } + + if ((argc - optind + 1) < 2) { + fprintf(stderr, "%s [-m] <path> <board>\n", argv[0]); + fprintf(stderr, " -m convert man (default is board)\n"); + return 0; + } + + path = argv[optind]; + board = argv[optind+1]; + + if (!dashd(path)) { + fprintf(stderr, "%s is not directory\n", path); + return 0; + } + + if (trans_man) + setapath(buf, board); + else + setbpath(buf, board); + + if (!dashd(buf)) { + fprintf(stderr, "%s is not directory\n", buf); + return 0; + } + + attach_SHM(); + + convert(path, buf); + + return 0; +} |