int glkunix_startup_code(glkunix_startup_t *data) { int i = 1; if (data->argc > 1 && strcmp (data->argv[i], "-w") == 0) { use_inputwindow = 1; i++; } #ifdef GARGLK garglk_set_program_name("Geas 0.4"); garglk_set_program_info( "Geas 0.4 by Mark Tilford and David Jones.\n" "Additional Glk support by Simon Baldwin."); #endif if (i == data->argc - 1) { storyfilename = data->argv[i]; #ifdef GARGLK char *s = strrchr(storyfilename, '/'); if (!s) s = strrchr(storyfilename, '\\'); garglk_set_story_name(s ? s + 1 : storyfilename); #endif } return 1; }
/* * Invoke the tads 2 main entrypoint with the given command-line arguments */ static int main_t2(int argc, char **argv) { int stat; #ifdef GARGLK garglk_set_program_name("TADS " TADS_RUNTIME_VERSION); char *s; s = strrchr(argv[1], '/'); if (!s) s = strrchr(argv[1], '\\'); garglk_set_story_name(s ? s + 1 : argv[1]); #endif /* initialize the OS layer */ os_init(&argc, argv, 0, 0, 0); /* install the break handler */ os_instbrk(1); /* invoke the tads 2 main entrypoint */ stat = os0main2(argc, argv, trdmain, "", 0, 0); /* done with the break handler */ os_instbrk(0); /* uninitialize the OS layer */ os_uninit(); /* return the status */ return stat; }
strid_t startup_open(const char *name) { strid_t str; char *s; str = glkunix_stream_open_pathname((char *) name, fileusage_Data | fileusage_BinaryMode, 0); if(str) { set_game_filename(name); #ifdef USE_GARGLK_FEATURES s = strrchr(name, '\\'); if (!s) s = strrchr(name, '/'); garglk_set_story_name(s ? s + 1 : name); #endif } 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); #ifdef USE_GARGLK_FEATURES s = strrchr(newname, '\\'); if (!s) s = strrchr(newname, '/'); garglk_set_story_name(s ? s + 1 : newname); #endif break; } } n_free(path); } } if(!str) fprintf(stderr, "Cannot open '%s'\n", name); return str; }
/* * Invoke the T3 VM with the given command-line arguments */ static int main_t3(int argc, char **argv) { CVmMainClientConsole clientifc; int stat; CVmHostIfc *hostifc = new CVmHostIfcStdio(argv[0]); #ifdef GARGLK garglk_set_program_name("TADS " T3VM_VSN_STRING); char *s; s = strrchr(argv[1], '/'); if (!s) s = strrchr(argv[1], '\\'); garglk_set_story_name(s ? s + 1 : argv[1]); #endif /* * Initialize the OS layer. Since this is a command-line-only * implementation, there's no need to ask the OS layer to try to get * us a filename to run, so pass in null for the prompt and filename * buffer. */ os_init(&argc, argv, 0, 0, 0); /* invoke the basic entrypoint */ stat = vm_run_image_main(&clientifc, "t3run", argc, argv, TRUE, FALSE, hostifc); /* uninitialize the OS layer */ os_uninit(); /* done with the host interface */ delete hostifc; /* show any unfreed memory */ t3_list_memory_blocks(0); /* exit with status code */ os_term(stat); /* we shouldn't get here, but in case os_term doesn't really exit... */ return stat; }
int glkunix_startup_code(glkunix_startup_t *data) { int argc = data->argc; char **argv = data->argv; if(argc < 1) return 0; while(argv[1]) { if(*argv[1]!='-') break; switch(argv[1][1]) { case 'y': Options|=YOUARE; break; case 'i': Options&=~YOUARE; break; case 'd': Options|=DEBUGGING; break; case 's': Options|=SCOTTLIGHT; break; case 't': Options|=TRS80_STYLE; break; case 'p': Options|=PREHISTORIC_LAMP; break; case 'w': split_screen = 0; break; } argv++; argc--; } #ifdef GARGLK garglk_set_program_name("ScottFree 1.14"); garglk_set_program_info( "ScottFree 1.14 by Alan Cox\n" "Glk port by Chris Spiegel\n"); #endif if(argc==2) { game_file = argv[1]; #ifdef GARGLK const char *s; if((s = strrchr(game_file, '/')) != NULL || (s = strrchr(game_file, '\\')) != NULL) { garglk_set_story_name(s + 1); } else { garglk_set_story_name(game_file); } #endif } return 1; }
int glkunix_startup_code(glkunix_startup_t *data) { /* It turns out to be more convenient if we return TRUE from here, even when an error occurs, and display an error in glk_main(). */ int ix; char *filename = NULL; char *gameinfofilename = NULL; int gameinfoloaded = FALSE; unsigned char buf[12]; int res; #ifdef GARGLK char *cx; #endif #ifdef GARGLK garglk_set_program_name("Glulxe 0.5.2"); garglk_set_program_info("Glulxe 0.5.2 by Andrew Plotkin"); #endif /* Parse out the arguments. They've already been checked for validity, and the library-specific ones stripped out. As usual for Unix, the zeroth argument is the executable name. */ for (ix=1; ix<data->argc; ix++) { #if VM_PROFILING if (!strcmp(data->argv[ix], "--profile")) { ix++; if (ix<data->argc) { strid_t profstr = glkunix_stream_open_pathname_gen(data->argv[ix], TRUE, FALSE, 1); if (!profstr) { init_err = "Unable to open profile output file."; init_err2 = data->argv[ix]; return TRUE; } setup_profile(profstr, NULL); } continue; } if (!strcmp(data->argv[ix], "--profcalls")) { profile_set_call_counts(TRUE); continue; } #endif /* VM_PROFILING */ #if VM_DEBUGGER if (!strcmp(data->argv[ix], "--gameinfo")) { ix++; if (ix<data->argc) { gameinfofilename = data->argv[ix]; } continue; } if (!strcmp(data->argv[ix], "--cpu")) { debugger_track_cpu(TRUE); continue; } if (!strcmp(data->argv[ix], "--starttrap")) { debugger_set_start_trap(TRUE); continue; } if (!strcmp(data->argv[ix], "--quittrap")) { debugger_set_quit_trap(TRUE); continue; } if (!strcmp(data->argv[ix], "--crashtrap")) { debugger_set_crash_trap(TRUE); continue; } #endif /* VM_DEBUGGER */ if (filename) { init_err = "You must supply exactly one game file."; return TRUE; } filename = data->argv[ix]; } if (!filename) { init_err = "You must supply the name of a game file."; return TRUE; } gamefile = glkunix_stream_open_pathname(filename, FALSE, 1); if (!gamefile) { init_err = "The game file could not be opened."; init_err2 = filename; return TRUE; } #ifdef GARGLK cx = strrchr(data->argv[1], '/'); if (!cx) cx = strrchr(data->argv[1], '\\'); garglk_set_story_name(cx ? cx + 1 : data->argv[1]); #endif #if VM_DEBUGGER if (gameinfofilename) { strid_t debugstr = glkunix_stream_open_pathname_gen(gameinfofilename, FALSE, FALSE, 1); if (!debugstr) { nonfatal_warning("Unable to open gameinfo file for debug data."); } else { int bres = debugger_load_info_stream(debugstr); glk_stream_close(debugstr, NULL); if (!bres) nonfatal_warning("Unable to parse game info."); else gameinfoloaded = TRUE; } } /* Report debugging available, whether a game info file is loaded or not. */ gidebug_debugging_available(debugger_cmd_handler, debugger_cycle_handler); #endif /* VM_DEBUGGER */ /* Now we have to check to see if it's a Blorb file. */ glk_stream_set_position(gamefile, 0, seekmode_Start); res = glk_get_buffer_stream(gamefile, (char *)buf, 12); if (!res) { init_err = "The data in this stand-alone game is too short to read."; return TRUE; } if (buf[0] == 'G' && buf[1] == 'l' && buf[2] == 'u' && buf[3] == 'l') { /* Load game directly from file. */ locate_gamefile(FALSE); return TRUE; } else if (buf[0] == 'F' && buf[1] == 'O' && buf[2] == 'R' && buf[3] == 'M' && buf[8] == 'I' && buf[9] == 'F' && buf[10] == 'R' && buf[11] == 'S') { /* Load game from a chunk in the Blorb file. */ locate_gamefile(TRUE); #if VM_DEBUGGER /* Load the debug info from the Blorb, if it wasn't loaded from a file. */ if (!gameinfoloaded) { glui32 giblorb_ID_Dbug = giblorb_make_id('D', 'b', 'u', 'g'); giblorb_err_t err; giblorb_result_t blorbres; err = giblorb_load_chunk_by_type(giblorb_get_resource_map(), giblorb_method_FilePos, &blorbres, giblorb_ID_Dbug, 0); if (!err) { int bres = debugger_load_info_chunk(gamefile, blorbres.data.startpos, blorbres.length); if (!bres) nonfatal_warning("Unable to parse game info."); else gameinfoloaded = TRUE; } } #endif /* VM_DEBUGGER */ return TRUE; } else { init_err = "This is neither a Glulx game file nor a Blorb file " "which contains one."; return TRUE; } }
int glkunix_startup_code(glkunix_startup_t *data) { /* It turns out to be more convenient if we return TRUE from here, even when an error occurs, and display an error in glk_main(). */ int ix; char *filename = NULL; unsigned char buf[12]; int res; #ifdef GARGLK char *cx; #endif #ifdef GARGLK garglk_set_program_name("Glulxe 0.5.2"); garglk_set_program_info("Glulxe 0.5.2 by Andrew Plotkin"); #endif /* Parse out the arguments. They've already been checked for validity, and the library-specific ones stripped out. As usual for Unix, the zeroth argument is the executable name. */ for (ix=1; ix<data->argc; ix++) { #if VM_PROFILING if (!strcmp(data->argv[ix], "--profile")) { ix++; if (ix<data->argc) { strid_t profstr = glkunix_stream_open_pathname_gen(data->argv[ix], TRUE, FALSE, 1); if (!profstr) { init_err = "Unable to open profile output file."; init_err2 = data->argv[ix]; return TRUE; } setup_profile(profstr, NULL); } continue; } #endif /* VM_PROFILING */ if (filename) { init_err = "You must supply exactly one game file."; return TRUE; } filename = data->argv[ix]; } if (!filename) { init_err = "You must supply the name of a game file."; return TRUE; } gamefile = glkunix_stream_open_pathname(filename, FALSE, 1); if (!gamefile) { init_err = "The game file could not be opened."; init_err2 = filename; return TRUE; } #ifdef GARGLK cx = strrchr(data->argv[1], '/'); if (!cx) cx = strrchr(data->argv[1], '\\'); garglk_set_story_name(cx ? cx + 1 : data->argv[1]); #endif /* Now we have to check to see if it's a Blorb file. */ glk_stream_set_position(gamefile, 0, seekmode_Start); res = glk_get_buffer_stream(gamefile, (char *)buf, 12); if (!res) { init_err = "The data in this stand-alone game is too short to read."; return TRUE; } if (buf[0] == 'G' && buf[1] == 'l' && buf[2] == 'u' && buf[3] == 'l') { locate_gamefile(FALSE); return TRUE; } else if (buf[0] == 'F' && buf[1] == 'O' && buf[2] == 'R' && buf[3] == 'M' && buf[8] == 'I' && buf[9] == 'F' && buf[10] == 'R' && buf[11] == 'S') { locate_gamefile(TRUE); return TRUE; } else { init_err = "This is neither a Glulx game file nor a Blorb file " "which contains one."; return TRUE; } }
void os_process_arguments(int argc, char *argv[]) { int c; #ifdef GARGLK garglk_set_program_name("Frotz " VERSION); garglk_set_program_info( "Glk Frotz " VERSION "\n" "Original Frotz by Stefan Jokisch\n" "Unix port by Jim Dunleavy and David Griffith\n" "Glk port by Tor Andersson\n"); #endif /* Parse the options */ do { c = zgetopt(argc, argv, "aAioOPQs:S:tu:xZ:"); switch (c) { case 'a': option_attribute_assignment = 1; break; case 'A': option_attribute_testing = 1; break; case 'i': option_ignore_errors = 1; break; case 'o': option_object_movement = 1; break; case 'O': option_object_locating = 1; break; case 'P': option_piracy = 1; break; case 'Q': option_save_quetzal = 0; break; case 's': user_random_seed = atoi(zoptarg); break; case 'S': option_script_cols = atoi(zoptarg); break; case 't': user_tandy_bit = 1; break; case 'u': option_undo_slots = atoi(zoptarg); break; case 'x': option_expand_abbreviations = 1; break; case 'Z': option_err_report_mode = atoi(zoptarg); if ((option_err_report_mode < ERR_REPORT_NEVER) || (option_err_report_mode > ERR_REPORT_FATAL)) option_err_report_mode = ERR_DEFAULT_REPORT_MODE; break; } } while (c != EOF); if (((argc - zoptind) != 1) && ((argc - zoptind) != 2)) { winid_t win; char buf[256]; win = glk_window_open(0, 0, 0, wintype_TextBuffer, 0); glk_set_window(win); glk_put_string("FROTZ V" VERSION " -- Glk 0.7.0 interface.\n"); glk_put_string(INFORMATION); sprintf(buf, " -Z # error checking mode (default = %d)\n" " %d = don't report errors. " "%d = report first error.\n" " %d = report all errors. " "%d = exit after any error.\n", ERR_DEFAULT_REPORT_MODE, ERR_REPORT_NEVER, ERR_REPORT_ONCE, ERR_REPORT_ALWAYS, ERR_REPORT_FATAL); glk_put_string(buf); glk_exit(); } else { char *s; story_name = argv[zoptind++]; if (zoptind < argc) graphics_filename = argv[zoptind++]; #ifdef GARGLK s = strrchr(story_name, '\\'); if (!s) s = strrchr(story_name, '/'); garglk_set_story_name(s ? s + 1 : story_name); #endif } }
/* db_init - read and decode the data file header */ void db_init(strid_t realfd) { int woff,ooff,aoff,voff,n; /* open the data file */ datafd = realfd; // glk_stream_open_file(name, filemode_Read, 0); // if (datafd == NULL) // error("can't open data file"); /* read the header */ if (glk_get_buffer_stream(datafd,hdr,HDR_SIZE) != HDR_SIZE) error("bad data file"); complement(hdr,HDR_SIZE); base = hdr; /* check the magic information */ if (strncmp(&hdr[HDR_MAGIC],"ADVSYS",6) != 0) error("not an adventure data file"); /* check the version number */ if ((n = getword(HDR_VERSION)) < 101 || n > VERSION) error("wrong version number"); /* decode the resident data length header field */ length = getword(HDR_LENGTH); /* allocate space for the resident data structure */ if ((data = malloc(length)) == 0) error("insufficient memory"); /* compute the offset to the data */ saveoff = (long)getword(HDR_DATBLK) * 512L; /* read the resident data structure */ glk_stream_set_position(datafd,saveoff,seekmode_Start); if (glk_get_buffer_stream(datafd,data,length) != length) error("bad data file"); complement(data,length); /* get the table base addresses */ wtable = data + (woff = getword(HDR_WTABLE)); wtypes = data + getword(HDR_WTYPES) - 1; otable = data + (ooff = getword(HDR_OTABLE)); atable = data + (aoff = getword(HDR_ATABLE)); vtable = data + (voff = getword(HDR_VTABLE)); /* get the save data area */ saveoff += (long)getword(HDR_SAVE); save = data + getword(HDR_SAVE); slen = getword(HDR_SLEN); /* get the base of the data and code spaces */ dbase = data + getword(HDR_DBASE); cbase = data + getword(HDR_CBASE); /* initialize the message routines */ msg_init(datafd,getword(HDR_MSGBLK)); /* get the code pointers */ h_init = getword(HDR_INIT); h_update = getword(HDR_UPDATE); h_before = getword(HDR_BEFORE); h_after = getword(HDR_AFTER); h_error = getword(HDR_ERROR); /* get the table lengths */ base = data; wcount = getword(woff); ocount = getword(ooff); acount = getword(aoff); vcount = getword(voff); /* setup the base of the resident data */ base = dbase; /* set the object count */ setvalue(V_OCOUNT,ocount); /* CHANGED FOR GLK */ #ifdef GARGLK garglk_set_story_name(&hdr[HDR_ANAME]); #endif #ifdef WINDOWS { int i; char *buf; i = strlen(&hdr[HDR_ANAME]); i += 1; i += strlen("GLK AdvSys - "); buf = malloc( sizeof(char) * i ); wsprintf(buf, "GLK AdvSys - %s", &hdr[HDR_ANAME]); winglk_window_set_title(buf); } #endif }