From 3c003bc168fe47f3e7ce08328782f969b59d89a3 Mon Sep 17 00:00:00 2001 From: Dale Weiler Date: Fri, 21 Dec 2012 01:00:51 -0500 Subject: [PATCH] Get gmqcc/qcvm compiling on windows again. Plus work in progress support for the testsuite on windows (does not compile yet). --- conout.c | 3 +- exec.c | 16 --- ftepp.c | 2 +- gmqcc.h | 38 ++++- msvc/gmqcc.sln | 32 +++++ gmqcc.vcxproj => msvc/gmqcc.vcxproj | 212 +++++++++++----------------- msvc/qcvm.vcxproj | 87 ++++++++++++ msvc/testsuite.vcxproj | 73 ++++++++++ test.c | 83 ++++++++++- 9 files changed, 388 insertions(+), 158 deletions(-) create mode 100644 msvc/gmqcc.sln rename gmqcc.vcxproj => msvc/gmqcc.vcxproj (51%) mode change 100755 => 100644 create mode 100644 msvc/qcvm.vcxproj create mode 100644 msvc/testsuite.vcxproj diff --git a/conout.c b/conout.c index 169aaa7..ff012c7 100644 --- a/conout.c +++ b/conout.c @@ -110,7 +110,6 @@ static void win_fputs(char *str, FILE *h) { int icolor; int state; - int place; /* attributes */ int intense = -1; @@ -219,7 +218,7 @@ static int con_write(FILE *handle, const char *fmt, va_list va) { data[ln] = 0; vsprintf(data, fmt, va); if (GMQCC_IS_DEFINE(handle)) - ln = win_fputs(data, handle); + win_fputs(data, handle); else ln = fputs(data, handle); free(data); diff --git a/exec.c b/exec.c index 5af6785..6e51c02 100644 --- a/exec.c +++ b/exec.c @@ -29,22 +29,6 @@ #include "gmqcc.h" -/* -(prog_section_statement, code) -(prog_section_def, defs) -(prog_section_def, fields) -(prog_section_function, functions) -(char, strings) -(qcint, globals) -(qcint, entitydata) -(bool, entitypool) -(qcint, localstack) -(qc_exec_stack, stack) -(size_t, profile) -(prog_builtin, builtins) -(const char*, function_stack) -*/ - static void loaderror(const char *fmt, ...) { int err = errno; diff --git a/ftepp.c b/ftepp.c index 3235147..96c20bf 100644 --- a/ftepp.c +++ b/ftepp.c @@ -217,7 +217,7 @@ static void ftepp_macro_delete(ftepp_t *ftepp, const char *name) } } -static inline int ftepp_next(ftepp_t *ftepp) +static GMQCC_INLINE int ftepp_next(ftepp_t *ftepp) { return (ftepp->token = lex_do(ftepp->lex)); } diff --git a/gmqcc.h b/gmqcc.h index 71873dc..4c4d129 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -39,6 +39,7 @@ # pragma warning(disable : 4018 ) /* signed/unsigned mismatch */ # pragma warning(disable : 4996 ) /* This function or variable may be unsafe */ # pragma warning(disable : 4700 ) /* uninitialized local variable used */ +# pragma warning(disable : 4129 ) /* unrecognized character secape sequence */ #endif #define GMQCC_VERSION_MAJOR 0 @@ -134,11 +135,31 @@ # define GMQCC_NORETURN #endif -/* TODO: visual studiblows work around */ #ifndef _MSC_VER # include +#else + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + typedef unsigned __int64 uint64_t; + + typedef __int16 int16_t; + typedef __int32 int32_t; + typedef __int64 int64_t; +#endif + +/* + *windows makes these prefixed because they're C99 + * TODO: utility versions that are type-safe and not + * just plain textual subsitution. + */ +#ifdef _MSC_VER +# define snprintf(X, Y, Z, ...) _snprintf(X, Y, Z, __VA_ARGS__) + /* strtof doesn't exist -> strtod does though :) */ +# define strtof(X, Y) (float)(strtod(X, Y)) #endif + /* * Very roboust way at determining endianess at compile time: this handles * almost every possible situation. Otherwise a runtime check has to be @@ -263,7 +284,7 @@ uint32_t util_crc32(uint32_t crc, const char *data, size_t len); /* * TODO: make these safer to use. Currently this only works on * x86 and x86_64, some systems will likely not like this. Such - * as BE systems. + * as BE systems. (and clean this up to use a structure ... ) */ #define FLT2INT(Y) *((int32_t*)&(Y)) #define INT2FLT(Y) *((float *)&(Y)) @@ -290,6 +311,7 @@ void _util_vec_grow(void **a, size_t i, size_t s); #define vec_shrinkto(A,N) (_vec_end(A) = (N)) #define vec_shrinkby(A,N) (_vec_end(A) -= (N)) +/* vec_upload needs to be cleaned up as well to be a function */ #define vec_upload(X,Y,S) \ do { \ size_t E = 0; \ @@ -365,11 +387,10 @@ enum { }; /* const/var qualifiers */ -#define CV_NONE 0 -#define CV_CONST 1 -#define CV_VAR -1 -/* magic number to help parsing */ -#define CV_WRONG 0x8000 +#define CV_NONE 0 +#define CV_CONST 1 +#define CV_VAR -1 +#define CV_WRONG 0x8000 /* magic number to help parsing */ extern const char *type_name [TYPE_COUNT]; extern uint16_t type_store_instr [TYPE_COUNT]; @@ -580,6 +601,7 @@ enum { VINSTR_NRCALL }; +/* TODO: cleanup this mess */ extern prog_section_statement *code_statements; extern int *code_linenums; extern prog_section_def *code_defs; @@ -589,6 +611,7 @@ extern int *code_globals; extern char *code_chars; extern uint16_t code_crc; +/* uhh? */ typedef float qcfloat; typedef int32_t qcint; @@ -663,6 +686,7 @@ bool GMQCC_WARN vcompile_warning(lex_ctx ctx, int warntype, const char *fmt, va_ /*===================================================================*/ /*========================= assembler.c =============================*/ /*===================================================================*/ +/* TODO: remove this ... */ static const struct { const char *m; /* menomic */ const size_t o; /* operands */ diff --git a/msvc/gmqcc.sln b/msvc/gmqcc.sln new file mode 100644 index 0000000..8d3de2e --- /dev/null +++ b/msvc/gmqcc.sln @@ -0,0 +1,32 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "qcvm", "qcvm.vcxproj", "{8DC505A6-6047-4683-BA81-BC4B7A839352}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gmqcc", "gmqcc.vcxproj", "{0F0B0779-1A2F-43E9-B833-18C443F7229E}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsuite", "testsuite.vcxproj", "{3F8F0021-66B8-43ED-906C-1CFE204E5673}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {8DC505A6-6047-4683-BA81-BC4B7A839352}.Debug|Win32.ActiveCfg = Debug|Win32 + {8DC505A6-6047-4683-BA81-BC4B7A839352}.Debug|Win32.Build.0 = Debug|Win32 + {8DC505A6-6047-4683-BA81-BC4B7A839352}.Release|Win32.ActiveCfg = Release|Win32 + {8DC505A6-6047-4683-BA81-BC4B7A839352}.Release|Win32.Build.0 = Release|Win32 + {0F0B0779-1A2F-43E9-B833-18C443F7229E}.Debug|Win32.ActiveCfg = Debug|Win32 + {0F0B0779-1A2F-43E9-B833-18C443F7229E}.Debug|Win32.Build.0 = Debug|Win32 + {0F0B0779-1A2F-43E9-B833-18C443F7229E}.Release|Win32.ActiveCfg = Release|Win32 + {0F0B0779-1A2F-43E9-B833-18C443F7229E}.Release|Win32.Build.0 = Release|Win32 + {3F8F0021-66B8-43ED-906C-1CFE204E5673}.Debug|Win32.ActiveCfg = Debug|Win32 + {3F8F0021-66B8-43ED-906C-1CFE204E5673}.Debug|Win32.Build.0 = Debug|Win32 + {3F8F0021-66B8-43ED-906C-1CFE204E5673}.Release|Win32.ActiveCfg = Release|Win32 + {3F8F0021-66B8-43ED-906C-1CFE204E5673}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/gmqcc.vcxproj b/msvc/gmqcc.vcxproj old mode 100755 new mode 100644 similarity index 51% rename from gmqcc.vcxproj rename to msvc/gmqcc.vcxproj index 40111c9..8c03288 --- a/gmqcc.vcxproj +++ b/msvc/gmqcc.vcxproj @@ -1,131 +1,83 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - - {85C266A8-7938-4AE6-AB64-428DC32B1ACD} - gmqcc - - - - Application - true - NotSet - - - Application - false - true - NotSet - - - - - - - - - - - - - .\ - - - .\ - - - gmqcc - false - - - . - - - . - - - gmqcc - false - - - - Level3 - Disabled - .\;%(AdditionalIncludeDirectories) - false - false - Fast - - - - - - - true - - - $(TargetName).pdb - Console - - - - - Level3 - MaxSpeed - true - true - .\;%(AdditionalIncludeDirectories) - false - false - Fast - - - - - - - true - true - true - - - $(TargetName).pdb - Console - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + Debug + Win32 + + + Release + Win32 + + + + {0F0B0779-1A2F-43E9-B833-18C443F7229E} + gmqcc + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + + + true + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/qcvm.vcxproj b/msvc/qcvm.vcxproj new file mode 100644 index 0000000..48d06df --- /dev/null +++ b/msvc/qcvm.vcxproj @@ -0,0 +1,87 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {8DC505A6-6047-4683-BA81-BC4B7A839352} + qcvm + + + + Application + true + Unicode + false + true + + + Application + false + true + Unicode + + + + + + + + + + + + + + + Level3 + Full + .;%(AdditionalIncludeDirectories) + AnySuitable + Speed + true + true + QCVM_EXECUTOR=1;%(PreprocessorDefinitions) + + + true + + + + + Level3 + Full + true + true + .;%(AdditionalIncludeDirectories) + AnySuitable + Speed + true + true + QCVM_EXECUTOR=1;%(PreprocessorDefinitions) + + + true + true + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/msvc/testsuite.vcxproj b/msvc/testsuite.vcxproj new file mode 100644 index 0000000..cfe055f --- /dev/null +++ b/msvc/testsuite.vcxproj @@ -0,0 +1,73 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {3F8F0021-66B8-43ED-906C-1CFE204E5673} + testsuite + + + + Application + true + MultiByte + + + Application + false + true + MultiByte + + + + + + + + + + + + + + + Level3 + Disabled + + + true + + + + + Level3 + MaxSpeed + true + true + + + true + true + true + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test.c b/test.c index 6ca4fec..ed0abc1 100644 --- a/test.c +++ b/test.c @@ -23,7 +23,6 @@ #include "gmqcc.h" #include #include -#include opts_cmd_t opts; @@ -50,6 +49,7 @@ char *task_bins[] = { #ifndef _WIN32 #include #include +#include #include typedef struct { FILE *handles[3]; @@ -156,7 +156,86 @@ int task_pclose(FILE **handles) { return status; } #else -#error "There is no support for windows yet ... this is not a FTBFS bug" +# ifdef __MINGW32__ + /* mingw32 has dirent.h */ +# include +# elif defined (_MSC_VER) +# define _WIN32_LEAN_AND_MEAN +# include +# include + /* + * visual studio lacks dirent.h it's a posix thing + * so we emulate it with the WinAPI. + */ + + struct dirent { + long d_ino; + unsigned short d_reclen; + unsigned short d_namlen; + char d_name[FILENAME_MAX]; + }; + + typedef struct { + struct _finddata_t dd_dta; + struct dirent dd_dir; + long dd_handle; + int dd_stat; + char dd_name[1]; + } DIR; + + DIR *opendir(const char *name) { + DIR *dir = (DIR*)mem_a(sizeof(DIR) + strlen(name)); + if (!dir) + return NULL; + + strcpy(dir->dd_name, name); + return dir; + } + + int closedir(DIR *dir) { + FindClose((HANDLE)dir->dd_handle); + mem_d ((void*)dir); + return 0; + } + + struct dirent *readdir(DIR *dir) { + WIN32_FIND_DATA info; + struct dirent *data; + int rets; + + if (!dir->dd_handle) { + char *dirname; + if (*dir->dd_name) { + size_t n = strlen(dir->dd_name); + if ((dirname = (char*)mem_a(n + 5) /* 4 + 1 */)) { + strcpy(dirname, dir->dd_name); + strcpy(dirname + n, "\\*.*"); /* 4 + 1 */ + } + } else { + if (!(dirname = util_strdup("\\*.*"))) + return NULL; + } + + dir->dd_handle = (long)FindFirstFile(dirname, &info); + mem_d(dirname); + rets = !(!dir->dd_handle); + } else if (dir->dd_handle != -11) { + rets = FindNextFile ((HANDLE)dir->dd_handle, &info); + } else { + rets = 0; + } + + if (!rets) + return NULL; + + if ((data = (struct dirent*)mem_a(sizeof(struct dirent)))) { + strncpy(data->d_name, info.cFileName, FILENAME_MAX - 1); + data->d_name[FILENAME_MAX - 1] = '\0'; /* terminate */ + data->d_namlen = strlen(data->d_name); + } + return data; + } +# endif #endif #define TASK_COMPILE 0 -- 2.39.2