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 | 2596725441bb9a88d42ba1a0d10c22e7cce1d885 (patch) | |
tree | cadcbc72450e535039e9257c6e106f3a629c8c08 | |
parent | 643bbd4428141ca90d625e5a701ed44d51691a72 (diff) | |
download | pttbbs-2596725441bb9a88d42ba1a0d10c22e7cce1d885.tar pttbbs-2596725441bb9a88d42ba1a0d10c22e7cce1d885.tar.gz pttbbs-2596725441bb9a88d42ba1a0d10c22e7cce1d885.tar.bz2 pttbbs-2596725441bb9a88d42ba1a0d10c22e7cce1d885.tar.lz pttbbs-2596725441bb9a88d42ba1a0d10c22e7cce1d885.tar.xz pttbbs-2596725441bb9a88d42ba1a0d10c22e7cce1d885.tar.zst pttbbs-2596725441bb9a88d42ba1a0d10c22e7cce1d885.zip |
Move transform programs to seperate directory.
Add transformation program for SOB
git-svn-id: http://opensvn.csie.org/pttbbs/trunk@4322 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
-rw-r--r-- | pttbbs/Makefile | 2 | ||||
-rw-r--r-- | pttbbs/trans/Makefile | 62 | ||||
-rw-r--r-- | pttbbs/trans/sob_trans.c | 113 | ||||
-rw-r--r-- | pttbbs/trans/transman.c (renamed from pttbbs/util/transman.c) | 0 | ||||
-rw-r--r-- | pttbbs/trans/wretch_man.c (renamed from pttbbs/util/wretch_man.c) | 0 | ||||
-rw-r--r-- | pttbbs/util/Makefile | 2 |
6 files changed, 177 insertions, 2 deletions
diff --git a/pttbbs/Makefile b/pttbbs/Makefile index d4c8df36..78ded7c9 100644 --- a/pttbbs/Makefile +++ b/pttbbs/Makefile @@ -1,4 +1,4 @@ -SUBDIR= common mbbsd util innbbsd +SUBDIR= common mbbsd util innbbsd trans all install clean: .if !exists(/usr/local/lib/libhz.so) && !exists(/usr/lib/libhz.so) diff --git a/pttbbs/trans/Makefile b/pttbbs/trans/Makefile new file mode 100644 index 00000000..6518509a --- /dev/null +++ b/pttbbs/trans/Makefile @@ -0,0 +1,62 @@ +# $Id$ + +SRCROOT= .. +.include "$(SRCROOT)/pttbbs.mk" + +CFLAGS+= -DPTTBBS_UTIL + +BBSBASE= $(SRCROOT)/include/var.h + +UTIL_OBJS= \ + util_cache.o util_record.o util_passwd.o util_var.o + +MBBSD_OBJS= \ + cache record passwd var + +# 下面這些程式, 會被 compile 並且和 $(UTIL_OBJS) 聯結 +CPROG_WITH_UTIL= \ + wretch_man \ + sob_trans \ + transman + +# 下面是 C++ 的程式 +CPP_WITH_UTIL= \ + + +# 下面這些程式, 會直接被 compile +CPROG_WITHOUT_UTIL= \ + +# 下面這些程式會被 install +PROGS= ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${CPP_WITH_UTIL}\ + +LIBS+= $(SRCROOT)/common/sys/libcmsys.a \ + $(SRCROOT)/common/bbs/libcmbbs.a + + +all: ${CPROG_WITH_UTIL} ${CPROG_WITHOUT_UTIL} ${CPP_WITH_UTIL} ${PROGS} + +$(SRCROOT)/include/var.h: $(SRCROOT)/mbbsd/var.c + cd $(SRCROOT)/mbbsd; $(MAKE) $(SRCROOT)/include/var.h + +.for fn in ${CPROG_WITH_UTIL} +${fn}: ${BBSBASE} ${fn}.c ${UTIL_OBJS} + $(CCACHE) ${CC} ${CFLAGS} ${LDFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.c $(LIBS) +.endfor + +.for fn in ${CPP_WITH_UTIL} +${fn}: ${BBSBASE} ${fn}.cc ${UTIL_OBJS} + $(CCACHE) ${CXX} ${CFLAGS} ${LDFLAGS} -o ${fn} ${UTIL_OBJS} ${fn}.cc $(LIBS) +.endfor + +.for fn in ${MBBSD_OBJS} +util_${fn}.o: ${BBSBASE} $(SRCROOT)/mbbsd/${fn}.c + $(CCACHE) ${CC} ${CFLAGS} -D_BBS_UTIL_C_ -c -o $@ $(SRCROOT)/mbbsd/${fn}.c +.endfor + +install: $(PROGS) + install -d $(BBSHOME)/bin/ + install -c -m 755 $(PROGS) $(BBSHOME)/bin/ + +clean: + rm -f *.o $(CPROGS) $(CPROG_WITH_UTIL) $(CPROG_WITHOUT_UTIL) $(CPP_WITH_UTIL) + diff --git a/pttbbs/trans/sob_trans.c b/pttbbs/trans/sob_trans.c new file mode 100644 index 00000000..bc92c095 --- /dev/null +++ b/pttbbs/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; +} diff --git a/pttbbs/util/transman.c b/pttbbs/trans/transman.c index 711e8ead..711e8ead 100644 --- a/pttbbs/util/transman.c +++ b/pttbbs/trans/transman.c diff --git a/pttbbs/util/wretch_man.c b/pttbbs/trans/wretch_man.c index d055980d..d055980d 100644 --- a/pttbbs/util/wretch_man.c +++ b/pttbbs/trans/wretch_man.c diff --git a/pttbbs/util/Makefile b/pttbbs/util/Makefile index 20477500..58c7bde8 100644 --- a/pttbbs/util/Makefile +++ b/pttbbs/util/Makefile @@ -22,7 +22,7 @@ CPROG_WITH_UTIL= \ yearsold toplazyBM toplazyBBM writemoney \ reaper buildAnnounce inndBM mailangel \ outmail chkhbf merge_dir \ - transman angel gamblegive wretch_man \ + angel gamblegive \ chesscountry tunepasswd buildir xchatd \ uhash_loader |