From 8656d935559de9299135e7289faa9cbc397ee94c Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 6 May 2005 23:25:08 +0000 Subject: [PATCH] bugfixes to make things compile on linux --- src/common/kernel/reports.c | 100 ++++++++++++++++++------------------ src/common/kernel/reports.h | 2 +- src/common/util/Jamfile | 5 +- src/common/util/bsdstring.c | 3 +- src/config.h | 12 ++++- src/mapper/map_units.c | 2 +- 6 files changed, 67 insertions(+), 57 deletions(-) diff --git a/src/common/kernel/reports.c b/src/common/kernel/reports.c index 1ea5be4bf..ebe039f84 100644 --- a/src/common/kernel/reports.c +++ b/src/common/kernel/reports.c @@ -302,7 +302,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode) dh = 0; if (u->faction == f || telepath_see) { for (sk = 0; sk != MAXSKILLS; sk++) { - bufp += spskill(bufp, f->locale, u, sk, &dh, 1); + bufp += spskill(bufp, sizeof(buf)-(bufp-buf), f->locale, u, sk, &dh, 1); } } @@ -597,59 +597,59 @@ bufunit_ugroupleader(const faction * f, const unit * u, int indent, int mode) #endif size_t -spskill(char * buffer, const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days) +spskill(char * buffer, size_t siz, const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days) { - char * pbuf = buffer; - int i, effsk; + char * bufp = buffer; + int i, effsk; - if (!u->number) return 0; + if (!u->number) return 0; - if (!has_skill(u, sk)) return 0; + if (!has_skill(u, sk)) return 0; + + bufp += strlcpy(bufp, ", ", siz); - pbuf += strlcpy(pbuf, ", ", sizeof(buf)); - - if (!*dh) { - pbuf += strlcpy(pbuf, LOC(lang, "nr_skills"), sizeof(buf)-(bufp-buf)); - pbuf += strlcpy(pbuf, ": ", sizeof(buf)-(bufp-buf)); - *dh = 1; - } - pbuf += strlcpy(pbuf, skillname(sk, lang), sizeof(buf)-(bufp-buf)); - strcpy(pbuf++, " "); - - if (sk == SK_MAGIC){ - if (find_magetype(u) != M_GRAU){ - pbuf += strlcpy(pbuf, LOC(lang, mkname("school", magietypen[find_magetype(u)])), sizeof(buf)-(bufp-buf)); - strcpy(pbuf++, " "); - } - } - - if (sk == SK_STEALTH) { - i = u_geteffstealth(u); - if(i>=0) { - pbuf += sprintf(pbuf, "%d/", i); - } - } - - effsk = effskill(u, sk); - pbuf += sprintf(pbuf, "%d", effsk); - - if(u->faction->options & Pow(O_SHOWSKCHANGE)) { - skill *skill = get_skill(u, sk); - int oldeff = 0; - int diff; - - if (skill->old > 0) { - oldeff = skill->old + get_modifier(u, sk, skill->old, u->region, false); - } - - oldeff = max(0, oldeff); - diff = effsk - oldeff; - - if(diff != 0) { - pbuf += sprintf(pbuf, " (%s%d)", (diff>0)?"+":"", diff); - } - } - return pbuf-buffer; + if (!*dh) { + bufp += strlcpy(bufp, LOC(lang, "nr_skills"), siz-(bufp-buffer)); + bufp += strlcpy(bufp, ": ", sizeof(buf)-(bufp-buf)); + *dh = 1; + } + bufp += strlcpy(bufp, skillname(sk, lang), siz-(bufp-buffer)); + strcpy(bufp++, " "); + + if (sk == SK_MAGIC){ + if (find_magetype(u) != M_GRAU){ + bufp += strlcpy(bufp, LOC(lang, mkname("school", magietypen[find_magetype(u)])), siz-(bufp-buffer)); + strcpy(bufp++, " "); + } + } + + if (sk == SK_STEALTH) { + i = u_geteffstealth(u); + if(i>=0) { + bufp += sprintf(bufp, "%d/", i); + } + } + + effsk = effskill(u, sk); + bufp += sprintf(bufp, "%d", effsk); + + if(u->faction->options & Pow(O_SHOWSKCHANGE)) { + skill *skill = get_skill(u, sk); + int oldeff = 0; + int diff; + + if (skill->old > 0) { + oldeff = skill->old + get_modifier(u, sk, skill->old, u->region, false); + } + + oldeff = max(0, oldeff); + diff = effsk - oldeff; + + if(diff != 0) { + bufp += sprintf(bufp, " (%s%d)", (diff>0)?"+":"", diff); + } + } + return bufp-buffer; } void diff --git a/src/common/kernel/reports.h b/src/common/kernel/reports.h index a5cf28f7a..31ab0cb21 100644 --- a/src/common/kernel/reports.h +++ b/src/common/kernel/reports.h @@ -43,7 +43,7 @@ extern int read_datenames(const char *filename); void sparagraph(struct strlist ** SP, const char *s, int indent, char mark); void lparagraph(struct strlist ** SP, char *s, int indent, char mark); const char *hp_status(const struct unit * u); -extern size_t spskill(char * pbuf, const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days); /* mapper */ +extern size_t spskill(char * pbuf, size_t siz, const struct locale * lang, const struct unit * u, skill_t sk, int *dh, int days); /* mapper */ extern void spunit(struct strlist ** SP, const struct faction * f, const struct unit * u, int indent, int mode); extern int reports(void); diff --git a/src/common/util/Jamfile b/src/common/util/Jamfile index 00d639499..51de42d3a 100644 --- a/src/common/util/Jamfile +++ b/src/common/util/Jamfile @@ -12,7 +12,6 @@ SOURCES = #
malloc.c attrib.c base36.c - bsdstring.c command.c crmessage.c cvector.c @@ -38,4 +37,8 @@ SOURCES = xml.c ; +if $(NO_INLINE) { + SOURCES += bsdstring.c ; +} + Library util : $(SOURCES) ; diff --git a/src/common/util/bsdstring.c b/src/common/util/bsdstring.c index c66da87aa..e0ccffe0c 100644 --- a/src/common/util/bsdstring.c +++ b/src/common/util/bsdstring.c @@ -1,7 +1,6 @@ #include -#include "bsdstring.h" - #include +#include "bsdstring.h" #if !defined(HAVE_STRLCPY) INLINE_FUNCTION size_t diff --git a/src/config.h b/src/config.h index f982b9eb6..9824dd4f3 100644 --- a/src/config.h +++ b/src/config.h @@ -46,6 +46,11 @@ extern "C" { # include #endif +#if defined __GNUC__ +# define HAVE_INLINE +# define INLINE_FUNCTION __inline +#endif + #ifdef DMALLOC # ifndef MALLOCDBG # define MALLOCDBG 1 @@ -148,8 +153,8 @@ typedef struct stat stat_type; # define R_OK 4 # define HAVE__MKDIR_WITHOUT_PERMISSION -#define HAVE_INLINE -#define INLINE_FUNCTION __inline +# define HAVE_INLINE +# define INLINE_FUNCTION __inline # define snprintf _snprintf # define HAVE_SNPRINTF @@ -245,6 +250,9 @@ extern char * strdup(const char *s); } #endif +#ifndef INLINE_FUNCTION +# define INLINE_FUNCTION +#endif /* this function must be implemented in a .o file */ extern char * strnzcpy(char * dst, const char *src, size_t len); #endif diff --git a/src/mapper/map_units.c b/src/mapper/map_units.c index 214851718..018e9be4c 100644 --- a/src/mapper/map_units.c +++ b/src/mapper/map_units.c @@ -896,7 +896,7 @@ mapper_spunit(dbllist ** SP, unit * u, int indent) dh = 0; for (sk = 0; sk != MAXSKILLS; sk++) - spskill(buf, find_locale("de"), u, sk, &dh, 1); + spskill(buf, sizeof(buf), find_locale("de"), u, sk, &dh, 1); dh = 0; for (itm = u->items;itm;itm=itm->next) {