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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
/* $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(buf, 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;
}
attach_SHM();
opt = getbnum(board);
if (opt == 0) {
fprintf(stderr, "ERR: board `%s' not found\n", board);
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;
}
convert(path, buf);
if (trans_man) {
strlcat(buf, "/.rebuild", sizeof(buf));
if ((opt = open(buf, O_CREAT, 0640)) > 0)
close(opt);
}
else
touchbtotal(opt);
return 0;
}
|