-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurses.c
More file actions
1108 lines (943 loc) · 20.1 KB
/
curses.c
File metadata and controls
1108 lines (943 loc) · 20.1 KB
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
/*
* Project : tin - a Usenet reader
* Module : curses.c
* Author : D.Taylor & I.Lea
* Created : 01-01-86
* Updated : 17-05-94
* Notes : This is a screen management library borrowed with permission
* from the Elm mail system. This library was hacked to provide
* what tin needs.
* Copyright : Copyright (c) 1986-94 Dave Taylor & Iain Lea
* The Elm Mail System - @Revision: 2.1 $ $State: Exp @
*/
#include "tin.h"
#include "tcurses.h"
#if USE_CURSES
void my_dummy(void) { } /* ANSI C requires non-empty file */
#else /* !USE_CURSES */
#ifdef M_AMIGA
# undef BSD
#endif
#ifndef ns32000
# undef sinix
#endif
#ifdef HAVE_CURSES_H
# if defined(M_XENIX)
# undef HZ /* looks like a bug in M_XENIX includefiles */
# endif
/* it doesn't do any harm, and <curses.h> may have conflicting defs */
# undef TRUE
# undef FALSE
# include <curses.h>
#endif
#if 0 /* FIXME: this has prototypes, but opens up new problems! */
#ifdef HAVE_TERM_H
# include <term.h>
#endif
#endif /* 0 */
#ifdef HAVE_TERMCAP_H
# include <termcap.h>
#endif
#ifdef VMS
#include <descrip.h>
#include <iodef.h>
#include <ssdef.h>
#include <dvidef.h>
#ifdef __GNUC__
#include <sys$routines.h>
#include <lib$routines.h>
#endif
#endif
#define DEFAULT_LINES_ON_TERMINAL 24
#define DEFAULT_COLUMNS_ON_TERMINAL 80
int cLINES = DEFAULT_LINES_ON_TERMINAL - 1;
int cCOLS = DEFAULT_COLUMNS_ON_TERMINAL;
t_bool inverse_okay = TRUE;
static int _inraw = FALSE; /* are we IN rawmode? */
int _hp_glitch = FALSE; /* standout not erased by overwriting on HP terms */
static int xclicks=FALSE; /* do we have an xterm? */
#ifndef INDEX_DAEMON
#define BACKSPACE '\b'
#define VERY_LONG_STRING 2500
#define TTYIN 0
#ifdef HAVE_CONFIG_H
#if HAVE_TERMIOS_H && HAVE_TCGETATTR && HAVE_TCSETATTR
# ifdef HAVE_IOCTL_H
# include <ioctl.h>
# else
# ifdef HAVE_SYS_IOCTL_H
# include <sys/ioctl.h>
# endif
# endif
# if !defined(sun) || !defined(NL0)
# include <termios.h>
# endif
# define USE_POSIX_TERMIOS 1
# define TTY struct termios
#else
# if HAVE_TERMIO_H
# include <termio.h>
# define USE_TERMIO 1
# define TTY struct termio
# else
# if HAVE_SGTTY_H
# include <sgtty.h>
# define USE_SGTTY 1
# define TTY struct sgttyb
# else
please-fix-me(thanks)
# endif
# endif
#endif
static TTY _raw_tty, _original_tty;
#else /* FIXME: prune the non-autoconf'd stuff */
#if (defined(M_AMIGA) && !defined(__SASC)) || defined(COHERENT) || defined(BSD)
# ifdef BSD4_1
# include <termio.h>
# define USE_TERMIO 1
# else
# include <sgtty.h>
# define USE_SGTTY 1
# endif
#else
# if !defined(SYSV) && !defined(M_AMIGA)
# ifdef MINIX
# include <sgtty.h>
# define USE_SGTTY 1
# else
# ifndef QNX42
# ifdef sinix
# include <termios.h>
# define USE_POSIX_TERMIOS 1
# else
# ifdef VMS
# include <curses.h>
# else
# include <termio.h>
# define USE_TERMIO 1
# endif
# endif
# endif
# endif
# endif
#endif
#ifndef VMS
#if (defined(M_AMIGA) && !defined(__SASC)) || defined(BSD) || defined(MINIX)
# define USE_SGTTY 1
struct sgttyb _raw_tty, _original_tty;
#else
# if !defined(M_AMIGA) && !defined(M_OS2)
# if defined(HAVE_TERMIOS_H) || defined(sinix)
# define USE_POSIX_TERMIOS 1
struct termios _raw_tty, _original_tty;
# else
# define USE_TERMIO 1
struct termio _raw_tty, _original_tty;
# endif
# endif
#endif
#endif /* VMS */
#endif /* HAVE_CONFIG_H */
#ifndef USE_SGTTY
#define USE_SGTTY 0
#endif
#ifndef USE_TERMIO
#define USE_TERMIO 0
#endif
#ifndef USE_POSIX_TERMIOS
#define USE_POSIX_TERMIOS 0
#endif
static char *_clearscreen, *_moveto, *_cleartoeoln, *_cleartoeos,
*_setinverse, *_clearinverse, *_setunderline, *_clearunderline,
*_xclickinit, *_xclickend, *_cursoron, *_cursoroff,
*_terminalinit, *_terminalend, *_keypadlocal, *_keypadxmit;
#ifdef M_AMIGA
static char *_getwinsize;
#endif
static int _columns, _line, _lines;
#ifdef M_UNIX
#if USE_POSIX_TERMIOS
# define SET_TTY(arg) tcsetattr (TTYIN, TCSANOW, arg)
# define GET_TTY(arg) tcgetattr (TTYIN, arg)
#else
# if USE_TERMIO
# define SET_TTY(arg) ioctl (TTYIN, TCSETAW, arg)
# define GET_TTY(arg) ioctl (TTYIN, TCGETA, arg)
# else
# if USE_SGTTY
# define SET_TTY(arg) stty(TTYIN, arg)
# define GET_TTY(arg) gtty(TTYIN, arg)
# else
please-fix-me(thanks)
# endif
# endif
#endif
static char _terminal[1024]; /* Storage for terminal entry */
static char _capabilities[1024]; /* String for cursor motion */
static char *ptr = _capabilities; /* for buffering */
#endif /* M_UNIX */
static int in_inverse; /* 1 when in inverse, 0 otherwise */
#endif /* INDEX_DAEMON */
/*
** Local prototypes
*/
static void ScreenSize (int *num_lines, int *num_columns);
void
setup_screen (void)
{
#ifndef INDEX_DAEMON
/*
* get screen size from termcap entry & setup sizes
*/
_line = 1;
ScreenSize (&cLINES, &cCOLS);
cmd_line = FALSE;
Raw (TRUE);
set_win_size (&cLINES, &cCOLS);
#endif /* INDEX_DAEMON */
}
#ifdef M_UNIX
int
InitScreen (void)
{
#ifndef INDEX_DAEMON
char the_termname[40], *p;
if ((p = getenv ("TERM")) == (char *) 0) {
fprintf (stderr, txt_no_term_set, progname);
return (FALSE);
}
if (strcpy (the_termname, p) == NULL) {
fprintf (stderr, txt_cannot_get_term, progname);
return (FALSE);
}
if (tgetent (_terminal, the_termname) != 1) {
fprintf (stderr, txt_cannot_get_term_entry, progname);
return (FALSE);
}
/* load in all those pesky values */
_clearscreen = tgetstr ("cl", &ptr);
_moveto = tgetstr ("cm", &ptr);
_cleartoeoln = tgetstr ("ce", &ptr);
_cleartoeos = tgetstr ("cd", &ptr);
_lines = tgetnum ("li");
_columns = tgetnum ("co");
_setinverse = tgetstr ("so", &ptr);
_clearinverse = tgetstr ("se", &ptr);
_setunderline = tgetstr ("us", &ptr);
_clearunderline = tgetstr ("ue", &ptr);
_hp_glitch = tgetflag ("xs");
#ifdef HAVE_BROKEN_TGETSTR
_terminalinit = "";
_terminalend = "";
_keypadlocal = "";
_keypadxmit = "";
#else
_terminalinit = tgetstr ("ti", &ptr);
_terminalend = tgetstr ("te", &ptr);
_keypadlocal = tgetstr ("ke", &ptr);
_keypadxmit = tgetstr ("ks", &ptr);
#endif
_cursoron = NULL;
_cursoroff = NULL;
if (STRCMPEQ(the_termname, "xterm")) {
xclicks = TRUE;
_xclickinit = "\033[?9h";
_xclickend = "\033[?9l";
}
InitWin ();
if (!_clearscreen) {
fprintf (stderr, txt_no_term_clearscreen, progname);
return (FALSE);
}
if (!_moveto) {
fprintf (stderr, txt_no_term_cursor_motion, progname);
return (FALSE);
}
if (!_cleartoeoln) {
fprintf (stderr, txt_no_term_clear_eol, progname);
return (FALSE);
}
if (!_cleartoeos) {
fprintf (stderr, txt_no_term_clear_eos, progname);
return (FALSE);
}
if (_lines == -1)
_lines = DEFAULT_LINES_ON_TERMINAL;
if (_columns == -1)
_columns = DEFAULT_COLUMNS_ON_TERMINAL;
/*
* kludge to workaround no inverse
*/
if (_setinverse == 0) {
_setinverse = _setunderline;
_clearinverse = _clearunderline;
if (_setinverse == 0)
draw_arrow_mark = 1;
}
return (TRUE);
#else
return (FALSE);
#endif /* INDEX_DAEMON */
}
#else /* !M_UNIX */
int
InitScreen (void)
{
#ifndef INDEX_DAEMON
char *ptr;
/*
* we're going to assume a terminal here...
*/
_clearscreen = "\033[1;1H\033[J";
_moveto = "\033[%d;%dH"; /* not a termcap string! */
_cleartoeoln = "\033[K";
_setinverse = "\033[7m";
_clearinverse = "\033[0m";
_setunderline = "\033[4m";
_clearunderline = "\033[0m";
_keypadlocal = "";
_keypadxmit = "";
#ifdef M_AMIGA
_terminalinit = "\033[12{\033[0 p";
_terminalend = "\033[12}\033[ p";
_cursoron = "\033[ p";
_cursoroff = "\033[0 p";
_cleartoeos = "\033[J";
_getwinsize = "\2330 q";
#endif
#if defined(M_OS2)
_cleartoeos = NULL;
_terminalinit = NULL;
_terminalend = "";
initscr ();
#endif /* M_OS2 */
#if defined(VMS)
_cleartoeos = "\033[J";
_terminalinit = NULL;
_terminalend = "";
#endif
_lines = _columns = -1;
/*
* Get lines and columns from environment settings - useful when
* you're using something other than an Amiga window
*/
if (ptr = getenv ("LINES")) {
_lines = atol (ptr);
}
if (ptr = getenv ("COLUMNS")) {
_columns = atol (ptr);
}
/*
* If that failed, try get a response from the console itself
*/
#ifdef M_AMIGA
if (_lines == -1 || _columns == -1) {
_lines = DEFAULT_LINES_ON_TERMINAL;
_columns = DEFAULT_COLUMNS_ON_TERMINAL;
} else {
_terminalinit = NULL; /* don't do fancy things on a non-amiga console */
_terminalend = NULL;
_cursoroff = NULL;
_cursoron = NULL;
_getwinsize = NULL;
}
#endif /* M_AMIGA */
#ifdef M_OS2
if (_lines == -1 || _columns == -1) {
_lines = LINES;
_columns = COLS;
}
#endif /* M_OS2 */
InitWin ();
#ifdef VMS
{
int input_chan, status;
int item_code, eightbit;
struct sensemode {
short status;
unsigned char xmit_baud;
unsigned char rcv_baud;
unsigned char crfill;
unsigned char lffill;
unsigned char parity;
unsigned char unused;
char class;
char type;
short scr_wid;
unsigned long tt_char : 24, scr_len : 8;
unsigned long tt2_char;
} tty;
$DESCRIPTOR (input_dsc, "TT");
status = SYS$ASSIGN (&input_dsc, &input_chan, 0, 0);
if (!(status & 1))
LIB$STOP (status);
SYS$QIOW (0, input_chan, IO$_SENSEMODE, &tty, 0, 0,
&tty.class, 12, 0, 0, 0, 0);
item_code = DVI$_TT_EIGHTBIT;
status = LIB$GETDVI(&item_code, &input_chan, 0, &eightbit, 0, 0);
_columns = tty.scr_wid;
_lines = tty.scr_len;
if (eightbit)
{ /* if using eightbit then use CSI (octal 233) rather than ESC "[" */
_clearscreen = "\2331;1H\233J";
_moveto = "\233%d;%dH"; /* not a termcap string !*/
_cleartoeoln = "\233K";
_cleartoeos = "\233J";
_setinverse = "\2337m";
_clearinverse = "\2330m";
_setunderline = "\2334m";
_clearunderline = "\2330m";
_keypadlocal = "";
_keypadxmit = "";
}
else
{
_clearscreen = "\033[1;1H\033[J";
_moveto = "\033[%d;%dH"; /* not a termcap string! */
_cleartoeoln = "\033[K";
_cleartoeos = "\033[J";
_setinverse = "\033[7m";
_clearinverse = "\033[0m";
_setunderline = "\033[4m";
_clearunderline = "\033[0m";
_keypadlocal = "";
_keypadxmit = "";
}
#ifdef HAVE_IS_XTERM
if (is_xterm())
{
xclicks = TRUE;
if (eightbit)
{ /* These are the settings for a DECterm but the reply can't easily be parsed */
/* Reply is of the form - CSI Pe ; Pb ; Pr ; Pc & w
Where Pe is the event, Pb the button, Pr and Pc the row and column */
/**
_xclickinit = "\2331;2'z";
_xclickend = "\2330;0'z";
**/
}
else
{
_xclickinit = "\033[?9h";
_xclickend = "\033[?9l";
}
}
#endif
}
#endif
Raw (FALSE);
return (TRUE);
#else
return (FALSE);
#endif /* INDEX_DAEMON */
}
#endif /* M_UNIX */
/*
* returns the number of lines and columns on the display.
*/
static void
ScreenSize (int *num_lines, int *num_columns)
{
#ifndef INDEX_DAEMON
if (_lines == 0) _lines = DEFAULT_LINES_ON_TERMINAL;
if (_columns == 0) _columns = DEFAULT_COLUMNS_ON_TERMINAL;
*num_lines = _lines - 1; /* assume index from zero*/
*num_columns = _columns; /* assume index from one */
#endif /* INDEX_DAEMON */
}
void
InitWin (void)
{
#ifndef INDEX_DAEMON
if (_terminalinit) {
tputs (_terminalinit, 1, outchar);
my_flush();
}
set_keypad_on ();
set_xclick_on ();
#endif /* INDEX_DAEMON */
}
void
EndWin (void)
{
#ifndef INDEX_DAEMON
if (_terminalend) {
tputs (_terminalend, 1, outchar);
my_flush();
}
set_keypad_off ();
set_xclick_off ();
#endif /* INDEX_DAEMON */
}
void
set_keypad_on (void)
{
#ifndef INDEX_DAEMON
# ifdef HAVE_KEYPAD
if (use_keypad && _keypadxmit) {
tputs (_keypadxmit, 1, outchar);
my_flush();
}
# endif
#endif /* INDEX_DAEMON */
}
void
set_keypad_off (void)
{
#ifndef INDEX_DAEMON
# ifdef HAVE_KEYPAD
if (use_keypad && _keypadlocal) {
tputs (_keypadlocal, 1, outchar);
my_flush();
}
# endif
#endif /* INDEX_DAEMON */
}
/*
* clear the screen
*/
void
ClearScreen (void)
{
#ifndef INDEX_DAEMON
tputs (_clearscreen, 1, outchar);
my_flush (); /* clear the output buffer */
_line = 1;
#endif /* INDEX_DAEMON */
}
/*
* move cursor to the specified row column on the screen.
* 0,0 is the top left!
*/
#ifdef M_UNIX
void
MoveCursor (int row, int col)
{
#ifndef INDEX_DAEMON
char *stuff;
stuff = tgoto (_moveto, col, row);
tputs (stuff, 1, outchar);
my_flush ();
_line = row + 1;
#endif /* INDEX_DAEMON */
}
#else /* !M_UNIX */
void
MoveCursor (int row, int col)
{
#ifndef INDEX_DAEMON
char stuff[12], *tgoto();
if (_moveto) {
sprintf (stuff, _moveto, row+1, col+1);
tputs (stuff, 1, outchar);
my_flush ();
_line = row + 1;
}
#endif /* INDEX_DAEMON */
}
#endif /* M_UNIX */
/*
* clear to end of line
*/
void
CleartoEOLN (void)
{
#ifndef INDEX_DAEMON
tputs (_cleartoeoln, 1, outchar);
my_flush (); /* clear the output buffer */
#endif /* INDEX_DAEMON */
}
/*
* clear to end of screen
*/
void
CleartoEOS (void)
{
#ifndef INDEX_DAEMON
int i;
if (_cleartoeos) {
tputs (_cleartoeos, 1, outchar);
} else {
for (i=_line - 1 ; i < _lines ; i++) {
MoveCursor (i, 0);
CleartoEOLN ();
}
}
my_flush (); /* clear the output buffer */
#endif /* INDEX_DAEMON */
}
/*
* set inverse video mode
*/
void
StartInverse (void)
{
#ifndef INDEX_DAEMON
in_inverse = 1;
if (_setinverse && inverse_okay) {
#ifdef HAVE_COLOR
if (use_color) {
bcol(col_invers_bg);
fcol(col_invers_fg);
} else {
tputs (_setinverse, 1, outchar);
}
#else
tputs (_setinverse, 1, outchar);
#endif
}
my_flush ();
#endif /* INDEX_DAEMON */
}
/*
* compliment of startinverse
*/
void
EndInverse (void)
{
#ifndef INDEX_DAEMON
in_inverse = 0;
if (_clearinverse && inverse_okay) {
#ifdef HAVE_COLOR
if (use_color) {
fcol(col_normal);
bcol(col_back);
} else {
tputs (_clearinverse, 1, outchar);
}
#else
tputs (_clearinverse, 1, outchar);
#endif
}
my_flush ();
#endif /* INDEX_DAEMON */
}
/*
* toggle inverse video mode
*/
void
ToggleInverse (void)
{
#ifndef INDEX_DAEMON
if (in_inverse == 0)
StartInverse();
else
EndInverse();
#endif /* INDEX_DAEMON */
}
/*
* returns either 1 or 0, for ON or OFF
*/
int
RawState(void)
{
return (_inraw);
}
/*
* state is either TRUE or FALSE, as indicated by call
*/
void
Raw (
int state)
{
#ifdef VMS
if (state == FALSE && _inraw) {
/* vmsnoraw();*/
_inraw = 0;
} else if (state == TRUE && !_inraw) {
/* vmsraw();*/
_inraw = 1;
}
#else
#if !defined(INDEX_DAEMON) && !defined(M_OS2)
#if defined(M_AMIGA) && defined(__SASC)
_inraw = state;
rawcon (state);
#else
if (state == FALSE && _inraw) {
SET_TTY (&_original_tty);
_inraw = 0;
} else if (state == TRUE && !_inraw) {
GET_TTY (&_original_tty);
GET_TTY (&_raw_tty);
#if USE_SGTTY
_raw_tty.sg_flags &= ~(ECHO | CRMOD); /* echo off */
_raw_tty.sg_flags |= CBREAK; /* raw on */
#ifdef M_AMIGA
_raw_tty.sg_flags |= RAW; /* Manx-C 5.2 does not support CBREAK */
#endif
#else
#ifdef __FreeBSD__
cfmakeraw(&_raw_tty);
_raw_tty.c_lflag |= ISIG; /* for ^Z */
#else
_raw_tty.c_lflag &= ~(ICANON | ECHO); /* noecho raw mode */
_raw_tty.c_cc[VMIN] = '\01'; /* minimum # of chars to queue */
_raw_tty.c_cc[VTIME] = '\0'; /* minimum time to wait for input */
#endif
#endif
SET_TTY (&_raw_tty);
_inraw = 1;
}
#endif /* M_AMIGA */
#endif /* INDEX_DAEMON */
#endif /* !VMS */
}
/*
* read a character with Raw mode set!
*/
#ifndef VMS
#ifdef M_OS2
int
ReadCh (void)
{
#ifndef INDEX_DAEMON
char ch;
KBDKEYINFO os2key;
int rc;
register int result = 0;
static secondkey = 0;
if (secondkey) {
result = secondkey;
secondkey = 0;
} else {
rc = KbdCharIn((PKBDKEYINFO)&os2key, IO_WAIT, 0);
result = os2key.chChar;
if (result == 0xe0) {
result = 0x1b;
switch (os2key.chScan) {
case 'H':
secondkey = 'A';
break;
case 'P':
secondkey = 'B';
break;
case 'K':
secondkey = 'D';
break;
case 'M':
secondkey = 'C';
break;
case 'I':
secondkey = 'I';
break;
case 'Q':
secondkey = 'G';
break;
case 'G':
secondkey = 'H';
break;
case 'O':
secondkey = 'F';
break;
default:
secondkey = '?';
break;
}
} else if (result == 0x0d) {
result = 0x0a;
}
}
return ((result == EOF) ? EOF : result & 0xFF);
#endif /* INDEX_DAEMON */
}
#endif /* M_OS2 */
#ifdef M_AMIGA
#include <sprof.h>
static int new_lines, new_columns;
static int
AmiReadCh (int getscrsize)
{
#ifndef INDEX_DAEMON
static unsigned char buf[128];
static int buflen = 0, bufp = 0;
int result;
unsigned char ch;
while (getscrsize || buflen == 0) {
PROFILE_OFF();
result = read (0, (char *)&buf[buflen], 1);
PROFILE_ON();
if (result <= 0) return EOF;
buflen++;
if (buf[bufp] == KEY_PREFIX) {
do {
result = read (0, (char *)&buf[buflen], 1);
if (result <= 0) return EOF;
} while (buf[buflen++] < 0x40);
switch (buf[buflen-1])
{ char *ptr;
long class;
case 'r': /* Window bounds report */
ptr = (char *)&buf[bufp+1];
strtol(ptr,&ptr,10);
ptr++;
strtol(ptr,&ptr,10);
ptr++;
new_lines = strtol(ptr,&ptr,10);
ptr++;
new_columns = strtol(ptr,&ptr,10);
buflen = bufp;
if (getscrsize)
return 0;
break;
case '|': /* Raw Input Events */
ptr = (char *)&buf[bufp+1];
class = strtol(ptr,&ptr,10);
ptr++;
switch (class)
{ int x,y;
case 12: /* Window resized */
buflen = bufp; /* Must do this before raise() */
raise(SIGWINCH);
break;
#ifdef notdef
case 2: /* Mouse event */
/*
* At this point we know what button was pressed
* but we don't really know where the mouse is.
* The <x> and <y> parameters don't help.
* Perhaps looking directly in the window's structure
* is the easiest thing to do (after finding out where
* the window's structure is! Sending an ACTION_INFO
* packet to the handler gives us this. I don't know
* if there is an easier way.
*/
buflen = bufp;
break;
#endif
default:
buflen = bufp;
break;
}
break;
default:
break;
}
}
}
ch = buf[bufp++];
if (bufp >= buflen) buflen = bufp = 0;
return ch;
#else
return -1;
#endif /* INDEX_DAEMON */
}
int
ReadCh(void)
{
return AmiReadCh(0);
}
void
AmiGetWinSize(int *lines, int *columns)
{
#ifndef INDEX_DAEMON
if (_getwinsize) {
tputs (_getwinsize,1,outchar); /* identify yourself */
my_flush ();
AmiReadCh(1); /* Look for the identification */
*lines = new_lines;
*columns = new_columns;
}
#endif /* INDEX_DAEMON */
}
#endif /* M_AMIGA */
#ifdef M_UNIX
int
ReadCh (void)
{
#ifndef INDEX_DAEMON
register int result;
#ifndef READ_CHAR_HACK
char ch;
#endif /* READ_CHAR_HACK */
#ifdef READ_CHAR_HACK
#undef getc