88 subentry *psubt, *psubtm, *psubtlast;
95 unsigned long ulmsginthread;
97 unsigned long authnum;
100 unsigned int startdate, nextdate;
101 unsigned int startmsg, nextmsg;
113 nextdate = pdatet->
date;
115 while (psubtm->
sub) {
117 if (psubtm->
lastmsg >= nextmsg)
128 startdate = nextdate;
129 nextdate = pdatet->
date;
131 nextmsg = pdatet->
msg;
133 if (!stralloc_copys(&
fn,
"archive/threads/"))
die_nomem();
134 if (!stralloc_catb(&
fn,strnum,fmt_uint(strnum,startdate)))
die_nomem();
139 if ((fdn = open_trunc(
fnn.s)) == -1)
142 if ((
fd = open_read(
fn.s)) == -1) {
149 if (getln(&
bi,&line,&
match,
'\n') == -1)
152 pos = scan_ulong(line.s,&
msgnum);
155 if (line.len < pos +
HASHLEN) {
170 }
else if (res > 0) {
172 psubt = psubt->
lower;
182 if (buffer_put(&
bo,line.s,line.len) == -1)
186 if (*(
cp++) ==
' ' && *(
cp++) ==
'[') {
187 cp += scan_ulong(
cp,&ulmsginthread);
189 psubt->
msginthread += (
unsigned char) (ulmsginthread & 0xff);
201 if (!stralloc_copyb(&line,strnum,fmt_ulong(strnum,psubtm->
lastmsg)))
203 if (!stralloc_cats(&line,
":"))
die_nomem();
205 if (!stralloc_cats(&line,
" ["))
die_nomem();
206 if (!stralloc_catb(&line,strnum,fmt_ulong(strnum,(
unsigned long) psubtm->
msginthread)))
208 if (!stralloc_cats(&line,
"]"))
die_nomem();
211 if (buffer_put(&
bo,line.s,line.len) == -1)
222 if (!stralloc_copys(&
fn,
"archive/subjects/"))
die_nomem();
225 if (mkdir(
fn.s,0755) == -1)
228 fn.s[
fn.len - 1] =
'/';
234 if ((fdn = open_trunc(
fnn.s)) == -1)
237 if ((
fd = open_read(
fn.s)) == -1) {
240 if (buffer_puts(&
bo,psubt->
sub) == -1)
247 if (getln(&
bi,&line,&
match,
'\n') == -1)
253 if (buffer_put(&
bo,line.s,line.len) == -1)
258 r = scan_ulong(line.s,&
msgnum);
260 if (buffer_put(&
bo,line.s,line.len) == -1)
266 subnum = (
unsigned long) (psubt - subtable + 1);
268 for (msg = psubt->
firstmsg; msg <= psubt->lastmsg; msg++) {
269 if (pmsgt->
subnum == subnum) {
270 if (!stralloc_copyb(&line,strnum,fmt_ulong(strnum,msg)))
die_nomem();
271 if (!stralloc_cats(&line,
":"))
die_nomem();
272 if (!stralloc_catb(&line,strnum,fmt_uint(strnum,pmsgt->
date)))
274 if (!stralloc_cats(&line,
":"))
die_nomem();
276 pautht = authtable + pmsgt->
authnum - 1;
278 cp1 =
cp + str_chr(
cp,
' ');
281 if (!stralloc_cats(&line,
cp))
284 if (!stralloc_cats(&line,
"\n"))
die_nomem();
285 if (buffer_put(&
bo,line.s,line.len) == -1)
298 while (pautht->
auth) {
299 if (!stralloc_copys(&
fn,
"archive/authors/"))
die_nomem();
302 if (mkdir(
fn.s,0755) == -1)
305 fn.s[
fn.len - 1] =
'/';
311 if ((fdn = open_trunc(
fnn.s)) == -1)
314 if ((
fd = open_read(
fn.s)) == -1) {
326 if (getln(&
bi,&line,&
match,
'\n') == -1)
332 if (buffer_put(&
bo,line.s,line.len) == -1)
337 scan_ulong(line.s,&
msgnum);
339 if (buffer_put(&
bo,line.s,line.len) == -1)
345 authnum = (
unsigned long) (pautht - authtable + 1);
347 for (msg = pautht->
firstmsg; msg <=
to; msg++) {
348 if (pmsgt->
authnum == authnum) {
349 if (!stralloc_copyb(&line,strnum,fmt_ulong(strnum,msg)))
die_nomem();
350 if (!stralloc_cats(&line,
":"))
die_nomem();
351 if (!stralloc_catb(&line,strnum,fmt_uint(strnum,pmsgt->
date)))
353 if (!stralloc_cats(&line,
":"))
die_nomem();
355 psubt = subtable + pmsgt->
subnum - 1;
356 if (!stralloc_catb(&line,psubt->
sub,psubt->
sublen))
359 if (buffer_put(&
bo,line.s,line.len) == -1)
371 unsigned long archnum = 0L;
372 unsigned long to = 0L;
387 while ((
opt = getoptb(argc,argv,
"cCf:FsSt:TvV")) != opteof)
389 case 'c': flagcreate = 1;
flagsync = 0;
break;
390 case 'C': flagcreate = 0;
break;
391 case 'f':
if (optarg) { scan_ulong(optarg,&archnum); archnum = (archnum / 100) * 100; }
393 case 'F': archnum = 0;
break;
394 case 's': flagsyncall = 1;
break;
395 case 'S': flagsyncall = 0;
break;
396 case 't':
if (optarg) { scan_ulong(optarg,&
to); }
flagsync = 0;
break;
397 case 'T':
to = 0;
break;
400 default: die_usage();
404 dir = argv[optind++];
405 if (!
dir) die_usage();
406 if (chdir(
dir) == -1)
409 if (mkdir(
"archive/threads",0755) == -1)
412 if (mkdir(
"archive/subjects",0755) == -1)
415 if (mkdir(
"archive/authors",0755) == -1)
432 if (!flagcreate && !archnum) {
435 scan_ulong(
num.s,&archnum);
440 if (archnum >
to) _exit(0);
449 if ((
fd = open_trunc(
"archnumn")) == -1)
452 if (buffer_put(&
bn,strnum,fmt_ulong(strnum,
to)) == -1)
454 if (buffer_puts(&
bn,
"\n") == -1)
460 case -1:
logmsg(
WHO,99,WARN,
"threads entry with illegal format");
break;
461 case -2:
logmsg(
WHO,99,WARN,
"thread in index, but threadfile mibing");
break;
462 case -3:
logmsg(
WHO,99,WARN,
"a subject file lacks subject");
break;
463 case -4:
logmsg(
WHO,99,WARN,
"an author file lacks author/hash");
break;
464 case -5:
logmsg(
WHO,99,WARN,
"threads entry lacks message count");
break;
465 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)