From 5bb60162d381017a85370e9baab240cf56266aa7 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Tue, 15 Jan 2013 22:31:36 +0000 Subject: [PATCH] Tidied up code (apart from legacy.py, which got messed up), updated docs. --- CMakeLists.txt | 53 +++++++++++++++++++++++---------------- docs/BOSS API Readme.html | 30 +++++++++++----------- mingw32-toolchain.cmake | 15 +++++++++++ src/api.cpp | 15 +++++++++++ src/api.h | 15 +++++------ src/game.cpp | 4 +-- src/helpers.cpp | 12 ++++++--- src/legacy.py | 3 ++- src/plugin/ModFormat.cpp | 4 +-- 9 files changed, 99 insertions(+), 52 deletions(-) create mode 100644 mingw32-toolchain.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 12820127..f0d67354 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ # Settings passed on the command line: # -# LIBSTR_LIBS_DIR = the directory which all external libraries may be referenced from. -# LIBSTR_ARCH = the build architecture -# LIBSTR_LINK = whether to build a static or dynamic library. +# PROJECT_LIBS_DIR = the directory which all external libraries may be referenced from. +# PROJECT_ARCH = the build architecture +# PROJECT_LINK = whether to build a static or dynamic library. ############################## # General Settings @@ -14,7 +14,8 @@ project (boss) set (BOSS_SRC "${CMAKE_SOURCE_DIR}/src/metadata.cpp" "${CMAKE_SOURCE_DIR}/src/game.cpp" "${CMAKE_SOURCE_DIR}/src/helpers.cpp" "${CMAKE_SOURCE_DIR}/src/plugin/ModFormat.cpp" "${CMAKE_SOURCE_DIR}/src/plugin/VersionRegex.cpp") # Include source and library directories. -include_directories ("${BOSS_LIBS_DIR}/alphanum" "${BOSS_LIBS_DIR}/utf8" "${BOSS_LIBS_DIR}/boost" "${BOSS_LIBS_DIR}/yaml-cpp/include" "${CMAKE_SOURCE_DIR}/src" "${BOSS_LIBS_DIR}/libloadorder/src") +include_directories ("${PROJECT_LIBS_DIR}/alphanum" "${PROJECT_LIBS_DIR}/utf8" "${PROJECT_LIBS_DIR}/boost" "${PROJECT_LIBS_DIR}/yaml-cpp/include" "${CMAKE_SOURCE_DIR}/src" "${PROJECT_LIBS_DIR}/libloadorder/src") + ############################## # Platform-Specific Settings @@ -22,35 +23,43 @@ include_directories ("${BOSS_LIBS_DIR}/alphanum" "${BOSS_LIBS_DIR}/utf8" "${BOSS # Settings when compiling for Windows. IF (CMAKE_SYSTEM_NAME MATCHES "Windows") - #IF (${BOSS_LINK} MATCHES "STATIC") - # add_definitions (-DBOSS_STATIC) - #ELSE () - # add_definitions (-DBOSS_EXPORT) - #ENDIF () + IF (${PROJECT_LINK} MATCHES "STATIC") + add_definitions (-DLIBLO_STATIC) + add_definitions (-DBOSS_STATIC) + ELSE () + add_definitions (-DLIBLO_STATIC) + add_definitions (-DBOSS_EXPORT) + ENDIF () ENDIF () -# Settings when compiling on Windows. -IF (CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") - #set (BOSS_LIBS libboost_filesystem-vc110-mt-1_52 libboost_system-vc110-mt-1_52) - set (CMAKE_CXX_FLAGS "/EHsc") +# Settings when not cross-compiling. +IF (CMAKE_SYSTEM_NAME MATCHES CMAKE_HOST_SYSTEM_NAME) + link_directories ("${PROJECT_LIBS_DIR}/boost/stage-${PROJECT_ARCH}/lib") ENDIF () +link_directories ("${PROJECT_LIBS_DIR}/yaml-cpp/build") +link_directories ("${PROJECT_LIBS_DIR}/libloadorder/build") + # Settings when compiling and cross-compiling on Linux. IF (CMAKE_HOST_SYSTEM_NAME MATCHES "Linux") - set (BOSS_LIBS loadorder yaml-cpp boost_filesystem boost_system boost_regex) - set (CMAKE_C_FLAGS "-m${BOSS_ARCH}") - set (CMAKE_CXX_FLAGS "-m${BOSS_ARCH}") + set (CMAKE_C_FLAGS "-m${PROJECT_ARCH}") + set (CMAKE_CXX_FLAGS "-m${PROJECT_ARCH}") set (CMAKE_EXE_LINKER_FLAGS "-static-libstdc++ -static-libgcc") set (CMAKE_SHARED_LINKER_FLAGS "-static-libstdc++ -static-libgcc") set (CMAKE_MODULE_LINKER_FLAGS "-static-libstdc++ -static-libgcc") - link_directories ("${BOSS_LIBS_DIR}/yaml-cpp/build") - link_directories ("${BOSS_LIBS_DIR}/libloadorder/build") - link_directories ("${BOSS_LIBS_DIR}/boost/stage-${BOSS_ARCH}/lib") - IF (CMAKE_SYSTEM_NAME MATCHES "Windows") - link_directories ("${BOSS_LIBS_DIR}/boost/stage-mingw-${BOSS_ARCH}/lib") + link_directories ("${PROJECT_LIBS_DIR}/boost/stage-mingw-${PROJECT_ARCH}/lib") + set (BOSS_LIBS version) ENDIF () + + set (BOSS_LIBS ${BOSS_LIBS} loadorder yaml-cpp boost_filesystem boost_system boost_regex) +ENDIF () + +# Settings when compiling on Windows. +IF (CMAKE_HOST_SYSTEM_NAME MATCHES "Windows") + set (BOSS_LIBS loadorder yaml-cpp libboost_filesystem-vc110-mt-1_52 libboost_system-vc110-mt-1_52) + set (CMAKE_CXX_FLAGS "/EHsc") ENDIF () ############################## @@ -58,7 +67,7 @@ ENDIF () ############################## # Build API. -add_library (boss "${CMAKE_SOURCE_DIR}/src/api.cpp" ${BOSS_SRC}) +add_library (boss ${PROJECT_LINK} "${CMAKE_SOURCE_DIR}/src/api.cpp" ${BOSS_SRC}) target_link_libraries (boss ${BOSS_LIBS}) # Build tester. diff --git a/docs/BOSS API Readme.html b/docs/BOSS API Readme.html index 486f99d8..b05fc890 100644 --- a/docs/BOSS API Readme.html +++ b/docs/BOSS API Readme.html @@ -69,7 +69,7 @@ h3{ -->
-This documentation is a work in progress, covering an API that is also still a work in progress, and is subject to change. Userlist loading and access has not yet been implemented. The minimal file write doesn't include dirty messages yet. +This documentation is a work in progress, covering an API that is also still a work in progress, and is subject to change. Userlist access has not yet been implemented.

