From: fliep Date: Mon, 25 May 2009 18:05:46 +0000 (+0000) Subject: Removed unnecessary files from nitfol X-Git-Tag: v0.9~374 X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=48c89dc9941a5a349f9dc5099baa4dcc54bd6169;p=projects%2Fchimara%2Fchimara.git Removed unnecessary files from nitfol --- diff --git a/interpreters/nitfol/Makefile.am b/interpreters/nitfol/Makefile.am index 077d0fc..b5d3099 100644 --- a/interpreters/nitfol/Makefile.am +++ b/interpreters/nitfol/Makefile.am @@ -2,22 +2,28 @@ PLUGIN_LIBTOOL_FLAGS=-module -avoid-version -export-symbols-regex "^glk" -GRAPHICS = no_graph.c -# GRAPHICS = graphics.c -BLORB = blorb.c -# BLORB = no_blorb.c -SOUND = no_snd.c -# SOUND = sound.c +GRAPHICS = no_graph.c no_graph.h +# GRAPHICS = graphics.c graphics.h +BLORB = blorb.c +# BLORB = no_blorb.c no_blorb.h +SOUND = no_snd.c no_snd.h +# SOUND = sound.c sound.h pkglib_LTLIBRARIES = nitfol.la -nitfol_la_SOURCES = automap.c solve.c infix.c debug.c inform.c quetzal.c \ - undo.c op_call.c decode.c errmesg.c globals.c iff.c init.c main.c io.c \ - z_io.c op_jmp.c op_math.c op_save.c op_table.c op_v6.c oplist.c stack.c \ - zscii.c tokenise.c struct.c objects.c portfunc.c hash.c startunix.c \ +nitfol_la_SOURCES = automap.c automap.h binary.h debug.c debug.h decode.c \ + decode.h errmesg.c errmesg.h globals.c globals.h hash.c hash.h iff.c iff.h \ + infix.c infix.h inform.c inform.h init.c init.h io.c linkevil.h main.c \ + main.h nio.h nitfol.h objects.c objects.h op_call.c op_call.h op_jmp.c \ + op_jmp.h oplist.c oplist.h op_math.c op_math.h op_save.c op_save.h \ + op_table.c op_table.h op_v6.c op_v6.h portfunc.c portfunc.h quetzal.c \ + quetzal.h solve.c solve.h stack.c stack.h startunix.c struct.c struct.h \ + tokenise.c tokenise.h undo.c undo.h z_io.c z_io.h zscii.c zscii.h \ $(GRAPHICS) \ $(BLORB) \ $(SOUND) nitfol_la_LDFLAGS = $(PLUGIN_LIBTOOL_FLAGS) +EXTRA_DIST = crashme.inf test.inf + nitfoldocdir = $(datadir)/doc/$(PACKAGE)/nitfol dist_nitfoldoc_DATA = ChangeLog COPYING INSTALL README diff --git a/interpreters/nitfol/inform.hhh b/interpreters/nitfol/inform.hhh deleted file mode 100644 index 6ef60ca..0000000 --- a/interpreters/nitfol/inform.hhh +++ /dev/null @@ -1,5 +0,0 @@ -#ifdef DEBUGGING -void process_debug_command(const char *buffer); -BOOL exp_has_locals(const char *exp); -z_typed evaluate_expression(const char *exp, unsigned frame); -#endif diff --git a/interpreters/nitfol/rg_qsort.h b/interpreters/nitfol/rg_qsort.h deleted file mode 100644 index be1cbe4..0000000 --- a/interpreters/nitfol/rg_qsort.h +++ /dev/null @@ -1,12 +0,0 @@ -/* This is a Cfunctions (version 0.24) generated header file. - Cfunctions is a free program for extracting headers from C files. - Get Cfunctions from `http://www.hayamasa.demon.co.uk/cfunctions'. */ - -/* This file was generated with: -`cfunctions -i rg_qsort.c' */ -#ifndef CFH_RG_QSORT_H -#define CFH_RG_QSORT_H - -/* From `rg_qsort.c': */ - -#endif /* CFH_RG_QSORT_H */ diff --git a/interpreters/nitfol/startdos.c b/interpreters/nitfol/startdos.c deleted file mode 100644 index 5f2372d..0000000 --- a/interpreters/nitfol/startdos.c +++ /dev/null @@ -1,637 +0,0 @@ -#line 228 "opt2glkc.pl" -#ifdef DEBUGGING -#include -#endif -#include -#include -#include -#include -#include -#include -#include -#include "nitfol.h" -#include - -static char *game_filename = NULL; - -static void set_game_filename(const char *name) -{ - n_free(game_filename); - game_filename = 0; - -#if defined(_GNU_SOURCE) - game_filename = canonicalize_file_name(name); -#else -#if defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) - game_filename = (char *) n_malloc(PATH_MAX); - if(!realpath(name, game_filename)) { - n_free(game_filename); - game_filename = 0; - } -#else -#ifdef __DJGPP__ - game_filename = (char *) n_malloc(FILENAME_MAX); - _fixpath(name, game_filename); -#endif -#endif -#endif - - if(!game_filename) - game_filename = n_strdup(name); -} - - -strid_t startup_findfile(void) -{ - static DIR *dir = NULL; - static char *pathstart = NULL; - static char *path = NULL; - strid_t stream; - struct dirent *d; - char *name = NULL; - - if(!pathstart) { - char *p = search_path; - if(!p) - return 0; - pathstart = n_strdup(p); - if(!(path = n_strtok(pathstart, ":"))) { - n_free(pathstart); - pathstart = 0; - return 0; - } - } - - do { - if(!dir) { - dir = opendir(path); - if(!dir) { - n_free(pathstart); - pathstart = 0; - return 0; - } - } - d = readdir(dir); - if(!d) { - closedir(dir); - dir = NULL; - if(!(path = n_strtok(NULL, ":"))) { - n_free(pathstart); - pathstart = 0; - return 0; - } - } - } while(!dir); - - name = (char *) n_malloc(n_strlen(path) + n_strlen(d->d_name) + 2); - n_strcpy(name, path); - n_strcat(name, "/"); - n_strcat(name, d->d_name); - stream = glkunix_stream_open_pathname(name, fileusage_Data | - fileusage_BinaryMode, 0); - if(stream) - set_game_filename(name); - n_free(name); - return stream; -} - - -strid_t intd_filehandle_open(strid_t savefile, glui32 operating_id, - glui32 contents_id, glui32 interp_id, - glui32 length) -{ - char *name; - strid_t str; - if(operating_id != 0x554e4958 /* 'UNIX' */) - return 0; - if(contents_id != 0) - return 0; - if(interp_id != 0x20202020 /* ' ' */) - return 0; - - name = (char *) n_malloc(length+1); - glk_get_buffer_stream(savefile, name, length); - name[length] = 0; - str = glkunix_stream_open_pathname(name, fileusage_Data | - fileusage_BinaryMode, 0); - if(str) - set_game_filename(name); - n_free(name); - return str; -} - -void intd_filehandle_make(strid_t savefile) -{ - if(!game_filename) - return; - w_glk_put_string_stream(savefile, "UNIX"); - glk_put_char_stream(savefile, b00000010); /* Flags */ - glk_put_char_stream(savefile, 0); /* Contents ID */ - glk_put_char_stream(savefile, 0); /* Reserved */ - glk_put_char_stream(savefile, 0); /* Reserved */ - w_glk_put_string_stream(savefile, " "); /* Interpreter ID */ - w_glk_put_string_stream(savefile, game_filename); -} - -glui32 intd_get_size(void) -{ - if(!game_filename) - return 0; - return n_strlen(game_filename) + 12; -} - -strid_t startup_open(const char *name) -{ - strid_t str; - - str = glkunix_stream_open_pathname((char *) name, fileusage_Data | fileusage_BinaryMode, 0); - if(str) { - set_game_filename(name); - } else { - char *path = search_path; - if(path) { - char *p; - char *newname = (char *) n_malloc(strlen(path) + strlen(name) + 2); - path = n_strdup(path); - for(p = n_strtok(path, ":"); p; p = n_strtok(NULL, ":")) { - n_strcpy(newname, p); - n_strcat(newname, "/"); - n_strcat(newname, name); - str = glkunix_stream_open_pathname((char *) newname, fileusage_Data | - fileusage_BinaryMode, 0); - if(str) { - set_game_filename(newname); - break; - } - } - n_free(path); - } - } - - if(!str) - fprintf(stderr, "Cannot open '%s'\n", name); - - return str; -} - -#line 717 "opt2glkc.pl" -static strid_t startup_wopen(const char *name) -{ - return n_file_name(fileusage_Data | fileusage_BinaryMode, - filemode_Write, name); -} -glkunix_argumentlist_t glkunix_arguments[] = { - { (char *) "", glkunix_arg_ValueCanFollow, (char *) "filename file to load" }, - { (char *) "-help", glkunix_arg_NoValue, (char *) "list command-line options" }, - { (char *) "--help", glkunix_arg_NoValue, (char *) "list command-line options" }, - { (char *) "-version", glkunix_arg_NoValue, (char *) "get version number" }, - { (char *) "--version", glkunix_arg_NoValue, (char *) "get version number" }, - { (char *) "-i", glkunix_arg_NoValue, (char *) "-i" }, - { (char *) "-no-ignore", glkunix_arg_NoValue, (char *) "-no-ignore" }, - { (char *) "--no-ignore", glkunix_arg_NoValue, (char *) "--no-ignore" }, - { (char *) "-ignore", glkunix_arg_NoValue, (char *) "-ignore" }, - { (char *) "--ignore", glkunix_arg_NoValue, (char *) "--ignore Ignore Z-machine strictness errors" }, - { (char *) "-f", glkunix_arg_NoValue, (char *) "-f" }, - { (char *) "-no-fullname", glkunix_arg_NoValue, (char *) "-no-fullname" }, - { (char *) "--no-fullname", glkunix_arg_NoValue, (char *) "--no-fullname" }, - { (char *) "-fullname", glkunix_arg_NoValue, (char *) "-fullname" }, - { (char *) "--fullname", glkunix_arg_NoValue, (char *) "--fullname For running under Emacs or DDD" }, - { (char *) "-x", glkunix_arg_ValueFollows, (char *) "-x" }, - { (char *) "-command", glkunix_arg_ValueFollows, (char *) "-command" }, - { (char *) "--command", glkunix_arg_ValueFollows, (char *) "--command Read commands from this file" }, - { (char *) "-P", glkunix_arg_NoValue, (char *) "-P" }, - { (char *) "-no-pirate", glkunix_arg_NoValue, (char *) "-no-pirate" }, - { (char *) "--no-pirate", glkunix_arg_NoValue, (char *) "--no-pirate" }, - { (char *) "-pirate", glkunix_arg_NoValue, (char *) "-pirate" }, - { (char *) "--pirate", glkunix_arg_NoValue, (char *) "--pirate Aye, matey" }, - { (char *) "-q", glkunix_arg_NoValue, (char *) "-q" }, - { (char *) "-no-quiet", glkunix_arg_NoValue, (char *) "-no-quiet" }, - { (char *) "--no-quiet", glkunix_arg_NoValue, (char *) "--no-quiet" }, - { (char *) "-quiet", glkunix_arg_NoValue, (char *) "-quiet" }, - { (char *) "--quiet", glkunix_arg_NoValue, (char *) "--quiet Do not print introductory messages" }, - { (char *) "-no-spell", glkunix_arg_NoValue, (char *) "-no-spell" }, - { (char *) "--no-spell", glkunix_arg_NoValue, (char *) "--no-spell" }, - { (char *) "-spell", glkunix_arg_NoValue, (char *) "-spell" }, - { (char *) "--spell", glkunix_arg_NoValue, (char *) "--spell Perform spelling correction" }, - { (char *) "-no-expand", glkunix_arg_NoValue, (char *) "-no-expand" }, - { (char *) "--no-expand", glkunix_arg_NoValue, (char *) "--no-expand" }, - { (char *) "-expand", glkunix_arg_NoValue, (char *) "-expand" }, - { (char *) "--expand", glkunix_arg_NoValue, (char *) "--expand Expand one letter abbreviations" }, - { (char *) "-s", glkunix_arg_ValueFollows, (char *) "-s" }, - { (char *) "-symbols", glkunix_arg_ValueFollows, (char *) "-symbols" }, - { (char *) "--symbols", glkunix_arg_ValueFollows, (char *) "--symbols Specify symbol file for game" }, - { (char *) "-t", glkunix_arg_NoValue, (char *) "-t" }, - { (char *) "-no-tandy", glkunix_arg_NoValue, (char *) "-no-tandy" }, - { (char *) "--no-tandy", glkunix_arg_NoValue, (char *) "--no-tandy" }, - { (char *) "-tandy", glkunix_arg_NoValue, (char *) "-tandy" }, - { (char *) "--tandy", glkunix_arg_NoValue, (char *) "--tandy Censors some Infocom games" }, - { (char *) "-T", glkunix_arg_ValueFollows, (char *) "-T" }, - { (char *) "-transcript", glkunix_arg_ValueFollows, (char *) "-transcript" }, - { (char *) "--transcript", glkunix_arg_ValueFollows, (char *) "--transcript Write transcript to this file" }, - { (char *) "-d", glkunix_arg_NoValue, (char *) "-d" }, - { (char *) "-no-debug", glkunix_arg_NoValue, (char *) "-no-debug" }, - { (char *) "--no-debug", glkunix_arg_NoValue, (char *) "--no-debug" }, - { (char *) "-debug", glkunix_arg_NoValue, (char *) "-debug" }, - { (char *) "--debug", glkunix_arg_NoValue, (char *) "--debug Enter debugger immediatly" }, - { (char *) "-prompt", glkunix_arg_ValueFollows, (char *) "-prompt" }, - { (char *) "--prompt", glkunix_arg_ValueFollows, (char *) "--prompt Specify debugging prompt" }, - { (char *) "-path", glkunix_arg_ValueFollows, (char *) "-path" }, - { (char *) "--path", glkunix_arg_ValueFollows, (char *) "--path Look for games in this directory" }, - { (char *) "-no-autoundo", glkunix_arg_NoValue, (char *) "-no-autoundo" }, - { (char *) "--no-autoundo", glkunix_arg_NoValue, (char *) "--no-autoundo" }, - { (char *) "-autoundo", glkunix_arg_NoValue, (char *) "-autoundo" }, - { (char *) "--autoundo", glkunix_arg_NoValue, (char *) "--autoundo Ensure @code{@@save_undo} is called every turn" }, - { (char *) "-S", glkunix_arg_NumberValue, (char *) "-S" }, - { (char *) "-stacklimit", glkunix_arg_NumberValue, (char *) "-stacklimit" }, - { (char *) "--stacklimit", glkunix_arg_NumberValue, (char *) "--stacklimit Exit when the stack is this deep" }, - { (char *) "-a", glkunix_arg_ValueFollows, (char *) "-a" }, - { (char *) "-alias", glkunix_arg_ValueFollows, (char *) "-alias" }, - { (char *) "--alias", glkunix_arg_ValueFollows, (char *) "--alias Specify an alias" }, - { (char *) "-ralias", glkunix_arg_ValueFollows, (char *) "-ralias" }, - { (char *) "--ralias", glkunix_arg_ValueFollows, (char *) "--ralias Specify an recursive alias" }, - { (char *) "-unalias", glkunix_arg_ValueFollows, (char *) "-unalias" }, - { (char *) "--unalias", glkunix_arg_ValueFollows, (char *) "--unalias Remove an alias" }, - { (char *) "-r", glkunix_arg_NumberValue, (char *) "-r" }, - { (char *) "-random", glkunix_arg_NumberValue, (char *) "-random" }, - { (char *) "--random", glkunix_arg_NumberValue, (char *) "--random Set random seed" }, - { (char *) "-mapsym", glkunix_arg_ValueFollows, (char *) "-mapsym" }, - { (char *) "--mapsym", glkunix_arg_ValueFollows, (char *) "--mapsym Specify mapping glyphs" }, - { (char *) "-mapsize", glkunix_arg_NumberValue, (char *) "-mapsize" }, - { (char *) "--mapsize", glkunix_arg_NumberValue, (char *) "--mapsize Specify map size" }, - { (char *) "-maploc", glkunix_arg_ValueFollows, (char *) "-maploc" }, - { (char *) "--maploc", glkunix_arg_ValueFollows, (char *) "--maploc Specify map location" }, - { (char *) "-terpnum", glkunix_arg_NumberValue, (char *) "-terpnum" }, - { (char *) "--terpnum", glkunix_arg_NumberValue, (char *) "--terpnum Specify interpreter number" }, - { (char *) "-terpver", glkunix_arg_ValueFollows, (char *) "-terpver" }, - { (char *) "--terpver", glkunix_arg_ValueFollows, (char *) "--terpver Specify interpreter version" }, - { NULL, glkunix_arg_End, NULL } -}; - -static void code_ignore(int flag) -#line 6 "nitfol.opt" -{ ignore_errors = flag; } - -static void code_fullname(int flag) -#line 9 "nitfol.opt" -{ fullname = flag; } - -static void code_command(strid_t stream) -#line 12 "nitfol.opt" -{ if(stream) input_stream1 = stream; } - -static void code_pirate(int flag) -#line 15 "nitfol.opt" -{ aye_matey = flag; } - -static void code_quiet(int flag) -#line 18 "nitfol.opt" -{ quiet = flag; } - -static void code_spell(int flag) -#line 21 "nitfol.opt" -{ do_spell_correct = flag; } - -static void code_expand(int flag) -#line 24 "nitfol.opt" -{ do_expand = flag; } - -static void code_symbols(strid_t stream) -#line 27 "nitfol.opt" -{ if(stream) init_infix(stream); } - -static void code_tandy(int flag) -#line 30 "nitfol.opt" -{ do_tandy = flag; } - -static void code_transcript(strid_t stream) -#line 33 "nitfol.opt" -{ if(stream) set_transcript(stream); } - -static void code_debug(int flag) -#line 36 "nitfol.opt" -{ enter_debugger = flag; do_check_watches = flag; } - -static void code_prompt(const char *string) -#line 39 "nitfol.opt" -{ n_free(db_prompt); db_prompt = n_strdup(string); } - -static void code_path(const char *string) -#line 42 "nitfol.opt" -{ n_free(search_path); search_path = n_strdup(string); } - -static void code_autoundo(int flag) -#line 45 "nitfol.opt" -{ auto_save_undo = flag; } - -static void code_stacklimit(int number) -#line 52 "nitfol.opt" -{ stacklimit = number; } - -static void code_alias(const char *string) -#line 55 "nitfol.opt" -{ if(string) parse_new_alias(string, FALSE); } - -static void code_ralias(const char *string) -#line 58 "nitfol.opt" -{ if(string) parse_new_alias(string, TRUE); } - -static void code_unalias(const char *string) -#line 61 "nitfol.opt" -{ if(string) remove_alias(string); } - -static void code_random(int number) -#line 64 "nitfol.opt" -{ faked_random_seed = number; } - -static void code_mapsym(const char *string) -#line 67 "nitfol.opt" -{ n_free(roomsymbol); roomsymbol = n_strdup(string); } - -static void code_mapsize(int number) -#line 70 "nitfol.opt" -{ automap_size = number; } - -static void code_maploc(const char *string) -#line 73 "nitfol.opt" -{ switch(glk_char_to_lower(*string)) { case 'a': case 't': case 'u': automap_split = winmethod_Above; break; case 'b': case 'd': automap_split = winmethod_Below; break; case 'l': automap_split = winmethod_Left; break; case 'r': automap_split = winmethod_Right; } } - -static void code_terpnum(int number) -#line 76 "nitfol.opt" -{ interp_num = number; } - -static void code_terpver(const char *string) -#line 79 "nitfol.opt" -{ if(string) { if(n_strlen(string) == 1) interp_ver = *string; else interp_ver = n_strtol(string, NULL, 10); } } - -#line 760 "opt2glkc.pl" -typedef enum { option_flag, option_file, option_wfile, option_number, option_string } option_type; -typedef struct { const char *longname; char shortname; const char *description; option_type type; void (*int_func)(int); int defint; void (*str_func)(strid_t); strid_t defstream; void (*string_func)(const char *); const char *defstring; } option_option; - -static option_option options[] = { - { "ignore", 'i', "Ignore Z-machine strictness errors", option_flag, code_ignore, 0, NULL, NULL, NULL, NULL }, - { "fullname", 'f', "For running under Emacs or DDD", option_flag, code_fullname, 0, NULL, NULL, NULL, NULL }, - { "command", 'x', "Read commands from this file", option_file, NULL, 0, code_command, NULL, NULL, NULL }, - { "pirate", 'P', "Aye, matey", option_flag, code_pirate, 0, NULL, NULL, NULL, NULL }, - { "quiet", 'q', "Do not print introductory messages", option_flag, code_quiet, 1, NULL, NULL, NULL, NULL }, - { "spell", '-', "Perform spelling correction", option_flag, code_spell, 1, NULL, NULL, NULL, NULL }, - { "expand", '-', "Expand one letter abbreviations", option_flag, code_expand, 1, NULL, NULL, NULL, NULL }, - { "symbols", 's', "Specify symbol file for game", option_file, NULL, 0, code_symbols, NULL, NULL, NULL }, - { "tandy", 't', "Censors some Infocom games", option_flag, code_tandy, 0, NULL, NULL, NULL, NULL }, - { "transcript", 'T', "Write transcript to this file", option_wfile, NULL, 0, code_transcript, NULL, NULL, NULL }, - { "debug", 'd', "Enter debugger immediatly", option_flag, code_debug, 0, NULL, NULL, NULL, NULL }, - { "prompt", '-', "Specify debugging prompt", option_string, NULL, 0, NULL, NULL, code_prompt, "(nitfol) " }, - { "path", '-', "Look for games in this directory", option_string, NULL, 0, NULL, NULL, code_path, NULL }, - { "autoundo", '-', "Ensure '@save_undo' is called every turn", option_flag, code_autoundo, 1, NULL, NULL, NULL, NULL }, - { "stacklimit", 'S', "Exit when the stack is this deep", option_number, code_stacklimit, 0, NULL, NULL, NULL, NULL }, - { "alias", 'a', "Specify an alias", option_string, NULL, 0, NULL, NULL, code_alias, NULL }, - { "ralias", '-', "Specify an recursive alias", option_string, NULL, 0, NULL, NULL, code_ralias, NULL }, - { "unalias", '-', "Remove an alias", option_string, NULL, 0, NULL, NULL, code_unalias, NULL }, - { "random", 'r', "Set random seed", option_number, code_random, 0, NULL, NULL, NULL, NULL }, - { "mapsym", '-', "Specify mapping glyphs", option_string, NULL, 0, NULL, NULL, code_mapsym, "*udb@UDB+" }, - { "mapsize", '-', "Specify map size", option_number, code_mapsize, 12, NULL, NULL, NULL, NULL }, - { "maploc", '-', "Specify map location", option_string, NULL, 0, NULL, NULL, code_maploc, "above" }, - { "terpnum", '-', "Specify interpreter number", option_number, code_terpnum, 2, NULL, NULL, NULL, NULL }, - { "terpver", '-', "Specify interpreter version", option_string, NULL, 0, NULL, NULL, code_terpver, "N" } -}; - -#line 811 "opt2glkc.pl" -static void set_defaults(void) -{ - unsigned n; - for(n = 0; n < sizeof(options) / sizeof(*options); n++) { - if(options[n].int_func) - options[n].int_func(options[n].defint); - if(options[n].str_func) - options[n].str_func(options[n].defstream); - if(options[n].string_func) - options[n].string_func(options[n].defstring); - } -} - -#line 829 "opt2glkc.pl" -static void read_textpref(strid_t pref, const char *progname) -{ - unsigned n; - char buffer[1024]; - int prognamelen = n_strlen(progname); - if(!pref) - return; - while(glk_get_line_stream(pref, buffer, sizeof(buffer))) { - char *optname; - char *optval; - long int optnum; - - if(buffer[0] == '#') - continue; - while(buffer[0] == '[') { - if(n_strncasecmp(buffer+1, progname, prognamelen) != 0 - || buffer[1+prognamelen] != ']') { - while(glk_get_line_stream(pref, buffer, sizeof(buffer))) - if(buffer[0] == '[') - break; - } else { - glk_get_line_stream(pref, buffer, sizeof(buffer)); - } - } - - optname = buffer; - while(isspace(*optname)) - optname++; - if((optval = n_strchr(optname, '=')) != NULL) { - char *p; - *optval = 0; - optval++; - - if((p = n_strchr(optname, ' ')) != NULL) - *p = 0; - - while(isspace(*optval)) - optval++; - - while(isspace(optval[strlen(optval)-1])) - optval[strlen(optval)-1] = 0; - - optnum = n_strtol(optval, NULL, 0); - if(n_strcasecmp(optval, "false") == 0 - || n_strcasecmp(optval, "f") == 0) - optnum = FALSE; - if(n_strcasecmp(optval, "true") == 0 - || n_strcasecmp(optval, "t") == 0) - optnum = TRUE; - - for(n = 0; n < sizeof(options) / sizeof(*options); n++) { - if(n_strcmp(options[n].longname, optname) == 0) { - switch(options[n].type) { - case option_flag: - case option_number: - options[n].int_func(optnum); - break; - case option_file: - options[n].str_func(startup_open(optval)); - break; - case option_wfile: - options[n].str_func(startup_wopen(optval)); - break; - case option_string: - options[n].string_func(optval); - break; - } - break; - } - } - } - } - glk_stream_close(pref, NULL); -} - -#line 910 "opt2glkc.pl" -static void show_help(void) -{ - unsigned n; - printf("Usage: nitfol [OPTIONS] gamefile\n"); - for(n = 0; n < sizeof(options) / sizeof(*options); n++) { - if(options[n].shortname != '-') - printf(" -%c, ", options[n].shortname); - else - printf(" "); - printf("-%-15s %s\n", options[n].longname, options[n].description); - } -} - -#line 928 "opt2glkc.pl" -static BOOL parse_commands(int argc, char **argv) -{ - int i; - unsigned n; - - for(i = 1; i < argc; i++) { - BOOL flag = TRUE; - - const char *p = argv[i]; - - if(p[0] == '-') { - BOOL found = FALSE; - - while(*p == '-') - p++; - if(n_strncmp(p, "no-", 3) == 0) { - flag = FALSE; - p+=3; - } - - if(n_strcasecmp(p, "help") == 0) { - show_help(); - exit(0); - } - if(n_strcasecmp(p, "version") == 0) { - printf("nitfol version %d.%d\n", NITFOL_MAJOR, NITFOL_MINOR); - exit(0); - } - - for(n = 0; n < sizeof(options) / sizeof(*options); n++) { - if((n_strlen(p) == 1 && *p == options[n].shortname) || - n_strcmp(options[n].longname, p) == 0) { - found = TRUE; - - switch(options[n].type) { - case option_flag: - options[n].int_func(flag); - break; - - case option_file: - i++; - options[n].str_func(startup_open(argv[i])); - break; - - case option_wfile: - i++; - options[n].str_func(startup_wopen(argv[i])); - break; - - case option_number: - i++; - options[n].int_func(n_strtol(argv[i], NULL, 0)); - break; - - case option_string: - i++; - options[n].string_func(argv[i]); - break; - } - } - } - - if(!found) - return FALSE; - - } else { - strid_t s = startup_open(argv[i]); - if(!s) - return FALSE; - if(!game_use_file(s)) - return FALSE; - } - } - - return TRUE; -} - -#line 415 "opt2glkc.pl" - -#ifdef DEBUGGING -static void sighandle(int unused); - -static void sighandle(int unused) -{ -/* signal(SIGINT, sighandle); */ /* SysV resets default behaviour - foil it */ - enter_debugger = TRUE; -} -#endif - -#ifdef __cplusplus -extern "C" { -#endif -int glkunix_startup_code(glkunix_startup_t *data) -{ - strid_t pref; - const char *configname; - char *configdir, *prefname; - char *execname; - char *p; - username = getenv("LOGNAME"); /* SysV */ - if(!username) - username = getenv("USER"); /* BSD */ - -#ifdef DEBUGGING -/* signal(SIGINT, sighandle); */ -#endif - - execname = n_strrchr(data->argv[0], '/'); - - if(execname) - execname++; - else - execname = data->argv[0]; - - set_defaults(); - configdir = n_strdup(data->argv[0]); if(n_strrchr(configdir, '/')) *n_strrchr(configdir, '/') = 0; - configname = "/nitfol.cfg"; - prefname = n_malloc(n_strlen(configdir) + n_strlen(configname) + 1); - n_strcpy(prefname, configdir); - n_strcat(prefname, configname); - pref = glkunix_stream_open_pathname(prefname, fileusage_Data | fileusage_TextMode, 0); - n_free(configdir); - n_free(prefname); - read_textpref(pref, execname); - - p = getenv("INFOCOM_PATH"); - if(p) { - free(search_path); - search_path = n_strdup(p); - } - - return parse_commands(data->argc, data->argv); -} -#ifdef __cplusplus -} -#endif diff --git a/interpreters/nitfol/startmac.c b/interpreters/nitfol/startmac.c deleted file mode 100644 index 94bdfd9..0000000 --- a/interpreters/nitfol/startmac.c +++ /dev/null @@ -1,82 +0,0 @@ -#line 576 "opt2glkc.pl" -#include "nitfol.h" -#include "macglk_startup.h" - -static strid_t mac_gamefile; - -static BOOL hashandle = FALSE; -static AliasHandle gamehandle; -#line 694 "opt2glkc.pl" -strid_t startup_findfile(void) -{ - ; -} -#line 586 "opt2glkc.pl" -strid_t intd_filehandle_open(strid_t savefile, glui32 operating_id, - glui32 contents_id, glui32 interp_id, - glui32 length) -{ - FSSpec file; - Boolean wasChanged; - if(operating_id != 0x4d414353 /* 'MACS' */) - return 0; - if(contents_id != 0) - return 0; - if(interp_id != 0x20202020 /* ' ' */) - return 0; - - gamehandle = NewHandle(length); - glk_get_buffer_stream(savefile, *gamehandle, length); - hashandle = TRUE; - ResolveAlias(NULL, gamehandle, &file, &wasChanged); - return macglk_stream_open_fsspec(&file, 0, 0); -} - -void intd_filehandle_make(strid_t savefile) -{ - if(!hashandle) - return; - glk_put_string_stream(savefile, "MACS"); - glk_put_char_stream(savefile, b00000010); /* Flags */ - glk_put_char_stream(savefile, 0); /* Contents ID */ - glk_put_char_stream(savefile, 0); /* Reserved */ - glk_put_char_stream(savefile, 0); /* Reserved */ - glk_put_string_stream(savefile, " ");/* Interpreter ID */ - glk_put_buffer_stream(savefile, *gamehandle, *gamehandle->aliasSize); -} - -glui32 intd_get_size(void) -{ - if(!hashandle) - return 0; - return *gamehandle->aliasSize + 12; -} - -static Boolean mac_whenselected(FSSpec *file, OSType filetype) -{ - NewAlias(NULL, file, &gamehandle); - hashandle = TRUE; - return game_use_file(mac_gamefile); -} - -static Boolean mac_whenbuiltin() -{ - return game_use_file(mac_gamefile); -} - -Boolean macglk_startup_code(macglk_startup_t *data) -{ - OSType mac_gamefile_types[] = { 0x5a434f44 /* 'ZCOD' */, 0x49465253 /* 'IFRS' */, 0x49465a53 /* 'IFZS' */ }; - - data->startup_model = macglk_model_ChooseOrBuiltIn; - data->app_creator = 0x6e695466 /* 'niTf' */; - data->gamefile_types = mac_gamefile_types; - data->num_gamefile_types = sizeof(mac_gamefile_types) / sizeof(*mac_gamefile_types); - data->savefile_type = 0x49465a53 /* 'IFZS' */; - data->datafile_type = 0x5a697044 /* 'ZipD' */; - data->gamefile = &mac_gamefile; - data->when_selected = mac_whenselected; - data->when_builtin = mac_whenbuiltin; - - return TRUE; -} diff --git a/interpreters/nitfol/startwin.c b/interpreters/nitfol/startwin.c deleted file mode 100644 index 5e64c80..0000000 --- a/interpreters/nitfol/startwin.c +++ /dev/null @@ -1,322 +0,0 @@ -#line 488 "opt2glkc.pl" -#include "nitfol.h" -#include "WinGlk.h" - -#line 671 "opt2glkc.pl" -strid_t intd_filehandle_open(strid_t savefile, glui32 operating_id, - glui32 contents_id, glui32 interp_id, - glui32 length) -{ - return 0; -} - -void intd_filehandle_make(strid_t savefile) -{ - ; -} - -glui32 intd_get_size(void) -{ - return 0; -} -#line 694 "opt2glkc.pl" -strid_t startup_findfile(void) -{ - ; -} -#line 705 "opt2glkc.pl" -strid_t startup_open(const char *name) -{ - return n_file_name(fileusage_Data | fileusage_BinaryMode, - filemode_Read, name); -} -#line 717 "opt2glkc.pl" -static strid_t startup_wopen(const char *name) -{ - return n_file_name(fileusage_Data | fileusage_BinaryMode, - filemode_Write, name); -} -static void code_ignore(int flag) -#line 6 "nitfol.opt" -{ ignore_errors = flag; } - -static void code_fullname(int flag) -#line 9 "nitfol.opt" -{ fullname = flag; } - -static void code_command(strid_t stream) -#line 12 "nitfol.opt" -{ if(stream) input_stream1 = stream; } - -static void code_pirate(int flag) -#line 15 "nitfol.opt" -{ aye_matey = flag; } - -static void code_quiet(int flag) -#line 18 "nitfol.opt" -{ quiet = flag; } - -static void code_spell(int flag) -#line 21 "nitfol.opt" -{ do_spell_correct = flag; } - -static void code_expand(int flag) -#line 24 "nitfol.opt" -{ do_expand = flag; } - -static void code_symbols(strid_t stream) -#line 27 "nitfol.opt" -{ if(stream) init_infix(stream); } - -static void code_tandy(int flag) -#line 30 "nitfol.opt" -{ do_tandy = flag; } - -static void code_transcript(strid_t stream) -#line 33 "nitfol.opt" -{ if(stream) set_transcript(stream); } - -static void code_debug(int flag) -#line 36 "nitfol.opt" -{ enter_debugger = flag; do_check_watches = flag; } - -static void code_prompt(const char *string) -#line 39 "nitfol.opt" -{ n_free(db_prompt); db_prompt = n_strdup(string); } - -static void code_path(const char *string) -#line 42 "nitfol.opt" -{ n_free(search_path); search_path = n_strdup(string); } - -static void code_autoundo(int flag) -#line 45 "nitfol.opt" -{ auto_save_undo = flag; } - -static void code_stacklimit(int number) -#line 52 "nitfol.opt" -{ stacklimit = number; } - -static void code_alias(const char *string) -#line 55 "nitfol.opt" -{ if(string) parse_new_alias(string, FALSE); } - -static void code_ralias(const char *string) -#line 58 "nitfol.opt" -{ if(string) parse_new_alias(string, TRUE); } - -static void code_unalias(const char *string) -#line 61 "nitfol.opt" -{ if(string) remove_alias(string); } - -static void code_random(int number) -#line 64 "nitfol.opt" -{ faked_random_seed = number; } - -static void code_mapsym(const char *string) -#line 67 "nitfol.opt" -{ n_free(roomsymbol); roomsymbol = n_strdup(string); } - -static void code_mapsize(int number) -#line 70 "nitfol.opt" -{ automap_size = number; } - -static void code_maploc(const char *string) -#line 73 "nitfol.opt" -{ switch(glk_char_to_lower(*string)) { case 'a': case 't': case 'u': automap_split = winmethod_Above; break; case 'b': case 'd': automap_split = winmethod_Below; break; case 'l': automap_split = winmethod_Left; break; case 'r': automap_split = winmethod_Right; } } - -static void code_terpnum(int number) -#line 76 "nitfol.opt" -{ interp_num = number; } - -static void code_terpver(const char *string) -#line 79 "nitfol.opt" -{ if(string) { if(n_strlen(string) == 1) interp_ver = *string; else interp_ver = n_strtol(string, NULL, 10); } } - -#line 760 "opt2glkc.pl" -typedef enum { option_flag, option_file, option_wfile, option_number, option_string } option_type; -typedef struct { const char *longname; char shortname; const char *description; option_type type; void (*int_func)(int); int defint; void (*str_func)(strid_t); strid_t defstream; void (*string_func)(const char *); const char *defstring; } option_option; - -static option_option options[] = { - { "ignore", 'i', "Ignore Z-machine strictness errors", option_flag, code_ignore, 0, NULL, NULL, NULL, NULL }, - { "fullname", 'f', "For running under Emacs or DDD", option_flag, code_fullname, 0, NULL, NULL, NULL, NULL }, - { "command", 'x', "Read commands from this file", option_file, NULL, 0, code_command, NULL, NULL, NULL }, - { "pirate", 'P', "Aye, matey", option_flag, code_pirate, 0, NULL, NULL, NULL, NULL }, - { "quiet", 'q', "Do not print introductory messages", option_flag, code_quiet, 1, NULL, NULL, NULL, NULL }, - { "spell", '-', "Perform spelling correction", option_flag, code_spell, 1, NULL, NULL, NULL, NULL }, - { "expand", '-', "Expand one letter abbreviations", option_flag, code_expand, 1, NULL, NULL, NULL, NULL }, - { "symbols", 's', "Specify symbol file for game", option_file, NULL, 0, code_symbols, NULL, NULL, NULL }, - { "tandy", 't', "Censors some Infocom games", option_flag, code_tandy, 0, NULL, NULL, NULL, NULL }, - { "transcript", 'T', "Write transcript to this file", option_wfile, NULL, 0, code_transcript, NULL, NULL, NULL }, - { "debug", 'd', "Enter debugger immediatly", option_flag, code_debug, 0, NULL, NULL, NULL, NULL }, - { "prompt", '-', "Specify debugging prompt", option_string, NULL, 0, NULL, NULL, code_prompt, "(nitfol) " }, - { "path", '-', "Look for games in this directory", option_string, NULL, 0, NULL, NULL, code_path, NULL }, - { "autoundo", '-', "Ensure '@save_undo' is called every turn", option_flag, code_autoundo, 1, NULL, NULL, NULL, NULL }, - { "stacklimit", 'S', "Exit when the stack is this deep", option_number, code_stacklimit, 0, NULL, NULL, NULL, NULL }, - { "alias", 'a', "Specify an alias", option_string, NULL, 0, NULL, NULL, code_alias, NULL }, - { "ralias", '-', "Specify an recursive alias", option_string, NULL, 0, NULL, NULL, code_ralias, NULL }, - { "unalias", '-', "Remove an alias", option_string, NULL, 0, NULL, NULL, code_unalias, NULL }, - { "random", 'r', "Set random seed", option_number, code_random, 0, NULL, NULL, NULL, NULL }, - { "mapsym", '-', "Specify mapping glyphs", option_string, NULL, 0, NULL, NULL, code_mapsym, "*udb@UDB+" }, - { "mapsize", '-', "Specify map size", option_number, code_mapsize, 12, NULL, NULL, NULL, NULL }, - { "maploc", '-', "Specify map location", option_string, NULL, 0, NULL, NULL, code_maploc, "above" }, - { "terpnum", '-', "Specify interpreter number", option_number, code_terpnum, 2, NULL, NULL, NULL, NULL }, - { "terpver", '-', "Specify interpreter version", option_string, NULL, 0, NULL, NULL, code_terpver, "N" } -}; - -#line 811 "opt2glkc.pl" -static void set_defaults(void) -{ - unsigned n; - for(n = 0; n < sizeof(options) / sizeof(*options); n++) { - if(options[n].int_func) - options[n].int_func(options[n].defint); - if(options[n].str_func) - options[n].str_func(options[n].defstream); - if(options[n].string_func) - options[n].string_func(options[n].defstring); - } -} - -#line 910 "opt2glkc.pl" -static void show_help(void) -{ - unsigned n; - printf("Usage: nitfol [OPTIONS] gamefile\n"); - for(n = 0; n < sizeof(options) / sizeof(*options); n++) { - if(options[n].shortname != '-') - printf(" -%c, ", options[n].shortname); - else - printf(" "); - printf("-%-15s %s\n", options[n].longname, options[n].description); - } -} - -#line 928 "opt2glkc.pl" -static BOOL parse_commands(int argc, char **argv) -{ - int i; - unsigned n; - - for(i = 1; i < argc; i++) { - BOOL flag = TRUE; - - const char *p = argv[i]; - - if(p[0] == '-') { - BOOL found = FALSE; - - while(*p == '-') - p++; - if(n_strncmp(p, "no-", 3) == 0) { - flag = FALSE; - p+=3; - } - - if(n_strcasecmp(p, "help") == 0) { - show_help(); - exit(0); - } - if(n_strcasecmp(p, "version") == 0) { - printf("nitfol version %d.%d\n", NITFOL_MAJOR, NITFOL_MINOR); - exit(0); - } - - for(n = 0; n < sizeof(options) / sizeof(*options); n++) { - if((n_strlen(p) == 1 && *p == options[n].shortname) || - n_strcmp(options[n].longname, p) == 0) { - found = TRUE; - - switch(options[n].type) { - case option_flag: - options[n].int_func(flag); - break; - - case option_file: - i++; - options[n].str_func(startup_open(argv[i])); - break; - - case option_wfile: - i++; - options[n].str_func(startup_wopen(argv[i])); - break; - - case option_number: - i++; - options[n].int_func(n_strtol(argv[i], NULL, 0)); - break; - - case option_string: - i++; - options[n].string_func(argv[i]); - break; - } - } - } - - if(!found) - return FALSE; - - } else { - strid_t s = startup_open(argv[i]); - if(!s) - return FALSE; - if(!game_use_file(s)) - return FALSE; - } - } - - return TRUE; -} - -#line 504 "opt2glkc.pl" -void shift_string_left(char *str) -{ - int len = strlen(str); - int i; - for(i = 0; i < len; i++) - str[i] = str[i+1]; -} - -int winglk_startup_code(void) -{ - BOOL status; - char *commandline = strdup(GetCommandLine()); - char **argv = (char **) n_malloc(sizeof(char *) * strlen(commandline)); - int argc = 0; - - int i; - - while(*commandline) { - while(*commandline && isspace(*commandline)) - commandline++; - - argv[argc++] = commandline; - - while(*commandline && !isspace(*commandline)) { - if(*commandline == '"') { - shift_string_left(commandline); - while(*commandline && *commandline != '"') - commandline++; - shift_string_left(commandline); - } else { - commandline++; - } - } - - *commandline++ = 0; - } - - argv[argc] = NULL; - - status = parse_commands(argc, argv); - - n_free(argv); - n_free(commandline); - - winglk_app_set_name("nitfol"); - winglk_window_set_title("nitfol"); - set_defaults(); - - return status; -} diff --git a/interpreters/nitfol/z_io.c.orig b/interpreters/nitfol/z_io.c.orig deleted file mode 100644 index 631e7f0..0000000 --- a/interpreters/nitfol/z_io.c.orig +++ /dev/null @@ -1,1099 +0,0 @@ -/* Nitfol - z-machine interpreter using Glk for output. - Copyright (C) 1999 Evin Robertson - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. - - The author can be reached at nitfol@deja.com -*/ -#include "nitfol.h" - -#define UPPER_WINDOW 1 -#define LOWER_WINDOW 0 - -static zwinid lower_win, upper_win; -static zwinid current_window; - - -#define STREAM1 1 -#define STREAM2 2 -#define STREAM3 4 -#define STREAM4 8 - -static strid_t stream2, stream4; - -static int output_stream; -static zword stream3_table_starts[16]; -static zword stream3_table_locations[16]; -static int stream3_nesting_depth; - - -static int font = 1; - -static BOOL abort_output = FALSE; /* quickly stop outputting */ - - -BOOL is_transcripting(void) -{ - return (output_stream & STREAM2) != 0; -} - -void set_transcript(strid_t stream) -{ - if(stream) { - if(z_memory) { - zword flags2 = LOWORD(HD_FLAGS2) | b00000001; - LOWORDwrite(HD_FLAGS2, flags2); - } - stream2 = stream; - output_stream |= STREAM2; - if(lower_win) - z_set_transcript(lower_win, stream2); - } else { - if(z_memory) { - zword flags2 = LOWORD(HD_FLAGS2) & b11111110; - LOWORDwrite(HD_FLAGS2, flags2); - } - output_stream &= ~STREAM2; - if(lower_win) - z_set_transcript(lower_win, 0); - } -} - - -/* initialize the windowing environment */ -void init_windows(BOOL dofixed, glui32 maxwidth, glui32 maxheight) -{ - z_init_windows(dofixed, draw_upper_callback, upper_mouse_callback, - maxwidth, maxheight, &upper_win, &lower_win); - - current_window = lower_win; - output_stream = STREAM1 | (output_stream & STREAM2); - stream3_nesting_depth = 0; - font = 1; - - if(output_stream & STREAM2) { - set_transcript(stream2); - } else { - set_transcript(0); - } - - if(zversion == 6) { - v6_main_window_is(lower_win); - } -} - - -static int upper_roomname_length; - -static void counting_glk_put_char(int ch) -{ - upper_roomname_length++; - glk_put_char(ch); -} - -glui32 draw_upper_callback(winid_t win, glui32 width, glui32 height) -{ - glui32 curx = 0, cury = 0; - - glui32 numlines = 0; - - if(win == NULL || height == 0) { - if(zversion <= 3) - numlines++; - return numlines; - } - - if(zversion <= 3) { - zword location = get_var(16); - offset short_name_off = object_name(location); - - glk_window_move_cursor(win, 0, cury); - - if(location && short_name_off) { - glk_put_char(' '); curx++; - upper_roomname_length = 0; - decodezscii(short_name_off, counting_glk_put_char); - curx += upper_roomname_length; - } - - glk_window_move_cursor(win, width - 8, cury); - if((zversion <= 2) || ((LOBYTE(HD_FLAGS1) & 2) == 0)) { - if(width > curx + 26) { - glk_window_move_cursor(win, width - 24, cury); - w_glk_put_string("Score: "); - g_print_znumber(get_var(17)); - - glk_window_move_cursor(win, width - 12, cury); - w_glk_put_string("Moves: "); - g_print_znumber(get_var(18)); - } else { - g_print_znumber(get_var(17)); /* score */ - glk_put_char('/'); - g_print_znumber(get_var(18)); /* turns */ - } - } else { - const char *ampmstr[8] = { " AM", " PM" }; - int ampm = 0; - zword hours = get_var(17); - zword minutes = get_var(18); - while(hours >= 12) { - hours-=12; - ampm ^= 1; - } - if(hours == 0) - hours = 12; - if(hours < 10) - glk_put_char(' '); - g_print_number(hours); - glk_put_char(':'); - if(minutes < 10) - glk_put_char('0'); - g_print_number(minutes); - w_glk_put_string(ampmstr[ampm]); - } - numlines++; - cury++; - glk_window_move_cursor(win, 0, cury); - } - - return numlines; -} - -void output_string(const char *s) -{ - while(*s) - output_char(*s++); -} - -void output_char(int c) -{ - static int starlength = 0; - - if(output_stream & STREAM3) { /* Table output */ - zword num_chars = LOWORD(stream3_table_starts[stream3_nesting_depth-1]) +1; - if((c < 32 && c != 13) || (c >= 127 && c <= 159) || (c > 255)) - c = '?'; /* Section 7.5.3 */ - LOBYTEwrite(stream3_table_locations[stream3_nesting_depth-1], c); - stream3_table_locations[stream3_nesting_depth-1] += 1; - LOWORDwrite(stream3_table_starts[stream3_nesting_depth-1], num_chars); - } else { - if(output_stream & STREAM1) { /* Normal screen output */ - if(c >= 155 && c <= 251) { /* "extra characters" */ - zword game_unicode_table = header_extension_read(3); - if(game_unicode_table && LOBYTE(game_unicode_table) >= (zbyte) (c - 155)) { - zword address = game_unicode_table + 1 + (c - 155) * 2; - c = LOWORD(address); - } else { - const unsigned default_unicode_translation[] = { - 0xe4, 0xf6, 0xfc, 0xc4, 0xd6, 0xdc, 0xdf, 0xbb, - 0xab, 0xeb, 0xef, 0xff, 0xcb, 0xcf, 0xe1, 0xe9, - 0xed, 0xf3, 0xfa, 0xfd, 0xc1, 0xc9, 0xcd, 0xd3, - 0xda, 0xdd, 0xe0, 0xe8, 0xec, 0xf2, 0xf9, 0xc0, - 0xc8, 0xcc, 0xd2, 0xd9, 0xe2, 0xea, 0xee, 0xf4, - 0xfb, 0xc2, 0xca, 0xce, 0xd4, 0xdb, 0xe5, 0xc5, - 0xf8, 0xd8, 0xe3, 0xf1, 0xf5, 0xc3, 0xd1, 0xd5, - 0xe6, 0xc6, 0xe7, 0xc7, 0xfe, 0xf0, 0xde, 0xd0, - 0xa3, 0x153, 0x152, 0xa1, 0xbf - }; - c = default_unicode_translation[c - 155]; - } - } - if(c == '*') { - if(++starlength == 3) /* Three asterisks usually means win or death */ - if(automap_unexplore()) - abort_output = TRUE; - } else { - starlength = 0; - } - - if(font == 3) { - const char font3trans[] = - " <>/" "\\ --" "||||" "--\\/" /* 32-47 */ - "\\//\\/\\@ " " |" "|-- " /* 48-63 */ - " /" "\\/\\ " " " " " /* 64-79 */ - " " "####" " X+" "udb*" /* 80-95 */ - "?abc" "defg" "hijk" "lmno" /* 96-111 */ - "pqrs" "tuvw" "xyzU" "DB?"; /* 112-126 */ - if(c >= 32 && c <= 126) - c = font3trans[c - 32]; - } - - if(allow_output) - z_put_char(current_window, c); - } - } -} - -void n_print_number(unsigned n) -{ - int i; - char buffer[12]; - int length = n_to_decimal(buffer, n); - - for(i = length - 1; i >= 0; i--) - output_char(buffer[i]); -} - - -void g_print_number(unsigned n) -{ - int i; - char buffer[12]; - int length = n_to_decimal(buffer, n); - - for(i = length - 1; i >= 0; i--) - glk_put_char(buffer[i]); -} - -void g_print_snumber(int n) -{ - if(n < 0) { - glk_put_char('-'); - n = -n; - } - g_print_number(n); -} - -void g_print_znumber(zword n) -{ - if(is_neg(n)) { - glk_put_char('-'); - g_print_number(neg(n)); - } else { - g_print_number(n); - } -} - -void n_print_znumber(zword n) -{ - if(is_neg(n)) { - output_char('-'); - n_print_number(neg(n)); - } else { - n_print_number(n); - } -} - - -void stream4number(unsigned c) -{ - if(output_stream & STREAM4) { - glk_stream_set_current(stream4); - glk_put_char('['); - g_print_number(c); - glk_put_char(']'); - glk_put_char(10); - } -} - - -void op_buffer_mode(void) -{ - /* FIXME: Glk can't really do this. - * I could rely on the Plotkin Bug to do it, but that's ugly and would - * break 20 years from now when somebody fixes it. I could also print - * spaces between each letter, which isn't the intended effect - * - * For now, do nothing. Doubt this opcode is used often anyway... - */ -} - - -void op_check_unicode(void) -{ - unsigned result = 0; - if(operand[0] <= 255 && - (glk_gestalt(gestalt_CharOutput, (unsigned char) operand[0]) != - gestalt_CharOutput_CannotPrint)) - result |= 1; - if(operand[0] <= 255 && - (glk_gestalt(gestalt_LineInput, (unsigned char) operand[0]) != - FALSE)) - result |= 2; - mop_store_result(result); -} - - -void op_erase_line(void) -{ - if(!allow_output) - return; - - if(operand[0] == 1 && current_window == upper_win) { - z_erase_line(current_window); - } -} - - -void op_erase_window(void) -{ - if(!allow_output) - return; - -#ifdef DEBUG_IO - n_show_debug(E_OUTPUT, "erase_window", operand[0]); - return; -#endif - - switch(operand[0]) { - case neg(1): - operand[0] = 0; op_split_window(); - current_window = lower_win; - case neg(2): - case UPPER_WINDOW: - z_clear_window(upper_win); - if(operand[0] == UPPER_WINDOW) break; /* Ok, this is evil, but it works. */ - case LOWER_WINDOW: - z_clear_window(lower_win); - break; - } -} - - -void op_get_cursor(void) -{ - zword x, y; - z_getxy(upper_win, &x, &y); - LOWORDwrite(operand[0], x); - LOWORDwrite(operand[0] + ZWORD_SIZE, y); -} - - -void op_new_line(void) -{ - output_char(13); -} - - -void op_output_stream(void) -{ - if(operand[0] == 0) - return; - if(is_neg(operand[0])) { - switch(neg(operand[0])) { - case 1: - if(!allow_output) - return; - output_stream &= ~STREAM1; - break; - - case 2: - if(!allow_output) - return; - set_transcript(0); - break; - - case 3: - if(stream3_nesting_depth) - stream3_nesting_depth--; - else - n_show_error(E_OUTPUT, "stream3 unnested too many times", 0); - if(!stream3_nesting_depth) - output_stream &= ~STREAM3; - break; - - case 4: - if(!allow_output) - return; - glk_stream_close(stream4, NULL); - stream4 = 0; - output_stream &= ~STREAM4; - break; - - default: - n_show_error(E_OUTPUT, "unknown stream deselected", neg(operand[0])); - } - } else { - switch(operand[0]) { - case 1: - if(!allow_output) - return; - output_stream |= STREAM1; - break; - - case 2: - if(!allow_output) - return; - if(!stream2) { - stream2 = n_file_prompt(fileusage_Transcript | fileusage_TextMode, - filemode_WriteAppend); - } - if(stream2) - set_transcript(stream2); - break; - - case 3: - if(stream3_nesting_depth >= 16) { - n_show_error(E_OUTPUT, "nesting stream 3 too deeply", - stream3_nesting_depth); - return; - } - LOWORDwrite(operand[1], 0); - stream3_table_starts[stream3_nesting_depth] = operand[1]; - stream3_table_locations[stream3_nesting_depth] = operand[1] + 2; - - output_stream |= STREAM3; - stream3_nesting_depth++; - break; - - case 4: - if(!allow_output) - return; - stream4 = n_file_prompt(fileusage_InputRecord | fileusage_TextMode, - filemode_WriteAppend); - if(stream4) - output_stream |= STREAM4; - break; - default: - n_show_error(E_OUTPUT, "unknown stream selected", operand[0]); - } - } -} - - -void op_print(void) -{ - int length; - abort_output = FALSE; - length = decodezscii(PC, output_char); - if(!abort_output) - PC += length; -} - - -void op_print_ret(void) -{ - int length; - abort_output = FALSE; - length = decodezscii(PC, output_char); - if(abort_output) - return; - PC += length; - output_char(13); - if(abort_output) - return; - mop_func_return(1); -} - - -void op_print_addr(void) -{ - decodezscii(operand[0], output_char); -} - - -void op_print_paddr(void) -{ - getstring(operand[0]); -} - - -void op_print_char(void) -{ - if(operand[0] > 1023) { - n_show_error(E_INSTR, "attempt to print character > 1023", operand[0]); - return; - } - output_char(operand[0]); -} - - -void op_print_num(void) -{ - n_print_znumber(operand[0]); -} - - -void op_print_table(void) -{ - unsigned x, y; - zword text = operand[0]; - zword width = operand[1]; - zword height = operand[2]; - zword skips = operand[3]; - - zword startx, starty; - unsigned win_width, win_height; - - z_getxy(current_window, &startx, &starty); - z_getsize(current_window, &win_width, &win_height); - - if(numoperands < 4) - skips = 0; - if(numoperands < 3) - height = 1; - - if(current_window == upper_win) { - if(startx + width - 1 > win_width) { - int diff; - n_show_warn(E_OUTPUT, "table too wide; trimming", width); - diff = startx + width - 1 - win_width; - width -= diff; - skips += diff; - } - if(starty + height - 1 > win_height) { - n_show_warn(E_OUTPUT, "table too tall; trimming", height); - height = win_height - starty + 1; - } - } - - for(y = 0; y < height; y++) { - if(current_window == upper_win && allow_output) - z_setxy(upper_win, startx, y+starty); - - for(x = 0; x < width; x++) { - output_char(LOBYTE(text)); - text++; - } - text += skips; - - if(current_window != upper_win && y+1 < height) - output_char(13); - } -} - - -void op_set_colour(void) -{ - if(!allow_output) - return; - - z_set_color(current_window, operand[0], operand[1]); -} - - -void op_set_cursor(void) -{ - unsigned width, height; - zword x = operand[1]; - zword y = operand[0]; - - if(!allow_output) - return; - -#ifdef DEBUG_IO - n_show_debug(E_OUTPUT, "set_cursor y=", operand[0]); - n_show_debug(E_OUTPUT, "set_cursor x=", operand[1]); -#endif - - if(current_window != upper_win) { - return; - } - - z_getsize(current_window, &width, &height); - - if(y == 0 || y > height) { /* section 8.7.2.3 */ - n_show_error(E_OUTPUT, "illegal line for set_cursor", y); - if(y == 0 || y > 512) - return; - z_set_height(upper_win, y); /* Resize to allow broken games to work */ - } - if(x == 0 || x > width) { - n_show_error(E_OUTPUT, "illegal column for set_cursor", x); - return; - } - - z_setxy(current_window, x, y); -} - - -void op_set_text_style(void) -{ - if(!allow_output) - return; - - z_set_style(current_window, operand[0]); -} - - -void op_set_window(void) -{ - if(!allow_output) - return; - -#ifdef DEBUG_IO - n_show_debug(E_OUTPUT, "set_window", operand[0]); - return; -#endif - - switch(operand[0]) { - case UPPER_WINDOW: - current_window = upper_win; - z_setxy(upper_win, 1, 1); - break; - case LOWER_WINDOW: - current_window = lower_win; - break; - default: - n_show_error(E_OUTPUT, "invalid window selected", operand[0]); - } -} - - -void op_split_window(void) -{ - if(!allow_output) - return; - -#ifdef DEBUG_IO - n_show_debug(E_OUTPUT, "split_window", operand[0]); -#endif - - if(zversion == 6) - return; - - - if(operand[0] > 512) { - n_show_error(E_OUTPUT, "game is being ridiculous", operand[0]); - return; - } - - if(zversion == 3) - z_set_height(upper_win, 0); /* clear the whole upper window first */ - - z_set_height(upper_win, operand[0]); -} - - -static BOOL timer_callback(zword routine) -{ - zword dummylocals[16]; - in_timer = TRUE; - mop_call(routine, 0, dummylocals, -2); /* add a special stack frame */ - decode(); /* start interpreting the routine */ - in_timer = FALSE; - exit_decoder = FALSE; - return time_ret; -} - - -BOOL upper_mouse_callback(BOOL is_char_event, winid_t win, glui32 x, glui32 y) -{ - int i; - - if(!(LOBYTE(HD_FLAGS2) & b00100000)) - return FALSE; - - header_extension_write(1, x + 1); - header_extension_write(2, y + 1); - - stream4number(254); - stream4number(x + 1); - stream4number(y + 1); - - if(is_char_event) - return TRUE; - - for(i = z_terminators; LOBYTE(i) != 0; i++) - if(LOBYTE(i) == 255 || LOBYTE(i) == 254) - return TRUE; - - /* @read will not receive mouse input inputs if they're not - * terminating characters, but I'm not sure how to reasonably do - * that and it shouldn't matter to most things */ - - return FALSE; -} - - -typedef struct alias_entry alias_entry; - -struct alias_entry -{ - alias_entry *next; - char *from; - char *to; - BOOL in_use, is_recursive; -}; - -static alias_entry *alias_list = NULL; - - -void parse_new_alias(const char *aliascommand, BOOL is_recursive) -{ - char *from, *to; - char *stringcopy = n_strdup(aliascommand); - char *pcommand = stringcopy; - while(isspace(*pcommand)) - pcommand++; - from = pcommand; - while(isgraph(*pcommand)) - pcommand++; - if(*pcommand) { - *pcommand = 0; - pcommand++; - } - while(isspace(*pcommand)) - pcommand++; - to = pcommand; - - while(*to == ' ') - to++; - - if(*to == 0) /* Expand blank aliases to a single space */ - add_alias(from, " ", is_recursive); - else - add_alias(from, to, is_recursive); - free(stringcopy); -} - -void add_alias(const char *from, const char *to, BOOL is_recursive) -{ - alias_entry newalias; - remove_alias(from); - newalias.next = NULL; - newalias.from = n_strdup(from); - newalias.to = n_strdup(to); - newalias.in_use = FALSE; - newalias.is_recursive = is_recursive; - LEadd(alias_list, newalias); -} - - -BOOL remove_alias(const char *from) -{ - alias_entry *p, *t; - while(*from == ' ') - from++; - LEsearchremove(alias_list, p, t, n_strcmp(p->from, from) == 0, (n_free(p->from), n_free(p->to))); - return t != NULL; -} - - -static alias_entry *find_alias(const char *text, int length) -{ - alias_entry *p; - LEsearch(alias_list, p, n_strmatch(p->from, text, length)); - return p; -} - - -int search_for_aliases(char *text, int length, int maxlen) -{ - int word_start = 0; - int i; - if(!length) - return length; - for(i = 0; i <= length; i++) { - if(i == length || isspace(text[i]) || ispunct(text[i])) { - int word_length = i - word_start; - if(word_length) { - alias_entry *p = find_alias(text + word_start, word_length); - if(p && !(p->in_use)) { - int newlen = strlen(p->to); - if(length - word_length + newlen > maxlen) - newlen = maxlen - length + word_length; - n_memmove(text + word_start + newlen, - text + word_start + word_length, - maxlen - word_start - MAX(newlen, word_length)); - n_memcpy(text + word_start, p->to, newlen); - - if(p->is_recursive) { - p->in_use = TRUE; - newlen = search_for_aliases(text + word_start, newlen, maxlen - word_start); - p->in_use = FALSE; - } - - length += newlen - word_length; - i = word_start + newlen; - } - } - word_start = i+1; - } - } - return length; -} - - -int n_read(zword dest, unsigned maxlen, zword parse, unsigned initlen, - zword timer, zword routine, unsigned char *terminator) -{ - unsigned length; - unsigned i; - char *buffer = (char *) n_malloc(maxlen + 1); - -#ifdef SMART_TOKENISER - forget_corrections(); -#endif - - if(false_undo) - initlen = 0; - false_undo = FALSE; - - if(maxlen < 3) - n_show_warn(E_OUTPUT, "small text buffer", maxlen); - - if(dest > dynamic_size || dest < 64) { - n_show_error(E_OUTPUT, "input buffer in invalid location", dest); - return 0; - } - - if(dest + maxlen > dynamic_size) { - n_show_error(E_OUTPUT, "input buffer exceeds dynamic memory", dest + maxlen); - maxlen = dynamic_size - dest; - } - - if(parse >= dest && dest + maxlen > parse) { - n_show_warn(E_OUTPUT, "input buffer overlaps parse", dest + maxlen - parse); - maxlen = parse - dest; - } - - for(i = 0; i < maxlen; i++) - buffer[i] = LOBYTE(dest + i); - - length = z_read(current_window, buffer, maxlen, initlen, timer, timer_callback, routine, terminator); - - if(read_abort) { - n_free(buffer); - return 0; - } - - length = search_for_aliases(buffer, length, maxlen); - - for(i = 0; i < length; i++) { - buffer[i] = glk_char_to_lower(buffer[i]); - LOBYTEwrite(dest + i, buffer[i]); - } - - if(parse) - z_tokenise(buffer, length, parse, z_dictionary, TRUE); - - n_free(buffer); - return length; -} - - -void stream4line(const char *buffer, int length, char terminator) -{ - if(output_stream & STREAM4) { - w_glk_put_buffer_stream(stream4, buffer, length); - if(terminator != 10) - stream4number(terminator); - glk_put_char_stream(stream4, 10); - } -} - - -void op_sread(void) -{ - unsigned maxlen, length; - unsigned char term; - zword text = operand[0]; - - maxlen = LOBYTE(text) - 1; - if(numoperands < 3) - operand[2] = 0; - if(numoperands < 4) - operand[3] = 0; - - length = n_read(text + 1, maxlen, operand[1], 0, - operand[2], operand[3], &term); - if(!read_abort) { - LOBYTEwrite(text + 1 + length, 0); /* zero terminator */ - - if(allow_saveundo) { - if(!has_done_save_undo && auto_save_undo) - saveundo(FALSE); - has_done_save_undo = FALSE; - } - } -} - -void op_aread(void) -{ - int maxlen, length, initlen; - unsigned char term; - zword text = operand[0]; - - maxlen = LOBYTE(text); - initlen = LOBYTE(text + 1); - if(numoperands < 3) - operand[2] = 0; - if(numoperands < 4) - operand[3] = 0; - - length = n_read(text + 2, maxlen, operand[1], initlen, - operand[2], operand[3], &term); - if(!read_abort) { - LOBYTEwrite(text + 1, length); - mop_store_result(term); - - if(allow_saveundo) { - if(!has_done_save_undo && auto_save_undo) - saveundo(FALSE); - has_done_save_undo = FALSE; - } - } -} - -void op_read_char(void) -{ - zword validch = 0; - - if(in_timer) { - n_show_error(E_OUTPUT, "input attempted during time routine", 0); - mop_store_result(0); - return; - } - - if(operand[0] != 1) { - n_show_warn(E_OUTPUT, "read_char with non-one first operand", operand[0]); - mop_store_result(0); - return; - } - - if(numoperands < 2) - operand[1] = 0; - if(numoperands < 3) - operand[2] = 0; - - validch = z_read_char(current_window, operand[1], timer_callback, operand[2]); - - if(read_abort) - return; - - mop_store_result(validch); - - /* - if(!has_done_save_undo && auto_save_undo_char) { - saveundo(FALSE); - has_done_save_undo = FALSE; - } - */ - - stream4number(validch); -} - - -void op_show_status(void) -{ - if(!in_timer) - z_flush_fixed(upper_win); -} - -/* Returns a character, or returns 0 if it found a number, which it stores - in *num */ -unsigned char transcript_getchar(unsigned *num) -{ - glsi32 c; - *num = 0; - if(!input_stream1) - return 0; - - c = glk_get_char_stream(input_stream1); - - if(c == GLK_EOF) { - glk_stream_close(input_stream1, NULL); - input_stream1 = 0; - return 0; - } - - if(c == '[') { - while((c = glk_get_char_stream(input_stream1)) != GLK_EOF) { - if(c == ']') - break; - if(c >= '0' && c <= '9') { - *num = (*num * 10) + (c - '0'); - } - } - c = glk_get_char_stream(input_stream1); - if(c != 10) - n_show_error(E_OUTPUT, "input script not understood", c); - - return 0; - } - return c; -} - -/* Returns line terminator. Writes up to *len bytes to dest, writing in the - actual number of characters read in *len. */ -unsigned char transcript_getline(char *dest, glui32 *length) -{ - unsigned char term = 10; - unsigned char c; - unsigned num; - glui32 len; - if(!input_stream1) { - *length = 0; - return 0; - } - for(len = 0; len < *length; len++) { - c = transcript_getchar(&num); - if(!c) { - term = num; - break; - } - if(c == 10) - break; - - dest[len] = c; - } - *length = len; - return term; -} - - -void op_input_stream(void) -{ - /* *FIXME*: 10.2.4 says we shouldn't wait for [MORE]. Glk won't allow this */ - if(input_stream1) - glk_stream_close(input_stream1, NULL); - input_stream1 = 0; - - switch(operand[0]) { - case 0: - break; - case 1: - input_stream1 = n_file_prompt(fileusage_InputRecord | fileusage_TextMode, - filemode_Read); - break; - default: - n_show_error(E_OUTPUT, "unknown input stream selected", operand[0]); - } -} - - -void op_set_font(void) -{ - int lastfont; - - if(!allow_output) { - mop_store_result(0); - return; - } - - lastfont = font; - -#ifdef DEBUG_IO - n_show_debug(E_OUTPUT, "set_font", operand[0]); - return; -#endif - - switch(operand[0]) { - case 1: font = 1; break; - case 4: font = 4; break; - case 3: if(enablefont3) font = 3; - default: mop_store_result(0); return; - } - set_fixed(font == 4); - - mop_store_result(lastfont); -} - - -void op_print_unicode(void) -{ - output_char(operand[0]); -}