From b70fd860bfecb146d2225de04051e1bd3c3b3d91 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Tue, 31 Dec 2013 10:25:25 +0100 Subject: [PATCH] add a macro o deal with unsigned int value --- CMakeLists.txt | 2 ++ config.h.in | 2 ++ core/src/kernel/connection.c | 6 +++--- core/src/kernel/curse.c | 5 +++-- core/src/kernel/save.c | 19 ++++++++++--------- core/src/platform.h | 10 +++++++++- core/src/util/attrib.h | 1 + src/curses.c | 2 +- 8 files changed, 31 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf04ffb40..8c3056180 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,6 +10,8 @@ CHECK_SYMBOL_EXISTS (_Bool "stdbool.h" HAVE__BOOL) CHECK_INCLUDE_FILES (strings.h HAVE_STRINGS_H) CHECK_SYMBOL_EXISTS (strdup "string.h" HAVE_STRDUP) CHECK_SYMBOL_EXISTS (_strdup "string.h" HAVE__STRDUP) +CHECK_SYMBOL_EXISTS (mkdir "sys/stat.h" HAVE_MKDIR) +CHECK_SYMBOL_EXISTS (_mkdir "direct.h" HAVE__MKDIR) CONFIGURE_FILE ( ${CMAKE_CURRENT_SOURCE_DIR}/config.h.in diff --git a/config.h.in b/config.h.in index 88f376ac7..9ea6eb099 100644 --- a/config.h.in +++ b/config.h.in @@ -3,3 +3,5 @@ #cmakedefine HAVE_STRINGS_H 1 #cmakedefine HAVE_STRDUP 1 #cmakedefine HAVE__STRDUP 1 +#cmakedefine HAVE_MKDIR 1 +#cmakedefine HAVE__MKDIR 1 diff --git a/core/src/kernel/connection.c b/core/src/kernel/connection.c index 5dc4c470f..ab302267d 100644 --- a/core/src/kernel/connection.c +++ b/core/src/kernel/connection.c @@ -633,7 +633,7 @@ int read_borders(struct storage *store) READ_TOK(store, zText, sizeof(zText)); if (!strcmp(zText, "end")) break; - READ_INT(store, &bid); + READ_UINT(store, &bid); if (global.data_version < UIDHASH_VERSION) { int fx, fy, tx, ty; READ_INT(store, &fx); @@ -644,8 +644,8 @@ int read_borders(struct storage *store) to = findregion(tx, ty); } else { unsigned int fid, tid; - READ_INT(store, &fid); - READ_INT(store, &tid); + READ_UINT(store, &fid); + READ_UINT(store, &tid); from = findregionbyid(fid); to = findregionbyid(tid); } diff --git a/core/src/kernel/curse.c b/core/src/kernel/curse.c index 7ea26d624..467e9ac4e 100644 --- a/core/src/kernel/curse.c +++ b/core/src/kernel/curse.c @@ -187,13 +187,14 @@ int curse_read(attrib * a, void *owner, struct storage *store) curse *c = (curse *) a->data.v; int ur; char cursename[64]; - unsigned int n, flags; + int n; + unsigned int flags; float flt; READ_INT(store, &c->no); chash(c); READ_TOK(store, cursename, sizeof(cursename)); - READ_INT(store, &flags); + READ_UINT(store, &flags); READ_INT(store, &c->duration); if (global.data_version >= CURSEVIGOURISFLOAT_VERSION) { READ_FLT(store, &flt); diff --git a/core/src/kernel/save.c b/core/src/kernel/save.c index e50df12e6..f2aaac17f 100644 --- a/core/src/kernel/save.c +++ b/core/src/kernel/save.c @@ -78,6 +78,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* libc includes */ #include +#include #include #include #include @@ -441,7 +442,7 @@ static void read_alliances(struct storage *store) READ_STR(store, aname, sizeof(aname)); al = makealliance(id, aname); if (global.data_version >= OWNER_2_VERSION) { - READ_INT(store, &al->flags); + READ_UINT(store, &al->flags); } if (global.data_version >= ALLIANCELEADER_VERSION) { read_reference(&al->_leader, store, read_faction_reference, @@ -513,7 +514,7 @@ static void read_owner(struct gamedata *data, region_owner ** powner) owner->since_turn = since_turn; READ_INT(data->store, &owner->morale_turn); if (data->version >= MOURNING_VERSION) { - READ_INT(data->store, &owner->flags); + READ_UINT(data->store, &owner->flags); } else { owner->flags = 0; } @@ -699,7 +700,7 @@ unit *read_unit(struct gamedata *data) READ_INT(data->store, &n); setstatus(u, n); - READ_INT(data->store, &u->flags); + READ_UINT(data->store, &u->flags); u->flags &= UFL_SAVEMASK; if ((u->flags & UFL_ANON_FACTION) && !rule_stealth_faction()) { /* if this rule is broken, then fix broken units */ @@ -848,7 +849,7 @@ static region *readregion(struct gamedata *data, int x, int y) int n; if (data->version >= UID_VERSION) { - READ_INT(data->store, &uid); + READ_UINT(data->store, &uid); } if (r == NULL) { @@ -896,7 +897,7 @@ static region *readregion(struct gamedata *data, int x, int y) } } r->terrain = terrain; - READ_INT(data->store, &r->flags); + READ_UINT(data->store, &r->flags); READ_INT(data->store, &n); r->age = (unsigned short)n; @@ -1269,7 +1270,7 @@ faction *readfaction(struct gamedata * data) READ_INT(data->store, &n); } - READ_INT(data->store, &f->flags); + READ_UINT(data->store, &f->flags); if (f->no == 0) { f->flags |= FFL_NPC; } @@ -1465,7 +1466,7 @@ int readgame(const char *filename, int backup) rng_init(turn); ++global.cookie; READ_INT(&store, &n); /* max_unique_id = ignore */ - READ_INT(&store, &nextborder); + READ_UINT(&store, &nextborder); /* Planes */ planes = NULL; @@ -1490,7 +1491,7 @@ int readgame(const char *filename, int backup) READ_INT(&store, &pl->maxx); READ_INT(&store, &pl->miny); READ_INT(&store, &pl->maxy); - READ_INT(&store, &pl->flags); + READ_UINT(&store, &pl->flags); /* read watchers */ if (gdata.version < FIX_WATCHERS_VERSION) { @@ -1628,7 +1629,7 @@ int readgame(const char *filename, int backup) READ_INT(&store, &sh->size); READ_INT(&store, &sh->damage); if (gdata.version >= FOSS_VERSION) { - READ_INT(&store, &sh->flags); + READ_UINT(&store, &sh->flags); } /* Attribute rekursiv einlesen */ diff --git a/core/src/platform.h b/core/src/platform.h index 96754eaa8..1fa0661ed 100644 --- a/core/src/platform.h +++ b/core/src/platform.h @@ -156,7 +156,6 @@ typedef struct stat stat_type; /* Microsoft Visual C */ #ifdef _MSC_VER -# include # include /* must be included here so strdup is not redefined */ # define R_OK 4 # define HAVE_INLINE @@ -258,4 +257,13 @@ typedef struct _stat stat_type; # endif #endif +#if defined(HAVE__MKDIR) +# include +#else +# if defined(HAVE_MKDIR) +# include +# define _mkdir(s) mkdir(s, 0777) +# endif +#endif + #endif diff --git a/core/src/util/attrib.h b/core/src/util/attrib.h index dc26e80ea..8a8650467 100644 --- a/core/src/util/attrib.h +++ b/core/src/util/attrib.h @@ -23,6 +23,7 @@ extern "C" { #endif struct gamedata; + struct storage; typedef void (*afun) (void); typedef struct attrib { diff --git a/src/curses.c b/src/curses.c index 34f723159..ae78dc966 100644 --- a/src/curses.c +++ b/src/curses.c @@ -65,7 +65,7 @@ static int cw_read(attrib * a, void *target, storage * store) curse_read(a, store, target); br->self = c; - READ_INT(store, &br->id); + READ_UINT(store, &br->id); var.i = br->id; ur_add(var, &wc->wall, resolve_borderid);