From 01b7538ffd1595a01023ebda4735d0fb91639c29 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 2 Dec 2018 05:04:49 +0100 Subject: [PATCH] remove jsreport. fix some cppcheck warnings. --- src/battle.c | 17 -------- src/battle.h | 1 - src/bind_unit.c | 22 ---------- src/eressea.c | 4 +- src/jsreport.c | 90 ---------------------------------------- src/jsreport.h | 24 ----------- src/kernel/curse.c | 10 ----- src/kernel/faction.c | 22 ---------- src/kernel/faction.h | 1 - src/kernel/race.c | 9 ---- src/kernel/terrain.c | 1 - src/tests.c | 29 +++---------- src/util/base36.c | 10 ----- src/util/base36.h | 7 ++-- src/util/crypto/crypto.c | 4 +- src/util/crypto/crypto.h | 4 +- src/util/lists.c | 9 ---- src/util/lists.h | 1 - src/util/log.c | 4 +- src/util/message.c | 3 ++ src/util/strings.c | 43 ------------------- src/vortex.c | 3 +- 22 files changed, 22 insertions(+), 296 deletions(-) delete mode 100644 src/jsreport.c delete mode 100644 src/jsreport.h diff --git a/src/battle.c b/src/battle.c index 00cece5b0..c2f4dfe27 100644 --- a/src/battle.c +++ b/src/battle.c @@ -3383,23 +3383,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack) return fig; } -fighter * get_fighter(battle * b, const struct unit * u) -{ - side * s; - - for (s = b->sides; s != b->sides + b->nsides; ++s) { - fighter *fig; - if (s->faction == u->faction) { - for (fig = s->fighters; fig; fig = fig->next) { - if (fig->unit == u) { - return fig; - } - } - } - } - return 0; -} - int join_battle(battle * b, unit * u, bool attack, fighter ** cp) { side *s; diff --git a/src/battle.h b/src/battle.h index eb6335bce..1b0962eeb 100644 --- a/src/battle.h +++ b/src/battle.h @@ -213,7 +213,6 @@ extern "C" { /* BEGIN battle interface */ side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); side * get_side(battle * b, const struct unit * u); - fighter * get_fighter(battle * b, const struct unit * u); /* END battle interface */ void do_battles(void); diff --git a/src/bind_unit.c b/src/bind_unit.c index 4e3047367..9a5f7e7c6 100644 --- a/src/bind_unit.c +++ b/src/bind_unit.c @@ -442,28 +442,6 @@ typedef struct event { char *msg; } event; -int fctr_handle(struct trigger *tp, void *data) -{ - trigger *t = tp; - event evt = { 0 }; - fctr_data *fd = (fctr_data *)t->data.v; - lua_State *L = (lua_State *)global.vm_state; - unit *u = fd->target; - - evt.args = (event_arg *)data; - lua_rawgeti(L, LUA_REGISTRYINDEX, fd->fhandle); - tolua_pushusertype(L, u, TOLUA_CAST "unit"); - tolua_pushusertype(L, &evt, TOLUA_CAST "event"); - if (lua_pcall(L, 2, 0, 0) != 0) { - const char *error = lua_tostring(L, -1); - log_error("event (%s): %s\n", unitname(u), error); - lua_pop(L, 1); - tolua_error(L, TOLUA_CAST "event handler call failed", NULL); - } - - return 0; -} - static int tolua_unit_addnotice(lua_State * L) { unit *self = (unit *)tolua_tousertype(L, 1, 0); diff --git a/src/eressea.c b/src/eressea.c index 8e7da7f7a..6efb1cb0b 100644 --- a/src/eressea.c +++ b/src/eressea.c @@ -28,6 +28,7 @@ #include "creport.h" #include "report.h" #include "names.h" +#include "prefix.h" #include "reports.h" #include "spells.h" #include "vortex.h" @@ -50,9 +51,10 @@ void game_done(void) calendar_cleanup(); free_functions(); free_config(); - free_special_directions(); free_locales(); #endif + free_prefixes(); + free_special_directions(); kernel_done(); swapdb_close(); } diff --git a/src/jsreport.c b/src/jsreport.c deleted file mode 100644 index a5c730438..000000000 --- a/src/jsreport.c +++ /dev/null @@ -1,90 +0,0 @@ -#include "reports.h" -#include "jsreport.h" -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -static void coor_to_tiled(int *x, int *y) { - *y = -*y; - *x = *x - (*y + 1) / 2; -} - -static void coor_from_tiled(int *x, int *y) { - *x = *x + (*y + 1) / 2; - *y = -*y; -} - -static int report_json(const char *filename, report_context * ctx, const char *charset) -{ - if (config_get_int("jsreport.enabled", 0) != 0) { - FILE * F = fopen(filename, "w"); - if (F) { - int minx = INT_MAX, maxx = INT_MIN, miny = INT_MAX, maxy = INT_MIN; - seen_region *sr; - region *r; - /* traverse all regions */ - for (sr = NULL, r = ctx->first; sr == NULL && r != ctx->last; r = r->next) { - sr = find_seen(ctx->f->seen, r); - } - for (; sr != NULL; sr = sr->next) { - int tx = sr->r->x; - int ty = sr->r->y; - coor_to_tiled(&tx, &ty); - if (ty < miny) miny = ty; - else if (ty > maxy) maxy = ty; - if (tx < minx) minx = tx; - else if (tx > maxx) maxx = tx; - } - if (maxx >= minx && maxy >= miny) { - int y, w = maxx - minx + 1, h = maxy - miny + 1; - fputs("{ \"orientation\":\"hexagonal\",\"staggeraxis\":\"y\",", F); - fprintf(F, "\"staggerindex\":\"%s\", \"height\":%d, \"width\":%d, \"layers\":[", (miny & 1) ? "odd" : "even", h, w); - fprintf(F, "{ \"height\":%d, \"width\":%d, ", h, w); - fputs("\"visible\":true, \"opacity\":1, \"type\":\"tilelayer\", \"name\":\"terrain\", \"x\":0, \"y\":0, \"data\":[", F); - for (y = miny; y <= maxy; ++y) { - int x; - for (x = minx; x <= maxx; ++x) { - int data = 0; - int tx = x, ty = y; - coor_from_tiled(&tx, &ty); - r = findregion(tx, ty); - if (r) { - sr = find_seen(ctx->f->seen, r); - if (sr) { - terrain_t ter = oldterrain(r->terrain); - if (ter == NOTERRAIN) { - data = 1 + r->terrain->_name[0]; - } - else { - data = 1 + (int)ter; - } - } - } - fprintf(F, "%d", data); - if (x != maxx || y != maxy) fputs(", ", F); - } - } - fputs("]}], \"tilesets\": [{\"firstgid\": 1, \"image\": \"magellan.png\", \"imageheight\": 192, \"imagewidth\": 256," - "\"margin\": 0, \"name\": \"hextiles\", \"properties\": { }, \"spacing\": 0, " - "\"tileheight\" : 64, \"tilewidth\" : 64 }], \"tilewidth\": 64, \"tileheight\": 96}", F); - } - fclose(F); - return 0; - } - return -1; - } - return 0; -} - -void register_jsreport(void) -{ - register_reporttype("json", &report_json, 1 << O_JSON); -} diff --git a/src/jsreport.h b/src/jsreport.h deleted file mode 100644 index fa3f7b115..000000000 --- a/src/jsreport.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -/* -+-------------------+ Christian Schlittchen -| | Enno Rehling -| Eressea PBEM host | Katja Zedel -| (c) 1998 - 2003 | Henning Peters -| | Ingo Wilken -+-------------------+ Stefan Reich - -This program may not be used, modified or distributed -without prior permission by the authors of Eressea. -*/ -#ifndef H_GC_JSREPORT -#define H_GC_JSREPORT -#ifdef __cplusplus -extern "C" { -#endif - - void register_jsreport(void); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/kernel/curse.c b/src/kernel/curse.c index bf3c8fef0..d6d77a7ea 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -672,16 +672,6 @@ bool curse_active(const curse * c) return true; } -bool is_cursed_internal(attrib * ap, const curse_type * ct) -{ - curse *c = get_curse(ap, ct); - - if (!c) - return false; - - return true; -} - bool is_cursed_with(const attrib * ap, const curse * c) { const attrib *a = ap; diff --git a/src/kernel/faction.c b/src/kernel/faction.c index c0c908186..7a1b63783 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -168,28 +168,6 @@ void set_show_item(faction * f, const struct item_type *itype) a->data.v = (void *)itype; } -const unit *random_unit_in_faction(const faction * f) -{ - unit *u; - int c = 0, u_nr; - - if (!f->units) { - return NULL; - } - for (u = f->units; u; u = u->next) - c++; - - u_nr = rng_int() % c; - c = 0; - - for (u = f->units; u; u = u->next) - if (u_nr == c) - return u; - - /* Hier sollte er nie ankommen */ - return NULL; -} - const char *factionname(const faction * f) { typedef char name[OBJECTIDSIZE + 1]; diff --git a/src/kernel/faction.h b/src/kernel/faction.h index 0c579603a..8127c371e 100644 --- a/src/kernel/faction.h +++ b/src/kernel/faction.h @@ -117,7 +117,6 @@ extern "C" { int max_magicians(const faction * f); void set_show_item(faction * f, const struct item_type *itype); - const struct unit *random_unit_in_faction(const struct faction *f); const char *factionname(const struct faction *f); struct unit *addplayer(struct region *r, faction * f); struct faction *addfaction(const char *email, const char *password, diff --git a/src/kernel/race.c b/src/kernel/race.c index 6c5f0b626..4a0d0689f 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -240,15 +240,6 @@ race_list *get_familiarraces(void) return familiarraces; } -void racelist_clear(struct race_list **rl) -{ - while (*rl) { - race_list *rl2 = (*rl)->next; - free(*rl); - *rl = rl2; - } -} - void racelist_insert(struct race_list **rl, const struct race *r) { race_list *rl2 = (race_list *)malloc(sizeof(race_list)); diff --git a/src/kernel/terrain.c b/src/kernel/terrain.c index bec8fa8e8..f5041dc03 100644 --- a/src/kernel/terrain.c +++ b/src/kernel/terrain.c @@ -67,7 +67,6 @@ bool terrain_changed(int *cache) { return false; } - void free_terrains(void) { while (registered_terrains) { diff --git a/src/tests.c b/src/tests.c index 22c18ef9c..f6a87b396 100644 --- a/src/tests.c +++ b/src/tests.c @@ -1,6 +1,8 @@ #include #include "tests.h" #include "prefix.h" +#include "creport.h" +#include "report.h" #include "reports.h" #include "vortex.h" @@ -230,9 +232,12 @@ static void test_reset(void) { free_gamedata(); free_terrains(); free_resources(); + free_functions(); free_config(); default_locale = 0; calendar_cleanup(); + creport_cleanup(); + report_cleanup(); close_orders(); log_close(); stats_close(); @@ -245,29 +250,7 @@ static void test_reset(void) { free_spellbooks(); free_prefixes(); mt_clear(); -/* - for (i = 0; i != MAXTERRAINS; ++i) { - int flags = 0; - if (i == T_FIREWALL) { - flags |= FORBIDDEN_REGION; - } else { - flags = FLY_INTO | WALK_INTO; - if (i == T_OCEAN) { - flags |= SEA_REGION | SWIM_INTO; - } - else { - flags |= LAND_REGION; - if (i == T_PLAIN) { - flags |= CAVALRY_REGION | FOREST_REGION; - } - else if (i == T_GLACIER || i == T_ICEBERG || i == T_ICEBERG_SLEEP) { - flags |= ARCTIC_REGION; - } - } - } - test_create_terrain(terrainnames[i], flags); - } -*/ + for (i = 0; i != MAXSKILLS; ++i) { enable_skill(i, true); } diff --git a/src/util/base36.c b/src/util/base36.c index 3b5543e88..b1bef983d 100644 --- a/src/util/base36.c +++ b/src/util/base36.c @@ -125,13 +125,3 @@ const char *itoa10(int i) { return itoab(i, 10); } - -int i10toi36(int i) -{ - int r = 0; - while (i) { - r = r * 36 + i % 10; - i = i / 10; - } - return r; -} diff --git a/src/util/base36.h b/src/util/base36.h index 33f0d2f08..ef08094b2 100644 --- a/src/util/base36.h +++ b/src/util/base36.h @@ -25,14 +25,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. extern "C" { #endif + const char *itoa36(int i); + int atoi36(const char *s); + const char *itoa36_r(int i, char *result, size_t len); const char *itoab_r(int i, int base, char *result, size_t len); const char *itoab(int i, int base); - const char *itoa36(int i); const char *itoa10(int i); - extern int atoi36(const char *s); - extern int atoi10(const char *s); - int i10toi36(int i); #ifdef __cplusplus } diff --git a/src/util/crypto/crypto.c b/src/util/crypto/crypto.c index 75129a826..1e9a84f91 100644 --- a/src/util/crypto/crypto.c +++ b/src/util/crypto/crypto.c @@ -131,14 +131,14 @@ int bcrypt_gensalt(int factor, char salt[BCRYPT_HASHSIZE]) return (aux == NULL)?5:0; } -int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE], char hash[BCRYPT_HASHSIZE]) +int bcrypt_hashpw(const char *passwd, const char salt[], char hash[BCRYPT_HASHSIZE]) { char *aux; aux = crypt_rn(passwd, salt, hash, BCRYPT_HASHSIZE); return (aux == NULL)?1:0; } -int bcrypt_checkpw(const char *passwd, const char hash[BCRYPT_HASHSIZE]) +int bcrypt_checkpw(const char *passwd, const char hash[]) { int ret; char outhash[BCRYPT_HASHSIZE]; diff --git a/src/util/crypto/crypto.h b/src/util/crypto/crypto.h index e45b3ca13..b7adc6137 100644 --- a/src/util/crypto/crypto.h +++ b/src/util/crypto/crypto.h @@ -45,7 +45,7 @@ int bcrypt_gensalt(int workfactor, char salt[BCRYPT_HASHSIZE]); * The return value is zero if the password could be hashed and nonzero * otherwise. */ -int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE], +int bcrypt_hashpw(const char *passwd, const char salt[], char hash[BCRYPT_HASHSIZE]); /* @@ -57,7 +57,7 @@ int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE], * passwords don't match. * */ -int bcrypt_checkpw(const char *passwd, const char hash[BCRYPT_HASHSIZE]); +int bcrypt_checkpw(const char *passwd, const char hash[]); /* * Brief Example diff --git a/src/util/lists.c b/src/util/lists.c index 97e782795..710a3c4f1 100644 --- a/src/util/lists.c +++ b/src/util/lists.c @@ -80,15 +80,6 @@ void translist(void *l1, void *l2, void *p) addlist(l2, p); } -void removelist(void *l, void *p) -{ - - /* remove entry p from list l; free p */ - - choplist(l, p); - free(p); -} - void freelist(void *p1) { diff --git a/src/util/lists.h b/src/util/lists.h index 7fd0ca034..ac6c4a7eb 100644 --- a/src/util/lists.h +++ b/src/util/lists.h @@ -32,7 +32,6 @@ extern "C" { void addlist(void *l1, void *p1); void translist(void *l1, void *l2, void *p); void freelist(void *p1); - void removelist(void *l, void *p); unsigned int listlen(void *l); #ifdef __cplusplus diff --git a/src/util/log.c b/src/util/log.c index 26f745a3b..97f44bd95 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -325,10 +325,10 @@ int log_level(log_t * log, int flags) static critbit_tree stats = CRITBIT_TREE(); int stats_count(const char *stat, int delta) { - size_t len; - char data[128]; void * match; if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) { + size_t len; + char data[128]; len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data); cb_insert(&stats, data, len); return delta; diff --git a/src/util/message.c b/src/util/message.c index fc645f3a2..6eb1b9a16 100644 --- a/src/util/message.c +++ b/src/util/message.c @@ -148,6 +148,9 @@ const char *section_add(const char *name) { } } assert(i < MAXSECTIONS); + if (i == MAXSECTIONS) { + return NULL; + } assert(sections[i] == NULL); if (i + 1 < MAXSECTIONS) { sections[i + 1] = NULL; diff --git a/src/util/strings.c b/src/util/strings.c index ffc443852..23947330b 100644 --- a/src/util/strings.c +++ b/src/util/strings.c @@ -181,49 +181,6 @@ int str_hash(const char *s) return key & 0x7FFFFFFF; } -const char *str_escape_wrong(const char *str, char *buffer, size_t len) -{ - const char *handle_start = strchr(str, '\"'); - if (!handle_start) handle_start = strchr(str, '\\'); - assert(buffer); - if (handle_start) { - const char *p = str; - char *o = buffer; - size_t skip = handle_start - str; - - if (skip > len) { - skip = len; - } - if (skip > 0) { - memcpy(buffer, str, skip); - o += skip; - p += skip; - len -= skip; - } - do { - if (*p == '\"' || *p == '\\') { - if (len < 2) { - break; - } - (*o++) = '\\'; - len -= 2; - } - else { - if (len < 1) { - break; - } - --len; - } - if (len > 0) { - (*o++) = (*p); - } - } while (len > 0 && *p++); - *o = '\0'; - return buffer; - } - return str; -} - unsigned int jenkins_hash(unsigned int a) { a = (a + 0x7ed55d16) + (a << 12); diff --git a/src/vortex.c b/src/vortex.c index c743ad857..36945ca3f 100644 --- a/src/vortex.c +++ b/src/vortex.c @@ -129,13 +129,12 @@ attrib_type at_direction = { region *find_special_direction(const region * r, const char *token) { attrib *a; - spec_direction *d; if (strlen(token) == 0) return NULL; for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; a = a->next) { - d = (spec_direction *)(a->data.v); + spec_direction *d = (spec_direction *)(a->data.v); if (d->active && strcmp(token, d->keyword) == 0) { return findregion(d->x, d->y);