diff -ru grfcodec-orig/Makefile grfcodec/Makefile
--- grfcodec-orig/Makefile	Tue Mar 18 02:51:00 2003
+++ grfcodec/Makefile	Sun May  2 23:33:05 2004
@@ -19,11 +19,11 @@
 CC = gcc
 CXX = g++
 # use 386 instructions but optimize for pentium II/III
-CFLAGS = -g -mno-cygwin -DWIN32 -O3 -march=i386 -mpentiumpro -mcpu=pentiumpro -I. $(CFLAGAPP)
+CFLAGS = -g -DWIN32 -O3 -I. $(CFLAGAPP)
 CXXFLAGS = $(CFLAGS)
 #LDOPT = -g -Wl,--subsystem,console -luser32 -lgdi32 -lwinmm -lcomdlg32 -lcomctl32
-LDOPT = -Wl,--subsystem,console,-s -luser32 -lgdi32 -lwinmm -lcomdlg32 -lcomctl32
-LDOPT += -Wl,-Map,$(@:%=%.map)		# to make map files
+#LDOPT = -Wl,--subsystem,console,-s
+#LDOPT += -Wl,-Map,$(@:%=%.map)		# to make map files
 
 # for profiling
 #CFLAGS += -pg
diff -ru grfcodec-orig/grfcodec.cc grfcodec/grfcodec.cc
--- grfcodec-orig/grfcodec.cc	Thu Mar  6 03:26:58 2003
+++ grfcodec/grfcodec.cc	Fri May 14 23:01:20 2004
@@ -21,7 +21,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
-#include <dir.h>
+//#include <dir.h>
 #include <getopt.h>
 #include <sys/stat.h>
 
@@ -51,7 +51,7 @@
 	"\n"
 	"<GRF-File> denotes the .GRF file you want to work on, e.g. TRG1.GRF\n"
 	"<Directory> is where the individual sprites should be saved. If omitted, they\n"
-	"\twill default to a subdirectory called SPRITES.\n"
+	"\twill default to a subdirectory called sprites/.\n"
 	"\n"
 	"Options for decoding:\n"
 	"    -w <num>  Write PCX files with the given width (default 800, minimum 16)\n"
@@ -160,6 +160,7 @@
 
   if (!tmp && (errno == ENOENT)) {
 	// .bak doesn't exist, rename orig to .bak
+	// XXX: Shouldn't we rename orig to .bak even if .bak already exists? --pasky
 	printf("\nRenaming %s to %s", realfile, bakfile);
 	if (rename(realfile, bakfile)) {
 		errno = EEXIST;		// go delete it
@@ -168,18 +169,12 @@
 	}
   }
 
-  printf("\nReplacing %s with %s\n", realfile, newfile);
-
-  if (tmp || (errno != ENOENT)) {
-	printf("Deleting %s\n", realfile);
-	if (remove(realfile)) {
-		fperror("Error while deleting");
-		exit(2);
-	}
-  }
+  if (tmp) fclose(tmp);
 
   // rename tmp to grf
 
