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