-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdisplay.c
1827 lines (1758 loc) · 42.9 KB
/
display.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
/* $Id: display.c,v 1.21 2003/03/08 01:27:05 amura Exp $ */
/*
* The functions in this file handle redisplay. The
* redisplay system knows almost nothing about the editing
* process; the editing functions do, however, set some
* hints to eliminate a lot of the grinding. There is more
* that can be done; the "vtputc" interface is a real
* pig. Two conditional compilation flags; the GOSLING
* flag enables dynamic programming redisplay, using the
* algorithm published by Jim Gosling in SIGOA. The MEMMAP
* changes things around for memory mapped video. With
* both off, the terminal is a VT52.
*/
#include "config.h" /* 90.12.20 by S.Yoshida */
#include "def.h"
#include "kbd.h"
/*
* You can change these back to the types
* implied by the name if you get tight for space. If you
* make both of them "int" you get better code on the VAX.
* They do nothing if this is not Gosling redisplay, except
* for change the size of a structure that isn't used.
* A bit of a cheat.
*/
/* These defines really belong in sysdef.h */
#ifndef XCHAR
# define XCHAR int
# define XSHORT int
#endif
#ifdef STANDOUT_GLITCH
# ifdef WITHOUT_TERMCAP
# undef STANDOUT_GLITCH
# else
extern int SG; /* number of standout glitches */
# endif /* WITHOUT_TERMCAP */
#endif /* STANDOUT_GLITCH */
#ifdef GOSLING
# undef GOSLING /* GOSLING too slow? */
#endif
/*
* A video structure always holds
* an array of characters whose length is equal to
* the longest line possible. Only some of this is
* used if "ncol" isn't the same as "NCOL".
*/
typedef struct {
short v_hash; /* Hash code, for compares. */
short v_flag; /* Flag word. */
short v_color; /* Color of the line. */
XSHORT v_cost; /* Cost of display. */
#ifndef ZEROARRAY
char v_text[1]; /* The actual characters. */
#else
char v_text[]; /* The actual characters. */
#endif
} VIDEO;
#define MEM_ROUND(n) (((n)+7)&~7) /* Memory round bound for 8 bytes*/
#ifdef SS_SUPPORT
#define SIZEOF_VIDEO MEM_ROUND(sizeof(VIDEO) + vncol*2)
#define v_sub(n) v_text[(n)+vncol] /* 2nd Character of HANKANA */
#else /* SS_SUPPORT */
#define SIZEOF_VIDEO MEM_ROUND(sizeof(VIDEO) + vncol)
#endif
#define VFCHG 0x0001 /* Changed. */
#define VFHBAD 0x0002 /* Hash and cost are bad. */
#define VFEXT 0x0004 /* extended line (beond ncol) */
/*
* SCORE structures hold the optimal
* trace trajectory, and the cost of redisplay, when
* the dynamic programming redisplay code is used.
* If no fancy redisplay, this isn't used. The trace index
* fields can be "char", and the score a "short", but
* this makes the code worse on the VAX.
*/
typedef struct {
XCHAR s_itrace; /* "i" index for track back. */
XCHAR s_jtrace; /* "j" index for trace back. */
XSHORT s_cost; /* Display cost. */
} SCORE;
int sgarbf = TRUE; /* TRUE if screen is garbage. */
static int vtrow = 0; /* Virtual cursor row. */
static int vtcol = 0; /* Virtual cursor column. */
int tthue = CNONE; /* Current color. */
int ttrow = HUGE; /* Physical cursor row. */
int ttcol = HUGE; /* Physical cursor column. */
int tttop = HUGE; /* Top of scroll region. */
int ttbot = HUGE; /* Bottom of scroll region. */
extern int ncol;
extern int nrow;
static int vncol = 0;
static int vnrow = 0;
static VIDEO **vscreen = NULL; /* Edge vector, virtual. */
static VIDEO **pscreen = NULL; /* Edge vector, physical. */
static VIDEO *video = NULL; /* Actual screen data. */
static VIDEO *blanks = NULL; /* Blank line image. */
#ifdef KANJI /* 90.01.29 by S.Yoshida */
#define ASCII 0
#define K1ST 1
#define K2ND 2
#define HAN1ST 3
#define HOJO1ST 4
#define HOJO2ND 5
static int vtkattr = ASCII;
#endif /* KANJI */
/*
* Some predeclerations to make ANSI compilers happy
*/
VOID vtinit _PRO((void));
VOID vttidy _PRO((void));
VOID vtputc _PRO((int));
VOID update _PRO((void));
static VOID vtmove _PRO((int, int));
static VOID vtmarkyen _PRO((int));
static VOID vteeol _PRO((void));
static VOID ucopy _PRO((VIDEO *, VIDEO *));
static VOID uline _PRO((int, VIDEO *, VIDEO *));
static VOID modeline _PRO((WINDOW *));
#ifdef ADDFUNC
static VOID moderatio _PRO((WINDOW *));
#endif
#ifdef GOSLING
/*
* This matrix is written as an array because
* we do funny things in the "setscores" routine, which
* is very compute intensive, to make the subscripts go away.
* It would be "SCORE score[vnrow][vnrow]" in old speak.
* Look at "setscores" to understand what is up.
*/
static VOID hash _PRO((void));
static VOID setscores _PRO((void));
static VOID traceback _PRO((void));
static SCORE *score = NULL;
#endif
VOID
vtsetsize(col, row)
int col, row;
{
register VIDEO *vp;
register int i;
if (col<=vncol && row<=vnrow)
return;
vncol = col;
vnrow = row;
if (vscreen != NULL)
free(vscreen);
if (pscreen != NULL)
free(pscreen);
if (video != NULL)
free(video);
if (blanks != NULL)
free(blanks);
vscreen = malloc(sizeof(VIDEO*)*(vnrow-1));
pscreen = malloc(sizeof(VIDEO*)*(vnrow-1));
video = malloc(SIZEOF_VIDEO*2*(vnrow-1));
blanks = malloc(SIZEOF_VIDEO);
if (vscreen==NULL || pscreen==NULL || video==NULL || blanks==NULL)
panic("Cannot allocate video buffer");
bzero(video, SIZEOF_VIDEO*2*(vnrow-1));
bzero(blanks, SIZEOF_VIDEO);
#ifdef GOSLING
if (score != NULL)
free(score);
score = malloc(sizeof(SCORE)*vnrow*vnrow);
if (score == NULL)
panic("Cannot allocate video buffer");
bzero(score, sizeof(SCORE)*vnrow*vnrow);
#endif
vp = video;
for (i=0; i<vnrow-1; ++i) {
vscreen[i] = (VIDEO*)vp;
vp = (VIDEO*)((char*)vp +SIZEOF_VIDEO);
pscreen[i] = (VIDEO*)vp;
vp = (VIDEO*)((char*)vp +SIZEOF_VIDEO);
}
blanks->v_color = CTEXT;
for (i=0; i<vncol; ++i) {
#ifdef SS_SUPPORT /* 92.11.21 by S.Sasaki */
blanks->v_sub(i) = 0;
#endif /* SS_SUPPORT */
blanks->v_text[i] = ' ';
}
}
/*
* Initialize the data structures used
* by the display code. The edge vectors used
* to access the screens are set up. The operating
* system's terminal I/O channel is set up. Fill the
* "blanks" array with ASCII blanks. The rest is done
* at compile time. The original window is marked
* as needing full update, and the physical screen
* is marked as garbage, so all the right stuff happens
* on the first call to redisplay.
*/
VOID
vtinit()
{
int col, row;
ttopen();
ttinit();
col = ncol;
row = nrow;
if (col < NCOL)
col = NCOL;
if (row < NROW)
row = NROW;
vtsetsize(col, row);
}
/*
* Tidy up the virtual display system
* in anticipation of a return back to the host
* operating system. Right now all we do is position
* the cursor to the last line, erase the line, and
* close the terminal channel.
*/
VOID
vttidy()
{
ttcolor(CTEXT);
ttnowindow(); /* No scroll window. */
ttmove(nrow-1, 0); /* Echo line. */
tteeol();
tttidy();
ttflush();
ttclose();
}
/*
* Move the virtual cursor to an origin
* 0 spot on the virtual display screen. I could
* store the column as a character pointer to the spot
* on the line, which would make "vtputc" a little bit
* more efficient. No checking for errors.
*/
static VOID
vtmove(row, col)
int row, col;
{
vtrow = row;
vtcol = col;
#ifdef KANJI /* 90.01.29 by S.Yoshida */
vtkattr = ASCII;
#endif /* KANJI */
}
/*
* Write a character to the virtual display,
* dealing with long lines and the display of unprintable
* things like control characters. Also expand tabs every 8
* columns. This code only puts printing characters into
* the virtual display image. Special care must be taken when
* expanding tabs. On a screen whose width is not a multiple
* of 8, it is possible for the virtual cursor to hit the
* right margin before the next tab stop is reached. This
* makes the tab code loop if you are not careful.
* Three guesses how we found this.
*/
VOID
vtputc(c)
register int c;
{
register VIDEO *vp;
#ifdef VARIABLE_TAB
int tab = curwp->w_bufp->b_tabwidth;
#endif
/* vtrow sometimes over-runs the vnrow -1. In the case, vp at
* following line becomes an uninitialized pointer. Then core
* dump or system error may occur. To avoid the error. Some
* range confirmation should be needed.
* By Tillanosoft Sep 9, 2000.
*/
if (vnrow - 1 <= vtrow)
return;
vp = vscreen[vtrow];
if (c == '\t' && !(curwp->w_bufp->b_flag & BFNOTAB)) {
if (
#ifdef VARIABLE_TAB
(vtcol/tab +1)*tab
#else
(vtcol | 0x07) + 1
#endif
<= ncol - 1 ) {
do {
vtputc(' ');
} while (vtcol<ncol &&
#ifdef VARIABLE_TAB
(vtcol%tab)!=0
#else
(vtcol&0x07)!=0
#endif
);
}
else {
vteeol();
vp->v_text[ncol-1]='\\';
vtcol=0;
vtrow++;
}
}
else if (ISCTRL(c)) {
vtputc('^');
vtputc(CCHR(c));
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
}
else if (vtkattr == HAN1ST) {
vp->v_sub(vtcol-1) = c;
vtkattr = ASCII;
#endif /* HANKANA */
#ifdef HOJO_KANJI
}
else if (vtkattr == HOJO1ST) {
vp->v_sub(vtcol-1) = c;
vtkattr = HOJO2ND;
}
else if (vtkattr == HOJO2ND) {
vp->v_text[vtcol++] = SS3;
vp->v_sub(vtcol) = c;
vtkattr = ASCII;
#endif /* HOJO_KANJI */
}
else {
#ifdef SS_SUPPORT /* 92.11.21 by S.Sasaki */
vp->v_sub(vtcol) = 0;
#endif
vp->v_text[vtcol++] = c;
#ifdef KANJI /* 90.01.29 by S.Yoshida */
if (vtkattr == K1ST) {
vtkattr = K2ND;
}
else if (ISKANJI(c)) {
#ifdef HANKANA /* 92.11.21 by S.Sasaki */
if (ISHANKANA(c)) vtkattr = HAN1ST;
else
#endif
#ifdef HOJO_KANJI
if (ISHOJO(c)) vtkattr = HOJO1ST;
else
#endif
vtkattr = K1ST;
} else {
vtkattr = ASCII;
}
#endif /* KANJI */
}
if (vtcol >= ncol-1
#ifdef HANKANA
&& vtkattr != HAN1ST
#endif
#ifdef HOJO_KANJI
&& vtkattr != HOJO1ST
#endif
) {
vp->v_text[ncol-1] = '\\';
vtcol=0;
vtrow++;
#ifdef KANJI /* 90.01.29 by S.Yoshida */
if (vtkattr == K1ST
#ifdef HOJO_KANJI
|| vtkattr == HOJO2ND
#endif
) {
vtkattr = ASCII;
vtputc(vp->v_text[ncol-2]);
vp->v_text[ncol - 2] = '\\';
}
#endif /* KANJI */
}
}
#if defined(MEMMAP) && !defined(HAVE_ORIGINAL_PUTLINE)
static VOID
#ifdef SS_SUPPORT
putline(row, col, s, t, color)
int row, col;
unsigned char *s, *t;
short color; /* this is dummy */
#else
putline(row, col, s, color)
int row, col;
unsigned char *s;
short color; /* this is dummy */
#endif
{
register int i;
unsigned char c;
#ifdef SS_SUPPORT
unsigned char c1;
#endif
int oldrow = vtrow;
int oldcol = vtcol;
vtrow = row;
vtcol = col;
for (i=row; i<=MAXROW; i++) {
c = *s++;
#ifdef SS_SUPPORT
if (vtkattr == ASCII) {
c1 = *t++;
#ifdef HANKANA
if (ISHANKANA(c) && c1!=0) {
vtkattr = HAN1ST;
c = c1;
}
#endif
#ifdef HOJO_KANJI
if (ISHOJO(c) && c1!=0) {
vtkattr = HOJO1ST;
c = c1;
}
#endif
}
#endif
vtputc(c);
}
vtrow = oldrow;
vtcol = oldcol;
}
#endif /* MEMMAP && !HAVE_ORIGINAL_PUTLINE */
/* Mark '\\' end of line
* whether curcol is not on the top of line.
*/
static VOID
vtmarkyen(fillchar)
int fillchar;
{
register VIDEO *vp;
vp = vscreen[vtrow];
if (vtcol > 0) {
while (vtcol < ncol) {
#ifdef SS_SUPPORT /* 92.11.21 by S.Sasaki */
vp->v_sub(vtcol)=0;
#endif /* SS_SUPPORT */
vp->v_text[vtcol++] = fillchar;
}
}
}
/* Erase from the end of the
* software cursor to the end of the
* line on which the software cursor is
* located. The display routines will decide
* if a hardware erase to end of line command
* should be used to display this.
*/
static VOID
vteeol()
{
register VIDEO *vp;
vp = vscreen[vtrow];
while (vtcol < ncol) {
#ifdef SS_SUPPORT /* 92.11.21 by S.Sasaki */
vp->v_sub(vtcol)=0;
#endif /* SS_SUPPORT */
vp->v_text[vtcol++] = ' ';
}
}
/* Calculate offset to col and row
*/
int
#ifdef SUPPORT_ANSI /* for strict compiler */
colrow(LINE *lp, short offset, int *curcol, int *lines)
#else
colrow(lp, offset, curcol, lines)
LINE *lp;
short offset;
int *curcol;
int *lines;
#endif
{
register int i;
register char c;
register int c1;
#ifdef VARIABLE_TAB
int tab = curbp->b_tabwidth;
#endif
c1 = 0;
*curcol = 0;
*lines = 0;
for (i=0; i<offset; ++i) {
c = lgetc(lp, i);
#ifdef KANJI
if (ISKANJI(c)) {
if (c1 == 1)
c1 = 0;
else
c1 = 1;
}
else
c1 = 0;
#endif /* KANJI */
#ifdef HANKANA
if (ISHANKANA(c) && c1 == 1)
--(*curcol);
#endif
if (c == '\t' && !(curbp->b_flag & BFNOTAB)) {
#ifdef VARIABLE_TAB
*curcol = ((*curcol)/tab +1)*tab -1;
#else
*curcol |= 0x07;
#endif
if (*curcol >= ncol -2) {
*curcol = -1;
(*lines)++;
}
} else if (ISCTRL(c) != FALSE)
++(*curcol);
++(*curcol);
if (*curcol >= ncol-1) {
#ifdef KANJI
if (c1 == 1)
*curcol=1;
else
*curcol = *curcol - ncol + 1;
#else /* not KANJI */
*curcol = *curcol - ncol + 1;
#endif /* KANJI */
++(*lines);
}
}
#ifdef CURSOR_POS
#ifdef KANJI
if (*curcol == ncol -2 && i < llength(lp)) {
c=lgetc(lp, i);
if (ISKANJI(c)
#ifdef HANKANA
&& ISHANKANA(c)
#endif
) {
++(*lines);
*curcol = 0;
}
}
#endif
#endif /* CURSOR_POS */
return (short)*lines;
}
/*
* Returns offset of specified location. This will be mainly used to
* respond to a mouse click on a screen. In case the specified
* location does not exist within the `lp', negative value will be
* returned. The absolute value of the negative result is the number
* of rows left.
*
* This will return an offset right neighbor to the position, if the
* character at the position is a wide character ,that is, the width
* of the character is more than or equal to a double width character,
* and the position is at the right half of the character.
*
* By Tillanosoft, March 21, 1999.
*/
int
rowcol2offset(lp, row, col)
LINE *lp;
int row, col;
{
register int i;
register int curcol;
register char c;
register int width, skipbytes;
#ifdef VARIABLE_TAB
int tab = curbp->b_tabwidth;
#endif /* VARIABLE_TAB */
curcol = 0;
for (i=0; i<llength(lp); i += skipbytes) {
if (row < 0 || (row == 0 && col < curcol))
return i;
c = lgetc(lp, i);
width = 1;
skipbytes = 1;
#ifdef KANJI
if (ISKANJI(c)) {
width = 2;
skipbytes = 2;
}
#ifdef HANKANA
if (ISHANKANA(c)) {
width = 1;
skipbytes = 2;
}
#endif /* HANKANA */
#endif /* KANJI */
if (c == '\t' && !(curbp->b_flag & BFNOTAB)) {
#ifdef VARIABLE_TAB
width = (curcol/tab + 1)*tab - curcol;
#else
width = (curcol | 0x07) - curcol + 1;
#endif
/*
* I should pay more care for the above line.
* In case, wrapping arround occurs, where should I put the curcol
* in the next line?
* By Tillanosoft Mar 21, 1999
*/
}
else if (ISCTRL(c) != FALSE) {
width = 2;
}
if (row == 0 && col < curcol + (width + 1) / 2) {
return i;
}
curcol += width;
if (curcol >= ncol-1
#ifdef KANJI
|| (ISKANJI(c) && curcol >= ncol-2)
#endif
) {
curcol= ISCTRL(c) ? (curcol - ncol + 1) : 0;
--row;
}
}
if (row <= 0) {
return i;
}
else {
return -row;
}
}
/* Return offset of #th lines
*/
short
skipline(lp, lines)
LINE *lp;
int lines;
{
register int i;
register int curcol;
register char c;
register int c1;
#ifdef VARIABLE_TAB
int tab = curbp->b_tabwidth;
#endif /* VARIABLE_TAB */
c1 = 0;
curcol = 0;
for (i=0; i<llength(lp); ++i) {
if (lines == 0)
return i - curcol;
c = lgetc(lp, i);
#ifdef KANJI
if ( ISKANJI(c) ) {
if (c1 == 1)
c1 = 0;
else
c1 = 1;
}
else
c1 = 0;
#endif /* KANJI */
#ifdef HANKANA
if (ISHANKANA(c) && c1 == 1)
--curcol;
#endif /* HANKANA */
if (c == '\t' && !(curbp->b_flag & BFNOTAB)) {
#ifdef VARIABLE_TAB
curcol = (curcol/tab + 1)*tab - 1;
#else
curcol |= 0x07;
#endif
if (curcol >= ncol -2) {
curcol = -1;
--lines;
}
}
else if (ISCTRL(c) != FALSE)
++curcol;
++curcol;
if (curcol >= ncol-1) {
#ifdef KANJI
if (c1 == 1)
curcol = 1;
else
curcol = 0;
#else /* not KANJI */
curcol = 0;
#endif /* KANJI */
--lines;
}
}
if (lines == 0)
return i - curcol;
ewprintf("Bug: skipline %d lines left",lines);
return FALSE;
}
/* Count number of displayed lines on tty.
* the line which is longer than ncol
* returns value more than 2 lines
*/
int
countlines(lp)
LINE *lp;
{
register int i;
register int curcol;
register int lines;
register char c;
register int c1;
#ifdef VARIABLE_TAB
int tab = curbp->b_tabwidth;
#endif /* VARIABLE_TAB */
c1 = 0;
curcol = 0;
lines = 0;
for (i=0; i<llength(lp); ++i) {
c = lgetc(lp, i);
#ifdef KANJI
if (ISKANJI(c)) {
if (c1 == 1)
c1 = 0;
else
c1 = 1;
}
else
c1 = 0;
#endif /* KANJI */
#ifdef HANKANA
if (ISHANKANA(c) && c1 == 1)
--curcol;
#endif /* HANKANA */
if (c == '\t' && !(curbp->b_flag & BFNOTAB)) {
#ifdef VARIABLE_TAB
curcol = (curcol/tab + 1)*tab - 1;
#else
curcol |= 0x07;
#endif
if (curcol >= ncol -2) {
curcol = -1;
lines++;
}
}
else if (ISCTRL(c) != FALSE)
++curcol;
++curcol;
if (curcol >= ncol-1) {
#ifdef KANJI
if (c1 == 1)
curcol = 1;
else
curcol = 0;
#else /* not KANJI */
curcol=0;
#endif /* KANJI */
++lines;
}
}
return lines+1;
}
#if 0
static VOID
vtpute(c)
int c;
{
register VIDEO *vp;
#ifdef VARIABLE_TAB
int tab = curwp->w_bufp->b_tabwidth;
#endif
vp = vscreen[vtrow];
if (vtcol >= ncol) {
#ifdef KANJI /* 90.01.29 by S.Yoshida */
if (vtkattr == K2ND) {
vp->v_text[ncol - 2] = '$';
}
#endif /* KANJI */
vp->v_text[ncol - 1] = '$';
}
else if (c == '\t' && !(curbp->b_flag & BFNOTAB)) {
do {
vtpute(' ');
}
#ifdef VARIABLE_TAB
while (((vtcol + lbound)%tab) != 0 && vtcol < ncol);
#else
while (((vtcol + lbound)&0x07) != 0 && vtcol < ncol);
#endif /* VARIABLE_TAB */
}
else if (ISCTRL(c) != FALSE) {
vtpute('^');
vtpute(CCHR(c));
}
else {
if (vtcol >= 0)
vp->v_text[vtcol] = c;
++vtcol;
#ifdef KANJI /* 90.01.29 by S.Yoshida */
if (vtkattr == K1ST) {
vtkattr = K2ND;
}
else if (ISKANJI(c)) { /* FIXME : unsupported kana */
vtkattr = K1ST;
}
else {
vtkattr = ASCII;
}
if (vtcol == 1 && vtkattr == K1ST) {
vtcol--;
lbound++;
}
#endif /* KANJI */
}
}
#endif
/*
* Make sure that the display is
* right. This is a three part process. First,
* scan through all of the windows looking for dirty
* ones. Check the framing, and refresh the screen.
* Second, make sure that "currow" and "curcol" are
* correct for the current window. Third, make the
* virtual and physical screens the same.
*/
/* Changed 98/01/23 by amura for Variable Tab handling */
VOID
update()
{
register LINE *lp;
WINDOW *old_curwp;
register WINDOW *wp;
register VIDEO *vp1;
VIDEO *vp2;
register int i, j;
register int hflag;
register int currow;
register int curcol;
#ifdef GOSLING
register int offs;
register int size;
#endif
int x,y;
int lines;
VOID traceback _PRO((void));
#ifdef KANJI /* 90.01.29 by S.Yoshida */
extern int no_k2nd; /* Defined at kbd.c */
#endif /* KANJI */
if (typeahead())
return;
if (sgarbf) { /* must update everything */
wp = wheadp;
while(wp != NULL) {
wp->w_flag |= WFMODE | WFHARD;
wp = wp->w_wndp;
}
#ifdef KANJI /* 90.01.29 by S.Yoshida */
no_k2nd = FALSE; /* Reset KANJI input condition. */
}
else if (no_k2nd) { /* We don't have KANJI 2nd byte. */
return;
#endif /* KANJI */
}
old_curwp = curwp;
hflag = FALSE; /* Not hard. */
wp = wheadp;
while (wp != NULL) {
if (wp == curwp && wp->w_flag == 0) {
lp = wp->w_linep; /* Cursor location. */
i = -wp->w_lines;
while (lp != wp->w_dotp) {
i += countlines(lp);
lp = lforw(lp);
}
i += colrow(lp, wp->w_doto, &x, &y);
if (i < 0 || i >= wp->w_ntrows)
wp->w_flag |= WFFORCE;
}
if (wp->w_flag != 0) { /* Need update. */
if (wp->w_dotlines != countlines(wp->w_dotp))
wp->w_flag |= WFHARD;
if ((wp->w_flag&WFFORCE) == 0) {
lp = wp->w_linep;
for (i = -wp->w_lines; i < wp->w_ntrows &&
lp != wp->w_bufp->b_linep; ) {
if (lp == wp->w_dotp) {
i += colrow(lp, wp->w_doto, &x, &y);
if (i>=0 && i<wp->w_ntrows)
goto out;
else
break;
}
i += countlines(lp);
lp = lforw(lp);
}
}
i = wp->w_force; /* Reframe this one. */
if (i > 0) {
--i;
if (i >= wp->w_ntrows)
i = wp->w_ntrows-1;
}
else if (i < 0) {
i += wp->w_ntrows;
if (i < 0)
i = 0;
}
else
i = wp->w_ntrows/2;
lp = wp->w_dotp;
i -= colrow(lp, wp->w_doto, &x, &y);
while (i>0 && lback(lp)!=wp->w_bufp->b_linep) {
lp = lback(lp);
i -= countlines(lp);
}
if (i>0)
i=0;
if (i<0)
i = -i;
wp->w_linep = lp;
wp->w_lines = i;
wp->w_flag |= WFHARD; /* Force full. */
out:
lp = wp->w_linep; /* Try reduced update. */
i = wp->w_toprow - wp->w_lines;
if ((wp->w_flag&~WFMODE) == WFEDIT) {
while (lp != wp->w_dotp) {
i += countlines(lp);
lp = lforw(lp);
}
j = i + countlines(lp);
if (j > wp->w_toprow + wp->w_ntrows) {
y = skipline(lp, wp->w_toprow + wp->w_ntrows - i);
j = wp->w_toprow + wp->w_ntrows;
}
else
y = llength(lp);
if (i < wp->w_toprow) {
x = skipline(lp, wp->w_toprow - i);
i = wp->w_toprow;
}
else
x = 0;
for (lines=i; lines<j; lines++) {
vscreen[lines]->v_color = CTEXT;
vscreen[lines]->v_flag |= (VFCHG|VFHBAD);
}
vtmove(i, 0);
for (j=x; j<y; ++j)
vtputc(lgetc(lp, j));
if (y < llength(lp))
vtmarkyen('\\');
else
vteeol();
}
else if ((wp->w_flag&(WFEDIT|WFHARD)) != 0) {
hflag = TRUE;
while (i < wp->w_toprow + wp->w_ntrows) {
if (lp == wp->w_bufp->b_linep) {
vtmove(i, 0);
vscreen[i]->v_color =CTEXT;
vscreen[i]->v_flag |= (VFCHG|VFHBAD);
vteeol();
i++;
continue;
}
j = i + countlines(lp);
if (j > wp->w_toprow + wp->w_ntrows){
y = skipline(lp, wp->w_toprow + wp->w_ntrows - i);
j = wp->w_toprow + wp->w_ntrows;
}
else
y = llength(lp);
if (i < wp->w_toprow) {
x = skipline(lp, wp->w_toprow - i);
i = wp->w_toprow;
}
else