remove tnode from anywhere, and use a void* instead, in preparation for a new findtoken implementation. this needs to have a good testing.

lots of warning fixes for high warning levels in visual studio also
This commit is contained in:
Enno Rehling 2012-05-15 15:04:23 -07:00
parent 77110158f9
commit 116a1ee8ba
28 changed files with 203 additions and 169 deletions

View File

@ -3,17 +3,24 @@
#include "stdafx.h"
#pragma warning(push)
#pragma warning(disable: 4706)
#pragma warning(disable: 4244)
#pragma warning(disable: 4127)
#pragma warning(disable: 4706) /* '__STDC_VERSION__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
#pragma warning(disable: 4244) /* '-=' : conversion from 'int' to 'u16', possible loss of data */
#pragma warning(disable: 4127) /* conditional expression is constant */
#pragma warning(disable: 4820) /* 'sqlite3_index_constraint' : '2' bytes padding added after data member 'usable' */
#pragma warning(disable: 4668) /* <name> is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
#pragma warning(disable: 4242) /* '=' : conversion from 'int' to 'ynVar', possible loss of data */
#include <sqlite3.c>
#pragma warning(pop)
#include <md5.c>
#pragma warning(push)
#pragma warning(disable: 4668) /* <name> is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
#include <bson/bson.c>
#pragma warning(pop)
#include <bson/numbers.c>
#include <md5.c>
#ifndef DISABLE_TESTS
#include <cutest/CuTest.c>
#endif

View File

@ -2,6 +2,13 @@
#include <platform.h>
#include "stdafx.h"
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4668)
#include <curses.h>
#pragma warning(pop)
#endif
#include <util/listbox.c>
#include <gmtool.c>
#include <eressea.c>

View File

@ -1 +1,2 @@
#pragma warning(disable: 4206)
#include "stdafx.h"

View File

@ -1,2 +1,14 @@
#ifdef _MSC_VER
#define VC_EXTRALEAN
#define WIN32_LEAN_AND_MEAN
#pragma warning(disable: 4820)
#pragma warning(push)
#pragma warning(disable: 4668)
#pragma warning(disable: 4255)
#include <windows.h>
#include <sys\stat.h>
#pragma warning(pop)
#endif /* _MSC_VER */
#include <settings.h>
#include <platform.h>

View File

