-
Notifications
You must be signed in to change notification settings - Fork 1
/
art.c
1234 lines (1192 loc) · 29.9 KB
/
art.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
/* art.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 "trn.h"
#include "hash.h"
#include "ngdata.h"
#include "nntpclient.h"
#include "datasrc.h"
#include "addng.h"
#include "nntp.h"
#include "ngstuff.h"
#include "cache.h"
#include "bits.h"
#include "head.h"
#include "help.h"
#include "search.h"
#include "artio.h"
#include "ng.h"
#include "final.h"
#include "artstate.h"
#include "rcstuff.h"
#include "mime.h"
#include "term.h"
#include "env.h"
#include "util.h"
#include "util2.h"
#include "utf.h"
#include "sw.h"
#include "kfile.h"
#include "decode.h"
#include "backpage.h"
#include "intrp.h"
#include "rthread.h"
#include "rt-select.h"
#include "rt-util.h"
#include "rt-wumpus.h"
#include "charsubst.h"
#ifdef SCAN_ART
#include "scanart.h"
#endif
#ifdef SCORE
#include "score.h" /* for sc_lookahead() */
#endif
#ifdef USE_TK
#include "tkstuff.h"
#include "tktree.h"
#endif
#include "color.h"
#include "INTERN.h"
#include "art.h"
#include "artstate.h" /* somebody has to do it */
#define LINE_PTR(pos) (artbuf + (pos) - htype[PAST_HEADER].minpos)
#define LINE_OFFSET(ptr) ((ptr) - artbuf + htype[PAST_HEADER].minpos)
/* page_switch() return values */
#define PS_NORM 0
#define PS_ASK 1
#define PS_RAISE 2
#define PS_TOEND 3
bool special = FALSE; /* is next page special length? */
int slines = 0; /* how long to make page when special */
ART_POS restart = 0; /* if nonzero, the place where last */
/* line left off on line split */
ART_POS alinebeg; /* where in file current line began */
int more_prompt_col; /* non-zero when the more prompt is indented */
ART_LINE isrchline = 0; /* last line to display */
#ifdef INNERSEARCH
COMPEX gcompex; /* in article search pattern */
#endif
bool firstpage; /* is this the 1st page of article? */
bool continuation; /* this line/header is being continued */
void
art_init()
{
#ifdef INNERSEARCH
init_compex(&gcompex);
#endif
}
int
do_article()
{
register char* s;
bool hide_this_line = FALSE; /* hidden header line? */
bool restart_color;
ART_LINE linenum; /* line # on page, 1 origin */
#ifdef ULSMARTS
bool under_lining = FALSE; /* are we underlining a word? */
#endif
#ifndef USE_UTF_HACK
register
#endif
char* bufptr = art_line; /* pointer to input buffer */
register int outpos; /* column position of output */
static char prompt_buf[64]; /* place to hold prompt */
bool notesfiles = FALSE; /* might there be notesfiles junk? */
char oldmode = mode;
register int outputok = TRUE;
#ifdef SUPPORT_NNTP
if (datasrc->flags & DF_REMOTE)
artsize = raw_artsize = nntp_artsize();
else
#endif
{
if (fstat(fileno(artfp),&filestat)) /* get article file stats */
return DA_CLEAN;
if (!S_ISREG(filestat.st_mode))
return DA_NORM;
artsize = raw_artsize = filestat.st_size;
}
#ifdef SCORE
#ifdef USE_TK
if (ttcl_running)
ttcl_set_int("score_curvar",sc_score_art((int)art,TRUE));
#endif
#endif
sprintf(prompt_buf, mousebar_cnt>3? "%%sEnd of art %ld (of %ld) %%s[%%s]"
: "%%sEnd of article %ld (of %ld) %%s-- what next? [%%s]",
(long)art,(long)lastart); /* format prompt string */
prompt = prompt_buf;
int_count = 0; /* interrupt count is 0 */
if ((firstpage = (topline < 0)) != 0) {
parseheader(art);
mime_SetArticle();
clear_artbuf();
seekart(artbuf_seek = htype[PAST_HEADER].minpos);
}
term_scrolled = 0;
#ifdef USE_TK
if (ThreadedGroup && ttk_running)
ttk_draw_tree(curr_artp, 0, 0);
#endif
for (;;) { /* for each page */
if (ThreadedGroup && max_tree_lines)
init_tree(); /* init tree display */
assert(art == openart);
if (do_fseek) {
parseheader(art); /* make sure header is ours */
if (!*artbuf) {
mime_SetArticle();
artbuf_seek = htype[PAST_HEADER].minpos;
}
artpos = vrdary(artline);
if (artpos < 0)
artpos = -artpos; /* labs(), anyone? */
if (firstpage)
artpos = (ART_POS)0;
if (artpos < htype[PAST_HEADER].minpos) {
in_header = SOME_LINE;
seekart(htype[PAST_HEADER].minpos);
seekartbuf(htype[PAST_HEADER].minpos);
}
else {
seekart(artbuf_seek);
seekartbuf(artpos);
}
do_fseek = FALSE;
restart = 0;
}
linenum = 1;
#if 0 /* This causes a bug (headers displayed twice sometimes when you press v then ^R) */
if (!do_hiding)
is_mime = FALSE;
#endif
if (firstpage) {
if (firstline) {
interp(art_line,sizeof art_line,firstline);
linenum += tree_puts(art_line,linenum+topline,0);
} else {
ART_NUM i;
int selected, unseen;
selected = (curr_artp->flags & AF_SEL);
unseen = article_unread(art)? 1 : 0;
sprintf(art_line,"%s%s #%ld",ngname,moderated,(long)art);
if (selected_only) {
i = selected_count - (unseen && selected);
sprintf(art_line+strlen(art_line)," (%ld + %ld more)",
(long)i,(long)ngptr->toread - selected_count
- (!selected && unseen));
}
else if ((i = (ART_NUM)(ngptr->toread - unseen)) != 0
|| (!ThreadedGroup && dmcount)) {
sprintf(art_line+strlen(art_line),
" (%ld more)",(long)i);
}
if (!ThreadedGroup && dmcount)
sprintf(art_line+strlen(art_line)-1,
" + %ld Marked to return)",(long)dmcount);
linenum += tree_puts(art_line,linenum+topline,0);
}
start_header(art);
forcelast = FALSE; /* we will have our day in court */
restart = 0;
artline = 0; /* start counting lines */
artpos = 0;
vwtary(artline,artpos); /* remember pos in file */
}
for (restart_color = 1; /* linenum already set */
innersearch? (in_header || innermore())
: special? (linenum < slines)
: (firstpage && !in_header)? (linenum < initlines)
: (linenum < tc_LINES);
linenum++) { /* for each line on page */
if (int_count) { /* exit via interrupt? */
newline(); /* get to left margin */
int_count = 0; /* reset interrupt count */
set_mode(gmode,oldmode);
special = FALSE;
return DA_NORM; /* skip out of loops */
}
if (restart) { /* did not finish last line? */
bufptr = LINE_PTR(restart);/* then start again here */
restart = 0; /* and reset the flag */
continuation = 1;
if (restart_color && do_hiding && !in_header)
maybe_set_color(bufptr, 1);
}
else if (in_header && *(bufptr = headbuf + artpos))
continuation = *bufptr == ' ' || *bufptr == '\t';
else {
if ((bufptr = readartbuf(auto_view_inline)) == NULL) {
special = FALSE;
if (innersearch)
(void)innermore();
break;
}
if (do_hiding && !in_header)
continuation = maybe_set_color(bufptr, restart_color);
else
continuation = 0;
}
alinebeg = artpos; /* remember where we began */
restart_color = 0;
if (in_header) {
hide_this_line = parseline(bufptr,do_hiding,hide_this_line);
if (!in_header) {
linenum += finish_tree(linenum+topline);
end_header();
seekart(artbuf_seek);
}
} else if (notesfiles && do_hiding && !continuation
&& *bufptr == '#' && isupper(bufptr[1])
&& bufptr[2] == ':' ) {
if ((bufptr = readartbuf(auto_view_inline)) == NULL)
break;
for (s = bufptr; *s && *s != '\n' && *s != '!'; s++) ;
if (*s != '!')
readartbuf(auto_view_inline);
mime_SetArticle();
clear_artbuf(); /* exclude notesfiles droppings */
artbuf_seek = htype[PAST_HEADER].minpos = tellart();
hide_this_line = TRUE; /* and do not print either */
notesfiles = FALSE;
}
#ifdef CUSTOMLINES
if (hideline && !continuation && execute(&hide_compex,bufptr))
hide_this_line = TRUE;
#endif
if (in_header && do_hiding && (htype[in_header].flags & HT_MAGIC)) {
switch (in_header) {
case NGS_LINE:
if ((s = index(bufptr,'\n')) != NULL)
*s = '\0';
hide_this_line = (index(bufptr,',') == NULL)
&& strEQ(bufptr+12, ngname);
if (s != NULL)
*s = '\n';
break;
case EXPIR_LINE:
if (!(htype[EXPIR_LINE].flags & HT_HIDE)) {
s = bufptr + htype[EXPIR_LINE].length + 1;
hide_this_line = *s != ' ' || s[1] == '\n';
}
break;
case FROM_LINE:
if ((s = index(bufptr,'\n')) != NULL
&& s-bufptr < sizeof art_line)
safecpy(art_line,bufptr,s-bufptr+1);
else
safecpy(art_line,bufptr,sizeof art_line);
if ((s = extract_name(art_line+6)) != NULL) {
strcpy(art_line+6,s);
bufptr = art_line;
}
break;
#ifdef HAS_STRFTIME
case DATE_LINE:
if (curr_artp->date != -1) {
strncpy(art_line,bufptr,6);
strftime(art_line+6, (sizeof art_line)-6,
getval("LOCALTIMEFMT", LOCALTIMEFMT),
localtime(&curr_artp->date));
bufptr = art_line;
}
break;
#endif
}
}
if (in_header == SUBJ_LINE && do_hiding
&& (htype[SUBJ_LINE].flags & HT_MAGIC)) { /* handle the subject */
s = get_cached_line(artp, SUBJ_LINE, FALSE);
if (s && continuation) {
/* continuation lines were already output */
linenum--;
}
else {
int length = strlen(bufptr+1);
notesfiles = instr(&bufptr[length-10]," - (nf", TRUE)!=NULL;
artline++;
if (!s)
bufptr += (continuation? 0 : 9);
else
bufptr = s;
/* tree_puts(, ,1) underlines subject */
linenum += tree_puts(bufptr,linenum+topline,1)-1;
}
}
else if (hide_this_line && do_hiding) { /* do not print line? */
linenum--; /* compensate for linenum++ */
if (!in_header)
hide_this_line = FALSE;
}
else if (in_header) {
artline++;
linenum += tree_puts(bufptr,linenum+topline,0)-1;
}
else { /* just a normal line */
if (outputok && erase_each_line)
erase_line(0);
if (highlight == artline) { /* this line to be highlit? */
if (marking == STANDOUT) {
#ifdef NOFIREWORKS
if (erase_screen)
no_sofire();
#endif
standout();
}
else {
#ifdef NOFIREWORKS
if (erase_screen)
no_ulfire();
#endif
underline();
carriage_return();
}
if (*bufptr == '\n')
putchar(' ');
}
outputok = !hide_everything; /* registerize it, hopefully */
#ifdef CUSTOMLINES
if (pagestop && !continuation && execute(&page_compex,bufptr))
linenum = 32700;
#endif
for (outpos = 0; outpos < tc_COLS; ) { /* while line has room */
if (AT_NORM_CHAR(bufptr)) { /* normal char? */
#ifdef ULSMARTS
if (*bufptr == '_') {
if (bufptr[1] == '\b') {
if (outputok && !under_lining
&& highlight != artline) {
under_lining++;
if (tc_UG) {
if (bufptr != buf && bufptr[-1]==' ') {
outpos--;
backspace();
}
}
underline();
}
bufptr += 2;
}
}
else {
if (under_lining) {
under_lining = 0;
un_underline();
if (tc_UG) {
outpos++;
if (*bufptr == ' ')
goto skip_put;
}
}
}
#endif
/* handle rot-13 if wanted */
if (rotate && !in_header && isalpha(*bufptr)) {
if (outputok) {
if ((*bufptr & 31) <= 13)
putchar(*bufptr+13);
else
putchar(*bufptr-13);
}
outpos++;
}
else {
#ifdef CHARSUBST
register int i;
#ifdef USE_UTF_HACK
if (outpos + visual_width_at(bufptr) > tc_COLS) { /* will line overflow? */
newline();
outpos = 0;
linenum++;
}
i = put_char_adv(&bufptr, outputok);
bufptr--;
#else /* !USE_UTF_HACK */
i = putsubstchar(*bufptr, tc_COLS - outpos, outputok);
#endif /* USE_UTF_HACK */
if (i < 0) {
outpos += -i - 1;
break;
}
outpos += i;
#else
#ifdef USE_UTF_HACK
outpos += put_char_adv(&bufptr, outputok);
bufptr--;
#else /* !USE_UTF_HACK */
if (outputok)
putchar(*bufptr);
outpos++;
#endif /* USE_UTF_HACK */
#endif /* CHARSUBST */
}
if (*tc_UC && ((highlight==artline && marking == STANDOUT)
#ifdef ULSMARTS
|| under_lining
#endif
)) {
backspace();
underchar();
}
skip_put:
bufptr++;
}
else if (AT_NL(*bufptr) || !*bufptr) { /* newline? */
#ifdef ULSMARTS
if (under_lining) {
under_lining = 0;
un_underline();
}
#endif
#ifdef DEBUG
if (debug & DEB_INNERSRCH && outpos < tc_COLS - 6) {
standout();
printf("%4d",artline);
un_standout();
}
#endif
if (outputok)
newline();
restart = 0;
outpos = 1000; /* signal normal \n */
}
else if (*bufptr == '\t') { /* tab? */
int incpos = 8 - outpos % 8;
if (outputok) {
if (tc_GT)
putchar(*bufptr);
else
while (incpos--) putchar(' ');
}
bufptr++;
outpos += 8 - outpos % 8;
}
else if (*bufptr == '\f') { /* form feed? */
if (outpos+2 > tc_COLS)
break;
if (outputok)
fputs("^L",stdout);
if (bufptr == LINE_PTR(alinebeg) && highlight != artline)
linenum = 32700;
/* how is that for a magic number? */
bufptr++;
outpos += 2;
}
else { /* other control char */
if (dont_filter_control) {
if (outputok)
putchar(*bufptr);
outpos++;
}
else if (*bufptr != '\r' || bufptr[1] != '\n') {
if (outpos+2 > tc_COLS)
break;
if (outputok) {
putchar('^');
if (highlight == artline && *tc_UC
&& marking == STANDOUT) {
backspace();
underchar();
putchar((*bufptr & 0x7F) ^ 0x40);
backspace();
underchar();
}
else
putchar((*bufptr & 0x7F) ^ 0x40);
}
outpos += 2;
}
bufptr++;
}
} /* end of column loop */
if (outpos < 1000) { /* did line overflow? */
restart = LINE_OFFSET(bufptr);/* restart here next time */
if (outputok) {
if (!tc_AM || tc_XN || outpos < tc_COLS)
newline();
else
term_line++;
}
if (AT_NL(*bufptr)) /* skip the newline */
restart = 0;
}
/* handle normal end of output line formalities */
if (highlight == artline) {
/* were we highlighting line? */
if (marking == STANDOUT)
un_standout();
else
un_underline();
carriage_return();
highlight = -1; /* no more we are */
/* in case terminal highlighted rest of line earlier */
/* when we did an eol with highlight turned on: */
if (erase_each_line)
erase_eol();
}
artline++; /* count the line just printed */
if (artline - tc_LINES + 1 > topline)
/* did we just scroll top line off? */
topline = artline - tc_LINES + 1;
/* then recompute top line # */
}
/* determine actual position in file */
if (restart) /* stranded somewhere in the buffer? */
artpos += restart - alinebeg;
else if (in_header)
artpos = index(headbuf+artpos,'\n') - headbuf + 1;
else
artpos = artbuf_pos + htype[PAST_HEADER].minpos;
vwtary(artline,artpos); /* remember pos in file */
} /* end of line loop */
#ifdef INNERSEARCH
innersearch = 0;
if (hide_everything) {
*buf = hide_everything;
hide_everything = 0;
goto fake_command;
}
#endif
if (linenum >= 32700) /* did last line have formfeed? */
vwtary(artline-1,-vrdary(artline-1));
/* remember by negating pos in file */
special = FALSE; /* end of page, so reset page length */
firstpage = FALSE; /* and say it is not 1st time thru */
highlight = -1;
/* extra loop bombout */
#ifdef SUPPORT_NNTP
if (artsize < 0 && (raw_artsize = nntp_artsize()) >= 0)
artsize = raw_artsize-artbuf_seek+artbuf_len+htype[PAST_HEADER].minpos;
recheck_pager:
if (do_hiding && artbuf_pos == artbuf_len) {
/* If we're filtering we need to figure out if any
* remaining text is going to vanish or not. */
long seekpos = artbuf_pos + htype[PAST_HEADER].minpos;
readartbuf(FALSE);
seekartbuf(seekpos);
}
#endif
if (artpos == artsize) {/* did we just now reach EOF? */
color_default();
set_mode(gmode,oldmode);
return DA_NORM; /* avoid --MORE--(100%) */
}
/* not done with this article, so pretend we are a pager */
reask_pager:
if (term_line >= tc_LINES) {
term_scrolled += term_line - tc_LINES + 1;
term_line = tc_LINES-1;
}
more_prompt_col = term_col;
unflush_output(); /* disable any ^O in effect */
maybe_eol();
color_default();
#ifdef SUPPORT_NNTP
if (artsize < 0)
strcpy(cmd_buf,"?");
else
#endif
sprintf(cmd_buf,"%ld",(long)(artpos*100/artsize));
#ifdef CHARSUBST
sprintf(buf,"%s--MORE--(%s%%)",current_charsubst(),cmd_buf);
#else
sprintf(buf,"--MORE--(%s%%)",cmd_buf);
#endif
outpos = term_col + strlen(buf);
draw_mousebar(tc_COLS - (term_line == tc_LINES-1? outpos+5 : 0), 1);
color_string(COLOR_MORE,buf);
fflush(stdout);
term_col = outpos;
eat_typeahead();
#ifdef DEBUG
if (debug & DEB_CHECKPOINTING) {
printf("(%d %d %d)",checkcount,linenum,artline);
fflush(stdout);
}
#endif
if (checkcount >= docheckwhen && linenum == tc_LINES
&& (artline > 40 || checkcount >= docheckwhen+10)) {
/* while he is reading a whole page */
/* in an article he is interested in */
checkcount = 0;
checkpoint_newsrcs(); /* update all newsrcs */
#ifdef KILLFILES
update_thread_kfile();
#endif
}
cache_until_key();
#ifdef SUPPORT_NNTP
if (artsize < 0 && (raw_artsize = nntp_artsize()) >= 0) {
artsize = raw_artsize-artbuf_seek+artbuf_len+htype[PAST_HEADER].minpos;
goto_xy(more_prompt_col,term_line);
goto recheck_pager;
}
#endif
set_mode(gmode,'p');
getcmd(buf);
if (errno) {
if (tc_LINES < 100 && !int_count)
*buf = '\f';/* on CONT fake up refresh */
else {
*buf = 'q'; /* on INTR or paper just quit */
}
}
erase_line(erase_screen && erase_each_line);
fake_command: /* used by innersearch */
color_default();
output_chase_phrase = TRUE;
/* parse and process pager command */
if (mousebar_cnt)
clear_rest();
switch (page_switch()) {
case PS_ASK: /* reprompt "--MORE--..." */
goto reask_pager;
case PS_RAISE: /* reparse on article level */
set_mode(gmode,oldmode);
return DA_RAISE;
case PS_TOEND: /* fast pager loop exit */
set_mode(gmode,oldmode);
return DA_TOEND;
case PS_NORM: /* display more article */
break;
}
} /* end of page loop */
}
int
maybe_set_color(cp, backsearch)
char* cp;
bool_int backsearch;
{
register char ch = (cp == artbuf || cp == art_line? 0 : cp[-1]);
if (ch == '\001')
color_object(COLOR_MIMEDESC, 0);
else if (ch == '\002')
color_object(COLOR_MIMESEP, 0);
else if (ch == WRAPPED_NL) {
if (backsearch) {
while (cp > artbuf && cp[-1] != '\n') cp--;
maybe_set_color(cp, 0);
}
return 1;
}
else {
while (*cp == ' ' || *cp == '\t') cp++;
if (index(">}]#!:|", *cp))
color_object(COLOR_CITEDTEXT, 0);
else
color_object(COLOR_BODYTEXT, 0);
}
return 0;
}
/* process pager commands */
int
page_switch()
{
register char* s;
switch (*buf) {
case '!': /* shell escape */
escapade();
return PS_ASK;
#ifdef INNERSEARCH
case Ctl('i'): {
ART_LINE i = artline;
ART_POS pos;
gline = 3;
s = LINE_PTR(alinebeg);
while (AT_NL(*s) && i >= topline) {
pos = vrdary(--i);
if (pos < 0)
pos = -pos;
if (pos < htype[PAST_HEADER].minpos)
break;
seekartbuf(pos);
if ((s = readartbuf(FALSE)) == NULL) {
s = LINE_PTR(alinebeg);
break;
}
}
sprintf(cmd_buf,"^[^%c\n]",*s);
compile(&gcompex,cmd_buf,TRUE,TRUE);
goto caseG;
}
case Ctl('g'):
gline = 3;
compile(&gcompex,"^Subject:",TRUE,TRUE);
goto caseG;
case 'g': /* in-article search */
if (!finish_command(FALSE))/* get rest of command */
return PS_ASK;
s = buf+1;
if (isspace(*s)) s++;
if ((s = compile(&gcompex,s,TRUE,TRUE)) != NULL) {
/* compile regular expression */
printf("\n%s\n",s) FLUSH;
termdown(2);
return PS_ASK;
}
erase_line(0); /* erase the prompt */
/* FALL THROUGH */
caseG:
case 'G': {
ART_POS start_where;
bool success;
char* nlptr;
char ch;
if (gline < 0 || gline > tc_LINES-2)
gline = tc_LINES-2;
#ifdef DEBUG
if (debug & DEB_INNERSRCH) {
printf("Start here? %d >=? %d\n",topline + gline + 1,artline)
FLUSH;
termdown(1);
}
#endif
if (*buf == Ctl('i') || topline+gline+1 >= artline)
start_where = artpos;
/* in case we had a line wrap */
else {
start_where = vrdary(topline+gline+1);
if (start_where < 0)
start_where = -start_where;
}
if (start_where < htype[PAST_HEADER].minpos)
start_where = htype[PAST_HEADER].minpos;
seekartbuf(start_where);
innerlight = 0;
innersearch = 0; /* assume not found */
while ((s = readartbuf(FALSE)) != NULL) {
if ((nlptr = index(s,'\n')) != NULL) {
ch = *++nlptr;
*nlptr = '\0';
}
#ifdef DEBUG
if (debug & DEB_INNERSRCH)
printf("Test %s\n",s) FLUSH;
#endif
success = execute(&gcompex,s) != NULL;
if (nlptr)
*nlptr = ch;
if (success) {
innersearch = artbuf_pos + htype[PAST_HEADER].minpos;
break;
}
}
if (!innersearch) {
seekartbuf(artpos);
fputs("(Not found)",stdout) FLUSH;
term_col = 11;
return PS_ASK;
}
#ifdef DEBUG
if (debug & DEB_INNERSRCH) {
printf("On page? %ld <=? %ld\n",(long)innersearch,(long)artpos)
FLUSH;
termdown(1);
}
#endif
if (innersearch <= artpos) { /* already on page? */
if (innersearch < artpos) {
artline = topline+1;
while (vrdary(artline) < innersearch)
artline++;
}
highlight = artline - 1;
#ifdef DEBUG
if (debug & DEB_INNERSRCH) {
printf("@ %d\n",highlight) FLUSH;
termdown(1);
}
#endif
topline = highlight - gline;
if (topline < -1)
topline = -1;
*buf = '\f'; /* fake up a refresh */
innersearch = 0;
return page_switch();
}
else { /* who knows how many lines it is? */
do_fseek = TRUE;
hide_everything = '\f';
}
return PS_NORM;
}
#else
case 'g': case 'G': case Ctl('g'):
notincl("g");
return PS_ASK;
#endif
case '\n': /* one line down */
case '\r':
special = TRUE;
slines = 2;
return PS_NORM;
case 'X':
rotate = !rotate;
/* FALL THROUGH */
case 'l':
case '\f': /* refresh screen */
refresh_screen:
#ifdef DEBUG
if (debug & DEB_INNERSRCH) {
printf("Topline = %d",topline) FLUSH;
fgets(buf, sizeof buf, stdin);
}
#endif
clear();
do_fseek = TRUE;
artline = topline;
if (artline < 0)
artline = 0;
firstpage = (topline < 0);
return PS_NORM;
#ifdef INNERSEARCH
case Ctl('e'):
#ifdef SUPPORT_NNTP
if (artsize < 0) {
nntp_finishbody(FB_OUTPUT);
raw_artsize = nntp_artsize();
artsize = raw_artsize-artbuf_seek+artbuf_len+htype[PAST_HEADER].minpos;
}
#endif
if (do_hiding) {
seekartbuf(artsize);
seekartbuf(artpos);
}
topline = artline;
innerlight = artline - 1;
innersearch = artsize;
gline = 0;
hide_everything = 'b';
return PS_NORM;
#endif
case 'B': /* one line up */
if (topline < 0)
break;
if (*tc_IL && *tc_HO) {
ART_POS pos;
home_cursor();
insert_line();
carriage_return();
pos = vrdary(topline-1);
if (pos < 0)
pos = -pos;
if (pos >= htype[PAST_HEADER].minpos) {
seekartbuf(pos);
if ((s = readartbuf(FALSE)) != NULL) {
artpos = vrdary(topline);
if (artpos < 0)
artpos = -artpos;
maybe_set_color(s, 1);
for (pos = artpos - pos; pos-- && !AT_NL(*s); s++)
putchar(*s);
color_default();
putchar('\n') FLUSH;
topline--;
artpos = vrdary(--artline);
if (artpos < 0)
artpos = -artpos;
seekartbuf(artpos);
alinebeg = vrdary(artline-1);
if (alinebeg < 0)
alinebeg = -alinebeg;
goto_xy(0,artline-topline);
erase_line(0);
return PS_ASK;
}
}
}
/* FALL THROUGH */
case 'b':
case Ctl('b'): { /* back up a page */
ART_LINE target;
if (erase_each_line)
home_cursor();
else
clear();
do_fseek = TRUE; /* reposition article file */
if (*buf == 'B')
target = topline - 1;
else {
target = topline - (tc_LINES - 2);
if (marking && (marking_areas & BACKPAGE_MARKING))
highlight = topline;
}
artline = topline;
if (artline >= 0) do {
artline--;
} while(artline >= 0 && artline > target && vrdary(artline-1) >= 0);
topline = artline; /* remember top line of screen */
/* (line # within article file) */
if (artline < 0)
artline = 0;
firstpage = (topline < 0);
return PS_NORM;
}
case 'H': /* help */
help_page();
return PS_ASK;
case 't': /* output thread data */
page_line = 1;
entire_tree(curr_artp);
return PS_ASK;
case '_':
if (!finish_dblchar())
return PS_ASK;
switch (buf[1] & 0177) {
#ifdef CHARSUBST
case 'C':
if (!*(++charsubst))
charsubst = charsets;
goto refresh_screen;
#endif
default:
break;
}
goto leave_pager;
case '\0': /* treat break as 'n' */
*buf = 'n';
/* FALL THROUGH */
case 'a': case 'A':
case 'e':
case 'k': case 'K': case 'J':
case 'n': case 'N': case Ctl('n'):
case 'F':
case 'R':
case 's': case 'S':
case 'T':
case 'u':
case 'w': case 'W':
case '|':
mark_as_read(artp); /* mark article as read */