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	Sat May  8 21:17:11 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);
@@ -345,7 +340,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 +349,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 +579,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/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	Sun May  2 23:53:27 2004
@@ -228,7 +228,7 @@
 	outbuffer = (U8*) myalloc(size+1);
 	outbuffer[0] = 0xff;
 	fread(outbuffer+1, 1, size, grf);
-	writer->adddata(size, outbuffer+1);
+	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__
 
