-
Notifications
You must be signed in to change notification settings - Fork 0
/
redraw.c
1460 lines (1347 loc) · 28.1 KB
/
redraw.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
/* redraw.c */
/* Author:
* Steve Kirkendall
* 1500 SW Park #326
* Portland OR, 97201
*/
/* This file contains functions that draw text on the screen. The major entry
* points are:
* redrawrange() - called from modify.c to give hints about what parts
* of the screen need to be redrawn.
* redraw() - redraws the screen (or part of it) and positions
* the cursor where it belongs.
* idx2col() - converts a markidx() value to a logical column number.
*/
#include "config.h"
#include "vi.h"
#ifdef CRUNCH
# define NEAR LINES
#else
# define NEAR (*o_nearscroll&0xff)
#endif
/* This variable contains the line number that smartdrawtext() knows best */
static long smartlno;
/* This function remembers where changes were made, so that the screen can be
* redrawn in a more efficient manner.
*/
static long redrawafter; /* line# of first line that must be redrawn */
static long preredraw; /* line# of last line changed, before change */
static long postredraw; /* line# of last line changed, after change */
static int mustredraw; /* boolean: anything forcing a screen update? */
void redrawrange(after, pre, post)
long after; /* lower bound of redrawafter */
long pre; /* upper bound of preredraw */
long post; /* upper bound of postredraw */
{
if (after == redrawafter)
{
/* multiple insertions/deletions at the same place -- combine
* them
*/
preredraw -= (post - pre);
if (postredraw < post)
{
preredraw += (post - postredraw);
postredraw = post;
}
if (redrawafter > preredraw)
{
redrawafter = preredraw;
}
if (redrawafter < 1L)
{
redrawafter = 0L;
preredraw = postredraw = INFINITY;
}
}
else if (postredraw > 0L)
{
/* multiple changes in different places -- redraw everything
* after "after".
*/
postredraw = preredraw = INFINITY;
if (after < redrawafter)
redrawafter = after;
}
else
{
/* first change */
redrawafter = after;
preredraw = pre;
postredraw = post;
}
mustredraw = TRUE;
}
#ifndef NO_CHARATTR
/* see if a given line uses character attribute strings */
static int hasattr(lno, text)
long lno; /* the line# of the cursor */
REG char *text; /* the text of the line, from fetchline */
{
static long plno; /* previous line number */
static long chgs; /* previous value of changes counter */
static int panswer;/* previous answer */
char *scan;
/* if charattr is off, then the answer is "no, it doesn't" */
if (!*o_charattr)
{
chgs = 0; /* <- forces us to check if charattr is later set */
return FALSE;
}
/* if we already know the answer, return it... */
if (lno == plno && chgs == changes)
{
return panswer;
}
/* get the line & look for "\fX" */
if (!text[0] || !text[1] || !text[2])
{
panswer = FALSE;
}
else
{
for (scan = text; scan[2] && !(scan[0] == '\\' && scan[1] == 'f'); scan++)
{
}
panswer = (scan[2] != '\0');
}
/* save the results */
plno = lno;
chgs = changes;
/* return the results */
return panswer;
}
#endif
#ifndef NO_VISIBLE
/* This function checks to make sure that the correct lines are shown in
* reverse-video. This is used to handle the "v" and "V" commands.
*/
static long vizlow, vizhigh; /* the starting and ending lines */
static int vizleft, vizright; /* starting & ending indicies */
static int vizchange; /* boolean: must use stupid drawtext? */
static void setviz(curs)
MARK curs;
{
long newlow, newhigh;
long extra = 0L;
/* for now, assume the worst... */
vizchange = TRUE;
/* set newlow & newhigh according to V_from and cursor */
if (!V_from)
{
/* no lines should have reverse-video */
if (vizlow)
{
redrawrange(vizlow, vizhigh + 1L, vizhigh + 1L);
vizlow = vizhigh = 0L;
}
else
{
vizchange = FALSE;
}
return;
}
/* figure out which lines *SHOULD* have hilites */
if (V_from < curs)
{
newlow = markline(V_from);
newhigh = markline(curs);
vizleft = markidx(V_from);
vizright = markidx(curs) + 1;
}
else
{
newlow = markline(curs);
newhigh = markline(V_from);
vizleft = markidx(curs);
vizright = markidx(V_from) + 1;
}
/* adjust for line-mode hiliting */
if (V_linemd)
{
vizleft = 0;
vizright = BLKSIZE - 1;
}
else
{
extra = 1L;
}
/* arrange for the necessary lines to be redrawn */
if (vizlow == 0L)
{
/* just starting to redraw */
redrawrange(newlow, newhigh, newhigh);
}
else
{
/* Were new lines added/removed at the front? */
if (newlow != vizlow)
{
if (newlow < vizlow)
redrawrange(newlow, vizlow + extra, vizlow + extra);
else
redrawrange(vizlow, newlow + extra, newlow + extra);
}
/* Were new lines added/removed at the back? */
if (newhigh != vizhigh)
{
if (newhigh < vizhigh)
redrawrange(newhigh + 1L - extra, vizhigh + 1L, vizhigh + 1L);
else
redrawrange(vizhigh + 1L - extra, newhigh, newhigh);
}
}
/* remember which lines will contain hilighted text now */
vizlow = newlow;
vizhigh = newhigh;
}
#endif /* !NO_VISIBLE */
/* This function converts a MARK to a column number. It doesn't automatically
* adjust for leftcol; that must be done by the calling function
*/
int idx2col(curs, text, inputting)
MARK curs; /* the line# & index# of the cursor */
REG char *text; /* the text of the line, from fetchline */
int inputting; /* boolean: called from input() ? */
{
static MARK pcursor;/* previous cursor, for possible shortcut */
static MARK pcol; /* column number for pcol */
static long chgs; /* previous value of changes counter */
REG int col; /* used to count column numbers */
REG int idx; /* used to count down the index */
REG int i;
/* for now, assume we have to start counting at the left edge */
col = 0;
idx = markidx(curs);
/* if the file hasn't changed & line number is the same & it has no
* embedded character attribute strings, can we do shortcuts?
*/
if (chgs == changes
&& !((curs ^ pcursor) & ~(BLKSIZE - 1))
#ifndef NO_CHARATTR
&& !hasattr(markline(curs), text)
#endif
)
{
/* no movement? */
if (curs == pcursor)
{
/* return the column of the char; for tabs, return its last column */
if (text[idx] == '\t' && !inputting && !*o_list)
{
return pcol + *o_tabstop - (pcol % *o_tabstop) - 1;
}
else
{
return pcol;
}
}
/* movement to right? */
if (curs > pcursor)
{
/* start counting from previous place */
col = pcol;
idx = markidx(curs) - markidx(pcursor);
text += markidx(pcursor);
}
}
/* count over to the char after the idx position */
while (idx > 0 && (i = *text)) /* yes, ASSIGNMENT! */
{
if (i == '\t' && !*o_list)
{
col += *o_tabstop;
col -= col % *o_tabstop;
}
else if (i >= '\0' && i < ' ' || i == '\177')
{
col += 2;
}
#ifndef NO_CHARATTR
else if (i == '\\' && text[1] == 'f' && text[2] && *o_charattr)
{
text += 2; /* plus one more at bottom of loop */
idx -= 2;
}
#endif
else if (IsHiBitOn(i))
{
if (idx == 1)
break;
col += 2;
text++;
idx--;
}
else
{
col++;
}
text++;
idx--;
}
/* save stuff to speed next call */
pcursor = curs;
pcol = col;
chgs = changes;
/* return the column of the char; for tabs, return its last column */
if (*text == '\t' && !inputting && !*o_list)
{
return col + *o_tabstop - (col % *o_tabstop) - 1;
}
else
{
return col;
}
}
/* This function is similar to idx2col except that it takes care of sideways
* scrolling - for the given line, at least.
*/
int mark2phys(m, text, inputting)
MARK m; /* a mark to convert */
char *text; /* the line that m refers to */
int inputting; /* boolean: caled from input() ? */
{
int i;
i = idx2col(m, text, inputting);
while (i < leftcol)
{
leftcol -= *o_sidescroll;
mustredraw = TRUE;
redrawrange(1L, INFINITY, INFINITY);
}
while (i > rightcol || ((i==rightcol) && IsHiBitOnMark(m)))
{
leftcol += *o_sidescroll;
mustredraw = TRUE;
redrawrange(1L, INFINITY, INFINITY);
}
physrow = markline(m) - topline;
physcol = i - leftcol;
if (*o_number)
physcol += 8;
return physcol;
}
/* This function draws a single line of text on the screen. The screen's
* cursor is assumed to be located at the leftmost column of the appropriate
* row.
*/
static void drawtext(text, lno, clr)
REG char *text; /* the text to draw */
long lno; /* the number of the line to draw */
int clr; /* boolean: do a clrtoeol? */
{
REG int col; /* column number */
REG int i;
REG int tabstop; /* *o_tabstop */
REG int limitcol; /* leftcol or leftcol + COLS */
int abnormal; /* boolean: charattr != A_NORMAL? */
#ifndef NO_VISIBLE
int rev = FALSE; /* boolean: standout mode, too? */
/* init added -dg */
int idx = 0;
#endif
char numstr[9];
/* show the line number, if necessary */
if (*o_number)
{
sprintf(numstr, "%6ld ", lno);
qaddstr(numstr);
}
#ifndef NO_SENTENCE
/* if we're hiding format lines, and this is one of them, then hide it */
if (*o_hideformat && *text == '.')
{
clrtoeol();
#if OSK
qaddch('\l');
#else
qaddch('\n');
#endif
return;
}
#endif
/* move some things into registers... */
limitcol = leftcol;
tabstop = *o_tabstop;
abnormal = FALSE;
#ifndef CRUNCH
if (clr)
clrtoeol();
#endif
/* skip stuff that was scrolled off left edge */
for (col = 0;
(i = *text) && col < limitcol; /* yes, ASSIGNMENT! */
text++)
{
#ifndef NO_VISIBLE
idx++;
#endif
if (i == '\t' && !*o_list)
{
col = col + tabstop - (col % tabstop);
}
else if (i >= 0 && i < ' ' || i == '\177')
{
col += 2;
}
#ifndef NO_CHARATTR
else if (i == '\\' && text[1] == 'f' && text[2] && *o_charattr)
{
text += 2; /* plus one more as part of "for" loop */
/* since this attribute might carry over, we need it */
switch (*text)
{
case 'R':
case 'P':
attrset(A_NORMAL);
abnormal = FALSE;
break;
case 'B':
attrset(A_BOLD);
abnormal = TRUE;
break;
case 'U':
attrset(A_UNDERLINE);
abnormal = TRUE;
break;
case 'I':
attrset(A_ALTCHARSET);
abnormal = TRUE;
break;
}
}
#endif
else if (IsHiBitOn(i))
{
col += 2;
text++;
idx++;
}
else
{
col++;
}
}
#ifndef NO_VISIBLE
/* Should we start hiliting at the first char of this line? */
if ((lno > vizlow && lno <= vizhigh
|| lno == vizlow && vizleft < idx)
&& !(lno == vizhigh && vizright < idx))
{
do_VISIBLE();
rev = TRUE;
}
#endif
/* adjust for control char that was partially visible */
while (col > limitcol)
{
qaddch(' ');
limitcol++;
}
/* now for the visible characters */
limitcol = leftcol + COLS;
if (*o_number)
limitcol -= 8;
for (; (i = *text) && col < limitcol; text++)
{
#ifndef NO_VISIBLE
/* maybe turn hilite on/off in the middle of the line */
if (lno == vizlow && vizleft == idx)
{
do_VISIBLE();
rev = TRUE;
}
if (lno == vizhigh && vizright <= idx)
{
do_SE();
rev = FALSE;
}
idx++;
/* if hiliting, never emit physical tabs */
if (rev && i == '\t' && !*o_list)
{
i = col + tabstop - (col % tabstop);
do
{
qaddch(' ');
col++;
} while (col < i && col < limitcol);
}
else
#endif /* !NO_VISIBLE */
if (i == '\t' && !*o_list)
{
i = col + tabstop - (col % tabstop);
if (i < limitcol)
{
#ifdef CRUNCH
if (!clr && has_PT && !((i - leftcol) & 7))
#else
if (has_PT && !((i - leftcol) & 7))
#endif
{
do
{
qaddch('\t');
col += 8; /* not exact! */
} while (col < i);
col = i; /* NOW it is exact */
}
else
{
do
{
qaddch(' ');
col++;
} while (col < i && col < limitcol);
}
}
else /* tab ending after screen? next line! */
{
#ifdef CRUNCH
/* needed at least when scrolling the screen right -nox */
if (clr && col < limitcol)
clrtoeol();
#endif
col = limitcol;
if (has_AM)
{
addch('\n'); /* GB */
}
}
}
else if (i >= 0 && i < ' ' || i == '\177')
{
col += 2;
qaddch('^');
if (col <= limitcol)
{
qaddch(i ^ '@');
}
}
#ifndef NO_CHARATTR
else if (i == '\\' && text[1] == 'f' && text[2] && *o_charattr)
{
text += 2; /* plus one more as part of "for" loop */
switch (*text)
{
case 'R':
case 'P':
attrset(A_NORMAL);
abnormal = FALSE;
break;
case 'B':
attrset(A_BOLD);
abnormal = TRUE;
break;
case 'U':
attrset(A_UNDERLINE);
abnormal = TRUE;
break;
case 'I':
attrset(A_ALTCHARSET);
abnormal = TRUE;
break;
}
}
#endif
else if (IsHiBitOn(i))
{
if (col < limitcol - 1)
{
col += 2;
qaddch(i);
text++;
idx ++;
qaddch(*text);
}
else
{
col++;
qaddch('~');
}
}
else
{
col++;
qaddch(i);
}
}
/* get ready for the next line */
#ifndef NO_CHARATTR
if (abnormal)
{
attrset(A_NORMAL);
}
#endif
if (*o_list && col < limitcol)
{
qaddch('$');
col++;
}
#ifndef NO_VISIBLE
/* did we hilite this whole line? If so, STOP! */
if (rev)
{
do_SE();
}
#endif
#ifdef CRUNCH
if (clr && col < limitcol)
{
clrtoeol();
}
#endif
if (!has_AM || col < limitcol)
{
addch('\n');
}
wqrefresh();
}
#ifndef CRUNCH
static void nudgecursor(same, scan, new, lno)
int same; /* number of chars to be skipped over */
char *scan; /* where the same chars end */
char *new; /* where the visible part of the line starts */
long lno; /* line number of this line */
{
int col;
if (same > 0)
{
if (same < 5)
{
/* move the cursor by overwriting */
while (same > 0)
{
qaddch(scan[-same]);
same--;
}
}
else
{
/* move the cursor by calling move() */
col = (int)(scan - new);
if (*o_number)
col += 8;
move((int)(lno - topline), col);
}
}
}
#endif /* not CRUNCH */
/* This function draws a single line of text on the screen, possibly with
* some cursor optimization. The cursor is repositioned before drawing
* begins, so its position before doesn't really matter.
*/
static void smartdrawtext(text, lno, showit)
REG char *text; /* the text to draw */
long lno; /* line number of the text */
int showit; /* boolean: output line? (else just remember it) */
{
#ifdef CRUNCH
move((int)(lno - topline), 0);
if (showit)
{
drawtext(text, lno, TRUE);
}
#else /* not CRUNCH */
static char old[256]; /* how the line looked last time */
char new[256]; /* how it looks now */
char *build; /* used to put chars into new[] */
char *scan; /* used for moving thru new[] or old[] */
char *end; /* last non-blank changed char */
char *shift; /* used to insert/delete chars */
int same; /* length of a run of unchanged chars */
int limitcol;
int col;
int i;
char numstr[9];
# ifndef NO_CHARATTR
/* if this line has attributes, do it the dumb way instead */
if (hasattr(lno, text))
{
move((int)(lno - topline), 0);
drawtext(text, lno, TRUE);
return;
}
# endif
# ifndef NO_SENTENCE
/* if this line is a format line, & we're hiding format lines, then
* let the dumb drawtext() function handle it
*/
if (*o_hideformat && *text == '.')
{
move((int)(lno - topline), 0);
drawtext(text, lno, TRUE);
return;
}
# endif
# ifndef NO_VISIBLE
if (vizchange)
{
move((int)(lno - topline), 0);
drawtext(text, lno, TRUE);
smartlno = 0L;
return;
}
# endif
/* skip stuff that was scrolled off left edge */
limitcol = leftcol;
for (col = 0;
(i = *text) && col < limitcol; /* yes, ASSIGNMENT! */
text++)
{
if (i == '\t' && !*o_list)
{
col = col + *o_tabstop - (col % *o_tabstop);
}
else if (i >= 0 && i < ' ' || i == '\177')
{
col += 2;
}
else if (IsHiBitOn(i))
{
col += 2;
text++;
}
else
{
col++;
}
}
/* adjust for control char that was partially visible */
build = new;
while (col > limitcol)
{
*build++ = ' ';
limitcol++;
}
/* now for the visible characters */
limitcol = leftcol + COLS;
if (*o_number)
limitcol -= 8;
for (; (i = *text) && col < limitcol; text++)
{
if (i == '\t' && !*o_list)
{
i = col + *o_tabstop - (col % *o_tabstop);
while (col < i && col < limitcol)
{
*build++ = ' ';
col++;
}
}
else if (i >= 0 && i < ' ' || i == '\177')
{
col += 2;
*build++ = '^';
if (col <= limitcol)
{
*build++ = (i ^ '@');
}
}
else if (IsHiBitOn(i))
{
if (col < limitcol - 1)
{
col += 2;
*build++ = i;
text++;
*build++ = *text;
}
else
{
col++;
*build++ = '~';
}
}
else
{
col++;
*build++ = i;
}
}
if (col < limitcol && *o_list)
{
*build++ = '$';
col++;
}
end = build;
while (col < limitcol)
{
*build++ = ' ';
col++;
}
/* if we're just supposed to remember this line, then remember it */
if (!showit)
{
smartlno = lno;
strncpy(old, new, COLS);
return;
}
/* locate the last non-blank character */
while (end > new && end[-1] == ' ')
{
end--;
}
/* can we optimize the displaying of this line? */
if (lno != smartlno)
{
/* nope, can't optimize - different line */
move((int)(lno - topline), 0);
/* show the line number, if necessary */
if (*o_number)
{
sprintf(numstr, "%6ld ", lno);
qaddstr(numstr);
}
/* show the new line */
for (scan = new, build = old; scan < end; )
{
qaddch(*scan);
*build++ = *scan++;
}
if (end < new + COLS - (*o_number ? 8 : 0))
{
clrtoeol();
while (build < old + COLS)
{
*build++ = ' ';
}
}
smartlno = lno;
return;
}
/* skip any initial unchanged characters */
for (scan = new, build = old; scan < end; )
{
if ( !IsHiBitOn(scan[0]) && scan[0] == build[0] )
{
scan++, build++;
}
else if ( IsHiBitOn(scan[0]) && scan[0] == build[0] && scan[0] == build[1] )
{
scan+=2, build+=2;
}
else
break;
}
i = (scan - new);
if (*o_number)
i += 8;
move((int)(lno - topline), i);
/* The in-between characters must be changed */
same = 0;
while (scan < end)
{
/* is this character a match? */
if (!IsHiBitOn(scan[0]) && scan[0] == build[0])
{
same++;
}
else if ( IsHiBitOn(scan[0]) && scan[0] == build[0] && scan[1] == build[1])
{
scan++, build++;
same += 2;
}
else /* do we want to insert? */
if (scan < end - 2 && !IsHiBitOn(scan[0]) && scan[1] == build[0] && scan[2] == build[1] && (has_IC || has_IM))
{
nudgecursor(same, scan, new, lno);
same = 0;
insch(*scan);
for (shift = old + COLS; shift > build; shift--)
{
shift[0] = shift[-1];
}
*build = *scan;
}
else /* do we want to insert Hangul? */
if (scan < end - 3 && IsHiBitOn(scan[0]) && scan[2] == build[0] && scan[3] == build[1] && (has_IC || has_IM))
{
nudgecursor(same, scan, new, lno);
same = 0;
insch2(scan[0], scan[1]);
for (shift = old + COLS; shift > build + 1; shift--)
{
shift[0] = shift[-2];
}
build[0] = scan[0];
build[1] = scan[1];
build++;
scan++;
}
else /* do we want to delete? */
if (build < old + COLS - 2 && !IsHiBitOn(build[0]) && !IsHiBitOn(scan[0]) && scan[0] == build[1] && scan[1] == build[2] && has_DC)
{
nudgecursor(same, scan, new, lno);
same = 0;
delch();
same++;
for (shift = build; shift < old + COLS - 1; shift++)
{
shift[0] = shift[1];
}
if (*o_number)
shift -= 8;
*shift = ' ';
}
else /* do we want to delete Hangul? */
if (build < old + COLS - 3 && IsHiBitOn(build[0]) && !IsHiBitOn(scan[0]) && scan[0] == build[2] && scan[1] == build[3] && has_DC)
{
nudgecursor(same, scan, new, lno);
same = 0;
delch();
delch();
same++;
for (shift = build; shift < old + COLS - 2; shift++)
{
shift[0] = shift[2];
}
if (*o_number)
shift -= 8;
*shift = ' ';
*(shift+1) = ' ';
}
else if (IsHiBitOn(*scan))
{ /* we must overwrite hangul */
nudgecursor(same, scan, new, lno);
same = 0;
addch(*scan);
*build = *scan;
build++;
scan++;
addch(*scan);
*build = *scan;
}
else /* we must overwrite */
{
nudgecursor(same, scan, new, lno);
same = 0;
addch(*scan);
*build = *scan;
}