Allow for alternative Blorb file at command line for curses, sdl, and dumb.
authorDavid Griffith <dave@661.org>
Sat, 6 Jul 2019 02:12:26 +0000 (19:12 -0700)
committerDavid Griffith <dave@661.org>
Sun, 7 Jul 2019 02:25:34 +0000 (19:25 -0700)
Doing this for the SDL interface is proved a bit 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
doc/frotz.6
doc/sfrotz.6
src/common/setup.h
src/curses/ux_blorb.c
src/curses/ux_init.c
src/dumb/dumb_blorb.c
src/dumb/dumb_init.c
src/sdl/sf_resource.c
src/sdl/sf_util.c

index d401bb81dec0be2a935ce6c24ec0cda330694e12..f5226e8fc15df2bdfc03fee04e734e66bcf68c93 100644 (file)
@@ -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
index 58d543637a842b5a074639b96bda22747943ecf2..e8865b47dd1603d6fb79378cac33b08223065433 100644 (file)
@@ -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
index 38bb416a1f9313c08e41299f6d0c70c24717d355..b53e114df5e8df7c0d4e8045401ef54357d46547 100644 (file)
@@ -6,7 +6,30 @@ sfrotz \- interpreter for Infocom and other Z-Machine games (SDL interface)
 
 .SH SYNOPSIS
 .B sfrotz
-.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 invocatio
 
 
 .SH DESCRIPTION
index 0c1ab35df7e8bee023389984190741934e9d1c62..06c3e69a36a0fa6a62396deb6ae1e0faf54b1d9e 100644 (file)
@@ -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;
index 9c85027241aa13591bccbcffd2dbe0c83a5acf03..34a1ffc986dd5c769f7ae388c5f4e3999dcf0b84 100644 (file)
@@ -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) {
index 5e09769d7ec2184e43944e4c7681a7eba0e056b7..b4f2812594898b2915eb932ab1288f154b5ff48f 100644 (file)
@@ -316,7 +316,7 @@ void os_process_arguments (int argc, char *argv[])
 
     } while (c != EOF);
 
-    if (zoptind != argc - 1) {
+    if ((argv[zoptind] == NULL)) {
        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[zoptind+1] != NULL)
+       f_setup.blorb_file = strdup(argv[zoptind+1]);
+
     /* Now strip off the extension */
     p = strrchr(f_setup.story_name, '.');
     if ( p != NULL )
@@ -1104,6 +1107,19 @@ void os_init_setup(void)
        f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE;
        f_setup.restore_mode = 0;
 
+       f_setup.blorb_file = NULL;
+       f_setup.story_file = NULL;
+       f_setup.story_name = NULL;
+       f_setup.story_base = NULL;
+       f_setup.script_name = NULL;
+       f_setup.command_name = NULL;
+       f_setup.save_name = NULL;
+       f_setup.tmp_save_name = NULL;
+       f_setup.aux_name = NULL;
+       f_setup.story_path = NULL;
+       f_setup.zcode_path = NULL;
+       f_setup.restricted_path = NULL;
+
        f_setup.use_blorb = 0;
        f_setup.exec_in_blorb = 0;
 
index 1cf77bc80f4617a6d52136c8e52494570330afed..4227c9c7049bd5da4ae570ab7e4890fcc87a99ac 100644 (file)
@@ -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. */
index 713b8bcb37c220d53efce4561ea057eb7eefa74b..08e32a0a08d740e222e4feea99fce257e13394a9 100644 (file)
@@ -138,7 +138,7 @@ void os_process_arguments(int argc, char *argv[])
        }
     } while (c != EOF);
 
-    if (((argc - zoptind) != 1) && ((argc - zoptind) != 2)) {
+    if ((argv[zoptind] == NULL)) {
        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[zoptind+1] != NULL)
+       f_setup.blorb_file = strdup(argv[zoptind+1]);
+
     /* Now strip off the extension */
     p = strrchr(f_setup.story_name, '.');
     if ( p != NULL )
@@ -297,6 +300,19 @@ void os_init_setup(void)
        f_setup.sound = 1;
        f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE;
        f_setup.restore_mode = 0;
+
+       f_setup.blorb_file = NULL;
+       f_setup.story_file = NULL;
+       f_setup.story_name = NULL;
+       f_setup.story_base = NULL;
+       f_setup.script_name = NULL;
+       f_setup.command_name = NULL;
+       f_setup.save_name = NULL;
+       f_setup.tmp_save_name = NULL;
+       f_setup.aux_name = NULL;
+       f_setup.story_path = NULL;
+       f_setup.zcode_path = NULL;
+       f_setup.restricted_path = NULL;
 }
 
 static void print_version(void)
