remove jsreport.

fix some cppcheck warnings.
This commit is contained in:
Enno Rehling 2018-12-02 05:04:49 +01:00
parent 781acdbf6b
commit 11316a4992
22 changed files with 22 additions and 296 deletions

View File

@ -3383,23 +3383,6 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
return fig; 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) int join_battle(battle * b, unit * u, bool attack, fighter ** cp)
{ {
side *s; side *s;

View File

@ -213,7 +213,6 @@ extern "C" {
/* BEGIN battle interface */ /* BEGIN battle interface */
side * find_side(battle * b, const struct faction * f, const struct group * g, unsigned int flags, const struct faction * stealthfaction); 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); side * get_side(battle * b, const struct unit * u);
fighter * get_fighter(battle * b, const struct unit * u);
/* END battle interface */ /* END battle interface */
void do_battles(void); void do_battles(void);

View File

@ -442,28 +442,6 @@ typedef struct event {
char *msg; char *msg;
} event; } 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) static int tolua_unit_addnotice(lua_State * L)
{ {
unit *self = (unit *)tolua_tousertype(L, 1, 0); unit *self = (unit *)tolua_tousertype(L, 1, 0);

View File

@ -28,6 +28,7 @@
#include "creport.h" #include "creport.h"
#include "report.h" #include "report.h"
#include "names.h" #include "names.h"
#include "prefix.h"
#include "reports.h" #include "reports.h"
#include "spells.h" #include "spells.h"
#include "vortex.h" #include "vortex.h"
@ -50,9 +51,10 @@ void game_done(void)
calendar_cleanup(); calendar_cleanup();
free_functions(); free_functions();
free_config(); free_config();
free_special_directions();
free_locales(); free_locales();
#endif #endif
free_prefixes();
free_special_directions();
kernel_done(); kernel_done();
swapdb_close(); swapdb_close();
} }

View File

@ -1,90 +0,0 @@
#include "reports.h"
#include "jsreport.h"
#include <kernel/faction.h>
#include <kernel/region.h>
#include <kernel/terrain.h>
#include <kernel/terrainid.h>
#include <kernel/config.h>
#include <util/log.h>
#include <limits.h>
#include <stdio.h>
#include <math.h>
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);
}

View File