+  printf("\nReplacing %s with %s\n", realfile, newfile);
+
   if (rename(newfile, realfile)) {
 	fperror("Error renaming %s to %s", newfile, realfile);
 	exit(2);
@@ -280,6 +275,11 @@
 		fputc(0xff, grf);
 		for (int i=0; i<info->size; i++)
 			fputc(info->nextverb(), grf);
+		if (info->verbatim_str) {
+			/* XXX: Trailing quote mark. */
+			fgetc(info->f);
+			info->verbatim_str = 0;
+		}
 	} else {				// real sprite, encode it
 		U8 *image = (U8*) myalloc(info->imgsize);
 		if (!image) {
@@ -345,7 +345,7 @@
 
   // make sure the directory exists, or create it if not
   realdir = spritefilename(file, dir, "", -1, "rb", 0);	// make fake filename
-  *strrchr(realdir, '\\') = 0;	// cut off filename
+  *strrchr(realdir, '/') = 0;	// cut off filename
 
   if (stat(realdir, &statbuf)) {
 	// error during stat
@@ -354,13 +354,13 @@
 		exit(2);
 	}
 
-	if (mkdir(realdir)) {
+	if (mkdir(realdir, 0755)) {
 		fperror("Error making %s", realdir);
 		exit(2);
 	}
   }
 
-  doopen(file, dir, ".NFO", "wt", NULL, &info, 0);
+  doopen(file, dir, ".nfo", "wt", NULL, &info, 0);
 
   fseek(grf, 0, SEEK_END);
   fsize = ftell(grf);
@@ -584,10 +584,10 @@
   if (optind < argc)
 	strcpy(directory, argv[optind++]);
   else
-	strcpy(directory, "SPRITES");
+	strcpy(directory, "sprites");
 
-  if (directory[strlen(directory) - 1] != '\\')
-	strcat(directory, "\\");
+  if (directory[strlen(directory) - 1] != '/')
+	strcat(directory, "/");
 
   if (!action || !grffile || (width < 16) ||
 	( (height < 16) && (height != -1) ) ||
diff -ru grfcodec-orig/grfcomm.c grfcodec/grfcomm.c
--- grfcodec-orig/grfcomm.c	Thu Mar  6 03:27:16 2003
+++ grfcodec/grfcomm.c	Sat May  8 20:54:13 2004
@@ -6,7 +6,7 @@
 
 #include <stdlib.h>
 #include <stdio.h>
-#include <dir.h>
+//#include <dir.h>
 #include <string.h>
 #include <errno.h>
 
@@ -36,7 +36,7 @@
 
 int getspritefilename(char *filename, char *basefilename, char *subdirectory, char *ext, long spriteno)
 {
-  char *fullpath = _fullpath(NULL, basefilename, 0);
+  char *fullpath = strdup(basefilename);//_fullpath(NULL, basefilename, 0);
 
   char bdrive[5], bdirectory[128], bname[20], bext[6];
   char sdrive[5], sdirectory[128];
@@ -45,7 +45,7 @@
   fnsplit(fullpath,     bdrive, bdirectory, bname, bext);
 
   if (strlen(sdrive)) {		// drive given, go relative
-	char *sfullpath = _fullpath(NULL, subdirectory, 0);
+	char *sfullpath = strdup(subdirectory);//_fullpath(NULL, subdirectory, 0);
 	fnsplit(sfullpath, sdrive, sdirectory, NULL, NULL);
 	myfree(sfullpath);
 
@@ -53,7 +53,7 @@
   }
 
   if (strlen(sdirectory)) {
-	if (sdirectory[0] == '\\')	// absolute path
+	if (sdirectory[0] == '\\' || sdirectory[0] == '/')	// absolute path
 		strcpy(bdirectory, sdirectory);
 	else
 		strcat(bdirectory, sdirectory);
@@ -117,14 +117,14 @@
   strcpy(directory, reldirectory);
   getspritefilename(filename, basefilename, directory, ext, spriteno);
 
-  if (directory[strlen(directory)-1] == '\\')
+  if (directory[strlen(directory)-1] == '\\' || directory[strlen(directory)-1] == '/')
 	  directory[strlen(directory)-1] = 0;	// cut off trailing backslash
 
   while (mustexist) {	// actuall mustexist doesn't change, loop is terminated by explicit break
 	sprite = fopen(filename, mode);
 	if (!sprite) {
 		if (errno == ENOENT) {		// directory doesn't exist
-			if (mkdir(directory)) {
+			if (mkdir(directory, 0755)) {
 				fperror("Creating %.228s", directory);
 				exit(2);
 			}
diff -ru grfcodec-orig/grfdiff.cc grfcodec/grfdiff.cc
--- grfcodec-orig/grfdiff.cc	Sat May 17 21:18:32 2003
+++ grfcodec/grfdiff.cc	Fri May 14 22:44:38 2004
@@ -390,7 +390,10 @@
   }
 
   if (grd) {
-	char *noext = strlwr(basename(grffile[1]));
+	char *noext = basename(grffile[1]);
+	char *p;
+
+	for (p = noext; *p; p++) { *p = tolower(*p); }
 
 	thisgrdstart = ftell(grd);
 
diff -ru grfcodec-orig/grfmerge.c grfcodec/grfmerge.c
--- grfcodec-orig/grfmerge.c	Sat May 17 21:27:06 2003
+++ grfcodec/grfmerge.c	Fri May 14 22:45:07 2004
@@ -67,7 +67,7 @@
   U32 magic = 0;
 
   f = fopen(exe, "rb");
-  if (!f && errno == ENOFILE) {
+  if (!f && errno == ENOENT) {
 		// try appending .exe for Win2k
 	char *altexe = malloc(strlen(exe)+5);
 	strcpy(altexe, exe);
diff -ru grfcodec-orig/info.cc grfcodec/info.cc
--- grfcodec-orig/info.cc	Thu Mar 20 04:18:28 2003
+++ grfcodec/info.cc	Fri May 14 23:24:09 2004
@@ -1,5 +1,7 @@
 /* A class for dealing with .NFO files */
 
+#include <ctype.h>
+
 #include "info.h"
 #include "sprites.h"
 #include "error.h"
@@ -50,6 +52,7 @@
   lasty = -1;
 
   colourmap = NULL;
+  verbatim_str = 0;
 }
 
 inforeader::~inforeader()
@@ -248,7 +251,32 @@
 int inforeader::nextverb()
 {
   int byte;
-  fscanf(f, "%2x ", &byte);
+  //printf(": ");
+
+  byte = fgetc(f);
+  if (byte == '"') {
+	//printf("Switched quoting from %d\n", verbatim_str);
+	verbatim_str = !verbatim_str;
+
+	if (!verbatim_str) {
+		do { byte = fgetc(f); } while (isspace(byte));
+		if (byte == '"') {
+			verbatim_str = 1;
+		} else {
+			ungetc(byte, f);
+		}
+	}
+  } else {
+	ungetc(byte, f);
+  }
+
+  if (verbatim_str) {
+	byte = fgetc(f);
+	//printf("Read quoted byte %c\n", byte);
+  } else {
+        fscanf(f, "%2x ", &byte);
+	//printf("Read unquoted byte %d\n", byte);
+  }
   return byte;
 }
 
@@ -272,7 +300,7 @@
 {
   infowriter::info = info;
   fputs("// Automatically generated by GRFCODEC. Do not modify!\n", info);
-  fputs("// (Info version 4)\n", info);
+  fputs("// (Info version 5)\n", info);
   fputs("// Format: spritenum pcxfile xpos ypos compression ysize xsize xrel yrel\n", info);
 
   infowriter::maxboxes = maxboxes;
@@ -305,14 +333,32 @@
 
 		case isdata:	{
 			box::boxdata *d = &(boxes[i].data);
+			int instr = 0;
 
 			fprintf(info, "* %d\t", d->size);
 			for (j=0; j<d->size; j++) {
-				fprintf(info, " %02X", d->data[j]);
-				if ( ( (j & 31) == 31) && (j<d->size-1) )
+				if (d->data[j] < 32 || d->data[j] > 126
+				    || d->data[j] == '"') {
+					if (instr) {
+						fputs("\"", info); instr = 0;
+					}
+					fprintf(info, " %02X", d->data[j]);
+				} else {
+					if (!instr) {
+						fputs(" \"", info); instr = 1;
+					}
+					fputc(d->data[j], info);
+				}
+
+				if (((j & 31) == 31) && (j<d->size-1)) {
+					if (instr) {
+						fputs("\"", info); instr = 0;
+					}
 					fputs("\n\t", info);
+				}
 			}
 
+			if (instr) fputs("\"", info);
 			fputs("\n", info);
 			delete(d->data);
 			break;	}
diff -ru grfcodec-orig/info.h grfcodec/info.h
--- grfcodec-orig/info.h	Sat Mar  8 22:27:08 2003
+++ grfcodec/info.h	Fri May 14 22:59:37 2004
@@ -17,6 +17,7 @@
 
 	// for dealing with verbatim data
 	int verbatim;
+	int verbatim_str;
 	int nextverb();
 
 	// and for regular sprites
diff -ru grfcodec-orig/path.c grfcodec/path.c
--- grfcodec-orig/path.c	Tue Oct  1 06:25:44 2002
+++ grfcodec/path.c	Sun May  2 23:42:21 2004
@@ -46,7 +46,7 @@
 	if (dirP && *dirP)
 	    {
 		pathP = stpcopy(pathP,dirP);
-		if (*(pathP-1) != '\\' && *(pathP-1) != '/') *pathP++ = '\\';
+		if (*(pathP-1) != '\\' && *(pathP-1) != '/') *pathP++ = '/';
 	    }
 	if (nameP)
 	pathP = stpcopy(pathP,nameP);
diff -ru grfcodec-orig/pcx.cc grfcodec/pcx.cc
--- grfcodec-orig/pcx.cc	Sat May 17 21:02:30 2003
+++ grfcodec/pcx.cc	Sun May  2 23:32:42 2004
@@ -16,7 +16,7 @@
 \*****************************************/
 
 #include <stdlib.h>
-#include <mem.h>
+//#include <mem.h>
 
 #include "pcx.h"
 #include "error.h"
diff -ru grfcodec-orig/renum.pl grfcodec/renum.pl
--- grfcodec-orig/renum.pl	Tue Dec 10 18:42:34 2002
+++ grfcodec/renum.pl	Sat May  8 21:16:13 2004
@@ -12,30 +12,32 @@
 # and must be of the correct form for a .nfo file.  That is, it must have 
 # sprite numbers (though they need not be correct).
 #
+
 s#//.*## if !m#//# .. "never";
 next unless length;
+
 sub done {
-	for ($cur) {
+	for (@cur) {
 		next unless defined;
 		chomp;
 		$count = 0;
 		s/^(\s*\d+\s+\*)\s+\d+\s+/$cut=$1;''/e;
 		$count++ while /[\da-f]{2}/gi;
-		$_ = "$cut $count\t $_";
-		print;
-		$_=undef;
+		print "$cut $count\t $_";
 	}
 }
+
 if (s/^(\s*\d+)\s*\*/sprintf '%*d *',(length $1),$a++/e) {
 	done;
-	$cur.="$_$/";
+	push(@cur, $_);
 } elsif (s/^(\s*\d+\s)(?!\s*[\da-fA-F]{2}(\s|$))/sprintf '%*d ',(length $1)-1,$a++/e) {
 	done;
 	print;
-} elsif ($cur) {
-	$cur.="$_$/";
+} elsif (@cur) {
+	push(@cur, $_);
 } else {
 	done;
 	print;
 }
+
 done if eof;
diff -ru grfcodec-orig/sprites.cc grfcodec/sprites.cc
--- grfcodec-orig/sprites.cc	Tue Mar 18 03:08:36 2003
+++ grfcodec/sprites.cc	Fri May 14 23:23:55 2004
@@ -225,10 +225,10 @@
 
   if (info[0] == 0xff) {
 	store->setsize(1, 0);
-	outbuffer = (U8*) myalloc(size+1);
-	outbuffer[0] = 0xff;
-	fread(outbuffer+1, 1, size, grf);
-	writer->adddata(size, outbuffer+1);
+	outbuffer = (U8*) myalloc(size);
+	//outbuffer[0] = 0xff;
+	fread(outbuffer, 1, size, grf);
+	writer->adddata(size, outbuffer/*+1*/);
 	store->spritedone();
 	return 1;
   }
diff -ru grfcodec-orig/typesize.h grfcodec/typesize.h
--- grfcodec-orig/typesize.h	Fri Jan 17 05:03:00 2003
+++ grfcodec/typesize.h	Sun May  2 23:31:30 2004
@@ -19,9 +19,10 @@
 *                                         *
 \*****************************************/
 
-#define maketype(type,size) \
-	typedef   signed type S ## size; \
-	typedef unsigned type U ## size;
+#define strnicmp strncasecmp
+#define stricmp strcasecmp
+
+#define maketype(type,size) typedef   signed type S##size; typedef unsigned type U##size;
 
 #ifdef __BORLANDC__
 
