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" #include "stdafx.h"
#pragma warning(push) #pragma warning(push)
#pragma warning(disable: 4706) #pragma warning(disable: 4706) /* '__STDC_VERSION__' is not defined as a preprocessor macro, replacing with '0' for '#if/#elif' */
#pragma warning(disable: 4244) #pragma warning(disable: 4244) /* '-=' : conversion from 'int' to 'u16', possible loss of data */
#pragma warning(disable: 4127) #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> #include <sqlite3.c>
#pragma warning(pop) #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> #include <bson/bson.c>
#pragma warning(pop)
#include <bson/numbers.c> #include <bson/numbers.c>
#include <md5.c>
#ifndef DISABLE_TESTS #ifndef DISABLE_TESTS
#include <cutest/CuTest.c> #include <cutest/CuTest.c>
#endif #endif

View file

@ -2,6 +2,13 @@
#include <platform.h> #include <platform.h>
#include "stdafx.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 <util/listbox.c>
#include <gmtool.c> #include <gmtool.c>
#include <eressea.c> #include <eressea.c>

View file

@ -1 +1,2 @@
#pragma warning(disable: 4206)
#include "stdafx.h" #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 <settings.h>
#include <platform.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) 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; 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 (const struct archetype *)token.v;
} }
return NULL; return NULL;
@ -53,7 +53,7 @@ void init_archetypes(void)
for (; lang; lang = nextlocale(lang)) { for (; lang; lang = nextlocale(lang)) {
variant var; variant var;
archetype *arch = archetypes; archetype *arch = archetypes;
struct tnode *tokens = get_translations(lang, UT_ARCHETYPES); void *tokens = get_translations(lang, UT_ARCHETYPES);
for (; arch; arch = arch->next) { for (; arch; arch = arch->next) {
const char *s1, *s2; const char *s1, *s2;
var.v = arch; var.v = arch;

View file

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

View file

@ -1452,7 +1452,7 @@ static void init_prefixnames(void)
variant var; variant var;
const char *pname = const char *pname =
locale_string(lang, mkname("prefix", race_prefixes[key])); 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; var.i = key;
addtoken(&in->names, pname, var); addtoken(&in->names, pname, var);
addtoken(&in->names, locale_string(lang, mkname("prefix", addtoken(&in->names, locale_string(lang, mkname("prefix",
@ -1500,7 +1500,7 @@ static int prefix_cmd(unit * u, struct order *ord)
return 0; return 0;
} }
if (findtoken(&in->names, s, &var) == E_TOK_NOMATCH) { if (findtoken(in->names, s, &var) == E_TOK_NOMATCH) {
return 0; return 0;
} else if (race_prefixes[var.i] == NULL) { } else if (race_prefixes[var.i] == NULL) {
cmistake(u, ord, 299, MSG_EVENT); 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) magic_t getmagicskill(const struct locale * lang)
{ {
struct tnode *tokens = get_translations(lang, UT_MAGIC); void **tokens = get_translations(lang, UT_MAGIC);
variant token; variant token;
const char *s = getstrtoken(); const char *s = getstrtoken();
if (s && s[0]) { if (tokens && s && s[0]) {
if (findtoken(tokens, s, &token) == E_TOK_SUCCESS) { if (findtoken(*tokens, s, &token) == E_TOK_SUCCESS) {
return (magic_t) token.i; return (magic_t) token.i;
} else { } else {
char buffer[3]; char buffer[3];
buffer[0] = s[0]; buffer[0] = s[0];
buffer[1] = s[1]; buffer[1] = s[1];
buffer[2] = '\0'; buffer[2] = '\0';
if (findtoken(tokens, buffer, &token) == E_TOK_SUCCESS) { if (findtoken(*tokens, buffer, &token) == E_TOK_SUCCESS) {
return (magic_t) token.i; return (magic_t) token.i;
} }
} }

View file

@ -122,32 +122,32 @@ static void create_transaction(int type, unit * u, order * ord)
transactions[type] = tr; 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); 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); 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); 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); 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); 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); create_transaction(ALLIANCE_JOIN, (unit *) data, ord);
} }
@ -290,7 +290,7 @@ static void execute(const struct syntaxtree *syntax, keyword_t kwd)
unit *u = *up; unit *u = *up;
if (u->number) { if (u->number) {
const struct locale *lang = u->faction->locale; const struct locale *lang = u->faction->locale;
tnode *root = stree_find(syntax, lang); void *root = stree_find(syntax, lang);
order *ord; order *ord;
for (ord = u->orders; ord; ord = ord->next) { for (ord = u->orders; ord; ord = ord->next) {
if (get_keyword(ord) == kwd) { if (get_keyword(ord) == kwd) {
@ -321,15 +321,13 @@ void alliance_cmd(void)
if (stree == NULL) { if (stree == NULL) {
syntaxtree *slang = stree = stree_create(); syntaxtree *slang = stree = stree_create();
while (slang) { while (slang) {
/* struct tnode * root = calloc(sizeof(tnode), 1); */ void *leaf = 0;
struct tnode *leaf = calloc(sizeof(tnode), 1); add_command(&leaf, NULL, LOC(slang->lang, "new"), &cmd_new);
/* add_command(root, leaf, LOC(slang->lang, "alliance"), NULL); */ add_command(&leaf, NULL, LOC(slang->lang, "invite"), &cmd_invite);
add_command(leaf, NULL, LOC(slang->lang, "new"), &cmd_new); add_command(&leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
add_command(leaf, NULL, LOC(slang->lang, "invite"), &cmd_invite); add_command(&leaf, NULL, LOC(slang->lang, "kick"), &cmd_kick);
add_command(leaf, NULL, LOC(slang->lang, "join"), &cmd_join); add_command(&leaf, NULL, LOC(slang->lang, "leave"), &cmd_leave);
add_command(leaf, NULL, LOC(slang->lang, "kick"), &cmd_kick); add_command(&leaf, NULL, LOC(slang->lang, "command"), &cmd_transfer);
add_command(leaf, NULL, LOC(slang->lang, "leave"), &cmd_leave);
add_command(leaf, NULL, LOC(slang->lang, "command"), &cmd_transfer);
slang->root = leaf; slang->root = leaf;
slang = slang->next; slang = slang->next;
} }
@ -344,10 +342,9 @@ void alliancejoin(void)
if (stree == NULL) { if (stree == NULL) {
syntaxtree *slang = stree = stree_create(); syntaxtree *slang = stree = stree_create();
while (slang) { while (slang) {
struct tnode *root = calloc(sizeof(tnode), 1); void *leaf = 0;
struct tnode *leaf = calloc(sizeof(tnode), 1); add_command(&leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
add_command(root, leaf, LOC(slang->lang, "alliance"), NULL); add_command(&slang->root, leaf, LOC(slang->lang, "alliance"), NULL);
add_command(leaf, NULL, LOC(slang->lang, "join"), &cmd_join);
slang = slang->next; 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/functions.h>
#include <util/language.h> #include <util/language.h>
#include <util/log.h> #include <util/log.h>
#include <util/quicklist.h>
#include <util/resolve.h> #include <util/resolve.h>
#include <util/storage.h> #include <util/storage.h>
#include <util/umlaut.h> #include <util/umlaut.h>
@ -384,7 +385,7 @@ const building_type *findbuildingtype(const char *name,
} }
bnames = bn; bnames = bn;
} }
if (findtoken(&bn->names, name, &type) == E_TOK_NOMATCH) if (findtoken(bn->names, name, &type) == E_TOK_NOMATCH)
return NULL; return NULL;
return (const building_type *)type.v; return (const building_type *)type.v;
} }

View file

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

View file

@ -16,23 +16,23 @@
extern "C" { extern "C" {
#endif #endif
struct tnode;
struct locale; struct locale;
struct order; struct order;
struct unit;
typedef struct syntaxtree { typedef struct syntaxtree {
const struct locale *lang; const struct locale *lang;
struct tnode *root; void *root;
struct syntaxtree *next; struct syntaxtree *next;
} syntaxtree; } syntaxtree;
typedef void (*parser) (const struct tnode *, void *, struct order *); typedef void (*parser) (const void *nodes, struct unit * u, struct order *);
extern void add_command(struct tnode *troot, struct tnode *tnext, extern void add_command(void **troot, void *tnext,
const char *str, parser fun); 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 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); const struct locale *lang);
#ifdef __cplusplus #ifdef __cplusplus

View file

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

View file

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

View file

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

View file

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

View file

@ -1027,12 +1027,16 @@ static void cycle_route(order * ord, unit * u, int gereist)
const struct locale *lang = u->faction->locale; const struct locale *lang = u->faction->locale;
pause = false; pause = false;
token = getstrtoken(); token = getstrtoken();
if (token && *token) {
d = finddirection(token, lang); d = finddirection(token, lang);
if (d == D_PAUSE) { if (d == D_PAUSE) {
pause = true; pause = true;
} else if (d == NODIRECTION) { } else if (d == NODIRECTION) {
break; break;
} }
} else {
break;
}
if (cm < gereist) { if (cm < gereist) {
/* hier sollte keine PAUSE auftreten */ /* hier sollte keine PAUSE auftreten */
assert(!pause); assert(!pause);

View file

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

View file

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

View file

@ -76,7 +76,7 @@ const ship_type *findshiptype(const char *name, const struct locale *lang)
} }
snames = sn; snames = sn;
} }
if (findtoken(&sn->names, name, &var) == E_TOK_NOMATCH) if (findtoken(sn->names, name, &var) == E_TOK_NOMATCH)
return NULL; return NULL;
return (const ship_type *)var.v; 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 = (spell_names *)calloc(1, sizeof(spell_names));
names->next = mage->spellnames; names->next = mage->spellnames;
names->lang = lang; 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)) { for (qi = 0, ql = mage->spells; ql; ql_advance(&ql, &qi, 1)) {
spell *sp = (spell *) ql_get(ql, qi); spell *sp = (spell *) ql_get(ql, qi);
const char *n = spell_name(sp, lang); const char *n = spell_name(sp, lang);
token.v = sp; token.v = sp;
addtoken(names->tokens, n, token); addtoken(&names->tokens, n, token);
} }
mage->spellnames = names; mage->spellnames = names;
} }
@ -105,7 +105,6 @@ spell *find_spellbyid(unsigned int id)
quicklist *ql; quicklist *ql;
int qi; int qi;
assert(id >= 0);
if (id == 0) if (id == 0)
return NULL; return NULL;
for (qi = 0, ql = spells; ql; ql_advance(&ql, &qi, 1)) { 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; 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; unit *u = (unit *) data;
int i; int i;
@ -168,7 +168,7 @@ static boolean has_permission(const attrib * permissions, unsigned int key)
** GM: GATE <id> <x> <y> ** GM: GATE <id> <x> <y>
** requires: permission-key "gmgate" ** 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; unit *u = (unit *) data;
const struct plane *pl = rplane(u->region); 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> ** GM: TERRAFORM <x> <y> <terrain>
** requires: permission-key "gmterf" ** 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; unit *u = (unit *) data;
const struct plane *p = rplane(u->region); 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); int y = rel_to_abs(p, u->faction, getint(), 1);
const char *c = getstrtoken(); const char *c = getstrtoken();
variant token; variant token;
tnode *tokens = get_translations(u->faction->locale, UT_TERRAINS); void **tokens = get_translations(u->faction->locale, UT_TERRAINS);
region *r; region *r;
pnormalize(&x, &y, p); pnormalize(&x, &y, p);
r = findregion(x, y); r = findregion(x, y);
@ -225,7 +225,7 @@ static void gm_terraform(const tnode * tnext, void *data, struct order *ord)
return; 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; const terrain_type *terrain = (const terrain_type *)token.v;
terraform_region(r, terrain); 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> ** GM: TELEPORT <unit> <x> <y>
** requires: permission-key "gmtele" ** 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; unit *u = (unit *) data;
const struct plane *p = rplane(u->region); 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> ** GM: TELL PLANE <string>
** requires: permission-key "gmmsgr" ** 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; unit *gm = (unit *) data;
const struct plane *p = rplane(gm->region); 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 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; unit *gm = (unit *) data;
int n = getid(); int n = getid();
@ -333,7 +333,7 @@ gm_messagefaction(const tnode * tnext, void *data, struct order *ord)
** GM: TELL REGION <x> <y> <string> ** GM: TELL REGION <x> <y> <string>
** requires: permission-key "gmmsgr" ** 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; unit *u = (unit *) data;
const struct plane *p = rplane(u->region); 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> ** GM: KILL UNIT <id> <string>
** requires: permission-key "gmkill" ** 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; unit *u = (unit *) data;
const struct plane *p = rplane(u->region); 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> ** GM: KILL FACTION <id> <string>
** requires: permission-key "gmmsgr" ** 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; unit *u = (unit *) data;
int n = getid(); int n = getid();
@ -420,7 +420,7 @@ static void gm_killfaction(const tnode * tnext, void *data, struct order *ord)
** GM: TELL <unit> <string> ** GM: TELL <unit> <string>
** requires: permission-key "gmmsgr" ** 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; unit *u = (unit *) data;
const struct plane *p = rplane(u->region); 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> ** GM: GIVE <unit> <int> <itemtype>
** requires: permission-key "gmgive" ** 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 *u = (unit *) data;
unit *to = findunit(getid()); 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> ** GM: TAKE <unit> <int> <itemtype>
** requires: permission-key "gmtake" ** 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 *u = (unit *) data;
unit *to = findunit(getid()); 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> ** GM: SKILL <unit> <skill> <tage>
** requires: permission-key "gmskil" ** 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 *u = (unit *) data;
unit *to = findunit(getid()); 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 void * g_keys;
static tnode g_root; static void * g_root;
static tnode g_tell; static void * g_tell;
static tnode g_kill; static void * g_kill;
void register_gmcmd(void) void register_gmcmd(void)
{ {

View file

@ -22,7 +22,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifdef _MSC_VER #ifdef _MSC_VER
# define VC_EXTRALEAN # define VC_EXTRALEAN
# define WIN32_LEAN_AND_MEAN # define WIN32_LEAN_AND_MEAN
# include <Windows.h> # include <windows.h>
# undef MOUSE_MOVED # undef MOUSE_MOVED
# define STDIO_CP 1252 /* log.c, convert to console character set */ # define STDIO_CP 1252 /* log.c, convert to console character set */
# pragma warning (disable: 4201 4214 4514 4115 4711) # 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) # pragma warning(disable: 4100)
/* warning C4100: <name> : unreferenced formal parameter */ /* warning C4100: <name> : unreferenced formal parameter */
# pragma warning(disable: 4996) # 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 */ /* warning C4100: <name> was declared deprecated */
#ifndef _CRT_SECURE_NO_DEPRECATE #ifndef _CRT_SECURE_NO_DEPRECATE

View file

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

View file

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

View file

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

View file

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

View file

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