Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Patched to compile on Windows.
  • Loading branch information
icculus committed Nov 19, 2010
1 parent a3bcff8 commit 8a333d7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 16 deletions.
3 changes: 2 additions & 1 deletion misc/lemon.c
Expand Up @@ -26,7 +26,8 @@
#endif

#ifdef __WIN32__
extern int access();
//extern int access();
#include <io.h>
#else
#include <unistd.h>
#endif
Expand Down
2 changes: 1 addition & 1 deletion mojoshader_assembler.c
Expand Up @@ -1650,7 +1650,7 @@ static const MOJOSHADER_parseData *build_final_assembly(Context *ctx)

// 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;

Expand Down
12 changes: 6 additions & 6 deletions mojoshader_common.c
Expand Up @@ -589,7 +589,7 @@ Buffer *buffer_create(size_t blksz, MOJOSHADER_malloc m,
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.
Expand All @@ -607,7 +607,7 @@ void *buffer_reserve(Buffer *buffer, const size_t len)
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

Expand All @@ -630,7 +630,7 @@ void *buffer_reserve(Buffer *buffer, const size_t len)

buffer->total_bytes += len;

return item->data;
return (char *) item->data;
} // buffer_reserve

int buffer_append(Buffer *buffer, const void *_data, size_t len)
Expand Down Expand Up @@ -739,7 +739,7 @@ void buffer_empty(Buffer *buffer)
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)
Expand All @@ -764,7 +764,7 @@ void *buffer_flatten(Buffer *buffer)
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;
Expand All @@ -779,7 +779,7 @@ void *buffer_merge(Buffer **buffers, const size_t n, size_t *_len)
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;
Expand Down
15 changes: 12 additions & 3 deletions mojoshader_internal.h
Expand Up @@ -85,13 +85,22 @@ typedef unsigned int uint; // this is a printf() helper. don't use for code.
#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"
Expand Down Expand Up @@ -214,14 +223,14 @@ void errorlist_destroy(ErrorList *list);

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);
Expand Down
13 changes: 10 additions & 3 deletions utils/finderrors.c
Expand Up @@ -132,10 +132,17 @@ static int do_file(const char *profile, const char *dname, const char *fn, int *
}
#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

Expand Down
4 changes: 2 additions & 2 deletions utils/mojoshader-compiler.c
Expand Up @@ -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;
Expand Down

0 comments on commit 8a333d7

Please sign in to comment.