forked from github/server
make getstrtoken() return null at EOL, kill init_tokens.
init_order all the things! added a bunch of new assertions to cover for oversights. added some new tests for order parsing.
This commit is contained in:
parent
ee2363a4d9
commit
808f343e34
|
@ -502,8 +502,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
|
|||
const struct race *rc = u_race(u);
|
||||
const char *str;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
n = getuint();
|
||||
|
||||
if (u->number == 0) {
|
||||
|
@ -666,8 +665,7 @@ int give_control_cmd(unit * u, order * ord)
|
|||
const char *s;
|
||||
param_t p;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
u2 = getunit(r, u->faction);
|
||||
s = getstrtoken();
|
||||
p = findparam(s, u->faction->locale);
|
||||
|
@ -730,11 +728,10 @@ static void give_cmd(unit * u, order * ord)
|
|||
plane *pl;
|
||||
message *msg;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
u2 = getunit(r, u->faction);
|
||||
s = getstrtoken();
|
||||
n = atoip(s);
|
||||
n = s ? atoip(s) : 0;
|
||||
p = (n > 0) ? NOPARAM : findparam(s, u->faction->locale);
|
||||
|
||||
/* first, do all the ones that do not require HELP_GIVE or CONTACT */
|
||||
|
@ -857,7 +854,7 @@ static void give_cmd(unit * u, order * ord)
|
|||
return;
|
||||
}
|
||||
s = getstrtoken();
|
||||
if (*s == 0) { /* GIVE ALL items that you have */
|
||||
if (!s || *s == 0) { /* GIVE ALL items that you have */
|
||||
|
||||
/* do these checks once, not for each item we have: */
|
||||
if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) {
|
||||
|
@ -990,8 +987,7 @@ static int forget_cmd(unit * u, order * ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if ((sk = get_skill(s, u->faction->locale)) != NOSKILL) {
|
||||
|
@ -1800,9 +1796,10 @@ int make_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
const struct locale *lang = u->faction->locale;
|
||||
char ibuf[16];
|
||||
keyword_t kwd;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_MAKE);
|
||||
s = getstrtoken();
|
||||
|
||||
m = atoi((const char *)s);
|
||||
|
@ -2060,6 +2057,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
|
|||
attrib *a;
|
||||
const item_type *itype = NULL;
|
||||
const luxury_type *ltype = NULL;
|
||||
keyword_t kwd;
|
||||
|
||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
||||
cmistake(u, ord, 69, MSG_INCOME);
|
||||
return;
|
||||
|
@ -2071,8 +2070,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
|
|||
/* Im Augenblick kann man nur 1 Produkt kaufen. expandbuying ist aber
|
||||
* schon dafür ausgerüstet, mehrere Produkte zu kaufen. */
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_BUY);
|
||||
n = getuint();
|
||||
if (!n) {
|
||||
cmistake(u, ord, 26, MSG_COMMERCE);
|
||||
|
@ -2351,10 +2350,11 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
|||
{
|
||||
bool unlimited = true;
|
||||
const item_type *itype;
|
||||
const luxury_type *ltype = NULL;
|
||||
const luxury_type *ltype;
|
||||
int n;
|
||||
region *r = u->region;
|
||||
const char *s;
|
||||
keyword_t kwd;
|
||||
|
||||
if (u->ship && is_guarded(r, u, GUARD_CREWS)) {
|
||||
cmistake(u, ord, 69, MSG_INCOME);
|
||||
|
@ -2363,8 +2363,8 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
|||
/* sellorders sind KEIN array, weil für alle items DIE SELBE resource
|
||||
* (das geld der region) aufgebraucht wird. */
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_SELL);
|
||||
s = getstrtoken();
|
||||
|
||||
if (findparam(s, u->faction->locale) == P_ANY) {
|
||||
|
@ -2424,9 +2424,8 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
|||
return false;
|
||||
}
|
||||
s = getstrtoken();
|
||||
itype = finditemtype(s, u->faction->locale);
|
||||
if (itype != NULL)
|
||||
ltype = resource2luxury(itype->rtype);
|
||||
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
||||
ltype = itype ? resource2luxury(itype->rtype) : 0;
|
||||
if (ltype == NULL) {
|
||||
cmistake(u, ord, 126, MSG_COMMERCE);
|
||||
return false;
|
||||
|
@ -2764,8 +2763,7 @@ static void breed_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
|
||||
/* züchte [<anzahl>] <parameter> */
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
(void)init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
m = atoi((const char *)s);
|
||||
|
@ -2830,9 +2828,10 @@ static const char *rough_amount(int a, int m)
|
|||
static void research_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
region *r = u->region;
|
||||
keyword_t kwd;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_RESEARCH);
|
||||
/*
|
||||
const char *s = getstrtoken();
|
||||
|
||||
|
@ -2908,6 +2907,10 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
|
|||
region *r = u->region;
|
||||
faction *f = NULL;
|
||||
message * msg;
|
||||
keyword_t kwd;
|
||||
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_STEAL);
|
||||
|
||||
assert(skill_enabled(SK_PERCEPTION) && skill_enabled(SK_STEALTH));
|
||||
|
||||
|
@ -2916,8 +2919,6 @@ static void steal_cmd(unit * u, struct order *ord, request ** stealorders)
|
|||
ADDMSG(&u->faction->msgs, msg);
|
||||
return;
|
||||
}
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
id = read_unitid(u->faction, r);
|
||||
u2 = findunitr(r, id);
|
||||
|
||||
|
@ -3040,7 +3041,10 @@ void entertain_cmd(unit * u, struct order *ord)
|
|||
request *o;
|
||||
static int entertainbase = 0;
|
||||
static int entertainperlevel = 0;
|
||||
keyword_t kwd;
|
||||
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_ENTERTAIN);
|
||||
if (!entertainbase) {
|
||||
const char *str = get_param(global.parameters, "entertain.base");
|
||||
entertainbase = str ? atoi(str) : 0;
|
||||
|
@ -3073,8 +3077,6 @@ void entertain_cmd(unit * u, struct order *ord)
|
|||
u->wants = u->number * (entertainbase + effskill(u, SK_ENTERTAINMENT)
|
||||
* entertainperlevel);
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
max_e = getuint();
|
||||
if (max_e != 0) {
|
||||
u->wants = _min(u->wants, max_e);
|
||||
|
@ -3214,6 +3216,10 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
|
|||
int n;
|
||||
request *o;
|
||||
int max;
|
||||
keyword_t kwd;
|
||||
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_TAX);
|
||||
|
||||
if (!humanoidrace(u_race(u)) && !is_monsters(u->faction)) {
|
||||
cmistake(u, ord, 228, MSG_INCOME);
|
||||
|
@ -3236,8 +3242,6 @@ void tax_cmd(unit * u, struct order *ord, request ** taxorders)
|
|||
return;
|
||||
}
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
max = getuint();
|
||||
|
||||
if (max == 0)
|
||||
|
|
28
src/items.c
28
src/items.c
|
@ -32,28 +32,28 @@
|
|||
#define MAXGAIN 15
|
||||
static int
|
||||
use_studypotion(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
if (getkeyword(u->thisorder) == K_STUDY) {
|
||||
if (init_order(u->thisorder) == K_STUDY) {
|
||||
skill_t sk;
|
||||
skill *sv;
|
||||
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
sk = get_skill(getstrtoken(), u->faction->locale);
|
||||
sv = unit_skill(u, sk);
|
||||
|
||||
if (sv && sv->level > 2) {
|
||||
/* TODO: message */
|
||||
} else if (study_cost(u, sk) > 0) {
|
||||
}
|
||||
else if (study_cost(u, sk) > 0) {
|
||||
/* TODO: message */
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
attrib *a = a_find(u->attribs, &at_learning);
|
||||
teaching_info *teach;
|
||||
if (a == NULL) {
|
||||
a = a_add(&u->attribs, a_new(&at_learning));
|
||||
}
|
||||
teach = (teaching_info *) a->data.v;
|
||||
teach = (teaching_info *)a->data.v;
|
||||
if (amount > MAXGAIN)
|
||||
amount = MAXGAIN;
|
||||
teach->value += amount * 30;
|
||||
|
@ -73,7 +73,7 @@ use_studypotion(struct unit *u, const struct item_type *itype, int amount,
|
|||
#define SPEEDSAIL_EFFECT 1
|
||||
static int
|
||||
use_speedsail(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
curse *c;
|
||||
float effect;
|
||||
|
@ -103,7 +103,7 @@ use_speedsail(struct unit *u, const struct item_type *itype, int amount,
|
|||
* Antimagiezone, die zwei Runden bestehen bleibt */
|
||||
static int
|
||||
use_antimagiccrystal(unit * u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
region *r = u->region;
|
||||
const resource_type *rt_crystal = NULL;
|
||||
|
@ -139,7 +139,7 @@ use_antimagiccrystal(unit * u, const struct item_type *itype, int amount,
|
|||
} while (*ap && a->type == (*ap)->type);
|
||||
continue;
|
||||
}
|
||||
c = (curse *) a->data.v;
|
||||
c = (curse *)a->data.v;
|
||||
|
||||
/* Immunität prüfen */
|
||||
if (c_flags(c) & CURSE_IMMUNE) {
|
||||
|
@ -170,7 +170,7 @@ use_antimagiccrystal(unit * u, const struct item_type *itype, int amount,
|
|||
|
||||
static int
|
||||
use_instantartsculpture(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
building *b;
|
||||
|
||||
|
@ -192,7 +192,7 @@ use_instantartsculpture(struct unit *u, const struct item_type *itype,
|
|||
|
||||
static int
|
||||
use_instantartacademy(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
building *b;
|
||||
|
||||
|
@ -217,7 +217,7 @@ use_instantartacademy(struct unit *u, const struct item_type *itype,
|
|||
|
||||
static int
|
||||
use_bagpipeoffear(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
int money;
|
||||
|
||||
|
@ -244,7 +244,7 @@ use_bagpipeoffear(struct unit *u, const struct item_type *itype,
|
|||
|
||||
static int
|
||||
use_aurapotion50(struct unit *u, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
if (!is_mage(u)) {
|
||||
cmistake(u, ord, 214, MSG_MAGIC);
|
||||
|
|
|
@ -158,8 +158,7 @@ static void perform_kick(void)
|
|||
|
||||
if (al && alliance_get_leader(al) == ta->u->faction) {
|
||||
faction *f;
|
||||
init_tokens(ta->ord);
|
||||
skip_token();
|
||||
init_order(ta->ord);
|
||||
skip_token();
|
||||
f = getfaction();
|
||||
if (f && f_get_alliance(f) == al) {
|
||||
|
@ -180,8 +179,7 @@ static void perform_new(void)
|
|||
int id;
|
||||
faction *f = ta->u->faction;
|
||||
|
||||
init_tokens(ta->ord);
|
||||
skip_token();
|
||||
init_order(ta->ord);
|
||||
skip_token();
|
||||
id = getid();
|
||||
|
||||
|
@ -216,8 +214,7 @@ static void perform_transfer(void)
|
|||
|
||||
if (al && alliance_get_leader(al) == ta->u->faction) {
|
||||
faction *f;
|
||||
init_tokens(ta->ord);
|
||||
skip_token();
|
||||
init_order(ta->ord);
|
||||
skip_token();
|
||||
f = getfaction();
|
||||
if (f && f_get_alliance(f) == al) {
|
||||
|
@ -237,8 +234,7 @@ static void perform_join(void)
|
|||
faction *fj = ta->u->faction;
|
||||
int aid;
|
||||
|
||||
init_tokens(ta->ord);
|
||||
skip_token();
|
||||
init_order(ta->ord);
|
||||
skip_token();
|
||||
aid = getid();
|
||||
if (aid) {
|
||||
|
@ -250,8 +246,7 @@ static void perform_join(void)
|
|||
faction *fi = ti->u->faction;
|
||||
if (fi && f_get_alliance(fi) == al) {
|
||||
int fid;
|
||||
init_tokens(ti->ord);
|
||||
skip_token();
|
||||
init_order(ti->ord);
|
||||
skip_token();
|
||||
fid = getid();
|
||||
if (fid == fj->no) {
|
||||
|
|
|
@ -3967,8 +3967,7 @@ static bool start_battle(region * r, battle ** bp)
|
|||
|
||||
/* Ende Fehlerbehandlung Angreifer */
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
/* attackierte Einheit ermitteln */
|
||||
u2 = getunit(r, u->faction);
|
||||
|
||||
|
|
|
@ -146,8 +146,7 @@ int destroy_cmd(unit * u, struct order *ord)
|
|||
if (u->number < 1)
|
||||
return 0;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (findparam(s, u->faction->locale) == P_ROAD) {
|
||||
|
|
|
@ -92,8 +92,7 @@ static int do_command_i(const void *keys, struct unit *u, struct order *ord)
|
|||
|
||||
void do_command(const void *keys, struct unit *u, struct order *ord)
|
||||
{
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
if (do_command_i(keys, u, ord) != E_TOK_SUCCESS) {
|
||||
char cmd[ORDERSIZE];
|
||||
get_command(ord, cmd, sizeof(cmd));
|
||||
|
|
|
@ -637,6 +637,7 @@ unsigned int atoip(const char *s)
|
|||
{
|
||||
int n;
|
||||
|
||||
assert(s);
|
||||
n = atoi(s);
|
||||
|
||||
if (n < 0)
|
||||
|
@ -1137,12 +1138,13 @@ const char *igetstrtoken(const char *initstr)
|
|||
|
||||
unsigned int getuint(void)
|
||||
{
|
||||
return atoip((const char *)getstrtoken());
|
||||
const char *s = getstrtoken();
|
||||
return s ? atoip(s) : 0;
|
||||
}
|
||||
|
||||
int getint(void)
|
||||
{
|
||||
return atoi((const char *)getstrtoken());
|
||||
return atoi(getstrtoken());
|
||||
}
|
||||
|
||||
const struct race *findrace(const char *s, const struct locale *lang)
|
||||
|
@ -1172,7 +1174,7 @@ param_t findparam(const char *s, const struct locale * lang)
|
|||
{
|
||||
param_t result = NOPARAM;
|
||||
char buffer[64];
|
||||
char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s);
|
||||
char * str = s ? transliterate(buffer, sizeof(buffer) - sizeof(int), s) : 0;
|
||||
|
||||
if (str && *str) {
|
||||
int i;
|
||||
|
@ -1204,6 +1206,7 @@ param_t findparam_ex(const char *s, const struct locale * lang)
|
|||
|
||||
bool isparam(const char *s, const struct locale * lang, param_t param)
|
||||
{
|
||||
assert(s);
|
||||
if (s[0] > '@') {
|
||||
param_t p = (param == P_GEBAEUDE) ? findparam_ex(s, lang) : findparam(s, lang);
|
||||
return p == param;
|
||||
|
@ -1855,8 +1858,8 @@ typedef struct param {
|
|||
|
||||
int getid(void)
|
||||
{
|
||||
const char *str = (const char *)getstrtoken();
|
||||
int i = atoi36(str);
|
||||
const char *str = getstrtoken();
|
||||
int i = str ? atoi36(str) : 0;
|
||||
if (i < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -2686,7 +2689,7 @@ int movewhere(const unit * u, const char *token, region * r, region ** resultp)
|
|||
region *r2;
|
||||
direction_t d;
|
||||
|
||||
if (*token == '\0') {
|
||||
if (!token || *token == '\0') {
|
||||
*resultp = NULL;
|
||||
return E_MOVE_OK;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -72,9 +72,10 @@ static int res_changeaura(unit * u, const resource_type * rtype, int delta)
|
|||
static int res_changeperson(unit * u, const resource_type * rtype, int delta)
|
||||
{
|
||||
assert(rtype != NULL || !"not implemented");
|
||||
if (u->number + delta >=0) {
|
||||
if (u->number + delta >= 0) {
|
||||
scale_number(u, u->number + delta);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
scale_number(u, 0);
|
||||
}
|
||||
return u->number;
|
||||
|
@ -110,14 +111,16 @@ static int res_changeitem(unit * u, const resource_type * rtype, int delta)
|
|||
--reduce;
|
||||
scale_number(u, u->number + reduce);
|
||||
num = u->number * GOLEM_STONE;
|
||||
} else if (rtype == get_resourcetype(R_IRON)
|
||||
}
|
||||
else if (rtype == get_resourcetype(R_IRON)
|
||||
&& u_race(u) == get_race(RC_IRONGOLEM) && delta <= 0) {
|
||||
int reduce = delta / GOLEM_IRON;
|
||||
if (delta % GOLEM_IRON != 0)
|
||||
--reduce;
|
||||
scale_number(u, u->number + reduce);
|
||||
num = u->number * GOLEM_IRON;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
const item_type *itype = resource2item(rtype);
|
||||
item *i;
|
||||
assert(itype != NULL);
|
||||
|
@ -155,7 +158,7 @@ static void rt_register(resource_type * rtype)
|
|||
const char * name = rtype->_name[0];
|
||||
size_t len = strlen(name);
|
||||
|
||||
assert(len<sizeof(buffer) - sizeof(rtype));
|
||||
assert(len < sizeof(buffer) - sizeof(rtype));
|
||||
len = cb_new_kv(name, len, &rtype, sizeof(rtype), buffer);
|
||||
cb_insert(&cb_resources, buffer, len);
|
||||
++num_resources;
|
||||
|
@ -166,7 +169,7 @@ resource_type *rt_get_or_create(const char *name) {
|
|||
if (!rtype) {
|
||||
rtype = (resource_type *)calloc(sizeof(resource_type), 1);
|
||||
rtype->_name[0] = _strdup(name);
|
||||
rtype->_name[1] = (char *)malloc(strlen(name)+3);
|
||||
rtype->_name[1] = (char *)malloc(strlen(name) + 3);
|
||||
sprintf(rtype->_name[1], "%s_p", name);
|
||||
rt_register(rtype);
|
||||
}
|
||||
|
@ -179,22 +182,22 @@ void it_register(item_type * itype)
|
|||
const char * name = itype->rtype->_name[0];
|
||||
size_t len = strlen(name);
|
||||
|
||||
assert(len<sizeof(buffer)-sizeof(itype));
|
||||
assert(len < sizeof(buffer) - sizeof(itype));
|
||||
len = cb_new_kv(name, len, &itype, sizeof(itype), buffer);
|
||||
}
|
||||
|
||||
static const char *it_aliases[][2] = {
|
||||
{"Runenschwert", "runesword"},
|
||||
{"p12", "truthpotion"},
|
||||
{"p1", "goliathwater"},
|
||||
{"p4", "ointment"},
|
||||
{"p5", "peasantblood"},
|
||||
{"p8", "nestwarmth"},
|
||||
{"diamond", "adamantium"},
|
||||
{"diamondaxe", "adamantiumaxe"},
|
||||
{"diamondplate", "adamantiumplate"},
|
||||
{"aoh", "ao_healing"},
|
||||
{NULL, NULL},
|
||||
{ "Runenschwert", "runesword" },
|
||||
{ "p12", "truthpotion" },
|
||||
{ "p1", "goliathwater" },
|
||||
{ "p4", "ointment" },
|
||||
{ "p5", "peasantblood" },
|
||||
{ "p8", "nestwarmth" },
|
||||
{ "diamond", "adamantium" },
|
||||
{ "diamondaxe", "adamantiumaxe" },
|
||||
{ "diamondplate", "adamantiumplate" },
|
||||
{ "aoh", "ao_healing" },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
static const char *it_alias(const char *zname)
|
||||
|
@ -368,7 +371,7 @@ resource_type *rt_find(const char *name)
|
|||
const void * matches;
|
||||
resource_type *result = 0;
|
||||
|
||||
if (cb_find_prefix(&cb_resources, name, strlen(name)+1, &matches, 1, 0)) {
|
||||
if (cb_find_prefix(&cb_resources, name, strlen(name) + 1, &matches, 1, 0)) {
|
||||
cb_get_kv(matches, &result, sizeof(result));
|
||||
}
|
||||
return result;
|
||||
|
@ -391,7 +394,7 @@ item *const* i_findc(item *const* iter, const item_type * it)
|
|||
|
||||
int i_get(const item * i, const item_type * it)
|
||||
{
|
||||
i = *i_find((item **) & i, it);
|
||||
i = *i_find((item **)& i, it);
|
||||
if (i)
|
||||
return i->number;
|
||||
return 0;
|
||||
|
@ -410,7 +413,8 @@ item *i_add(item ** pi, item * i)
|
|||
(*pi)->number += i->number;
|
||||
assert((*pi)->number >= 0);
|
||||
i_free(i);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i->next = *pi;
|
||||
*pi = i;
|
||||
}
|
||||
|
@ -432,7 +436,8 @@ void i_merge(item ** pi, item ** si)
|
|||
(*pi)->number += i->number;
|
||||
assert((*pi)->number >= 0);
|
||||
i_free(i_remove(&i, i));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
itmp = i->next;
|
||||
i->next = *pi;
|
||||
*pi = i;
|
||||
|
@ -458,7 +463,8 @@ item *i_change(item ** pi, const item_type * itype, int delta)
|
|||
i = i_new(itype, delta);
|
||||
i->next = *pi;
|
||||
*pi = i;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
item *i = *pi;
|
||||
i->number += delta;
|
||||
if (i->number < 0) {
|
||||
|
@ -496,7 +502,8 @@ void i_free(item * i)
|
|||
{
|
||||
if (icache_size >= ICACHE_MAX) {
|
||||
free(i);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i->next = icache;
|
||||
icache = i;
|
||||
++icache_size;
|
||||
|
@ -521,7 +528,8 @@ item *i_new(const item_type * itype, int size)
|
|||
i = icache;
|
||||
icache = i->next;
|
||||
--icache_size;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i = malloc(sizeof(item));
|
||||
}
|
||||
assert(itype);
|
||||
|
@ -536,7 +544,7 @@ item *i_new(const item_type * itype, int size)
|
|||
|
||||
static int
|
||||
give_horses(unit * s, unit * d, const item_type * itype, int n,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
if (d == NULL) {
|
||||
int use = use_pooled(s, item2resource(itype), GET_SLACK, n);
|
||||
|
@ -552,7 +560,7 @@ give_horses(unit * s, unit * d, const item_type * itype, int n,
|
|||
|
||||
static int
|
||||
give_money(unit * s, unit * d, const item_type * itype, int n,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
if (d == NULL) {
|
||||
int use = use_pooled(s, item2resource(itype), GET_SLACK, n);
|
||||
|
@ -594,7 +602,7 @@ static const char *resourcenames[MAX_RESOURCES] = {
|
|||
const resource_type *get_resourcetype(resource_t type) {
|
||||
static int update;
|
||||
static struct resource_type * rtypes[MAX_RESOURCES];
|
||||
if (update!=num_resources) {
|
||||
if (update != num_resources) {
|
||||
memset(rtypes, 0, sizeof(rtypes));
|
||||
update = num_resources;
|
||||
}
|
||||
|
@ -620,7 +628,8 @@ int set_item(unit * u, const item_type *itype, int value)
|
|||
i = *i_find(&u->items, itype);
|
||||
if (!i) {
|
||||
i = i_add(&u->items, i_new(itype, value));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i->number = value;
|
||||
assert(i->number >= 0);
|
||||
}
|
||||
|
@ -629,7 +638,7 @@ int set_item(unit * u, const item_type *itype, int value)
|
|||
|
||||
static int
|
||||
use_birthdayamulet(unit * u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
direction_t d;
|
||||
message *msg = msg_message("meow", "");
|
||||
|
@ -660,7 +669,7 @@ use_birthdayamulet(unit * u, const struct item_type *itype, int amount,
|
|||
* Runde um -1 - 4 Punkte. */
|
||||
static int
|
||||
use_tacticcrystal(unit * u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i != amount; ++i) {
|
||||
|
@ -693,7 +702,7 @@ typedef struct t_item {
|
|||
int gewicht;
|
||||
int preis;
|
||||
unsigned int flags;
|
||||
void (*benutze_funktion) (struct region *, struct unit *, int amount,
|
||||
void(*benutze_funktion) (struct region *, struct unit *, int amount,
|
||||
struct order *);
|
||||
} t_item;
|
||||
|
||||
|
@ -730,29 +739,29 @@ static int heal(unit * user, int effect)
|
|||
}
|
||||
|
||||
void
|
||||
register_item_give(int (*foo) (struct unit *, struct unit *,
|
||||
const struct item_type *, int, struct order *), const char *name)
|
||||
register_item_give(int(*foo) (struct unit *, struct unit *,
|
||||
const struct item_type *, int, struct order *), const char *name)
|
||||
{
|
||||
register_function((pf_generic) foo, name);
|
||||
register_function((pf_generic)foo, name);
|
||||
}
|
||||
|
||||
void
|
||||
register_item_use(int (*foo) (struct unit *, const struct item_type *, int,
|
||||
struct order *), const char *name)
|
||||
register_item_use(int(*foo) (struct unit *, const struct item_type *, int,
|
||||
struct order *), const char *name)
|
||||
{
|
||||
register_function((pf_generic) foo, name);
|
||||
register_function((pf_generic)foo, name);
|
||||
}
|
||||
|
||||
void
|
||||
register_item_useonother(int (*foo) (struct unit *, int,
|
||||
const struct item_type *, int, struct order *), const char *name)
|
||||
register_item_useonother(int(*foo) (struct unit *, int,
|
||||
const struct item_type *, int, struct order *), const char *name)
|
||||
{
|
||||
register_function((pf_generic) foo, name);
|
||||
register_function((pf_generic)foo, name);
|
||||
}
|
||||
|
||||
static int
|
||||
use_healingpotion(struct unit *user, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
int effect = amount * 400;
|
||||
unit *u = user->region->units;
|
||||
|
@ -774,11 +783,12 @@ use_healingpotion(struct unit *user, const struct item_type *itype, int amount,
|
|||
|
||||
static int
|
||||
use_warmthpotion(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
if (u->faction->race == get_race(RC_INSECT)) {
|
||||
fset(u, UFL_WARMTH);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
/* nur fuer insekten: */
|
||||
cmistake(u, ord, 163, MSG_EVENT);
|
||||
return ECUSTOM;
|
||||
|
@ -794,7 +804,7 @@ use_warmthpotion(struct unit *u, const struct item_type *itype, int amount,
|
|||
|
||||
static int
|
||||
use_foolpotion(struct unit *u, int targetno, const struct item_type *itype,
|
||||
int amount, struct order *ord)
|
||||
int amount, struct order *ord)
|
||||
{
|
||||
unit *target = findunit(targetno);
|
||||
if (target == NULL || u->region != target->region) {
|
||||
|
@ -816,11 +826,12 @@ use_foolpotion(struct unit *u, int targetno, const struct item_type *itype,
|
|||
|
||||
static int
|
||||
use_bloodpotion(struct unit *u, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
if (u_race(u) == get_race(RC_DAEMON)) {
|
||||
change_effect(u, itype->rtype->ptype, 100 * amount);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
const race *irace = u_irace(u);
|
||||
if (irace == u_race(u)) {
|
||||
static const race *rcfailure;
|
||||
|
@ -854,7 +865,7 @@ use_bloodpotion(struct unit *u, const struct item_type *itype, int amount,
|
|||
#include <attributes/fleechance.h>
|
||||
static int
|
||||
use_mistletoe(struct unit *user, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
int mtoes =
|
||||
get_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
|
||||
|
@ -876,7 +887,7 @@ use_mistletoe(struct unit *user, const struct item_type *itype, int amount,
|
|||
|
||||
static int
|
||||
use_magicboost(struct unit *user, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
int mtoes =
|
||||
get_pooled(user, itype->rtype, GET_SLACK | GET_RESERVE | GET_POOLED_SLACK,
|
||||
|
@ -905,7 +916,7 @@ use_magicboost(struct unit *user, const struct item_type *itype, int amount,
|
|||
|
||||
static int
|
||||
use_snowball(struct unit *user, const struct item_type *itype, int amount,
|
||||
struct order *ord)
|
||||
struct order *ord)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -985,7 +996,8 @@ int set_money(unit * u, int v)
|
|||
if (v) {
|
||||
(*ip)->number = v;
|
||||
assert((*ip)->number >= 0);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i_remove(ip, *ip);
|
||||
}
|
||||
}
|
||||
|
@ -1009,7 +1021,8 @@ int change_money(unit * u, int v)
|
|||
i->number += v;
|
||||
assert(i->number >= 0);
|
||||
return i->number;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
i_free(i_remove(ip, *ip));
|
||||
}
|
||||
}
|
||||
|
@ -1020,17 +1033,17 @@ static int add_resourcename_cb(const void * match, const void * key, size_t keyl
|
|||
{
|
||||
struct locale * lang = (struct locale *)data;
|
||||
int i = locale_index(lang);
|
||||
critbit_tree * cb = rnames+i;
|
||||
critbit_tree * cb = rnames + i;
|
||||
resource_type *rtype;
|
||||
|
||||
cb_get_kv(match, &rtype, sizeof(rtype));
|
||||
for (i = 0; i!=2;++i) {
|
||||
for (i = 0; i != 2; ++i) {
|
||||
char buffer[128];
|
||||
const char * name = locale_string(lang, rtype->_name[i]);
|
||||
|
||||
if (name && transliterate(buffer, sizeof(buffer), name)) {
|
||||
size_t len = strlen(buffer);
|
||||
assert(len+sizeof(rtype)<sizeof(buffer));
|
||||
assert(len + sizeof(rtype) < sizeof(buffer));
|
||||
len = cb_new_kv(buffer, len, &rtype, sizeof(rtype), buffer);
|
||||
cb_insert(cb, buffer, len);
|
||||
}
|
||||
|
@ -1041,7 +1054,7 @@ static int add_resourcename_cb(const void * match, const void * key, size_t keyl
|
|||
const resource_type *findresourcetype(const char *name, const struct locale *lang)
|
||||
{
|
||||
int i = locale_index(lang);
|
||||
critbit_tree * cb = rnames+i;
|
||||
critbit_tree * cb = rnames + i;
|
||||
char buffer[128];
|
||||
|
||||
if (transliterate(buffer, sizeof(buffer), name)) {
|
||||
|
@ -1055,7 +1068,8 @@ const resource_type *findresourcetype(const char *name, const struct locale *lan
|
|||
cb_get_kv(match, (void*)&rtype, sizeof(rtype));
|
||||
return rtype;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
log_debug("findresourcetype: transliterate failed for '%s'\n", name);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1092,9 +1106,10 @@ static int add_itemname_cb(const void * match, const void * key, size_t keylen,
|
|||
const item_type *finditemtype(const char *name, const struct locale *lang)
|
||||
{
|
||||
int i = locale_index(lang);
|
||||
critbit_tree * cb = inames+i;
|
||||
critbit_tree * cb = inames + i;
|
||||
char buffer[128];
|
||||
|
||||
assert(name);
|
||||
if (transliterate(buffer, sizeof(buffer), name)) {
|
||||
const void * match;
|
||||
if (!cb->root) {
|
||||
|
@ -1106,7 +1121,8 @@ const item_type *finditemtype(const char *name, const struct locale *lang)
|
|||
cb_get_kv(match, (void*)&itype, sizeof(itype));
|
||||
return itype;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
log_debug("finditemtype: transliterate failed for '%s'\n", name);
|
||||
}
|
||||
return 0;
|
||||
|
@ -1175,7 +1191,7 @@ void test_clear_resources(void)
|
|||
cb_clear(&cb_resources);
|
||||
++num_resources;
|
||||
|
||||
for (i=0; i!=MAXLOCALES; ++i) {
|
||||
for (i = 0; i != MAXLOCALES; ++i) {
|
||||
cb_clear(inames + i);
|
||||
cb_clear(rnames + i);
|
||||
}
|
||||
|
@ -1188,15 +1204,15 @@ void register_resources(void)
|
|||
if (registered) return;
|
||||
registered = true;
|
||||
|
||||
register_function((pf_generic) mod_elves_only, "mod_elves_only");
|
||||
register_function((pf_generic) mod_dwarves_only, "mod_dwarves_only");
|
||||
register_function((pf_generic) res_changeitem, "changeitem");
|
||||
register_function((pf_generic) res_changeperson, "changeperson");
|
||||
register_function((pf_generic) res_changepeasants, "changepeasants");
|
||||
register_function((pf_generic) res_changepermaura, "changepermaura");
|
||||
register_function((pf_generic) res_changehp, "changehp");
|
||||
register_function((pf_generic) res_changeaura, "changeaura");
|
||||
register_function((pf_generic) default_spoil, "defaultdrops");
|
||||
register_function((pf_generic)mod_elves_only, "mod_elves_only");
|
||||
register_function((pf_generic)mod_dwarves_only, "mod_dwarves_only");
|
||||
register_function((pf_generic)res_changeitem, "changeitem");
|
||||
register_function((pf_generic)res_changeperson, "changeperson");
|
||||
register_function((pf_generic)res_changepeasants, "changepeasants");
|
||||
register_function((pf_generic)res_changepermaura, "changepermaura");
|
||||
register_function((pf_generic)res_changehp, "changehp");
|
||||
register_function((pf_generic)res_changeaura, "changeaura");
|
||||
register_function((pf_generic)default_spoil, "defaultdrops");
|
||||
|
||||
register_item_use(use_potion, "usepotion");
|
||||
register_item_use(use_potion_delayed, "usepotion_delayed");
|
||||
|
|
|
@ -2535,8 +2535,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
}
|
||||
level = eff_skill(u, SK_MAGIC, r);
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
param = findparam(s, u->faction->locale);
|
||||
/* für Syntax ' STUFE x REGION y z ' */
|
||||
|
@ -2712,7 +2711,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
|||
int p = 0, size = 2;
|
||||
for (;;) {
|
||||
s = getstrtoken();
|
||||
if (*s == 0)
|
||||
if (!s || *s == 0)
|
||||
break;
|
||||
if (p + 1 >= size) {
|
||||
size *= 2;
|
||||
|
|
|
@ -1060,8 +1060,7 @@ static void cycle_route(order * ord, unit * u, int gereist)
|
|||
return;
|
||||
tail[0] = '\0';
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
neworder[0] = 0;
|
||||
for (cm = 0;; ++cm) {
|
||||
|
@ -1142,8 +1141,7 @@ static bool transport(unit * ut, unit * u)
|
|||
|
||||
for (ord = ut->orders; ord; ord = ord->next) {
|
||||
if (getkeyword(ord) == K_TRANSPORT) {
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
if (getunit(ut->region, ut->faction) == u) {
|
||||
return true;
|
||||
}
|
||||
|
@ -1176,8 +1174,7 @@ static void init_transportation(void)
|
|||
&& !fval(u, UFL_NOTMOVING) && !LongHunger(u)) {
|
||||
unit *ut;
|
||||
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
init_order(u->thisorder);
|
||||
ut = getunit(r, u->faction);
|
||||
if (ut == NULL) {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder,
|
||||
|
@ -1207,8 +1204,7 @@ static void init_transportation(void)
|
|||
|
||||
for (ord = u->orders; ord; ord = ord->next) {
|
||||
if (getkeyword(ord) == K_TRANSPORT) {
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
for (;;) {
|
||||
unit *ut = getunit(r, u->faction);
|
||||
|
||||
|
@ -1216,8 +1212,7 @@ static void init_transportation(void)
|
|||
break;
|
||||
if (getkeyword(ut->thisorder) == K_DRIVE && can_move(ut)
|
||||
&& !fval(ut, UFL_NOTMOVING) && !LongHunger(ut)) {
|
||||
init_tokens(ut->thisorder);
|
||||
skip_token();
|
||||
init_order(ut->thisorder);
|
||||
if (getunit(r, ut->faction) == u) {
|
||||
w += weight(ut);
|
||||
}
|
||||
|
@ -2088,8 +2083,7 @@ static const region_list *travel_i(unit * u, const region_list * route_begin,
|
|||
if (getkeyword(ord) != K_TRANSPORT)
|
||||
continue;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
ut = getunit(r, u->faction);
|
||||
if (ut != NULL) {
|
||||
if (getkeyword(ut->thisorder) == K_DRIVE) {
|
||||
|
@ -2104,8 +2098,7 @@ static const region_list *travel_i(unit * u, const region_list * route_begin,
|
|||
bool found = false;
|
||||
|
||||
if (!fval(ut, UFL_NOTMOVING) && !LongHunger(ut)) {
|
||||
init_tokens(ut->thisorder);
|
||||
skip_token();
|
||||
init_order(ut->thisorder);
|
||||
if (getunit(u->region, ut->faction) == u) {
|
||||
const region_list *route_to =
|
||||
travel_route(ut, route_begin, route_end, ord,
|
||||
|
@ -2301,8 +2294,7 @@ static void piracy_cmd(unit * u, struct order *ord)
|
|||
/* Feststellen, ob schon ein anderer alliierter Pirat ein
|
||||
* Ziel gefunden hat. */
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
if (s != NULL && *s) {
|
||||
il = intlist_init();
|
||||
|
@ -2389,8 +2381,7 @@ static void piracy_cmd(unit * u, struct order *ord)
|
|||
LOC(u->faction->locale, directions[target_dir])));
|
||||
|
||||
/* Bewegung ausführen */
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
init_order(u->thisorder);
|
||||
move(u, true);
|
||||
}
|
||||
|
||||
|
@ -2543,8 +2534,7 @@ static void move_hunters(void)
|
|||
if (getkeyword(ord) == K_FOLLOW) {
|
||||
param_t p;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
p = getparam(u->faction->locale);
|
||||
if (p != P_SHIP) {
|
||||
if (p != P_UNIT) {
|
||||
|
@ -2666,15 +2656,13 @@ void movement(void)
|
|||
else {
|
||||
if (ships) {
|
||||
if (u->ship && ship_owner(u->ship) == u) {
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
init_order(u->thisorder);
|
||||
move(u, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (!u->ship || ship_owner(u->ship) != u) {
|
||||
init_tokens(u->thisorder);
|
||||
skip_token();
|
||||
init_order(u->thisorder);
|
||||
move(u, false);
|
||||
}
|
||||
}
|
||||
|
@ -2729,10 +2717,10 @@ void follow_unit(unit * u)
|
|||
const struct locale *lang = u->faction->locale;
|
||||
|
||||
if (getkeyword(ord) == K_FOLLOW) {
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
int id;
|
||||
param_t p = getparam(lang);
|
||||
param_t p;
|
||||
init_order(ord);
|
||||
p = getparam(lang);
|
||||
if (p == P_UNIT) {
|
||||
id = read_unitid(u->faction, r);
|
||||
if (a != NULL) {
|
||||
|
@ -2753,7 +2741,7 @@ void follow_unit(unit * u)
|
|||
a = NULL;
|
||||
}
|
||||
}
|
||||
if (p == P_SHIP) {
|
||||
else if (p == P_SHIP) {
|
||||
id = getshipid();
|
||||
if (id <= 0) {
|
||||
/* cmistake(u, ord, 20, MSG_MOVE); */
|
||||
|
|
|
@ -357,17 +357,19 @@ order *parse_order(const char *s, const struct locale * lang)
|
|||
keyword_t kwd;
|
||||
const char *sptr;
|
||||
int persistent = 0;
|
||||
const char * p;
|
||||
|
||||
while (*s == '@') {
|
||||
persistent = 1;
|
||||
++s;
|
||||
}
|
||||
sptr = s;
|
||||
kwd = get_keyword(parse_token(&sptr), lang);
|
||||
p = *sptr ? parse_token(&sptr) : 0;
|
||||
kwd = p ? get_keyword(p, lang) : NOKEYWORD;
|
||||
if (kwd == K_MAKE) {
|
||||
const char *s, *sp = sptr;
|
||||
s = parse_token(&sp);
|
||||
if (isparam(s, lang, P_TEMP)) {
|
||||
if (s && isparam(s, lang, P_TEMP)) {
|
||||
kwd = K_MAKETEMP;
|
||||
sptr = sp;
|
||||
}
|
||||
|
@ -564,15 +566,11 @@ static char *getcommand(const order * ord)
|
|||
return _strdup(get_command(ord, cmd, sizeof(cmd)));
|
||||
}
|
||||
|
||||
void init_tokens(const struct order *ord)
|
||||
{
|
||||
char *cmd = getcommand(ord);
|
||||
init_tokens_str(cmd, cmd);
|
||||
}
|
||||
|
||||
keyword_t init_order(const struct order *ord)
|
||||
{
|
||||
char *cmd = _strdup(ord->data->_str);
|
||||
char *cmd = 0;
|
||||
|
||||
if (ord->data->_str) cmd = _strdup(ord->data->_str);
|
||||
init_tokens_str(cmd, cmd);
|
||||
return ord->data->_keyword;
|
||||
}
|
||||
|
|
|
@ -59,7 +59,6 @@ extern "C" {
|
|||
bool is_long(const order * ord);
|
||||
|
||||
char *write_order(const order * ord, char *buffer, size_t size);
|
||||
void init_tokens(const struct order *ord); /* initialize token parsing */
|
||||
keyword_t init_order(const struct order *ord);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -17,9 +17,9 @@ static void test_create_order(CuTest *tc) {
|
|||
ord = create_order(K_MOVE, lang, "NORTH");
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
||||
init_tokens(ord);
|
||||
CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));
|
||||
CuAssertStrEquals(tc, "MOVE", getstrtoken());
|
||||
|
||||
CuAssertIntEquals(tc, K_MOVE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
@ -33,9 +33,9 @@ static void test_parse_order(CuTest *tc) {
|
|||
ord = parse_order("MOVE NORTH", lang);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MOVE, getkeyword(ord));
|
||||
init_tokens(ord);
|
||||
CuAssertStrEquals(tc, "MOVE NORTH", get_command(ord, cmd, sizeof(cmd)));
|
||||
CuAssertStrEquals(tc, "MOVE", getstrtoken());
|
||||
|
||||
CuAssertIntEquals(tc, K_MOVE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "NORTH", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
@ -51,9 +51,9 @@ static void test_parse_make(CuTest *tc) {
|
|||
ord = parse_order("M hurrdurr", lang);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MAKE, getkeyword(ord));
|
||||
init_tokens(ord);
|
||||
CuAssertStrEquals(tc, "MAKE hurrdurr", get_command(ord, cmd, sizeof(cmd)));
|
||||
CuAssertStrEquals(tc, "MAKE", getstrtoken());
|
||||
|
||||
CuAssertIntEquals(tc, K_MAKE, init_order(ord));
|
||||
CuAssertStrEquals(tc, "hurrdurr", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
@ -71,9 +71,9 @@ static void test_parse_make_temp(CuTest *tc) {
|
|||
ord = parse_order("M T herp", lang);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
||||
init_tokens(ord);
|
||||
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
|
||||
CuAssertStrEquals(tc, "MAKETEMP", getstrtoken());
|
||||
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
||||
CuAssertStrEquals(tc, "herp", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
@ -90,25 +90,13 @@ static void test_parse_maketemp(CuTest *tc) {
|
|||
|
||||
ord = parse_order("MAKET herp", lang);
|
||||
CuAssertPtrNotNull(tc, ord);
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
||||
init_tokens(ord);
|
||||
CuAssertStrEquals(tc, "MAKETEMP herp", get_command(ord, cmd, sizeof(cmd)));
|
||||
CuAssertStrEquals(tc, "MAKETEMP", getstrtoken());
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, getkeyword(ord));
|
||||
CuAssertIntEquals(tc, K_MAKETEMP, init_order(ord));
|
||||
CuAssertStrEquals(tc, "herp", getstrtoken());
|
||||
free_order(ord);
|
||||
}
|
||||
|
||||
static void test_init_tokens(CuTest *tc) {
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
|
||||
ord = create_order(K_MAKETEMP, lang, "hurr durr");
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
CuAssertStrEquals(tc, "hurr", getstrtoken());
|
||||
CuAssertStrEquals(tc, "durr", getstrtoken());
|
||||
}
|
||||
|
||||
static void test_init_order(CuTest *tc) {
|
||||
order *ord;
|
||||
struct locale * lang = get_or_create_locale("en");
|
||||
|
@ -119,6 +107,26 @@ static void test_init_order(CuTest *tc) {
|
|||
CuAssertStrEquals(tc, "durr", getstrtoken());
|
||||
}
|
||||
|
||||
static void test_getstrtoken(CuTest *tc) {
|
||||
char *cmd = _strdup("hurr \"durr\" \"\" \'\'");
|
||||
init_tokens_str(cmd, cmd);
|
||||
CuAssertStrEquals(tc, "hurr", getstrtoken());
|
||||
CuAssertStrEquals(tc, "durr", getstrtoken());
|
||||
CuAssertStrEquals(tc, "", getstrtoken());
|
||||
CuAssertStrEquals(tc, "", getstrtoken());
|
||||
CuAssertStrEquals(tc, 0, getstrtoken());
|
||||
init_tokens_str(0, 0);
|
||||
CuAssertStrEquals(tc, 0, getstrtoken());
|
||||
}
|
||||
|
||||
static void test_skip_token(CuTest *tc) {
|
||||
char *cmd = _strdup("hurr \"durr\"");
|
||||
init_tokens_str(cmd, cmd);
|
||||
skip_token();
|
||||
CuAssertStrEquals(tc, "durr", getstrtoken());
|
||||
CuAssertStrEquals(tc, 0, getstrtoken());
|
||||
}
|
||||
|
||||
CuSuite *get_order_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
|
@ -127,7 +135,8 @@ CuSuite *get_order_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_parse_make);
|
||||
SUITE_ADD_TEST(suite, test_parse_make_temp);
|
||||
SUITE_ADD_TEST(suite, test_parse_maketemp);
|
||||
SUITE_ADD_TEST(suite, test_init_tokens);
|
||||
SUITE_ADD_TEST(suite, test_init_order);
|
||||
SUITE_ADD_TEST(suite, test_skip_token);
|
||||
SUITE_ADD_TEST(suite, test_getstrtoken);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ const char * keyword(keyword_t kwd)
|
|||
if (!result[0]) {
|
||||
strcpy(result, "keyword::");
|
||||
}
|
||||
strcpy(result+9, keywords[kwd]);
|
||||
strcpy(result + 9, keywords[kwd]);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
93
src/laws.c
93
src/laws.c
|
@ -1090,8 +1090,7 @@ int contact_cmd(unit * u, order * ord)
|
|||
unit *u2;
|
||||
region *r = u->region;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
u2 = getunitg(r, u->faction);
|
||||
|
||||
if (u2 != NULL) {
|
||||
|
@ -1147,10 +1146,10 @@ int quit_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
faction *f = u->faction;
|
||||
const char *passwd;
|
||||
keyword_t kwd;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token(); /* skip keyword */
|
||||
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_PASSWORD);
|
||||
passwd = getstrtoken();
|
||||
if (checkpasswd(f, (const char *)passwd, false)) {
|
||||
if (EnhancedQuit()) {
|
||||
|
@ -1359,8 +1358,7 @@ void do_enter(struct region *r, bool is_final_attempt)
|
|||
unit *ulast = NULL;
|
||||
const char * s;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
p = findparam_ex(s, u->faction->locale);
|
||||
id = getid();
|
||||
|
@ -1540,8 +1538,7 @@ int ally_cmd(unit * u, struct order *ord)
|
|||
int keyword, not_kw;
|
||||
const char *s;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
f = getfaction();
|
||||
|
||||
if (f == NULL || is_monsters(f)) {
|
||||
|
@ -1707,8 +1704,7 @@ int prefix_cmd(unit * u, struct order *ord)
|
|||
for (in = pnames; in->lang != lang; in = in->next);
|
||||
}
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (!*s) {
|
||||
|
@ -1761,8 +1757,7 @@ int display_cmd(unit * u, struct order *ord)
|
|||
const char *str;
|
||||
region *r = u->region;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
str = getstrtoken();
|
||||
switch (findparam_ex(str, u->faction->locale)) {
|
||||
|
@ -1933,8 +1928,7 @@ int name_cmd(struct unit *u, struct order *ord)
|
|||
bool foreign = false;
|
||||
const char *str;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
str = getstrtoken();
|
||||
p = findparam_ex(str, u->faction->locale);
|
||||
|
||||
|
@ -2193,8 +2187,7 @@ int mail_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
int n, cont;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token(); /* skip the keyword */
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
/* Falls kein Parameter, ist das eine Einheitsnummer;
|
||||
|
@ -2357,8 +2350,7 @@ int mail_cmd(unit * u, struct order *ord)
|
|||
|
||||
int banner_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
free(u->faction->banner);
|
||||
u->faction->banner = _strdup(getstrtoken());
|
||||
|
@ -2372,8 +2364,7 @@ int email_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
const char *s;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (!s[0]) {
|
||||
|
@ -2399,8 +2390,7 @@ int password_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
bool pwok = true;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (!s || !*s) {
|
||||
|
@ -2438,8 +2428,7 @@ int send_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
int option;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
option = findoption(s, u->faction->locale);
|
||||
|
@ -2778,9 +2767,10 @@ int promotion_cmd(unit * u, struct order *ord)
|
|||
int group_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
const char *s;
|
||||
keyword_t kwd;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
kwd = init_order(ord);
|
||||
assert(kwd == K_GROUP);
|
||||
s = getstrtoken();
|
||||
|
||||
join_group(u, s);
|
||||
|
@ -2791,8 +2781,7 @@ int origin_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
short px, py;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
px = (short)getint();
|
||||
py = (short)getint();
|
||||
|
@ -2804,8 +2793,7 @@ int origin_cmd(unit * u, struct order *ord)
|
|||
int guard_off_cmd(unit * u, struct order *ord)
|
||||
{
|
||||
assert(getkeyword(ord) == K_GUARD);
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
if (getparam(u->faction->locale) == P_NOT) {
|
||||
setguard(u, GUARD_NONE);
|
||||
|
@ -2818,8 +2806,7 @@ int reshow_cmd(unit * u, struct order *ord)
|
|||
const char *s;
|
||||
param_t p = NOPARAM;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
if (isparam(s, u->faction->locale, P_ANY)) {
|
||||
|
@ -2835,8 +2822,7 @@ int status_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
const char *param;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
param = getstrtoken();
|
||||
switch (findparam(param, u->faction->locale)) {
|
||||
|
@ -2867,7 +2853,7 @@ int status_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
break;
|
||||
default:
|
||||
if (param[0]) {
|
||||
if (param && param[0]) {
|
||||
add_message(&u->faction->msgs,
|
||||
msg_feedback(u, ord, "unknown_status", ""));
|
||||
}
|
||||
|
@ -2884,8 +2870,7 @@ int combatspell_cmd(unit * u, struct order *ord)
|
|||
int level = 0;
|
||||
spell *sp = 0;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
/* KAMPFZAUBER [NICHT] löscht alle gesetzten Kampfzauber */
|
||||
|
@ -2970,8 +2955,7 @@ int guard_on_cmd(unit * u, struct order *ord)
|
|||
{
|
||||
assert(getkeyword(ord) == K_GUARD);
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
/* GUARD NOT is handled in goard_off_cmd earlier in the turn */
|
||||
if (getparam(u->faction->locale) == P_NOT)
|
||||
|
@ -3132,8 +3116,7 @@ void restack_units(void)
|
|||
int id;
|
||||
unit *v;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
p = findparam(s, u->faction->locale);
|
||||
id = getid();
|
||||
|
@ -3208,8 +3191,7 @@ int renumber_cmd(unit * u, order * ord)
|
|||
int i;
|
||||
faction *f = u->faction;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
switch (findparam_ex(s, u->faction->locale)) {
|
||||
|
||||
|
@ -3942,8 +3924,7 @@ void defaultorders(void)
|
|||
if (getkeyword(ord) == K_DEFAULT) {
|
||||
char lbuf[8192];
|
||||
order *new_order;
|
||||
init_tokens(ord);
|
||||
skip_token(); /* skip the keyword */
|
||||
init_order(ord);
|
||||
strcpy(lbuf, getstrtoken());
|
||||
new_order = parse_order(lbuf, u->faction->locale);
|
||||
*ordp = ord->next;
|
||||
|
@ -4055,8 +4036,7 @@ int use_cmd(unit * u, struct order *ord)
|
|||
int n, err = ENOITEM;
|
||||
const item_type *itype;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
t = getstrtoken();
|
||||
n = atoi((const char *)t);
|
||||
|
@ -4105,8 +4085,7 @@ int pay_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
else {
|
||||
param_t p;
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
p = getparam(u->faction->locale);
|
||||
if (p == P_NOT) {
|
||||
unit *owner = building_owner(u->building);
|
||||
|
@ -4128,16 +4107,16 @@ static int reserve_i(unit * u, struct order *ord, int flags)
|
|||
const resource_type *rtype;
|
||||
const char *s;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
count = atoip((const char *)s);
|
||||
count = s ? atoip(s) : 0;
|
||||
para = findparam(s, u->faction->locale);
|
||||
|
||||
if (count == 0 && para == P_EACH) {
|
||||
count = getint() * u->number;
|
||||
}
|
||||
rtype = findresourcetype(getstrtoken(), u->faction->locale);
|
||||
s = getstrtoken();
|
||||
rtype = s ? findresourcetype(s, u->faction->locale) : 0;
|
||||
if (rtype == NULL)
|
||||
return 0;
|
||||
|
||||
|
@ -4170,8 +4149,7 @@ int claim_cmd(unit * u, struct order *ord)
|
|||
int n;
|
||||
const item_type *itype;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
t = getstrtoken();
|
||||
n = atoi((const char *)t);
|
||||
|
@ -4437,8 +4415,7 @@ int siege_cmd(unit * u, order * ord)
|
|||
resource_type *rt_catapultammo = NULL;
|
||||
resource_type *rt_catapult = NULL;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
b = getbuilding(r);
|
||||
|
||||
if (!b) {
|
||||
|
|
|
@ -92,9 +92,9 @@ skill_t get_skill(const char *s, const struct locale * lang)
|
|||
{
|
||||
skill_t result = NOSKILL;
|
||||
char buffer[64];
|
||||
char * str = transliterate(buffer, sizeof(buffer)-sizeof(int), s);
|
||||
|
||||
if (str) {
|
||||
if (s) {
|
||||
char * str = transliterate(buffer, sizeof(buffer) - sizeof(int), s);
|
||||
int i;
|
||||
const void * match;
|
||||
void **tokens = get_translations(lang, UT_SKILLS);
|
||||
|
|
11
src/spy.c
11
src/spy.c
|
@ -120,8 +120,7 @@ int spy_cmd(unit * u, struct order *ord)
|
|||
double spychance, observechance;
|
||||
region *r = u->region;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
target = getunit(r, u->faction);
|
||||
|
||||
if (!target) {
|
||||
|
@ -213,8 +212,7 @@ int setstealth_cmd(unit * u, struct order *ord)
|
|||
int level, rule;
|
||||
const race *trace;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
/* Tarne ohne Parameter: Setzt maximale Tarnung */
|
||||
|
@ -298,7 +296,7 @@ int setstealth_cmd(unit * u, struct order *ord)
|
|||
}
|
||||
if (rule&2) {
|
||||
if (get_keyword(s, u->faction->locale) == K_NUMBER) {
|
||||
const char *s2 = (const char *)getstrtoken();
|
||||
const char *s2 = getstrtoken();
|
||||
int nr = -1;
|
||||
|
||||
if (s2) {
|
||||
|
@ -484,8 +482,7 @@ int sabotage_cmd(unit * u, struct order *ord)
|
|||
region *r = u->region;
|
||||
int skdiff;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
s = getstrtoken();
|
||||
|
||||
i = findparam(s, u->faction->locale);
|
||||
|
|
21
src/study.c
21
src/study.c
|
@ -315,8 +315,7 @@ int teach_cmd(unit * u, struct order *ord)
|
|||
|
||||
count = 0;
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
#if TEACH_ALL
|
||||
if (getparam(u->faction->locale) == P_ANY) {
|
||||
|
@ -338,8 +337,7 @@ int teach_cmd(unit * u, struct order *ord)
|
|||
#endif
|
||||
if (getkeyword(student->thisorder) == K_STUDY) {
|
||||
/* Input ist nun von student->thisorder !! */
|
||||
init_tokens(student->thisorder);
|
||||
skip_token();
|
||||
init_order(student->thisorder);
|
||||
sk = getskill(student->faction->locale);
|
||||
if (sk != NOSKILL && teachskill[0] != NOSKILL) {
|
||||
for (i = 0; teachskill[i] != NOSKILL; ++i)
|
||||
|
@ -369,8 +367,7 @@ int teach_cmd(unit * u, struct order *ord)
|
|||
#endif
|
||||
if (getkeyword(student->thisorder) == K_STUDY) {
|
||||
/* Input ist nun von student->thisorder !! */
|
||||
init_tokens(student->thisorder);
|
||||
skip_token();
|
||||
init_order(student->thisorder);
|
||||
sk = getskill(student->faction->locale);
|
||||
if (sk != NOSKILL
|
||||
&& eff_skill_study(u, sk, r) - TEACHDIFFERENCE >= eff_skill(student,
|
||||
|
@ -390,8 +387,7 @@ int teach_cmd(unit * u, struct order *ord)
|
|||
order *new_order;
|
||||
|
||||
zOrder[0] = '\0';
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
while (!parser_end()) {
|
||||
unit *u2 = getunit(r, u->faction);
|
||||
|
@ -406,8 +402,7 @@ int teach_cmd(unit * u, struct order *ord)
|
|||
const char *token;
|
||||
/* Finde den string, der den Fehler verursacht hat */
|
||||
parser_pushstate();
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
|
||||
for (j = 0; j != count - 1; ++j) {
|
||||
/* skip over the first 'count' units */
|
||||
|
@ -450,8 +445,7 @@ int teach_cmd(unit * u, struct order *ord)
|
|||
|
||||
/* Input ist nun von u2->thisorder !! */
|
||||
parser_pushstate();
|
||||
init_tokens(u2->thisorder);
|
||||
skip_token();
|
||||
init_order(u2->thisorder);
|
||||
sk = getskill(u2->faction->locale);
|
||||
parser_popstate();
|
||||
|
||||
|
@ -551,8 +545,7 @@ int learn_cmd(unit * u, order * ord)
|
|||
return 0;
|
||||
}
|
||||
|
||||
init_tokens(ord);
|
||||
skip_token();
|
||||
init_order(ord);
|
||||
sk = getskill(u->faction->locale);
|
||||
|
||||
if (sk < 0) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -91,7 +91,8 @@ const char *itoab(int i, int base)
|
|||
*(dst) = '-';
|
||||
else
|
||||
++dst;
|
||||
} else
|
||||
}
|
||||
else
|
||||
*dst = '0';
|
||||
|
||||
return dst;
|
||||
|
|
|
@ -81,8 +81,11 @@ void parser_popstate(void)
|
|||
|
||||
bool parser_end(void)
|
||||
{
|
||||
if (states->current_token) {
|
||||
eatwhitespace_c(&states->current_token);
|
||||
return *states->current_token == 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void skip_token(void)
|
||||
|
@ -132,9 +135,13 @@ const char *parse_token(const char **str)
|
|||
bool escape = false;
|
||||
const char *ctoken = *str;
|
||||
|
||||
assert(ctoken);
|
||||
|
||||
if (!ctoken) {
|
||||
return 0;
|
||||
}
|
||||
eatwhitespace_c(&ctoken);
|
||||
if (!*ctoken) {
|
||||
return 0;
|
||||
}
|
||||
while (*ctoken && cursor - lbuf < MAXTOKENSIZE - 1) {
|
||||
ucs4_t ucs;
|
||||
size_t len;
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
Katja Zedel <katze@felidae.kn-bremen.de
|
||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
|
@ -48,49 +48,58 @@ char * transliterate(char * out, size_t size, const char * in)
|
|||
const char *src = in;
|
||||
char *dst = out;
|
||||
|
||||
assert(in && size > 0);
|
||||
--size; /* need space for a final 0-byte */
|
||||
while (*src && size) {
|
||||
size_t len;
|
||||
const char * p = src;
|
||||
while ((p+size>src) && *src && (~*src & 0x80)) {
|
||||
while ((p + size > src) && *src && (~*src & 0x80)) {
|
||||
*dst++ = (char)tolower(*src++);
|
||||
}
|
||||
len = src-p;
|
||||
len = src - p;
|
||||
size -= len;
|
||||
while (size>0 && *src && (*src & 0x80)) {
|
||||
while (size > 0 && *src && (*src & 0x80)) {
|
||||
unsigned int advance = 2;
|
||||
if (src[0]=='\xc3') {
|
||||
if (src[1]=='\xa4' || src[1]=='\x84') {
|
||||
if (src[0] == '\xc3') {
|
||||
if (src[1] == '\xa4' || src[1] == '\x84') {
|
||||
memcpy(dst, "ae", 2);
|
||||
} else if (src[1]=='\xb6' || src[1]=='\x96') {
|
||||
}
|
||||
else if (src[1] == '\xb6' || src[1] == '\x96') {
|
||||
memcpy(dst, "oe", 2);
|
||||
} else if (src[1]=='\xbc' || src[1]=='\x9c') {
|
||||
}
|
||||
else if (src[1] == '\xbc' || src[1] == '\x9c') {
|
||||
memcpy(dst, "ue", 2);
|
||||
} else if (src[1]=='\x9f') {
|
||||
}
|
||||
else if (src[1] == '\x9f') {
|
||||
memcpy(dst, "ss", 2);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
advance = 0;
|
||||
}
|
||||
} else if (src[0]=='\xe1') {
|
||||
if (src[1]=='\xba' && src[2]=='\x9e') {
|
||||
}
|
||||
else if (src[0] == '\xe1') {
|
||||
if (src[1] == '\xba' && src[2] == '\x9e') {
|
||||
memcpy(dst, "ss", 2);
|
||||
++src;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
advance = 0;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
advance = 0;
|
||||
}
|
||||
|
||||
if (advance && advance<=size) {
|
||||
src+=advance;
|
||||
dst+=advance;
|
||||
size-=advance;
|
||||
} else {
|
||||
if (advance && advance <= size) {
|
||||
src += advance;
|
||||
dst += advance;
|
||||
size -= advance;
|
||||
}
|
||||
else {
|
||||
ucs4_t ucs;
|
||||
unicode_utf8_to_ucs4(&ucs, src, &len);
|
||||
src+=len;
|
||||
*dst++='?';
|
||||
src += len;
|
||||
*dst++ = '?';
|
||||
--size;
|
||||
}
|
||||
}
|
||||
|
@ -108,34 +117,36 @@ void addtoken(void ** root, const char *str, variant id)
|
|||
} replace[] = {
|
||||
/* match lower-case (!) umlauts and others to transcriptions */
|
||||
{
|
||||
228, "AE"}, /* auml */
|
||||
228, "AE" }, /* auml */
|
||||
{
|
||||
246, "OE"}, /* ouml */
|
||||
246, "OE" }, /* ouml */
|
||||
{
|
||||
252, "UE"}, /* uuml */
|
||||
252, "UE" }, /* uuml */
|
||||
{
|
||||
223, "SS"}, /* szlig */
|
||||
223, "SS" }, /* szlig */
|
||||
{
|
||||
230, "AE"}, /* norsk */
|
||||
230, "AE" }, /* norsk */
|
||||
{
|
||||
248, "OE"}, /* norsk */
|
||||
248, "OE" }, /* norsk */
|
||||
{
|
||||
229, "AA"}, /* norsk */
|
||||
229, "AA" }, /* norsk */
|
||||
{
|
||||
0, ""}
|
||||
0, "" }
|
||||
};
|
||||
|
||||
assert(root && str);
|
||||
if (!*root) {
|
||||
tk = *root = calloc(1, sizeof(tnode));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
tk = *root;
|
||||
}
|
||||
assert(tk && tk==*root);
|
||||
assert(tk && tk == *root);
|
||||
if (!*str) {
|
||||
tk->id = id;
|
||||
tk->flags |= LEAF;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
tref *next;
|
||||
int ret, index, i = 0;
|
||||
ucs4_t ucs, lcs;
|
||||
|
@ -161,10 +172,10 @@ void addtoken(void ** root, const char *str, variant id)
|
|||
tnode *node = (tnode *)calloc(1, sizeof(tnode));
|
||||
|
||||
if (ucs < 'a' || ucs > 'z') {
|
||||
lcs = towlower((wint_t) ucs);
|
||||
lcs = towlower((wint_t)ucs);
|
||||
}
|
||||
if (ucs == lcs) {
|
||||
ucs = towupper((wint_t) ucs);
|
||||
ucs = towupper((wint_t)ucs);
|
||||
}
|
||||
|
||||
ref = (tref *)malloc(sizeof(tref));
|
||||
|
@ -187,7 +198,8 @@ void addtoken(void ** root, const char *str, variant id)
|
|||
tk->next[index] = ref;
|
||||
}
|
||||
next = ref;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
tnode * next_node = (tnode *)next->node;
|
||||
next_node->flags |= SHARED;
|
||||
if ((next_node->flags & LEAF) == 0)
|
||||
|
@ -211,7 +223,7 @@ void freetokens(void * root)
|
|||
{
|
||||
tnode * node = (tnode *)root;
|
||||
int i;
|
||||
for (i=0;node && i!=NODEHASHSIZE;++i) {
|
||||
for (i = 0; node && i != NODEHASHSIZE; ++i) {
|
||||
if (node->next[i]) {
|
||||
freetokens(node->next[i]->node);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue