Newsgroups: rec.arts.int-fiction
From: [email protected] (Sander van Malssen)
Subject: Re: ZIP under Linux?


These are my patches to Zip. (They also include some small general
improvements to the unix interface). I sent them to the author a while
ago, & they'll probably be part of the official package whenever a new
release comes out.

Cheers,
Sander

diff -ur orig/fileio.c new/fileio.c
--- orig/fileio.c       Thu Jun  2 17:08:02 1994
+++ new/fileio.c        Mon Jul 11 00:11:32 1994
@@ -41,10 +41,25 @@
const char *storyname;
#endif
{
+    char *path, *p;
+    char tmp[PATHNAME_MAX + 1];
+
+    if ((gfp = fopen (storyname, "rb")))
+       return;

-    gfp = fopen (storyname, "rb");
-    if (gfp == NULL)
-        fatal ("Game file not found");
+    if ((path = getenv("INFOCOM_PATH")) == NULL)
+       fatal ("Can't open game file");
+
+    p = strtok(path, ":");
+    while (p)
+    {
+       sprintf (tmp, "%s/%s", p, storyname);
+       if ((gfp = fopen (tmp, "rb")))
+           return;
+       p = strtok(NULL, ":");
+    }
+
+    fatal ("Can't open game file");

}/* open_story */

diff -ur orig/interpre.c new/interpre.c
--- orig/interpre.c     Thu Jun  2 17:08:06 1994
+++ new/interpre.c      Mon Jul 11 00:11:32 1994
@@ -133,7 +135,7 @@
                    case 0x24: read_line (count, operand); break;
                    case 0x25: print_character (operand[0]); break;
                    case 0x26: print_number (operand[0]); break;
-                    case 0x27: random (operand[0]); break;
+                    case 0x27: zip_random (operand[0]); break;
                    case 0x28: push_var (operand[0]); break;
                    case 0x29: pop_var (operand[0]); break;
                    case 0x2a: set_status_size (operand[0]); break;
diff -ur orig/math.c new/math.c
--- orig/math.c Thu Jun  2 17:08:07 1994
+++ new/math.c  Mon Jul 11 00:11:32 1994
@@ -210,16 +210,16 @@
}/* and */

/*
- * random
+ * zip_random
 *
 * Return random number between 1 and operand
 *
 */

#ifdef __STDC__
-void random (zword_t a)
+void zip_random (zword_t a)
#else
-void random (a)
+void zip_random (a)
zword_t a;
#endif
{
@@ -232,7 +232,7 @@
    } else /* (a > 0) */
        store_operand (((zword_t) rand () % a) + 1);

-}/* random */
+}/* zip_random */

/*
 * test
diff -ur orig/osdepend.c new/osdepend.c
--- orig/osdepend.c     Thu Jun  2 17:08:16 1994
+++ new/osdepend.c      Mon Jul 11 01:13:24 1994
@@ -9,6 +9,8 @@

#include "ztypes.h"

+char *storybasename;
+
/* File names will be O/S dependent */

#if defined(AMIGA)
@@ -87,8 +89,13 @@
        exit (EXIT_FAILURE);
    }

-    /* Open the story file */
+    /* Strip leading directories */
+    if ((storybasename = strrchr(argv[optind], '/')))
+       storybasename++;
+    else
+       storybasename = argv[optind];

+    /* Open the story file */
    open_story (argv[optind]);

}/* process_arguments */
@@ -225,7 +232,12 @@
        else if (flag == GAME_RECORD || flag == GAME_PLAYBACK)
            strcpy (default_name, RECORD_NAME);
        else /* (flag == GAME_SAVE || flag == GAME_RESTORE) */
+#if 0
            strcpy (default_name, SAVE_NAME);
+#else
+           strcpy (default_name, storybasename);
+           strcat (default_name, ".sav");
+#endif
    }

    /* Prompt for the file name */
@@ -310,7 +322,10 @@
{

    reset_screen ();
-    printf ("\nFatal error: %s (PC = %lx)\n", s, pc);
+    printf ("\nFatal error: %s", s);
+    if (pc)
+       printf (" (PC = %lx)", pc);
+    putchar ('\n');
    exit (1);

}/* fatal */
diff -ur orig/unixio.c new/unixio.c
--- orig/unixio.c       Thu Jun  2 17:08:25 1994
+++ new/unixio.c        Mon Jul 11 00:54:03 1994
@@ -2,16 +2,16 @@

#include "ztypes.h"

-#if !defined(BSD) || !defined(SYSTEM_FIVE) || !defined(POSIX)
-#define BSD
-#endif /* !defined(BSD) || !defined(SYSTEM_FIVE) || !defined(POSIX) */
+#if !defined(BSD) && !defined(SYSTEM_FIVE) && !defined(POSIX)
+#error "define one of BSD, SYSTEM_FIVE or POSIX"
+#endif /* !defined(BSD) && !defined(SYSTEM_FIVE) && !defined(POSIX) */

