Debian Codegraph @

terps/advsys/advint.c

raw symbols SCIP
1
2 /* advint.c - an interpreter for adventure games */
3 /*
4 Copyright (c) 1986, by David Michael Betz
5 All rights reserved
6 */
7
8 #include "header.h"
9
10 #include "advint.h"
11 #include "advdbs.h"
12
13
14 /* global variables */
15 jmp_buf restart;
16
17 /* CHANGED TO WORK WITH GLK */
18 /* Modernize it */
19 void play(void);
20 int single_action(void);
21
22 /* GLK Specifics */
23 winid_t window;
24 strid_t screen;
25
26 extern char *gas_filename;
27
28 /* main - the main routine */
29 void glk_main()
30 {
31 char *fname,*lname;
32 int rows,cols;
33
34 strid_t file;
35
36 window = glk_window_open(0, 0, 0, wintype_TextBuffer, WINDOW);
37 screen = glk_window_get_stream(window);
38 glk_stream_set_current(screen);
39
40 #ifdef GARGLK
41 garglk_set_program_name("AdvSys 1.2");
42 garglk_set_program_info(
43 "ADVINT v1.2 - Copyright (c) 1986 by David Betz\n"
44 "GLK Build v0.1 - Copyright (c) 2000 by Zenki\n"
45 "Gargoyle tweaks by Tor Andersson");
46 #else
47
48 #ifdef WINDOWS
49 glk_put_string("ADVINT v1.2 - Copyright (c) 1986, by David Betz\n"
50 "GLK Build v0.1 - Copyright (c) 2000 by Zenki\n\n");
51 #endif
52
53 #ifdef UNIX
54 glk_put_string("ADVINT v1.2 - Copyright (c) 1986, by David Betz\n"
55 "GLK Build v0.1 - Copyright(c) 2000 by Zenki\n\n");
56 #endif
57 #endif
58
59 fname = NULL;
60 lname = NULL;
61 rows = 24;
62 cols = 80;
63
64 /* initialize terminal i/o */
65 trm_init(rows,cols,lname);
66
67 /* Get the file reference. */
68 if (!gas_filename)
69 error("AdvSys: No file given");
70
71 file = glkunix_stream_open_pathname(gas_filename, 0, SOURCEFILE);
72
73 /* END OF CHANGES FOR GLK */
74
75 /* initialize the database */
76 db_init(file);
77
78 /* play the game */
79 play();
80 }
81
82 /* play - the main loop */
83 void play()
84 {
85 /* establish the restart point */
86 setjmp(restart);
87
88 /* execute the initialization code */
89 execute(h_init);
90
91 /* turn handling loop */
92 for (;;) {
93
94 /* execute the update code */
95 execute(h_update);
96
97 /* parse the next input command */
98 if (parse()) {
99 if (single_action())
100 while (next() && single_action())
101 ;
102 }
103
104 /* parse error, call the error handling code */
105 else
106 execute(h_error);
107 }
108 }
109
110 /* single_action - handle a single action */
111 int single_action()
112 {
113 /* execute the before code */
114 switch (execute(h_before)) {
115 case ABORT: /* before handler aborted sequence */
116 return (FALSE);
117 case CHAIN: /* execute the action handler */
118 if (execute(getafield(getvalue(V_ACTION),A_CODE)) == ABORT)
119 return (FALSE);
120 case FINISH:/* execute the after code */
121 if (execute(h_after) == ABORT)
122 return (FALSE);
123 break;
124 }
125 return (TRUE);
126 }
127
128 /* error - print an error message and exit */
129 void error(char *msg)
130 {
131 trm_str(msg);
132 trm_chr('\n');
133 glk_exit();
134 }