-
Notifications
You must be signed in to change notification settings - Fork 1
/
cache.c
1058 lines (978 loc) · 22.3 KB
/
cache.c
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* cache.c
* vi: set sw=4 ts=8 ai sm noet :
*/
/* This software is copyrighted as detailed in the LICENSE file. */
#include "EXTERN.h"
#include "common.h"
#include "list.h"
#include "intrp.h"
#include "search.h"
#include "ng.h"
#include "trn.h"
#include "hash.h"
#include "ngdata.h"
#include "nntpclient.h"
#include "datasrc.h"
#include "nntp.h"
#include "term.h"
#include "final.h"
#include "artsrch.h"
#include "head.h"
#include "mime.h"
#include "bits.h"
#include "kfile.h"
#include "rcstuff.h"
#include "rthread.h"
#include "rt-ov.h"
#include "rt-page.h"
#include "rt-process.h"
#include "rt-select.h"
#include "rt-util.h"
#ifdef SCORE
#include "score.h"
#endif
#include "env.h"
#include "util.h"
#include "util2.h"
#include "utf.h"
#include "INTERN.h"
#include "cache.h"
#include "cache.ih"
#ifdef PENDING
# ifdef ARTSEARCH
COMPEX srchcompex; /* compiled regex for searchahead */
# endif
#endif
HASHTABLE* subj_hash = 0;
HASHTABLE* shortsubj_hash = 0;
void
cache_init()
{
#ifdef PENDING
# ifdef ARTSEARCH
init_compex(&srchcompex);
# endif
#endif
}
static NGDATA* cached_ng = NULL;
static time_t cached_time = 0;
void
build_cache()
{
if (cached_ng == ngptr && time((time_t*)NULL) < cached_time + 6*60*60L) {
ART_NUM an;
cached_time = time((time_t*)NULL);
if (sel_mode == SM_ARTICLE)
set_selector(sel_mode, sel_artsort);
else
set_selector(sel_threadmode, sel_threadsort);
for (an = last_cached+1; an <= lastart; an++)
article_ptr(an)->flags |= AF_EXISTS;
rc_to_bits();
article_list->high = lastart;
thread_grow();
return;
}
close_cache();
cached_ng = ngptr;
cached_time = time((time_t*)NULL);
article_list = new_list(absfirst, lastart, sizeof (ARTICLE), 371,
LF_SPARSE, init_artnode);
subj_hash = hashcreate(991, subject_cmp); /*TODO: pick a better size */
set_firstart(ngptr->rcline + ngptr->numoffset);
first_cached = thread_always? absfirst : firstart;
last_cached = first_cached-1;
cached_all_in_range = FALSE;
#ifdef PENDING
subj_to_get = xref_to_get = firstart;
#endif
/* Cache as much data in advance as possible, possibly threading
** articles as we go. */
thread_open();
}
void
close_cache()
{
SUBJECT* sp;
SUBJECT* next;
#ifdef SUPPORT_NNTP
nntp_artname(0, FALSE); /* clear the tmpfile cache */
#endif
if (subj_hash) {
hashdestroy(subj_hash);
subj_hash = 0;
}
if (shortsubj_hash) {
hashdestroy(shortsubj_hash);
shortsubj_hash = 0;
}
/* Free all the subjects. */
for (sp = first_subject; sp; sp = next) {
next = sp->next;
free(sp->str);
free((char*)sp);
}
first_subject = last_subject = NULL;
subject_count = 0; /* just to be sure */
parsed_art = 0;
if (artptr_list) {
free((char*)artptr_list);
artptr_list = NULL;
}
artptr = NULL;
thread_close();
if (article_list) {
walk_list(article_list, clear_artitem, 0);
delete_list(article_list);
article_list = NULL;
}
cached_ng = NULL;
}
/* Initialize the memory for an entire node's worth of article's */
static void
init_artnode(list, node)
LIST* list;
LISTNODE* node;
{
register ART_NUM i;
register ARTICLE* ap;
bzero(node->data, list->items_per_node * list->item_size);
for (i = node->low, ap = (ARTICLE*)node->data; i <= node->high; i++, ap++)
ap->num = i;
}
static bool
clear_artitem(cp, arg)
char* cp;
int arg;
{
clear_article((ARTICLE*)cp);
return 0;
}
/* The article has all it's data in place, so add it to the list of articles
** with the same subject.
*/
void
cache_article(ap)
register ARTICLE* ap;
{
register ARTICLE* next;
register ARTICLE* ap2;
if (!(next = ap->subj->articles) || ap->date < next->date)
ap->subj->articles = ap;
else {
while ((next = (ap2 = next)->subj_next) && next->date <= ap->date)
;
ap2->subj_next = ap;
}
ap->subj_next = next;
ap->flags |= AF_CACHED;
if (!!(ap->flags & AF_UNREAD) ^ sel_rereading) {
if (ap->subj->flags & sel_mask)
select_article(ap, 0);
else {
if (ap->subj->flags & SF_WASSELECTED) {
#if 0
if (selected_only)
ap->flags |= sel_mask;
else
#endif
select_article(ap, 0);
}
ap->subj->flags |= SF_VISIT;
}
}
if (join_subject_len != 0)
check_for_near_subj(ap);
}
void
check_for_near_subj(ap)
ARTICLE* ap;
{
register SUBJECT* sp;
if (!shortsubj_hash) {
shortsubj_hash = hashcreate(401, subject_cmp); /*TODO: pick a better size */
sp = first_subject;
}
else {
sp = ap->subj;
if (sp->next)
sp = 0;
}
while (sp) {
if ((int)strlen(sp->str+4) >= join_subject_len && sp->thread) {
SUBJECT* sp2;
HASHDATUM data;
data = hashfetch(shortsubj_hash, sp->str+4, join_subject_len);
if (!(sp2 = (SUBJECT*)data.dat_ptr)) {
data.dat_ptr = (char*)sp;
hashstorelast(data);
}
else if (sp->thread != sp2->thread) {
merge_threads(sp2, sp);
}
}
sp = sp->next;
}
}
void
change_join_subject_len(len)
int len;
{
if (join_subject_len != len) {
if (shortsubj_hash) {
hashdestroy(shortsubj_hash);
shortsubj_hash = 0;
}
join_subject_len = len;
if (len && first_subject && first_subject->articles)
check_for_near_subj(first_subject->articles);
}
}
void
check_poster(ap)
register ARTICLE* ap;
{
if (auto_select_postings && (ap->flags & AF_EXISTS) && ap->from) {
if (ap->flags & AF_FROMTRUNCED) {
strcpy(cmd_buf,realName);
if (strEQ(ap->from,compress_name(cmd_buf,16))) {
untrim_cache = TRUE;
fetchfrom(article_num(ap),FALSE);
untrim_cache = FALSE;
}
}
if (!(ap->flags & AF_FROMTRUNCED)) {
char* s = cmd_buf;
char* u;
char* h;
strcpy(s,ap->from);
if ((h=index(s,'<')) != NULL) { /* grab the good part */
s = h+1;
if ((h=index(s,'>')) != NULL)
*h = '\0';
} else if ((h=index(s,'(')) != NULL) {
while (h-- != s && *h == ' ')
;
h[1] = '\0'; /* or strip the comment */
}
if ((h = index(s,'%')) != NULL || (h = index(s,'@')) != NULL) {
*h++ = '\0';
u = s;
} else if ((u = rindex(s,'!')) != NULL) {
*u++ = '\0';
h = s;
} else
h = u = s;
if (strEQ(u,loginName)) {
if (instr(h,hostname,FALSE)) {
switch (auto_select_postings) {
case '.':
select_subthread(ap,AUTO_SEL_FOL);
break;
case '+':
select_arts_thread(ap,AUTO_SEL_THD);
break;
case 'p':
if (ap->parent)
select_subthread(ap->parent,AUTO_SEL_FOL);
else
select_subthread(ap,AUTO_SEL_FOL);
break;
}
} else {
#ifdef REPLYTO_POSTER_CHECKING
char* reply_buf = fetchlines(article_num(ap),REPLY_LINE);
if (instr(reply_buf,loginName,TRUE))
select_subthread(ap,AUTO_SEL_FOL);
free(reply_buf);
#endif
}
}
}
}
}
/* The article turned out to be a duplicate, so remove it from the cached
** list and possibly destroy the subject (should only happen if the data
** was corrupt and the duplicate id got a different subject).
*/
void
uncache_article(ap, remove_empties)
register ARTICLE* ap;
bool_int remove_empties;
{
register ARTICLE* next;
if (ap->subj) {
if (ALLBITS(ap->flags, AF_CACHED | AF_EXISTS)) {
if ((next = ap->subj->articles) == ap)
ap->subj->articles = ap->subj_next;
else {
register ARTICLE* ap2;
while (next) {
if ((ap2 = next->subj_next) == ap) {
next->subj_next = ap->subj_next;
break;
}
next = ap2;
}
}
}
if (remove_empties && !ap->subj->articles) {
register SUBJECT* sp = ap->subj;
if (sp == first_subject)
first_subject = sp->next;
else
sp->prev->next = sp->next;
if (sp == last_subject)
last_subject = sp->prev;
else
sp->next->prev = sp->prev;
hashdelete(subj_hash, sp->str+4, strlen(sp->str+4));
free((char*)sp);
ap->subj = NULL;
subject_count--;
}
}
ap->flags2 |= AF2_BOGUS;
onemissing(ap);
}
/* get the header line from an article's cache or parse the article trying */
char*
fetchcache(artnum,which_line,fill_cache)
ART_NUM artnum;
int which_line;
bool_int fill_cache;
{
register char* s;
register ARTICLE* ap;
register bool cached = (htype[which_line].flags & HT_CACHED);
/* article_find() returns a NULL if the artnum value is invalid */
if (!(ap = article_find(artnum)) || !(ap->flags & AF_EXISTS))
return nullstr;
if (cached && (s=get_cached_line(ap,which_line,untrim_cache)) != NULL)
return s;
if (!fill_cache)
return NULL;
if (!parseheader(artnum))
return nullstr;
if (cached)
return get_cached_line(ap,which_line,untrim_cache);
return NULL;
}
/* Return a pointer to a cached header line for the indicated article.
** Truncated headers (e.g. from a .thread file) are optionally ignored.
*/
char*
get_cached_line(ap, which_line, no_truncs)
register ARTICLE* ap;
int which_line;
bool_int no_truncs;
{
register char* s;
switch (which_line) {
case SUBJ_LINE:
if (!ap->subj || (no_truncs && (ap->subj->flags & SF_SUBJTRUNCED)))
s = NULL;
else
s = ap->subj->str + ((ap->flags & AF_HAS_RE) ? 0 : 4);
break;
case FROM_LINE:
if (no_truncs && (ap->flags & AF_FROMTRUNCED))
s = NULL;
else
s = ap->from;
break;
#ifdef DBM_XREFS
case NGS_LINE:
#else
case XREF_LINE:
#endif
s = ap->xrefs;
break;
case MSGID_LINE:
s = ap->msgid;
break;
#ifdef USE_FILTER
case REFS_LINE:
s = ap->refs;
break;
#endif
case LINES_LINE: {
static char linesbuf[32];
sprintf(linesbuf, "%ld", ap->lines);
s = linesbuf;
break;
}
case BYTES_LINE: {
static char bytesbuf[32];
sprintf(bytesbuf, "%ld", ap->bytes);
s = bytesbuf;
break;
}
default:
s = NULL;
break;
}
return s;
}
void
set_subj_line(ap, subj, size)
ARTICLE* ap;
char* subj; /* not yet allocated, so we can tweak it first */
int size;
{
HASHDATUM data;
SUBJECT* sp;
char* newsubj;
char* subj_start;
short def_flags = 0;
if (subject_has_Re(subj, &subj_start))
ap->flags |= AF_HAS_RE;
if ((size -= subj_start - subj) < 0)
size = 0;
newsubj = safemalloc(size + 4 + 1);
strcpy(newsubj, "Re: ");
size = decode_header(newsubj + 4, subj_start, size);
/* Do the Re:-stripping over again, just in case it was encoded. */
if (subject_has_Re(newsubj + 4, &subj_start))
ap->flags |= AF_HAS_RE;
if (subj_start != newsubj + 4) {
safecpy(newsubj + 4, subj_start, size);
if ((size -= subj_start - newsubj - 4) < 0)
size = 0;
}
if (ap->subj && strnEQ(ap->subj->str+4, newsubj+4, size)) {
free(newsubj);
return;
}
if (ap->subj) {
/* This only happens when we freshen truncated subjects */
hashdelete(subj_hash, ap->subj->str+4, strlen(ap->subj->str+4));
free(ap->subj->str);
ap->subj->str = newsubj;
ap->subj->flags |= def_flags;
data.dat_ptr = (char*)ap->subj;
hashstore(subj_hash, newsubj + 4, size, data);
} else {
data = hashfetch(subj_hash, newsubj + 4, size);
if (!(sp = (SUBJECT*)data.dat_ptr)) {
sp = (SUBJECT*)safemalloc(sizeof (SUBJECT));
bzero((char*)sp, sizeof (SUBJECT));
subject_count++;
if ((sp->prev = last_subject) != NULL)
sp->prev->next = sp;
else
first_subject = sp;
last_subject = sp;
sp->str = newsubj;
sp->thread_link = sp;
sp->flags = def_flags;
data.dat_ptr = (char*)sp;
hashstorelast(data);
} else
free(newsubj);
ap->subj = sp;
}
}
int
decode_header(t, f, size)
char* t;
char* f;
int size;
{
int i;
char *s = t; /* save for pass 2 */
bool pass2needed = FALSE;
/* Pass 1 to decode coded bytes (which might be character fragments - so 1 pass is wrong) */
for (i = size; *f && i--; ) {
if (*f == '=' && f[1] == '?') {
char* q = index(f+2,'?');
char ch = (q && q[2] == '?')? q[1] : 0;
char* e;
if (ch == 'q' || ch == 'Q' || ch == 'b' || ch == 'B') {
const char* old_ics = input_charset_name();
const char* old_ocs = output_charset_name();
#ifdef USE_UTF_HACK
*q = '\0';
utf_init(f+2, "utf-8"); /*FIXME*/
*q = '?';
#endif
e = q+2;
do {
e = index(e+1, '?');
} while (e && e[1] != '=');
if (e) {
int len = e - f + 2;
#ifdef USE_UTF_HACK
char *d;
#endif
i -= len-1;
size -= len;
q += 3;
f = e+2;
*e = '\0';
if (ch == 'q' || ch == 'Q')
len = qp_decodestring(t, q, 1);
else
len = b64_decodestring(t, q);
#ifdef USE_UTF_HACK
d = create_utf8_copy(t);
if (d) {
for (len = 0; d[len]; ) {
t[len] = d[len];
len++;
}
free(d);
}
#endif
*e = '?';
t += len;
size += len;
/* If the next character is whitespace we should eat it now */
while (*f == ' ' || *f == '\t')
f++;
}
else
*t++ = *f++;
#ifdef USE_UTF_HACK
utf_init(old_ics, old_ocs);
#endif
}
else
*t++ = *f++;
} else if (*f != '\n')
*t++ = *f++;
else
f++, size--;
pass2needed = TRUE;
}
while (size > 1 && t[-1] == ' ')
t--, size--;
*t = '\0';
/* Pass 2 to clear out "control" characters */
if (pass2needed)
dectrl(s);
return size;
}
void
dectrl(str)
char* str;
{
if (str == NULL)
return;
for ( ; *str;) {
int w = byte_length_at(str);
if (AT_GREY_SPACE(str)) {
register int i;
for (i = 0; i < w; i += 1) {
str[i] = ' ';
}
}
str += w;
}
}
void
set_cached_line(ap, which_line, s)
register ARTICLE* ap;
register int which_line;
register char* s; /* already allocated, ready to save */
{
char* cp;
/* SUBJ_LINE is handled specially above */
switch (which_line) {
case FROM_LINE:
ap->flags &= ~AF_FROMTRUNCED;
if (ap->from)
free(ap->from);
decode_header(s, s, strlen(s));
ap->from = s;
break;
#ifdef DBM_XREFS
case NGS_LINE:
if (ap->xrefs && ap->xrefs != nullstr)
free(ap->xrefs);
if (!index(s, ',')) { /* if no comma, no Xref! */
free(s);
s = nullstr;
}
ap->xrefs = s;
break;
#else
case XREF_LINE:
if (ap->xrefs && ap->xrefs != nullstr)
free(ap->xrefs);
/* Exclude an xref for just this group or "(none)". */
cp = index(s, ':');
if (!cp || !index(cp+1, ':')) {
free(s);
s = nullstr;
}
ap->xrefs = s;
break;
#endif
case MSGID_LINE:
if (ap->msgid)
free(ap->msgid);
ap->msgid = s;
break;
#ifdef USE_FILTER
case REFS_LINE:
if (ap->refs && ap->refs != nullstr)
free(ap->refs);
ap->refs = s;
break;
#endif
case LINES_LINE:
ap->lines = atol(s);
break;
case BYTES_LINE:
ap->bytes = atol(s);
break;
}
}
int
subject_cmp(key, keylen, data)
char* key;
int keylen;
HASHDATUM data;
{
/* We already know that the lengths are equal, just compare the strings */
return bcmp(key, ((SUBJECT*)data.dat_ptr)->str+4, keylen);
}
/* see what we can do while they are reading */
#ifdef PENDING
void
look_ahead()
{
#ifdef ARTSEARCH
register char* h;
register char* s;
#ifdef DEBUG
if (debug && srchahead) {
printf("(%ld)",(long)srchahead);
fflush(stdout);
}
#endif
#endif
if (ThreadedGroup) {
artp = curr_artp;
inc_art(selected_only,FALSE);
if (artp)
parseheader(art);
}
else
#ifdef ARTSEARCH
if (srchahead && srchahead < art) { /* in ^N mode? */
char* pattern;
pattern = buf+1;
strcpy(pattern,": *");
h = pattern + strlen(pattern);
interp(h,(sizeof buf) - (h-buf),"%\\s");
{ /* compensate for notesfiles */
register int i;
for (i = 24; *h && i--; h++)
if (*h == '\\')
h++;
*h = '\0';
}
#ifdef DEBUG
if (debug & DEB_SEARCH_AHEAD) {
fputs("(hit CR)",stdout);
fflush(stdout);
fgets(buf+128, sizeof buf-128, stdin);
printf("\npattern = %s\n",pattern);
termdown(2);
}
#endif
if ((s = compile(&srchcompex,pattern,TRUE,TRUE)) != NULL) {
/* compile regular expression */
printf("\n%s\n",s) FLUSH;
termdown(2);
srchahead = 0;
}
if (srchahead) {
srchahead = art;
for (;;) {
srchahead++; /* go forward one article */
if (srchahead > lastart) { /* out of articles? */
#ifdef DEBUG
if (debug)
fputs("(not found)",stdout);
#endif
break;
}
if (!was_read(srchahead) &&
wanted(&srchcompex,srchahead,0)) {
/* does the shoe fit? */
#ifdef DEBUG
if (debug)
printf("(%ld)",(long)srchahead);
#endif
parseheader(srchahead);
break;
}
if (input_pending())
break;
}
fflush(stdout);
}
}
else
#endif /* ARTSEARCH */
{
if (article_next(art) <= lastart) /* how about a pre-fetch? */
parseheader(article_next(art)); /* look for the next article */
}
}
#endif /* PENDING */
/* see what else we can do while they are reading */
void
cache_until_key()
{
if (!in_ng)
return;
#ifdef PENDING
if (input_pending())
return;
# ifdef SUPPORT_NNTP
if ((datasrc->flags & DF_REMOTE) && nntp_finishbody(FB_BACKGROUND))
return;
# endif
# ifdef NICEBG
if (wait_key_pause(10))
return;
# endif
untrim_cache = TRUE;
sentinel_artp = curr_artp;
/* Prioritize our caching based on what mode we're in */
if (gmode == 's') {
if (cache_subjects()) {
if (cache_xrefs()) {
if (chase_xrefs(TRUE)) {
if (ThreadedGroup)
cache_all_arts();
else
cache_unread_arts();
}
}
}
} else {
if (!ThreadedGroup || cache_all_arts()) {
if (cache_subjects()) {
if (cache_unread_arts()) {
if (cache_xrefs())
chase_xrefs(TRUE);
}
}
}
}
# ifdef SCORE
if (!input_pending() && sc_initialized)
sc_lookahead(TRUE,TRUE);
# endif
setspin(SPIN_OFF);
untrim_cache = FALSE;
#endif
#ifdef SUPPORT_NNTP
check_datasrcs();
#endif
}
#ifdef PENDING
bool
cache_subjects()
{
register ART_NUM an;
if (subj_to_get > lastart)
return TRUE;
setspin(SPIN_BACKGROUND);
for (an=article_first(subj_to_get); an <= lastart; an=article_next(an)) {
if (input_pending())
break;
if (article_unread(an))
fetchsubj(an,FALSE);
}
subj_to_get = an;
return subj_to_get > lastart;
}
bool
cache_xrefs()
{
register ART_NUM an;
if (olden_days || (datasrc->flags & DF_NOXREFS) || xref_to_get > lastart)
return TRUE;
setspin(SPIN_BACKGROUND);
for (an=article_first(xref_to_get); an <= lastart; an=article_next(an)) {
if (input_pending())
break;
if (article_unread(an))
fetchxref(an,FALSE);
}
xref_to_get = an;
return xref_to_get > lastart;
}
bool
cache_all_arts()
{
int old_last_cached = last_cached;
if (!cached_all_in_range)
last_cached = first_cached-1;
if (last_cached >= lastart && first_cached <= absfirst)
return TRUE;
/* turn it on as late as possible to avoid fseek()ing openart */
setspin(SPIN_BACKGROUND);
if (last_cached < lastart) {
if (datasrc->ov_opened)
ov_data(last_cached+1, lastart, TRUE);
if (!art_data(last_cached+1, lastart, TRUE, TRUE)) {
last_cached = old_last_cached;
return FALSE;
}
cached_all_in_range = TRUE;
}
if (first_cached > absfirst) {
if (datasrc->ov_opened)
ov_data(absfirst, first_cached-1, TRUE);
else
art_data(absfirst, first_cached-1, TRUE, TRUE);
/* If we got interrupted, make a quick exit */
if (first_cached > absfirst) {
last_cached = old_last_cached;
return FALSE;
}
}
/* We're all done threading the group, so if the current article is
** still in doubt, tell them it's missing. */
if (curr_artp && !(curr_artp->flags & AF_CACHED) && !input_pending())
pushchar('\f' | 0200);
/* A completely empty group needs a count & a sort */
if (gmode != 's' && !obj_count && !selected_only)
thread_grow();
return TRUE;
}
bool
cache_unread_arts()
{
if (last_cached >= lastart)
return TRUE;
setspin(SPIN_BACKGROUND);
return art_data(last_cached+1, lastart, TRUE, FALSE);
}
#endif
bool
art_data(first, last, cheating, all_articles)
ART_NUM first, last;
bool_int cheating;
bool_int all_articles;
{
register ART_NUM i;
ART_NUM expected_i = first;
int cachemask = (ThreadedGroup ? AF_THREADED : AF_CACHED)
+ (all_articles? 0 : AF_UNREAD);
int cachemask2 = (all_articles? 0 : AF_UNREAD);
if (cheating)
setspin(SPIN_BACKGROUND);
else {
#ifdef SUPPORT_NNTP
int lots2do = ((datasrc->flags & DF_REMOTE)? netspeed : 20) * 25;
#else
int lots2do = 20 * 25;
#endif
setspin(spin_estimate > lots2do? SPIN_BARGRAPH : SPIN_FOREGROUND);
}
/*assert(first >= absfirst && last <= lastart);*/
for (i = article_first(first); i <= last; i = article_next(i)) {
if ((article_ptr(i)->flags & cachemask) ^ cachemask2)
continue;
spin_todo -= i - expected_i;
expected_i = i + 1;
/* This parses the header which will cache/thread the article */
(void) parseheader(i);
if (int_count) {
int_count = 0;
break;
}
if (cheating) {
if (input_pending())
break;
/* If the current article is no longer a '?', let them know. */
if (curr_artp != sentinel_artp) {
pushchar('\f' | 0200);
break;
}
}
}
setspin(SPIN_POP);
if (i > last)
i = last;
if (i > last_cached)
last_cached = i;
if (i == last) {
if (first < first_cached)
first_cached = first;
return TRUE;
}
return FALSE;
}
bool
cache_range(first,last)
ART_NUM first;
ART_NUM last;
{
bool success = TRUE;
bool all_arts = (sel_rereading || thread_always);
ART_NUM count = 0;
if (sel_rereading && !cached_all_in_range) {
first_cached = first;
last_cached = first-1;