From 1c3b46f9475b7bb8763e6589a3080c6825ff2fa3 Mon Sep 17 00:00:00 2001 From: David Griffith Date: Thu, 4 Jul 2019 17:43:12 -0700 Subject: [PATCH] Allow for alternative Blorb file at command line for dumb and curses. Doing this for the SDL interface is proving troublesome because it's not very clear where stuff is being set and where not. After the audio overhaul release, I want to overhaul the SDL interface code to make it as closely resemble as feasible that of the curses interface. --- doc/dfrotz.6 | 25 ++++++++++++++++++++++++- doc/frotz.6 | 25 ++++++++++++++++++++++++- src/common/setup.h | 1 + src/curses/ux_blorb.c | 21 ++++++++++++--------- src/curses/ux_init.c | 5 ++++- src/dumb/dumb_blorb.c | 16 ++++++++++------ src/dumb/dumb_init.c | 5 ++++- 7 files changed, 79 insertions(+), 19 deletions(-) diff --git a/doc/dfrotz.6 b/doc/dfrotz.6 index d401bb8..f5226e8 100644 --- a/doc/dfrotz.6 +++ b/doc/dfrotz.6 @@ -6,7 +6,30 @@ dfrotz \- interpreter for Infocom and other Z-Machine games (dumb interface) .SH SYNOPSIS .B dfrotz -.RI [ options "] " file +.RI [ options "] " "file " [ blorbfile "]" + +At least one file must be specified on the command line. This can be +either a plain Z-code file or a Blorb file. A Z-code file is a compiled +executable for the Z-Machine. A Blorb file contains audio, graphics, +and other things in addition to the game wrapped up into a single file. +It can also optionally contain the Z-Machine executable. If a plain +Z-code file is supplied, then +.B Frotz +will check for a Blorb file with the same base name but an extension of +.B .blb, +.B .blorb, +or +.B .zblorb +and load it if found. + +If the file supplied on the command line is a Blorb file, then +.B Frotz +will check to see if a Z-code file is contained within. If not found, then +.B Frotz +will complain and exit. + +An alternatively-named Blorb file can be supplied as the optional second +parameter to the command line invocation. .SH DESCRIPTION diff --git a/doc/frotz.6 b/doc/frotz.6 index 58d5436..e8865b4 100644 --- a/doc/frotz.6 +++ b/doc/frotz.6 @@ -6,7 +6,30 @@ frotz \- interpreter for Infocom and other Z-Machine games .SH SYNOPSIS .B frotz -.RI [ options "] " file +.RI [ options "] " "file " [ blorbfile "]" + +At least one file must be specified on the command line. This can be +either a plain Z-code file or a Blorb file. A Z-code file is a compiled +executable for the Z-Machine. A Blorb file contains audio, graphics, +and other things in addition to the game wrapped up into a single file. +It can also optionally contain the Z-Machine executable. If a plain +Z-code file is supplied, then +.B Frotz +will check for a Blorb file with the same base name but an extension of +.B .blb, +.B .blorb, +or +.B .zblorb +and load it if found. + +If the file supplied on the command line is a Blorb file, then +.B Frotz +will check to see if a Z-code file is contained within. If not found, then +.B Frotz +will complain and exit. + +An alternatively-named Blorb file can be supplied as the optional second +parameter to the command line invocation. .SH DESCRIPTION diff --git a/src/common/setup.h b/src/common/setup.h index 0c1ab35..06c3e69 100644 --- a/src/common/setup.h +++ b/src/common/setup.h @@ -23,6 +23,7 @@ typedef struct frotz_setup_struct { int err_report_mode; char *story_file; + char *blorb_file; char *story_name; char *story_base; char *script_name; diff --git a/src/curses/ux_blorb.c b/src/curses/ux_blorb.c index 9c85027..34a1ffc 100644 --- a/src/curses/ux_blorb.c +++ b/src/curses/ux_blorb.c @@ -84,16 +84,19 @@ bb_err_t ux_blorb_init(char *filename) blorb_fp = fp; } else { fclose(fp); - len1 = strlen(filename) + strlen(EXT_BLORB); - len2 = strlen(filename) + strlen(EXT_BLORB3); - mystring = malloc(len2 * sizeof(char) + 1); - strncpy(mystring, filename, len1 * sizeof(char)); - p = strrchr(mystring, '.'); - if (p != NULL) - *p = '\0'; - - strncat(mystring, EXT_BLORB, len1 * sizeof(char)); + if (f_setup.blorb_file != NULL) + mystring = strdup(f_setup.blorb_file); + else { + len1 = strlen(filename) + strlen(EXT_BLORB); + len2 = strlen(filename) + strlen(EXT_BLORB3); + mystring = malloc(len2 * sizeof(char) + 1); + strncpy(mystring, filename, len1 * sizeof(char)); + p = strrchr(mystring, '.'); + if (p != NULL) + *p = '\0'; + strncat(mystring, EXT_BLORB, len1 * sizeof(char)); + } /* Check if foo.blb is there. */ if ((fp = os_path_open(mystring, "rb")) == NULL) { diff --git a/src/curses/ux_init.c b/src/curses/ux_init.c index 5e09769..6dfad15 100644 --- a/src/curses/ux_init.c +++ b/src/curses/ux_init.c @@ -316,7 +316,7 @@ void os_process_arguments (int argc, char *argv[]) } while (c != EOF); - if (zoptind != argc - 1) { + if (argc < 2) { printf("FROTZ V%s\tCurses interface. ", VERSION); #ifndef NO_SOUND @@ -340,6 +340,9 @@ void os_process_arguments (int argc, char *argv[]) f_setup.story_file = strdup(argv[zoptind]); f_setup.story_name = strdup(basename(argv[zoptind])); + if (argv[3] != NULL) + f_setup.blorb_file = strdup(argv[3]); + /* Now strip off the extension */ p = strrchr(f_setup.story_name, '.'); if ( p != NULL ) diff --git a/src/dumb/dumb_blorb.c b/src/dumb/dumb_blorb.c index 1cf77bc..4227c9c 100644 --- a/src/dumb/dumb_blorb.c +++ b/src/dumb/dumb_blorb.c @@ -95,12 +95,16 @@ bb_err_t dumb_blorb_init(char *filename) fp = NULL; /* Check if foo.blb is there. */ - if ((blorb_fp = fopen(mystring, "rb")) == NULL) { - p = strrchr(mystring, '.'); - if (p != NULL) - *p = '\0'; - strncat(mystring, EXT_BLORB3, len2 * sizeof(char)); - blorb_fp = fopen(mystring, "rb"); + if (f_setup.blorb_file != NULL) + mystring = strdup(f_setup.blorb_file); + else { + if ((blorb_fp = fopen(mystring, "rb")) == NULL) { + p = strrchr(mystring, '.'); + if (p != NULL) + *p = '\0'; + strncat(mystring, EXT_BLORB3, len2 * sizeof(char)); + blorb_fp = fopen(mystring, "rb"); + } } if (blorb_fp == NULL || !isblorb(fp)) /* No matching blorbs found. */ diff --git a/src/dumb/dumb_init.c b/src/dumb/dumb_init.c index 713b8bc..b528439 100644 --- a/src/dumb/dumb_init.c +++ b/src/dumb/dumb_init.c @@ -138,7 +138,7 @@ void os_process_arguments(int argc, char *argv[]) } } while (c != EOF); - if (((argc - zoptind) != 1) && ((argc - zoptind) != 2)) { + if (argc < 2) { printf("FROTZ V%s\tDumb interface.\n", VERSION); puts(INFORMATION); puts(INFO2); @@ -150,6 +150,9 @@ void os_process_arguments(int argc, char *argv[]) f_setup.story_file = strdup(argv[zoptind]); f_setup.story_name = strdup(basename(argv[zoptind])); + if (argv[3] != NULL) + f_setup.blorb_file = strdup(argv[3]); + /* Now strip off the extension */ p = strrchr(f_setup.story_name, '.'); if ( p != NULL ) -- 2.34.1