]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
Windows stuff for visual studio now offical works with exception to colorized output...
authorDale Weiler <killfieldengine@gmail.com>
Fri, 21 Dec 2012 11:13:16 +0000 (06:13 -0500)
committerDale Weiler <killfieldengine@gmail.com>
Fri, 21 Dec 2012 11:16:08 +0000 (06:16 -0500)
conout.c
gmqcc.h
msvc/gmqcc.sln
msvc/gmqcc.vcxproj
msvc/qcvm.vcxproj
msvc/testsuite.vcxproj

index ff012c72067fbb6d7a4e34d97ee3aebc88690121..b8227e5b07b882401bb5387d7abeaab2bd27a5b1 100644 (file)
--- 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 4c4d129df3aa868f251274962911c81fd4ce1d14..169995f31b93bb5142b39331f593854e2fb09816 100644 (file)
--- 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 <typename T>
+            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
 
 /*
index 8d3de2ef15845ccb367ea5474955f455d63db127..b87c6f43d604f25451bbd9e629010f46dd775ebd 100644 (file)
@@ -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
index 8c0328837dcea41cd467ca504b56b048f2310b63..d8f46a84482dcbef1263fba93a3ccd08ca95264f 100644 (file)
@@ -1,10 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
     <ProjectConfiguration Include="Release|Win32">
       <Configuration>Release</Configuration>
       <Platform>Win32</Platform>
@@ -13,13 +9,9 @@
   <PropertyGroup Label="Globals">
     <ProjectGuid>{0F0B0779-1A2F-43E9-B833-18C443F7229E}</ProjectGuid>
     <RootNamespace>gmqcc</RootNamespace>
+    <TrackFileAccess>false</TrackFileAccess>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
   </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   </ImportGroup>
   <PropertyGroup Label="UserMacros" />
-  <PropertyGroup />
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
+  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+    <EmbedManifest>false</EmbedManifest>
+  </PropertyGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
       <WarningLevel>Level3</WarningLevel>
       <IntrinsicFunctions>true</IntrinsicFunctions>
     </ClCompile>
     <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
+      <GenerateDebugInformation>false</GenerateDebugInformation>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
+      <ProgramDatabaseFile>
+      </ProgramDatabaseFile>
     </Link>
+    <PostBuildEvent>
+      <Command>Del /Q "$(IntDir)\*.tlog"</Command>
+    </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="..\ast.c" />
-    <ClCompile Include="..\code.c" />
-    <ClCompile Include="..\conout.c" />
+    <ClCompile Include="..\ast.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)</ObjectFileName>
+    </ClCompile>
+    <ClCompile Include="..\code.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)</ObjectFileName>
+    </ClCompile>
+    <ClCompile Include="..\conout.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)conout_gmqcc.o</ObjectFileName>
+    </ClCompile>
     <ClCompile Include="..\ftepp.c" />
     <ClCompile Include="..\ir.c" />
     <ClCompile Include="..\lexer.c" />
     <ClCompile Include="..\main.c" />
     <ClCompile Include="..\opts.c" />
     <ClCompile Include="..\parser.c" />
-    <ClCompile Include="..\util.c" />
+    <ClCompile Include="..\util.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)util_gmqcc.o</ObjectFileName>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\ast.h" />
index 48d06df594cc59f223bcba99a9c5219a69083a53..538227949088294db02c798092c3b414a2389ab3 100644 (file)
@@ -1,10 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
     <ProjectConfiguration Include="Release|Win32">
       <Configuration>Release</Configuration>
       <Platform>Win32</Platform>
@@ -13,15 +9,9 @@
   <PropertyGroup Label="Globals">
     <ProjectGuid>{8DC505A6-6047-4683-BA81-BC4B7A839352}</ProjectGuid>
     <RootNamespace>qcvm</RootNamespace>
+    <TrackFileAccess>false</TrackFileAccess>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>Unicode</CharacterSet>
-    <UseOfMfc>false</UseOfMfc>
-    <WholeProgramOptimization>true</WholeProgramOptimization>
-  </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
   </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   </ImportGroup>
   <PropertyGroup Label="UserMacros" />
-  <PropertyGroup />
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Full</Optimization>
-      <AdditionalIncludeDirectories>.;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
-      <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
-      <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
-      <OmitFramePointers>true</OmitFramePointers>
-      <EnableFiberSafeOptimizations>true</EnableFiberSafeOptimizations>
-      <PreprocessorDefinitions>QCVM_EXECUTOR=1;%(PreprocessorDefinitions)</PreprocessorDefinitions>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
       <WarningLevel>Level3</WarningLevel>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
     </Link>
+    <PostBuildEvent>
+      <Command>Del /Q "$(IntDir)\*.tlog"</Command>
+    </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="..\conout.c" />
-    <ClCompile Include="..\exec.c" />
-    <ClCompile Include="..\util.c" />
+    <ClCompile Include="..\conout.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)conout_qcvm.o</ObjectFileName>
+    </ClCompile>
+    <ClCompile Include="..\exec.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)</ObjectFileName>
+    </ClCompile>
+    <ClCompile Include="..\util.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)util_qcvm.o</ObjectFileName>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\gmqcc.h" />
index cfe055f65295d9cfca23affd3a6067f76d4d9d41..3e7723168a312019833c3bcac1d30469d00a73ca 100644 (file)
@@ -1,10 +1,6 @@
 <?xml version="1.0" encoding="utf-8"?>
 <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup Label="ProjectConfigurations">
-    <ProjectConfiguration Include="Debug|Win32">
-      <Configuration>Debug</Configuration>
-      <Platform>Win32</Platform>
-    </ProjectConfiguration>
     <ProjectConfiguration Include="Release|Win32">
       <Configuration>Release</Configuration>
       <Platform>Win32</Platform>
@@ -13,13 +9,9 @@
   <PropertyGroup Label="Globals">
     <ProjectGuid>{3F8F0021-66B8-43ED-906C-1CFE204E5673}</ProjectGuid>
     <RootNamespace>testsuite</RootNamespace>
+    <TrackFileAccess>false</TrackFileAccess>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
-  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
-    <ConfigurationType>Application</ConfigurationType>
-    <UseDebugLibraries>true</UseDebugLibraries>
-    <CharacterSet>MultiByte</CharacterSet>
-  </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
     <ConfigurationType>Application</ConfigurationType>
     <UseDebugLibraries>false</UseDebugLibraries>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
   <ImportGroup Label="ExtensionSettings">
   </ImportGroup>
-  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
-  </ImportGroup>
   <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
   </ImportGroup>
-  <PropertyGroup Label="UserMacros" />
-  <PropertyGroup />
-  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
-    <ClCompile>
-      <WarningLevel>Level3</WarningLevel>
-      <Optimization>Disabled</Optimization>
-    </ClCompile>
-    <Link>
-      <GenerateDebugInformation>true</GenerateDebugInformation>
-    </Link>
-  </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
       <WarningLevel>Level3</WarningLevel>
       <EnableCOMDATFolding>true</EnableCOMDATFolding>
       <OptimizeReferences>true</OptimizeReferences>
     </Link>
+    <PostBuildEvent>
+      <Command>Del /Q "$(IntDir)\*.tlog"</Command>
+    </PostBuildEvent>
   </ItemDefinitionGroup>
   <ItemGroup>
-    <ClCompile Include="..\conout.c" />
+    <ClCompile Include="..\conout.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)conout_testsuite.o</ObjectFileName>
+    </ClCompile>
     <ClCompile Include="..\test.c" />
-    <ClCompile Include="..\util.c" />
+    <ClCompile Include="..\util.c">
+      <ObjectFileName Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(IntDir)util_testsuite.o</ObjectFileName>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="..\gmqcc.h" />