Patched to compile on Windows.
authorRyan C. Gordon <icculus@icculus.org>
Thu, 18 Nov 2010 22:42:58 -0500
changeset 956 7888858a6777
parent 955 9315c168a97a
child 957 c5992f4bee6d
Patched to compile on Windows.
misc/lemon.c
mojoshader_assembler.c
mojoshader_common.c
mojoshader_internal.h
utils/finderrors.c
utils/mojoshader-compiler.c
--- a/misc/lemon.c	Wed Nov 17 15:58:40 2010 -0500
+++ b/misc/lemon.c	Thu Nov 18 22:42:58 2010 -0500
@@ -26,7 +26,8 @@
 #endif
 
 #ifdef __WIN32__
-extern int access();
+//extern int access();
+#include <io.h>
 #else
 #include <unistd.h>
 #endif
--- a/mojoshader_assembler.c	Wed Nov 17 15:58:40 2010 -0500
+++ b/mojoshader_assembler.c	Thu Nov 18 22:42:58 2010 -0500
@@ -1650,7 +1650,7 @@
 
     // get the final bytecode!
     const unsigned int output_len = (unsigned int) buffer_size(ctx->output);
-    unsigned char *bytecode = buffer_flatten(ctx->output);
+    unsigned char *bytecode = (unsigned char *) buffer_flatten(ctx->output);
     buffer_destroy(ctx->output);
     ctx->output = NULL;
 
--- a/mojoshader_common.c	Wed Nov 17 15:58:40 2010 -0500
+++ b/mojoshader_common.c	Thu Nov 18 22:42:58 2010 -0500
@@ -589,7 +589,7 @@
     return buffer;
 } // buffer_create
 
-void *buffer_reserve(Buffer *buffer, const size_t len)
+char *buffer_reserve(Buffer *buffer, const size_t len)
 {
     // note that we make the blocks bigger than blocksize when we have enough
     //  data to overfill a fresh block, to reduce allocations.
@@ -607,7 +607,7 @@
             buffer->tail->bytes += len;
             buffer->total_bytes += len;
             assert(buffer->tail->bytes <= blocksize);
-            return buffer->tail->data + tailbytes;
+            return (char *) buffer->tail->data + tailbytes;
         } // if
     } // if
 
@@ -630,7 +630,7 @@
 
     buffer->total_bytes += len;
 
-    return item->data;
+    return (char *) item->data;
 } // buffer_reserve
 
 int buffer_append(Buffer *buffer, const void *_data, size_t len)
@@ -739,7 +739,7 @@
     buffer->total_bytes = 0;
 } // buffer_empty
 
-void *buffer_flatten(Buffer *buffer)
+char *buffer_flatten(Buffer *buffer)
 {
     char *retval = (char *) buffer->m(buffer->total_bytes + 1, buffer->d);
     if (retval == NULL)
@@ -764,7 +764,7 @@
     return retval;
 } // buffer_flatten
 
-void *buffer_merge(Buffer **buffers, const size_t n, size_t *_len)
+char *buffer_merge(Buffer **buffers, const size_t n, size_t *_len)
 {
     Buffer *first = NULL;
     size_t len = 0;
@@ -779,7 +779,7 @@
         len += buffer->total_bytes;
     } // for
 
-    char *retval = (char *) first ? first->m(len + 1, first->d) : NULL;
+    char *retval = (char *) (first ? first->m(len + 1, first->d) : NULL);
     if (retval == NULL)
     {
         *_len = 0;
--- a/mojoshader_internal.h	Wed Nov 17 15:58:40 2010 -0500
+++ b/mojoshader_internal.h	Thu Nov 18 22:42:58 2010 -0500
@@ -85,13 +85,22 @@
 #include <malloc.h>
 #define va_copy(a, b) a = b
 #define snprintf _snprintf  // !!! FIXME: not a safe replacement!
+#define vsnprintf _vsnprintf  // !!! FIXME: not a safe replacement!
 #define strcasecmp stricmp
+#define strncasecmp strnicmp
 typedef unsigned __int8 uint8;
 typedef unsigned __int16 uint16;
 typedef unsigned __int32 uint32;
 typedef unsigned __int64 uint64;
 typedef __int32 int32;
 typedef __int64 int64;
+#ifdef _WIN64
+typedef __int64 ssize_t;
+#elif defined _WIN32
+typedef __int32 ssize_t;
+#else
+#error Please define your platform.
+#endif
 // Warning Level 4 considered harmful.  :)
 #pragma warning(disable: 4100)  // "unreferenced formal parameter"
 #pragma warning(disable: 4389)  // "signed/unsigned mismatch"
@@ -214,14 +223,14 @@
 
 typedef struct Buffer Buffer;
 Buffer *buffer_create(size_t blksz,MOJOSHADER_malloc m,MOJOSHADER_free f,void *d);
-void *buffer_reserve(Buffer *buffer, const size_t len);
+char *buffer_reserve(Buffer *buffer, const size_t len);
 int buffer_append(Buffer *buffer, const void *_data, size_t len);
 int buffer_append_fmt(Buffer *buffer, const char *fmt, ...) ISPRINTF(2,3);
 int buffer_append_va(Buffer *buffer, const char *fmt, va_list va);
 size_t buffer_size(Buffer *buffer);
 void buffer_empty(Buffer *buffer);
-void *buffer_flatten(Buffer *buffer);
-void *buffer_merge(Buffer **buffers, const size_t n, size_t *_len);
+char *buffer_flatten(Buffer *buffer);
+char *buffer_merge(Buffer **buffers, const size_t n, size_t *_len);
 void buffer_destroy(Buffer *buffer);
 ssize_t buffer_find(Buffer *buffer, const size_t start,
                     const void *data, const size_t len);
--- a/utils/finderrors.c	Wed Nov 17 15:58:40 2010 -0500
+++ b/utils/finderrors.c	Thu Nov 18 22:42:58 2010 -0500
@@ -132,10 +132,17 @@
     }
     #else
     const MOJOSHADER_parseData *pd = MOJOSHADER_parse(profile, buf, rc, NULL, 0, NULL, NULL, NULL);
-    if (pd->error != NULL)
-        report("FAIL: %s (position %d) %s\n", fname, pd->error_position, pd->error);
-    else
+    if (pd->error_count == 0)
         report("PASS: %s\n", fname);
+	else
+	{
+		int i;
+		for (i = 0; i < pd->error_count; i++)
+		{
+			report("FAIL: %s (position %d) %s\n", pd->errors[i].filename,
+			       pd->errors[i].error_position, pd->errors[i].error);
+		} // for
+	} // else
     MOJOSHADER_freeParseData(pd);
     #endif
 
--- a/utils/mojoshader-compiler.c	Wed Nov 17 15:58:40 2010 -0500
+++ b/utils/mojoshader-compiler.c	Thu Nov 18 22:42:58 2010 -0500
@@ -14,8 +14,8 @@
 
 #include "mojoshader.h"
 
-#ifndef _WIN32
-#define stricmp(a,b) strcasecmp(a,b)
+#ifdef _WIN32
+#define snprintf _snprintf   // !!! FIXME: not a safe replacement!
 #endif
 
 static const char **include_paths = NULL;