-
Notifications
You must be signed in to change notification settings - Fork 0
/
display.c
1205 lines (1141 loc) · 24.4 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
/* display.c
* The functions in this file
* handle redisplay. There are two halves,
* the ones that update the virtual display
* screen, and the ones that make the physical
* display screen the same as the virtual
* display screen. These functions use hints
* that are left in the windows by the
* commands.
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "ed.h"
#define WFDEBUG 0 /* Window flag debug. */
#if VT100 && !W32
extern int escseq();
#endif
typedef struct VIDEO {
int v_col; /* mb: line len / scrn offset */
int v_flag; /* Flags */
char v_text[NLINE]; /* Screen data. */
} VIDEO;
#define VIDEOSIZE (sizeof(VIDEO)-NLINE)
void updateline(int row, VIDEO *vline, VIDEO *pline);
#define VFCHG 0x0001 /* Changed. */
#define VFMOD 0x0002 /* Mode line. (dal/mb:) */
int sgarbf = TRUE; /* TRUE if screen is garbage */
int mpresf = FALSE; /* TRUE if message in last line */
int visible = FALSE; /* mb: show white-space chars */
int vtrow = 0; /* Row location of SW cursor */
int vtcol = 0; /* Column location of SW cursor */
int ttrow = HUGE; /* Row location of HW cursor */
int ttcol = HUGE; /* Column location of HW cursor */
VIDEO **vscreen = NULL; /* Virtual screen. */
VIDEO **pscreen = NULL; /* Physical screen. */
/*
* 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. All the
* other things get initialized at compile time.
* The original window has "WFCHG" set, so that it
* will get completely redrawn on the first
* call to "update".
* mb: added initialization of v_flag fields since we want VFMOD right.
*/
void vtinit()
{
int firstinit = 0;
register int i;
register VIDEO *vp;
(*term.t_open)();
if (vscreen == NULL) {
firstinit = 1;
vscreen = (VIDEO **) malloc(term.t_nrow*sizeof(VIDEO *));
if (vscreen == NULL)
#if BFILES
_exit(1);
#else
exit(1);
#endif
pscreen = (VIDEO **) malloc(term.t_nrow*sizeof(VIDEO *));
if (pscreen == NULL)
#if BFILES
_exit(1);
#else
exit(1);
#endif
}
for (i=0; i<term.t_nrow; ++i) {
if (firstinit) {
vp = (VIDEO *) malloc(VIDEOSIZE+NLINE);
if (vp == NULL)
#if BFILES
_exit(1);
#else
exit(1);
#endif
vscreen[i] = vp;
} else { vp = vscreen[i]; }
vp->v_flag = 0;
vp->v_col = 0; /* mb: line length */
if (firstinit) {
vp = (VIDEO *) malloc(VIDEOSIZE+term.t_ncol);
if (vp == NULL)
#if BFILES
_exit(1);
#else
exit(1);
#endif
pscreen[i] = vp;
} else { vp = pscreen[i]; }
vp->v_flag = 0;
vp->v_col = 0; /* mb: screen offset */
}
}
/*
* Send a command to the terminal
* to move the hardware cursor to row "row"
* and column "col". The row and column arguments
* are origin 0. Optimize out random calls.
* Update "ttrow" and "ttcol".
*/
void movecursor(row, col)
int row, col;
{
if (row!=ttrow || col!=ttcol) {
ttrow = row;
ttcol = col;
(*term.t_move)(row, col);
}
}
/*
* Clean up the virtual terminal
* system, in anticipation for a return to the
* operating system. Move down to the last line and
* clear it out (the next system prompt will be
* written in the line). Shut down the channel
* to the terminal.
*/
int vttidy()
{
movecursor(term.t_nrow, 0);
#ifndef MSDOS
/* (*term.t_putchar)('\n'); / * mb: scroll! */
#endif
return (*term.t_close)();
}
/*
* Write a character to the
* virtual screen. The virtual row and
* column are updated.
* This routine only puts printing characters
* into the virtual terminal buffers.
* Only column overflow is checked.
* mb: added general tab size & "visible" option.
*/
void vtputc(int c);
void
vvtputc(c, wvsbl)
register int c;
register int wvsbl; /* mb: white-space visibility */
{
register VIDEO *vp;
c &= 0x00FF;
if (c == '\t') {
if (wvsbl)
c = '-';
else
c = ' ';
while (((vtcol+1)%tabsize) != 0)
vtputc(c);
if (wvsbl)
c = '>';
} else if (c == '\n') {
if (wvsbl) {
c = '<';
vtputc(c);
} else
return;
} else if (c == ' ') {
if (wvsbl)
c = '_';
} else if (c<0x20 || c==0x7F) {
vtputc('^');
c ^= 0x40;
}
vp = vscreen[vtrow];
if (vtcol < NLINE)
vp->v_text[vtcol++] = c;
vp->v_col = vtcol;
}
void vtputc(c) /* mb: split */
int c;
{
vvtputc(c, 0);
}
int
modeput (cp, n)
register char *cp;
int n;
{
register int c, m;
m = n;
while ((c = *cp++) != 0) {
vtputc(c);
++m;
}
return (m);
}
/*
* mb: toggle visibility of tabs, spaces and newlines
*/
int
visitog(f,n)
int f, n;
{
visible = !visible;
sgarbf = TRUE;
update (FALSE);
if (visible)
mlwrite("[white-space characters visible]");
else
mlwrite("[white-space white]");
return (TRUE);
}
/*
* Set the virtual cursor to
* the specified row and column on the
* virtual screen. There is no checking for
* nonsense values; this might be a good
* idea during the early stages.
*/
void vtmove(row, col)
int row, col;
{
vtrow = row;
vtcol = col;
}
/*
* Erase from the end of the
* software cursor to the end of the
* line on which the software cursor is
* located.
*/
void vteeol()
{
register VIDEO *vp;
vp = vscreen[vtrow];
/* while (vtcol < NLINE)
* vp->v_text[vtcol++] = ' ';
*/
memset(vp->v_text+vtcol, ' ', NLINE-vtcol);
}
int
mlputc(c)
register int c;
{
register int t, i;
int (*tputc)();
tputc = term.t_putchar;
c &= 0xFF;
t = c;
i = 0;
if (c == '\n') {
(*tputc)('<');
t = '<';
i = 1;
} else if (c == '\t') {
(*tputc)('>');
t = '>';
i = 1;
} else if (c == WHITESPACE) {
(*tputc)('_');
t = '_';
i = 1;
} else if (c == ANYCHAR) {
t = '.';
} else if (c == NEGCHAR) {
t = '!';
} else if (c<0x20 || c==0x7F) {
(*tputc)('^');
t ^= 0x40;
i = 1;
}
(*tputc)(t);
return (i);
}
/*
* Write out a string. Update the physical cursor position.
* This assumes that the characters in the
* string all have width "1"; if this is not
* the case things will get messed up a little.
*/
void mlputs(s)
register char *s;
{
register int c;
while ((c = *s++) != 0) {
(*term.t_putchar)(c);
++ttcol;
}
}
/*
* Write out an integer, in
* the specified radix. Update the physical
* cursor position. This will not handle any
* negative numbers; maybe it should.
*/
void mlputi(i, r)
int i, r;
{
register int q;
static char hexdigits[] = "0123456789ABCDEF";
if (i < 0) {
i = -i;
(*term.t_putchar)('-');
}
q = i/r;
if (q != 0)
mlputi(q, r);
(*term.t_putchar)(hexdigits[i%r]);
++ttcol;
}
/*
* do the same except as a long integer.
*/
void mlputli(l, r)
long l;
int r;
{
register long q;
if (l < 0) {
l = -l;
(*term.t_putchar)('-');
}
q = l/r;
if (q != 0)
mlputli(q, r);
(*term.t_putchar)((int)(l%r)+'0');
++ttcol;
}
/*
* Redisplay the mode line for
* the window pointed to by the "wp".
* This is the only routine that has any idea
* of how the modeline is formatted.
* (mb: changed the modeline format.)
* Called by "update" any time a window is dirty.
*/
void modeline(wp)
register WINDOW *wp;
{
register char *cp;
register int n;
register BUFFER *bp;
int verbose = TRUE;
start:
n = wp->w_toprow+wp->w_ntrows; /* Location. */
vscreen[n]->v_flag |= VFCHG | VFMOD; /* Redraw next time. */
vtmove(n, 0); /* Seek to right line. */
bp = wp->w_bufp;
if (bp->b_flag & BFEDIT) {
if (bp->b_flag & BFFORE)
vtputc('*'); /* ar: '*' if in foreign mode */
else
vtputc('+'); /* mb: '+' if in edit mode */
}
else
vtputc('-');
if (bp->b_flag & BFCHG) /* '*' if buffer changed. */
vtputc('*');
else
vtputc('-');
if (ovrstrk)
vtputc('x');
else
vtputc('>');
vtputc(' ');
n = 3;
if (verbose) {
#if AtST
cp = "MEX -- Buffer: "; /* mb: AtST has 'Help' key */
#endif
#if (MSDOS | W32)
#if HELP
cp = "MEX -- F1 for help -- ";
#else
cp = "MEX -- Buffer: ";
#endif
#endif
#if (V7 | VMS | CPM)
#if HELP
#if CURSES
cp = "MEX - F1 Help - ";
#else
cp = "MEX -- ESC-? for help -- ";
#endif
#else
cp = "MEX -- Buffer: ";
#endif
#endif
n = modeput (cp, n);
}
n = modeput (bp->b_bname, n); /* Buffer name */
n = modeput (" -- ", n);
if (bp->b_fname[0] != 0) { /* File name */
n = modeput ("File: ", n);
n = modeput (bp->b_fname, n);
}
#if WFDEBUG
vtputc('-');
vtputc((wp->w_flag&WFMODE)!=0 ? 'M' : '-');
vtputc((wp->w_flag&WFHARD)!=0 ? 'H' : '-');
vtputc((wp->w_flag&WFEDIT)!=0 ? 'E' : '-');
vtputc((wp->w_flag&WFMOVE)!=0 ? 'V' : '-');
vtputc((wp->w_flag&WFFORCE)!=0 ? 'F' : '-');
n += 6;
#endif
vtputc(' ');
++n;
if (verbose && n > term.t_ncol) { /* long pathname */
verbose = FALSE;
goto start;
}
while (n < term.t_ncol) { /* Pad to full width. */
vtputc('-');
++n;
}
}
/*
* mb: heavily altered.
* Make sure that the display is
* right. This is a three part process.
* First, make sure that "currow" and "curcol" are
* correct for the current window, and get the screen
* offset into the v_col fields of each line.
* Second, scan through all of the windows looking for
* dirty ones. Check the framing, and refresh the screen.
* Third, make the virtual and physical screens the same.
*/
void
update(visiplay)
int visiplay;
{
register LINE *lp;
register WINDOW *wp;
register int j;
register int c;
register int v;
register int i;
int *pvflag;
int wshift, wsflag, offset;
VIDEO *vp;
BUFFER *bp;
if (playback == TRUE) {
if (visiplay)
mlwrite("[Playback in progress...]");
else
return; /* mb: invisible playback */
}
/* Always recompute the row and column number of the hardware */
/* cursor. This is the only update for simple moves. */
/* mb: do it here to find out if w_offset needs to be changed */
wp = curwp;
lp = wp->w_linep;
while (lp != wp->w_dotp)
lp = lforw(lp);
curcol = 0;
i = 0;
while (i < wp->w_doto) {
c = lgetc(lp, i++);
if (c == '\t')
curcol += tabsize-(curcol%tabsize)-1; /* mb: */
else if (c<0x20 || c==0x7F)
++curcol;
++curcol;
}
wsflag = 0;
offset = wp->w_offset;
curcol -= offset;
wshift = term.t_ncol / WSHIFT;
while (curcol >= term.t_ncol - (offset? 2 : 1)) {
offset += wshift; /* mb: shift window right */
curcol -= wshift;
wsflag = 1;
}
while (curcol < 0) {
offset -= wshift; /* mb: shift window left */
curcol += wshift;
wsflag = 1;
}
if (wsflag) {
wp->w_offset = offset;
wp->w_flag |= WFHARD; /* mb: must redraw window */
}
if (offset)
++curcol; /* mb: for the '$' at the left */
wp = wheadp;
while (wp != NULL) {
v = visible;
bp = wp->w_bufp;
if (bp==blistp || bp==bhelpp)
v = FALSE;
if (sgarbf != FALSE) /* mb: added */
wp->w_flag |= WFHARD;
/* Look at any window with update flags set on. */
if (wp->w_flag != 0) {
/* If not force reframe, check the framing. */
if ((wp->w_flag&WFFORCE) == 0) {
lp = wp->w_linep;
for (i=0; i<wp->w_ntrows; ++i) {
if (lp == wp->w_dotp)
goto out;
if (lp == wp->w_bufp->b_linep)
break;
lp = lforw(lp);
}
}
/* Not acceptable, better compute a new value */
/* for the line at the top of the window. Then */
/* set the "WFHARD" flag to force full redraw. */
i = wp->w_force;
if (i > 0) {
if (i > wp->w_ntrows)
i = wp->w_ntrows;
--i;
} else if (i < 0) {
i += wp->w_ntrows;
if (i < 0)
i = 0;
} else
i = wp->w_ntrows/2;
lp = wp->w_dotp;
while (i!=0 && lback(lp)!=wp->w_bufp->b_linep) {
--i;
lp = lback(lp);
}
wp->w_linep = lp;
wp->w_flag |= WFHARD; /* Force full. */
out:
/* mb: put the window offsets in the pscreen[]
v_col fields for aid in later display. */
lp = wp->w_linep;
i = wp->w_toprow;
while (i < wp->w_toprow+wp->w_ntrows) {
pscreen[i]->v_col = wp->w_offset;
lp = lforw(lp);
++i;
}
/* Try to use reduced update. Mode line update */
/* has its own special flag. The fast update is */
/* used if the only thing to do is within the */
/* line editing. */
lp = wp->w_linep;
i = wp->w_toprow;
if ((wp->w_flag&~WFMODE) == WFEDIT) {
while (lp != wp->w_dotp) {
++i;
lp = lforw(lp);
}
vtmove(i, 0);
vp = vscreen[i];
vp->v_col = 0;
pvflag = &vp->v_flag;
*pvflag |= VFCHG;
*pvflag &= ~VFMOD;
for (j=0; j<llength(lp); ++j)
vvtputc(lgetc(lp, j), v);
vvtputc('\n', v);
vteeol();
} else if ((wp->w_flag&(WFEDIT|WFHARD)) != 0) {
while (i < wp->w_toprow+wp->w_ntrows) {
vtmove(i, 0);
vp = vscreen[i];
vp->v_col = 0;
pvflag = &vp->v_flag;
*pvflag |= VFCHG;
*pvflag &= ~VFMOD;
if (lp != bp->b_linep) {
for (j=0; j<llength(lp); ++j)
vvtputc(lgetc(lp, j), v);
vvtputc('\n', v);
lp = lforw(lp);
}
vteeol();
++i;
}
}
#if WFDEBUG
/* nothing */
#else
if ((wp->w_flag&WFMODE) != 0)
modeline(wp);
wp->w_flag = 0;
wp->w_force = 0;
#endif
}
#if WFDEBUG
modeline(wp);
wp->w_flag = 0;
wp->w_force = 0;
#endif
wp = wp->w_wndp;
}
/* Special hacking if the screen is garbage. Clear the hardware */
/* screen, and update your copy to agree with it. Set all the */
/* virtual screen change bits, to force a full update. */
if (sgarbf != FALSE) {
for (i=0; i<term.t_nrow; ++i) {
vscreen[i]->v_flag |= VFCHG;
vp = pscreen[i];
for (j=0; j<term.t_ncol; ++j)
vp->v_text[j] = ' ';
}
movecursor(0, 0); /* Erase the screen. */
(*term.t_eeop)();
sgarbf = FALSE; /* Erase-page clears */
mpresf = FALSE; /* the message area. */
}
/* Make sure that the physical and virtual displays agree. */
/* Unlike before, the "updateline" code is only called with a */
/* line that has been updated for sure. */
for (i=0; i<term.t_nrow; ++i) {
vp = vscreen[i];
pvflag = &vp->v_flag;
if ((*pvflag & VFCHG) || wsflag) {
if ((*term.t_pend)()) /* mb: key pressed? */
break; /* skip rest of repaint */
*pvflag &= ~VFCHG;
updateline(i, vp, pscreen[i]);
}
}
/* Need to recompute the cursor row in case of reframe. */
wp = curwp;
lp = wp->w_linep;
currow = wp->w_toprow;
while (lp != wp->w_dotp) {
++currow;
lp = lforw(lp);
}
/* Finally, update the hardware cursor and flush out buffers. */
movecursor(currow, curcol);
(*term.t_flush)();
}
/*
* Update a single line. This
* does not know how to use insert
* or delete character sequences; we are
* using VT52 functionality. Update the physical
* row and column variables. It does try to
* exploit erase to end of line.
* mb: changed calling syntax, added the "offset" business,
* and added special treatment for modeline.
*/
void
updateline(row, vline, pline)
int row;
VIDEO *vline, *pline;
{
register unsigned char *cp1;
register unsigned char *cp2;
register unsigned char *cp3;
register unsigned char *cp5;
int nbflag, modflag, eovlflag;
unsigned char *vtext, *ptext;
int vmod, pmod;
int offset, lastcol, ncol;
vtext = (unsigned char*)vline->v_text;
ptext = (unsigned char*)pline->v_text;
ncol = term.t_ncol;
vmod = vline->v_flag & VFMOD;
pmod = pline->v_flag & VFMOD;
modflag = (vmod != pmod);
if (modflag)
pline->v_flag = vmod;
if (vmod)
offset = 0;
else
offset = pline->v_col;
if (offset) { /* mb: do screen edges */
if (ptext[0] != '$') {
movecursor(row, 0);
(*term.t_putchar)('$');
}
ptext[0] = '$';
cp1 = &vtext[offset];
cp2 = &ptext[1];
lastcol = offset + ncol - 1;
} else {
cp1 = &vtext[0];
cp2 = &ptext[0];
lastcol = ncol;
}
if (lastcol > NLINE) { /* mb: beyond physical end of vline */
lastcol = NLINE;
eovlflag = TRUE;
} else {
eovlflag = FALSE;
}
if (! modflag) { /* Compute left match. */
while (cp1!=&vtext[lastcol] && cp1[0]==cp2[0]) {
++cp1;
++cp2;
}
if (cp1 == &vtext[lastcol]) /* All equal. */
return;
/* - can still happen, even though we only call this routine */
/* on changed lines. A hard update is always done when a line */
/* splits, a massive change is done, or a buffer is displayed */
/* twice. This optimizes out most of the excess updating. A lot */
/* of computes are used, but these tend to be hard operations */
/* that do a lot of update, so I don't really care. */
}
nbflag = FALSE;
cp3 = &vtext[lastcol]; /* Compute right match. */
cp5 = &ptext[ncol];
if (! modflag) {
while (cp3[-1] == cp5[-1]) {
--cp3;
--cp5;
if (cp3[0] != ' ') /* Note if any nonblank */
nbflag = TRUE;
}
}
cp5 = cp3;
if (nbflag == FALSE) { /* Erase to EOL ? */
while (cp5>cp1 && cp5[-1]==' ')
--cp5;
if ((int)(cp3-cp5) <= 3) /* Use only if erase is */
cp5 = cp3; /* fewer characters. */
}
movecursor(row, (int)(cp2-(unsigned char *)&ptext[0]));/* Go to first change */
if (vmod)
(*term.t_hglt)();
#ifdef HP700
else
(*term.t_nrml)();
#endif
while (cp1 < cp5) { /* Ordinary. */
(*term.t_putchar)(*cp1);
++ttcol;
*cp2++ = *cp1++;
}
if (cp5 != cp3 || eovlflag) { /* Erase. */
(*term.t_eeol)();
while (cp1 < cp3)
*cp2++ = *cp1++;
}
if (vline->v_col > lastcol) {
if (vmod) (*term.t_hglt)();
movecursor(row, ncol-1);
(*term.t_putchar)('$');
ptext[ncol-1] = '$';
}
#ifndef HP700
if (vmod)
(*term.t_nrml)();
#endif
}
/*
* Erase the message line.
* This is a special routine because
* the message line is not considered to be
* part of the virtual screen. It always works
* immediately; the terminal buffer is flushed
* via a call to the flusher.
*/
void mlerase()
{
movecursor(term.t_nrow, 0);
(*term.t_eeol)();
(*term.t_flush)();
mpresf = FALSE;
}
/*
* Ask a yes or no question in
* the message line. Return either TRUE,
* FALSE, or ABORT. The ABORT status is returned
* if the user bumps out of the question with
* a ^G. Used any time a confirmation is
* required. mb: modified so cr unneeded.
*/
int mlyesno(prompt)
char *prompt;
{
register int c;
char buf[64];
for (;;) {
strcpy(buf, prompt);
strcat(buf, " [y/n]? ");
mlwrite(buf);
c = getkey();
if (c=='y' || c=='Y')
return (TRUE);
if (c=='n' || c=='N')
return (FALSE);
if (c==(CNTL|'G'))
return (ABORT);
if (c == METACH)
return (ABORT);
#if AtST
if (c==(FUNC|0x61))
return (ABORT);
#endif
#if (MSDOS | W32)
if (c==(FUNC|0x3C))
return (ABORT);
#endif
/* else repeat */
}
}
/*
* Write a prompt into the message
* line, then read back a response. Keep
* track of the physical position of the cursor.
* If we are in a keyboard macro throw the prompt
* away, and return the remembered response. This
* lets macros run at full speed. The reply is
* terminated by a newline (\n or \r) only.
* mb: completely rewritten and calling syntax changed!
*/
int
mlreply(prompt, dflt, buf, width, doesc)
char *prompt, *dflt, *buf;
int width, doesc;
{
register int c, i, j;
register char *p1, *p2;
int col, row, fresh, escmode;
int (*tputc)();
extern int getkey();
tputc = term.t_putchar;
i = 0;
if (kbdmop != NULL) {
do {
c = *kbdmop++;
buf[i++] = c;
} while (c != '\0');
return (TRUE);
}
i = term.t_ncol - 1 - strlen(prompt);
if (width > i) width = i;
width -= 3;
start:
mlwrite (prompt);
(*tputc)(':');
(*tputc)(' ');
ttcol += 2;
col = ttcol;
row = ttrow;
fresh = TRUE;
escmode = FALSE;
p1 = buf;
p2 = dflt;
if (p2 != NULL) {
i = 0;
while ((c=(*p2++))!='\0' && (i++)<=width) {
*p1++ = c;
mlputc(c);
}
}
(*term.t_eeol)();
while (i++ <= width)
*p1++ = '\0';
i = 0;
loop:
(*term.t_move)(row, col+i);
(*term.t_flush)();
c = getkey();
#if VT100 && !W32
if (c=='\\' && doesc && !escmode) {
c = getkey();
escmode = TRUE;
goto verbatim;
}
if (c==METACH && !escmode) {
c = getkey();
if (c=='[' || c=='O') {
c = escseq(c);
if (c!=UP && c!=DOWN && c!=LEFT && c!=RIGHT)
c = getkey();
} else if (c == '?') {
return (ABORT);
} else if (doesc) {
escmode = TRUE;
goto verbatim;
}
}
#else
if ((c=='\\' || c==METACH) && doesc && !escmode) {
c = getkey();
escmode = TRUE;
goto verbatim;
}
#endif
if (c == METACH && ! doesc)
return (ABORT);
#if AtST
if (c==(CNTL|'G') || c==(FUNC|0x61) /* Undo, abort */
|| c==(CNTL|'C') || c==(FUNC|0x62)) /* Help */
#endif
#if (MSDOS | W32)
if (c==(CNTL|'G') || c==(FUNC|0x3C) /* Undo (F2) */
|| c==(CNTL|'C') || c==(FUNC|0x3B)) /* Help (F1) */
#endif
#if (V7 | VMS | CPM)
if (c == (CNTL|'G') || c==(CNTL|'C')) /* Bell, abort */
#endif
return (ABORT);
if (c == CANCEL)
goto start;
#if AtST
if (c == (FUNC|0x47)) /* Clr/Home */
goto start;
#endif
#if (MSDOS | W32)
if (c == (FUNC|0x52)) /* Insert */
goto start;
#endif
if (c==(CNTL|'M') || c==(CNTL|'J')) { /* <Return> */
if (buf[0] == '\0')
return (ABORT);
if (kbdmip != NULL) {
if (kbdmip+i > &kbdm[NKBDM-3])
return(ctrlg());
for (j=0; (c=buf[j])!='\0'; j++)
*kbdmip++ = buf[j] & 0xFF;
*kbdmip++ = '\0';
}
(*tputc)('\r');
ttcol = 0;
(*term.t_flush)();
if (fresh)
return (FALSE);
else
return (TRUE);
}
if (c==UP || c==DOWN)
return (c);
#if (AtST | MSDOS | W32)
if (c==(FUNC|0x48))
return (UP);
if (c==(FUNC|0x50))
return (DOWN);
#endif
#if (AtST | MSDOS | W32)
if (c==RIGHT || c==(FUNC|0x4D)) {
#else
if (c == RIGHT) {
#endif
fresh = FALSE;
if (i<width && buf[i]!='\0') {
c = buf[i] & 0xFF;
if ((c<0x20 || c==0x7F) && c!=ANYCHAR && c!=NEGCHAR)
++col;
++i;
}
goto loop;
}
#if (AtST | MSDOS | W32)
if (c==LEFT || c==(FUNC|0x4B)) {
#else