Debian Codegraph @

terps/jacl/loader.c

raw symbols SCIP
1 /* loader.c --- Functions to load gamefile into memory.
2 * (C) 2008 Stuart Allen, distribute and use
3 * according to GNU GPL, see file COPYING for details.
4 */
5
6 #include "jacl.h"
7 #include "language.h"
8 #include "types.h"
9 #include "prototypes.h"
10 #include "interpreter.h"
11 #include "encapsulate.h"
12 #include "parser.h"
13 #include <string.h>
14
15 /* INDICATES THAT THE CURRENT '.j2' FILE BEING WORKED
16 * WITH IS ENCRYPTED */
17 int encrypted = FALSE;
18 static int in_print = FALSE;
19
20 #ifdef GLK
21 #else
22 #ifndef __NDS__
23 extern struct parameter_type *parameter_table;
24 struct parameter_type *current_parameter = NULL;
25 struct parameter_type *new_parameter;
26 #endif
27 #endif
28
29 static struct string_type *current_string = NULL;
30 static struct integer_type *current_integer = NULL;
31 static struct attribute_type *current_attribute = NULL;
32 static struct integer_type *last_system_integer = NULL;
33
34 int value_resolved;
35
36 static int legal_label_check(const char *word, int line, int type);
37 static void create_language_constants(void);
38 static void create_attribute(const char *name);
39 static void set_defaults(void);
40 static void build_grammar_table(struct word_type *pointer);
41 static void free_from(struct word_type *x);
42 static void create_cstring(const char *name, const char *value);
43 static void create_string(const char *name, const char *value);
44 static void create_integer(const char *name, int value);
45 static void create_cinteger(const char *name, int value);
46
47 void
48 read_gamefile()
49 {
50 int index,
51 counter,
52 errors;
53 #ifdef GLK
54 int result;
55 #endif
56 int location_count = 0;
57 int object_count = 0;
58 int line = 0;
59 int self_parent = 0;
60 int is_static = FALSE;
61
62 long start_of_file = 0;
63 #ifdef GLK
64 glui32 current_file_position;
65 #else
66 long current_file_position;
67 #endif
68
69 long bit_mask;
70
71 struct filter_type *current_filter = NULL;
72 struct filter_type *new_filter = NULL;
73 struct attribute_type *current_attribute = NULL;
74 struct attribute_type *new_attribute = NULL;
75 struct cinteger_type *resolved_cinteger = NULL;
76 struct synonym_type *current_synonym = NULL;
77 struct synonym_type *new_synonym = NULL;
78 struct function_type *current_function = NULL;
79 struct name_type *current_name = NULL;
80
81 char function_name[81];
82
83 // CREATE SOME SYSTEM VARIABLES
84
85 // THIS IS USED BY JACL FUNCTIONS TO PASS STRING VALUES BACK
86 // TO THE INTERPRETER AS JACL FUNCTION CAN ONLY RETURN
87 // AN INTEGER
88 create_string ("return_value", "");
89
90 create_cstring ("function_name", "JACL*Internal");
91
92 // THESE ARE THE FIELDS FOR THE CSV PARSER
93 create_cstring ("field", "field0");
94 create_cstring ("field", "field1");
95 create_cstring ("field", "field2");
96 create_cstring ("field", "field3");
97 create_cstring ("field", "field4");
98 create_cstring ("field", "field5");
99 create_cstring ("field", "field6");
100 create_cstring ("field", "field7");
101 create_cstring ("field", "field8");
102 create_cstring ("field", "field9");
103 create_cstring ("field", "field10");
104 create_cstring ("field", "field11");
105 create_cstring ("field", "field12");
106 create_cstring ("field", "field13");
107 create_cstring ("field", "field14");
108 create_cstring ("field", "field15");
109 create_cstring ("field", "field16");
110 create_cstring ("field", "field17");
111 create_cstring ("field", "field18");
112 create_cstring ("field", "field19");
113
114 create_cinteger ("field_count", 0);
115
116 create_integer ("compass", 0);
117 // START AT -1 AS TIME PASSES BEFORE THE FIRST PROMPT
118 create_integer ("total_moves", -1);
119 create_integer ("time", TRUE);
120 create_integer ("score", 0);
121 create_integer ("display_mode", 0);
122 create_integer ("internal_version", J_VERSION);
123 create_integer ("max_rand", 100);
124 create_integer ("destination", 0);
125 create_integer ("interrupted", 0);
126 create_integer ("debug", 0);
127 create_integer ("graphics_enabled", 0);
128 create_integer ("sound_enabled", 0);
129 create_integer ("timer_enabled", 0);
130 create_integer ("multi_prefix", 0);
131 create_integer ("notify", 1);
132 create_integer ("debug", 0);
133 create_integer ("local", 0);
134 create_integer ("local_x", 0);
135 create_integer ("local_y", 0);
136 create_integer ("local_a", 0);
137 create_integer ("linebreaks", 1);
138
139 // CREATE DEFAULT ATTRIBUTE FOR BACKWARDS COMPATIBILITY
140 create_attribute("FIRST");
141
142 /* STORE THIS SO THE SECOND PASS KNOWS WHERE TO START
143 * SETTING VALUES FROM (EVERYTHING BEFORE THIS IN THE
144 * VARIABLE TABLE IS A SYSTEM VARIABLE */
145 last_system_integer = current_integer;
146
147 /* CREATE SOME SYSTEM CONSTANTS */
148 create_cinteger ("graphics_supported", 0);
149 create_cinteger ("sound_supported", 0);
150 create_cinteger ("timer_supported", 0);
151 create_cinteger ("remote_user", 0);
152 create_cinteger ("jacl_version", J_VERSION);
153 create_cinteger ("jacl_release", J_RELEASE);
154 create_cinteger ("jacl_build", J_BUILD);
155 create_cinteger ("GLK", 0);
156 create_cinteger ("CGI", 1);
157 create_cinteger ("NDS", 2);
158 #ifdef GLK
159 create_cinteger ("interpreter", 0);
160 #else
161 #ifdef __NDS__
162 create_cinteger ("interpreter", 2);
163 #else
164 create_cinteger ("interpreter", 1);
165 #endif
166 #endif
167
168 /* TEST FOR AVAILABLE FUNCTIONALITY BEFORE EXECUTING ANY JACL CODE */
169
170 #ifdef GLK
171 GRAPHICS_SUPPORTED->value = (int) glk_gestalt(gestalt_Graphics, 0);
172 GRAPHICS_ENABLED->value = (int) glk_gestalt(gestalt_Graphics, 0);
173 SOUND_SUPPORTED->value = (int) glk_gestalt(gestalt_Sound, 0);
174 SOUND_ENABLED->value = (int) glk_gestalt(gestalt_Sound, 0);
175 TIMER_SUPPORTED->value = (int) glk_gestalt(gestalt_Timer, 0);
176 TIMER_ENABLED->value = (int) glk_gestalt(gestalt_Timer, 0);
177 #else
178 GRAPHICS_SUPPORTED->value = TRUE;
179 GRAPHICS_ENABLED->value = TRUE;
180 SOUND_SUPPORTED->value = TRUE;
181 SOUND_ENABLED->value = TRUE;
182 TIMER_SUPPORTED->value = FALSE;
183 TIMER_ENABLED->value = FALSE;
184 #endif
185
186 create_cinteger ("true", 1);
187 create_cinteger ("false", 0);
188 create_cinteger ("null", 0);
189 create_cinteger ("nowhere", 0);
190 create_cinteger ("heavy", HEAVY);
191 create_cinteger ("scenery", SCENERY);
192 create_cinteger ("north", NORTH_DIR);
193 create_cinteger ("south", SOUTH_DIR);
194 create_cinteger ("east", EAST_DIR);
195 create_cinteger ("west", WEST_DIR);
196 create_cinteger ("northeast", NORTHEAST_DIR);
197 create_cinteger ("northwest", NORTHWEST_DIR);
198 create_cinteger ("southeast", SOUTHEAST_DIR);
199 create_cinteger ("southwest", SOUTHWEST_DIR);
200 create_cinteger ("up", UP_DIR);
201 create_cinteger ("down", DOWN_DIR);
202 create_cinteger ("in", IN_DIR);
203 create_cinteger ("out", OUT_DIR);
204 create_cinteger ("parent", 0);
205 create_cinteger ("quantity", 1);
206 create_cinteger ("capacity", 1);
207 create_cinteger ("mass", 2);
208 create_cinteger ("bearing", 3);
209 create_cinteger ("velocity", 4);
210 create_cinteger ("next", 5);
211 create_cinteger ("previous", 6);
212 create_cinteger ("child", 7);
213 create_cinteger ("index", 8);
214 create_cinteger ("status", 9);
215 create_cinteger ("timer", 10);
216 create_cinteger ("counter", 11);
217 create_cinteger ("points", 12);
218 create_cinteger ("class", 13);
219 create_cinteger ("x", 14);
220 create_cinteger ("y", 15);
221 create_cinteger ("volume", 100);
222 create_cinteger ("volume", 100);
223 create_cinteger ("volume", 100);
224 create_cinteger ("volume", 100);
225 create_cinteger ("volume", 100);
226 create_cinteger ("volume", 100);
227 create_cinteger ("volume", 100);
228 create_cinteger ("volume", 100);
229 create_cinteger ("event_timer", 500);
230
231 set_defaults();
232
233 /* CREATE A DUMMY FUNCTION TO BE USED WHEN AN ERROR MESSAGE
234 IS PRINTED AS A RESULT OF CODE CALLED BY THE INTERPRETER */
235 if ((function_table = (struct function_type *)
236 malloc(sizeof(struct function_type))) == NULL)
237 outofmem();
238 else {
239 current_function = function_table;
240 strcpy(current_function->name, "JACL*Internal");
241 current_function->position = 0;
242 current_function->self = 0;
243 current_function->call_count = 0;
244 current_function->call_count_backup = 0;
245 current_function->next_function = NULL;
246 current_function->nosave = TRUE;
247 }
248
249 executing_function = function_table;
250
251 errors = 0;
252 objects = 0;
253 integers = 0;
254 functions = 0;
255 strings = 0;
256
257 #ifdef GLK
258 glk_stream_set_position(game_stream, (glsi32)start_of_file, seekmode_Start);
259 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
260 #else
261 fseek(file, start_of_file, SEEK_SET);
262 fgets(text_buffer, 1024, file);
263 #endif
264
265 line++;
266
267 if (!encrypted && strstr(text_buffer, "#encrypted")) {
268 encrypted = TRUE;
269 #ifdef GLK
270 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
271 #else
272 fgets(text_buffer, 1024, file);
273 #endif
274 line++;
275 }
276
277 if (encrypted) jacl_decrypt(text_buffer);
278
279 #ifdef GLK
280 while (result)
281 #else
282 while (!feof(file))
283 #endif
284 {
285 encapsulate();
286 if (word[0] == NULL);
287 else if (text_buffer[0] == '{') {
288 #ifdef GLK
289 while (result) {
290 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
291 #else
292 while (!feof(file)) {
293 fgets(text_buffer, 1024, file);
294 #endif
295 line++;
296 if (!encrypted && strstr(text_buffer, "#encrypted")) {
297 encrypted = TRUE;
298 #ifdef GLK
299 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
300 #else
301 fgets(text_buffer, 1024, file);
302 #endif
303 line++;
304 }
305 if (encrypted) jacl_decrypt(text_buffer);
306 if (text_buffer[0] == '}')
307 break;
308 }
309 } else {
310 if (!strcmp(word[0], "grammar")) {
311 if (word[++wp] == NULL) {
312 noproperr(line);
313 errors++;
314 } else {
315 if (grammar_table == NULL) {
316 if ((grammar_table = (struct word_type *)
317 malloc(sizeof(struct word_type))) == NULL)
318 outofmem();
319 else {
320 strncpy(grammar_table->word, word[wp], 40);
321 grammar_table->word[40] = 0;
322 grammar_table->next_sibling = NULL;
323 grammar_table->first_child = NULL;
324 build_grammar_table(grammar_table);
325 }
326 } else
327 build_grammar_table(grammar_table);
328 }
329 } else if (!strcmp(word[0], "object")
330 || !strcmp(word[0], "location")) {
331 if (word[1] == NULL) {
332 noproperr(line);
333 errors++;
334 } else if (legal_label_check(word[1], line, OBJ_TYPE)) {
335 errors++;
336 } else {
337 objects++;
338
339 if (objects == MAX_OBJECTS) {
340 log_error(MAXIMUM_EXCEEDED, PLUS_STDERR);
341 terminate(47);
342 } else {
343 if ((object[objects] = (struct object_type *)
344 malloc(sizeof(struct object_type))) == NULL)
345 outofmem();
346
347 strncpy(object[objects]->label, word[1], 40);
348
349 object[objects]->label[40] = 0;
350 object[objects]->first_plural = NULL;
351
352 strcpy(object[objects]->described, object[objects]->label);
353 strcpy(object[objects]->inventory, object[objects]->label);
354 strcpy(object[objects]->article, "the");
355 strcpy(object[objects]->definite, "the");
356 object[objects]->attributes = FALSE;
357 object[objects]->user_attributes = FALSE;
358
359 for (counter = 0; counter < 16; counter++)
360 object[objects]->integer[counter] = 0;
361 }
362 object[objects]->nosave = FALSE;
363 }
364 } else if (!strcmp(word[0], "synonym")) {
365 if (word[++wp] == NULL) {
366 noproperr(line);
367 errors++;
368 } else {
369 if ((new_synonym = (struct synonym_type *)
370 malloc(sizeof(struct synonym_type))) == NULL)
371 outofmem();
372 else {
373 if (synonym_table == NULL) {
374 synonym_table = new_synonym;
375 } else {
376 current_synonym->next_synonym = new_synonym;
377 }
378 }
379 current_synonym = new_synonym;
380 strncpy(current_synonym->original, word[wp], 40);
381 current_synonym->original[40] = 0;
382 if (word[++wp] == NULL) {
383 noproperr(line);
384 errors++;
385 } else {
386 strncpy(current_synonym->standard, word[wp], 40);
387 current_synonym->standard[40] = 0;
388 }
389 current_synonym->next_synonym = NULL;
390 }
391 } else if (!strcmp(word[0], "parameter")) {
392 #ifndef GLK
393 #ifndef __NDS__
394 if (word[2] == NULL) {
395 noproperr(line);
396 errors++;
397 } else {
398 if ((new_parameter = (struct parameter_type *)
399 malloc(sizeof(struct parameter_type))) == NULL)
400 outofmem();
401 else {
402 if (parameter_table == NULL) {
403 parameter_table = new_parameter;
404 } else {
405 current_parameter->next_parameter =
406 new_parameter;
407 }
408 current_parameter = new_parameter;
409 strncpy(current_parameter->name, word[1], 40);
410 current_parameter->name[40] = 0;
411 strncpy(current_parameter->container, word[2], 40);
412 current_parameter->container[40] = 0;
413 current_parameter->next_parameter = NULL;
414 }
415
416 if (word[4] != NULL) {
417 if (validate(word[3]))
418 current_parameter->low = atoi(word[3]);
419 else
420 current_parameter->low = -65535;
421
422 if (validate(word[4]))
423 current_parameter->high = atoi(word[4]);
424 else
425 current_parameter->high = 65535;
426 } else {
427 current_parameter->low = -65535;
428 current_parameter->high = 65535;
429 }
430
431 }
432 #endif
433 #endif
434 } else if (!strcmp(word[0], "constant")) {
435 if (word[2] == NULL) {
436 noproperr(line);
437 errors++;
438 } else {
439 /* CHECK IF MORE THAN ONE VALUE IS SUPPLIED AND CREATE
440 ADDITIONAL CONSTANTS IF REQUIRED */
441 index = 2;
442
443 while (word[index] != NULL && index < MAX_WORDS) {
444 if (quoted[index] == TRUE || !validate(word[index])) {
445 if (legal_label_check(word[1], line, CSTR_TYPE)) {
446 errors++;
447 } else {
448 create_cstring(word[1], word[index]);
449 }
450 } else {
451 if (legal_label_check(word[1], line, CINT_TYPE)) {
452 errors++;
453 } else {
454 create_cinteger(word[1], value_of(word[index], 0));
455 if (!value_resolved) {
456 unkvalerr(line, index);
457 errors++;
458 }
459 }
460 }
461 index++;
462 }
463 }
464 } else if (!strcmp(word[0], "attribute")) {
465 if (word[1] == NULL) {
466 noproperr(line);
467 errors++;
468 } else {
469 index = 1;
470 while (word[index] != NULL && index < MAX_WORDS) {
471 if (legal_label_check(word[index], line, ATT_TYPE)) {
472 errors++;
473 } else if (current_attribute != NULL && current_attribute->value == 1073741824) {
474 maxatterr(line, index);
475 errors++;
476 } else {
477 create_attribute(word[index]);
478 }
479 index++;
480 }
481 }
482 } else if (!strcmp(word[0], "string")) {
483 if (word[1] == NULL) {
484 noproperr(line);
485 errors++;
486 } else if (legal_label_check(word[1], line, STR_TYPE)) {
487 errors++;
488 } else {
489 if (word[2] == NULL) {
490 create_string(word[1], "");
491 } else {
492 create_string(word[1], word[2]);
493 index = 3;
494 while (word[index] != NULL && index < MAX_WORDS) {
495 create_string(word[1], word[index]);
496 index++;
497 }
498 }
499 }
500 } else if (!strcmp(word[0], "filter")) {
501 if (word[++wp] == NULL) {
502 noproperr(line);
503 errors++;
504 } else {
505 if ((new_filter = (struct filter_type *)
506 malloc(sizeof(struct filter_type))) == NULL)
507 outofmem();
508 else {
509 if (filter_table == NULL) {
510 filter_table = new_filter;
511 } else {
512 current_filter->next_filter = new_filter;
513 }
514 current_filter = new_filter;
515 strncpy(current_filter->word, word[wp], 40);
516 current_filter->word[40] = 0;
517 current_filter->next_filter = NULL;
518 }
519 }
520 } else if (!strcmp(word[0], "string_array")) {
521 if (word[2] == NULL) {
522 noproperr(line);
523 errors++;
524 } else if (legal_label_check(word[1], line, STR_TYPE)) {
525 errors++;
526 } else {
527 int x;
528
529 index = value_of(word[2], FALSE);
530 if (!value_resolved) {
531 unkvalerr(line, 2);
532 errors++;
533 }
534
535 for (x = 0; x < index; x++) {
536 create_string (word[1], word[3]);
537 }
538 }
539 } else if (!strcmp(word[0], "integer_array")) {
540 if (word[2] == NULL) {
541 noproperr(line);
542 errors++;
543 } else if (legal_label_check(word[1], line, INT_TYPE)) {
544 errors++;
545 } else {
546 int default_value, x;
547
548 if (word[3] != NULL) {
549 default_value = value_of(word[3], FALSE);
550 if (!value_resolved) {
551 unkvalerr(line, 3);
552 errors++;
553 }
554 } else {
555 default_value = 0;
556 }
557
558 /* THIS IS THE NUMBER OF ARRAY ELEMENTS TO MAKE */
559 index = value_of(word[2], FALSE);
560 if (!value_resolved) {
561 unkvalerr(line, 2);
562 errors++;
563 }
564
565 for (x = 0; x < index; x++) {
566 create_integer (word[1], default_value);
567 }
568 }
569 } else if (!strcmp(word[0], "integer")
570 || !strcmp(word[0], "variable")) {
571 if (word[1] == NULL) {
572 noproperr(line);
573 errors++;
574 } else if (legal_label_check(word[1], line, INT_TYPE)) {
575 errors++;
576 } else {
577 create_integer (word[1], 0);
578
579 /* CHECK IF MORE THAN ONE VALUE IS SUPPLIED AND CREATE
580 ADDITIONAL VARIABLES IF REQUIRED */
581 index = 3;
582 while (word[index] != NULL && index < MAX_WORDS) {
583 create_integer (word[1], 0);
584 index++;
585 }
586 }
587 }
588 }
589 #ifdef GLK
590 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
591 #else
592 fgets(text_buffer, 1024, file);
593 #endif
594 line++;
595
596 if (!encrypted && strstr(text_buffer, "#encrypted")) {
597 encrypted = TRUE;
598 #ifdef GLK
599 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
600 #else
601 fgets(text_buffer, 1024, file);
602 #endif
603 line++;
604 }
605 if (encrypted) jacl_decrypt(text_buffer);
606 }
607
608 if (errors) {
609 totalerrs(errors);
610 terminate(48);
611 }
612
613 /*************************************************************************
614 * START OF SECOND PASS *
615 *************************************************************************/
616
617 /* IF NO SIZE IS SPECIFIED FOR THE STATUS WINDOW, SET IT TO 1 */
618 if (integer_resolve("status_window") == NULL) {
619 create_integer ("status_window", 1);
620 }
621
622 /* IF NO STRING IS SPECIFIED FOR THE COMMAND PROMPT, SET IT TO "^> " */
623 if (string_resolve("command_prompt") == NULL) {
624 create_string ("command_prompt", "^> ");
625 }
626
627 /* IF NO STRING IS SPECIFIED FOR THE GAME_TITLE, SET IT TO THE FILENAME */
628 if (cstring_resolve("game_title") == NULL) {
629 create_cstring ("game_title", prefix);
630 }
631
632 create_language_constants();
633
634 /* MUST RE-DETERMINE THE POINT IN THE GAME FILE THAT ENCRYPTION STARTS */
635 encrypted = FALSE;
636
637 /* SET CURRENT VARIABLE TO POINT TO THE FIRST USER VARIABLE THAT WAS
638 * CREATED AFTER THE SYSTEM VARIABLES */
639 current_integer = last_system_integer;
640
641 line = 0;
642 #ifdef GLK
643 glk_stream_set_position(game_stream, (glsi32)start_of_file, seekmode_Start);
644 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
645 #else
646 fseek(file, start_of_file, SEEK_SET);
647 fgets(text_buffer, 1024, file);
648 #endif
649
650 line++;
651
652 if (!encrypted && strstr(text_buffer, "#encrypted")) {
653 encrypted = TRUE;
654 #ifdef GLK
655 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
656 #else
657 fgets(text_buffer, 1024, file);
658 #endif
659 line++;
660 }
661 if (encrypted) jacl_decrypt(text_buffer);
662
663 #ifdef GLK
664 while (result)
665 #else
666 while (!feof(file))
667 #endif
668 {
669 encapsulate();
670 if (word[0] == NULL);
671 else if (text_buffer[0] == '{') {
672 in_print = FALSE;
673 word[wp]++; /* MOVE THE START OF THE FIRST WORD ONLY
674 * TO PAST THE '{'. */
675 if (word[wp][0] == 0) {
676 nofnamerr(line);
677 errors++;
678 } else {
679 // BY DEFAULT FUNCTIONS ARE NOT STATIC UNLESS EXPLICITLY DECLARED AS SUCH
680 is_static = FALSE;
681
682 // LOOP THROUGH ALL THE NAMES OF THIS FUNCTION, CREATING A NEW FUNCTION
683 // FOR EACH NAME (UNLESS THE DIRECTIVE 'static')
684 while (word[wp] != NULL && wp < MAX_WORDS) {
685 if (word[wp][0] == '+') {
686 strncpy(function_name, word[wp], 80);
687 function_name[80] = 0;
688 self_parent = 0;
689 } else if (word[wp][0] == '*') {
690 char *last_underscore = (char *) NULL;
691
692 /* ALLOW MANUAL NAMING OF ASSOCIATED FUNCTIONS */
693 /* TO GIVE CLASS-LIKE BEHAVIOR */
694 strncpy(function_name, word[wp] + 1, 80);
695 function_name[80] = 0;
696
697 /* LOOK FOR THE FINAL UNDERSCORE AND SEE IF */
698 /* IT IS FOLLOWED BY AN OBJECT LABEL */
699 last_underscore = strrchr(word[wp], '_');
700 if (last_underscore != NULL) {
701 self_parent = object_resolve(last_underscore + 1);
702 } else {
703 self_parent = 0;
704 }
705 } else if (!strcmp(word[wp], "static")) {
706 // ALL FUNCTION AFTER THIS POINT ARE STATIC.
707 is_static = TRUE;
708 // THIS IS ONLY A DIRECTIVE CHANGING FUTURE FUNCTION DECLARATIONS,
709 // NOT A REAL FUNCTION, SO MOVE ON TO THE NEXT WORD
710 wp++;
711 continue;
712 } else if (object_count == 0) {
713 nongloberr(line);
714 errors++;
715 } else {
716 strncpy(function_name, word[wp], 59);
717 strcat(function_name, "_");
718 strcat(function_name, object[object_count]->label);
719 self_parent = object_count;
720 }
721 if ((current_function->next_function =
722 (struct function_type *)
723 malloc(sizeof(struct function_type))) == NULL)
724 outofmem();
725 else {
726 // STORE THE NUMBER OF FUNCTIONS DEFINED TO
727 // HELP VALIDATE SAVED GAME FILES
728 functions++;
729
730 current_function = current_function->next_function;
731 strcpy(current_function->name, function_name);
732 #ifdef GLK
733 current_function->position = glk_stream_get_position(game_stream);
734 #else
735 current_function->position = ftell(file);
736 #endif
737 current_function->call_count = 0;
738 current_function->nosave = is_static;
739 current_function->call_count_backup = 0;
740 current_function->self = self_parent;
741 current_function->next_function = NULL;
742 }
743 wp++;
744 }
745 }
746
747 #ifdef GLK
748 while (result) {
749 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
750 #else
751 while (!feof(file)) {
752 fgets(text_buffer, 1024, file);
753 #endif
754 line++;
755
756 if (!encrypted && strstr(text_buffer, "#encrypted")) {
757 encrypted = TRUE;
758 #ifdef GLK
759 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
760 #else
761 fgets(text_buffer, 1024, file);
762 #endif
763 line++;
764 }
765 if (encrypted) jacl_decrypt(text_buffer);
766 encapsulate();
767 if (word[0] != NULL && !strcmp(word[0], "print")) {
768 // NOW INSIDE A PRINT BLOCK, SKIP UNTIL '.' IS REACHED
769 in_print = TRUE;
770 } else if (text_buffer[0] == '.') {
771 // NOW BACK OUT OF THE PRINT BLOCK AGAIN
772 in_print = FALSE;
773 } else if (in_print == FALSE && text_buffer[0] == '}') {
774 in_print = FALSE;
775 break;
776 }
777 }
778 } else if (!strcmp(word[0], "string_array")) {
779 } else if (!strcmp(word[0], "integer_array")) {
780 if (word[2] == NULL) {
781 noproperr(line);
782 errors++;
783 } else {
784 int x;
785
786 /* THIS IS THE NUMBER OF ARRAY ELEMENTS TO MAKE */
787 index = value_of(word[2], FALSE);
788 if (!value_resolved) {
789 unkvalerr(line, 2);
790 errors++;
791 }
792
793 for (x = 0; x < index; x++) {
794 current_integer = current_integer->next_integer;
795 }
796 }
797 } else if (!strcmp(word[0], "integer")) {
798 if (word[2] != NULL) {
799 current_integer = current_integer->next_integer;
800 current_integer->value = value_of(word[2], FALSE);
801 if (!value_resolved) {
802 unkvalerr(line, 2);
803 errors++;
804 }
805 index = 3;
806 while (word[index] != NULL && index < MAX_WORDS) {
807 current_integer = current_integer->next_integer;
808 current_integer->value = value_of(word[index], FALSE);
809 if (!value_resolved) {
810 unkvalerr(line, index);
811 errors++;
812 }
813 index++;
814 }
815 } else {
816 current_integer = current_integer->next_integer;
817 current_integer->value = FALSE;
818 }
819
820 /* CONSUME ALL THESE KEYWORDS TO AVOID AN UNKNOWN KEYWORD */
821 /* ERROR DURING THE SECOND PASS (ALL WORK DONE IN FIRST PASS) */
822 } else if (!strcmp(word[0], "constant"));
823 else if (!strcmp(word[0], "string"));
824 else if (!strcmp(word[0], "attribute"));
825 else if (!strcmp(word[0], "parameter"));
826 else if (!strcmp(word[0], "synonym"));
827 else if (!strcmp(word[0], "grammar"));
828 else if (!strcmp(word[0], "filter"));
829 else if (!strcmp(word[0], "has")) {
830 if (word[1] == NULL) {
831 noproperr(line);
832 errors++;
833 } else if (object_count == 0) {
834 noobjerr(line);
835 errors++;
836 } else {
837 for (index = 1; word[index] != NULL && index < MAX_WORDS; index++) {
838 if ((bit_mask = attribute_resolve(word[index]))) {
839 object[object_count]->attributes = object[object_count]->attributes | bit_mask;
840 } else if ((bit_mask = user_attribute_resolve(word[index]))) {
841 object[object_count]->user_attributes = object[object_count]->user_attributes | bit_mask;
842 } else {
843 unkatterr(line, index);
844 errors++;
845 }
846 }
847 }
848 } else if (!strcmp(word[0], "object")
849 || !strcmp(word[0], "location")) {
850 object_count++;
851
852 if (!strcmp(word[0], "object")) {
853 object[object_count]->MASS = SCENERY;
854 if (location_count == 0)
855 object[object_count]->PARENT = 0;
856 else
857 object[object_count]->PARENT = location_count;
858 } else {
859 location_count = object_count;
860 object[object_count]->PARENT = 0;
861 object[object_count]->attributes =
862 object[object_count]->attributes | LOCATION;
863 }
864
865
866 if ((object[object_count]->first_name =
867 (struct name_type *) malloc(sizeof(struct name_type)))
868 == NULL)
869 outofmem();
870 else {
871 current_name = object[object_count]->first_name;
872 if (word[2] != NULL) {
873 strncpy(current_name->name, word[2], 40);
874 } else {
875 strncpy(current_name->name, object[object_count]->label, 40);
876 }
877 current_name->name[40] = 0;
878 current_name->next_name = NULL;
879 }
880
881 wp = 3;
882
883 while (word[wp] != NULL && wp < MAX_WORDS) {
884 if ((current_name->next_name = (struct name_type *)
885 malloc(sizeof(struct name_type))) == NULL)
886 outofmem();
887 else {
888 current_name = current_name->next_name;
889 strncpy(current_name->name, word[wp], 40);
890 current_name->name[40] = 0;
891 current_name->next_name = NULL;
892 }
893 wp++;
894 }
895 } else if (!strcmp(word[0], "plural")) {
896 if (word[1] == NULL) {
897 noproperr(line);
898 errors++;
899 } else {
900 if ((object[object_count]->first_plural =
901 (struct name_type *) malloc(sizeof(struct name_type)))
902 == NULL)
903 outofmem();
904 else {
905 current_name = object[object_count]->first_plural;
906 strncpy(current_name->name, word[1], 40);
907 current_name->name[40] = 0;
908 current_name->next_name = NULL;
909 }
910
911 wp = 2;
912
913 while (word[wp] != NULL && wp < MAX_WORDS) {
914 if ((current_name->next_name = (struct name_type *)
915 malloc(sizeof(struct name_type))) == NULL)
916 outofmem();
917 else {
918 current_name = current_name->next_name;
919 strncpy(current_name->name, word[wp], 40);
920 current_name->name[40] = 0;
921 current_name->next_name = NULL;
922 }
923 wp++;
924 }
925 }
926 } else if (!strcmp(word[0], "static")) {
927 if (object_count == 0) {
928 noobjerr(line);
929 errors++;
930 } else {
931 object[object_count]->nosave = TRUE;
932 }
933 } else if (!strcmp(word[0], "player")) {
934 if (object_count == 0) {
935 noobjerr(line);
936 errors++;
937 } else
938 player = object_count;
939 } else if (!strcmp(word[0], "short")) {
940 if (word[2] == NULL) {
941 noproperr(line);
942 errors++;
943 } else if (object_count == 0) {
944 noobjerr(line);
945 errors++;
946 } else {
947 strncpy(object[object_count]->article, word[1], 10);
948 object[object_count]->article[10] = 0;
949 strncpy(object[object_count]->inventory, word[2], 40);
950 object[object_count]->inventory[40] = 0;
951 }
952 } else if (!strcmp(word[0], "definite")) {
953 if (word[1] == NULL) {
954 noproperr(line);
955 errors++;
956 } else if (object_count == 0) {
957 noobjerr(line);
958 errors++;
959 } else {
960 strncpy(object[object_count]->definite, word[1], 10);
961 object[object_count]->definite[10] = 0;
962 }
963 } else if (!strcmp(word[0], "long")) {
964 if (word[1] == NULL) {
965 noproperr(line);
966 errors++;
967 } else if (object_count == 0) {
968 noobjerr(line);
969 errors++;
970 } else {
971 strncpy(object[object_count]->described, word[1], 80);
972 object[object_count]->described[80] = 0;
973 }
974 } else if ((resolved_cinteger = cinteger_resolve(word[0])) != NULL) {
975 index = resolved_cinteger->value;
976 if (word[1] == NULL) {
977 noproperr(line);
978 errors++;
979 } else if (object_count == 0) {
980 noobjerr(line);
981 errors++;
982 } else if (!strcmp(word[1], "here")) {
983 object[object_count]->integer[index] = location_count;
984 } else {
985 object[object_count]->integer[index] = value_of(word[1], FALSE);
986 if (!value_resolved) {
987 unkvalerr(line, 1);
988 errors++;
989 }
990 }
991 } else {
992 unkkeyerr(line, 0);
993 errors++;
994 }
995
996 #ifdef GLK
997 current_file_position = glk_stream_get_position(game_stream);
998 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
999 #else
1000 current_file_position = ftell(file);
1001 fgets(text_buffer, 1024, file);
1002 #endif
1003 line++;
1004
1005 if (!encrypted && strstr(text_buffer, "#encrypted")) {
1006 encrypted = TRUE;
1007 #ifdef GLK
1008 result = glk_get_bin_line_stream(game_stream, text_buffer, (glui32) 1024);
1009 #else
1010 fgets(text_buffer, 1024, file);
1011 #endif
1012 line++;
1013 }
1014 if (encrypted) jacl_decrypt(text_buffer);
1015 }
1016
1017 /* CREATE THE CONSTANT THE RECORDS THE TOTAL NUMBER OF OBJECTS */
1018 create_cinteger ("objects", objects);
1019
1020 /* LOOP THROUGH ALL THE OBJECTS AND CALL THEIR CONSTRUCTORS
1021 for (index = 1; index <= objects; index++) {
1022 strcpy (function_name, "constructor_");
1023 strcat (function_name, object[index]->label);
1024 execute (function_name);
1025 }
1026 */
1027
1028 if (errors) {
1029 totalerrs(errors);
1030 terminate(48);
1031 }
1032 }
1033
1034 void
1035 build_grammar_table(struct word_type *pointer)
1036 {
1037 do {
1038 if (!strcmp(word[wp], pointer->word)) {
1039 if (pointer->first_child == NULL && word[wp + 1] != NULL) {
1040 if ((pointer->first_child = (struct word_type *)
1041 malloc(sizeof(struct word_type)))
1042 == NULL)
1043 outofmem();
1044 else {
1045 pointer = pointer->first_child;
1046 strncpy(pointer->word, word[++wp], 40);
1047 pointer->word[40] = 0;
1048 pointer->next_sibling = NULL;
1049 pointer->first_child = NULL;
1050 }
1051 } else {
1052 pointer = pointer->first_child;
1053 wp++;
1054 }
1055 } else {
1056 if (pointer->next_sibling == NULL) {
1057 if ((pointer->next_sibling = (struct word_type *)
1058 malloc(sizeof(struct word_type)))
1059 == NULL)
1060 outofmem();
1061 else {
1062 pointer = pointer->next_sibling;
1063 strncpy(pointer->word, word[wp], 40);
1064 pointer->word[40] = 0;
1065 pointer->next_sibling = NULL;
1066 pointer->first_child = NULL;
1067 }
1068 } else
1069 pointer = pointer->next_sibling;
1070 }
1071 }
1072 while (word[wp] != NULL && wp < MAX_WORDS);
1073 }
1074
1075 int
1076 legal_label_check(const char *word, int line, int type)
1077 {
1078 struct integer_type *integer_pointer = integer_table;
1079 struct cinteger_type *cinteger_pointer = cinteger_table;
1080 struct string_type *string_pointer = string_table;
1081 struct string_type *cstring_pointer = cstring_table;
1082 struct attribute_type *attribute_pointer = attribute_table;
1083
1084 int index;
1085
1086 if (!strcmp(word, "here") ||
1087 !strcmp(word, "player") ||
1088 !strcmp(word, "integer") ||
1089 !strcmp(word, "arg") ||
1090 !strcmp(word, "string_arg") ||
1091 !strcmp(word, "arg") ||
1092 !strcmp(word, "$word") ||
1093 !strcmp(word, "self") ||
1094 !strcmp(word, "this") ||
1095 !strcmp(word, "noun1") ||
1096 !strcmp(word, "noun2") ||
1097 !strcmp(word, "noun3") ||
1098 !strcmp(word, "noun4") ||
1099 !strcmp(word, "objects") ||
1100 validate (word)) {
1101 sprintf(error_buffer, ILLEGAL_LABEL, line, word);
1102 log_error(error_buffer, PLUS_STDERR);
1103
1104 return (TRUE);
1105 }
1106
1107 if (type == CSTR_TYPE) {
1108 if (!strcmp(word, "command_prompt")) {
1109 sprintf(error_buffer, USED_LABEL_STR, line, word);
1110 log_error(error_buffer, PLUS_STDERR);
1111
1112 return (TRUE);
1113 }
1114 }
1115
1116 while (integer_pointer != NULL && type != INT_TYPE) {
1117 if (!strcmp(word, integer_pointer->name)) {
1118 sprintf(error_buffer, USED_LABEL_INT, line, word);
1119 log_error(error_buffer, PLUS_STDERR);
1120
1121 return (TRUE);
1122 } else
1123 integer_pointer = integer_pointer->next_integer;
1124 }
1125
1126
1127 while (cinteger_pointer != NULL && type != CINT_TYPE) {
1128 if (!strcmp(word, cinteger_pointer->name)) {
1129 sprintf(error_buffer, USED_LABEL_CINT, line, word);
1130 log_error(error_buffer, PLUS_STDERR);
1131
1132 return (TRUE);
1133 } else
1134 cinteger_pointer = cinteger_pointer->next_cinteger;
1135 }
1136
1137 while (string_pointer != NULL && type != STR_TYPE) {
1138 if (!strcmp(word, string_pointer->name)) {
1139 sprintf(error_buffer, USED_LABEL_STR, line, word);
1140 log_error(error_buffer, PLUS_STDERR);
1141
1142 return (TRUE);
1143 } else
1144 string_pointer = string_pointer->next_string;
1145 }
1146
1147 while (cstring_pointer != NULL && type != CSTR_TYPE) {
1148 if (!strcmp(word, cstring_pointer->name)) {
1149 sprintf(error_buffer, USED_LABEL_CSTR, line, word);
1150 log_error(error_buffer, PLUS_STDERR);
1151
1152 return (TRUE);
1153 } else
1154 cstring_pointer = cstring_pointer->next_string;
1155 }
1156
1157 /* DON'T CHECK FOR ATT_TYPE AS YOU CAN'T HAVE ATTRIBUTE ARRAYS. */
1158 while (attribute_pointer != NULL) {
1159 if (!strcmp(word, attribute_pointer->name)) {
1160 sprintf(error_buffer, USED_LABEL_ATT, line, word);
1161 write_text(error_buffer);
1162
1163 return (TRUE);
1164 } else
1165 attribute_pointer = attribute_pointer->next_attribute;
1166 }
1167
1168 for (index = 1; index <= objects; index++) {
1169 if (!strcmp(word, object[index]->label)) {
1170 sprintf(error_buffer, USED_LABEL_OBJ,
1171 line, word);
1172 log_error(error_buffer, PLUS_STDERR);
1173
1174 return (TRUE);
1175 }
1176 }
1177
1178 return (FALSE);
1179 }
1180
1181 void
1182 restart_game()
1183 {
1184 int index;
1185
1186 struct integer_type *current_integer;
1187 struct integer_type *previous_integer;
1188 struct synonym_type *current_synonym;
1189 struct synonym_type *previous_synonym;
1190 struct name_type *current_name;
1191 struct name_type *next_name;
1192 struct function_type *current_function;
1193 struct function_type *previous_function;
1194 struct string_type *current_string;
1195 struct string_type *previous_string;
1196 struct attribute_type *current_attribute;
1197 struct attribute_type *previous_attribute;
1198 struct cinteger_type *previous_cinteger;
1199 struct filter_type *current_filter;
1200 struct filter_type *previous_filter;
1201
1202 #ifdef GLK
1203 if (SOUND_SUPPORTED->value) {
1204 /* STOP ALL SOUNDS AND SET VOLUMES BACK TO 100% */
1205 for (index = 0; index < 4; index++) {
1206 glk_schannel_stop(sound_channel[index]);
1207 glk_schannel_set_volume(sound_channel[index], 65535);
1208
1209 /* STORE A COPY OF THE CURRENT VOLUME FOR ACCESS
1210 * FROM JACL CODE */
1211 sprintf(temp_buffer, "volume[%d]", index);
1212 cinteger_resolve(temp_buffer)->value = 100;
1213 }
1214 }
1215 #endif
1216
1217 /* FREE ALL OBJECTS */
1218 for (index = 1; index <= objects; index++) {
1219 current_name = object[index]->first_name;
1220 while (current_name->next_name != NULL) {
1221 next_name = current_name->next_name;
1222 free(current_name);
1223 current_name = next_name;
1224 }
1225 free(current_name);
1226 free(object[index]);
1227 }
1228
1229 /* FREE ALL VARIABLES */
1230
1231 if (integer_table != NULL) {
1232 if (integer_table->next_integer != NULL) {
1233 do {
1234 current_integer = integer_table;
1235 previous_integer = integer_table;
1236 while (current_integer->next_integer != NULL) {
1237 previous_integer = current_integer;
1238 current_integer = current_integer->next_integer;
1239 }
1240 free(current_integer);
1241 previous_integer->next_integer = NULL;
1242 } while (previous_integer != integer_table);
1243 }
1244
1245 free(integer_table);
1246 integer_table = NULL;
1247 }
1248
1249 /* FREE ALL FUNCTIONS */
1250 if (function_table != NULL) {
1251 if (function_table->next_function != NULL) {
1252 do {
1253 current_function = function_table;
1254 previous_function = function_table;
1255 while (current_function->next_function != NULL) {
1256 previous_function = current_function;
1257 current_function = current_function->next_function;
1258 }
1259 free(current_function);
1260 previous_function->next_function = NULL;
1261 } while (previous_function != function_table);
1262 }
1263
1264 free(function_table);
1265 function_table = NULL;
1266 }
1267
1268 /* FREE ALL FILTERS */
1269 if (filter_table != NULL) {
1270 if (filter_table->next_filter != NULL) {
1271 do {
1272 current_filter = filter_table;
1273 previous_filter = filter_table;
1274 while (current_filter->next_filter != NULL) {
1275 previous_filter = current_filter;
1276 current_filter = current_filter->next_filter;
1277 }
1278 free(current_filter);
1279 previous_filter->next_filter = NULL;
1280 } while (previous_filter != filter_table);
1281 }
1282
1283 free(filter_table);
1284 filter_table = NULL;
1285 }
1286
1287 /* FREE ALL STRINGS */
1288 if (string_table != NULL) {
1289 if (string_table->next_string != NULL) {
1290 do {
1291 current_string = string_table;
1292 previous_string = string_table;
1293 while (current_string->next_string != NULL) {
1294 previous_string = current_string;
1295 current_string = current_string->next_string;
1296 }
1297 free(current_string);
1298 previous_string->next_string = NULL;
1299 } while (previous_string != string_table);
1300 }
1301
1302 free(string_table);
1303 string_table = NULL;
1304 }
1305
1306 /* FREE ALL ATTRIBUTES */
1307 if (attribute_table != NULL) {
1308 if (attribute_table->next_attribute != NULL) {
1309 do {
1310 current_attribute = attribute_table;
1311 previous_attribute = attribute_table;
1312 while (current_attribute->next_attribute != NULL) {
1313 previous_attribute = current_attribute;
1314 current_attribute = current_attribute->next_attribute;
1315 }
1316 free(current_attribute);
1317 previous_attribute->next_attribute = NULL;
1318 } while (previous_attribute != attribute_table);
1319 }
1320
1321 free(attribute_table);
1322 attribute_table = NULL;
1323 }
1324
1325 /* FREE ALL CONSTANTS */
1326 if (cinteger_table != NULL) {
1327 if (cinteger_table->next_cinteger != NULL) {
1328 do {
1329 current_cinteger = cinteger_table;
1330 previous_cinteger = cinteger_table;
1331 while (current_cinteger->next_cinteger != NULL) {
1332 previous_cinteger = current_cinteger;
1333 current_cinteger = current_cinteger->next_cinteger;
1334 }
1335 free(current_cinteger);
1336 previous_cinteger->next_cinteger = NULL;
1337 } while (previous_cinteger != cinteger_table);
1338 }
1339
1340 free(cinteger_table);
1341 cinteger_table = NULL;
1342 }
1343
1344 if (cstring_table != NULL) {
1345 if (cstring_table->next_string != NULL) {
1346 do {
1347 current_string = cstring_table;
1348 previous_string = cstring_table;
1349 while (current_string->next_string != NULL) {
1350 previous_string = current_string;
1351 current_string = current_string->next_string;
1352 }
1353 free(current_string);
1354 previous_string->next_string = NULL;
1355 } while (previous_string != cstring_table);
1356 }
1357
1358 free(cstring_table);
1359 cstring_table = NULL;
1360 }
1361
1362 /* FREE ALL SYNONYMS */
1363 if (synonym_table != NULL) {
1364 if (synonym_table->next_synonym != NULL) {
1365 do {
1366 current_synonym = synonym_table;
1367 previous_synonym = synonym_table;
1368 while (current_synonym->next_synonym != NULL) {
1369 previous_synonym = current_synonym;
1370 current_synonym = current_synonym->next_synonym;
1371 }
1372 free(current_synonym);
1373 previous_synonym->next_synonym = NULL;
1374 } while (previous_synonym != synonym_table);
1375 }
1376 free(synonym_table);
1377 synonym_table = NULL;
1378 }
1379
1380 free_from(grammar_table);
1381 grammar_table = NULL;
1382
1383 read_gamefile();
1384 }
1385
1386 void
1387 free_from(struct word_type *x)
1388 {
1389 if (x) {
1390 free_from(x->first_child);
1391 free_from(x->next_sibling);
1392 free(x);
1393 }
1394 }
1395
1396 void
1397 set_defaults()
1398 {
1399 /* RESET THE BACK-REFERENCE VARIABLES */
1400 them[0] = 0;
1401 it = 0;
1402 her = 0;
1403 him = 0;
1404 }
1405
1406 void
1407 create_attribute(const char *name)
1408 {
1409 struct attribute_type *new_attribute = NULL;
1410 int index;
1411
1412 if ((new_attribute = (struct attribute_type *)
1413 malloc(sizeof(struct attribute_type))) == NULL) {
1414 outofmem();
1415 } else {
1416 if (attribute_table == NULL) {
1417 attribute_table = new_attribute;
1418 new_attribute->value = 1;
1419 } else {
1420 current_attribute->next_attribute = new_attribute;
1421 new_attribute->value = current_attribute->value * 2;
1422 }
1423 current_attribute = new_attribute;
1424 strncpy(current_attribute->name, name, 40);
1425 current_attribute->name[40] = 0;
1426 current_attribute->next_attribute = NULL;
1427 }
1428 }
1429
1430 void
1431 create_cinteger (const char *name, int value)
1432 {
1433 struct cinteger_type *new_cinteger = NULL;
1434
1435 if ((new_cinteger = (struct cinteger_type *)
1436 malloc(sizeof(struct cinteger_type))) == NULL) {
1437 outofmem();
1438 } else {
1439 if (cinteger_table == NULL) {
1440 cinteger_table = new_cinteger;
1441 } else {
1442 current_cinteger->next_cinteger = new_cinteger;
1443 }
1444
1445 current_cinteger = new_cinteger;
1446 strncpy(current_cinteger->name, name, 40);
1447 current_cinteger->name[40] = 0;
1448 current_cinteger->value = value;
1449 current_cinteger->next_cinteger = NULL;
1450 }
1451 }
1452
1453 void
1454 create_integer (const char *name, int value)
1455 {
1456 struct integer_type *new_integer = NULL;
1457
1458 if ((new_integer = (struct integer_type *)
1459 malloc(sizeof(struct integer_type))) == NULL) {
1460 outofmem();
1461 } else {
1462 /* KEEP A COUNT OF HOW MANY INTEGERS ARE DEFINED TO
1463 * VALIDATE SAVED GAMES */
1464 integers++;
1465
1466 if (integer_table == NULL) {
1467 integer_table = new_integer;
1468 } else {
1469 current_integer->next_integer = new_integer;
1470 }
1471 current_integer = new_integer;
1472 strncpy(current_integer->name, name, 40);
1473 current_integer->name[40] = 0;
1474 current_integer->value = value;
1475 current_integer->next_integer = NULL;
1476 }
1477 }
1478
1479 void
1480 create_string (const char *name, const char *value)
1481 {
1482 struct string_type *new_string = NULL;
1483
1484 if ((new_string = (struct string_type *)
1485 malloc(sizeof(struct string_type))) == NULL) {
1486 outofmem();
1487 } else {
1488 /* KEEP A COUNT OF HOW MANY STRINGS ARE DEFINED TO
1489 * VALIDATE SAVED GAMES */
1490 strings++;
1491
1492 if (string_table == NULL) {
1493 string_table = new_string;
1494 } else {
1495 current_string->next_string = new_string;
1496 }
1497 current_string = new_string;
1498 strncpy(current_string->name, name, 40);
1499 current_string->name[40] = 0;
1500
1501 if (value != NULL) {
1502 strncpy(current_string->value, value, 1023);
1503 } else {
1504 /* IF NO VALUE IS SUPPLIED, JUST NULL-TERMINATE
1505 * THE STRING */
1506 current_string->value[0] = 0;
1507 }
1508
1509 current_string->value[1024] = 0;
1510 current_string->next_string = NULL;
1511 }
1512 }
1513
1514 void
1515 create_cstring (const char *name, const char *value)
1516 {
1517 struct string_type *new_string = NULL;
1518
1519 if ((new_string = (struct string_type *)
1520 malloc(sizeof(struct string_type))) == NULL) {
1521 outofmem();
1522 } else {
1523 if (cstring_table == NULL) {
1524 cstring_table = new_string;
1525 } else {
1526 current_cstring->next_string = new_string;
1527 }
1528 current_cstring = new_string;
1529 strncpy(current_cstring->name, name, 40);
1530 current_cstring->name[40] = 0;
1531
1532 if (value != NULL) {
1533 strncpy(current_cstring->value, value, 1023);
1534 } else {
1535 /* IF NO VALUE IS SUPPLIED, JUST NULL-TERMINATE
1536 * THE STRING */
1537 current_cstring->value[0] = 0;
1538 }
1539
1540 current_cstring->value[1024] = 0;
1541 current_cstring->next_string = NULL;
1542 }
1543 }
1544
1545 void
1546 create_language_constants()
1547 {
1548
1549 /* SET THE DEFAULT LANGUAGE CONSTANTS IF ANY OR ALL OF THEM
1550 * ARE MISSING FROM THE GAME THAT IS BEING LOADED. DEFAULT
1551 * TO THE NATIVE_LANGUAGE SETTING IN language.h */
1552
1553 if (cstring_resolve("COMMENT_IGNORED") == NULL)
1554 create_cstring ("COMMENT_IGNORED", COMMENT_IGNORED);
1555 if (cstring_resolve("COMMENT_RECORDED") == NULL)
1556 create_cstring ("COMMENT_RECORDED", COMMENT_RECORDED);
1557 if (cstring_resolve("YES_WORD") == NULL)
1558 create_cstring ("YES_WORD", YES_WORD);
1559 if (cstring_resolve("NO_WORD") == NULL)
1560 create_cstring ("NO_WORD", NO_WORD);
1561 if (cstring_resolve("YES_OR_NO") == NULL)
1562 create_cstring ("YES_OR_NO", YES_OR_NO);
1563 if (cstring_resolve("INVALID_SELECTION") == NULL)
1564 create_cstring ("INVALID_SELECTION", INVALID_SELECTION);
1565 if (cstring_resolve("RESTARTING") == NULL)
1566 create_cstring ("RESTARTING", RESTARTING);
1567 if (cstring_resolve("RETURN_GAME") == NULL)
1568 create_cstring ("RETURN_GAME", RETURN_GAME);
1569 if (cstring_resolve("SCRIPTING_ON") == NULL)
1570 create_cstring ("SCRIPTING_ON", SCRIPTING_ON);
1571 if (cstring_resolve("SCRIPTING_OFF") == NULL)
1572 create_cstring ("SCRIPTING_OFF", SCRIPTING_OFF);
1573 if (cstring_resolve("SCRIPTING_ALREADY_OFF") == NULL)
1574 create_cstring ("SCRIPTING_ALREADY_OFF", SCRIPTING_ALREADY_OFF);
1575 if (cstring_resolve("SCRIPTING_ALREADY_ON") == NULL)
1576 create_cstring ("SCRIPTING_ALREADY_OFF", SCRIPTING_ALREADY_OFF);
1577 if (cstring_resolve("CANT_WRITE_SCRIPT") == NULL)
1578 create_cstring ("CANT_WRITE_SCRIPT", CANT_WRITE_SCRIPT);
1579 if (cstring_resolve("ERROR_READING_WALKTHRU") == NULL)
1580 create_cstring ("ERROR_READING_WALKTHRU", ERROR_READING_WALKTHRU);
1581 if (cstring_resolve("BAD_OOPS") == NULL)
1582 create_cstring ("BAD_OOPS", BAD_OOPS);
1583 if (cstring_resolve("CANT_CORRECT") == NULL)
1584 create_cstring ("CANT_CORRECT", CANT_CORRECT);
1585 if (cstring_resolve("SURE_QUIT") == NULL)
1586 create_cstring ("SURE_QUIT", SURE_QUIT);
1587 if (cstring_resolve("SURE_RESTART") == NULL)
1588 create_cstring ("SURE_RESTART", SURE_RESTART);
1589 if (cstring_resolve("NOT_CLEVER") == NULL)
1590 create_cstring ("NOT_CLEVER", NOT_CLEVER);
1591 if (cstring_resolve("NO_MOVES") == NULL)
1592 create_cstring ("NO_MOVES", NO_MOVES);
1593 if (cstring_resolve("TYPE_NUMBER") == NULL)
1594 create_cstring ("TYPE_NUMBER", TYPE_NUMBER);
1595 if (cstring_resolve("BY") == NULL)
1596 create_cstring ("BY", BY);
1597 if (cstring_resolve("REFERRING_TO") == NULL)
1598 create_cstring ("REFERRING_TO", REFERRING_TO);
1599 if (cstring_resolve("WALKTHRU_WORD") == NULL)
1600 create_cstring ("WALKTHRU_WORD", WALKTHRU_WORD);
1601 if (cstring_resolve("INFO_WORD") == NULL)
1602 create_cstring ("INFO_WORD", INFO_WORD);
1603 if (cstring_resolve("RESTART_WORD") == NULL)
1604 create_cstring ("RESTART_WORD", RESTART_WORD);
1605 if (cstring_resolve("AGAIN_WORD") == NULL)
1606 create_cstring ("AGAIN_WORD", AGAIN_WORD);
1607 if (cstring_resolve("SCRIPT_WORD") == NULL)
1608 create_cstring ("SCRIPT_WORD", SCRIPT_WORD);
1609 if (cstring_resolve("UNSCRIPT_WORD") == NULL)
1610 create_cstring ("UNSCRIPT_WORD", UNSCRIPT_WORD);
1611 if (cstring_resolve("QUIT_WORD") == NULL)
1612 create_cstring ("QUIT_WORD", QUIT_WORD);
1613 if (cstring_resolve("UNDO_WORD") == NULL)
1614 create_cstring ("UNDO_WORD", UNDO_WORD);
1615 if (cstring_resolve("OOPS_WORD") == NULL)
1616 create_cstring ("OOPS_WORD", OOPS_WORD);
1617 if (cstring_resolve("FROM_WORD") == NULL)
1618 create_cstring ("FROM_WORD", FROM_WORD);
1619 if (cstring_resolve("EXCEPT_WORD") == NULL)
1620 create_cstring ("EXCEPT_WORD", EXCEPT_WORD);
1621 if (cstring_resolve("FOR_WORD") == NULL)
1622 create_cstring ("FOR_WORD", FOR_WORD);
1623 if (cstring_resolve("BUT_WORD") == NULL)
1624 create_cstring ("BUT_WORD", BUT_WORD);
1625 if (cstring_resolve("AND_WORD") == NULL)
1626 create_cstring ("AND_WORD", AND_WORD);
1627 if (cstring_resolve("THEN_WORD") == NULL)
1628 create_cstring ("THEN_WORD", THEN_WORD);
1629 if (cstring_resolve("OF_WORD") == NULL)
1630 create_cstring ("OF_WORD", OF_WORD);
1631 if (cstring_resolve("SHE_WORD") == NULL)
1632 create_cstring ("SHE_WORD", SHE_WORD);
1633 if (cstring_resolve("HE_WORD") == NULL)
1634 create_cstring ("HE_WORD", HE_WORD);
1635 if (cstring_resolve("THAT_WORD") == NULL)
1636 create_cstring ("THAT_WORD", THAT_WORD);
1637 if (cstring_resolve("THEM_WORD") == NULL)
1638 create_cstring ("THEM_WORD", THEM_WORD);
1639 if (cstring_resolve("THOSE_WORD") == NULL)
1640 create_cstring ("THOSE_WORD", THOSE_WORD);
1641 if (cstring_resolve("THEY_WORD") == NULL)
1642 create_cstring ("THEY_WORD", THEY_WORD);
1643 if (cstring_resolve("IT_WORD") == NULL)
1644 create_cstring ("IT_WORD", IT_WORD);
1645 if (cstring_resolve("ITSELF_WORD") == NULL)
1646 create_cstring ("ITSELF_WORD", ITSELF_WORD);
1647 if (cstring_resolve("HIM_WORD") == NULL)
1648 create_cstring ("HIM_WORD", HIM_WORD);
1649 if (cstring_resolve("HIMSELF_WORD") == NULL)
1650 create_cstring ("HIMSELF_WORD", HIMSELF_WORD);
1651 if (cstring_resolve("HER_WORD") == NULL)
1652 create_cstring ("HER_WORD", HER_WORD);
1653 if (cstring_resolve("HERSELF_WORD") == NULL)
1654 create_cstring ("HERSELF_WORD", HERSELF_WORD);
1655 if (cstring_resolve("THEMSELVES_WORD") == NULL)
1656 create_cstring ("THEMSELVES_WORD", THEMSELVES_WORD);
1657 if (cstring_resolve("YOU_WORD") == NULL)
1658 create_cstring ("YOU_WORD", YOU_WORD);
1659 if (cstring_resolve("YOURSELF_WORD") == NULL)
1660 create_cstring ("YOURSELF_WORD", YOURSELF_WORD);
1661 if (cstring_resolve("ONES_WORD") == NULL)
1662 create_cstring ("ONES_WORD", ONES_WORD);
1663 if (cstring_resolve("NO_MULTI_VERB") == NULL)
1664 create_cstring ("NO_MULTI_VERB", NO_MULTI_VERB);
1665 if (cstring_resolve("NO_MULTI_START") == NULL)
1666 create_cstring ("NO_MULTI_START", NO_MULTI_START);
1667 if (cstring_resolve("PERSON_CONCEALING") == NULL)
1668 create_cstring ("PERSON_CONCEALING", PERSON_CONCEALING);
1669 if (cstring_resolve("PERSON_POSSESSIVE") == NULL)
1670 create_cstring ("PERSON_POSSESSIVE", PERSON_POSSESSIVE);
1671 if (cstring_resolve("CONTAINER_CLOSED") == NULL)
1672 create_cstring ("CONTAINER_CLOSED", CONTAINER_CLOSED);
1673 if (cstring_resolve("CONTAINER_CLOSED_FEM") == NULL)
1674 create_cstring ("CONTAINER_CLOSED_FEM", CONTAINER_CLOSED_FEM);
1675 if (cstring_resolve("FROM_NON_CONTAINER") == NULL)
1676 create_cstring ("FROM_NON_CONTAINER", FROM_NON_CONTAINER);
1677 if (cstring_resolve("DOUBLE_EXCEPT") == NULL)
1678 create_cstring ("DOUBLE_EXCEPT", DOUBLE_EXCEPT);
1679 if (cstring_resolve("NONE_HELD") == NULL)
1680 create_cstring ("NONE_HELD", NONE_HELD);
1681 if (cstring_resolve("NO_OBJECTS") == NULL)
1682 create_cstring ("NO_OBJECTS", NO_OBJECTS);
1683 if (cstring_resolve("NO_FILENAME") == NULL)
1684 create_cstring ("NO_FILENAME", NO_FILENAME);
1685 if (cstring_resolve("MOVE_UNDONE") == NULL)
1686 create_cstring ("MOVE_UNDONE", MOVE_UNDONE);
1687 if (cstring_resolve("NO_UNDO") == NULL)
1688 create_cstring ("NO_UNDO", NO_UNDO);
1689 if (cstring_resolve("CANT_SAVE") == NULL)
1690 create_cstring ("CANT_SAVE", CANT_SAVE);
1691 if (cstring_resolve("CANT_RESTORE") == NULL)
1692 create_cstring ("CANT_RESTORE", CANT_RESTORE);
1693 if (cstring_resolve("GAME_SAVED") == NULL)
1694 create_cstring ("GAME_SAVED", GAME_SAVED);
1695 if (cstring_resolve("INCOMPLETE_SENTENCE") == NULL)
1696 create_cstring ("INCOMPLETE_SENTENCE", INCOMPLETE_SENTENCE);
1697 if (cstring_resolve("UNKNOWN_OBJECT") == NULL)
1698 create_cstring ("UNKNOWN_OBJECT", UNKNOWN_OBJECT);
1699 if (cstring_resolve("UNKNOWN_OBJECT_END") == NULL)
1700 create_cstring ("UNKNOWN_OBJECT_END", UNKNOWN_OBJECT_END);
1701 if (cstring_resolve("CANT_USE_WORD") == NULL)
1702 create_cstring ("CANT_USE_WORD", CANT_USE_WORD);
1703 if (cstring_resolve("IN_CONTEXT") == NULL)
1704 create_cstring ("IN_CONTEXT", IN_CONTEXT);
1705 if (cstring_resolve("DONT_SEE") == NULL)
1706 create_cstring ("DONT_SEE", DONT_SEE);
1707 if (cstring_resolve("HERE_WORD") == NULL)
1708 create_cstring ("HERE_WORD", HERE_WORD);
1709 if (cstring_resolve("BAD_SAVED_GAME") == NULL)
1710 create_cstring ("BAD_SAVED_GAME", BAD_SAVED_GAME);
1711 if (cstring_resolve("ARENT") == NULL)
1712 create_cstring ("ARENT", ARENT);
1713 if (cstring_resolve("ISNT") == NULL)
1714 create_cstring ("ISNT", ISNT);
1715 if (cstring_resolve("ARE") == NULL)
1716 create_cstring ("ARE", ARE);
1717 if (cstring_resolve("IS") == NULL)
1718 create_cstring ("IS", IS);
1719 if (cstring_resolve("DONT") == NULL)
1720 create_cstring ("DONT", DONT);
1721 if (cstring_resolve("DOESNT") == NULL)
1722 create_cstring ("DOESNT", DOESNT);
1723 if (cstring_resolve("DO") == NULL)
1724 create_cstring ("DO", DO);
1725 if (cstring_resolve("DOES") == NULL)
1726 create_cstring ("DOES", DOES);
1727 if (cstring_resolve("SCORE_UP") == NULL)
1728 create_cstring ("SCORE_UP", SCORE_UP);
1729 if (cstring_resolve("POINT") == NULL)
1730 create_cstring ("POINT", POINT);
1731 if (cstring_resolve("POINTS") == NULL)
1732 create_cstring ("POINTS", POINTS);
1733 if (cstring_resolve("STARTING") == NULL)
1734 create_cstring ("STARTING", STARTING);
1735 if (cstring_resolve("NO_IT") == NULL)
1736 create_cstring ("NO_IT", NO_IT);
1737 if (cstring_resolve("NO_IT_END") == NULL)
1738 create_cstring ("NO_IT_END", NO_IT_END);
1739 if (cstring_resolve("BACK_REFERENCE") == NULL)
1740 create_cstring ("BACK_REFERENCE", BACK_REFERENCE);
1741 if (cstring_resolve("BACK_REFERENCE_END") == NULL)
1742 create_cstring ("BACK_REFERENCE_END", BACK_REFERENCE_END);
1743 if (cstring_resolve("WHEN_YOU_SAY") == NULL)
1744 create_cstring ("WHEN_YOU_SAY", WHEN_YOU_SAY);
1745 if (cstring_resolve("MUST_SPECIFY") == NULL)
1746 create_cstring ("MUST_SPECIFY", MUST_SPECIFY);
1747 if (cstring_resolve("OR_WORD") == NULL)
1748 create_cstring ("OR_WORD", OR_WORD);
1749 }