How to apply the NetHack 1.4f patch

The patch to convert NetHack 1.3d to NetHack 1.4f is difficult to apply correctly. Some parts of it seem to be interpreted incorrectly by a modern Unix shell, and the patch for invent.c seems to be created from something different from its counterpart in 1.3d. This article will describe how to correct these problems and apply the NetHack 1.4f patch.

Note to users of Microsoft Windows
The original archives are distributed in a format called a "shell archive" and are most easily unpacked in a Unix environment. Users of Windows can install MinGW or Cygwin to obtain the necessary tools. DJGPP may also work.

The necessary files
Start with a copy of NetHack 1.3d. The Harlow and UUNet distributions are the same, so either may be used.

Download the file patch1.Z from UUNet at. This is in the same directory as the UUNet distribution above.

The .Z extension on patch1.Z indicates that "compress" has been used to pack the file. Gzip understands the compress format, and so either gunzip or uncompress may be used to unpack it.

Extracting the patch files
The file patch1 is a shell archive -- a Bourne shell script that, when run, creates the archived files in the current directory. However, it also has Usenet headers and a brief explanation at the top. You'll need to delete all lines before the one that reads "#! /bin/sh".

Run the resulting file as a Bourne shell script, say, as "sh patch1". This will produce the following files:
 * README.NEW
 * Fixes.1.4
 * Manifest.upd
 * Makefile.tcc
 * Maketcc.ini
 * update.patches

Editing the patch for a modern shell
The file update.patches is itself a Bourne shell script that invokes ed to modify the files that have changed in 1.4f. Specifically, it contains a series of shell commands such as these:

cp apply.c apply.c.orig ed apply.c &lt;&lt;ED_EOF 187d 183,185d 1c /*	SCCS Id: @(#)apply.c	1.4	87/08/08 . w q ED_EOF

It is not quite compatible with GNU bash as provided, because the text that is passed to ed (between the <<ED_EOF and ED_EOF markers) may contain characters that are meaningful to the shell. We need to edit update.patches to tell bash not to interpret these characters.

Bash will not interprete these characters if the starting marker is quoted in any way. (We must not alter the ending marker.) So it is sufficient to use the replace function of your favorite text editor, and replace all instances of <<ED_EOF with <<'ED_EOF'. For example, in vi, use ":1,$s/<<ED_EOF/<<'ED_EOF'/".

The above block then reads:

cp apply.c apply.c.orig ed apply.c &lt;&lt; 'ED_EOF' 187d 183,185d 1c /*	SCCS Id: @(#)apply.c	1.4	87/08/08 . w q ED_EOF

and other such blocks are similarly affected.

Editing invent.c to match the patch
Now it is necessary to edit invent.c so that it matches the provided patch. The patch was generated from an altered invent.c that had six extra lines that are not present in the distributed version of 1.3d. Go to line 778; it and the surrounding lines read:

doinv (stuff); return(0); } /* look at what is here */ dolook {

Line 778 is highlighted in green.

You need to insert exactly six lines above this line. It does not matter what the lines contain, as the patch will blindly delete them, but there must be exactly six lines and they must be placed above that comment. You might see something like:

doinv (stuff); return(0); } 1 2 3 4 5 6 /* look at what is here */ dolook {

Applying the patch
Once update.patches and invent.c are both edited in this way, you can now apply the patch with "sh update.patches".

When you are satisfied that the patch is applied correctly (you may do well to do "diff invent.c.orig invent.c" in particular), then you can go ahead and delete the files "*.orig", update.patches, and patch1. You now have a NetHack 1.4f that matches the likely intentions of the developers.