@ -32,10 +32,10 @@ struct attrib_type at_recruit = {
const struct archetype *find_archetype(const char *s, const struct locale *lang)
{
struct tnode *tokens = get_translations(lang, UT_ARCHETYPES);
void **tokens = get_translations(lang, UT_ARCHETYPES);
variant token;
if (findtoken(tokens, s, &token) == E_TOK_SUCCESS) {
if (tokens && findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (const struct archetype *)token.v;
}
return NULL;
@ -53,7 +53,7 @@ void init_archetypes(void)
for (; lang; lang = nextlocale(lang)) {
variant var;
archetype *arch = archetypes;
struct tnode *tokens = get_translations(lang, UT_ARCHETYPES);
void *tokens = get_translations(lang, UT_ARCHETYPES);
for (; arch; arch = arch->next) {
const char *s1, *s2;
var.v = arch;

View File

@ -512,7 +512,7 @@ static void render_messages(FILE * F, faction * f, message_list * msgs)
#ifdef RENDER_CRMESSAGES
char nrbuffer[1024 * 32];
nrbuffer[0] = '\0';
if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f) >= 0) {
if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f) > 0) {
fprintf(F, "MESSAGE %u\n", messagehash(m->msg));
fprintf(F, "%d;type\n", hash);
fwritestr(F, nrbuffer);

View File

@ -1452,7 +1452,7 @@ static void init_prefixnames(void)
variant var;
const char *pname =
locale_string(lang, mkname("prefix", race_prefixes[key]));
if (findtoken(&in->names, pname, &var) == E_TOK_NOMATCH || var.i != key) {
if (findtoken(in->names, pname, &var) == E_TOK_NOMATCH || var.i != key) {
var.i = key;
addtoken(&in->names, pname, var);
addtoken(&in->names, locale_string(lang, mkname("prefix",
@ -1500,7 +1500,7 @@ static int prefix_cmd(unit * u, struct order *ord)
return 0;
}
if (findtoken(&in->names, s, &var) == E_TOK_NOMATCH) {
if (findtoken(in->names, s, &var) == E_TOK_NOMATCH) {
return 0;
} else if (race_prefixes[var.i] == NULL) {
cmistake(u, ord, 299, MSG_EVENT);

View File

@ -64,19 +64,19 @@ static skill_t getskill(const struct locale *lang)
magic_t getmagicskill(const struct locale * lang)
{
struct tnode *tokens = get_translations(lang, UT_MAGIC);
void **tokens = get_translations(lang, UT_MAGIC);
variant token;
const char *s = getstrtoken();
if (s && s[0]) {
if (findtoken(tokens, s, &token) == E_TOK_SUCCESS) {
if (tokens && s && s[0]) {
if (findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (magic_t) token.i;
} else {
char buffer[3];
buffer[0] = s[0];
buffer[1] = s[1];
buffer[2] = '\0';
if (findtoken(tokens, buffer, &token) == E_TOK_SUCCESS) {
if (findtoken(*tokens, buffer, &token) == E_TOK_SUCCESS) {
return (magic_t) token.i;
}
}

View File

@ -122,32 +122,32 @@ static void create_transaction(int type, unit * u, order * ord)
transactions[type] = tr;
}
static void cmd_kick(const tnode * tnext, void *data, struct order *ord)
static void cmd_kick(const void *tnext, void *data, struct order *ord)
{
create_transaction(ALLIANCE_KICK, (unit *) data, ord);
}
static void cmd_leave(const tnode * tnext, void *data, struct order *ord)
static void cmd_leave(const void *tnext, void *data, struct order *ord)
{
create_transaction(ALLIANCE_LEAVE, (unit *) data, ord);
}
static void cmd_transfer(const tnode * tnext, void *data, struct order *ord)
static void cmd_transfer(const void *tnext, void *data, struct order *ord)
{
create_transaction(ALLIANCE_TRANSFER, (unit *) data, ord);
}
static void cmd_new(const tnode * tnext, void *data, struct order *ord)
static void cmd_new(const void *tnext, void *data, struct order *ord)
{
create_transaction(ALLIANCE_NEW, (unit *) data, ord);
}
static void cmd_invite(const tnode * tnext, void *data, struct order *ord)
static void cmd_invite(const void *tnext, void *data, struct order *ord)
{
create_transaction(ALLIANCE_INVITE, (unit *) data, ord);
}
static void cmd_join(const tnode * tnext, void *data, struct order *ord)
static void cmd_join(const void *tnext, void *data, struct order *ord)
{
create_transaction(ALLIANCE_JOIN, (unit *) data, ord);
}
@ -290,7 +290,7 @@ static void execute(const struct syntaxtree *syntax, keyword_t kwd)
unit *u = *up;
if (u->number) {
const struct locale *lang = u->faction->locale;
tnode *root = stree_find(syntax, lang);
void *root = stree_find(syntax, lang);
order *ord;
for (ord = u->orders; ord; ord = ord->next) {
if (get_keyword(ord) == kwd) {
@ -321,15 +321,13 @@ void alliance_cmd(void)
if (stree == NULL) {
syntaxtree *slang = stree = stree_create();
while (slang) {
/* struct tnode * root = calloc(sizeof(tnode), 1); */
struct tnode *leaf = calloc(sizeof(tnode), 1);
/* add_command(root, leaf, LOC(slang->lang, "alliance"), NULL); */
add_command(leaf, NULL, LOC(slang->lang, "new"), &cmd_new);
add_command(leaf, NULL, LOC(slang->lang, "invite"), &cmd_invite);
add_command(leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
add_command(leaf, NULL, LOC(slang->lang, "kick"), &cmd_kick);
add_command(leaf, NULL, LOC(slang->lang, "leave"), &cmd_leave);
add_command(leaf, NULL, LOC(slang->lang, "command"), &cmd_transfer);
void *leaf = 0;
add_command(&leaf, NULL, LOC(slang->lang, "new"), &cmd_new);
add_command(&leaf, NULL, LOC(slang->lang, "invite"), &cmd_invite);
add_command(&leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
add_command(&leaf, NULL, LOC(slang->lang, "kick"), &cmd_kick);
add_command(&leaf, NULL, LOC(slang->lang, "leave"), &cmd_leave);
add_command(&leaf, NULL, LOC(slang->lang, "command"), &cmd_transfer);
slang->root = leaf;
slang = slang->next;
}
@ -344,10 +342,9 @@ void alliancejoin(void)
if (stree == NULL) {
syntaxtree *slang = stree = stree_create();
while (slang) {
struct tnode *root = calloc(sizeof(tnode), 1);
struct tnode *leaf = calloc(sizeof(tnode), 1);
add_command(root, leaf, LOC(slang->lang, "alliance"), NULL);
add_command(leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
void *leaf = 0;
add_command(&leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
add_command(&slang->root, leaf, LOC(slang->lang, "alliance"), NULL);
slang = slang->next;
}
}

View File

@ -39,6 +39,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <util/functions.h>
#include <util/language.h>
#include <util/log.h>
#include <util/quicklist.h>
#include <util/resolve.h>
#include <util/storage.h>
#include <util/umlaut.h>
@ -384,7 +385,7 @@ const building_type *findbuildingtype(const char *name,
}
bnames = bn;
}
if (findtoken(&bn->names, name, &type) == E_TOK_NOMATCH)
if (findtoken(bn->names, name, &type) == E_TOK_NOMATCH)
return NULL;
return (const building_type *)type.v;
}

View File

@ -29,10 +29,10 @@
typedef struct command {
parser fun;
struct tnode *nodes;
void *nodes;
} command;
tnode *stree_find(const syntaxtree * stree, const struct locale *lang)
void *stree_find(const syntaxtree * stree, const struct locale *lang)
{
while (stree) {
if (stree->lang == lang)
@ -50,6 +50,7 @@ syntaxtree *stree_create(void)
syntaxtree *stree = (syntaxtree *) malloc(sizeof(syntaxtree));
stree->lang = lang;
stree->next = sroot;
stree->root = 0;
sroot = stree;
lang = nextlocale(lang);
}
@ -57,7 +58,7 @@ syntaxtree *stree_create(void)
}
void
add_command(struct tnode *keys, struct tnode *tnext,
add_command(void **keys, void *tnext,
const char *str, parser fun)
{
command *cmd = (command *) malloc(sizeof(command));
@ -69,7 +70,7 @@ add_command(struct tnode *keys, struct tnode *tnext,
addtoken(keys, str, var);
}
static int do_command_i(const struct tnode *keys, void *u, struct order *ord)
static int do_command_i(const void *keys, struct unit *u, struct order *ord)
{
const char *c;
variant var;
@ -88,7 +89,7 @@ static int do_command_i(const struct tnode *keys, void *u, struct order *ord)
return E_TOK_NOMATCH;
}
void do_command(const struct tnode *keys, void *u, struct order *ord)
void do_command(const void *keys, struct unit *u, struct order *ord)
{
init_tokens(ord);
skip_token();

View File

@ -16,23 +16,23 @@
extern "C" {
#endif
struct tnode;
struct locale;
struct order;
struct unit;
typedef struct syntaxtree {
const struct locale *lang;
struct tnode *root;
void *root;
struct syntaxtree *next;
} syntaxtree;
typedef void (*parser) (const struct tnode *, void *, struct order *);
extern void add_command(struct tnode *troot, struct tnode *tnext,
typedef void (*parser) (const void *nodes, struct unit * u, struct order *);
extern void add_command(void **troot, void *tnext,
const char *str, parser fun);
extern void do_command(const struct tnode *troot, void *u, struct order *);
extern void do_command(const void *troot, struct unit *u, struct order *);
extern struct syntaxtree *stree_create(void);
extern struct tnode *stree_find(const struct syntaxtree *stree,
extern void *stree_find(const struct syntaxtree *stree,
const struct locale *lang);
#ifdef __cplusplus

View File

@ -1327,11 +1327,11 @@ int getint(void)
const struct race *findrace(const char *s, const struct locale *lang)
{
struct tnode *tokens = get_translations(lang, UT_RACES);
void **tokens = get_translations(lang, UT_RACES);
variant token;
assert(lang);
if (findtoken(tokens, s, &token) == E_TOK_SUCCESS) {
if (tokens && findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (const struct race *)token.v;
}
return NULL;
@ -1339,16 +1339,16 @@ const struct race *findrace(const char *s, const struct locale *lang)
int findoption(const char *s, const struct locale *lang)
{
struct tnode *tokens = get_translations(lang, UT_OPTIONS);
void **tokens = get_translations(lang, UT_OPTIONS);
variant token;
if (findtoken(tokens, s, &token) == E_TOK_SUCCESS) {
if (findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (direction_t) token.i;
}
return NODIRECTION;
}
#if PTRIES
#ifdef PTRIES
static struct trie_node *ptries[UT_MAX][4];
static struct trie_node **get_ptrie(const struct locale *lang, int type)
@ -1456,7 +1456,7 @@ ptrie_insert(struct trie_node **ptrie, const char *name, void *data,
skill_t findskill(const char *s, const struct locale * lang)
{
#if PTRIES
#ifdef PTRIES
char lowercase[256];
int res = unicode_utf8_tolower(lowercase, sizeof(lowercase), s);
if (res == 0) {
@ -1468,10 +1468,10 @@ skill_t findskill(const char *s, const struct locale * lang)
}
return NOSKILL;
#else
struct tnode *tokens = get_translations(lang, UT_SKILLS);
void **tokens = get_translations(lang, UT_SKILLS);
variant token;
if (findtoken(tokens, s, &token) == E_TOK_NOMATCH)
if (findtoken(*tokens, s, &token) == E_TOK_NOMATCH)
return NOSKILL;
return (skill_t) token.i;
#endif
@ -1479,12 +1479,12 @@ skill_t findskill(const char *s, const struct locale * lang)
keyword_t findkeyword(const char *s, const struct locale * lang)
{
struct tnode *tokens = get_translations(lang, UT_KEYWORDS);
void **tokens = get_translations(lang, UT_KEYWORDS);
variant token;
if (*s == '@')
s++;
if (findtoken(tokens, s, &token) == E_TOK_NOMATCH)
if (findtoken(*tokens, s, &token) == E_TOK_NOMATCH)
return NOKEYWORD;
if (global.disabled[token.i])
return NOKEYWORD;
@ -1493,10 +1493,10 @@ keyword_t findkeyword(const char *s, const struct locale * lang)
param_t findparam(const char *s, const struct locale * lang)
{
struct tnode *tokens = get_translations(lang, UT_PARAMS);
void **tokens = get_translations(lang, UT_PARAMS);
variant token;
if (findtoken(tokens, s, &token) == E_TOK_NOMATCH) {
if (findtoken(*tokens, s, &token) == E_TOK_NOMATCH) {
const building_type *btype = findbuildingtype(s, lang);
if (btype != NULL)
return (param_t) P_GEBAEUDE;
@ -2005,7 +2005,7 @@ void *gc_add(void *p)
return p;
}
static void init_directions(tnode * root, const struct locale *lang)
static void init_directions(void ** root, const struct locale *lang)
{
/* mit dieser routine kann man mehrere namen für eine direction geben,
* das ist für die hexes ideal. */
@ -2030,7 +2030,7 @@ static void init_directions(tnode * root, const struct locale *lang)
NULL, NODIRECTION}
};
int i;
struct tnode *tokens = get_translations(lang, UT_DIRECTIONS);
void **tokens = get_translations(lang, UT_DIRECTIONS);
for (i = 0; dirs[i].direction != NODIRECTION; ++i) {
variant token;
@ -2041,10 +2041,10 @@ static void init_directions(tnode * root, const struct locale *lang)
direction_t finddirection(const char *s, const struct locale *lang)
{
struct tnode *tokens = get_translations(lang, UT_DIRECTIONS);
void **tokens = get_translations(lang, UT_DIRECTIONS);
variant token;
if (findtoken(tokens, s, &token) == E_TOK_SUCCESS) {
if (findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (direction_t) token.i;
}
return NODIRECTION;
@ -2055,9 +2055,9 @@ static void init_locale(const struct locale *lang)
variant var;
int i;
const struct race *rc;
struct tnode *tokens;
void **tokens;
const terrain_type *terrain;
#if PTRIES
#ifdef PTRIES
trie_node **ptrie;
#endif
@ -2099,7 +2099,7 @@ static void init_locale(const struct locale *lang)
var.i = i;
addtoken(tokens, LOC(lang, parameters[i]), var);
}
#if PTRIES
#ifdef PTRIES
ptrie = get_ptrie(lang, UT_SKILLS);
for (i = 0; i != MAXSKILLS; ++i) {
skill_t sk = (skill_t) i;

View File

@ -1093,7 +1093,7 @@ const resource_type *findresourcetype(const char *name,
rnames = rn;
}
if (findtoken(&rn->names, name, &token) == E_TOK_NOMATCH)
if (findtoken(rn->names, name, &token) == E_TOK_NOMATCH)
return NULL;
return (const resource_type *)token.v;
}
@ -1131,7 +1131,7 @@ void init_itemnames(void)
for (itl = itemtypes[key]; itl; itl = itl->next) {
variant var;
const char *iname = locale_string(lang, itl->rtype->_name[0]);
if (findtoken(&in->names, iname, &var) == E_TOK_NOMATCH
if (findtoken(in->names, iname, &var) == E_TOK_NOMATCH
|| var.v != itl) {
var.v = (void *)itl;
addtoken(&in->names, iname, var);
@ -1159,7 +1159,7 @@ const item_type *finditemtype(const char *name, const struct locale *lang)
init_itemnames();
for (in = inames; in->lang != lang; in = in->next) ;
}
if (findtoken(&in->names, name, &var) == E_TOK_NOMATCH)
if (findtoken(in->names, name, &var) == E_TOK_NOMATCH)
return NULL;
return (const item_type *)var.v;
}

View File

@ -539,7 +539,7 @@ void add_spellname(sc_mage * mage, const spell * sp)
variant token;
const char *n = spell_name(sp, names->lang);
token.v = (void *)sp;
addtoken(names->tokens, n, token);
addtoken(&names->tokens, n, token);
names = names->next;
}
}

View File

@ -108,7 +108,7 @@ typedef struct combatspell {
typedef struct spell_names {
struct spell_names *next;
const struct locale *lang;
struct tnode * tokens;
void * tokens;
} spell_names;
typedef struct sc_mage {

View File

@ -1027,10 +1027,14 @@ static void cycle_route(order * ord, unit * u, int gereist)
const struct locale *lang = u->faction->locale;
pause = false;
token = getstrtoken();
d = finddirection(token, lang);
if (d == D_PAUSE) {
pause = true;
} else if (d == NODIRECTION) {
if (token && *token) {
d = finddirection(token, lang);
if (d == D_PAUSE) {
pause = true;
} else if (d == NODIRECTION) {
break;
}
} else {
break;
}
if (cm < gereist) {

View File

@ -190,16 +190,16 @@ adjust_coordinates(const faction * f, int *x, int *y, const plane * pl,
ny -= ursprung_y(f, pl, r);
}
if (pl) {
nx -= plane_center_x(pl);
ny -= plane_center_y(pl);
}
if (pl) {
int plx = plane_center_x(pl);
int ply = plane_center_y(pl);
int width = plane_width(pl);
int height = plane_height(pl);
int width_2 = width / 2;
int height_2 = height / 2;
nx -= plx;
ny -= ply;
if (nx < 0)
nx = (width - (-nx) % width);
if (nx > width_2)
@ -208,12 +208,13 @@ adjust_coordinates(const faction * f, int *x, int *y, const plane * pl,
ny = (height - (-ny) % height);
if (ny > height_2)
ny -= height;
}
assert(!pl || nx <= pl->maxx - plane_center_x(pl));
assert(!pl || nx >= pl->minx - plane_center_x(pl));
assert(!pl || ny <= pl->maxy - plane_center_y(pl));
assert(!pl || ny >= pl->miny - plane_center_y(pl));
assert(nx <= pl->maxx - plx);
assert(nx >= pl->minx - plx);
assert(ny <= pl->maxy - ply);
assert(ny >= pl->miny - ply);
}
*x = nx;
*y = ny;

View File

@ -64,7 +64,7 @@ extern int dice_rand(const char *s);
region *regions;
int get_maxluxuries()
int get_maxluxuries(void)
{
static int maxluxuries = -1;
if (maxluxuries == -1) {
@ -219,7 +219,7 @@ void register_special_direction(const char *name)
char *str = strdup(name);
for (lang = locales; lang; lang = nextlocale(lang)) {
tnode *tokens = get_translations(lang, UT_SPECDIR);
void **tokens = get_translations(lang, UT_SPECDIR);
const char *token = LOC(lang, name);
if (token) {
@ -311,9 +311,9 @@ region *find_special_direction(const region * r, const char *token,
d = (spec_direction *) (a->data.v);
if (d->active) {
tnode *tokens = get_translations(lang, UT_SPECDIR);
void **tokens = get_translations(lang, UT_SPECDIR);
variant var;
if (findtoken(tokens, token, &var) == E_TOK_SUCCESS) {
if (findtoken(*tokens, token, &var) == E_TOK_SUCCESS) {
if (strcmp((const char *)var.v, d->keyword) == 0) {
return findregion(d->x, d->y);
}
@ -451,24 +451,19 @@ boolean pnormalize(int *x, int *y, const plane * pl)
static region *rfindhash(int x, int y)
{
unsigned int rid;
rid = coor_hashkey(x, y);
unsigned int rid = coor_hashkey(x, y);
int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH);
#if HASH_STATISTICS
++hash_requests;
#endif
if (rid >= 0) {
int key = HASH1(rid, RMAXHASH), gk = HASH2(rid, RMAXHASH);
while (regionhash[key] != NULL && (regionhash[key] == DELMARKER
|| regionhash[key]->x != x || regionhash[key]->y != y)) {
key = (key + gk) % RMAXHASH;
while (regionhash[key] != NULL && (regionhash[key] == DELMARKER
|| regionhash[key]->x != x || regionhash[key]->y != y)) {
key = (key + gk) % RMAXHASH;
#if HASH_STATISTICS
++hash_misses;
++hash_misses;
#endif
}
return regionhash[key];
}
return NULL;
return regionhash[key];
}
void rhash(region * r)

View File

@ -76,7 +76,7 @@ const ship_type *findshiptype(const char *name, const struct locale *lang)
}
snames = sn;
}
if (findtoken(&sn->names, name, &var) == E_TOK_NOMATCH)
if (findtoken(sn->names, name, &var) == E_TOK_NOMATCH)
return NULL;
return (const ship_type *)var.v;
}

View File

@ -84,12 +84,12 @@ spell *get_spellfromtoken(sc_mage *mage, const char *name,
names = (spell_names *)calloc(1, sizeof(spell_names));
names->next = mage->spellnames;
names->lang = lang;
names->tokens = (tnode *)calloc(1, sizeof(tnode));
names->tokens = 0;
for (qi = 0, ql = mage->spells; ql; ql_advance(&ql, &qi, 1)) {
spell *sp = (spell *) ql_get(ql, qi);
const char *n = spell_name(sp, lang);
token.v = sp;
addtoken(names->tokens, n, token);
addtoken(&names->tokens, n, token);
}
mage->spellnames = names;
}
@ -105,7 +105,6 @@ spell *find_spellbyid(unsigned int id)
quicklist *ql;
int qi;
assert(id >= 0);
if (id == 0)
return NULL;
for (qi = 0, ql = spells; ql; ql_advance(&ql, &qi, 1)) {

View File

@ -129,7 +129,7 @@ attrib *make_atgmcreate(const struct item_type * itype)
return a;
}
static void gm_create(const tnode * tnext, void *data, struct order *ord)
static void gm_create(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
int i;
@ -168,7 +168,7 @@ static boolean has_permission(const attrib * permissions, unsigned int key)
** GM: GATE <id> <x> <y>
** requires: permission-key "gmgate"
**/
static void gm_gate(const tnode * tnext, void *data, struct order *ord)
static void gm_gate(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
const struct plane *pl = rplane(u->region);
@ -202,7 +202,7 @@ static void gm_gate(const tnode * tnext, void *data, struct order *ord)
** GM: TERRAFORM <x> <y> <terrain>
** requires: permission-key "gmterf"
**/
static void gm_terraform(const tnode * tnext, void *data, struct order *ord)
static void gm_terraform(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
const struct plane *p = rplane(u->region);
@ -210,7 +210,7 @@ static void gm_terraform(const tnode * tnext, void *data, struct order *ord)
int y = rel_to_abs(p, u->faction, getint(), 1);
const char *c = getstrtoken();
variant token;
tnode *tokens = get_translations(u->faction->locale, UT_TERRAINS);
void **tokens = get_translations(u->faction->locale, UT_TERRAINS);
region *r;
pnormalize(&x, &y, p);
r = findregion(x, y);
@ -225,7 +225,7 @@ static void gm_terraform(const tnode * tnext, void *data, struct order *ord)
return;
}
if (findtoken(tokens, c, &token) != E_TOK_NOMATCH) {
if (findtoken(*tokens, c, &token) != E_TOK_NOMATCH) {
const terrain_type *terrain = (const terrain_type *)token.v;
terraform_region(r, terrain);
}
@ -235,7 +235,7 @@ static void gm_terraform(const tnode * tnext, void *data, struct order *ord)
** GM: TELEPORT <unit> <x> <y>
** requires: permission-key "gmtele"
**/
static void gm_teleport(const tnode * tnext, void *data, struct order *ord)
static void gm_teleport(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
const struct plane *p = rplane(u->region);
@ -266,7 +266,7 @@ static void gm_teleport(const tnode * tnext, void *data, struct order *ord)
** GM: TELL PLANE <string>
** requires: permission-key "gmmsgr"
**/
static void gm_messageplane(const tnode * tnext, void *data, struct order *ord)
static void gm_messageplane(const void *tnext,void *data, struct order *ord)
{
unit *gm = (unit *) data;
const struct plane *p = rplane(gm->region);
@ -302,7 +302,7 @@ static void gm_messageplane(const tnode * tnext, void *data, struct order *ord)
}
static void
gm_messagefaction(const tnode * tnext, void *data, struct order *ord)
gm_messagefaction(const void *tnext,void *data, struct order *ord)
{
unit *gm = (unit *) data;
int n = getid();
@ -333,7 +333,7 @@ gm_messagefaction(const tnode * tnext, void *data, struct order *ord)
** GM: TELL REGION <x> <y> <string>
** requires: permission-key "gmmsgr"
**/
static void gm_messageregion(const tnode * tnext, void *data, struct order *ord)
static void gm_messageregion(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
const struct plane *p = rplane(u->region);
@ -359,7 +359,7 @@ static void gm_messageregion(const tnode * tnext, void *data, struct order *ord)
** GM: KILL UNIT <id> <string>
** requires: permission-key "gmkill"
**/
static void gm_killunit(const tnode * tnext, void *data, struct order *ord)
static void gm_killunit(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
const struct plane *p = rplane(u->region);
@ -386,7 +386,7 @@ static void gm_killunit(const tnode * tnext, void *data, struct order *ord)
** GM: KILL FACTION <id> <string>
** requires: permission-key "gmmsgr"
**/
static void gm_killfaction(const tnode * tnext, void *data, struct order *ord)
static void gm_killfaction(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
int n = getid();
@ -420,7 +420,7 @@ static void gm_killfaction(const tnode * tnext, void *data, struct order *ord)
** GM: TELL <unit> <string>
** requires: permission-key "gmmsgr"
**/
static void gm_messageunit(const tnode * tnext, void *data, struct order *ord)
static void gm_messageunit(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
const struct plane *p = rplane(u->region);
@ -454,7 +454,7 @@ static void gm_messageunit(const tnode * tnext, void *data, struct order *ord)
** GM: GIVE <unit> <int> <itemtype>
** requires: permission-key "gmgive"
**/
static void gm_give(const tnode * tnext, void *data, struct order *ord)
static void gm_give(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
unit *to = findunit(getid());
@ -489,7 +489,7 @@ static void gm_give(const tnode * tnext, void *data, struct order *ord)
** GM: TAKE <unit> <int> <itemtype>
** requires: permission-key "gmtake"
**/
static void gm_take(const tnode * tnext, void *data, struct order *ord)
static void gm_take(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
unit *to = findunit(getid());
@ -524,7 +524,7 @@ static void gm_take(const tnode * tnext, void *data, struct order *ord)
** GM: SKILL <unit> <skill> <tage>
** requires: permission-key "gmskil"
**/
static void gm_skill(const tnode * tnext, void *data, struct order *ord)
static void gm_skill(const void *tnext,void *data, struct order *ord)
{
unit *u = (unit *) data;
unit *to = findunit(getid());
@ -552,10 +552,10 @@ static void gm_skill(const tnode * tnext, void *data, struct order *ord)
}
}
static tnode g_keys;
static tnode g_root;
static tnode g_tell;
static tnode g_kill;
static void * g_keys;
static void * g_root;
static void * g_tell;
static void * g_kill;
void register_gmcmd(void)
{

View File

@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifdef _MSC_VER
# define VC_EXTRALEAN
# define WIN32_LEAN_AND_MEAN
# include <Windows.h>
# include <windows.h>
# undef MOUSE_MOVED
# define STDIO_CP 1252 /* log.c, convert to console character set */
# pragma warning (disable: 4201 4214 4514 4115 4711)
@ -35,6 +35,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# pragma warning(disable: 4100)
/* warning C4100: <name> : unreferenced formal parameter */
# pragma warning(disable: 4996)
/* <name> is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
# pragma warning(disable: 4668)
/* warning C4100: <name> was declared deprecated */
#ifndef _CRT_SECURE_NO_DEPRECATE

View File

@ -233,12 +233,12 @@ locale *nextlocale(const struct locale * lang)
}
typedef struct lstr {
tnode tokens[UT_MAX];
void * tokens[UT_MAX];
} lstr;
static lstr lstrs[MAXLOCALES];
struct tnode *get_translations(const struct locale *lang, int index)
void ** get_translations(const struct locale *lang, int index)
{
assert(lang);
assert(lang->index < MAXLOCALES

View File

@ -63,7 +63,7 @@ extern "C" {
UT_MAX
};
struct tnode *get_translations(const struct locale *lang, int index);
void ** get_translations(const struct locale *lang, int index);
#ifdef __cplusplus
}

View File

@ -28,6 +28,21 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include <string.h>
#include <assert.h>
typedef struct tref {
struct tref *nexthash;
ucs4_t ucs;
struct tnode *node;
} tref;
#define LEAF 1 /* leaf node for a word. always matches */
#define SHARED 2 /* at least two words share the node */
typedef struct tnode {
struct tref *next[NODEHASHSIZE];
unsigned char flags;
variant id;
} tnode;
char * transliterate(char * out, size_t size, const char * in)
{
const char *src = in;
@ -85,17 +100,9 @@ char * transliterate(char * out, size_t size, const char * in)
return *src ? 0 : out;
}
typedef struct tref {
struct tref *nexthash;
ucs4_t ucs;
struct tnode *node;
} tref;
#define LEAF 1 /* leaf node for a word. always matches */
#define SHARED 2 /* at least two words share the node */
void addtoken(tnode * root, const char *str, variant id)
void addtoken(void ** root, const char *str, variant id)
{
tnode * tk;
static const struct replace { /* STATIC_CONST: constant value */
ucs4_t ucs;
const char str[3];
@ -120,9 +127,15 @@ void addtoken(tnode * root, const char *str, variant id)
};
assert(root);
if (!*root) {
tk = *root = calloc(1, sizeof(tnode));
} else {
tk = *root;
}
assert(tk && tk==*root);
if (!*str) {
root->id = id;
root->flags |= LEAF;
tk->id = id;
tk->flags |= LEAF;
} else {
tref *next;
int ret, index, i = 0;
@ -139,9 +152,9 @@ void addtoken(tnode * root, const char *str, variant id)
index = ucs % NODEHASHSIZE;
#endif
assert(index >= 0);
next = root->next[index];
if (!(root->flags & LEAF))
root->id = id;
next = tk->next[index];
if (!(tk->flags & LEAF))
tk->id = id;
while (next && next->ucs != ucs)
next = next->nexthash;
if (!next) {
@ -158,8 +171,8 @@ void addtoken(tnode * root, const char *str, variant id)
ref = (tref *)malloc(sizeof(tref));
ref->ucs = ucs;
ref->node = node;
ref->nexthash = root->next[index];
root->next[index] = ref;
ref->nexthash = tk->next[index];
tk->next[index] = ref;
/* try lower/upper casing the character, and try again */
if (ucs != lcs) {
@ -171,8 +184,8 @@ void addtoken(tnode * root, const char *str, variant id)
ref = (tref *)malloc(sizeof(tref));
ref->ucs = lcs;
ref->node = node;
ref->nexthash = root->next[index];
root->next[index] = ref;
ref->nexthash = tk->next[index];
tk->next[index] = ref;
}
next = ref;
} else {
@ -180,7 +193,7 @@ void addtoken(tnode * root, const char *str, variant id)
if ((next->node->flags & LEAF) == 0)
next->node->id.v = NULL; /* why? */
}
addtoken(next->node, str + len, id);
addtoken(&next->node, str + len, id);
while (replace[i].str[0]) {
if (lcs == replace[i].ucs) {
char zText[1024];
@ -203,10 +216,11 @@ void freetokens(struct tnode *root)
}
}
int findtoken(const tnode * tk, const char *str, variant * result)
int findtoken(void * root, const char *str, variant * result)
{
assert(tk);
if (!str || *str == 0)
const tnode * tk = (const tnode *)root;
if (!tk || !str || *str == 0)
return E_TOK_NOMATCH;
do {

View File

@ -28,24 +28,17 @@ extern "C" {
#define E_TOK_NOMATCH (-1)
#define E_TOK_SUCCESS 0
#define NODEHASHSIZE 8
struct tref;
typedef struct tnode {
struct tref *next[NODEHASHSIZE];
unsigned char flags;
variant id;
} tnode;
int findtoken(const struct tnode *tk, const char *str, variant * result);
void addtoken(struct tnode *root, const char *str, variant id);
void freetokens(struct tnode *root);
int findtoken(const void *tk, const char *str, variant * result);
void addtoken(void **root, const char *str, variant id);
void freetokens(void *root);
char * transliterate(char * out, size_t size, const char * in);
typedef struct local_names {
struct local_names *next;
const struct locale *lang;
struct tnode names;
void * names;
} local_names;
#ifdef __cplusplus

View File

@ -22,12 +22,12 @@ static void test_transliterate(CuTest * tc)
static void test_umlaut(CuTest * tc)
{
const char * umlauts = "\xc3\xa4\xc3\xb6\xc3\xbc\xc3\x9f"; /* auml ouml uuml szlig nul */
tnode tokens = { 0 };
void * tokens = 0;
variant id;
int result;
/* don't crash on an empty set */
result = findtoken(&tokens, "herpderp", &id);
result = findtoken(tokens, "herpderp", &id);
CuAssertIntEquals(tc, E_TOK_NOMATCH, result);
id.i = 1;
@ -38,24 +38,24 @@ static void test_umlaut(CuTest * tc)
addtoken(&tokens, umlauts, id);
/* we can find substrings if they are significant */
result = findtoken(&tokens, "herp", &id);
result = findtoken(tokens, "herp", &id);
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
CuAssertIntEquals(tc, 1, id.i);
result = findtoken(&tokens, "DERP", &id);
result = findtoken(tokens, "DERP", &id);
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
CuAssertIntEquals(tc, 2, id.i);
result = findtoken(&tokens, umlauts, &id);
result = findtoken(tokens, umlauts, &id);
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
CuAssertIntEquals(tc, 3, id.i);
/* transliteration is the real magic */
result = findtoken(&tokens, "AEoeUEss", &id);
result = findtoken(tokens, "AEoeUEss", &id);
CuAssertIntEquals(tc, E_TOK_SUCCESS, result);
CuAssertIntEquals(tc, 3, id.i);
result = findtoken(&tokens, "herp-a-derp", &id);
result = findtoken(tokens, "herp-a-derp", &id);
CuAssertIntEquals(tc, E_TOK_NOMATCH, result);
}