86 subentry *psubt, *psubtm, *psubtlast;
93 unsigned long ulmsginthread;
95 unsigned long authnum;
98 unsigned int startdate, nextdate;
99 unsigned int startmsg, nextmsg;
111 nextdate = pdatet->
date;
113 while (psubtm->
sub) {
115 if (psubtm->
lastmsg >= nextmsg)
126 startdate = nextdate;
127 nextdate = pdatet->
date;
129 nextmsg = pdatet->
msg;
131 if (!stralloc_copys(&
fn,
"archive/threads/"))
die_nomem();
132 if (!stralloc_catb(&
fn,strnum,fmt_uint(strnum,startdate)))
die_nomem();
137 if ((fdn = open_trunc(
fnn.s)) == -1)
140 if ((
fd = open_read(
fn.s)) == -1) {
147 if (getln(&
bi,&line,&
match,
'\n') == -1)
150 pos = scan_ulong(line.s,&
msgnum);
153 if (line.len < pos +
HASHLEN) {
168 }
else if (res > 0) {
170 psubt = psubt->
lower;
180 if (buffer_put(&
bo,line.s,line.len) == -1)
184 if (*(
cp++) ==
' ' && *(
cp++) ==
'[') {
185 cp += scan_ulong(
cp,&ulmsginthread);
187 psubt->
msginthread += (
unsigned char) (ulmsginthread & 0xff);
199 if (!stralloc_copyb(&line,strnum,fmt_ulong(strnum,psubtm->
lastmsg)))
201 if (!stralloc_cats(&line,
":"))
die_nomem();
203 if (!stralloc_cats(&line,
" ["))
die_nomem();
204 if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,(
unsigned long) psubtm->
msginthread)))
206 if (!stralloc_cats(&line,
"]"))
die_nomem();
209 if (buffer_put(&
bo,line.s,line.len) == -1)
220 if (!stralloc_copys(&
fn,
"archive/subjects/"))
die_nomem();
223 if (mkdir(
fn.s,0755) == -1)
226 fn.s[
fn.len - 1] =
'/';
232 if ((fdn = open_trunc(
fnn.s)) == -1)
235 if ((
fd = open_read(
fn.s)) == -1) {
238 if (buffer_puts(&
bo,psubt->
sub) == -1)
245 if (getln(&
bi,&line,&
match,
'\n') == -1)
251 if (buffer_put(&
bo,line.s,line.len) == -1)
256 r = scan_ulong(line.s,&
msgnum);
258 if (buffer_put(&
bo,line.s,line.len) == -1)
264 subnum = (
unsigned long) (psubt - subtable + 1);
266 for (msg = psubt->
firstmsg; msg <= psubt->lastmsg; msg++) {
267 if (pmsgt->
subnum == subnum) {
268 if (!stralloc_copyb(&line,strnum,fmt_ulong(strnum,msg)))
die_nomem();
269 if (!stralloc_cats(&line,
":"))
die_nomem();
270 if (!stralloc_catb(&line,strnum,fmt_uint(strnum,pmsgt->
date)))
272 if (!stralloc_cats(&line,
":"))
die_nomem();
274 pautht = authtable + pmsgt->
authnum - 1;
276 cp1 =
cp + str_chr(
cp,
' ');
279 if (!stralloc_cats(&line,
cp))
282 if (!stralloc_cats(&line,
"\n"))
die_nomem();
283 if (buffer_put(&
bo,line.s,line.len) == -1)
296 while (pautht->
auth) {
297 if (!stralloc_copys(&
fn,
"archive/authors/"))
die_nomem();
300 if (mkdir(
fn.s,0755) == -1)
303 fn.s[
fn.len - 1] =
'/';
309 if ((fdn = open_trunc(
fnn.s)) == -1)
312 if ((
fd = open_read(
fn.s)) == -1) {
324 if (getln(&
bi,&line,&
match,
'\n') == -1)
330 if (buffer_put(&
bo,line.s,line.len) == -1)
335 scan_ulong(line.s,&
msgnum);
337 if (buffer_put(&
bo,line.s,line.len) == -1)
343 authnum = (
unsigned long) (pautht - authtable + 1);
345 for (msg = pautht->
firstmsg; msg <=
to; msg++) {
346 if (pmsgt->
authnum == authnum) {
347 if (!stralloc_copyb(&line,strnum,fmt_ulong(strnum,msg)))
die_nomem();
348 if (!stralloc_cats(&line,
":"))
die_nomem();
349 if (!stralloc_catb(&line,strnum,fmt_uint(strnum,pmsgt->
date)))
351 if (!stralloc_cats(&line,
":"))
die_nomem();
353 psubt = subtable + pmsgt->
subnum - 1;
354 if (!stralloc_catb(&line,psubt->
sub,psubt->
sublen))
357 if (buffer_put(&
bo,line.s,line.len) == -1)
369 unsigned long archnum = 0L;
370 unsigned long to = 0L;
385 while ((
opt = getoptb(argc,argv,
"cCf:FsSt:TvV")) != opteof)
387 case 'c': flagcreate = 1;
flagsync = 0;
break;
388 case 'C': flagcreate = 0;
break;
389 case 'f':
if (optarg) { scan_ulong(optarg,&archnum); archnum = (archnum / 100) * 100; }
391 case 'F': archnum = 0;
break;
392 case 's': flagsyncall = 1;
break;
393 case 'S': flagsyncall = 0;
break;
394 case 't':
if (optarg) { scan_ulong(optarg,&
to); }
flagsync = 0;
break;
395 case 'T':
to = 0;
break;
398 default: die_usage();
402 dir = argv[optind++];
403 if (!
dir) die_usage();
404 if (chdir(
dir) == -1)
407 if (mkdir(
"archive/threads",0755) == -1)
410 if (mkdir(
"archive/subjects",0755) == -1)
413 if (mkdir(
"archive/authors",0755) == -1)
430 if (!flagcreate && !archnum) {
433 scan_ulong(
num.s,&archnum);
438 if (archnum >
to) _exit(0);
447 if ((
fd = open_trunc(
"archnumn")) == -1)
450 if (buffer_put(&
bn,strnum,fmt_ulong(strnum,
to)) == -1)
452 if (buffer_puts(&
bn,
"\n") == -1)
458 case -1:
logmsg(
WHO,99,WARN,
"threads entry with illegal format");
break;
459 case -2:
logmsg(
WHO,99,WARN,
"thread in index, but threadfile mibing");
break;
460 case -3:
logmsg(
WHO,99,WARN,
"a subject file lacks subject");
break;
461 case -4:
logmsg(
WHO,99,WARN,
"an author file lacks author/hash");
break;
462 case -5:
logmsg(
WHO,99,WARN,
"threads entry lacks message count");
break;
463 default:
logmsg(
WHO,99,WARN,
"something happened that isn't quite right");
void close_proper(buffer *bo, char *s, char *sn)
flush,sync,close,move sn->s
void write_threads(msgentry *msgtable, subentry *subtable, authentry *authtable, dateentry *datetable, unsigned long from, unsigned long to)
void idx_mkthreads(msgentry **pmsgtable, subentry **psubtable, authentry **pauthtable, dateentry **pdatetable, unsigned long msg_from, unsigned long msg_to, unsigned long msg_latest, int locked)
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)