Eh, what the heck. It may only be an approximate patch---I haven't
thoroughly read the source---but it makes the solution files work,
and doesn't obviously break anything...
---> Drake Wilson
diff -urN tworld-1.3.0/defs.h tworld-1.3.0.new/defs.h
--- tworld-1.3.0/defs.h 2006-04-15 19:58:36.000000000 -0500
+++ tworld-1.3.0.new/defs.h 2007-11-21 04:19:28.000000000 -0600
@@ -8,6 +8,7 @@
#define _defs_h_
#include <stdio.h>
+#include <stdint.h>
#include "gen.h"
/*
@@ -34,8 +35,8 @@
/* Pseudorandom number generators.
*/
typedef struct prng {
- unsigned long initial; /* initial seed value */
- unsigned long value; /* latest random value */
+ uint32_t initial; /* initial seed value */
+ uint32_t value; /* latest random value */
char shared; /* FALSE if independent sequence */
} prng;
@@ -65,8 +66,8 @@
*/
typedef struct solutioninfo {
actlist moves; /* the actual moves of the solution */
- unsigned long rndseed; /* the PRNG's initial seed */
- unsigned long flags; /* other flags (currently unused) */
+ uint32_t rndseed; /* the PRNG's initial seed */
+ uint32_t flags; /* other flags (currently unused) */
unsigned char rndslidedir; /* random slide's initial direction */
signed char stepping; /* the timer offset */
} solutioninfo;
@@ -196,7 +197,7 @@
int solutionsize; /* size of the saved solution data */
unsigned char *leveldata; /* the data defining the level */
unsigned char *solutiondata; /* the player's best solution so far */
- unsigned long levelhash; /* the level data's hash value */
+ uint32_t levelhash; /* the level data's hash value */
char const *unsolvable; /* why level is unsolvable, or NULL */
char name[256]; /* name of the level */
char passwd[256]; /* the level's password */
diff -urN tworld-1.3.0/fileio.c tworld-1.3.0.new/fileio.c
--- tworld-1.3.0/fileio.c 2006-02-23 21:34:54.000000000 -0600
+++ tworld-1.3.0.new/fileio.c 2007-11-21 04:21:36.000000000 -0600
@@ -242,7 +242,7 @@
/* Read one byte as an unsigned integer value.
*/
-int filereadint8(fileinfo *file, unsigned char *val8, char const *msg)
+int filereadint8(fileinfo *file, uint8_t *val8, char const *msg)
{
int byte;
@@ -255,7 +255,7 @@
/* Write one byte as an unsigned integer value.
*/
-int filewriteint8(fileinfo *file, unsigned char val8, char const *msg)
+int filewriteint8(fileinfo *file, uint8_t val8, char const *msg)
{
errno = 0;
if (fputc(val8, file->fp) != EOF)
@@ -265,7 +265,7 @@
/* Read two bytes as an unsigned integer value stored in little-endian.
*/
-int filereadint16(fileinfo *file, unsigned short *val16, char const *msg)
+int filereadint16(fileinfo *file, uint16_t *val16, char const *msg)
{
int byte;
@@ -282,7 +282,7 @@
/* Write two bytes as an unsigned integer value in little-endian.
*/
-int filewriteint16(fileinfo *file, unsigned short val16, char const *msg)
+int filewriteint16(fileinfo *file, uint16_t val16, char const *msg)
{
errno = 0;
if (fputc(val16 & 0xFF, file->fp) != EOF
@@ -293,7 +293,7 @@
/* Read four bytes as an unsigned integer value stored in little-endian.
*/
-int filereadint32(fileinfo *file, unsigned long *val32, char const *msg)
+int filereadint32(fileinfo *file, uint32_t *val32, char const *msg)
{
int byte;
@@ -316,7 +316,7 @@
/* Write four bytes as an unsigned integer value in little-endian.
*/
-int filewriteint32(fileinfo *file, unsigned long val32, char const *msg)
+int filewriteint32(fileinfo *file, uint32_t val32, char const *msg)
{
errno = 0;
if (fputc(val32 & 0xFF, file->fp) != EOF
diff -urN tworld-1.3.0/fileio.h tworld-1.3.0.new/fileio.h
--- tworld-1.3.0/fileio.h 2006-02-23 20:51:59.000000000 -0600
+++ tworld-1.3.0.new/fileio.h 2007-11-21 04:18:25.000000000 -0600
@@ -8,6 +8,7 @@
#define _fileio_h_
#include "defs.h"
+#include <stdint.h>
/* Reset a fileinfo structure to indicate no file.
*/
@@ -49,17 +50,17 @@
* from the current position in the given file. For the multi-byte
* values, the value is assumed to be stored in little-endian.
*/
-extern int filereadint8(fileinfo *file, unsigned char *val8,
+extern int filereadint8(fileinfo *file, uint8_t *val8,
char const *msg);
-extern int filewriteint8(fileinfo *file, unsigned char val8,
+extern int filewriteint8(fileinfo *file, uint8_t val8,
char const *msg);
-extern int filereadint16(fileinfo *file, unsigned short *val16,
+extern int filereadint16(fileinfo *file, uint16_t *val16,
char const *msg);
-extern int filewriteint16(fileinfo *file, unsigned short val16,
+extern int filewriteint16(fileinfo *file, uint16_t val16,
char const *msg);
-extern int filereadint32(fileinfo *file, unsigned long *val32,
+extern int filereadint32(fileinfo *file, uint32_t *val32,
char const *msg);
-extern int filewriteint32(fileinfo *file, unsigned long val32,
+extern int filewriteint32(fileinfo *file, uint32_t val32,
char const *msg);
/* Read size bytes from the given file and return the bytes in a
diff -urN tworld-1.3.0/oshw.h tworld-1.3.0.new/oshw.h
--- tworld-1.3.0/oshw.h 2006-04-11 03:53:27.000000000 -0500
+++ tworld-1.3.0.new/oshw.h 2007-11-21 04:25:55.000000000 -0600
@@ -131,7 +131,7 @@
/* The font provides special monospaced digit characters at 144-153.
*/
-enum { CHAR_MZERO = 144 };
+#define CHAR_MZERO ((char)144)
/*
* Video output functions.
diff -urN tworld-1.3.0/random.c tworld-1.3.0.new/random.c
--- tworld-1.3.0/random.c 2006-04-10 00:53:38.000000000 -0500
+++ tworld-1.3.0.new/random.c 2007-11-21 04:26:06.000000000 -0600
@@ -24,12 +24,12 @@
/* The most recently generated random number is stashed here, so that
* it can provide the initial seed of the next PRNG.
*/
-static unsigned long lastvalue = 0x80000000UL;
+static uint32_t lastvalue = 0x80000000UL;
/* The standard linear congruential random-number generator needs no
* introduction.
*/
-static unsigned long nextvalue(unsigned long value)
+static uint32_t nextvalue(uint32_t value)
{
return ((value * 1103515245UL) + 12345UL) & 0x7FFFFFFFUL;
}
@@ -67,7 +67,7 @@
/* Reset a PRNG to an independent sequence.
*/
-void restartprng(prng *gen, unsigned long seed)
+void restartprng(prng *gen, uint32_t seed)
{
gen->value = gen->initial = seed & 0x7FFFFFFFUL;
gen->shared = FALSE;
diff -urN tworld-1.3.0/random.h tworld-1.3.0.new/random.h
--- tworld-1.3.0/random.h 2006-01-14 05:12:55.000000000 -0600
+++ tworld-1.3.0.new/random.h 2007-11-21 04:27:25.000000000 -0600
@@ -19,7 +19,7 @@
/* Restart an existing PRNG upon a predetermined sequence.
*/
-extern void restartprng(prng *gen, unsigned long initial);
+extern void restartprng(prng *gen, uint32_t initial);
/* Retrieve the original seed value of the current sequence.
*/
diff -urN tworld-1.3.0/series.c tworld-1.3.0.new/series.c
--- tworld-1.3.0/series.c 2006-04-16 18:18:01.000000000 -0500
+++ tworld-1.3.0.new/series.c 2007-11-21 04:15:37.000000000 -0600
@@ -46,9 +46,9 @@
/* Calculate a hash value for the given block of data.
*/
-static unsigned long hashvalue(unsigned char const *data, unsigned int size)
+static uint32_t hashvalue(unsigned char const *data, unsigned int size)
{
- static unsigned long remainders[256] = {
+ static uint32_t remainders[256] = {
0x00000000, 0x04C11DB7, 0x09823B6E, 0x0D4326D9, 0x130476DC, 0x17C56B6B,
0x1A864DB2, 0x1E475005, 0x2608EDB8, 0x22C9F00F, 0x2F8AD6D6, 0x2B4BCB61,
0x350C9B64, 0x31CD86D3, 0x3C8EA00A, 0x384FBDBD, 0x4C11DB70, 0x48D0C6C7,
@@ -94,7 +94,7 @@
0xBCB4666D, 0xB8757BDA, 0xB5365D03, 0xB1F740B4
};
- unsigned long accum;
+ uint32_t accum;
unsigned int i, j;
for (j = 0, accum = 0xFFFFFFFFUL ; j < size ; ++j) {
@@ -113,7 +113,7 @@
*/
static int readseriesheader(gameseries *series)
{
- unsigned short val16;
+ uint16_t val16;
int ruleset;
if (!filereadint16(&series->mapfile, &val16, "not a valid data file"))
@@ -149,7 +149,7 @@
{
unsigned char *data;
unsigned char const *dataend;
- unsigned short size;
+ uint16_t size;
int n;
if (!filereadint16(file, &size, NULL))
@@ -450,7 +450,7 @@
fileinfo file;
seriesdata *sdata = (seriesdata*)data;
gameseries *series;
- unsigned long magic;
+ uint32_t magic;
char *datfilename;
int config, f;
diff -urN tworld-1.3.0/solution.c tworld-1.3.0.new/solution.c
--- tworld-1.3.0/solution.c 2006-04-15 18:49:27.000000000 -0500
+++ tworld-1.3.0.new/solution.c 2007-11-21 04:17:46.000000000 -0600
@@ -8,6 +8,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <stdint.h>
#include "defs.h"
#include "err.h"
#include "fileio.h"
@@ -215,9 +216,9 @@
static int readsolutionheader(fileinfo *file, int ruleset, int *flags,
int *extrasize, unsigned char *extra)
{
- unsigned long sig;
- unsigned short f;
- unsigned char n;
+ uint32_t sig;
+ uint16_t f;
+ uint8_t n;
if (!filereadint32(file, &sig, "not a valid solution file"))
return FALSE;
@@ -475,7 +476,7 @@
*/
static int readsolution(fileinfo *file, gamesetup *game)
{
- unsigned long size;
+ uint32_t size;
game->number = 0;
game->sgflags = 0;
@@ -706,8 +707,8 @@
int loadsolutionsetname(char const *filename, char *buffer)
{
fileinfo file;
- unsigned long dwrd;
- unsigned short word;
+ uint32_t dwrd;
+ uint16_t word;
int size;
clearfileinfo(&file);
diff -urN tworld-1.3.0/unslist.c tworld-1.3.0.new/unslist.c
--- tworld-1.3.0/unslist.c 2006-04-12 23:47:50.000000000 -0500
+++ tworld-1.3.0.new/unslist.c 2007-11-21 04:27:16.000000000 -0600
@@ -22,7 +22,7 @@
int setid; /* the ID of the level set's name */
int levelnum; /* the level's number */
int size; /* the levels data's compressed size */
- unsigned long hashval; /* the levels data's hash value */
+ uint32_t hashval; /* the levels data's hash value */
int note; /* the entry's annotation ID, if any */
} unslistentry;
@@ -112,7 +112,7 @@
/* Add a new entry with the given data to the list.
*/
static int addtounslist(int setid, int levelnum,
- int size, unsigned long hashval, int note)
+ int size, uint32_t hashval, int note)
{
if (listcount == listallocated) {
listallocated = listallocated ? listallocated * 2 : 16;
@@ -152,8 +152,10 @@
{
char buf[256], token[256];
char const *p;
- unsigned long hashval;
- int setid, size;
+ uint32_t hashval;
+ unsigned long hashval_long;
+ int setid;
+ unsigned int size;
int lineno, levelnum, n;
setid = 0;
@@ -169,7 +171,8 @@
continue;
}
n = sscanf(p, "%d: %04X%08lX: %[^\n\r]",
- &levelnum, &size, &hashval, token);
+ &levelnum, &size, &hashval_long, token);
+ hashval = (uint32_t)hashval_long;
if (n > 0 && levelnum > 0 && levelnum < 65536 && setid) {
if (n == 1) {
n = sscanf(p, "%*d: %s", token);