The new file format filters use types and POSIX functions that are not defined
by some of libmodplug's supported platforms, namely MINGW's version of GCC.

Convert these incorrect types, and at the same time provide a better win32
compatibility library which these files can be converted to use.

--ajs.

Index: libmodplug/src/load_abc.cpp
===================================================================
RCS file: /cvsroot/megazeux/megazeux2/contrib/libmodplug/src/load_abc.cpp,v
retrieving revision 1.1
diff -u -d -r1.1 load_abc.cpp
--- libmodplug/src/load_abc.cpp	19 Apr 2007 02:26:02 -0000	1.1
+++ libmodplug/src/load_abc.cpp	19 Apr 2007 03:27:03 -0000
@@ -29,7 +29,6 @@
 #include <string.h>
 #include <math.h>
 #include <ctype.h>
-#include <unistd.h> // for sleep
 
 #ifdef NEWMIKMOD
 #include "mikmod.h"
@@ -2333,24 +2332,24 @@
 			if( *p == '-' ) {
 #ifdef NEWMIKMOD
 				retval->pickrandom = atoi(p+1);
-				sprintf(buf,"-%ld",retval->pickrandom+1);
+				sprintf(buf,"%s=-%ld",ABC_ENV_NORANDOMPICK,retval->pickrandom+1);
 #else
 				retval->pickrandom = atoi(p+1)-1; // xmms preloads the file
-				sprintf(buf,"-%ld",retval->pickrandom+2);
+				sprintf(buf,"%s=-%ld",ABC_ENV_NORANDOMPICK,retval->pickrandom+2);
 #endif
-				setenv(ABC_ENV_NORANDOMPICK, buf, 1);
+				putenv(buf);
 			}
 		}
 		else {
-			srandom(time(0));	// initialize random generator with seed
-			retval->pickrandom = 1+(int)(10000.0*random()/(RAND_MAX+1.0));
+			srand(time(NULL)); // initialize random generator with seed
+			retval->pickrandom = 1+(int)(10000.0*rand()/(RAND_MAX+1.0));
 			// can handle pickin' from songbooks with 10.000 songs
 #ifdef NEWMIKMOD
-			sprintf(buf,"-%ld",retval->pickrandom+1); // next in sequence
+			sprintf(buf,"%s=-%ld",ABC_ENV_NORANDOMPICK,retval->pickrandom+1); // next in sequence
 #else
-			sprintf(buf,"-%ld",retval->pickrandom); // xmms preloads the file
+			sprintf(buf,"%s=-%ld",ABC_ENV_NORANDOMPICK,retval->pickrandom); // xmms preloads the file
 #endif
-			setenv(ABC_ENV_NORANDOMPICK, buf, 1);
+			putenv(buf);
 		}
     return retval;
 }
@@ -3713,10 +3712,10 @@
 #define m_nDefaultTempo	of->inittempo
 #else
 	ABCHANDLE *h;
-	uint numpat;
+	UINT numpat;
 	MMFILE mm, *mmfile;
 #endif
-	uint t;
+	UINT t;
 	char	*line, *p, *pp, ch, ch0=0;
 	char barsig[52];	// for propagated accidental key signature within bar
 	char *abcparts;
@@ -5023,7 +5022,7 @@
 	m_nMinPeriod    = 28 << 2;
 	m_nMaxPeriod    = 1712 << 3;
 	// orderlist
-	for(t=0; t < (uint)orderlen; t++)
+	for(t=0; t < (UINT)orderlen; t++)
 		Order[t] = orderlist[t];
 	free(orderlist);	// get rid of orderlist memory
 #endif
Index: libmodplug/src/load_mid.cpp
===================================================================
RCS file: /cvsroot/megazeux/megazeux2/contrib/libmodplug/src/load_mid.cpp,v
retrieving revision 1.1
diff -u -d -r1.1 load_mid.cpp
--- libmodplug/src/load_mid.cpp	19 Apr 2007 02:26:02 -0000	1.1
+++ libmodplug/src/load_mid.cpp	19 Apr 2007 03:27:04 -0000
@@ -1408,7 +1408,7 @@
 #endif
 	int ch, dmulti, maxtempo, panlow, panhigh, numchans, numtracks;
 	MIDTRACK *ttp;