#if defined(BSD)
#include <sgtty.h>
#endif /* defined(BSD) */
#if defined(SYSTEM_FIVE)
#include <termio.h>
-#endif /* defined(SYSTEM_FIVE)
+#endif /* defined(SYSTEM_FIVE) */
#if defined(POSIX)
#include <termios.h>
#endif /* defined(POSIX) */
@@ -44,6 +44,8 @@
static int read_key ();
static void set_cbreak_mode ();
static void rundown ();
+static void tstp_zip ();
+static void cont_zip ();

extern int tgetent ();
extern int tgetnum ();
@@ -104,14 +106,15 @@
        US = SO;
    }

-    tputs (TI, 1, outc);
+    if (TI && *TI)
+       tputs (TI, 1, outc);

    clear_screen ();

    row = screen_rows / 2;
    col = (screen_cols - (sizeof ("The story is loading...") - 1)) / 2;
    move_cursor (row, col);
-    display_string ("The story is loading...");
+    display_string ("The story is loading..."); fflush (stdout);

    h_interpreter = INTERP_MSDOS;

@@ -144,7 +147,8 @@

    set_cbreak_mode (0);

-    tputs (TE, 1, outc);
+    if (TE && *TE)
+       tputs (TE, 1, outc);

}/* reset_screen */

@@ -175,7 +179,7 @@
{
    int row, col;

-    if (*CS) {
+    if (CS && *CS) {
        get_cursor_position (&row, &col);

        tputs (tgoto (CS, screen_rows - 1, status_size), 1, outc);
@@ -189,7 +193,7 @@
{
    int row, col;

-    if (*CS) {
+    if (CS && *CS) {
        get_cursor_position (&row, &col);

        tputs (tgoto (CS, screen_rows - 1, 0), 1, outc);
@@ -326,7 +330,7 @@

    get_cursor_position (&row, &col);

-    if (*CS || row < screen_rows) {
+    if ((CS && *CS) || row < screen_rows) {
        display_char ('\n');
    } else {
        move_cursor (status_size + 1, 1);
@@ -421,7 +425,7 @@

                /* Scroll line if return key pressed */

-                if (c == '\n') {
+                if (c == '\r') {
                    scroll_line ();
                    return (c);
                } else {
@@ -482,8 +486,8 @@

    if (c == 127)
        c = '\b';
-    else if (c == '\r')
-        c = '\n';
+    else if (c == '\n')
+        c = '\r';

    return (c);

@@ -526,6 +530,7 @@
    if (mode) {
        signal (SIGINT, rundown);
        signal (SIGTERM, rundown);
+        signal (SIGTSTP, tstp_zip);
    }

    if (mode) {
@@ -572,6 +577,7 @@
    if (mode == 0) {
        signal (SIGINT, SIG_DFL);
        signal (SIGTERM, SIG_DFL);
+        signal (SIGTSTP, SIG_DFL);
    }

}/* set_cbreak_mode */
@@ -585,3 +591,23 @@
    reset_screen ();

}/* rundown */
+
+static void tstp_zip ()
+{
+    reset_screen ();
+    signal (SIGTSTP, SIG_DFL);
+    signal (SIGCONT, cont_zip);
+    raise (SIGTSTP);
+
+}/* tstp_zip */
+
+static void cont_zip ()
+{
+    signal (SIGINT, rundown);
+    signal (SIGTERM, rundown);
+    signal (SIGTSTP, tstp_zip);
+    clear_screen ();
+    restart_screen ();
+    set_cbreak_mode ();
+
+}/* cont_zip */
diff -ur orig/ztypes.h new/ztypes.h
--- orig/ztypes.h       Thu Jun  2 17:08:28 1994
+++ new/ztypes.h        Mon Jul 11 00:11:33 1994
@@ -41,6 +41,10 @@
#define FILENAME_MAX 255
#endif

+#ifndef PATHNAME_MAX
+#define PATHNAME_MAX 1024
+#endif
+
#ifndef EXIT_SUCCESS
#define EXIT_SUCCESS 0
#endif
@@ -470,7 +474,7 @@
void multiply (zword_t, zword_t);
void not (zword_t);
void or (zword_t, zword_t);
-void random (zword_t);
+void zip_random (zword_t);
void remainder (zword_t, zword_t);
void shift (zword_t, zword_t);
void subtract (zword_t, zword_t);
@@ -487,7 +491,7 @@
void multiply ();
void not ();
void or ();
-void random ();
+void zip_random ();
void remainder ();
void shift ();
void subtract ();

--- unixio.c.~1~        Mon Jul 11 17:12:36 1994
+++ unixio.c    Thu Jul 14 04:10:03 1994
@@ -497,6 +498,7 @@
int mode;
{
    int status;
+    static int initialized = 0;
#if defined(BSD)
    struct sgttyb new_tty;
    static struct sgttyb old_tty;
@@ -509,6 +511,11 @@
    struct termios new_termios;
    static struct termios old_termios;
#endif /* defined(POSIX) */
+
+    /* Don't try to restore terminal settings if they weren't saved first */
+    if (mode == 0 && initialized == 0)
+       return;
+    initialized = mode;

#if defined(BSD)
    status = ioctl (fileno (stdin), (mode) ? TIOCGETP : TIOCSETP, &old_tty);
--
Sander van Malssen
[email protected]