some work on MSVC support (still doesn't work yet...)

Thu, 23 Jul 2015 00:16:47 +0300

author
Teemu Piippo <tsapii@utu.fi>
date
Thu, 23 Jul 2015 00:16:47 +0300
changeset 87
53c2aecb9704
parent 86
3c02a728a681
child 88
08ccaf26cffd

some work on MSVC support (still doesn't work yet...)

CMakeLists.txt file | annotate | diff | comparison | revisions
sources/basics.h file | annotate | diff | comparison | revisions
sources/coloredline.cpp file | annotate | diff | comparison | revisions
sources/list.h file | annotate | diff | comparison | revisions
sources/mystring.h file | annotate | diff | comparison | revisions
--- a/CMakeLists.txt	Wed May 27 21:44:42 2015 +0300
+++ b/CMakeLists.txt	Thu Jul 23 00:16:47 2015 +0300
@@ -1,6 +1,7 @@
 cmake_minimum_required (VERSION 2.4)
 cmake_policy (SET CMP0003 NEW)
-project (zfc9000)
+project (ZFC9000)
+string (TOLOWER ${CMAKE_PROJECT_NAME} TARGET_NAME)
 
 add_library (huffman STATIC
 	huffman/bitreader.cpp
@@ -22,31 +23,54 @@
 	sources/network/udpsocket.cpp
 )
 
-set (CURSES_NEED_NCURSES, True)
-set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -W -Wall")
+set (HEADER_FILES
+	sources/basics.h
+	sources/coloredline.h
+	sources/geometry.h
+	sources/interface.h
+	sources/list.h
+	sources/main.h
+	sources/md5.h
+	sources/mystring.h
+	sources/network/bytestream.h
+	sources/network/ipaddress.h
+	sources/network/rconsession.h
+	sources/network/udpsocket.h
+	sources/range.h
+	sources/version.h
+)
 
 if (NOT WIN32)
-	find_package (Curses)
+	find_package (Curses REQUIRED)
 endif()
 
 if (MINGW)
 	set (CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
 endif()
 
-include_directories (${CURSES_INCUDE_DIRS})
 include_directories (${CMAKE_CURRENT_BINARY_DIR})
 include_directories (huffman)
-add_executable (${PROJECT_NAME} ${SOURCE_FILES})
-target_link_libraries (${PROJECT_NAME} huffman)
+add_executable (${TARGET_NAME} ${SOURCE_FILES} ${HEADER_FILES})
+target_link_libraries (${TARGET_NAME} huffman)
+
+if (WIN32)
+	add_definitions ("/Za /D_CRT_SEURE_NO_WARNINGS")
 
-if (NOT WIN32)
-	target_link_libraries (${PROJECT_NAME} ${CURSES_LIBRARIES})
+	if (NOT PDCURSES_WIN32A_PATH)
+		message (SEND_ERROR "Must give PDCURSES_WIN32A_PATH on Windows")
+	else()
+		include_directories (${PDCURSES_WIN32A_PATH}/include)
+		target_link_libraries (${TARGET_NAME} ${PDCURSES_WIN32A_PATH}/lib/pdcurses.a)
+		target_link_libraries (${TARGET_NAME} wsock32 ws2_32)
+	endif()
 else()
-	target_link_libraries (${PROJECT_NAME} ${CMAKE_CURRENT_BINARY_DIR}/pdcurses.a wsock32 ws2_32)
+	include_directories (${CURSES_INCUDE_DIRS}) # sic
+	target_link_libraries (${TARGET_NAME} ${CURSES_LIBRARIES})
+	set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -W -Wall -std=c++0x")
 endif()
 
 add_custom_target (make_hginfo_h
 	COMMAND python
 		"${CMAKE_SOURCE_DIR}/updaterevision/updaterevision.py"
 		"${CMAKE_CURRENT_BINARY_DIR}/hginfo.h")
-add_dependencies (${PROJECT_NAME} make_hginfo_h)
+add_dependencies (${TARGET_NAME} make_hginfo_h)
--- a/sources/basics.h	Wed May 27 21:44:42 2015 +0300
+++ b/sources/basics.h	Thu Jul 23 00:16:47 2015 +0300
@@ -31,26 +31,23 @@
 #pragma once
 #include <algorithm>
 #include <functional>
+#include <cstdio>
+#include <cstdlib>
+#include <cstring>
+#include <cctype>
 
-#ifndef _MSC_VER
+#if !defined(_MSC_VER) && !defined(__cdecl)
 # define __cdecl
 #endif
 
-#define FUNCTION auto
-#define STATIC
-#define METHOD auto
 #define MACRO_TO_STRING_2(A) #A
 #define MACRO_TO_STRING(A) MACRO_TO_STRING_2(A)
 
 class String;
-
 using std::swap;
 using std::min;
 using std::max;
 
-template<typename Signature>
-using Function = std::function<Signature>;
-
 // -------------------------------------------------------------------------------------------------
 //
 enum Color
@@ -87,12 +84,8 @@
 
 // -------------------------------------------------------------------------------------------------
 //
-FUNCTION print_to_console (String a) -> void;
-
-// -------------------------------------------------------------------------------------------------
-//
-template<typename T> inline FUNCTION
-clamp (T a, T b, T c) -> T
+template<typename T>
+inline T clamp (T a, T b, T c)
 {
 	return (a < b) ? b : (a > c) ? c : a;
 }
--- a/sources/coloredline.cpp	Wed May 27 21:44:42 2015 +0300
+++ b/sources/coloredline.cpp	Thu Jul 23 00:16:47 2015 +0300
@@ -30,35 +30,11 @@
 
 #include "coloredline.h"
 
-static const struct
+struct ColorCodeInfo
 {
 	const char* name;
 	Color color;
 	bool bold;
-} g_colorCodes['v' - 'a' + 1] =
-{
-	{ "Brick",        RED,     true  }, // a
-	{ "Tan",          YELLOW,  true  }, // b
-	{ "Gray",         WHITE,   false }, // c
-	{ "Green",        GREEN,   true  }, // d
-	{ "Brown",        YELLOW,  false }, // e
-	{ "Gold",         YELLOW,  true  }, // f
-	{ "Red",          RED,     true  }, // g
-	{ "Blue",         BLUE,    false }, // h
-	{ "Orange",       YELLOW,  false }, // i
-	{ "White",        WHITE,   true  }, // j
-	{ "Yellow",       YELLOW,  true  }, // k
-	{ "Untranslated", DEFAULT, false }, // l
-	{ "Black",        BLACK,   false }, // m
-	{ "Blue",         BLUE,    true  }, // n
-	{ "Cream",        YELLOW,  true  }, // o
-	{ "Olive",        GREEN,   true  }, // p
-	{ "Dark Green",   GREEN,   false }, // q
-	{ "Dark Red",     RED,     false }, // r
-	{ "Dark Brown",   YELLOW,  false }, // s
-	{ "Purple",       MAGENTA, false }, // t
-	{ "Dark Gray",    BLACK,   true  }, // u
-	{ "Cyan",         CYAN,    true  }, // v
 };
 
 // -------------------------------------------------------------------------------------------------
@@ -78,6 +54,32 @@
 //
 void ColoredLine::add_char (char ch)
 {
+	static const ColorCodeInfo colorCodes[] =
+	{
+		{ "Brick",        RED,     true  }, // a
+		{ "Tan",          YELLOW,  true  }, // b
+		{ "Gray",         WHITE,   false }, // c
+		{ "Green",        GREEN,   true  }, // d
+		{ "Brown",        YELLOW,  false }, // e
+		{ "Gold",         YELLOW,  true  }, // f
+		{ "Red",          RED,     true  }, // g
+		{ "Blue",         BLUE,    false }, // h
+		{ "Orange",       YELLOW,  false }, // i
+		{ "White",        WHITE,   true  }, // j
+		{ "Yellow",       YELLOW,  true  }, // k
+		{ "Untranslated", DEFAULT, false }, // l
+		{ "Black",        BLACK,   false }, // m
+		{ "Blue",         BLUE,    true  }, // n
+		{ "Cream",        YELLOW,  true  }, // o
+		{ "Olive",        GREEN,   true  }, // p
+		{ "Dark Green",   GREEN,   false }, // q
+		{ "Dark Red",     RED,     false }, // r
+		{ "Dark Brown",   YELLOW,  false }, // s
+		{ "Purple",       MAGENTA, false }, // t
+		{ "Dark Gray",    BLACK,   true  }, // u
+		{ "Cyan",         CYAN,    true  }, // v
+	};
+
 	if (m_final)
 		return; // Don't touch finalized lines.
 
@@ -101,7 +103,7 @@
 
 		if (ch >= 'a' and ch <= 'v' and ch != 'l')
 		{
-			auto colorInfo = g_colorCodes[ch - 'a'];
+			auto colorInfo = colorCodes[ch - 'a'];
 			m_activeColor = colorInfo.color;
 			m_boldActive = colorInfo.bold;
 			assert (m_activeColor < 8);
--- a/sources/list.h	Wed May 27 21:44:42 2015 +0300
+++ b/sources/list.h	Thu Jul 23 00:16:47 2015 +0300
@@ -32,9 +32,9 @@
 #include "basics.h"
 #include <algorithm>
 #include <deque>
-#include <initializer_list>
 #include <functional>
 #include <cassert>
+#include <vector>
 #include "range.h"
 
 // -------------------------------------------------------------------------------------------------
@@ -57,9 +57,6 @@
 	Container (const C& other) :
 		m_container (other) {}
 
-	Container (std::initializer_list<T>&& a) :
-		m_container (a) {}
-
 	T& append (const T& value)
 	{
 		m_container.push_back (value);
@@ -329,17 +326,28 @@
 //
 
 template<typename T>
-using List = Container<T, std::deque<T>>;
+class List : public Container<T, std::deque<T> >
+{
+public:
+	typedef Container<T, std::deque<T> > Super;
+
+	List(){}
+
+	List (int numvalues) :
+		Super (numvalues) {}
+
+	List (const Super& other) :
+		Super (other) {}
+};
 
 // -------------------------------------------------------------------------------------------------
 //
 
 template<typename T>
-class Vector : public Container<T, std::vector<T>>
+class Vector : public Container<T, std::vector<T> >
 {
 public:
-	using Super = Container<T, std::vector<T>>;
-	using typename Super::Container;
+	typedef Container<T, std::vector<T> > Super;
 
 	Vector(){}
 
--- a/sources/mystring.h	Wed May 27 21:44:42 2015 +0300
+++ b/sources/mystring.h	Thu Jul 23 00:16:47 2015 +0300
@@ -94,7 +94,7 @@
 	void insert (int pos, char c) { m_string.insert (m_string.begin() + pos, c); }
 	void insert (int pos, const char*c) { m_string.insert (pos, c); }
 	void modify_index (int &a) { if (a < 0) { a = length() - a; } }
-	void normalize (int (*filter)(int) = &std::isspace);
+	void normalize (int (*filter)(int) = &isspace);
 	void prepend (String a) { m_string = (a + m_string).std_string(); }
 	void remove (int pos, int len) { m_string.replace (pos, len, ""); }
 	void remove_at (int pos) { m_string.erase (m_string.begin() + pos); }
@@ -145,11 +145,13 @@
 class StringList : public List<String>
 {
 public:
-	using Super = List<String>;
-	using Super::Super;
+	typedef List<String> Super;
 
 	StringList() {}
 
+	StringList (int numvalues) :
+		Super (numvalues) {}
+
 	StringList (const Super& other) :
 		Super (other) {}
 

mercurial