| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
#include "header.h" |
| 9 |
|
| 10 |
#include "advint.h" |
| 11 |
#include "advdbs.h" |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
jmp_buf restart; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
void play(void); |
| 20 |
int single_action(void); |
| 21 |
|
| 22 |
|
| 23 |
winid_t window; |
| 24 |
strid_t screen; |
| 25 |
|
| 26 |
extern char *gas_filename; |
| 27 |
|
| 28 |
|
| 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 |
|
| 65 |
trm_init(rows,cols,lname); |
| 66 |
|
| 67 |
|
| 68 |
if (!gas_filename) |
| 69 |
error("AdvSys: No file given"); |
| 70 |
|
| 71 |
file = glkunix_stream_open_pathname(gas_filename, 0, SOURCEFILE); |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
db_init(file); |
| 77 |
|
| 78 |
|
| 79 |
play(); |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
void play() |
| 84 |
{ |
| 85 |
|
| 86 |
setjmp(restart); |
| 87 |
|
| 88 |
|
| 89 |
execute(h_init); |
| 90 |
|
| 91 |
|
| 92 |
for (;;) { |
| 93 |
|
| 94 |
|
| 95 |
execute(h_update); |
| 96 |
|
| 97 |
|
| 98 |
if (parse()) { |
| 99 |
if (single_action()) |
| 100 |
while (next() && single_action()) |
| 101 |
; |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
else |
| 106 |
execute(h_error); |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
|
| 111 |
int single_action() |
| 112 |
{ |
| 113 |
|
| 114 |
switch (execute(h_before)) { |
| 115 |
case ABORT: |
| 116 |
return (FALSE); |
| 117 |
case CHAIN: |
| 118 |
if (execute(getafield(getvalue(V_ACTION),A_CODE)) == ABORT) |
| 119 |
return (FALSE); |
| 120 |
case FINISH: |
| 121 |
if (execute(h_after) == ABORT) |
| 122 |
return (FALSE); |
| 123 |
break; |
| 124 |
} |
| 125 |
return (TRUE); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
void error(char *msg) |
| 130 |
{ |
| 131 |
trm_str(msg); |
| 132 |
trm_chr('\n'); |
| 133 |
glk_exit(); |
| 134 |
} |