From bae9939e50f8b06305cc5fce8515b42d4ef1b8f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 2 May 2010 01:20:31 +0200 Subject: [PATCH] Fix-merge early C API implementation --- dfhack/DFHackAPI_C.cpp | 4 +- dfhack/DFProcess-linux-wine.cpp | 2 +- dfhack/DFProcess-linux.cpp | 2 +- dfhack/DFProcess-windows.cpp | 2 +- dfhack/include/DFCommonInternal.h | 69 ++++++++++++----------------- dfhack/include/DFHackAPI_C.h | 28 ++++++------ dfhack/include/Export.h | 32 ++++++------- dfhack/include/modules/Position_C.h | 14 +++--- dfhack/modules/Creatures.cpp | 3 +- dfhack/python/DF_MemInfo.cpp | 2 +- tools/dfbauxite.cpp | 1 - 11 files changed, 70 insertions(+), 89 deletions(-) diff --git a/dfhack/DFHackAPI_C.cpp b/dfhack/DFHackAPI_C.cpp index 81847c419..db3c9db95 100644 --- a/dfhack/DFHackAPI_C.cpp +++ b/dfhack/DFHackAPI_C.cpp @@ -1,6 +1,6 @@ /* www.sourceforge.net/projects/dfhack -Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -179,4 +179,4 @@ void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, #ifdef __cplusplus } -#endif \ No newline at end of file +#endif diff --git a/dfhack/DFProcess-linux-wine.cpp b/dfhack/DFProcess-linux-wine.cpp index f79a327e4..18a1ca6fd 100644 --- a/dfhack/DFProcess-linux-wine.cpp +++ b/dfhack/DFProcess-linux-wine.cpp @@ -50,7 +50,7 @@ class WineProcess::Private DFWindow* my_window; memory_info * my_descriptor; Process * self; - ProcessHandle my_handle; + pid_t my_handle; uint32_t my_pid; string memFile; int memFileHandle; diff --git a/dfhack/DFProcess-linux.cpp b/dfhack/DFProcess-linux.cpp index 2b6057a09..9e5232995 100644 --- a/dfhack/DFProcess-linux.cpp +++ b/dfhack/DFProcess-linux.cpp @@ -47,7 +47,7 @@ class NormalProcess::Private ~Private(){}; DFWindow* my_window; memory_info * my_descriptor; - ProcessHandle my_handle; + pid_t my_handle; uint32_t my_pid; string memFile; int memFileHandle; diff --git a/dfhack/DFProcess-windows.cpp b/dfhack/DFProcess-windows.cpp index 0a103de5b..54254d235 100644 --- a/dfhack/DFProcess-windows.cpp +++ b/dfhack/DFProcess-windows.cpp @@ -44,7 +44,7 @@ class NormalProcess::Private ~Private(){}; memory_info * my_descriptor; DFWindow * my_window; - ProcessHandle my_handle; + HANDLE my_handle; HANDLE my_main_thread; uint32_t my_pid; string memFile; diff --git a/dfhack/include/DFCommonInternal.h b/dfhack/include/DFCommonInternal.h index 3a583c23b..789bc246b 100644 --- a/dfhack/include/DFCommonInternal.h +++ b/dfhack/include/DFCommonInternal.h @@ -25,23 +25,43 @@ distribution. #ifndef DFCOMMONINTERNAL_H_INCLUDED #define DFCOMMONINTERNAL_H_INCLUDED -// this makes everything that includes this file export symbols whn using DFHACK_EXPORT (see Export.h) -#define BUILD_DFHACK_LIB +// this makes everything that includes this file export symbols when using DFHACK_EXPORT (see Export.h) +#ifndef BUILD_DFHACK_LIB + #define BUILD_DFHACK_LIB +#endif + +// wizardry for the cmake-generated config.h +#define _QUOTEME(x) #x +#define QUOT(x) _QUOTEME(x) +#ifdef USE_CONFIG_H // set by cmake for Linux builds + #include "config.h" +#else + #define MEMXML_DATA_PATH . +#endif + +// one file for globals #include "DFGlobal.h" + +// one file for telling the MSVC compiler where it can shove its pointless warnings #include "Tranquility.h" +// basic stl containers and IO stuff #include #include #include - #include #include using namespace std; + +// C99 integer types #include "integers.h" +// C includes #include #include +#include +// platform includes and defines #ifdef LINUX_BUILD #include #include @@ -53,59 +73,26 @@ using namespace std; #include #include #else + // WINDOWS #define _WIN32_WINNT 0x0501 // needed for INPUT struct - #define WINVER 0x0501 // OpenThread(), PSAPI, Toolhelp32 + #define WINVER 0x0501 // OpenThread(), PSAPI, Toolhelp32 #define WIN32_LEAN_AND_MEAN #include - //#include #include #include #include #endif -#ifdef LINUX_BUILD -typedef pid_t ProcessHandle; -#else -typedef HANDLE ProcessHandle; -#endif - -#ifndef BUILD_DFHACK_LIB -# define BUILD_DFHACK_LIB -#endif - -/* -#include "DFTypes.h" -//#include "DFDataModel.h" -#include "DFProcess.h" -#include "DFWindow.h" -#include "DFProcessEnumerator.h" -#include "DFMemInfoManager.h" -#include "DFVector.h" -#include "DFMemInfo.h" -#include "DFError.h" -*/ -#include - +// dfhack dependencies #include #include -#include -//#include "DFHackAPI.h" - -#define _QUOTEME(x) #x -#define QUOT(x) _QUOTEME(x) - -#ifdef USE_CONFIG_H -#include "config.h" -#else -#define MEMXML_DATA_PATH . -#endif - +/* #if defined(_MSC_VER) && _MSC_VER >= 1400 #define fill_char_buf(buf, str) strcpy_s((buf), sizeof(buf) / sizeof((buf)[0]), (str).c_str()) #else #define fill_char_buf(buf, str) strncpy((buf), (str).c_str(), sizeof(buf) / sizeof((buf)[0])) #endif - +*/ #endif // DFCOMMONINTERNAL_H_INCLUDED diff --git a/dfhack/include/DFHackAPI_C.h b/dfhack/include/DFHackAPI_C.h index 64408fa84..88e7a3f2e 100644 --- a/dfhack/include/DFHackAPI_C.h +++ b/dfhack/include/DFHackAPI_C.h @@ -1,6 +1,6 @@ /* www.sourceforge.net/projects/dfhack -Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -34,24 +34,24 @@ typedef void DFHackObject; extern "C" { #endif -EXPORT DFHackObject* API_Alloc(const char* path_to_xml); -EXPORT void API_Free(DFHackObject* api); +DFHACK_EXPORT DFHackObject* API_Alloc(const char* path_to_xml); +DFHACK_EXPORT void API_Free(DFHackObject* api); -EXPORT int API_Attach(DFHackObject* api); -EXPORT int API_Detach(DFHackObject* api); -EXPORT int API_isAttached(DFHackObject* api); +DFHACK_EXPORT int API_Attach(DFHackObject* api); +DFHACK_EXPORT int API_Detach(DFHackObject* api); +DFHACK_EXPORT int API_isAttached(DFHackObject* api); -EXPORT int API_Suspend(DFHackObject* api); -EXPORT int API_Resume(DFHackObject* api); -EXPORT int API_isSuspended(DFHackObject* api); -EXPORT int API_ForceResume(DFHackObject* api); -EXPORT int API_AsyncSuspend(DFHackObject* api); +DFHACK_EXPORT int API_Suspend(DFHackObject* api); +DFHACK_EXPORT int API_Resume(DFHackObject* api); +DFHACK_EXPORT int API_isSuspended(DFHackObject* api); +DFHACK_EXPORT int API_ForceResume(DFHackObject* api); +DFHACK_EXPORT int API_AsyncSuspend(DFHackObject* api); -EXPORT void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* target); -EXPORT void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* source); +DFHACK_EXPORT void API_ReadRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* target); +DFHACK_EXPORT void API_WriteRaw(DFHackObject* api, const uint32_t offset, const uint32_t size, uint8_t* source); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/dfhack/include/Export.h b/dfhack/include/Export.h index a3984c372..bbdb2f348 100644 --- a/dfhack/include/Export.h +++ b/dfhack/include/Export.h @@ -23,23 +23,17 @@ distribution. */ #ifdef LINUX_BUILD -#ifndef DFHACK_EXPORT -#ifndef SWIGIMPORTED -#define DFHACK_EXPORT __attribute__ ((visibility("default"))) -#else -#define DFHACK_EXPORT + #ifndef DFHACK_EXPORT + #define DFHACK_EXPORT __attribute__ ((visibility("default"))) + #endif + #else + #ifdef BUILD_DFHACK_LIB + #ifndef DFHACK_EXPORT + #define DFHACK_EXPORT __declspec(dllexport) + #endif + #else + #ifndef DFHACK_EXPORT + #define DFHACK_EXPORT __declspec(dllimport) + #endif + #endif #endif -#endif -#else -#ifdef BUILD_DFHACK_LIB -#ifndef DFHACK_EXPORT -#define DFHACK_EXPORT __declspec(dllexport) -#endif -#else -#ifndef DFHACK_EXPORT -#define DFHACK_EXPORT __declspec(dllimport) -#endif -#endif -#endif - -#define EXPORT __declspec(dllexport) diff --git a/dfhack/include/modules/Position_C.h b/dfhack/include/modules/Position_C.h index 4879116c8..fb74fc647 100644 --- a/dfhack/include/modules/Position_C.h +++ b/dfhack/include/modules/Position_C.h @@ -1,6 +1,6 @@ /* www.sourceforge.net/projects/dfhack -Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild +Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf, doomchild This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -33,16 +33,16 @@ distribution. extern "C" { #endif -EXPORT int Position_getViewCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z); -EXPORT int Position_setViewCoords(DFHackObject* pos, const int32_t x, const int32_t y, const int32_t z); +DFHACK_EXPORT int Position_getViewCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z); +DFHACK_EXPORT int Position_setViewCoords(DFHackObject* pos, const int32_t x, const int32_t y, const int32_t z); -EXPORT int Position_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z); -EXPORT int Position_setCursorCoords(DFHackObject* pos, const int32_t x, const int32_t y, const int32_t z); +DFHACK_EXPORT int Position_getCursorCoords(DFHackObject* pos, int32_t* x, int32_t* y, int32_t* z); +DFHACK_EXPORT int Position_setCursorCoords(DFHackObject* pos, const int32_t x, const int32_t y, const int32_t z); -EXPORT int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height); +DFHACK_EXPORT int Position_getWindowSize(DFHackObject* pos, int32_t* width, int32_t* height); #ifdef __cplusplus } #endif -#endif \ No newline at end of file +#endif diff --git a/dfhack/modules/Creatures.cpp b/dfhack/modules/Creatures.cpp index 7c527d8c0..9b22d2ad8 100644 --- a/dfhack/modules/Creatures.cpp +++ b/dfhack/modules/Creatures.cpp @@ -191,7 +191,8 @@ bool Creatures::ReadCreature (const int32_t index, t_creature & furball) d->d->readName(furball.artifact_name, temp + offs.artifact_name_offset); // custom profession - fill_char_buf (furball.custom_profession, p->readSTLString (temp + offs.custom_profession_offset)); + p->readSTLString(temp + offs.custom_profession_offset, furball.custom_profession, sizeof(furball.custom_profession)); + //fill_char_buf (furball.custom_profession, p->readSTLString (temp + offs.custom_profession_offset)); // labors p->read (temp + offs.labors_offset, NUM_CREATURE_LABORS, furball.labors); diff --git a/dfhack/python/DF_MemInfo.cpp b/dfhack/python/DF_MemInfo.cpp index c55cf4bbb..bce6910ed 100644 --- a/dfhack/python/DF_MemInfo.cpp +++ b/dfhack/python/DF_MemInfo.cpp @@ -31,7 +31,7 @@ distribution. using namespace std; #include "Export.h" -#include "DFCommonInternal.h" +//#include "DFCommonInternal.h" #include "DFMemInfo.h" using namespace DFHack; diff --git a/tools/dfbauxite.cpp b/tools/dfbauxite.cpp index cebff1351..c0012854d 100644 --- a/tools/dfbauxite.cpp +++ b/tools/dfbauxite.cpp @@ -5,7 +5,6 @@ Author: Alex Legg Based on code from and uses DFHack - www.sourceforge.net/projects/dfhack */ -//#include #include #include #include