forked from dungeons-of-moria/icmoria
-
Notifications
You must be signed in to change notification settings - Fork 0
/
term.c
1981 lines (1793 loc) · 41.8 KB
/
term.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
/* term.c */
/* stuff to print stuff to the screen. This file originaly came from umoria. */
#include "imoria.h"
#include <sys/wait.h>
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
/* source/io.c: terminal I/O code, uses the curses package
Copyright (c) 1989-94 James E. Wilson, Robert A. Koeneke
This software may be copied and distributed for educational, research, and
not for profit purposes provided that this copyright and statement are
included in all such copies. */
#include <stdio.h>
#ifndef STDIO_LOADED
#define STDIO_LOADED
#endif
#include "config.h"
#ifdef HPUX
#include <sys/bsdtty.h>
#endif
#if defined(atarist) && defined(__GNUC__)
#include <osbind.h>
#endif
#ifdef MSDOS
#include <process.h>
#endif
#ifdef AMIGA
/* detach from cli process */
long _stack = 30000;
long _priority = 0;
long _BackGroundIO = 1;
char *_procname = "Moria";
#endif
#if defined(NLS) && defined(lint)
/* for AIX, don't let curses include the NL stuff */
#undef NLS
#endif
/* Default if not Atari or Mac */
#if !defined(GEMDOS) && !defined(MAC)
# include <curses.h>
#endif
/* Macintosh */
#ifdef MAC
# ifdef THINK_C
# include "ScrnMgr.h"
# else
# include <scrnmgr.h>
# endif
#endif
/* GEMDOS i.e. Atari ST */
#if defined(GEMDOS)
# include "curses.h"
long wgetch();
# ifdef ATARIST_TC
# include <tos.h> /* TC */
# include <ext.h>
# else
# include <osbind.h> /* MWC */
# endif
char *getenv();
#endif
#include <ctype.h>
#if defined(SYS_V) && defined(lint)
/* for AIX, prevent hundreds of unnecessary lint errors, must define before
signal.h is included */
#define _h_IEEETRAP
typedef struct { int stuff; } fpvmach;
#endif
#if defined(MSDOS)
#if defined(ANSI)
#include "ms_ansi.h"
#endif
#else /* not msdos */
#if !defined(ATARI_ST) && !defined(MAC) && !defined(AMIGA)
#ifndef VMS
#include <sys/ioctl.h>
#endif
#include <signal.h>
#endif
#endif
#ifndef USG
/* only needed for Berkeley UNIX */
#include <sys/param.h>
#include <sys/file.h>
#include <sys/types.h>
#endif
#ifdef USG
#ifndef ATARI_ST
#include <string.h>
#else
#include "string.h"
#endif
#if 0
/* Used to include termio.h here, but that caused problems on some systems,
as curses.h includes it also above. */
#if !defined(MAC) && !defined(MSDOS) && !defined(ATARI_ST)
#if !defined(AMIGA) && !defined(VMS)
#include <termio.h>
#endif
#endif
#endif /* 0 */
#ifdef HPUX
/* Needs termio.h because curses.h doesn't include it */
#include <termio.h>
#endif
#else /* ! USG */
#include <strings.h>
#if defined(atarist) && defined(__GNUC__)
/* doesn't have sys/wait.h */
#else
#include <sys/wait.h>
#endif
#endif
#ifdef ATARIST_TC
/* Include this to get prototypes for standard library functions. */
#include <stdlib.h>
#endif
/* These are included after other includes (particularly curses.h)
to avoid redefintion warnings. */
/*#include "constant.h"*/
/*#include "types.h"*/
/*#include "externs.h"*/
#if !defined(VINTR) && !defined(__NetBSD__)
# include <termios.h>
/*#include "termbits.h"*/ /* try this one if termios.h does not work */
#endif
#if defined(SYS_V) && defined(lint)
struct screen { int dumb; };
#endif
/* Fooling lint. Unfortunately, c defines all the TIO. -CJS-
constants to be long, and lint expects them to be int. Also,
ioctl is sometimes called with just two arguments. The
following definition keeps lint happy. It may need to be
reset for different systems. */
#ifndef MAC
#ifdef lint
#ifdef Pyramid
/* Pyramid makes constants greater than 65535 into long! Gakk! -CJS- */
/*ARGSUSED*/
/*VARARGS2*/
static Ioctl(i, l, p) long l; char *p; { return 0; }
#else
/*ARGSUSED*/
/*VARARGS2*/
static Ioctl(i, l, p) char *p; { return 0; }
#endif
#define ioctl Ioctl
#endif
#if !defined(USG) && defined(lint)
/* This use_value hack is for curses macros which return a value,
but don't shut up about it when you try to tell them (void). */
/* only needed for Berkeley UNIX */
int Use_value;
#define use_value Use_value +=
#else
#define use_value
#endif
#if defined(SYS_V) && defined(lint)
/* This use_value2 hack is for curses macros which use a conditional
expression, and which say null effect even if you cast to (void). */
/* only needed for SYS V */
int Use_value2;
#define use_value2 Use_value2 +=
#else
#define use_value2
#endif
#endif
#ifndef MAC
char *getenv();
#endif
#ifndef VMS
#ifdef USG
void exit();
#if defined(__TURBOC__)
void sleep();
#else
#ifndef AMIGA
unsigned sleep();
#endif
#endif
#endif
#endif
#ifdef ultrix
void exit();
void sleep();
#endif
#ifdef __NetBSD__
#include <sgtty.h>
#endif
#if !defined(MAC) && !defined(MSDOS) && !defined(ATARI_ST) && !defined(VMS)
#ifndef AMIGA
#ifdef USG
#ifdef __linux__
static struct termios save_termio;
#else
static struct termio save_termio;
#endif
#else
static struct ltchars save_special_chars;
static struct sgttyb save_ttyb;
static struct tchars save_tchars;
static int save_local_chars;
#endif
#endif
#endif
#ifndef MAC
static int curses_on = FALSE;
static WINDOW *savescr; /* Spare window for saving the screen. -CJS-*/
#ifdef VMS
static WINDOW *tempscr; /* Spare window for VMS CTRL('R'). */
#endif
#endif
#ifdef MAC
/* Attributes of normal and hilighted characters */
#define ATTR_NORMAL attrNormal
#define ATTR_HILITED attrReversed
#endif
#ifndef MAC
#ifdef SIGTSTP
/* suspend() -CJS-
Handle the stop and start signals. This ensures that the log
is up to date, and that the terminal is fully reset and
restored. */
int suspend()
{
#ifdef USG
/* for USG systems with BSDisms that have SIGTSTP defined, but don't
actually implement it */
#else
struct sgttyb tbuf;
struct ltchars lcbuf;
struct tchars cbuf;
long time();
/* py.misc.male |= 2;*/
/* py.misc.male = py.misc.male | 2; XXXX */
(void) ioctl(0, TIOCGETP, (char *)&tbuf);
(void) ioctl(0, TIOCGETC, (char *)&cbuf);
(void) ioctl(0, TIOCGLTC, (char *)&lcbuf);
#if !defined(atarist) && !defined(__GNUC__)
(void) ioctl(0, TIOCLGET, (char *)&lbuf);
#endif
restore_term();
(void) kill(0, SIGSTOP);
curses_on = TRUE;
(void) ioctl(0, TIOCSETP, (char *)&tbuf);
(void) ioctl(0, TIOCSETC, (char *)&cbuf);
(void) ioctl(0, TIOCSLTC, (char *)&lcbuf);
#if !defined(atarist) && !defined(__GNUC__)
(void) ioctl(0, TIOCLSET, (char *)&lbuf);
#endif
(void) wrefresh(curscr);
/* py.misc.male &= ~2; XXXX */
#endif
return 0;
}
#endif
#endif
/* initializes curses routines */
void init_curses()
#ifdef MAC
{
/* Primary initialization is done in mac.c since game is restartable */
/* Only need to clear the screen here */
Rect scrn;
scrn.left = scrn.top = 0;
scrn.right = SCRN_COLS;
scrn.bottom = SCRN_ROWS;
EraseScreen(&scrn);
UpdateScreen();
}
#else
{
printf("Attempting to start curses...\n");
fflush(stdout);
/* int i, y, x;*/
#ifdef AMIGA
if (opentimer() == 0)
{
(void) printf ("Could not open timer device.\n\r");
exit (1);
}
#endif
#ifndef USG
(void) ioctl(0, TIOCGLTC, (char *)&save_special_chars);
(void) ioctl(0, TIOCGETP, (char *)&save_ttyb);
(void) ioctl(0, TIOCGETC, (char *)&save_tchars);
#if !defined(atarist) && !defined(__GNUC__)
(void) ioctl(0, TIOCLGET, (char *)&save_local_chars);
#endif
#else
#if !defined(VMS) && !defined(MSDOS) && !defined(ATARI_ST)
#ifndef AMIGA
(void) ioctl(0, TCGETA, (char *)&save_termio);
#endif
#endif
#endif
/* PC curses returns ERR */
#if defined(USG) && !defined(PC_CURSES) && !defined(AMIGA)
if (initscr() == NULL)
#else
if (initscr() == ERR)
#endif
{
(void) printf("Error allocating screen in curses package.\n\r");
exit(1);
}
if (LINES < 24 || COLS < 80) /* Check we have enough screen. -CJS- */
{
(void) printf("Screen too small for moria.\n\r");
exit (1);
}
#ifdef SIGTSTP
#if defined(atarist) && defined(__GNUC__)
(void) signal (SIGTSTP, (__Sigfunc)suspend);
#else
#ifdef __386BSD__
(void) signal (SIGTSTP, (sig_t)suspend);
#else
(void) signal (SIGTSTP, (void *)suspend);
#endif
#endif
#endif
if (((savescr = newwin (0, 0, 0, 0)) == NULL)
#ifdef VMS
|| ((tempscr = newwin (0, 0, 0, 0)) == NULL))
#else
)
#endif
{
(void) printf ("Out of memory in starting up curses.\n\r");
exit_game();
}
(void) clear();
(void) refresh();
moriaterm ();
#if 0
/* This assumes that the terminal is 80 characters wide, which is not
guaranteed to be true. */
/* check tab settings, exit with error if they are not 8 spaces apart */
(void) move(0, 0);
for (i = 1; i < 10; i++)
{
(void) addch('\t');
getyx(stdscr, y, x);
if (y != 0 || x != i*8)
break;
}
if (i != 10)
{
msg_print("Tabs must be set 8 spaces apart.");
exit_game();
}
#endif
}
#endif
/* Set up the terminal into a suitable state for moria. -CJS- */
void moriaterm()
#ifdef MAC
/* Nothing to do on Mac */
{
}
#else
{
#if !defined(MSDOS) && !defined(ATARI_ST) && !defined(VMS)
#ifndef AMIGA
#ifdef USG
#ifdef __linux__
struct termios tbuf;
#else
struct termio tbuf;
#endif
#else
struct ltchars lbuf;
struct tchars buf;
#endif
#endif
#endif
curses_on = TRUE;
#ifndef BSD4_3
use_value crmode();
#else
#ifdef VMS
use_value vms_crmode ();
#else
use_value cbreak();
#endif
#endif
use_value noecho();
/* can not use nonl(), because some curses do not handle it correctly */
#ifdef MSDOS
msdos_raw();
#else
#ifdef AMIGA
init_color (0, 0, 0, 0); /* pen 0 - black */
init_color (1,1000,1000,1000); /* pen 1 - white */
init_color (2, 0, 300, 700); /* pen 2 - blue */
init_color (3,1000, 500, 0); /* pen 3 - orange */
#else
#if !defined(ATARI_ST) && !defined(VMS)
#ifdef USG
(void) ioctl(0, TCGETA, (char *)&tbuf);
/* disable all of the normal special control characters */
tbuf.c_cc[VINTR] = (char)3; /* control-C */
tbuf.c_cc[VQUIT] = (char)-1;
tbuf.c_cc[VERASE] = (char)-1;
tbuf.c_cc[VKILL] = (char)-1;
tbuf.c_cc[VEOF] = (char)-1;
/* don't know what these are for */
tbuf.c_cc[VEOL] = (char)-1;
#ifdef VEOL2
tbuf.c_cc[VEOL2] = (char)-1;
#endif
/* stuff needed when !icanon, i.e. cbreak/raw mode */
tbuf.c_cc[VMIN] = 1; /* Input should wait for at least 1 char */
tbuf.c_cc[VTIME] = 0; /* no matter how long that takes. */
(void) ioctl(0, TCSETA, (char *)&tbuf);
#else
/* disable all of the special characters except the suspend char, interrupt
char, and the control flow start/stop characters */
(void) ioctl(0, TIOCGLTC, (char *)&lbuf);
lbuf.t_suspc = (char)26; /* control-Z */
lbuf.t_dsuspc = (char)-1;
lbuf.t_rprntc = (char)-1;
lbuf.t_flushc = (char)-1;
lbuf.t_werasc = (char)-1;
lbuf.t_lnextc = (char)-1;
(void) ioctl(0, TIOCSLTC, (char *)&lbuf);
(void) ioctl (0, TIOCGETC, (char *)&buf);
buf.t_intrc = (char)3; /* control-C */
buf.t_quitc = (char)-1;
buf.t_startc = (char)17; /* control-Q */
buf.t_stopc = (char)19; /* control-S */
buf.t_eofc = (char)-1;
buf.t_brkc = (char)-1;
(void) ioctl(0, TIOCSETC, (char *)&buf);
#endif
#endif
#endif
#endif
#ifdef ATARIST_TC
raw ();
#endif
}
#endif
void highlite_on()
{
#if 1 || USE_CURSES_ATTRS
attron(A_DIM);
#endif
};
void highlite_off()
{
#if 1 || USE_CURSES_ATTRS
attroff(A_DIM);
#endif
};
int cool_mvaddch(int row, int col, char ch)
{
if ((ch & 0x80) != 0) {
highlite_on();
mvaddch(row, col, ch & 0x7F);
highlite_off();
} else {
mvaddch(row, col, ch);
}
return OK;
}
int cool_mvaddstr(int row, int col, char *printString)
{
/* search for characters with the high bit set */
int i1;
char *s1;
for (s1 = printString, i1 = 0 ; s1[i1] ; i1++) {
if ( (s1[i1] & 0x80) != 0 ) {
if (i1 > 0) {
mvaddnstr(row, col, s1, i1);
col += i1;
s1 = &(s1[i1]);
}
highlite_on();
*s1 &= 0x7F;
mvaddnstr(row, col, s1, 1);
highlite_off();
col++;
s1++;
i1 = -1; /* will be 0 when the top of the loop is hit */
}
}
if (i1 > 0) {
mvaddnstr(row, col, s1, i1);
}
return OK;
}
/* Dump IO to buffer -RAK- */
void Put_Buffer(out_str, row, col)
char *out_str;
integer row, col;
#ifdef MAC
{
/* The screen manager handles writes past the edge ok */
DSetScreenCursor((int)col, (int)row);
DWriteScreenStringAttr(out_str, ATTR_NORMAL);
}
#else
{
vtype tmp_str;
// ENTER("put_buffer","i");
if (out_str && out_str[0]) {
/* truncate the string, to make sure that it won't go past right edge of
screen */
if (col > 80)
col = 80;
(void) strncpy (tmp_str, out_str, 80 - col);
tmp_str [80 - col] = '\0';
if (cool_mvaddstr((int)row, (int)col, tmp_str) == ERR)
{
abort();
/* clear msg_flag to avoid problems with unflushed messages */
msg_flag = 0;
(void) sprintf(tmp_str, "error in put_buffer, row = %ld col = %ld\n",
row, col);
Prt(tmp_str, 0, 0);
bell();
/* wait so user can see error */
(void) sleep(2);
}
}
// LEAVE("put_buffer","i");
}
#endif
void put_buffer_attr(out_str, row, col, attrs)
char *out_str;
integer row, col;
int attrs;
{
#if USE_CURSES_ATTRS
/*
* If you are getting an error about attr_get in here then
* you might want to change the USE_CURSES_ATTRS setting in
* configure.h
*/
#if NCURSES_VERSION_MAJOR == 5
attr_t old_attr;
short unused_pair, unused_opts;
(void)unused_opts;
attr_get(&old_attr, &unused_pair, &unused_opts);
#else
int old_attr;
old_attr = attr_get();
#endif
attrset(attrs);
put_buffer(out_str, row, col);
attrset(old_attr);
#else
put_buffer(out_str, row, col);
#endif
}
/* Dump the IO buffer to terminal -RAK- */
void put_qio()
{
screen_change = TRUE; /* Let inven_command know something has changed. */
#ifdef MAC
UpdateScreen();
#else
(void) refresh();
#endif
}
/* Put the terminal in the original mode. -CJS- */
void restore_term()
#ifdef MAC
/* Nothing to do on Mac */
{
}
#else
{
#ifdef AMIGA
closetimer ();
#endif
if (!curses_on)
return;
put_qio(); /* Dump any remaining buffer */
#ifdef MSDOS
(void) sleep(2); /* And let it be read. */
#endif
#ifdef VMS
clear_screen();
Pause_Line(15);
#endif
/* this moves curses to bottom right corner */
mvcur(getcury(stdscr), getcurx(stdscr), LINES-1, 0);
endwin(); /* exit curses */
(void) fflush (stdout);
#ifdef MSDOS
msdos_noraw();
#endif
/* restore the saved values of the special chars */
#ifdef USG
#if !defined(MSDOS) && !defined(ATARI_ST) && !defined(VMS)
#ifndef AMIGA
(void) ioctl(0, TCSETA, (char *)&save_termio);
#endif
#endif
#else
(void) ioctl(0, TIOCSLTC, (char *)&save_special_chars);
(void) ioctl(0, TIOCSETP, (char *)&save_ttyb);
(void) ioctl(0, TIOCSETC, (char *)&save_tchars);
#if !defined(atarist) && !defined(__GNUC__)
(void) ioctl(0, TIOCLSET, (char *)&save_local_chars);
#endif
#endif
curses_on = FALSE;
}
#endif
void shell_out()
#if defined(atarist) && defined(__GNUC__)
{ char fail_message[80], arg_list[1], *p;
int escape_code;
save_screen();
clear_screen();
use_value nocbreak(); /* Must remember to reset terminal modes */
use_value echo(); /* or shell i/o will be quite messed up! */
p = (char *)getenv("SHELL");
if (p != (char *)NULL)
{ Put_Buffer("Escaping to Shell\n",0,0);
put_qio();
arg_list[0]=0;
escape_code = Pexec(0,p,arg_list,0); /* Launch the shell. */
if (escape_code != 0)
{ sprintf(fail_message,"Pexec() error code = %d\n",escape_code);
Put_Buffer(fail_message,0,0);
put_qio();
sleep(5);
}
}
use_value cbreak(); /* Reset the terminal back to CBREAK/NOECHO */
use_value noecho();
clear_screen(); /* Do not want shell data on screen. */
restore_screen();
}
#else
#ifdef MAC
{
alert_error("This command is not implemented on the Macintosh.");
}
#else
#if defined(AMIGA) || defined(ATARIST_TC)
{
Put_Buffer("This command is not implemented.\n", 0, 0);
}
#else
#ifdef VMS /* TPP */
{
int val, istat;
char *str;
save_screen();
/* clear screen and print 'exit' message */
clear_screen();
Put_Buffer("[Entering subprocess, type 'EOJ' to resume your game.]\n",
0, 0);
put_qio();
use_value vms_nocrmode();
use_value echo();
ignore_signals();
istat = lib$spawn();
if (!istat)
lib$signal (istat);
restore_signals();
use_value vms_crmode();
use_value noecho();
/* restore the cave to the screen */
restore_screen();
Put_Buffer("Welcome back to UMoria.\n", 0, 0);
save_screen();
clear_screen();
put_qio();
restore_screen();
(void) wrefresh(curscr);
}
#else
{
#ifdef USG
#if !defined(MSDOS) && !defined(ATARI_ST) && !defined(AMIGA)
#ifdef __linux__
struct termios tbuf;
#else
struct termio tbuf;
#endif
#endif
#else
struct sgttyb tbuf;
struct ltchars lcbuf;
struct tchars cbuf;
int lbuf;
#endif
#ifdef MSDOS
char *comspec, key;
#else
#ifdef ATARI_ST
char comstr[80];
char *str;
extern char **environ;
#else
int val;
char *str;
#endif
#endif
save_screen();
/* clear screen and print 'exit' message */
clear_screen();
#ifndef ATARI_ST
Put_Buffer("[Entering shell, type 'exit' to resume your game.]\n",0,0);
#else
Put_Buffer("[Escaping to shell]\n",0,0);
#endif
put_qio();
#ifdef USG
#if !defined(MSDOS) && !defined(ATARI_ST) && !defined(AMIGA)
(void) ioctl(0, TCGETA, (char *)&tbuf);
#endif
#else
(void) ioctl(0, TIOCGETP, (char *)&tbuf);
(void) ioctl(0, TIOCGETC, (char *)&cbuf);
(void) ioctl(0, TIOCGLTC, (char *)&lcbuf);
(void) ioctl(0, TIOCLGET, (char *)&lbuf);
#endif
/* would call nl() here if could use nl()/nonl(), see moriaterm() */
#ifndef BSD4_3
use_value nocrmode();
#else
#ifdef VMS
use_value vms_nocrmode ();
#else
use_value nocbreak();
#endif
#endif
#ifdef MSDOS
use_value msdos_noraw();
#endif
use_value echo();
ignore_signals();
#ifdef MSDOS /*{*/
if ((comspec = getenv("COMSPEC")) == CNIL
|| spawnl(P_WAIT, comspec, comspec, CNIL) < 0) {
clear_screen(); /* BOSS key if shell failed */
Put_Buffer("M:\\> ", 0, 0);
do {
key = inkey();
} while (key != '!');
}
#else /* MSDOS }{*/
#ifndef ATARI_ST
val = fork();
if (val == 0)
{
#endif
default_signals();
#ifdef USG
#if !defined(MSDOS) && !defined(ATARI_ST) && !defined(AMIGA)
(void) ioctl(0, TCSETA, (char *)&save_termio);
#endif
#else
(void) ioctl(0, TIOCSLTC, (char *)&save_special_chars);
(void) ioctl(0, TIOCSETP, (char *)&save_ttyb);
(void) ioctl(0, TIOCSETC, (char *)&save_tchars);
(void) ioctl(0, TIOCLSET, (char *)&save_local_chars);
#endif
#ifndef MSDOS
/* close scoreboard descriptor */
/* it is not open on MSDOS machines */
(void) fclose(highscore_fp);
#endif
if ((str = getenv("SHELL")))
#ifndef ATARI_ST
(void) execl(str, str, (char *) 0);
#else
system(str);
#endif
else
#ifndef ATARI_ST
(void) execl("/bin/sh", "sh", (char *) 0);
#endif
msg_print("Cannot execute shell.");
#ifndef ATARI_ST
exit(1);
}
if (val == -1)
{
msg_print("Fork failed. Try again.");
return;
}
#if defined(USG) || defined(__386BSD__) || defined(__NetBSD__)
(void) wait((int *) 0);
#else
(void) wait((union wait *) 0);
#endif
#endif /* ATARI_ST */
#endif /* MSDOS }*/
restore_signals();
/* restore the cave to the screen */
restore_screen();
#ifndef BSD4_3
use_value crmode();
#else
#ifdef VMS
use_value vms_crmode ();
#else
use_value cbreak();
#endif
#endif
use_value noecho();
/* would call nonl() here if could use nl()/nonl(), see moriaterm() */
#ifdef MSDOS
msdos_raw();
#endif
/* disable all of the local special characters except the suspend char */
/* have to disable ^Y for tunneling */
#ifdef USG
#if !defined(MSDOS) && !defined(ATARI_ST)
(void) ioctl(0, TCSETA, (char *)&tbuf);
#endif
#else
(void) ioctl(0, TIOCSLTC, (char *)&lcbuf);
(void) ioctl(0, TIOCSETP, (char *)&tbuf);
(void) ioctl(0, TIOCSETC, (char *)&cbuf);
(void) ioctl(0, TIOCLSET, (char *)&lbuf);
#endif
(void) wrefresh(curscr);
}
#endif
#endif
#endif
#endif
/* Returns a single character input from the terminal. This silently -CJS-
consumes ^R to redraw the screen and reset the terminal, so that this
operation can always be performed at any input prompt. inkey() never
returns ^R. */
char inkey()
#ifdef MAC
/* The Mac does not need ^R, so it just consumes it */
/* This routine does nothing special with direction keys */
/* Just returns their keypad ascii value (e.g. '0'-'9') */
/* Compare with inkeydir() below */
{
char ch;
int dir;
int shift_flag, ctrl_flag;
put_qio();
command_count = 0;
do {
macgetkey(&ch, FALSE);
} while (ch == CTRL_('R'));
dir = extractdir(ch, &shift_flag, &ctrl_flag);
if (dir != -1)
ch = '0' + dir;
return(ch);
}
#else
{
int i;
#ifdef VMS
vtype tmp_str;
#endif
put_qio(); /* Dump IO buffer */
command_count = 0; /* Just to be safe -CJS- */
while (TRUE)
{
#ifdef MSDOS
i = msdos_getch();
#else
#ifdef VMS
i = vms_getch ();
#else
i = getch();
#if defined(atarist) && defined(__GNUC__)
/* for some reason a keypad number produces an initial negative number. */
if (i<0) i = getch();
#endif
#endif
#endif
#ifdef VMS
if (i == 27) /* if ESCAPE key, then we probably have a keypad key */
{
i = vms_getch();
if (i == 'O') /* Now it is definitely a numeric keypad key */
{
i = vms_getch();
switch (i)
{
case 'p': i = '0'; break;
case 'q' : i = '1'; break;
case 'r' : i = '2'; break;
case 's' : i = '3'; break;
case 't' : i = '4'; break;
case 'u' : i = '5'; break;
case 'v' : i = '6'; break;
case 'w' : i = '7'; break;
case 'x' : i = '8'; break;
case 'y' : i = '9'; break;
case 'm' : i = '-'; break;
case 'M' : i = 10; break; /* Enter = RETURN */
case 'n' : i = '.'; break;
default : while (kbhit()) (void) vms_getch();
}
}
else