Beispiel #1
0
void record_open (void)
{
    char new_name[MAX_PATH];

    if (os_read_file_name (new_name, command_name, FILE_RECORD)) {

	strcpy (command_name, new_name);

	if ((rfp = rb->open (new_name, O_WRONLY|O_CREAT|O_TRUNC)) != -1)
	    ostream_record = TRUE;
	else
	    print_string ("Cannot open file\n");

    }

}/* record_open */
Beispiel #2
0
void record_open (void)
{
    char new_name[MAX_FILE_NAME + 1];

    if (os_read_file_name (new_name, command_name, FILE_RECORD)) {

	strcpy (command_name, new_name);

	if ((rfp = fopen (new_name, "wt")) != NULL)
	    ostream_record = TRUE;
	else
	    print_string ("Cannot open file\n");

    }

}/* record_open */
Beispiel #3
0
void replay_open (void)
{
    char new_name[MAX_PATH];

    if (os_read_file_name (new_name, command_name, FILE_PLAYBACK)) {

	strcpy (command_name, new_name);

	if ((pfp = rb->open (new_name, O_RDONLY)) != -1) {

	    set_more_prompts (read_yes_or_no ("Do you want MORE prompts"));

	    istream_replay = TRUE;

	} else print_string ("Cannot open file\n");

    }

}/* replay_open */
Beispiel #4
0
void replay_open (void)
{
    char new_name[MAX_FILE_NAME + 1];

    if (os_read_file_name (new_name, f_setup.command_name, FILE_PLAYBACK)) {

	strcpy (f_setup.command_name, new_name);

	if ((pfp = fopen (new_name, "rt")) != NULL) {

	    set_more_prompts (read_yes_or_no ("Do you want MORE prompts"));

	    istream_replay = TRUE;

	} else print_string ("Cannot open file\n");

    }

}/* replay_open */
Beispiel #5
0
void script_open (void)
{
    char new_name[MAX_FILE_NAME + 1];

    if (h_version >= V5 || !script_valid) {

	if (!os_read_file_name (new_name, script_name, FILE_SCRIPT)) {
	    print_string ("[Scripting canceled.");
	    if (h_version < V8)
		print_string(" Some games may not detect this; type 'unscript' to correct.");
	    print_string ("]\n");

	    h_flags &= ~SCRIPTING_FLAG;
	    SET_WORD (H_FLAGS, h_flags)
	    return;
	}

	strcpy (script_name, new_name);
#if FROTZ_IOS_PORT
	os_start_script();
#endif
    }
Beispiel #6
0
void script_open (void)
{
    static bool script_valid = FALSE;

    char new_name[MAX_FILE_NAME + 1];

    h_flags &= ~SCRIPTING_FLAG;

    if (h_version >= V5 || !script_valid) {

	if (!os_read_file_name (new_name, f_setup.script_name, FILE_SCRIPT))
	    goto done;

	strcpy (f_setup.script_name, new_name);

    }

    /* Opening in "at" mode doesn't work for script_erase_input... */

    if ((sfp = fopen (f_setup.script_name, "r+t")) != NULL ||
		(sfp = fopen (f_setup.script_name, "w+t")) != NULL) {

	fseek (sfp, 0, SEEK_END);

	h_flags |= SCRIPTING_FLAG;

	script_valid = TRUE;
	ostream_script = TRUE;

	script_width = 0;

    } else print_string ("Cannot open file\n");

done:

    SET_WORD (H_FLAGS, h_flags);

}/* script_open */
Beispiel #7
0
void script_open (void)
{
    static bool script_valid = FALSE;

    char new_name[MAX_PATH];

    h_flags &= ~SCRIPTING_FLAG;

    if (h_version >= V5 || !script_valid) {

	if (!os_read_file_name (new_name, script_name, FILE_SCRIPT))
	    goto done;

	strcpy (script_name, new_name);

    }

    /* Opening in "at" mode doesn't work for script_erase_input... */

    if ((sfp = rb->open (script_name, O_RDWR|O_CREAT)) != -1) {

	fseek (sfp, 0, SEEK_END);

	h_flags |= SCRIPTING_FLAG;

	script_valid = TRUE;
	ostream_script = TRUE;

	script_width = 0;

    } else print_string ("Cannot open file\n");

done:

    SET_WORD (H_FLAGS, h_flags)

}/* script_open */
Beispiel #8
0
void z_restore (void)
{
    char new_name[MAX_FILE_NAME + 1];
    char default_name[MAX_FILE_NAME + 1];
    FILE *gfp;

    zword success = 0;

    if (zargc != 0) {

	/* Get the file name */

	get_default_name (default_name, (zargc >= 3) ? zargs[2] : 0);

	if (os_read_file_name (new_name, default_name, FILE_LOAD_AUX) == 0)
	    goto finished;

	strcpy (auxilary_name, default_name);

	/* Open auxilary file */

	if ((gfp = fopen (new_name, "rb")) == NULL)
	    goto finished;

	/* Load auxilary file */

	success = fread (zmp + zargs[0], 1, zargs[1], gfp);

	/* Close auxilary file */

	fclose (gfp);

    } else {

	long pc;
	zword release;
	zword addr;
	int i;

	/* Get the file name */

	if (os_read_file_name (new_name, save_name, FILE_RESTORE) == 0)
	    goto finished;

	strcpy (save_name, new_name);

	/* Open game file */

	if ((gfp = fopen (new_name, "rb")) == NULL)
	    goto finished;

	if (f_setup.save_quetzal) {
	    success = restore_quetzal (gfp, story_fp);

	} else {
	    /* Load game file */

	    release = (unsigned) fgetc (gfp) << 8;
	    release |= fgetc (gfp);

	    (void) fgetc (gfp);
	    (void) fgetc (gfp);

	    /* Check the release number */

	    if (release == h_release) {

		pc = (long) fgetc (gfp) << 16;
		pc |= (unsigned) fgetc (gfp) << 8;
		pc |= fgetc (gfp);

		SET_PC (pc);

		sp = stack + (fgetc (gfp) << 8);
		sp += fgetc (gfp);
		fp = stack + (fgetc (gfp) << 8);
		fp += fgetc (gfp);

		for (i = (int) (sp - stack); i < STACK_SIZE; i++) {
		    stack[i] = (unsigned) fgetc (gfp) << 8;
		    stack[i] |= fgetc (gfp);
		}

		fseek (story_fp, 0, SEEK_SET);

		for (addr = 0; addr < h_dynamic_size; addr++) {
		    int skip = fgetc (gfp);
		    for (i = 0; i < skip; i++)
			zmp[addr++] = fgetc (story_fp);
		    zmp[addr] = fgetc (gfp);
		    (void) fgetc (story_fp);
		}

		/* Check for errors */

		if (ferror (gfp) || ferror (story_fp) || addr != h_dynamic_size)
		    success = -1;
		else

		    /* Success */

		    success = 2;

	    } else print_string ("Invalid save file\n");
	}

	if ((short) success >= 0) {

	    /* Close game file */

	    fclose (gfp);

	    if ((short) success > 0) {
		zbyte old_screen_rows;
		zbyte old_screen_cols;

		/* In V3, reset the upper window. */
		if (h_version == V3)
		    split_window (0);

		LOW_BYTE (H_SCREEN_ROWS, old_screen_rows);
		LOW_BYTE (H_SCREEN_COLS, old_screen_cols);

		/* Reload cached header fields. */
		restart_header ();

		/*
		 * Since QUETZAL files may be saved on many different machines,
		 * the screen sizes may vary a lot. Erasing the status window
		 * seems to cover up most of the resulting badness.
		 */
		if (h_version > V3 && h_version != V6
		    && (h_screen_rows != old_screen_rows
		    || h_screen_cols != old_screen_cols))
		    erase_window (1);
	    }
	} else
	    os_fatal ("Error reading save file");
    }

finished:

    if (h_version <= V3)
	branch (success);
    else
	store (success);

}/* z_restore */