@ -1,24 +0,0 @@
#pragma once
/*
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2003 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.de>
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

View File

@ -672,16 +672,6 @@ bool curse_active(const curse * c)
return true; 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) bool is_cursed_with(const attrib * ap, const curse * c)
{ {
const attrib *a = ap; const attrib *a = ap;

View File

@ -168,28 +168,6 @@ void set_show_item(faction * f, const struct item_type *itype)
a->data.v = (void *)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) const char *factionname(const faction * f)
{ {
typedef char name[OBJECTIDSIZE + 1]; typedef char name[OBJECTIDSIZE + 1];

View File

@ -117,7 +117,6 @@ extern "C" {
int max_magicians(const faction * f); int max_magicians(const faction * f);
void set_show_item(faction * f, const struct item_type *itype); 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); const char *factionname(const struct faction *f);
struct unit *addplayer(struct region *r, faction * f); struct unit *addplayer(struct region *r, faction * f);
struct faction *addfaction(const char *email, const char *password, struct faction *addfaction(const char *email, const char *password,

View File

@ -240,15 +240,6 @@ race_list *get_familiarraces(void)
return familiarraces; 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) void racelist_insert(struct race_list **rl, const struct race *r)
{ {
race_list *rl2 = (race_list *)malloc(sizeof(race_list)); race_list *rl2 = (race_list *)malloc(sizeof(race_list));

View File

@ -67,7 +67,6 @@ bool terrain_changed(int *cache) {
return false; return false;
} }
void free_terrains(void) void free_terrains(void)
{ {
while (registered_terrains) { while (registered_terrains) {

View File

@ -1,6 +1,8 @@
#include <platform.h> #include <platform.h>
#include "tests.h" #include "tests.h"
#include "prefix.h" #include "prefix.h"
#include "creport.h"
#include "report.h"
#include "reports.h" #include "reports.h"
#include "vortex.h" #include "vortex.h"
@ -230,9 +232,12 @@ static void test_reset(void) {
free_gamedata(); free_gamedata();
free_terrains(); free_terrains();
free_resources(); free_resources();
free_functions();
free_config(); free_config();
default_locale = 0; default_locale = 0;
calendar_cleanup(); calendar_cleanup();
creport_cleanup();
report_cleanup();
close_orders(); close_orders();
log_close(); log_close();
stats_close(); stats_close();
@ -245,29 +250,7 @@ static void test_reset(void) {
free_spellbooks(); free_spellbooks();
free_prefixes(); free_prefixes();
mt_clear(); 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) { for (i = 0; i != MAXSKILLS; ++i) {
enable_skill(i, true); enable_skill(i, true);
} }

View File

@ -125,13 +125,3 @@ const char *itoa10(int i)
{ {
return itoab(i, 10); return itoab(i, 10);
} }
int i10toi36(int i)
{
int r = 0;
while (i) {
r = r * 36 + i % 10;
i = i / 10;
}
return r;
}

View File

@ -25,14 +25,13 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
extern "C" { extern "C" {
#endif #endif
const char *itoa36(int i);
int atoi36(const char *s);
const char *itoa36_r(int i, char *result, size_t len); 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_r(int i, int base, char *result, size_t len);
const char *itoab(int i, int base); const char *itoab(int i, int base);
const char *itoa36(int i);
const char *itoa10(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 #ifdef __cplusplus
} }

View File

@ -131,14 +131,14 @@ int bcrypt_gensalt(int factor, char salt[BCRYPT_HASHSIZE])
return (aux == NULL)?5:0; 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; char *aux;
aux = crypt_rn(passwd, salt, hash, BCRYPT_HASHSIZE); aux = crypt_rn(passwd, salt, hash, BCRYPT_HASHSIZE);
return (aux == NULL)?1:0; 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; int ret;
char outhash[BCRYPT_HASHSIZE]; char outhash[BCRYPT_HASHSIZE];

View File

@ -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 * The return value is zero if the password could be hashed and nonzero
* otherwise. * 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]); char hash[BCRYPT_HASHSIZE]);
/* /*
@ -57,7 +57,7 @@ int bcrypt_hashpw(const char *passwd, const char salt[BCRYPT_HASHSIZE],
* passwords don't match. * 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 * Brief Example

View File

@ -80,15 +80,6 @@ void translist(void *l1, void *l2, void *p)
addlist(l2, 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) void freelist(void *p1)
{ {

View File

@ -32,7 +32,6 @@ extern "C" {
void addlist(void *l1, void *p1); void addlist(void *l1, void *p1);
void translist(void *l1, void *l2, void *p); void translist(void *l1, void *l2, void *p);
void freelist(void *p1); void freelist(void *p1);
void removelist(void *l, void *p);
unsigned int listlen(void *l); unsigned int listlen(void *l);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -325,10 +325,10 @@ int log_level(log_t * log, int flags)
static critbit_tree stats = CRITBIT_TREE(); static critbit_tree stats = CRITBIT_TREE();
int stats_count(const char *stat, int delta) { int stats_count(const char *stat, int delta) {
size_t len;
char data[128];
void * match; void * match;
if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) { 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); len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data);
cb_insert(&stats, data, len); cb_insert(&stats, data, len);
return delta; return delta;

View File

@ -148,6 +148,9 @@ const char *section_add(const char *name) {
} }
} }
assert(i < MAXSECTIONS); assert(i < MAXSECTIONS);
if (i == MAXSECTIONS) {
return NULL;
}
assert(sections[i] == NULL); assert(sections[i] == NULL);
if (i + 1 < MAXSECTIONS) { if (i + 1 < MAXSECTIONS) {
sections[i + 1] = NULL; sections[i + 1] = NULL;

View File

@ -177,49 +177,6 @@ int str_hash(const char *s)
return key & 0x7FFFFFFF; 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) unsigned int jenkins_hash(unsigned int a)
{ {
a = (a + 0x7ed55d16) + (a << 12); a = (a + 0x7ed55d16) + (a << 12);

View File

@ -129,13 +129,12 @@ attrib_type at_direction = {
region *find_special_direction(const region * r, const char *token) region *find_special_direction(const region * r, const char *token)
{ {
attrib *a; attrib *a;
spec_direction *d;
if (strlen(token) == 0) if (strlen(token) == 0)
return NULL; return NULL;
for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction; for (a = a_find(r->attribs, &at_direction); a && a->type == &at_direction;
a = a->next) { 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) { if (d->active && strcmp(token, d->keyword) == 0) {
return findregion(d->x, d->y); return findregion(d->x, d->y);