index f3a91f50b3b59f0f2fd3a846843b917444aa96b1..7ba1cba0f6ca7e5b6fe9ab7a2f5e17015b1bf38e 100644 (file)
@@ -201,13 +201,23 @@ static int load_resources( char *givenfn)
   zsize = ftell(f);
   zoffset = 0;
 
-       // try loading a corresponding blorb, but without complaining...
-  p = strrchr(buf,'.');
-  if (p){
-    strcpy(p,".blb");
-    tryloadblorb(buf);
+  // See if the user explicitly provided a blorb file
+  if (f_setup.blorb_file != NULL) {
+    tryloadblorb(f_setup.blorb_file);
+  } else {
+  // No?  Let's see if we can find one.
+    p = malloc(strlen(f_setup.story_name) + strlen(EXT_BLORB4) * sizeof(char));
+    strncpy(p, f_setup.story_name, strlen(f_setup.story_name));
+    strncat(p, EXT_BLORB3, strlen(EXT_BLORB3)+1);
+
+    if (tryloadblorb(p) != bb_err_None) {  /* Trying foo.blorb */
+      free(p);
+      p = malloc(strlen(f_setup.story_name) + strlen(EXT_BLORB4) * sizeof(char));
+      strncpy(p, f_setup.story_name, strlen(f_setup.story_name));
+      strncat(p, EXT_BLORB, strlen(EXT_BLORB)+1);
+      tryloadblorb(p);  /* Trying foo.blb */
     }
-
+  }
   return 0;
   }
 
@@ -1075,5 +1085,18 @@ void os_init_setup(void)
     f_setup.err_report_mode = ERR_DEFAULT_REPORT_MODE;
     f_setup.restore_mode = 0;
 
+    f_setup.blorb_file = NULL;
+    f_setup.story_file = NULL;
+    f_setup.story_name = NULL;
+    f_setup.story_base = NULL;
+    f_setup.script_name = NULL;
+    f_setup.command_name = NULL;
+    f_setup.save_name = NULL;
+    f_setup.tmp_save_name = NULL;
+    f_setup.aux_name = NULL;
+    f_setup.story_path = NULL;
+    f_setup.zcode_path = NULL;
+    f_setup.restricted_path = NULL;
+
     sdl_active = FALSE;
 }
index 55d14c0b6a3ebac3740ea2b97e7cc57a949b86ae..78d3b121d097264460e0e9a6d0a08ca24cc8ec07 100644 (file)
@@ -333,19 +333,18 @@ void os_process_arguments (int argc, char *argv[])
   sf_readsettings();
   parse_options(argc, argv);
 
-  if (optind != argc - 1) 
+  if (argv[optind] == NULL)
        {
        usage();
        exit (EXIT_FAILURE);
        }
   f_setup.story_file = strdup(argv[optind]);
 
-  // it's useless to test the retval, as in case of error it does not return
-  sf_load_resources( f_setup.story_file);
+  if(argv[optind+1] != NULL)
+    f_setup.blorb_file = argv[optind+1];
 
     /* Strip path and extension off the story file name */
-
-  f_setup.story_name = new_basename(argv[optind]);
+  f_setup.story_name = new_basename(f_setup.story_file);
 
   /* Now strip off the extension. */
   p = strrchr(f_setup.story_name, '.');
@@ -358,7 +357,6 @@ void os_process_arguments (int argc, char *argv[])
   else
     // blorb_ext = strdup(EXT_BLORB);
 
-
     /* Get rid of extensions with 1 to 6 character extensions. */
     /* This will take care of an extension like ".zblorb". */
     /* More than that, there might be something weird going on */
@@ -406,6 +404,9 @@ void os_process_arguments (int argc, char *argv[])
   if (user_foreground != -1) m_defaultFore = sf_GetColour(user_foreground);
   if (user_tandy_bit != -1) m_tandy = user_tandy_bit;
 
+  // it's useless to test the retval, as in case of error it does not return
+  sf_load_resources( f_setup.story_file);
+
   sf_initfonts();
 
 }/* os_process_arguments */