BOSS API Readme

@@ -101,10 +101,10 @@ This documentation is a work in progress, covering an API that is also still a w

Variable Types

The API uses character strings and unsigned integers for data input/output.

The API also provides two new structures: typedef struct _boss_db_int * boss_db; @@ -158,20 +158,20 @@ This documentation is a work in progress, covering an API that is also still a w

Functions

Error Handling Functions

-
+
unsigned int boss_get_error_message (char ** message);

Outputs a string detailing the last error encountered.

  • message - A pointer to the error string outputted.
-
+
void boss_cleanup ();

Frees the memory allocated to the error message string, if boss_get_error_message has been called.

Version Functions

-
+
bool boss_is_compatible (const unsigned int versionMajor, const unsigned int versionMinor, const unsigned int versionPatch); @@ -182,7 +182,7 @@ This documentation is a work in progress, covering an API that is also still a w
  • versionPatch - The patch version number (major.minor.patch) to check.
  • -
    +
    unsigned int boss_get_version (unsigned int * versionMajor, unsigned int * versionMinor, unsigned int * versionPatch); @@ -195,7 +195,7 @@ This documentation is a work in progress, covering an API that is also still a w

    Lifecycle Management Functions

    -
    +
    unsigned int boss_create_db (boss_db * db, const unsigned int clientGame, const char * gamePath); @@ -206,7 +206,7 @@ This documentation is a work in progress, covering an API that is also still a w
  • gamePath - A string giving the path to the game's main folder, ie. the one in which the game's executable lies, or null. If null, then the API will attempt to detect the game folder location itself using the game's registry entries.
  • -
    +
    void boss_destroy_db (boss_db db);

    Destroys the given database, freeing any memory allocated during its use.

      @@ -215,7 +215,7 @@ This documentation is a work in progress, covering an API that is also still a w

    Database Loading Functions

    -
    +
    unsigned int boss_load_lists (boss_db db, const char * masterlistPath, const char * userlistPath); @@ -226,7 +226,7 @@ This documentation is a work in progress, covering an API that is also still a w
  • userlistPath - A string containing the relative or absolute path to the userlist file that should be loaded, or null. If null, no userlist will be loaded.
  • -
    +
    unsigned int boss_eval_lists (boss_db db);

    Refreshes the active plugin list used during evaluation then evaluates all conditional and regular expression metadata entries. Repeated calls re-evaluate the metadata from scratch. This function affects the output of all the database access functions.

      @@ -235,7 +235,7 @@ This documentation is a work in progress, covering an API that is also still a w

    Database Access Functions

    -
    +
    unsigned int boss_get_tag_map (boss_db db, char *** tagMap, size_t * numTags); @@ -246,7 +246,7 @@ This documentation is a work in progress, covering an API that is also still a w
  • numTags - A pointer to the size of the tagMap array. 0 if tagMap is null.
  • -
    +
    unsigned int boss_get_plugin_tags (boss_db db, const char * plugin, unsigned int ** tags_added, @@ -265,7 +265,7 @@ This documentation is a work in progress, covering an API that is also still a w
  • userlistModified - true if the Bash Tag suggestions were modified by the data in the userlist, false otherwise.
  • -
    +
    unsigned int boss_get_plugin_messages (boss_db db, const char * plugin, boss_message ** messages, @@ -278,7 +278,7 @@ This documentation is a work in progress, covering an API that is also still a w
  • numMessages - A pointer to the size of the messages array. 0 if messages is null.
  • -
    +
    unsigned int boss_write_minimal_list (boss_db db, const char * outputFile, const bool overwrite); diff --git a/mingw32-toolchain.cmake b/mingw32-toolchain.cmake new file mode 100644 index 00000000..f458f27c --- /dev/null +++ b/mingw32-toolchain.cmake @@ -0,0 +1,15 @@ +# Cross-compiling from Linux to Windows. +# +# Takes the PROJECT_ARCH variable, with value "32" or "64". +set (CMAKE_SYSTEM_NAME Windows) + +IF (PROJECT_ARCH MATCHES "32") + set (MINGW i586-mingw32msvc) +ELSE () + set (MINGW x86_64-w64-mingw32) +ENDIF () + +set (CMAKE_C_COMPILER ${MINGW}-gcc) +set (CMAKE_CXX_COMPILER ${MINGW}-g++) +set (CMAKE_RC_COMPILER ${MINGW}-windres) +set (CMAKE_RANLIB ${MINGW}-ranlib) diff --git a/src/api.cpp b/src/api.cpp index 57c5da06..21ab2a55 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -35,6 +35,8 @@ #include #include +#include +#include #include #include #include @@ -549,6 +551,19 @@ BOSS_API unsigned int boss_write_minimal_list (boss_db db, const char * outputFi for (std::list::iterator it=temp.begin(), endIt=temp.end(); it != endIt; ++it) { boss::Plugin p(it->Name()); p.Tags(it->Tags()); + + std::list messages = it->Messages(), newMessages; + for (std::list::iterator messageIter = messages.begin(); messageIter != messages.end(); ++messageIter) { + if (messageIter->Type() == "warn") { + const std::string content = messageIter->Content(); + if (boost::contains(content, "Do not clean")) + newMessages.push_back(*messageIter); + else if (boost::contains(content, "Contains dirty edits")) + newMessages.push_back(*messageIter); + } + } + it->Messages(newMessages); + *it = p; } diff --git a/src/api.h b/src/api.h index 72417968..2f72c245 100644 --- a/src/api.h +++ b/src/api.h @@ -24,29 +24,30 @@ #ifndef __BOSS_API_H__ #define __BOSS_API_H__ -#include #include #if defined(_MSC_VER) //MSVC doesn't support C99, so do the stdbool.h definitions ourselves. //START OF stdbool.h DEFINITIONS. # ifndef __cplusplus -# define bool _Bool -# define true 1 -# define false 0 +# define bool _Bool +# define true 1 +# define false 0 # endif -# define __bool_true_false_are_defined 1 +# define __bool_true_false_are_defined 1 //END OF stdbool.h DEFINITIONS. #else # include #endif // set up dll import/export decorators -// when compiling the dll on windows, ensure BOSS_API_EXPORT is defined. clients +// when compiling the dll on windows, ensure BOSS_EXPORT is defined. clients // that use this header do not need to define anything to import the symbols // properly. #if defined(_WIN32) || defined(_WIN64) -# ifdef BOSS_API_EXPORT +# ifdef BOSS_STATIC +# define BOSS_API +# elif defined BOSS_EXPORT # define BOSS_API __declspec(dllexport) # else # define BOSS_API __declspec(dllimport) diff --git a/src/game.cpp b/src/game.cpp index d90137e0..da083523 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -32,8 +32,8 @@ #include #if _WIN32 || _WIN64 -# include -# include +# include +# include #endif using namespace std; diff --git a/src/helpers.cpp b/src/helpers.cpp index 2b88efb5..941b86b0 100644 --- a/src/helpers.cpp +++ b/src/helpers.cpp @@ -46,8 +46,14 @@ #include #if _WIN32 || _WIN64 -# include "Windows.h" -# include "Shlobj.h" +# ifndef UNICODE +# define UNICODE +# endif +# ifndef _UNICODE +# define _UNICODE +# endif +# include "windows.h" +# include "shlobj.h" #endif namespace boss { @@ -62,7 +68,7 @@ namespace boss { uint32_t chksum = 0; static const size_t buffer_size = 8192; char buffer[buffer_size]; - ifstream ifile(filename.c_str(), ios::binary); + ifstream ifile(filename.string().c_str(), ios::binary); // LOG_TRACE("calculating CRC for: '%s'", filename.string().c_str()); boost::crc_32_type result; if (ifile) { diff --git a/src/legacy.py b/src/legacy.py index 824e15b2..e9e6f176 100755 --- a/src/legacy.py +++ b/src/legacy.py @@ -35,7 +35,8 @@ # - Conditional plugin positions are all made unconditional, so there will be # duplicate entries. -import re +class Plugin: + def escapeYAMLStr(s): special = ['-', '?', ':', ',', '[', ']', '{', '}', '&', '*', '!', '|', '>', '\'', '"', '%', '@', '`'] diff --git a/src/plugin/ModFormat.cpp b/src/plugin/ModFormat.cpp index fadbdc66..046dbbb0 100644 --- a/src/plugin/ModFormat.cpp +++ b/src/plugin/ModFormat.cpp @@ -134,7 +134,7 @@ namespace boss { if (filename.empty()) return false; - ifstream file(filename.native().c_str(), ios_base::binary | ios_base::in); + ifstream file(filename.string().c_str(), ios_base::binary | ios_base::in); if (file.bad()) //throw boss_error(BOSS_ERROR_FILE_READ_FAIL, filename.string()); @@ -163,7 +163,7 @@ namespace boss { char buffer[MAXLENGTH]; char* bufptr = buffer; ModHeader modHeader; - ifstream file(filename.native().c_str(), ios_base::binary | ios_base::in); + ifstream file(filename.string().c_str(), ios_base::binary | ios_base::in); modHeader.Name = filename.string();