From 78e63ed4c6c4908c0f8dcde15aa1a848b8e0e659 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Nov 2016 09:48:38 +0000 Subject: [PATCH 01/12] misleading indentation --- src/kernel/save.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/kernel/save.c b/src/kernel/save.c index 83fa72f76..2f157af41 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -298,7 +298,7 @@ int readorders(const char *filename) * vermerkt. */ case P_UNIT: - if (!f || !unitorders(F, enc_gamedata, f)) + if (!f || !unitorders(F, enc_gamedata, f)) { do { b = getbuf(F, enc_gamedata); if (!b) { @@ -309,7 +309,8 @@ int readorders(const char *filename) p = (s && s[0] != '@') ? findparam(s, lang) : NOPARAM; } while ((p != P_UNIT || !f) && p != P_FACTION && p != P_NEXT && p != P_GAMENAME); - break; + } + break; /* Falls in unitorders() abgebrochen wird, steht dort entweder eine neue * Partei, eine neue Einheit oder das File-Ende. Das switch() wird erneut From c9c4f5dd3732606809f818a76e52814d327486fb Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Nov 2016 09:54:05 +0000 Subject: [PATCH 02/12] gcc complains about BSD_SOURCE now --- src/platform.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/platform.h b/src/platform.h index 77a767875..d813fab9d 100644 --- a/src/platform.h +++ b/src/platform.h @@ -81,17 +81,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #endif /* _MSC_VER_ */ #if defined __GNUC__ -# undef _BSD_SOURCE -# define _BSD_SOURCE +# undef _DEFAULT_SOURCE +# define _DEFAULT_SOURCE # undef __USE_BSD # define __USE_BSD #endif -#ifdef _BSD_SOURCE -# undef __EXTENSIONS__ -# define __EXTENSIONS__ -#endif - #ifdef SOLARIS # define _SYS_PROCSET_H #undef _XOPEN_SOURCE From 5e49ac6fdfac79021c2034be243274e7005a0788 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Nov 2016 16:01:28 +0000 Subject: [PATCH 03/12] fix $MACHINE variable, update submodules --- s/cmake-init | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/s/cmake-init b/s/cmake-init index b1ea6759a..ea94afb7c 100755 --- a/s/cmake-init +++ b/s/cmake-init @@ -9,17 +9,18 @@ while [ ! -d $ROOT/.git ]; do done [ -z $BUILD ] && BUILD=Debug -MACHINE=`uname -m` [ -z "$CC" ] && [ ! -z `which clang` ] && CC="clang" [ -z "$CC" ] && [ ! -z `which gcc` ] && CC="gcc" [ -z "$CC" ] && [ ! -z `which tcc` ] && CC="tcc" [ -z "$CC" ] && [ ! -z `which cc` ] && CC="cc" + +MACHINE=`$CC -dumpmachine` +[ -z $MACHINE ] && MACHINE=`uname -m` BIN_DIR="$ROOT/build-$MACHINE-$CC-$BUILD" mkdir -p $BIN_DIR rm -f $BUILD ln -sf $BIN_DIR $BUILD -MACHINE=$(gcc -dumpmachine) rm -f CMakeCache.txt # use anything installed in /opt or /usr @@ -41,6 +42,8 @@ ARGS=" -DCMAKE_MODULE_PATH=$ROOT/cmake/Modules \ -DCMAKE_PREFIX_PATH=$PREFIX_PATH \ -DCMAKE_INSTALL_PREFIX=$HOME/eressea/server" +git submodule update --init + path="$(which tolua)" if [ "$HAVE_TOLUA" = "0" ] || [ -z $path ] ; then echo "tolua is not installed, building from source" From e52cf75c59de82cf6e316d87f12d9f3ae9d3d1d0 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Nov 2016 20:15:11 +0100 Subject: [PATCH 04/12] remove autoconf.h from platform.h, fix lots of includes --- src/attributes/fleechance.c | 2 + src/attributes/key.test.c | 1 + src/attributes/matmod.c | 1 + src/console.h | 3 ++ src/creport.c | 11 +++--- src/creport.test.c | 1 - src/game.pkg | 1 - src/game.pkg.c | 1 - src/kernel/building.h | 1 + src/kernel/config.h | 1 + src/kernel/curse.c | 2 +- src/kernel/order.h | 6 ++- src/kernel/order.test.c | 1 - src/kernel/race.h | 7 ++-- src/kernel/ship.h | 9 +++-- src/kernel/unit.h | 2 + src/main.c | 5 --- src/modules/score.h | 2 + src/names.h | 3 ++ src/platform.h | 76 ++++++++++++++++++++++++++++++++++-- src/report.c | 16 +++----- src/report.test.c | 1 - src/reports.c | 15 ++----- src/reports.test.c | 1 - src/spells/magicresistance.c | 2 + src/util/nrmessage.h | 3 ++ src/util/parser.h | 3 ++ src/util/strings.h | 3 ++ src/util/translation.h | 3 ++ 29 files changed, 131 insertions(+), 52 deletions(-) diff --git a/src/attributes/fleechance.c b/src/attributes/fleechance.c index 232037972..afba2d301 100644 --- a/src/attributes/fleechance.c +++ b/src/attributes/fleechance.c @@ -21,6 +21,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include +#include + attrib_type at_fleechance = { "fleechance", NULL, diff --git a/src/attributes/key.test.c b/src/attributes/key.test.c index 46343d19f..2b7632917 100644 --- a/src/attributes/key.test.c +++ b/src/attributes/key.test.c @@ -3,6 +3,7 @@ #include #include +#include static void test_get_set_keys(CuTest *tc) { attrib *a = 0; diff --git a/src/attributes/matmod.c b/src/attributes/matmod.c index f885de99b..0cf1955d8 100644 --- a/src/attributes/matmod.c +++ b/src/attributes/matmod.c @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "matmod.h" #include +#include attrib_type at_matmod = { "matmod", diff --git a/src/console.h b/src/console.h index a00a3ad58..fdc869f11 100644 --- a/src/console.h +++ b/src/console.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_LUA_CONSOLE #define H_LUA_CONSOLE + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/creport.c b/src/creport.c index b63a30ad4..c05377e2e 100644 --- a/src/creport.c +++ b/src/creport.c @@ -1468,7 +1468,7 @@ static void cr_output_region(FILE * F, report_context * ctx, region * r) /* main function of the creport. creates the header and traverses all regions */ static int -report_computer(const char *filename, report_context * ctx, const char *charset) +report_computer(const char *filename, report_context * ctx, const char *bom) { static int era = -1; int i; @@ -1488,9 +1488,8 @@ report_computer(const char *filename, report_context * ctx, const char *charset) perror(filename); return -1; } - else if (_strcmpl(charset, "utf-8") == 0 || _strcmpl(charset, "utf8") == 0) { - const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; - fwrite(utf8_bom, 1, 3, F); + else if (bom) { + fwrite(bom, 1, strlen(bom), F); } /* must call this to get all the neighbour regions */ @@ -1498,8 +1497,8 @@ report_computer(const char *filename, report_context * ctx, const char *charset) /* initialisations, header and lists */ fprintf(F, "VERSION %d\n", C_REPORT_VERSION); - fprintf(F, "\"%s\";charset\n", charset); - fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); + fprintf(F, "\"utf-8\";charset\n\"%s\";locale\n", + locale_name(f->locale)); fprintf(F, "%d;noskillpoints\n", 1); fprintf(F, "%lld;date\n", (long long)ctx->report_time); fprintf(F, "\"%s\";Spiel\n", game_name()); diff --git a/src/creport.test.c b/src/creport.test.c index 3a84ea566..72669e99f 100644 --- a/src/creport.test.c +++ b/src/creport.test.c @@ -1,5 +1,4 @@ #include -#include #include "creport.h" #include "move.h" #include "travelthru.h" diff --git a/src/game.pkg b/src/game.pkg index 88b3bda9a..dc2b324e4 100644 --- a/src/game.pkg +++ b/src/game.pkg @@ -1,6 +1,5 @@ $#undef tolua_reg_types $#define tolua_reg_types tolua_reg_types_game -$#include "config.h" $#include "bind_eressea.h" module eressea { diff --git a/src/game.pkg.c b/src/game.pkg.c index abd7832ca..30671021d 100644 --- a/src/game.pkg.c +++ b/src/game.pkg.c @@ -20,7 +20,6 @@ LUALIB_API int luaopen_game (lua_State* tolua_S); #undef tolua_reg_types #define tolua_reg_types tolua_reg_types_game -#include "config.h" #include "bind_eressea.h" /* function to register type */ diff --git a/src/kernel/building.h b/src/kernel/building.h index aee387e7f..92b006b98 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -22,6 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #ifdef __cplusplus extern "C" { #endif diff --git a/src/kernel/config.h b/src/kernel/config.h index df0004e8b..91d5d576f 100644 --- a/src/kernel/config.h +++ b/src/kernel/config.h @@ -24,6 +24,7 @@ extern "C" { #endif /* this should always be the first thing included after platform.h */ +#include #include "types.h" struct param; diff --git a/src/kernel/curse.c b/src/kernel/curse.c index 2ee89799d..123f858f5 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -349,7 +349,7 @@ const curse_type *ct_find(const char *c) } else { size_t k = _min(c_len, strlen(type->cname)); - if (!_memicmp(c, type->cname, k)) { + if (!memcmp(c, type->cname, k)) { return type; } } diff --git a/src/kernel/order.h b/src/kernel/order.h index 8ad5592b7..69cf1ea33 100644 --- a/src/kernel/order.h +++ b/src/kernel/order.h @@ -12,12 +12,14 @@ #ifndef KRNL_ORDER_H #define KRNL_ORDER_H + +#include "keyword.h" +#include + #ifdef __cplusplus extern "C" { #endif -#include "keyword.h" - /* Encapsulation of an order * * This structure contains one order given by a unit. These used to be diff --git a/src/kernel/order.test.c b/src/kernel/order.test.c index 635e6e078..f5eb51c6f 100644 --- a/src/kernel/order.test.c +++ b/src/kernel/order.test.c @@ -1,5 +1,4 @@ #include -#include #include #include "order.h" diff --git a/src/kernel/race.h b/src/kernel/race.h index c7dbe3669..022d09c86 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -18,13 +18,14 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_RACE_H #define H_KRNL_RACE_H +#include +#include "magic.h" /* wegen MAXMAGIETYP */ +#include "skill.h" + #ifdef __cplusplus extern "C" { #endif -#include "magic.h" /* wegen MAXMAGIETYP */ -#include "skill.h" - #define AT_NONE 0 #define AT_STANDARD 1 #define AT_DRAIN_EXP 2 diff --git a/src/kernel/ship.h b/src/kernel/ship.h index 748315d44..964ee2124 100644 --- a/src/kernel/ship.h +++ b/src/kernel/ship.h @@ -18,13 +18,16 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_SHIP #define H_KRNL_SHIP -#ifdef __cplusplus -extern "C" { -#endif #include "types.h" #include "direction.h" +#include + +#ifdef __cplusplus +extern "C" { +#endif + #define DAMAGE_SCALE 100 /* multiplier for sh->damage */ /* ship_type::flags */ diff --git a/src/kernel/unit.h b/src/kernel/unit.h index e81c43135..e846ca1f4 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -22,6 +22,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include "types.h" #include "skills.h" +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/main.c b/src/main.c index 16f56bf57..44c1b9e2d 100644 --- a/src/main.c +++ b/src/main.c @@ -70,11 +70,6 @@ static void load_inifile(dictionary * d) lomem = iniparser_getint(d, "eressea:lomem", lomem) ? 1 : 0; - str = iniparser_getstring(d, "eressea:encoding", NULL); - if (str && (_strcmpl(str, "utf8") == 0 || _strcmpl(str, "utf-8") == 0)) { - enc_gamedata = ENCODING_UTF8; - } - verbosity = iniparser_getint(d, "eressea:verbose", 2); battledebug = iniparser_getint(d, "eressea:debug", battledebug) ? 1 : 0; diff --git a/src/modules/score.h b/src/modules/score.h index b0f1b2a91..4fc1f52bb 100644 --- a/src/modules/score.h +++ b/src/modules/score.h @@ -18,6 +18,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef SCORE_H #define SCORE_H + +#include #ifdef __cplusplus extern "C" { #endif diff --git a/src/names.h b/src/names.h index 63e9c8628..d7ab417c1 100644 --- a/src/names.h +++ b/src/names.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef H_KRNL_NAMES #define H_KRNL_NAMES + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/platform.h b/src/platform.h index d813fab9d..553f734c9 100644 --- a/src/platform.h +++ b/src/platform.h @@ -81,10 +81,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #endif /* _MSC_VER_ */ #if defined __GNUC__ +# define _POSIX_C_SOURCE 200809L # undef _DEFAULT_SOURCE # define _DEFAULT_SOURCE # undef __USE_BSD # define __USE_BSD +# define HAVE_SNPRINTF +# define HAVE_SYS_STAT_MKDIR +# define HAVE_STRDUP +# define HAVE_UNISTD_H #endif #ifdef SOLARIS @@ -104,10 +109,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define TOLUA_CAST (char*) -#ifdef USE_AUTOCONF -# include -#endif - #if !defined(MAX_PATH) #if defined(PATH_MAX) # define MAX_PATH PATH_MAX @@ -124,5 +125,72 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif +#if defined(HAVE_STDBOOL_H) +# include +#else +# if ! HAVE__BOOL +# ifdef __cplusplus +typedef bool _Bool; +# else +typedef unsigned char _Bool; +# endif +# endif +# define bool _Bool +# define false 0 +# define true 1 +# define __bool_true_false_are_defined 1 +#endif + +#ifndef HAVE__ACCESS +#ifdef HAVE_ACCESS +#define _access(path, mode) access(path, mode) +#endif +#endif + +#if defined(HAVE_DIRECT__MKDIR) +#include +#elif defined(HAVE_DIRECT_MKDIR) +#include +#define _mkdir(a) mkdir(a) +#elif defined(HAVE_SYS_STAT_MKDIR) +#include +#define _mkdir(a) mkdir(a, 0777) +#endif + +#ifndef _min +#define _min(a,b) ((a) < (b) ? (a) : (b)) +#endif +#ifndef _max +#define _max(a,b) ((a) > (b) ? (a) : (b)) +#endif + +#if !defined(HAVE__STRDUP) +#if defined(HAVE_STRDUP) +#define _strdup(a) strdup(a) +#else +#define _strdup(a) lcp_strdup(a) +#endif +#endif + +#if !defined(HAVE__SNPRINTF) +#if defined(HAVE_SNPRINTF) +#define _snprintf snprintf +#endif +#endif + +#if !defined(HAVE__STRCMPL) +#if defined(HAVE_STRCMPL) +#define _strcmpl(a, b) strcmpl(a, b) +#elif defined(HAVE__STRICMP) +#define _strcmpl(a, b) _stricmp(a, b) +#elif defined(HAVE_STRICMP) +#define _strcmpl(a, b) stricmp(a, b) +#elif defined(HAVE_STRCASECMP) +#define _strcmpl(a, b) strcasecmp(a, b) +#else +#define _strcmpl(a, b) lcp_strcmpl(a, b) +#endif +#endif + #endif diff --git a/src/report.c b/src/report.c index 040c44db1..dd6b29525 100644 --- a/src/report.c +++ b/src/report.c @@ -1379,7 +1379,7 @@ static int buildingmaintenance(const building * b, const resource_type * rtype) } static int -report_template(const char *filename, report_context * ctx, const char *charset) +report_template(const char *filename, report_context * ctx, const char *bom) { const resource_type *rsilver = get_resourcetype(R_SILVER); faction *f = ctx->f; @@ -1389,7 +1389,6 @@ report_template(const char *filename, report_context * ctx, const char *charset) char buf[8192], *bufp; size_t size; int bytes; - bool utf8 = _strcmpl(charset, "utf8") == 0 || _strcmpl(charset, "utf-8") == 0; const curse_type *nocost_ct = ct_find("nocostbuilding"); if (F == NULL) { @@ -1398,9 +1397,8 @@ report_template(const char *filename, report_context * ctx, const char *charset) } fstream_init(&strm, F); - if (utf8) { - const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; - swrite(utf8_bom, 1, 3, out); + if (bom) { + swrite(bom, 1, strlen(bom), out); } newline(out); @@ -2026,7 +2024,7 @@ void write_travelthru(struct stream *out, region *r, const faction *f) int report_plaintext(const char *filename, report_context * ctx, - const char *charset) + const char *bom) { int flag = 0; char ch; @@ -2044,7 +2042,6 @@ report_plaintext(const char *filename, report_context * ctx, stream strm = { 0 }, *out = &strm; char buf[8192]; char *bufp; - bool utf8 = _strcmpl(charset, "utf8") == 0 || _strcmpl(charset, "utf-8") == 0; size_t size; int thisseason; int nextseason; @@ -2061,9 +2058,8 @@ report_plaintext(const char *filename, report_context * ctx, } fstream_init(&strm, F); - if (utf8) { - const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; - fwrite(utf8_bom, 1, 3, F); + if (bom) { + fwrite(bom, 1, strlen(bom), F); } strftime(pzTime, 64, "%A, %d. %B %Y, %H:%M", localtime(&ctx->report_time)); diff --git a/src/report.test.c b/src/report.test.c index cf074b284..202458db5 100644 --- a/src/report.test.c +++ b/src/report.test.c @@ -1,5 +1,4 @@ #include -#include #include "report.h" #include "move.h" #include "travelthru.h" diff --git a/src/reports.c b/src/reports.c index f0c82d024..a8b9e5cfb 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1401,12 +1401,10 @@ void finish_reports(report_context *ctx) { int write_reports(faction * f, time_t ltime) { - unsigned int backup = 1, maxbackup = 128 * 1000; bool gotit = false; struct report_context ctx; - const char *encoding = "UTF-8"; + const unsigned char utf8_bom[4] = { 0xef, 0xbb, 0xbf, 0 }; report_type *rtype; - if (noreports) { return false; } @@ -1423,19 +1421,12 @@ int write_reports(faction * f, time_t ltime) rtype->extension); join_path(reportpath(), filename, path, sizeof(path)); errno = 0; - if (rtype->write(path, &ctx, encoding) == 0) { + if (rtype->write(path, &ctx, (const char *)utf8_bom) == 0) { gotit = true; } if (errno) { - char zText[64]; - log_warning("retrying, error %d during %s report for faction %s", errno, rtype->extension, factionname(f)); - sprintf(zText, "waiting %u seconds before we retry", backup); - perror(zText); - _sleep(backup); - if (backup < maxbackup) { - backup *= 2; - } error = errno; + log_fatal("error %d during %s report for faction %s: %s", errno, rtype->extension, factionname(f), strerror(error)); errno = 0; } } while (error); diff --git a/src/reports.test.c b/src/reports.test.c index bc89bb4b4..c9fe39c19 100644 --- a/src/reports.test.c +++ b/src/reports.test.c @@ -1,5 +1,4 @@ #include -#include #include "reports.h" #include "move.h" diff --git a/src/spells/magicresistance.c b/src/spells/magicresistance.c index a897ea348..7b0c1413d 100644 --- a/src/spells/magicresistance.c +++ b/src/spells/magicresistance.c @@ -3,6 +3,8 @@ #include #include +#include + static struct message *cinfo_magicresistance(const void *obj, objtype_t typ, const struct curse * c, int self) { if (typ == TYP_UNIT) { diff --git a/src/util/nrmessage.h b/src/util/nrmessage.h index 5d775be9e..122b1f1a8 100644 --- a/src/util/nrmessage.h +++ b/src/util/nrmessage.h @@ -12,6 +12,9 @@ #ifndef H_UTIL_NRMESSAGE #define H_UTIL_NRMESSAGE + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/parser.h b/src/util/parser.h index 839968480..802fc56cb 100644 --- a/src/util/parser.h +++ b/src/util/parser.h @@ -10,6 +10,9 @@ #ifndef UTIL_PARSER_H #define UTIL_PARSER_H + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/strings.h b/src/util/strings.h index 7178cf179..05a435e2c 100644 --- a/src/util/strings.h +++ b/src/util/strings.h @@ -18,6 +18,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifndef STRINGS_H #define STRINGS_H + +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/src/util/translation.h b/src/util/translation.h index 01c19a72d..76206021b 100644 --- a/src/util/translation.h +++ b/src/util/translation.h @@ -12,6 +12,9 @@ #ifndef H_UTIL_TRANSLATION #define H_UTIL_TRANSLATION + +#include + #ifdef __cplusplus extern "C" { #endif From 0208304b0720f229c78782d4d36fb81e2c2cbacd Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Nov 2016 21:12:14 +0100 Subject: [PATCH 05/12] use autoconf when not MSCVER or GLIBC --- autoconf.h.in | 123 ------------------------------------------------- src/platform.h | 11 ++--- storage | 2 +- 3 files changed, 6 insertions(+), 130 deletions(-) diff --git a/autoconf.h.in b/autoconf.h.in index 1c151b6f9..f3f197db1 100644 --- a/autoconf.h.in +++ b/autoconf.h.in @@ -33,127 +33,4 @@ #cmakedefine HAVE_DIRECT_MKDIR 1 #cmakedefine HAVE_DIRECT__MKDIR 1 -#if defined(HAVE_STRINGS_H) -#include -#endif - -#if defined(HAVE_UNISTD_H) -#include -#endif - -#if defined(HAVE_IO_H) -#include -#endif - -#if defined(HAVE_WINDOWS_H) -#include -#endif - -#if defined(HAVE_STDBOOL_H) -# include -#else -# if ! HAVE__BOOL -# ifdef __cplusplus -typedef bool _Bool; -# else -typedef unsigned char _Bool; -# endif -# endif -# define bool _Bool -# define false 0 -# define true 1 -# define __bool_true_false_are_defined 1 -#endif - -#ifndef HAVE__ACCESS -#ifdef HAVE_ACCESS -#define _access(path, mode) access(path, mode) -#endif -#endif - -#ifndef _A_RDONLY -#ifdef R_OK -#define _A_RDONLY R_OK -#endif -#endif - -#if !defined(HAVE__MEMICMP) -#if defined(HAVE_MEMICMP) -#define _memicmp(a, b, n) memicmp(a, b, n) -#elif defined(HAVE_STRNCASECMP) -#define _memicmp(a, b, n) strncasecmp(a, b, n) -#else -#define _memicmp(a, b, n) lcp_memicmp(a, b, n) -#endif -#endif - -#if !defined(HAVE__STRCMPL) -#if defined(HAVE_STRCMPL) -#define _strcmpl(a, b) strcmpl(a, b) -#elif defined(HAVE__STRICMP) -#define _strcmpl(a, b) _stricmp(a, b) -#elif defined(HAVE_STRICMP) -#define _strcmpl(a, b) stricmp(a, b) -#elif defined(HAVE_STRCASECMP) -#define _strcmpl(a, b) strcasecmp(a, b) -#else -#define _strcmpl(a, b) lcp_strcmpl(a, b) -#endif -#endif - -#if defined(HAVE_DIRECT__MKDIR) -#include -#elif defined(HAVE_DIRECT_MKDIR) -#include -#define _mkdir(a) mkdir(a) -#elif defined(HAVE_SYS_STAT_MKDIR) -#include -#define _mkdir(a) mkdir(a, 0777) -#endif - -#if !defined(HAVE__STRLWR) -#if defined(HAVE_STRLWR) -#define _strlwr(a) strlwr(a) -#else -#define _strlwr(a) lcp_strlwr(a) -#endif -#endif - -#if !defined(HAVE__STRDUP) -#if defined(HAVE_STRDUP) -#define _strdup(a) strdup(a) -#else -#define _strdup(a) lcp_strdup(a) -#endif -#endif - -#if !defined(HAVE__SLEEP) -#if defined(HAVE_USLEEP) -#define _sleep(a) usleep(a) -#elif defined(HAVE_SLEEP) -#define _sleep(a) sleep((a)/1000) -#else -#define _sleep(a) lcp_sleep(a) -#endif -#endif - -#if !defined(HAVE__SNPRINTF) -#if defined(HAVE_SNPRINTF) -#define _snprintf snprintf -#else -#define _snprintf lcp_snprintf -#endif -#endif - -#ifndef _min -#define _min(a,b) ((a) < (b) ? (a) : (b)) -#endif -#ifndef _max -#define _max(a,b) ((a) > (b) ? (a) : (b)) -#endif - -#if !defined(DBG_UNREFERENCED_PARAMETER) -#define DBG_UNREFERENCED_PARAMETER(x) x -#endif - #endif diff --git a/src/platform.h b/src/platform.h index 553f734c9..0a191d345 100644 --- a/src/platform.h +++ b/src/platform.h @@ -78,9 +78,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # define _CRTDBG_MAP_ALLOC #endif -#endif /* _MSC_VER_ */ - -#if defined __GNUC__ +#elif defined __GLIBC__ +#error gnuc # define _POSIX_C_SOURCE 200809L # undef _DEFAULT_SOURCE # define _DEFAULT_SOURCE @@ -90,12 +89,12 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # define HAVE_SYS_STAT_MKDIR # define HAVE_STRDUP # define HAVE_UNISTD_H -#endif - -#ifdef SOLARIS +#elif defined SOLARIS # define _SYS_PROCSET_H #undef _XOPEN_SOURCE # define _XOPEN_SOURCE +#else +#include #endif #define unused_arg (void) diff --git a/storage b/storage index 18cc3bb8f..2117191d4 160000 --- a/storage +++ b/storage @@ -1 +1 @@ -Subproject commit 18cc3bb8f8906237915eb31c9899f95340318087 +Subproject commit 2117191d4ad75e1eb14809878bc71d15b20a5d86 From 31ff07cbec79ee144bc83f8d125e54e83301ec62 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Nov 2016 21:17:10 +0100 Subject: [PATCH 06/12] do not #error --- s/build | 2 +- src/platform.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/s/build b/s/build index 363e3e5a6..b59804626 100755 --- a/s/build +++ b/s/build @@ -39,5 +39,5 @@ echo "build eressea" cd $ROOT/$BUILD VERSION=$(git describe --match 'v*.*.*' --tags | sed 's/^v//') cmake -DERESSEA_VERSION="$VERSION" .. -make -k $MAKEOPTS && make test +make $MAKEOPTS && make test cd $OLDPWD diff --git a/src/platform.h b/src/platform.h index 0a191d345..ee19e0723 100644 --- a/src/platform.h +++ b/src/platform.h @@ -79,7 +79,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #endif #elif defined __GLIBC__ -#error gnuc # define _POSIX_C_SOURCE 200809L # undef _DEFAULT_SOURCE # define _DEFAULT_SOURCE From 2f81dc16b2882388a04d2e0569c4e033614910fe Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Nov 2016 21:57:35 +0100 Subject: [PATCH 07/12] fix autoconf usage, force my OSX build to use it --- src/platform.h | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) diff --git a/src/platform.h b/src/platform.h index ee19e0723..765b5c4a7 100644 --- a/src/platform.h +++ b/src/platform.h @@ -23,6 +23,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define LOMEM #endif +#undef USE_AUTOCONF +#define USE_AUTOCONF + #ifdef _MSC_VER # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN @@ -78,7 +81,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # define _CRTDBG_MAP_ALLOC #endif -#elif defined __GLIBC__ +#undef USE_AUTOCONF +#elif __GNUC__ +#include +#if __GLIBC__ >= 2 # define _POSIX_C_SOURCE 200809L # undef _DEFAULT_SOURCE # define _DEFAULT_SOURCE @@ -88,11 +94,11 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # define HAVE_SYS_STAT_MKDIR # define HAVE_STRDUP # define HAVE_UNISTD_H -#elif defined SOLARIS -# define _SYS_PROCSET_H -#undef _XOPEN_SOURCE -# define _XOPEN_SOURCE -#else +# undef USE_AUTOCONF +#endif +#endif + +#ifdef USE_AUTOCONF #include #endif @@ -164,9 +170,8 @@ typedef unsigned char _Bool; #if !defined(HAVE__STRDUP) #if defined(HAVE_STRDUP) +#undef _strdup #define _strdup(a) strdup(a) -#else -#define _strdup(a) lcp_strdup(a) #endif #endif @@ -176,19 +181,5 @@ typedef unsigned char _Bool; #endif #endif -#if !defined(HAVE__STRCMPL) -#if defined(HAVE_STRCMPL) -#define _strcmpl(a, b) strcmpl(a, b) -#elif defined(HAVE__STRICMP) -#define _strcmpl(a, b) _stricmp(a, b) -#elif defined(HAVE_STRICMP) -#define _strcmpl(a, b) stricmp(a, b) -#elif defined(HAVE_STRCASECMP) -#define _strcmpl(a, b) strcasecmp(a, b) -#else -#define _strcmpl(a, b) lcp_strcmpl(a, b) -#endif -#endif - #endif From 14b5c0f922cce8b90480ae80b27a0194f3abb88e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 25 Nov 2016 22:19:59 +0100 Subject: [PATCH 08/12] mac builds using gcc do not need autoconf. need to find a differnt way to test autoconf. --- src/platform.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/platform.h b/src/platform.h index 765b5c4a7..9f4fca3db 100644 --- a/src/platform.h +++ b/src/platform.h @@ -83,8 +83,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #undef USE_AUTOCONF #elif __GNUC__ -#include -#if __GLIBC__ >= 2 # define _POSIX_C_SOURCE 200809L # undef _DEFAULT_SOURCE # define _DEFAULT_SOURCE @@ -96,7 +94,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. # define HAVE_UNISTD_H # undef USE_AUTOCONF #endif -#endif #ifdef USE_AUTOCONF #include From 7870b636558b54edd1481cee2cf1e765e5edd278 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 Nov 2016 07:04:18 +0100 Subject: [PATCH 09/12] fix VS 2015 build --- src/kernel/config.c | 7 ------- src/platform.h | 5 ++++- storage | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/kernel/config.c b/src/kernel/config.c index 80e949215..f33303ead 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -599,13 +599,6 @@ void kernel_done(void) translation_done(); } -#ifndef HAVE_STRDUP -char *_strdup(const char *s) -{ - return strcpy((char *)malloc(sizeof(char) * (strlen(s) + 1)), s); -} -#endif - bool rule_stealth_other(void) { static int rule, config; diff --git a/src/platform.h b/src/platform.h index 9f4fca3db..722ab0b5c 100644 --- a/src/platform.h +++ b/src/platform.h @@ -27,6 +27,9 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define USE_AUTOCONF #ifdef _MSC_VER +# define HAVE_STDBOOL_H +# define HAVE_DIRECT__MKDIR +# define HAVE__ACCESS # define VC_EXTRALEAN # define WIN32_LEAN_AND_MEAN #pragma warning(push) @@ -129,7 +132,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #if defined(HAVE_STDBOOL_H) # include #else -# if ! HAVE__BOOL +# ifndef HAVE__BOOL # ifdef __cplusplus typedef bool _Bool; # else diff --git a/storage b/storage index 2117191d4..18cc3bb8f 160000 --- a/storage +++ b/storage @@ -1 +1 @@ -Subproject commit 2117191d4ad75e1eb14809878bc71d15b20a5d86 +Subproject commit 18cc3bb8f8906237915eb31c9899f95340318087 From 68ce6907f3d776c70b587dca9c62accfc69dea18 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 Nov 2016 07:24:19 +0100 Subject: [PATCH 10/12] new storage module (without textstore and snprintf) --- storage | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/storage b/storage index 18cc3bb8f..2117191d4 160000 --- a/storage +++ b/storage @@ -1 +1 @@ -Subproject commit 18cc3bb8f8906237915eb31c9899f95340318087 +Subproject commit 2117191d4ad75e1eb14809878bc71d15b20a5d86 From 43b8ff1ea8bf7e550cc25684ac0275aed8164e3a Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 Nov 2016 16:21:41 +0100 Subject: [PATCH 11/12] fix strdup compilications when compiling with gcc and autoconf. --- CMakeLists.txt | 4 ++- src/CMakeLists.txt | 2 +- src/platform.h | 71 +++++++++++++++++++++---------------------- src/util/filereader.c | 2 +- src/vortex.c | 5 +-- 5 files changed, 43 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ad7b3528..d60d3d721 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,7 +60,9 @@ CONFIGURE_FILE ( ${CMAKE_CURRENT_SOURCE_DIR}/autoconf.h.in ${CMAKE_BINARY_DIR}/include/autoconf.h) INCLUDE_DIRECTORIES (${CMAKE_BINARY_DIR}/include) -add_definitions(-DUSE_AUTOCONF) + +## skip compiler/libc detection and force cmake autoconf: +#add_definitions(-DUSE_AUTOCONF) add_subdirectory (cutest) add_subdirectory (cJSON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7d7fba859..8a4445b55 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -84,6 +84,7 @@ TOLUA_BINDING(settings.pkg kenel/config.h) ENDIF() set (ERESSEA_SRC + vortex.c calendar.c move.c piracy.c @@ -92,7 +93,6 @@ set (ERESSEA_SRC alchemy.c academy.c upkeep.c - vortex.c names.c lighthouse.c reports.c diff --git a/src/platform.h b/src/platform.h index 722ab0b5c..d7a7e87e5 100644 --- a/src/platform.h +++ b/src/platform.h @@ -16,22 +16,39 @@ ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. **/ -#ifndef CONFIG_H -#define CONFIG_H +#ifndef PLATFORM_H +#define PLATFORM_H #ifdef NDEBUG #define LOMEM #endif -#undef USE_AUTOCONF +// enable X/Open 7 extensions (like strdup): +#ifndef _XOPEN_SOURCE +#define _XOPEN_SOURCE 700 +#endif + +// enable bsd string extensions, prior to glibc 2.12: +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif + +// enable bsd string extensions, since glibc 2.12: +#ifndef _POSIX_C_SOURCE +#define _POSIX_C_SOURCE 200809L +#endif + +#ifndef USE_AUTOCONF #define USE_AUTOCONF #ifdef _MSC_VER -# define HAVE_STDBOOL_H -# define HAVE_DIRECT__MKDIR -# define HAVE__ACCESS -# define VC_EXTRALEAN -# define WIN32_LEAN_AND_MEAN +#undef USE_AUTOCONF +#define HAVE_STDBOOL_H +#define HAVE_DIRECT__MKDIR +#define HAVE__ACCESS + +#define VC_EXTRALEAN +#define WIN32_LEAN_AND_MEAN #pragma warning(push) #pragma warning(disable:4820 4255 4668) # include @@ -66,7 +83,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* warning C4100: was declared deprecated */ #ifndef _CRT_SECURE_NO_DEPRECATE -# define _CRT_SECURE_NO_DEPRECATE +#define _CRT_SECURE_NO_DEPRECATE #endif /* @@ -75,39 +92,25 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * single-threaded I/O model and use the _nolock forms of the functions. */ #ifndef _CRT_DISABLE_PERFCRIT_LOCKS -# define _CRT_DISABLE_PERFCRIT_LOCKS +#define _CRT_DISABLE_PERFCRIT_LOCKS #endif -/* define CRTDBG to enable MSVC CRT Debug library functions */ -#if defined(_DEBUG) && defined(CRTDBG) -# include -# define _CRTDBG_MAP_ALLOC -#endif - -#undef USE_AUTOCONF #elif __GNUC__ -# define _POSIX_C_SOURCE 200809L -# undef _DEFAULT_SOURCE -# define _DEFAULT_SOURCE -# undef __USE_BSD -# define __USE_BSD -# define HAVE_SNPRINTF -# define HAVE_SYS_STAT_MKDIR -# define HAVE_STRDUP -# define HAVE_UNISTD_H -# undef USE_AUTOCONF +#undef USE_AUTOCONF +#define HAVE_SNPRINTF +#define HAVE_SYS_STAT_MKDIR +#define HAVE_STRDUP +#define HAVE_UNISTD_H +#endif #endif #ifdef USE_AUTOCONF +// unknown toolchain, using autoconf #include #endif #define unused_arg (void) -#ifndef INLINE_FUNCTION -# define INLINE_FUNCTION -#endif - #define iswxspace(c) (c==160 || iswspace(c)) #define isxspace(c) (c==160 || isspace(c)) @@ -125,10 +128,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #endif -#ifdef HAVE_STRINGS_H -#include -#endif - #if defined(HAVE_STDBOOL_H) # include #else @@ -171,7 +170,7 @@ typedef unsigned char _Bool; #if !defined(HAVE__STRDUP) #if defined(HAVE_STRDUP) #undef _strdup -#define _strdup(a) strdup(a) +#define _strdup strdup #endif #endif diff --git a/src/util/filereader.c b/src/util/filereader.c index ee5ec398c..3223ca2ab 100644 --- a/src/util/filereader.c +++ b/src/util/filereader.c @@ -18,7 +18,7 @@ static void unicode_warning(const char *bp) log_warning("invalid sequence in UTF-8 string: %s\n", bp); } -INLINE_FUNCTION int eatwhite(const char *ptr, size_t * total_size) +static int eatwhite(const char *ptr, size_t * total_size) { int ret = 0; diff --git a/src/vortex.c b/src/vortex.c index 244c83a29..725460ce2 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -14,8 +14,9 @@ #include #include -#include #include +#include + typedef struct dir_lookup { char *name; @@ -32,7 +33,7 @@ void register_special_direction(struct locale *lang, const char *name) if (token) { void **tokens = get_translations(lang, UT_SPECDIR); variant var; - char *str = _strdup(name); + char *str = strdup(name); var.v = str; addtoken((struct tnode **)tokens, token, var); From 6079293feaa95bbf532dd75004c936566fc498f7 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sat, 26 Nov 2016 16:54:19 +0100 Subject: [PATCH 12/12] the _BSD_SOURCE macro was deprecated with glibc 2.12 --- src/platform.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/platform.h b/src/platform.h index d7a7e87e5..c781021ae 100644 --- a/src/platform.h +++ b/src/platform.h @@ -28,12 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #define _XOPEN_SOURCE 700 #endif -// enable bsd string extensions, prior to glibc 2.12: -#ifndef _BSD_SOURCE -#define _BSD_SOURCE -#endif - -// enable bsd string extensions, since glibc 2.12: +// enable bsd string extensions, since glibc 2.12 (_BSD_SOURCE is dead): #ifndef _POSIX_C_SOURCE #define _POSIX_C_SOURCE 200809L #endif