-
Notifications
You must be signed in to change notification settings - Fork 2
/
new_curse.c
3824 lines (3577 loc) · 85.8 KB
/
new_curse.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
/*
| new_curse.c
|
| A subset of curses developed for use with ae.
|
| written by Hugh Mahon
|
| THIS MATERIAL IS PROVIDED "AS IS". THERE ARE
| NO WARRANTIES OF ANY KIND WITH REGARD TO THIS
| MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE
| IMPLIED WARRANTIES OF MERCHANTABILITY AND
| FITNESS FOR A PARTICULAR PURPOSE. Neither
| Hewlett-Packard nor Hugh Mahon shall be liable
| for errors contained herein, nor for
| incidental or consequential damages in
| connection with the furnishing, performance or
| use of this material. Neither Hewlett-Packard
| nor Hugh Mahon assumes any responsibility for
| the use or reliability of this software or
| documentation. This software and
| documentation is totally UNSUPPORTED. There
| is no support contract available. Hewlett-
| Packard has done NO Quality Assurance on ANY
| of the program or documentation. You may find
| the quality of the materials inferior to
| supported materials.
|
| This software is not a product of Hewlett-Packard, Co., or any
| other company. No support is implied or offered with this software.
| You've got the source, and you're on your own.
|
| This software may be distributed under the terms of Larry Wall's
| Artistic license, a copy of which is included in this distribution.
|
| This notice must be included with this software and any derivatives.
|
| Copyright (c) 1986, 1987, 1988, 1991, 1992, 1993, 1994, 1995 Hugh Mahon
| All are rights reserved.
|
| $Header: /home/hugh/sources/old_ae/RCS/new_curse.c,v 1.54 2002/09/21 00:47:14 hugh Exp $
|
*/
char *copyright_message[] = { "Copyright (c) 1986, 1987, 1988, 1991, 1992, 1993, 1994, 1995 Hugh Mahon",
"All rights are reserved."};
char * new_curse_name= "@(#) new_curse.c $Revision: 1.54 $";
#include "new_curse.h"
#include <signal.h>
#include <fcntl.h>
#ifdef SYS5
#include <string.h>
#else
#include <strings.h>
#endif
#ifdef BSD_SELECT
#include <sys/types.h>
#include <sys/time.h>
#ifdef SLCT_HDR
#include <sys/select.h> /* on AIX */
#endif /* SLCT_HDR */
#endif /* BSD_SELECT */
#ifdef HAS_STDLIB
#include <stdlib.h>
#endif
#if defined(__STDC__)
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#ifdef HAS_UNISTD
#include <unistd.h>
#endif
#ifdef HAS_SYS_IOCTL
#include <sys/ioctl.h>
#endif
struct _line *top_of_win;
WINDOW *curscr;
static WINDOW *virtual_scr;
WINDOW *stdscr;
WINDOW *last_window_refreshed;
#ifdef TIOCGWINSZ
struct winsize ws;
#endif
#define min(a, b) (a < b ? a : b)
#define highbitset(a) ((a) & 0x80)
#ifndef CAP
#define String_Out(table, stack, place) Info_Out(table, stack, place)
#else
#define String_Out(table, stack, place) Cap_Out(table, stack, place)
#endif
#define bw__ 0 /* booleans */
#define am__ 1
#define xb__ 2
#define xs__ 3 /* hp glitch (standout not erased by overwrite) */
#define xn__ 4
#define eo__ 5
#define gn__ 6 /* generic type terminal */
#define hc__ 7 /* hardcopy terminal */
#define km__ 8
#define hs__ 9
#define in__ 10
#define da__ 11
#define db__ 12
#define mi__ 13 /* safe to move during insert mode */
#define ms__ 14 /* safe to move during standout mode */
#define os__ 15
#define es__ 16
#define xt__ 17
#define hz__ 18 /* hazeltine glitch */
#define ul__ 19
#define xo__ 20
#define chts__ 21
#define nxon__ 22
#define nrrmc__ 23
#define npc__ 24
#define mc5i__ 25
#define co__ 0 /* number of columns */ /* numbers */
#define it__ 1 /* spaces per tab */
#define li__ 2 /* number of lines */
#define lm__ 3
#define sg__ 4 /* magic cookie glitch */
#define pb__ 5
#define vt__ 6
#define ws__ 7
#define cols__ 0
#define lines__ 2
#define xmc__ 4
#define vt__ 6
#define wsl__ 7
#define nlab__ 8
#define lh__ 9
#define lw__ 10
#define bt__ 0 /* back tab */ /* strings */
#define bl__ 1 /* bell */
#define cr__ 2 /* carriage return */
#define cs__ 3 /* change scroll region */
#define ct__ 4 /* clear all tab stops */
#define cl__ 5 /* clear screen and home cursor */
#define ce__ 6 /* clear to end of line */
#define cd__ 7 /* clear to end of display */
#define ch__ 8 /* set cursor column */
#define CC__ 9 /* term, settable cmd char in */
#define cm__ 10 /* screen rel cursor motion, row, column */
#define do__ 11 /* down one line */
#define ho__ 12 /* home cursor */
#define vi__ 13 /* make cursor invisible */
#define le__ 14 /* move cursor left one space */
#define CM__ 15 /* memory rel cursor addressing */
#define ve__ 16 /* make cursor appear normal */
#define nd__ 17 /* non-destructive space (cursor right) */
#define ll__ 18 /* last line, first col */
#define up__ 19 /* cursor up */
#define vs__ 20
#define dc__ 21 /* delete character */
#define dl__ 22 /* delete line */
#define ds__ 23
#define hd__ 24
#define as__ 25
#define mb__ 26
#define md__ 27 /* turn on bold */
#define ti__ 28
#define dm__ 29 /* turn on delete mode */
#define mh__ 30 /* half bright mode */
#define im__ 31 /* insert mode */
#define mk__ 32
#define mp__ 33
#define mr__ 34
#define so__ 35 /* enter standout mode */
#define us__ 36
#define ec__ 37
#define ae__ 38
#define me__ 39
#define te__ 40
#define ed__ 41
#define ei__ 42 /* exit insert mode */
#define se__ 43 /* exit standout mode */
#define ue__ 44
#define vb__ 45
#define ff__ 46
#define fs__ 47
#define i1__ 48
#define i2__ 49
#define i3__ 50
#define if__ 51
#define ic__ 52
#define al__ 53
#define ip__ 54
#define kb__ 55 /* backspace key */
#define ka__ 56
#define kC__ 57
#define kt__ 58
#define kD__ 59
#define kL__ 60
#define kd__ 61
#define kM__ 62
#define kE__ 63
#define kS__ 64
#define k0__ 65
#define k1__ 66
#define kf10__ 67
#define k2__ 68
#define k3__ 69
#define k4__ 70
#define k5__ 71
#define k6__ 72
#define k7__ 73
#define k8__ 74
#define k9__ 75
#define kh__ 76
#define kI__ 77
#define kA__ 78
#define kl__ 79
#define kH__ 80
#define kN__ 81
#define kP__ 82
#define kr__ 83
#define kF__ 84
#define kR__ 85
#define kT__ 86
#define ku__ 87 /* key up */
#define ke__ 88
#define ks__ 89
#define l0__ 90
#define l1__ 91
#define la__ 92
#define l2__ 93
#define l3__ 94
#define l4__ 95
#define l5__ 96
#define l6__ 97
#define l7__ 98
#define l8__ 99
#define l9__ 100
#define mo__ 101
#define mm__ 102
#define nw__ 103
#define pc__ 104
#define DC__ 105
#define DL__ 106
#define DO__ 107
#define IC__ 118
#define SF__ 109
#define AL__ 110
#define LE__ 111
#define RI__ 112
#define SR__ 113
#define UP__ 114
#define pk__ 115
#define pl__ 116
#define px__ 117
#define ps__ 118
#define pf__ 119
#define po__ 120
#define rp__ 121
#define r1__ 122
#define r2__ 123
#define r3__ 124
#define rf__ 125
#define rc__ 126
#define cv__ 127
#define sc__ 128
#define sf__ 129
#define sr__ 130
#define sa__ 131 /* sgr */
#define st__ 132
#define wi__ 133
#define ta__ 134
#define ts__ 135
#define uc__ 136
#define hu__ 137
#define iP__ 138
#define K1__ 139
#define K2__ 140
#define K3__ 141
#define K4__ 142
#define K5__ 143
#define pO__ 144
#define ml__ 145
#define mu__ 146
#define rmp__ 145
#define acsc__ 146
#define pln__ 147
#define kcbt__ 148
#define smxon__ 149
#define rmxon__ 150
#define smam__ 151
#define rmam__ 152
#define xonc__ 153
#define xoffc__ 154
#define enacs__ 155
#define smln__ 156
#define rmln__ 157
#define kbeg__ 158
#define kcan__ 159
#define kclo__ 160
#define kcmd__ 161
#define kcpy__ 162
#define kcrt__ 163
#define kend__ 164
#define kent__ 165
#define kext__ 166
#define kfnd__ 167
#define khlp__ 168
#define kmrk__ 169
#define kmsg__ 170
#define kmov__ 171
#define knxt__ 172
#define kopn__ 173
#define kopt__ 174
#define kprv__ 175
#define kprt__ 176
#define krdo__ 177
#define kref__ 178
#define krfr__ 179
#define krpl__ 180
#define krst__ 181
#define kres__ 182
#define ksav__ 183
#define kspd__ 184
#define kund__ 185
#define kBEG__ 186
#define kCAN__ 187
#define kCMD__ 188
#define kCPY__ 189
#define kCRT__ 190
#define kDC__ 191
#define kDL__ 192
#define kslt__ 193
#define kEND__ 194
#define kEOL__ 195
#define kEXT__ 196
#define kFND__ 197
#define kHLP__ 198
#define kHOM__ 199
#define kIC__ 200
#define kLFT__ 201
#define kMSG__ 202
#define kMOV__ 203
#define kNXT__ 204
#define kOPT__ 205
#define kPRV__ 206
#define kPRT__ 207
#define kRDO__ 208
#define kRPL__ 209
#define kRIT__ 210
#define kRES__ 211
#define kSAV__ 212
#define kSPD__ 213
#define kUND__ 214
#define rfi__ 215
#define kf11__ 216
#define kf12__ 217
#define kf13__ 218
#define kf14__ 219
#define kf15__ 220
#define kf16__ 221
#define kf17__ 222
#define kf18__ 223
#define kf19__ 224
#define kf20__ 225
#define kf21__ 226
#define kf22__ 227
#define kf23__ 228
#define kf24__ 229
#define kf25__ 230
#define kf26__ 231
#define kf27__ 232
#define kf28__ 233
#define kf29__ 234
#define kf30__ 235
#define kf31__ 236
#define kf32__ 237
#define kf33__ 238
#define kf34__ 239
#define kf35__ 240
#define kf36__ 241
#define kf37__ 242
#define kf38__ 243
#define kf39__ 244
#define kf40__ 245
#define kf41__ 246
#define kf42__ 247
#define kf43__ 248
#define kf44__ 249
#define kf45__ 250
#define kf46__ 251
#define kf47__ 252
#define kf48__ 253
#define kf49__ 254
#define kf50__ 255
#define kf51__ 256
#define kf52__ 257
#define kf53__ 258
#define kf54__ 259
#define kf55__ 260
#define kf56__ 261
#define kf57__ 262
#define kf58__ 263
#define kf59__ 264
#define kf60__ 265
#define kf61__ 266
#define kf62__ 267
#define kf63__ 268
#define el1__ 269
#define mgc__ 270
#define smgl__ 271
#define smgr__ 272
#ifdef CAP
char *Boolean_names[] = {
"bw", "am", "xb", "xs", "xn", "eo", "gn", "hc", "km", "hs", "in", "da", "db",
"mi", "ms", "os", "es", "xt", "hz", "ul", "xo", "HC", "nx", "NR", "NP", "5i"
};
char *Number_names[] = {
"co#", "it#", "li#", "lm#", "sg#", "pb#", "vt#", "ws#", "Nl#", "lh#", "lw#"
};
char *String_names[] = {
"bt=", "bl=", "cr=", "cs=", "ct=", "cl=", "ce=", "cd=", "ch=", "CC=", "cm=",
"do=", "ho=", "vi=", "le=", "CM=", "ve=", "nd=", "ll=", "up=", "vs=", "dc=",
"dl=", "ds=", "hd=", "as=", "mb=", "md=", "ti=", "dm=", "mh=", "im=", "mk=",
"mp=", "mr=", "so=", "us=", "ec=", "ae=", "me=", "te=", "ed=", "ei=", "se=",
"ue=", "vb=", "ff=", "fs=", "i1=", "i2=", "i3=", "if=", "ic=", "al=", "ip=",
"kb=", "ka=", "kC=", "kt=", "kD=", "kL=", "kd=", "kM=", "kE=", "kS=", "k0=",
"k1=", "k;=", "k2=", "k3=", "k4=", "k5=", "k6=", "k7=", "k8=", "k9=", "kh=",
"kI=", "kA=", "kl=", "kH=", "kN=", "kP=", "kr=", "kF=", "kR=", "kT=", "ku=",
"ke=", "ks=", "l0=", "l1=", "la=", "l2=", "l3=", "l4=", "l5=", "l6=", "l7=",
"l8=", "l9=", "mo=", "mm=", "nw=", "pc=", "DC=", "DL=", "DO=", "IC=", "SF=",
"AL=", "LE=", "RI=", "SR=", "UP=", "pk=", "pl=", "px=", "ps=", "pf=", "po=",
"rp=", "r1=", "r2=", "r3=", "rf=", "rc=", "cv=", "sc=", "sf=", "sr=", "sa=",
"st=", "wi=", "ta=", "ts=", "uc=", "hu=", "iP=", "K1=", "K3=", "K2=", "K4=",
"K5=", "pO=", "rP=", "ac=", "pn=", "kB=", "SX=", "RX=", "SA=", "RA=", "XN=",
"XF=", "eA=", "LO=", "LF=", "@1=", "@2=", "@3=", "@4=", "@5=", "@6=", "@7=",
"@8=", "@9=", "@0=", "%1=", "%2=", "%3=", "%4=", "%5=", "%6=", "%7=", "%8=",
"%9=", "%0=", "&1=", "&2=", "&3=", "&4=", "&5=", "&6=", "&7=", "&8=", "&9=",
"&0=", "*1=", "*2=", "*3=", "*4=", "*5=", "*6=", "*7=", "*8=", "*9=", "*0=",
"#1=", "#2=", "#3=", "#4=", "%a=", "%b=", "%c=", "%d=", "%e=", "%f=", "%g=",
"%h=", "%i=", "%j=", "!1=", "!2=", "!3=", "RF=", "F1=", "F2=", "F3=", "F4=",
"F5=", "F6=", "F7=", "F8=", "F9=", "FA=", "FB=", "FC=", "FD=", "FE=", "FF=",
"FG=", "FH=", "FI=", "FJ=", "FK=", "FL=", "FM=", "FN=", "FO=", "FP=", "FQ=",
"FR=", "FS=", "FT=", "FU=", "FV=", "FW=", "FX=", "FY=", "FZ=", "Fa=", "Fb=",
"Fc=", "Fd=", "Fe=", "Ff=", "Fg=", "Fh=", "Fi=", "Fj=", "Fk=", "Fl=", "Fm=",
"Fn=", "Fo=", "Fp=", "Fq=", "Fr=", "cb=", "MC=", "ML=", "MR="
};
#endif
char *new_curse = "October 1987";
char in_buff[100]; /* buffer for ungetch */
int bufp; /* next free position in in_buff */
char *TERMINAL_TYPE = NULL; /* terminal type to be gotten from environment */
int CFOUND = FALSE;
int Data_Line_len = 0;
int Max_Key_len; /* max length of a sequence sent by a key */
char *Data_Line = NULL;
char *TERM_PATH = NULL;
char *TERM_data_ptr = NULL;
char *Term_File_name = NULL; /* name of file containing terminal description */
FILE *TFP; /* file pointer to file with terminal des. */
int Fildes; /* file descriptor for terminfo file */
int STAND = FALSE; /* is standout mode activated? */
int TERM_INFO = FALSE; /* is terminfo being used (TRUE), or termcap (FALSE) */
int Time_Out; /* set when time elapsed while trying to read function key */
int Curr_x; /* current x position on screen */
int Curr_y; /* current y position on the screen */
int LINES;
int COLS;
int Move_It; /* flag to move cursor if magic cookie glitch */
int initialized = FALSE; /* tells whether new_curse is initialized */
float speed;
float chars_per_millisecond;
int Repaint_screen; /* if an operation to change screen impossible, repaint screen */
int Intr; /* storeage for interrupt character */
int Parity; /* 0 = no parity, 1 = odd parity, 2 = even parity */
int Noblock; /* for BSD systems */
int Num_bits; /* number of bits per character */
int Flip_Bytes; /* some systems have byte order reversed */
int interrupt_flag = FALSE; /* set true if SIGWINCH received */
#ifndef CAP
char *Strings;
#endif
#if !defined(TERMCAP)
#define TERMCAP "/etc/termcap"
#endif
struct KEYS {
int length; /* length of string sent by key */
char *string; /* string sent by key */
int value; /* CURSES value of key (9-bit) */
};
struct KEY_STACK {
struct KEYS *element;
struct KEY_STACK *next;
};
struct KEY_STACK *KEY_TOS = NULL;
struct KEY_STACK *KEY_POINT;
/*
|
| Not all systems have good terminal information, so we will define
| keyboard information here for the most widely used terminal type,
| the VT100.
|
*/
struct KEYS vt100[] =
{
{ 3, "\033[A", 0403 }, /* key up */
{ 3, "\033[C", 0405 }, /* key right */
{ 3, "\033[D", 0404 }, /* key left */
{ 4, "\033[6~", 0522 }, /* key next page */
{ 4, "\033[5~", 0523 }, /* key prev page */
{ 3, "\033[[", 0550 }, /* key end */
{ 3, "\033[@", 0406 }, /* key home */
{ 4, "\033[2~", 0513 }, /* key insert char */
{ 3, "\033[y", 0410 }, /* key F0 */
{ 3, "\033[P", 0411 }, /* key F1 */
{ 3, "\033[Q", 0412 }, /* key F2 */
{ 3, "\033[R", 0413 }, /* key F3 */
{ 3, "\033[S", 0414 }, /* key F4 */
{ 3, "\033[t", 0415 }, /* key F5 */
{ 3, "\033[u", 0416 }, /* key F6 */
{ 3, "\033[v", 0417 }, /* key F7 */
{ 3, "\033[l", 0420 }, /* key F8 */
{ 3, "\033[w", 0421 }, /* key F9 */
{ 3, "\033[x", 0422 }, /* key F10 */
{ 5, "\033[10~", 0410 }, /* key F0 */
{ 5, "\033[11~", 0411 }, /* key F1 */
{ 5, "\033[12~", 0412 }, /* key F2 */
{ 5, "\033[13~", 0413 }, /* key F3 */
{ 5, "\033[14~", 0414 }, /* key F4 */
{ 5, "\033[15~", 0415 }, /* key F5 */
{ 5, "\033[17~", 0416 }, /* key F6 */
{ 5, "\033[18~", 0417 }, /* key F7 */
{ 5, "\033[19~", 0420 }, /* key F8 */
{ 5, "\033[20~", 0421 }, /* key F9 */
{ 5, "\033[21~", 0422 }, /* key F10 */
{ 5, "\033[23~", 0423 }, /* key F11 */
{ 5, "\033[24~", 0424 }, /* key F12 */
{ 3, "\033[q", 0534 }, /* ka1 upper-left of keypad */
{ 3, "\033[s", 0535 }, /* ka3 upper-right of keypad */
{ 3, "\033[r", 0536 }, /* kb2 center of keypad */
{ 3, "\033[p", 0537 }, /* kc1 lower-left of keypad */
{ 3, "\033[n", 0540 }, /* kc3 lower-right of keypad */
/*
| The following are the same keys as above, but with
| a different character following the escape char.
*/
{ 3, "\033OA", 0403 }, /* key up */
{ 3, "\033OC", 0405 }, /* key right */
{ 3, "\033OD", 0404 }, /* key left */
{ 3, "\033OB", 0402 }, /* key down */
{ 4, "\033O6~", 0522 }, /* key next page */
{ 4, "\033O5~", 0523 }, /* key prev page */
{ 3, "\033O[", 0550 }, /* key end */
{ 3, "\033O@", 0406 }, /* key home */
{ 4, "\033O2~", 0513 }, /* key insert char */
{ 3, "\033Oy", 0410 }, /* key F0 */
{ 3, "\033OP", 0411 }, /* key F1 */
{ 3, "\033OQ", 0412 }, /* key F2 */
{ 3, "\033OR", 0413 }, /* key F3 */
{ 3, "\033OS", 0414 }, /* key F4 */
{ 3, "\033Ot", 0415 }, /* key F5 */
{ 3, "\033Ou", 0416 }, /* key F6 */
{ 3, "\033Ov", 0417 }, /* key F7 */
{ 3, "\033Ol", 0420 }, /* key F8 */
{ 3, "\033Ow", 0421 }, /* key F9 */
{ 3, "\033Ox", 0422 }, /* key F10 */
{ 5, "\033O10~", 0410 }, /* key F0 */
{ 5, "\033O11~", 0411 }, /* key F1 */
{ 5, "\033O12~", 0412 }, /* key F2 */
{ 5, "\033O13~", 0413 }, /* key F3 */
{ 5, "\033O14~", 0414 }, /* key F4 */
{ 5, "\033O15~", 0415 }, /* key F5 */
{ 5, "\033O17~", 0416 }, /* key F6 */
{ 5, "\033O18~", 0417 }, /* key F7 */
{ 5, "\033O19~", 0420 }, /* key F8 */
{ 5, "\033O20~", 0421 }, /* key F9 */
{ 5, "\033O21~", 0422 }, /* key F10 */
{ 5, "\033O23~", 0423 }, /* key F11 */
{ 5, "\033O24~", 0424 }, /* key F12 */
{ 3, "\033Oq", 0534 }, /* ka1 upper-left of keypad */
{ 3, "\033Os", 0535 }, /* ka3 upper-right of keypad */
{ 3, "\033Or", 0536 }, /* kb2 center of keypad */
{ 3, "\033Op", 0537 }, /* kc1 lower-left of keypad */
{ 3, "\033On", 0540 }, /* kc3 lower-right of keypad */
{ 0, "", 0 } /* end */
};
struct Parameters {
int value;
struct Parameters *next;
};
int Key_vals[] = {
0407, 0526, 0515, 0525, 0512, 0510, 0402, 0514, 0517, 0516, 0410, 0411,
0422, 0412, 0413, 0414, 0415, 0416, 0417, 0420, 0421, 0406, 0513, 0511,
0404, 0533, 0522, 0523, 0405, 0520, 0521, 0524, 0403,
0534, 0535, 0536, 0537, 0540, 0541, 0542, 0543, 0544, 0545, 0546, 0547,
0550, 0527, 0551, 0552, 0553, 0554, 0555, 0556, 0557, 0560, 0561, 0562,
0532, 0563, 0564, 0565, 0566, 0567, 0570, 0571, 0627, 0630, 0572, 0573,
0574, 0575, 0576, 0577, 0600, 0601, 0602, 0603, 0604, 0605, 0606, 0607,
0610, 0611, 0612, 0613, 0614, 0615, 0616, 0617, 0620, 0621, 0622, 0623,
0624, 0625, 0626, 0423, 0424, 0425, 0426, 0427, 0430, 0431,
0432, 0433, 0434, 0435, 0436, 0437, 0440, 0441, 0442, 0443, 0444, 0445,
0446, 0447, 0450, 0451, 0452, 0453, 0454, 0455, 0456, 0457, 0460, 0461,
0462, 0463, 0464, 0465, 0466, 0467, 0470, 0471, 0472, 0473, 0474, 0475,
0476, 0477, 0500, 0501, 0502, 0503, 0504, 0505, 0506, 0507
};
int attributes_set[9];
static int nc_attributes = 0; /* global attributes for new_curse to observe */
#ifdef SYS5
struct termio Terminal;
struct termio Saved_tty;
#else
struct sgttyb Terminal;
struct sgttyb Saved_tty;
#endif
char *tc_;
int Booleans[128];
int Numbers[128];
char *String_table[1024];
int *virtual_lines;
static char nc_scrolling_ability = FALSE;
char *terminfo_path[] = {
"/lib/terminfo",
"/usr/lib/terminfo",
"/usr/share/lib/terminfo",
"/usr/share/terminfo",
NULL
};
#ifdef CAP
#if defined(__STDC__) || defined(__cplusplus)
#define P_(s) s
#else
#define P_(s) ()
#endif /* __STDC__ */
int tc_Get_int P_((int));
void CAP_PARSE P_((void));
void Find_term P_((void));
#undef P_
#endif /* CAP */
#ifndef __STDC__
#ifndef HAS_STDLIB
extern char *fgets();
extern char *malloc();
extern char *getenv();
FILE *fopen(); /* declaration for open function */
#endif /* HAS_STDLIB */
#endif /* __STDC__ */
#ifdef SIGWINCH
/*
| Copy the contents of one window to another.
*/
void
copy_window(origin, destination)
WINDOW *origin, *destination;
{
int row, column;
struct _line *orig, *dest;
orig = origin->first_line;
dest = destination->first_line;
for (row = 0;
row < (min(origin->Num_lines, destination->Num_lines));
row++)
{
for (column = 0;
column < (min(origin->Num_cols, destination->Num_cols));
column++)
{
dest->row[column] = orig->row[column];
dest->attributes[column] = orig->attributes[column];
}
dest->changed = orig->changed;
dest->scroll = orig->scroll;
dest->last_char = min(orig->last_char, destination->Num_cols);
orig = orig->next_screen;
dest = dest->next_screen;
}
destination->LX = min((destination->Num_cols - 1), origin->LX);
destination->LY = min((destination->Num_lines - 1), origin->LY);
destination->Attrib = origin->Attrib;
destination->scroll_up = origin->scroll_up;
destination->scroll_down = origin->scroll_down;
destination->SCROLL_CLEAR = origin->SCROLL_CLEAR;
}
void
reinitscr(foo)
int foo;
{
WINDOW *local_virt;
WINDOW *local_std;
WINDOW *local_cur;
signal(SIGWINCH, reinitscr);
#ifdef TIOCGWINSZ
if (ioctl(0, TIOCGWINSZ, &ws) >= 0)
{
if (ws.ws_row == LINES && ws.ws_col == COLS)
return;
if (ws.ws_row > 0)
LINES = ws.ws_row;
if (ws.ws_col > 0)
COLS = ws.ws_col;
}
#endif /* TIOCGWINSZ */
local_virt = newwin(LINES, COLS, 0, 0);
local_std = newwin(LINES, COLS, 0, 0);
local_cur = newwin(LINES, COLS, 0, 0);
copy_window(virtual_scr, local_virt);
copy_window(stdscr, local_std);
copy_window(curscr, local_cur);
delwin(virtual_scr);
delwin(stdscr);
delwin(curscr);
virtual_scr = local_virt;
stdscr = local_std;
curscr = local_cur;
free(virtual_lines);
virtual_lines = (int *) malloc(LINES * (sizeof(int)));
interrupt_flag = TRUE;
}
#endif /* SIGWINCH */
void
initscr() /* initialize terminal for operations */
{
int value;
int counter;
char *lines_string;
char *columns_string;
#ifdef CAP
char *pointer;
#endif /* CAP */
#ifdef DIAG
printf("starting initscr \n");fflush(stdout);
#endif
if (initialized)
return;
#ifdef BSD_SELECT
setbuf(stdin, NULL);
#endif /* BSD_SELECT */
Flip_Bytes = FALSE;
Parity = 0;
Time_Out = FALSE;
bufp = 0;
Move_It = FALSE;
Noblock = FALSE;
#ifdef SYS5
value = ioctl(0, TCGETA, &Terminal);
if (Terminal.c_cflag & PARENB)
{
if (Terminal.c_cflag & PARENB)
Parity = 1;
else
Parity = 2;
}
if ((Terminal.c_cflag & CS8) == CS8)
{
Num_bits = 8;
}
else if ((Terminal.c_cflag & CS7) == CS7)
Num_bits = 7;
else if ((Terminal.c_cflag & CS6) == CS6)
Num_bits = 6;
else
Num_bits = 5;
value = Terminal.c_cflag & 037;
switch (value) {
case 01: speed = 50.0;
break;
case 02: speed = 75.0;
break;
case 03: speed = 110.0;
break;
case 04: speed = 134.5;
break;
case 05: speed = 150.0;
break;
case 06: speed = 200.0;
break;
case 07: speed = 300.0;
break;
case 010: speed = 600.0;
break;
case 011: speed = 900.0;
break;
case 012: speed = 1200.0;
break;
case 013: speed = 1800.0;
break;
case 014: speed = 2400.0;
break;
case 015: speed = 3600.0;
break;
case 016: speed = 4800.0;
break;
case 017: speed = 7200.0;
break;
case 020: speed = 9600.0;
break;
case 021: speed = 19200.0;
break;
case 022: speed = 38400.0;
break;
default: speed = 0.0;
}
#else
value = ioctl(0, TIOCGETP, &Terminal);
if (Terminal.sg_flags & EVENP)
Parity = 2;
else if (Terminal.sg_flags & ODDP)
Parity = 1;
value = Terminal.sg_ospeed;
switch (value) {
case 01: speed = 50.0;
break;
case 02: speed = 75.0;
break;
case 03: speed = 110.0;
break;
case 04: speed = 134.5;
break;
case 05: speed = 150.0;
break;
case 06: speed = 200.0;
break;
case 07: speed = 300.0;
break;
case 010: speed = 600.0;
break;
case 011: speed = 1200.0;
break;
case 012: speed = 1800.0;
break;
case 013: speed = 2400.0;
break;
case 014: speed = 4800.0;
break;
case 015: speed = 9600.0;
break;
default: speed = 0.0;
}
#endif
chars_per_millisecond = (0.001 * speed) / 8.0;
TERMINAL_TYPE = getenv("TERM");
if (TERMINAL_TYPE == NULL)
{
printf("unknown terminal type\n");
exit(0);
}
#ifndef CAP
Fildes = -1;
TERM_PATH = getenv("TERMINFO");
if (TERM_PATH != NULL)
{
Data_Line_len = 23 + strlen(TERM_PATH) + strlen(TERMINAL_TYPE);
Term_File_name = malloc(Data_Line_len);
sprintf(Term_File_name, "%s/%c/%s", TERM_PATH, *TERMINAL_TYPE, TERMINAL_TYPE);
Fildes = open(Term_File_name, O_RDONLY);
if (Fildes == -1)
{
sprintf(Term_File_name, "%s/%x/%s", TERM_PATH, *TERMINAL_TYPE, TERMINAL_TYPE);
Fildes = open(Term_File_name, O_RDONLY);
}
}
counter = 0;
while ((Fildes == -1) && (terminfo_path[counter] != NULL))
{
TERM_PATH = terminfo_path[counter];
Data_Line_len = 23 + strlen(TERM_PATH) + strlen(TERMINAL_TYPE);
Term_File_name = malloc(Data_Line_len);
sprintf(Term_File_name, "%s/%c/%s", TERM_PATH, *TERMINAL_TYPE, TERMINAL_TYPE);
Fildes = open(Term_File_name, O_RDONLY);
if (Fildes == -1)
{
sprintf(Term_File_name, "%s/%x/%s", TERM_PATH, *TERMINAL_TYPE, TERMINAL_TYPE);
Fildes = open(Term_File_name, O_RDONLY);
}
counter++;
}
if (Fildes == -1)
{
free(Term_File_name);
Term_File_name = NULL;
}
else
TERM_INFO = INFO_PARSE();
#else
/*
| termcap information can be in the TERMCAP env variable, if so
| use that, otherwise check the /etc/termcap file
*/
if ((pointer = Term_File_name = getenv("TERMCAP")) != NULL)
{
if (*Term_File_name != '/')
Term_File_name = TERMCAP;
}
else
{
Term_File_name = TERMCAP;
}
if ((TFP = fopen(Term_File_name, "r")) == NULL)
{
printf("unable to open %s file \n", TERMCAP);
exit(0);
}
for (value = 0; value < 1024; value++)
String_table[value] = NULL;
for (value = 0; value < 128; value++)
Booleans[value] = 0;
for (value = 0; value < 128; value++)
Numbers[value] = 0;
Data_Line = malloc(512);
if (pointer && *pointer != '/')
{
TERM_data_ptr = pointer;
CAP_PARSE();
}
else
{
Find_term();
CAP_PARSE();
}
#endif
if (String_table[pc__] == NULL)
String_table[pc__] = "\0";
if ((String_table[cm__] == NULL) || (Booleans[hc__]))
{
fprintf(stderr, "sorry, unable to use this terminal type for screen editing\n");
exit(0);
}
Key_Get();
keys_vt100();
LINES = Numbers[li__];
COLS = Numbers[co__];
if ((lines_string = getenv("LINES")) != NULL)
{
value = atoi(lines_string);
if (value > 0)
LINES = value;
}
if ((columns_string = getenv("COLUMNS")) != NULL)
{