From: Dale Weiler Date: Fri, 21 Dec 2012 11:13:16 +0000 (-0500) Subject: Windows stuff for visual studio now offical works with exception to colorized output... X-Git-Tag: 0.2~22 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fgmqcc.git;a=commitdiff_plain;h=88fee022287e327b1959fceb872e16255038c355 Windows stuff for visual studio now offical works with exception to colorized output to cmd (which actually should work). As well as the testsuite which lacks implementations of task_popen/task_pclose. --- diff --git a/conout.c b/conout.c index ff012c7..b8227e5 100644 --- a/conout.c +++ b/conout.c @@ -77,7 +77,7 @@ enum { MAGENTA, CYAN, GRAY, - WHITE + WHITE = GRAY }; enum { @@ -90,9 +90,9 @@ enum { WMAGENTA = WBLUE | WRED, WYELLOW = WGREEN | WRED, WWHITE = WBLUE | WGREEN | WRED -} +}; -static const ansi2win[] = { +static const int ansi2win[] = { WBLACK, WRED, WGREEN, @@ -103,7 +103,7 @@ static const ansi2win[] = { WWHITE }; -static void win_fputs(char *str, FILE *h) { +static int win_fputs(const char *str, FILE *h) { /* state for translate */ int acolor; int wcolor; @@ -115,7 +115,7 @@ static void win_fputs(char *str, FILE *h) { int intense = -1; int colors[] = {-1, -1 }; int colorpos = 1; - + int length = 0; CONSOLE_SCREEN_BUFFER_INFO cinfo; GetConsoleScreenBufferInfo ( (GMQCC_IS_STDOUT(h)) ? @@ -125,9 +125,9 @@ static void win_fputs(char *str, FILE *h) { icolor = cinfo.wAttributes; while (*str) { - if (*str == '\e') - state = '\e'; - else if (state == '\e' && *str == '[') + if (*str == '\x1B') + state = '\x1B'; + else if (state == '\x1B' && *str == '[') state = '['; else if (state == '[') { if (*str != 'm') { @@ -148,7 +148,7 @@ static void win_fputs(char *str, FILE *h) { intense = WBLACK; wcolor = icolor; } - else if (BLACK < acolor && acolor <= WHITE) + else if (BLACK <= acolor && acolor <= WHITE) wcolor = ansi2win[acolor - 30]; else if (acolor == 90) { /* special gray really white man */ @@ -157,7 +157,7 @@ static void win_fputs(char *str, FILE *h) { } SetConsoleTextAttribute ( - (h == stdout) ? + (GMQCC_IS_STDOUT(h)) ? GetStdHandle(STD_OUTPUT_HANDLE) : GetStdHandle(STD_ERROR_HANDLE), @@ -168,7 +168,9 @@ static void win_fputs(char *str, FILE *h) { } } else { fputc(*str, h); + length ++; } + str++; } /* restore */ SetConsoleTextAttribute( @@ -177,6 +179,7 @@ static void win_fputs(char *str, FILE *h) { GetStdHandle(STD_ERROR_HANDLE), icolor ); + return length; } #endif @@ -212,16 +215,10 @@ static int con_write(FILE *handle, const char *fmt, va_list va) { ln = vfprintf(handle, fmt, va); #else { - char *data = NULL; - ln = _vscprintf(fmt, va); - data = malloc(ln + 1); - data[ln] = 0; - vsprintf(data, fmt, va); - if (GMQCC_IS_DEFINE(handle)) - win_fputs(data, handle); - else - ln = fputs(data, handle); - free(data); + char data[4096]; + memset(data, 0, sizeof(data)); + vsnprintf(data, sizeof(data), fmt, va); + ln = (GMQCC_IS_DEFINE(handle)) ? win_fputs(data, handle) : fputs(data, handle); } #endif return ln; diff --git a/gmqcc.h b/gmqcc.h index 4c4d129..169995f 100644 --- a/gmqcc.h +++ b/gmqcc.h @@ -77,6 +77,8 @@ # endif /* !__STDC_VERSION__ */ #endif /* !__cplusplus */ + + /* * Of some functions which are generated we want to make sure * that the result isn't ignored. To find such function calls, @@ -271,14 +273,42 @@ size_t util_strtononcmd (const char *, char *, size_t); uint16_t util_crc16(uint16_t crc, const char *data, size_t len); uint32_t util_crc32(uint32_t crc, const char *data, size_t len); +/* + * If we're compiling as C++ code we need to fix some subtle issues regarding casts between mem_a/mem_d + * since C++ doesn't allow implicit conversions between void* + */ +#ifdef __cplusplus + /* + * void * will be implicitally converted to gmqcc_voidptr using gmqcc_voidptr(void*). This is what + * essentially allows us to allow implicit conversion to whatever pointer type we're trying to assign + * to because it acks as a default assignment constructor. + */ + class gmqcc_voidptr { + void *m_pointer; + public: + gmqcc_voidptr(void *pointer) : + m_pointer(pointer) + { }; + + template + GMQCC_INLINE operator T *() { + return m_pointer; + } + }; + +# define GMQCC_IMPLICIT_POINTER(X) (gmqcc_voidptr(X)) +#else +# define GMQCC_IMPLICIT_POINTER(X) (X) +#endif + #ifdef NOTRACK -# define mem_a(x) malloc (x) -# define mem_d(x) free (x) -# define mem_r(x, n) realloc(x, n) +# define mem_a(x) GMQCC_IMPLICIT_POINTER(malloc (x)) +# define mem_d(x) free ((void*)x) +# define mem_r(x, n) realloc((void*)x, n) #else -# define mem_a(x) util_memory_a((x), __LINE__, __FILE__) -# define mem_d(x) util_memory_d((x), __LINE__, __FILE__) -# define mem_r(x, n) util_memory_r((x), (n), __LINE__, __FILE__) +# define mem_a(x) GMQCC_IMPLICIT_POINTER(util_memory_a((x), __LINE__, __FILE__)) +# define mem_d(x) util_memory_d((void*)(x), __LINE__, __FILE__) +# define mem_r(x, n) util_memory_r((void*)(x), (n), __LINE__, __FILE__) #endif /* diff --git a/msvc/gmqcc.sln b/msvc/gmqcc.sln index 8d3de2e..b87c6f4 100644 --- a/msvc/gmqcc.sln +++ b/msvc/gmqcc.sln @@ -9,20 +9,13 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testsuite", "testsuite.vcxp 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 diff --git a/msvc/gmqcc.vcxproj b/msvc/gmqcc.vcxproj index 8c03288..d8f46a8 100644 --- a/msvc/gmqcc.vcxproj +++ b/msvc/gmqcc.vcxproj @@ -1,10 +1,6 @@  - - Debug - Win32 - Release Win32 @@ -13,13 +9,9 @@ {0F0B0779-1A2F-43E9-B833-18C443F7229E} gmqcc + false - - Application - true - MultiByte - Application false @@ -29,23 +21,13 @@ - - - - - - - Level3 - Disabled - - - true - - + + false + Level3 @@ -54,22 +36,35 @@ true - true + false true true + + + + Del /Q "$(IntDir)\*.tlog" + - - - + + $(IntDir) + + + $(IntDir) + + + $(IntDir)conout_gmqcc.o + - + + $(IntDir)util_gmqcc.o + diff --git a/msvc/qcvm.vcxproj b/msvc/qcvm.vcxproj index 48d06df..5382279 100644 --- a/msvc/qcvm.vcxproj +++ b/msvc/qcvm.vcxproj @@ -1,10 +1,6 @@  - - Debug - Win32 - Release Win32 @@ -13,15 +9,9 @@ {8DC505A6-6047-4683-BA81-BC4B7A839352} qcvm + false - - Application - true - Unicode - false - true - Application false @@ -31,29 +21,10 @@ - - - - - - - Level3 - Full - .;%(AdditionalIncludeDirectories) - AnySuitable - Speed - true - true - QCVM_EXECUTOR=1;%(PreprocessorDefinitions) - - - true - - Level3 @@ -72,11 +43,20 @@ true true + + Del /Q "$(IntDir)\*.tlog" + - - - + + $(IntDir)conout_qcvm.o + + + $(IntDir) + + + $(IntDir)util_qcvm.o + diff --git a/msvc/testsuite.vcxproj b/msvc/testsuite.vcxproj index cfe055f..3e77231 100644 --- a/msvc/testsuite.vcxproj +++ b/msvc/testsuite.vcxproj @@ -1,10 +1,6 @@  - - Debug - Win32 - Release Win32 @@ -13,13 +9,9 @@ {3F8F0021-66B8-43ED-906C-1CFE204E5673} testsuite + false - - Application - true - MultiByte - Application false @@ -29,23 +21,9 @@ - - - - - - - - Level3 - Disabled - - - true - - Level3 @@ -58,11 +36,18 @@ true true + + Del /Q "$(IntDir)\*.tlog" + - + + $(IntDir)conout_testsuite.o + - + + $(IntDir)util_testsuite.o +