Exemple #1
0
void TADS2::runGame() {
	errcxdef errctx;
	errctx.errcxlgc = &errctx;
	errctx.errcxfp = nullptr;
	errctx.errcxofs = 0;
	errctx.errcxappctx = this;

	/* copyright-date-string */
#ifdef T2_COPYRIGHT_NOTICE
	trdptf("%s - A %s TADS %s Interpreter.\n",
		G_tads_oem_app_name, G_tads_oem_display_mode,
		TADS_RUNTIME_VERSION);
	trdptf("%sopyright (c) 1993, 2012 by Michael J. Roberts.\n",
		G_tads_oem_copyright_prefix ? "TADS c" : "C");
	trdptf("%s\n", G_tads_oem_author);
#endif

	trdmain1(&errctx);

	// pause before exiting if the OS desires it
	os_expause();
}
Exemple #2
0
void glk_main(void)
{
    int stat;
    static const char *defexts[] = { "gam", "t3" };
    char prog_arg[OSFNMAX];
    char fname[OSFNMAX];
    int engine_ver;

    int argc = tads_argc;
    char **argv = tads_argv;

    winid_t mainwin;
    char buf[256];
    char copyright[512];
    char errorload[512];

#ifdef GARGLK
    garglk_set_program_name("TADS " TADS_RUNTIME_VERSION " / " T3VM_VSN_STRING);
    garglk_set_program_info(
                "TADS Interpreter by Michael J. Roberts\n"
                "TADS 2 VM version " TADS_RUNTIME_VERSION "\n"
                "T3 VM version " T3VM_VSN_STRING "\n"
                "Gargoyle port by Tor Andersson\n"
    );
#endif

    /* 
     *   if one of our special usage message arguments was given, show the
     *   usage 
     */
    if (argc == 2 && stricmp(argv[1], "-help2") == 0)
    {
        /* invoke the tads 2 main entrypoint with no arguments */
        main_t2(1, argv);
        
        /* that's all we need to do with this option */
        os_term(OSEXSUCC);
    }
    else if (argc == 2 && stricmp(argv[1], "-help3") == 0)
    {
        /* invoke the tads 3 main entrypoint with no arguments */
        main_t3(1, argv);
        
        /* that's all we need to do with this option */
        os_term(OSEXSUCC);
    }

    /* look at the arguments and try to find the program name */
    if (!vm_get_game_arg(argc, argv, prog_arg, sizeof(prog_arg), &engine_ver))
    {
        /* 
         *   there's no game file name specified or implied - show the
         *   generic combined v2/v3 usage message 
         */
        mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
        glk_set_window(mainwin);

         /* copyright-date-string */
        sprintf(copyright,
                "TADS Interpreter - "
                "Copyright (c) 1993, 2004 Michael J. Roberts\n"
                "TADS 2 VM version " TADS_RUNTIME_VERSION " / "
                "T3 VM version " T3VM_VSN_STRING "\n\n");
        glk_put_string(copyright);

        sprintf(errorload,
                "Error: you didn't specify a game file name on the command "
                "line, or the command "
                "options are incorrect. You must specify the name of "
                "the game file you would "
                "like to run.\n"
                "\n"
                "If you'd like a list of command-line options for TADS 2 "
                "games, specify -help2 "
                "instead of giving a game file name. Or, if you'd like a "
                "list of command-line "
                "options for TADS 3, specify -help3.\n");
        glk_put_string(errorload);

        /* pause (if desired by OS layer) and exit */
        os_expause();
        os_term(OSEXFAIL);
    }

    /* determine the type of the game we have */
    engine_ver = vm_get_game_type(prog_arg, fname, sizeof(fname),
                                  defexts,
                                  sizeof(defexts)/sizeof(defexts[0]));

    /* presume failure */
    stat = OSEXFAIL;

    /* see what we have */
    switch(engine_ver)
    {
        case VM_GGT_TADS2:
            /* run the game using the TADS 2 engine */
            stat = main_t2(argc, argv);
            break;

        case VM_GGT_TADS3:
            /* run the game using the TADS 3 engine */
            stat = main_t3(argc, argv);
            break;

        case VM_GGT_INVALID:
            /* invalid file type */
            sprintf(buf,
                    "The file you have selected (%s) is not a valid game file.\n",
                    fname);
            mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
            glk_set_window(mainwin);
            glk_put_string(buf);
            break;

        case VM_GGT_NOT_FOUND:
            /* file not found */
            sprintf(buf, "The game file (%s) cannot be found.\n", prog_arg);
            mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
            glk_set_window(mainwin);
            glk_put_string(buf);
            break;

        case VM_GGT_AMBIG:
            /* ambiguous file */
            sprintf(buf,"The game file (%s) cannot be found exactly as given, "
                        "but multiple game "
                        "files with this name and different default suffixes "
                        "(.gam, .t3) exist. "
                        "Please specify the full name of the file, including the "
                        "suffix, that you "
                        "wish to use.\n",
                   prog_arg);
            mainwin = glk_window_open(0, 0, 0, wintype_TextBuffer, 0);
            glk_set_window(mainwin);
            glk_put_string(buf);
            break;
    }

    /* pause (if desired by OS layer) and terminate with our status code */
    os_expause();
    os_term(stat);
}