-	uint t, numpats;
+	UINT t, numpats;
 	char buf[256];
 	long miditracklen;
 	BYTE runningstatus;
@@ -1493,7 +1493,7 @@
 		printf("Multiplying resolution and deltatimes by %d to get %d miditicks per patternrow\n",
 			dmulti, h->midispeed);
 	}
-	for( t=0; t<(uint)h->miditracks; t++ ) {
+	for( t=0; t<(UINT)h->miditracks; t++ ) {
 		if( h->verbose ) printf("Parsing track %d\n", t+1);
 		mmreadSBYTES(buf,4,h->mmf);
 		buf[4] = '\0';
Index: libmodplug/src/load_pat.cpp
===================================================================
RCS file: /cvsroot/megazeux/megazeux2/contrib/libmodplug/src/load_pat.cpp,v
retrieving revision 1.1
diff -u -d -r1.1 load_pat.cpp
--- libmodplug/src/load_pat.cpp	19 Apr 2007 02:26:03 -0000	1.1
+++ libmodplug/src/load_pat.cpp	19 Apr 2007 03:27:04 -0000
@@ -1289,7 +1289,7 @@
 // =====================================================================================
 BOOL PAT_Load_Instruments(void *c)
 {
-	uint t;
+	UINT t;
 #ifdef NEWMIKMOD
 	UNIMOD *of = (UNIMOD *)c;
 	INSTRUMENT *d;
Index: libmodplug/src/libmodplug/stdafx.h
===================================================================
RCS file: /cvsroot/megazeux/megazeux2/contrib/libmodplug/src/libmodplug/stdafx.h,v
retrieving revision 1.3
diff -u -d -r1.3 stdafx.h
--- libmodplug/src/libmodplug/stdafx.h	19 Apr 2007 02:26:03 -0000	1.3
+++ libmodplug/src/libmodplug/stdafx.h	19 Apr 2007 03:27:04 -0000
@@ -9,7 +9,6 @@
 #ifndef _STDAFX_H_
 #define _STDAFX_H_
 
-
 #ifdef MSC_VER
 
 #pragma warning (disable:4201)
@@ -37,6 +36,17 @@
 #include <stdio.h>
 #include <string.h>
 
+#ifdef __WIN32__
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+#define sleep Sleep
+
+#else // !__WIN32__
+
+#include <unistd.h> // for sleep()
+
 typedef int8_t CHAR;
 typedef uint8_t UCHAR;
 typedef uint8_t* PUCHAR;
@@ -59,6 +69,16 @@
 typedef void* PVOID;
 typedef void VOID;
 
+#define lstrcpyn	strncpy
+#define lstrcpy		strcpy
+#define lstrcmp		strcmp
+#define wsprintf	sprintf
+#define strnicmp(a,b,c)	strncasecmp(a,b,c)
+
+#define GHND		0
+
+#endif // !__WIN32__
+
 inline LONG MulDiv (long a, long b, long c)
 {
   // if (!c) return 0;
@@ -68,14 +88,9 @@
 #define MODPLUG_NO_FILESAVE
 #define NO_AGC
 #define LPCTSTR LPCSTR
-#define lstrcpyn strncpy
-#define lstrcpy strcpy
-#define lstrcmp strcmp
 #define WAVE_FORMAT_PCM 1
 //#define ENABLE_EQ
 
-#define  GHND   0
-
 inline int8_t * GlobalAllocPtr(unsigned int, size_t size)
 {
   int8_t * p = (int8_t *) malloc(size);
@@ -88,9 +103,6 @@
 
 #define GlobalFreePtr(p) free((void *)(p))
 
-#define strnicmp(a,b,c)		strncasecmp(a,b,c)
-#define wsprintf			sprintf
-
 #ifndef FALSE
 #define FALSE	false
 #endif
@@ -102,6 +114,3 @@
 #endif // MSC_VER
 
 #endif
-
-
-
