# HG changeset patch # User Teemu Piippo # Date 1437599807 -10800 # Node ID 53c2aecb9704c46b4bb7a9c5603497ed87c481bc # Parent 3c02a728a681213021d60632792dee6bb8159500 some work on MSVC support (still doesn't work yet...) diff -r 3c02a728a681 -r 53c2aecb9704 CMakeLists.txt --- 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) diff -r 3c02a728a681 -r 53c2aecb9704 sources/basics.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 #include +#include +#include +#include +#include -#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 -using Function = std::function; - // ------------------------------------------------------------------------------------------------- // enum Color @@ -87,12 +84,8 @@ // ------------------------------------------------------------------------------------------------- // -FUNCTION print_to_console (String a) -> void; - -// ------------------------------------------------------------------------------------------------- -// -template inline FUNCTION -clamp (T a, T b, T c) -> T +template +inline T clamp (T a, T b, T c) { return (a < b) ? b : (a > c) ? c : a; } diff -r 3c02a728a681 -r 53c2aecb9704 sources/coloredline.cpp --- 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); diff -r 3c02a728a681 -r 53c2aecb9704 sources/list.h --- 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 #include -#include #include #include +#include #include "range.h" // ------------------------------------------------------------------------------------------------- @@ -57,9 +57,6 @@ Container (const C& other) : m_container (other) {} - Container (std::initializer_list&& a) : - m_container (a) {} - T& append (const T& value) { m_container.push_back (value); @@ -329,17 +326,28 @@ // template -using List = Container>; +class List : public Container > +{ +public: + typedef Container > Super; + + List(){} + + List (int numvalues) : + Super (numvalues) {} + + List (const Super& other) : + Super (other) {} +}; // ------------------------------------------------------------------------------------------------- // template -class Vector : public Container> +class Vector : public Container > { public: - using Super = Container>; - using typename Super::Container; + typedef Container > Super; Vector(){} diff -r 3c02a728a681 -r 53c2aecb9704 sources/mystring.h --- 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 { public: - using Super = List; - using Super::Super; + typedef List Super; StringList() {} + StringList (int numvalues) : + Super (numvalues) {} + StringList (const Super& other) : Super (other) {}