forked from github/server
rename to gettoken, use more widely, add a basic test.
This commit is contained in:
parent
870d8001ef
commit
c8b9044f78
14 changed files with 859 additions and 816 deletions
|
@ -476,7 +476,8 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders)
|
||||||
n = getuint();
|
n = getuint();
|
||||||
|
|
||||||
if (u->number == 0) {
|
if (u->number == 0) {
|
||||||
str = getstrtoken();
|
char token[128];
|
||||||
|
str = gettoken(token, sizeof(token));
|
||||||
if (str && str[0]) {
|
if (str && str[0]) {
|
||||||
/* Monsters can RECRUIT 15 DRACOID
|
/* Monsters can RECRUIT 15 DRACOID
|
||||||
* also: secondary race */
|
* also: secondary race */
|
||||||
|
@ -626,6 +627,7 @@ void give_control(unit * u, unit * u2)
|
||||||
|
|
||||||
int give_control_cmd(unit * u, order * ord)
|
int give_control_cmd(unit * u, order * ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
unit *u2;
|
unit *u2;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
@ -633,7 +635,7 @@ int give_control_cmd(unit * u, order * ord)
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
getunit(r, u->faction, &u2);
|
getunit(r, u->faction, &u2);
|
||||||
|
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
if (s && isparam(s, u->faction->locale, P_CONTROL)) {
|
if (s && isparam(s, u->faction->locale, P_CONTROL)) {
|
||||||
message *msg = 0;
|
message *msg = 0;
|
||||||
|
|
||||||
|
@ -676,6 +678,7 @@ int give_control_cmd(unit * u, order * ord)
|
||||||
|
|
||||||
static int forget_cmd(unit * u, order * ord)
|
static int forget_cmd(unit * u, order * ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
skill_t sk;
|
skill_t sk;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
|
@ -685,7 +688,7 @@ static int forget_cmd(unit * u, order * ord)
|
||||||
}
|
}
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if ((sk = get_skill(s, u->faction->locale)) != NOSKILL) {
|
if ((sk = get_skill(s, u->faction->locale)) != NOSKILL) {
|
||||||
ADDMSG(&u->faction->msgs, msg_message("forget", "unit skill", u, sk));
|
ADDMSG(&u->faction->msgs, msg_message("forget", "unit skill", u, sk));
|
||||||
|
@ -1499,14 +1502,14 @@ int make_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
kwd = init_order(ord);
|
kwd = init_order(ord);
|
||||||
assert(kwd == K_MAKE);
|
assert(kwd == K_MAKE);
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (s) {
|
if (s) {
|
||||||
m = atoi((const char *)s);
|
m = atoi((const char *)s);
|
||||||
sprintf(ibuf, "%d", m);
|
sprintf(ibuf, "%d", m);
|
||||||
if (!strcmp(ibuf, (const char *)s)) {
|
if (!strcmp(ibuf, (const char *)s)) {
|
||||||
/* a quantity was given */
|
/* a quantity was given */
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m = INT_MAX;
|
m = INT_MAX;
|
||||||
|
@ -1522,7 +1525,7 @@ int make_cmd(unit * u, struct order *ord)
|
||||||
cmistake(u, ord, 275, MSG_PRODUCE);
|
cmistake(u, ord, 275, MSG_PRODUCE);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const char * s = getstrtok(token, sizeof(token));
|
const char * s = gettoken(token, sizeof(token));
|
||||||
direction_t d = s ? get_direction(s, u->faction->locale) : NODIRECTION;
|
direction_t d = s ? get_direction(s, u->faction->locale) : NODIRECTION;
|
||||||
if (d != NODIRECTION) {
|
if (d != NODIRECTION) {
|
||||||
build_road(r, u, m, d);
|
build_road(r, u, m, d);
|
||||||
|
@ -1755,6 +1758,7 @@ attrib_type at_trades = {
|
||||||
|
|
||||||
static void buy(unit * u, request ** buyorders, struct order *ord)
|
static void buy(unit * u, request ** buyorders, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
int n, k;
|
int n, k;
|
||||||
request *o;
|
request *o;
|
||||||
|
@ -1838,7 +1842,7 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
|
||||||
/* die Menge der verkauften Güter merken */
|
/* die Menge der verkauften Güter merken */
|
||||||
a->data.i += n;
|
a->data.i += n;
|
||||||
|
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
||||||
if (itype != NULL) {
|
if (itype != NULL) {
|
||||||
ltype = resource2luxury(itype->rtype);
|
ltype = resource2luxury(itype->rtype);
|
||||||
|
@ -2061,6 +2065,7 @@ static void expandselling(region * r, request * sellorders, int limit)
|
||||||
|
|
||||||
static bool sell(unit * u, request ** sellorders, struct order *ord)
|
static bool sell(unit * u, request ** sellorders, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
bool unlimited = true;
|
bool unlimited = true;
|
||||||
const item_type *itype;
|
const item_type *itype;
|
||||||
const luxury_type *ltype;
|
const luxury_type *ltype;
|
||||||
|
@ -2078,7 +2083,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
||||||
|
|
||||||
kwd = init_order(ord);
|
kwd = init_order(ord);
|
||||||
assert(kwd == K_SELL);
|
assert(kwd == K_SELL);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (findparam(s, u->faction->locale) == P_ANY) {
|
if (findparam(s, u->faction->locale) == P_ANY) {
|
||||||
unlimited = false;
|
unlimited = false;
|
||||||
|
@ -2136,7 +2141,7 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
||||||
cmistake(u, ord, 54, MSG_COMMERCE);
|
cmistake(u, ord, 54, MSG_COMMERCE);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
||||||
ltype = itype ? resource2luxury(itype->rtype) : 0;
|
ltype = itype ? resource2luxury(itype->rtype) : 0;
|
||||||
if (ltype == NULL) {
|
if (ltype == NULL) {
|
||||||
|
@ -2464,6 +2469,7 @@ static void breedhorses(region * r, unit * u)
|
||||||
|
|
||||||
static void breed_cmd(unit * u, struct order *ord)
|
static void breed_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
int m;
|
int m;
|
||||||
const char *s;
|
const char *s;
|
||||||
param_t p;
|
param_t p;
|
||||||
|
@ -2477,12 +2483,12 @@ static void breed_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
/* züchte [<anzahl>] <parameter> */
|
/* züchte [<anzahl>] <parameter> */
|
||||||
(void)init_order(ord);
|
(void)init_order(ord);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
m = s ? atoi((const char *)s) : 0;
|
m = s ? atoi((const char *)s) : 0;
|
||||||
if (m != 0) {
|
if (m != 0) {
|
||||||
/* first came a want-paramter */
|
/* first came a want-paramter */
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
m = INT_MAX;
|
m = INT_MAX;
|
||||||
|
@ -2545,10 +2551,6 @@ static void research_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
kwd = init_order(ord);
|
kwd = init_order(ord);
|
||||||
assert(kwd == K_RESEARCH);
|
assert(kwd == K_RESEARCH);
|
||||||
/*
|
|
||||||
const char *s = getstrtoken();
|
|
||||||
|
|
||||||
if (findparam(s, u->faction->locale) == P_HERBS) { */
|
|
||||||
|
|
||||||
if (eff_skill(u, SK_HERBALISM, r) < 7) {
|
if (eff_skill(u, SK_HERBALISM, r) < 7) {
|
||||||
cmistake(u, ord, 227, MSG_EVENT);
|
cmistake(u, ord, 227, MSG_EVENT);
|
||||||
|
|
11
src/give.c
11
src/give.c
|
@ -531,6 +531,7 @@ bool can_give_to(unit *u, unit *u2) {
|
||||||
|
|
||||||
void give_cmd(unit * u, order * ord)
|
void give_cmd(unit * u, order * ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
unit *u2;
|
unit *u2;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
@ -544,7 +545,7 @@ void give_cmd(unit * u, order * ord)
|
||||||
kwd = init_order(ord);
|
kwd = init_order(ord);
|
||||||
assert(kwd == K_GIVE);
|
assert(kwd == K_GIVE);
|
||||||
err = getunit(r, u->faction, &u2);
|
err = getunit(r, u->faction, &u2);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
n = s ? atoip(s) : 0;
|
n = s ? atoip(s) : 0;
|
||||||
p = (n > 0) ? NOPARAM : findparam(s, u->faction->locale);
|
p = (n > 0) ? NOPARAM : findparam(s, u->faction->locale);
|
||||||
|
|
||||||
|
@ -652,7 +653,7 @@ void give_cmd(unit * u, order * ord)
|
||||||
feedback_give_not_allowed(u, ord);
|
feedback_give_not_allowed(u, ord);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
if (!s || *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: */
|
/* do these checks once, not for each item we have: */
|
||||||
|
@ -732,11 +733,11 @@ void give_cmd(unit * u, order * ord)
|
||||||
msg_feedback(u, ord, "peasants_give_invalid", ""));
|
msg_feedback(u, ord, "peasants_give_invalid", ""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
s = getstrtoken(); /* skip one ahead to get the amount. */
|
s = gettoken(token, sizeof(token)); /* skip one ahead to get the amount. */
|
||||||
n = atoip(s); /* n: Anzahl */
|
n = s ? atoip(s) : 0; /* n: Anzahl */
|
||||||
n *= u2->number;
|
n *= u2->number;
|
||||||
}
|
}
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (s == NULL) {
|
if (s == NULL) {
|
||||||
cmistake(u, ord, 113, MSG_COMMERCE);
|
cmistake(u, ord, 113, MSG_COMMERCE);
|
||||||
|
|
|
@ -35,9 +35,10 @@ use_studypotion(struct unit *u, const struct item_type *itype, int amount,
|
||||||
struct order *ord)
|
struct order *ord)
|
||||||
{
|
{
|
||||||
if (init_order(u->thisorder) == K_STUDY) {
|
if (init_order(u->thisorder) == K_STUDY) {
|
||||||
|
char token[128];
|
||||||
skill_t sk = NOSKILL;
|
skill_t sk = NOSKILL;
|
||||||
skill *sv = 0;
|
skill *sv = 0;
|
||||||
const char * s = getstrtoken();
|
const char * s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (s) {
|
if (s) {
|
||||||
sk = get_skill(s, u->faction->locale);
|
sk = get_skill(s, u->faction->locale);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
Copyright (c) 1998-2010, Enno Rehling <enno@eressea.de>
|
||||||
Katja Zedel <katze@felidae.kn-bremen.de
|
Katja Zedel <katze@felidae.kn-bremen.de
|
||||||
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
Christian Schlittchen <corwin@amber.kn-bremen.de>
|
||||||
|
|
||||||
Permission to use, copy, modify, and/or distribute this software for any
|
Permission to use, copy, modify, and/or distribute this software for any
|
||||||
purpose with or without fee is hereby granted, provided that the above
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -91,19 +91,22 @@ ship *getship(const struct region * r)
|
||||||
|
|
||||||
static void destroy_road(unit * u, int nmax, struct order *ord)
|
static void destroy_road(unit * u, int nmax, struct order *ord)
|
||||||
{
|
{
|
||||||
const char *s = getstrtoken();
|
char token[128];
|
||||||
|
const char *s = gettoken(token, sizeof(token));
|
||||||
direction_t d = s ? get_direction(s, u->faction->locale) : NODIRECTION;
|
direction_t d = s ? get_direction(s, u->faction->locale) : NODIRECTION;
|
||||||
if (d == NODIRECTION) {
|
if (d == NODIRECTION) {
|
||||||
/* Die Richtung wurde nicht erkannt */
|
/* Die Richtung wurde nicht erkannt */
|
||||||
cmistake(u, ord, 71, MSG_PRODUCE);
|
cmistake(u, ord, 71, MSG_PRODUCE);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
unit *u2;
|
unit *u2;
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
short road, n = (short)nmax;
|
short road, n = (short)nmax;
|
||||||
|
|
||||||
if (nmax > SHRT_MAX) {
|
if (nmax > SHRT_MAX) {
|
||||||
n = SHRT_MAX;
|
n = SHRT_MAX;
|
||||||
} else if (nmax < 0) {
|
}
|
||||||
|
else if (nmax < 0) {
|
||||||
n = 0;
|
n = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,6 +141,7 @@ static void destroy_road(unit * u, int nmax, struct order *ord)
|
||||||
|
|
||||||
int destroy_cmd(unit * u, struct order *ord)
|
int destroy_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
ship *sh;
|
ship *sh;
|
||||||
unit *u2;
|
unit *u2;
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
|
@ -150,7 +154,7 @@ int destroy_cmd(unit * u, struct order *ord)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (findparam(s, u->faction->locale) == P_ROAD) {
|
if (findparam(s, u->faction->locale) == P_ROAD) {
|
||||||
destroy_road(u, INT_MAX, ord);
|
destroy_road(u, INT_MAX, ord);
|
||||||
|
@ -173,7 +177,7 @@ int destroy_cmd(unit * u, struct order *ord)
|
||||||
if (u->building) {
|
if (u->building) {
|
||||||
building *b = u->building;
|
building *b = u->building;
|
||||||
|
|
||||||
if (u!=building_owner(b)) {
|
if (u != building_owner(b)) {
|
||||||
cmistake(u, ord, 138, MSG_PRODUCE);
|
cmistake(u, ord, 138, MSG_PRODUCE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -192,16 +196,18 @@ int destroy_cmd(unit * u, struct order *ord)
|
||||||
ADDMSG(&u->faction->msgs, msg_message("destroy", "building unit", b, u));
|
ADDMSG(&u->faction->msgs, msg_message("destroy", "building unit", b, u));
|
||||||
con = b->type->construction;
|
con = b->type->construction;
|
||||||
remove_building(&r->buildings, b);
|
remove_building(&r->buildings, b);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* partial destroy */
|
/* partial destroy */
|
||||||
b->size -= n;
|
b->size -= n;
|
||||||
ADDMSG(&u->faction->msgs, msg_message("destroy_partial",
|
ADDMSG(&u->faction->msgs, msg_message("destroy_partial",
|
||||||
"building unit", b, u));
|
"building unit", b, u));
|
||||||
}
|
}
|
||||||
} else if (u->ship) {
|
}
|
||||||
|
else if (u->ship) {
|
||||||
sh = u->ship;
|
sh = u->ship;
|
||||||
|
|
||||||
if (u!=ship_owner(sh)) {
|
if (u != ship_owner(sh)) {
|
||||||
cmistake(u, ord, 138, MSG_PRODUCE);
|
cmistake(u, ord, 138, MSG_PRODUCE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -222,13 +228,15 @@ int destroy_cmd(unit * u, struct order *ord)
|
||||||
"unit region ship", u, r, sh));
|
"unit region ship", u, r, sh));
|
||||||
con = sh->type->construction;
|
con = sh->type->construction;
|
||||||
remove_ship(&sh->region->ships, sh);
|
remove_ship(&sh->region->ships, sh);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* partial destroy */
|
/* partial destroy */
|
||||||
sh->size -= (sh->type->construction->maxsize * n) / 100;
|
sh->size -= (sh->type->construction->maxsize * n) / 100;
|
||||||
ADDMSG(&u->faction->msgs, msg_message("shipdestroy_partial",
|
ADDMSG(&u->faction->msgs, msg_message("shipdestroy_partial",
|
||||||
"unit region ship", u, r, sh));
|
"unit region ship", u, r, sh));
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
cmistake(u, ord, 138, MSG_PRODUCE);
|
cmistake(u, ord, 138, MSG_PRODUCE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -238,7 +246,7 @@ int destroy_cmd(unit * u, struct order *ord)
|
||||||
int c;
|
int c;
|
||||||
for (c = 0; con->materials[c].number; ++c) {
|
for (c = 0; con->materials[c].number; ++c) {
|
||||||
const requirement *rq = con->materials + c;
|
const requirement *rq = con->materials + c;
|
||||||
int recycle = (rq->number * size / con->reqsize)/2;
|
int recycle = (rq->number * size / con->reqsize) / 2;
|
||||||
if (recycle) {
|
if (recycle) {
|
||||||
change_resource(u, rq->rtype, recycle);
|
change_resource(u, rq->rtype, recycle);
|
||||||
}
|
}
|
||||||
|
@ -281,14 +289,16 @@ void build_road(region * r, unit * u, int size, direction_t d)
|
||||||
cmistake(u, u->thisorder, 132, MSG_PRODUCE);
|
cmistake(u, u->thisorder, 132, MSG_PRODUCE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (r->terrain == newterrain(T_DESERT)) {
|
}
|
||||||
|
else if (r->terrain == newterrain(T_DESERT)) {
|
||||||
const struct building_type *bt_caravan = bt_find("caravan");
|
const struct building_type *bt_caravan = bt_find("caravan");
|
||||||
/* wenn keine Karawanserei existiert */
|
/* wenn keine Karawanserei existiert */
|
||||||
if (!bt_caravan || !buildingtype_exists(r, bt_caravan, true)) {
|
if (!bt_caravan || !buildingtype_exists(r, bt_caravan, true)) {
|
||||||
cmistake(u, u->thisorder, 133, MSG_PRODUCE);
|
cmistake(u, u->thisorder, 133, MSG_PRODUCE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (r->terrain == newterrain(T_GLACIER)) {
|
}
|
||||||
|
else if (r->terrain == newterrain(T_GLACIER)) {
|
||||||
const struct building_type *bt_tunnel = bt_find("tunnel");
|
const struct building_type *bt_tunnel = bt_find("tunnel");
|
||||||
/* wenn kein Tunnel existiert */
|
/* wenn kein Tunnel existiert */
|
||||||
if (!bt_tunnel || !buildingtype_exists(r, bt_tunnel, true)) {
|
if (!bt_tunnel || !buildingtype_exists(r, bt_tunnel, true)) {
|
||||||
|
@ -312,7 +322,8 @@ void build_road(region * r, unit * u, int size, direction_t d)
|
||||||
/* baumaximum anhand der rohstoffe */
|
/* baumaximum anhand der rohstoffe */
|
||||||
if (u_race(u) == get_race(RC_STONEGOLEM)) {
|
if (u_race(u) == get_race(RC_STONEGOLEM)) {
|
||||||
n = u->number * GOLEM_STONE;
|
n = u->number * GOLEM_STONE;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
n = get_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, left);
|
n = get_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, left);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
cmistake(u, u->thisorder, 151, MSG_PRODUCE);
|
cmistake(u, u->thisorder, 151, MSG_PRODUCE);
|
||||||
|
@ -357,7 +368,8 @@ void build_road(region * r, unit * u, int size, direction_t d)
|
||||||
++golemsused;
|
++golemsused;
|
||||||
}
|
}
|
||||||
scale_number(u, u->number - golemsused);
|
scale_number(u, u->number - golemsused);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
use_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, n);
|
use_pooled(u, get_resourcetype(R_STONE), GET_DEFAULT, n);
|
||||||
/* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */
|
/* Nur soviel PRODUCEEXP wie auch tatsaechlich gemacht wurde */
|
||||||
produceexp(u, SK_ROAD_BUILDING, _min(n, u->number));
|
produceexp(u, SK_ROAD_BUILDING, _min(n, u->number));
|
||||||
|
@ -373,7 +385,7 @@ void build_road(region * r, unit * u, int size, direction_t d)
|
||||||
* ** ** ** ** ** ** */
|
* ** ** ** ** ** ** */
|
||||||
|
|
||||||
static int required(int size, int msize, int maxneed)
|
static int required(int size, int msize, int maxneed)
|
||||||
/* um size von msize Punkten zu bauen,
|
/* um size von msize Punkten zu bauen,
|
||||||
* braucht man required von maxneed resourcen */
|
* braucht man required von maxneed resourcen */
|
||||||
{
|
{
|
||||||
int used;
|
int used;
|
||||||
|
@ -386,11 +398,11 @@ static int required(int size, int msize, int maxneed)
|
||||||
|
|
||||||
static int
|
static int
|
||||||
matmod(const attrib * a, const unit * u, const resource_type * material,
|
matmod(const attrib * a, const unit * u, const resource_type * material,
|
||||||
int value)
|
int value)
|
||||||
{
|
{
|
||||||
for (a = a_find((attrib *) a, &at_matmod); a && a->type == &at_matmod;
|
for (a = a_find((attrib *)a, &at_matmod); a && a->type == &at_matmod;
|
||||||
a = a->next) {
|
a = a->next) {
|
||||||
mm_fun fun = (mm_fun) a->data.f;
|
mm_fun fun = (mm_fun)a->data.f;
|
||||||
value = fun(u, material, value);
|
value = fun(u, material, value);
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
return value; /* pass errors to caller */
|
return value; /* pass errors to caller */
|
||||||
|
@ -496,7 +508,8 @@ int build(unit * u, const construction * ctype, int completed, int want)
|
||||||
*/
|
*/
|
||||||
if (type->maxsize > 1) {
|
if (type->maxsize > 1) {
|
||||||
completed = completed % type->maxsize;
|
completed = completed % type->maxsize;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
completed = 0;
|
completed = 0;
|
||||||
assert(type->reqsize >= 1);
|
assert(type->reqsize >= 1);
|
||||||
}
|
}
|
||||||
|
@ -509,7 +522,8 @@ int build(unit * u, const construction * ctype, int completed, int want)
|
||||||
/* n = maximum buildable size */
|
/* n = maximum buildable size */
|
||||||
if (type->minskill > 1) {
|
if (type->minskill > 1) {
|
||||||
n = skills / type->minskill;
|
n = skills / type->minskill;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
n = skills;
|
n = skills;
|
||||||
}
|
}
|
||||||
/* Flinkfingerring wirkt nicht auf Mengenbegrenzte (magische)
|
/* Flinkfingerring wirkt nicht auf Mengenbegrenzte (magische)
|
||||||
|
@ -556,7 +570,8 @@ int build(unit * u, const construction * ctype, int completed, int want)
|
||||||
break;
|
break;
|
||||||
--n; /* TODO: optimieren? */
|
--n; /* TODO: optimieren? */
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
int maxn = canuse / type->materials[c].number;
|
int maxn = canuse / type->materials[c].number;
|
||||||
if (maxn < n)
|
if (maxn < n)
|
||||||
n = maxn;
|
n = maxn;
|
||||||
|
@ -623,8 +638,8 @@ message *msg_materials_required(unit * u, order * ord,
|
||||||
}
|
}
|
||||||
|
|
||||||
int maxbuild(const unit * u, const construction * cons)
|
int maxbuild(const unit * u, const construction * cons)
|
||||||
/* calculate maximum size that can be built from available material */
|
/* calculate maximum size that can be built from available material */
|
||||||
/* !! ignores maximum objectsize and improvements... */
|
/* !! ignores maximum objectsize and improvements... */
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
int maximum = INT_MAX;
|
int maximum = INT_MAX;
|
||||||
|
@ -634,7 +649,8 @@ int maxbuild(const unit * u, const construction * cons)
|
||||||
int need = required(1, cons->reqsize, cons->materials[c].number);
|
int need = required(1, cons->reqsize, cons->materials[c].number);
|
||||||
if (have < need) {
|
if (have < need) {
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
maximum = _min(maximum, have / need);
|
maximum = _min(maximum, have / need);
|
||||||
}
|
}
|
||||||
return maximum;
|
return maximum;
|
||||||
|
@ -673,13 +689,15 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
||||||
/* vieleicht Tippfehler und die eigene Burg ist gemeint? */
|
/* vieleicht Tippfehler und die eigene Burg ist gemeint? */
|
||||||
if (u->building && u->building->type == btype) {
|
if (u->building && u->building->type == btype) {
|
||||||
b = u->building;
|
b = u->building;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* keine neue Burg anfangen wenn eine Nummer angegeben war */
|
/* keine neue Burg anfangen wenn eine Nummer angegeben war */
|
||||||
cmistake(u, ord, 6, MSG_PRODUCE);
|
cmistake(u, ord, 6, MSG_PRODUCE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (u->building && u->building->type == btype) {
|
}
|
||||||
|
else if (u->building && u->building->type == btype) {
|
||||||
b = u->building;
|
b = u->building;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -733,13 +751,16 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
||||||
if (b == NULL) {
|
if (b == NULL) {
|
||||||
if (btype->maxsize > 0) {
|
if (btype->maxsize > 0) {
|
||||||
n = btype->maxsize - built;
|
n = btype->maxsize - built;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
n = INT_MAX;
|
n = INT_MAX;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
if (b->type->maxsize > 0) {
|
if (b->type->maxsize > 0) {
|
||||||
n = b->type->maxsize - built;
|
n = b->type->maxsize - built;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
n = INT_MAX;
|
n = INT_MAX;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -761,7 +782,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
||||||
cmistake(u, ord, 50, MSG_PRODUCE);
|
cmistake(u, ord, 50, MSG_PRODUCE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (built<=0) {
|
if (built <= 0) {
|
||||||
return built;
|
return built;
|
||||||
}
|
}
|
||||||
/* at this point, the building size is increased. */
|
/* at this point, the building size is increased. */
|
||||||
|
@ -769,7 +790,7 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
||||||
/* build a new building */
|
/* build a new building */
|
||||||
b = new_building(btype, r, lang);
|
b = new_building(btype, r, lang);
|
||||||
b->type = btype;
|
b->type = btype;
|
||||||
fset(b, BLD_MAINTAINED|BLD_WORKING);
|
fset(b, BLD_MAINTAINED | BLD_WORKING);
|
||||||
|
|
||||||
/* Die Einheit befindet sich automatisch im Inneren der neuen Burg. */
|
/* Die Einheit befindet sich automatisch im Inneren der neuen Burg. */
|
||||||
if (u->number && leave(u, false)) {
|
if (u->number && leave(u, false)) {
|
||||||
|
@ -782,22 +803,26 @@ build_building(unit * u, const building_type * btype, int id, int want, order *
|
||||||
if (want - built <= 0) {
|
if (want - built <= 0) {
|
||||||
/* gebäude fertig */
|
/* gebäude fertig */
|
||||||
new_order = default_order(lang);
|
new_order = default_order(lang);
|
||||||
} else if (want != INT_MAX) {
|
}
|
||||||
|
else if (want != INT_MAX) {
|
||||||
/* reduzierte restgröße */
|
/* reduzierte restgröße */
|
||||||
const char *hasspace = strchr(btname, ' ');
|
const char *hasspace = strchr(btname, ' ');
|
||||||
if (hasspace) {
|
if (hasspace) {
|
||||||
new_order =
|
new_order =
|
||||||
create_order(K_MAKE, lang, "%d \"%s\" %i", n - built, btname, b->no);
|
create_order(K_MAKE, lang, "%d \"%s\" %i", n - built, btname, b->no);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
new_order =
|
new_order =
|
||||||
create_order(K_MAKE, lang, "%d %s %i", n - built, btname, b->no);
|
create_order(K_MAKE, lang, "%d %s %i", n - built, btname, b->no);
|
||||||
}
|
}
|
||||||
} else if (btname) {
|
}
|
||||||
|
else if (btname) {
|
||||||
/* Neues Haus, Befehl mit Gebäudename */
|
/* Neues Haus, Befehl mit Gebäudename */
|
||||||
const char *hasspace = strchr(btname, ' ');
|
const char *hasspace = strchr(btname, ' ');
|
||||||
if (hasspace) {
|
if (hasspace) {
|
||||||
new_order = create_order(K_MAKE, lang, "\"%s\" %i", btname, b->no);
|
new_order = create_order(K_MAKE, lang, "\"%s\" %i", btname, b->no);
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
new_order = create_order(K_MAKE, lang, "%s %i", btname, b->no);
|
new_order = create_order(K_MAKE, lang, "%s %i", btname, b->no);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -828,7 +853,8 @@ static void build_ship(unit * u, ship * sh, int want)
|
||||||
if (can >= n) {
|
if (can >= n) {
|
||||||
sh->size += n;
|
sh->size += n;
|
||||||
can -= n;
|
can -= n;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
sh->size += can;
|
sh->size += can;
|
||||||
n = can;
|
n = can;
|
||||||
can = 0;
|
can = 0;
|
||||||
|
@ -850,7 +876,7 @@ static void build_ship(unit * u, ship * sh, int want)
|
||||||
|
|
||||||
void
|
void
|
||||||
create_ship(region * r, unit * u, const struct ship_type *newtype, int want,
|
create_ship(region * r, unit * u, const struct ship_type *newtype, int want,
|
||||||
order * ord)
|
order * ord)
|
||||||
{
|
{
|
||||||
ship *sh;
|
ship *sh;
|
||||||
int msize;
|
int msize;
|
||||||
|
|
|
@ -73,10 +73,11 @@ const char *str, parser fun)
|
||||||
|
|
||||||
static int do_command_i(const void *keys, struct unit *u, struct order *ord)
|
static int do_command_i(const void *keys, struct unit *u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
const char *c;
|
const char *c;
|
||||||
variant var;
|
variant var;
|
||||||
|
|
||||||
c = getstrtoken();
|
c = gettoken(token, sizeof(token));
|
||||||
if (findtoken(keys, c, &var) == E_TOK_SUCCESS) {
|
if (findtoken(keys, c, &var) == E_TOK_SUCCESS) {
|
||||||
command *cmd = (command *)var.v;
|
command *cmd = (command *)var.v;
|
||||||
if (cmd->nodes && *c) {
|
if (cmd->nodes && *c) {
|
||||||
|
|
|
@ -796,13 +796,15 @@ parse(keyword_t kword, int(*dofun) (unit *, struct order *), bool thisorder)
|
||||||
|
|
||||||
unsigned int getuint(void)
|
unsigned int getuint(void)
|
||||||
{
|
{
|
||||||
const char *s = getstrtoken();
|
char token[16];
|
||||||
|
const char *s = gettoken(token, sizeof(token));
|
||||||
return s ? atoip(s) : 0;
|
return s ? atoip(s) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int getint(void)
|
int getint(void)
|
||||||
{
|
{
|
||||||
const char * s = getstrtoken();
|
char token[16];
|
||||||
|
const char * s = gettoken(token, sizeof(token));
|
||||||
return s ? atoi(s) : 0;
|
return s ? atoi(s) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -875,7 +877,8 @@ bool isparam(const char *s, const struct locale * lang, param_t param)
|
||||||
|
|
||||||
param_t getparam(const struct locale * lang)
|
param_t getparam(const struct locale * lang)
|
||||||
{
|
{
|
||||||
const char *s = getstrtoken();
|
char token[64];
|
||||||
|
const char *s = gettoken(token, sizeof(token));
|
||||||
return s ? findparam(s, lang) : NOPARAM;
|
return s ? findparam(s, lang) : NOPARAM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -909,7 +912,8 @@ static int read_newunitid(const faction * f, const region * r)
|
||||||
|
|
||||||
int read_unitid(const faction * f, const region * r)
|
int read_unitid(const faction * f, const region * r)
|
||||||
{
|
{
|
||||||
const char *s = getstrtoken();
|
char token[8];
|
||||||
|
const char *s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
/* Da s nun nur einen string enthaelt, suchen wir ihn direkt in der
|
/* Da s nun nur einen string enthaelt, suchen wir ihn direkt in der
|
||||||
* paramliste. machen wir das nicht, dann wird getnewunit in s nach der
|
* paramliste. machen wir das nicht, dann wird getnewunit in s nach der
|
||||||
|
|
|
@ -225,7 +225,7 @@ static faction *factionorders(void)
|
||||||
|
|
||||||
if (f != NULL && !fval(f, FFL_NPC)) {
|
if (f != NULL && !fval(f, FFL_NPC)) {
|
||||||
char token[128];
|
char token[128];
|
||||||
const char *pass = getstrtok(token, sizeof(token));
|
const char *pass = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (!checkpasswd(f, (const char *)pass)) {
|
if (!checkpasswd(f, (const char *)pass)) {
|
||||||
log_debug("Invalid password for faction %s\n", itoa36(fid));
|
log_debug("Invalid password for faction %s\n", itoa36(fid));
|
||||||
|
@ -273,7 +273,7 @@ int readorders(const char *filename)
|
||||||
param_t p;
|
param_t p;
|
||||||
const char *s;
|
const char *s;
|
||||||
init_tokens_str(b);
|
init_tokens_str(b);
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
p = s ? findparam(s, lang) : NOPARAM;
|
p = s ? findparam(s, lang) : NOPARAM;
|
||||||
switch (p) {
|
switch (p) {
|
||||||
#undef LOCALE_CHANGE
|
#undef LOCALE_CHANGE
|
||||||
|
|
|
@ -491,16 +491,19 @@ void usetprivate(unit * u, const char *str)
|
||||||
{
|
{
|
||||||
attrib *a = a_find(u->attribs, &at_private);
|
attrib *a = a_find(u->attribs, &at_private);
|
||||||
|
|
||||||
if (str == NULL) {
|
if (str == NULL || *str == 0) {
|
||||||
if (a)
|
if (a) {
|
||||||
a_remove(&u->attribs, a);
|
a_remove(&u->attribs, a);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!a)
|
if (!a) {
|
||||||
a = a_add(&u->attribs, a_new(&at_private));
|
a = a_add(&u->attribs, a_new(&at_private));
|
||||||
if (a->data.v)
|
}
|
||||||
|
if (a->data.v) {
|
||||||
free(a->data.v);
|
free(a->data.v);
|
||||||
a->data.v = _strdup((const char *)str);
|
}
|
||||||
|
a->data.v = _strdup(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************/
|
/*********************/
|
||||||
|
|
102
src/laws.c
102
src/laws.c
|
@ -953,7 +953,7 @@ int quit_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
kwd = init_order(ord);
|
kwd = init_order(ord);
|
||||||
assert(kwd == K_QUIT);
|
assert(kwd == K_QUIT);
|
||||||
passwd = getstrtok(token, sizeof(token));
|
passwd = gettoken(token, sizeof(token));
|
||||||
if (checkpasswd(f, (const char *)passwd)) {
|
if (checkpasswd(f, (const char *)passwd)) {
|
||||||
if (EnhancedQuit()) {
|
if (EnhancedQuit()) {
|
||||||
int f2_id = getid();
|
int f2_id = getid();
|
||||||
|
@ -1167,7 +1167,7 @@ void do_enter(struct region *r, bool is_final_attempt)
|
||||||
const char * s;
|
const char * s;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
p = findparam_ex(s, u->faction->locale);
|
p = findparam_ex(s, u->faction->locale);
|
||||||
id = getid();
|
id = getid();
|
||||||
|
|
||||||
|
@ -1357,7 +1357,7 @@ int ally_cmd(unit * u, struct order *ord)
|
||||||
if (f == u->faction)
|
if (f == u->faction)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (!s[0])
|
if (!s[0])
|
||||||
keyword = P_ANY;
|
keyword = P_ANY;
|
||||||
|
@ -1495,6 +1495,7 @@ static void init_prefixnames(void)
|
||||||
|
|
||||||
int prefix_cmd(unit * u, struct order *ord)
|
int prefix_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
attrib **ap;
|
attrib **ap;
|
||||||
const char *s;
|
const char *s;
|
||||||
local_names *in = pnames;
|
local_names *in = pnames;
|
||||||
|
@ -1512,7 +1513,7 @@ int prefix_cmd(unit * u, struct order *ord)
|
||||||
}
|
}
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (!s || !*s) {
|
if (!s || !*s) {
|
||||||
attrib *a = NULL;
|
attrib *a = NULL;
|
||||||
|
@ -1559,13 +1560,14 @@ static cmp_building_cb get_cmp_region_owner(void)
|
||||||
|
|
||||||
int display_cmd(unit * u, struct order *ord)
|
int display_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
char **s = NULL;
|
char **s = NULL;
|
||||||
const char *str;
|
const char *str;
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
|
|
||||||
str = getstrtoken();
|
str = gettoken(token, sizeof(token));
|
||||||
switch (findparam_ex(str, u->faction->locale)) {
|
switch (findparam_ex(str, u->faction->locale)) {
|
||||||
case P_BUILDING:
|
case P_BUILDING:
|
||||||
case P_GEBAEUDE:
|
case P_GEBAEUDE:
|
||||||
|
@ -1601,15 +1603,7 @@ int display_cmd(unit * u, struct order *ord)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case P_PRIVAT:
|
case P_PRIVAT:
|
||||||
{
|
usetprivate(u, getstrtoken());
|
||||||
const char *d = getstrtoken();
|
|
||||||
if (d == NULL || *d == 0) {
|
|
||||||
usetprivate(u, NULL);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
usetprivate(u, d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case P_REGION:
|
case P_REGION:
|
||||||
|
@ -1732,6 +1726,7 @@ rename_building(unit * u, order * ord, building * b, const char *name)
|
||||||
|
|
||||||
int name_cmd(struct unit *u, struct order *ord)
|
int name_cmd(struct unit *u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
building *b = u->building;
|
building *b = u->building;
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
char **s = NULL;
|
char **s = NULL;
|
||||||
|
@ -1740,11 +1735,11 @@ int name_cmd(struct unit *u, struct order *ord)
|
||||||
const char *str;
|
const char *str;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
str = getstrtoken();
|
str = gettoken(token, sizeof(token));
|
||||||
p = findparam_ex(str, u->faction->locale);
|
p = findparam_ex(str, u->faction->locale);
|
||||||
|
|
||||||
if (p == P_FOREIGN) {
|
if (p == P_FOREIGN) {
|
||||||
str = getstrtoken();
|
str = gettoken(token, sizeof(token));
|
||||||
foreign = true;
|
foreign = true;
|
||||||
p = findparam_ex(str, u->faction->locale);
|
p = findparam_ex(str, u->faction->locale);
|
||||||
}
|
}
|
||||||
|
@ -1994,13 +1989,14 @@ static void mailfaction(unit * u, int n, struct order *ord, const char *s)
|
||||||
|
|
||||||
int mail_cmd(unit * u, struct order *ord)
|
int mail_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
region *r = u->region;
|
region *r = u->region;
|
||||||
unit *u2;
|
unit *u2;
|
||||||
const char *s;
|
const char *s;
|
||||||
int n, cont;
|
int n, cont;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
/* Falls kein Parameter, ist das eine Einheitsnummer;
|
/* Falls kein Parameter, ist das eine Einheitsnummer;
|
||||||
* das Füllwort "AN" muß wegfallen, da gültige Nummer! */
|
* das Füllwort "AN" muß wegfallen, da gültige Nummer! */
|
||||||
|
@ -2185,7 +2181,7 @@ int email_cmd(unit * u, struct order *ord)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
faction *f = u->faction;
|
faction *f = u->faction;
|
||||||
if (set_email(&f->email, (const char *)s) != 0) {
|
if (set_email(&f->email, s) != 0) {
|
||||||
log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), s);
|
log_error("Invalid email address for faction %s: %s\n", itoa36(f->no), s);
|
||||||
ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", s));
|
ADDMSG(&f->msgs, msg_message("changemail_invalid", "value", s));
|
||||||
}
|
}
|
||||||
|
@ -2204,7 +2200,7 @@ int password_cmd(unit * u, struct order *ord)
|
||||||
bool pwok = true;
|
bool pwok = true;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtoken();
|
s = gettoken(pwbuf, sizeof(pwbuf));
|
||||||
|
|
||||||
if (!s || !*s) {
|
if (!s || !*s) {
|
||||||
for (i = 0; i < 6; i++)
|
for (i = 0; i < 6; i++)
|
||||||
|
@ -2213,14 +2209,10 @@ int password_cmd(unit * u, struct order *ord)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
char *c;
|
char *c;
|
||||||
|
for (c = pwbuf; *c && pwok; ++c) {
|
||||||
strlcpy(pwbuf, (const char *)s, 31);
|
if (!isalnum(*(unsigned char *)c)) {
|
||||||
pwbuf[31] = 0;
|
|
||||||
c = pwbuf;
|
|
||||||
while (*c && pwok) {
|
|
||||||
if (!isalnum(*(unsigned char *)c))
|
|
||||||
pwok = false;
|
pwok = false;
|
||||||
c++;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free(u->faction->passw);
|
free(u->faction->passw);
|
||||||
|
@ -2238,11 +2230,12 @@ int password_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
int send_cmd(unit * u, struct order *ord)
|
int send_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
const char *s;
|
const char *s;
|
||||||
int option;
|
int option;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
option = findoption(s, u->faction->locale);
|
option = findoption(s, u->faction->locale);
|
||||||
|
|
||||||
|
@ -2579,14 +2572,11 @@ int promotion_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
int group_cmd(unit * u, struct order *ord)
|
int group_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
const char *s;
|
|
||||||
keyword_t kwd;
|
keyword_t kwd;
|
||||||
|
|
||||||
kwd = init_order(ord);
|
kwd = init_order(ord);
|
||||||
assert(kwd == K_GROUP);
|
assert(kwd == K_GROUP);
|
||||||
s = getstrtoken();
|
join_group(u, getstrtoken());
|
||||||
|
|
||||||
join_group(u, s);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2621,7 +2611,7 @@ int reshow_cmd(unit * u, struct order *ord)
|
||||||
param_t p = NOPARAM;
|
param_t p = NOPARAM;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtok(lbuf, sizeof(lbuf));
|
s = gettoken(lbuf, sizeof(lbuf));
|
||||||
|
|
||||||
if (s && isparam(s, u->faction->locale, P_ANY)) {
|
if (s && isparam(s, u->faction->locale, P_ANY)) {
|
||||||
p = getparam(u->faction->locale);
|
p = getparam(u->faction->locale);
|
||||||
|
@ -2634,12 +2624,12 @@ int reshow_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
int status_cmd(unit * u, struct order *ord)
|
int status_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
const char *param;
|
char token[128];
|
||||||
|
const char *s;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
|
s = gettoken(token, sizeof(token));
|
||||||
param = getstrtoken();
|
switch (findparam(s, u->faction->locale)) {
|
||||||
switch (findparam(param, u->faction->locale)) {
|
|
||||||
case P_NOT:
|
case P_NOT:
|
||||||
setstatus(u, ST_AVOID);
|
setstatus(u, ST_AVOID);
|
||||||
break;
|
break;
|
||||||
|
@ -2667,7 +2657,7 @@ int status_cmd(unit * u, struct order *ord)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (param && param[0]) {
|
if (s && s[0]) {
|
||||||
add_message(&u->faction->msgs,
|
add_message(&u->faction->msgs,
|
||||||
msg_feedback(u, ord, "unknown_status", ""));
|
msg_feedback(u, ord, "unknown_status", ""));
|
||||||
}
|
}
|
||||||
|
@ -2686,7 +2676,7 @@ int combatspell_cmd(unit * u, struct order *ord)
|
||||||
spell *sp = 0;
|
spell *sp = 0;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
/* KAMPFZAUBER [NICHT] löscht alle gesetzten Kampfzauber */
|
/* KAMPFZAUBER [NICHT] löscht alle gesetzten Kampfzauber */
|
||||||
if (!s || *s == 0 || findparam(s, u->faction->locale) == P_NOT) {
|
if (!s || *s == 0 || findparam(s, u->faction->locale) == P_NOT) {
|
||||||
|
@ -2699,7 +2689,7 @@ int combatspell_cmd(unit * u, struct order *ord)
|
||||||
/* Merken, setzen kommt erst später */
|
/* Merken, setzen kommt erst später */
|
||||||
level = getint();
|
level = getint();
|
||||||
level = _max(0, level);
|
level = _max(0, level);
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
}
|
}
|
||||||
|
|
||||||
sp = unit_getspell(u, s, u->faction->locale);
|
sp = unit_getspell(u, s, u->faction->locale);
|
||||||
|
@ -2708,7 +2698,7 @@ int combatspell_cmd(unit * u, struct order *ord)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
|
|
||||||
if (findparam(s, u->faction->locale) == P_NOT) {
|
if (findparam(s, u->faction->locale) == P_NOT) {
|
||||||
/* KAMPFZAUBER "<Spruchname>" NICHT löscht diesen speziellen
|
/* KAMPFZAUBER "<Spruchname>" NICHT löscht diesen speziellen
|
||||||
|
@ -2933,7 +2923,7 @@ void restack_units(void)
|
||||||
unit *v;
|
unit *v;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
p = findparam(s, u->faction->locale);
|
p = findparam(s, u->faction->locale);
|
||||||
id = getid();
|
id = getid();
|
||||||
v = findunit(id);
|
v = findunit(id);
|
||||||
|
@ -3009,11 +2999,11 @@ int renumber_cmd(unit * u, order * ord)
|
||||||
faction *f = u->faction;
|
faction *f = u->faction;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
switch (findparam_ex(s, u->faction->locale)) {
|
switch (findparam_ex(s, u->faction->locale)) {
|
||||||
|
|
||||||
case P_FACTION:
|
case P_FACTION:
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
if (s && *s) {
|
if (s && *s) {
|
||||||
int id = atoi36((const char *)s);
|
int id = atoi36((const char *)s);
|
||||||
attrib *a = a_find(f->attribs, &at_number);
|
attrib *a = a_find(f->attribs, &at_number);
|
||||||
|
@ -3024,7 +3014,7 @@ int renumber_cmd(unit * u, order * ord)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case P_UNIT:
|
case P_UNIT:
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
if (s == NULL || *s == 0) {
|
if (s == NULL || *s == 0) {
|
||||||
i = newunitid();
|
i = newunitid();
|
||||||
}
|
}
|
||||||
|
@ -3067,7 +3057,7 @@ int renumber_cmd(unit * u, order * ord)
|
||||||
cmistake(u, ord, 116, MSG_EVENT);
|
cmistake(u, ord, 116, MSG_EVENT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
if (s == NULL || *s == 0) {
|
if (s == NULL || *s == 0) {
|
||||||
i = newcontainerid();
|
i = newcontainerid();
|
||||||
}
|
}
|
||||||
|
@ -3096,7 +3086,7 @@ int renumber_cmd(unit * u, order * ord)
|
||||||
cmistake(u, ord, 148, MSG_EVENT);
|
cmistake(u, ord, 148, MSG_EVENT);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
if (*s == 0) {
|
if (*s == 0) {
|
||||||
i = newcontainerid();
|
i = newcontainerid();
|
||||||
}
|
}
|
||||||
|
@ -3397,7 +3387,7 @@ void new_units(void)
|
||||||
init_order(makeord);
|
init_order(makeord);
|
||||||
alias = getid();
|
alias = getid();
|
||||||
|
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
if (s && s[0]) {
|
if (s && s[0]) {
|
||||||
name = _strdup(s);
|
name = _strdup(s);
|
||||||
}
|
}
|
||||||
|
@ -3707,7 +3697,7 @@ void defaultorders(void)
|
||||||
order *new_order = 0;
|
order *new_order = 0;
|
||||||
const char *s;
|
const char *s;
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtok(lbuf, sizeof(lbuf));
|
s = gettoken(lbuf, sizeof(lbuf));
|
||||||
if (s) {
|
if (s) {
|
||||||
new_order = parse_order(s, u->faction->locale);
|
new_order = parse_order(s, u->faction->locale);
|
||||||
}
|
}
|
||||||
|
@ -3823,13 +3813,13 @@ int use_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
|
|
||||||
t = getstrtok(token, sizeof(token));
|
t = gettoken(token, sizeof(token));
|
||||||
n = atoi((const char *)t);
|
n = atoi((const char *)t);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
if (isparam(t, u->faction->locale, P_ANY)) {
|
if (isparam(t, u->faction->locale, P_ANY)) {
|
||||||
/* BENUTZE ALLES Yanxspirit */
|
/* BENUTZE ALLES Yanxspirit */
|
||||||
n = INT_MAX;
|
n = INT_MAX;
|
||||||
t = getstrtok(token, sizeof(token));
|
t = gettoken(token, sizeof(token));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* BENUTZE Yanxspirit */
|
/* BENUTZE Yanxspirit */
|
||||||
|
@ -3838,7 +3828,7 @@ int use_cmd(unit * u, struct order *ord)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* BENUTZE 42 Yanxspirit */
|
/* BENUTZE 42 Yanxspirit */
|
||||||
t = getstrtok(token, sizeof(token));
|
t = gettoken(token, sizeof(token));
|
||||||
}
|
}
|
||||||
itype = t ? finditemtype(t, u->faction->locale) : NULL;
|
itype = t ? finditemtype(t, u->faction->locale) : NULL;
|
||||||
|
|
||||||
|
@ -3920,20 +3910,21 @@ int pay_cmd(unit * u, struct order *ord)
|
||||||
|
|
||||||
static int reserve_i(unit * u, struct order *ord, int flags)
|
static int reserve_i(unit * u, struct order *ord, int flags)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
|
if (u->number > 0 && (urace(u)->ec_flags & GETITEM)) {
|
||||||
int use, count, para;
|
int use, count, para;
|
||||||
const item_type *itype;
|
const item_type *itype;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
count = s ? atoip(s) : 0;
|
count = s ? atoip(s) : 0;
|
||||||
para = findparam(s, u->faction->locale);
|
para = findparam(s, u->faction->locale);
|
||||||
|
|
||||||
if (count == 0 && para == P_EACH) {
|
if (count == 0 && para == P_EACH) {
|
||||||
count = getint() * u->number;
|
count = getint() * u->number;
|
||||||
}
|
}
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
itype = s ? finditemtype(s, u->faction->locale) : 0;
|
||||||
if (itype == NULL)
|
if (itype == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -3963,19 +3954,20 @@ int reserve_self(unit * u, struct order *ord) {
|
||||||
|
|
||||||
int claim_cmd(unit * u, struct order *ord)
|
int claim_cmd(unit * u, struct order *ord)
|
||||||
{
|
{
|
||||||
|
char token[128];
|
||||||
const char *t;
|
const char *t;
|
||||||
int n;
|
int n;
|
||||||
const item_type *itype;
|
const item_type *itype;
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
|
|
||||||
t = getstrtoken();
|
t = gettoken(token, sizeof(token));
|
||||||
n = atoi((const char *)t);
|
n = atoi((const char *)t);
|
||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
n = 1;
|
n = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
t = getstrtoken();
|
t = gettoken(token, sizeof(token));
|
||||||
}
|
}
|
||||||
itype = finditemtype(t, u->faction->locale);
|
itype = finditemtype(t, u->faction->locale);
|
||||||
|
|
||||||
|
|
10
src/magic.c
10
src/magic.c
|
@ -2519,7 +2519,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
||||||
level = eff_skill(u, SK_MAGIC, r);
|
level = eff_skill(u, SK_MAGIC, r);
|
||||||
|
|
||||||
init_order(ord);
|
init_order(ord);
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
param = findparam(s, u->faction->locale);
|
param = findparam(s, u->faction->locale);
|
||||||
/* für Syntax ' STUFE x REGION y z ' */
|
/* für Syntax ' STUFE x REGION y z ' */
|
||||||
if (param == P_LEVEL) {
|
if (param == P_LEVEL) {
|
||||||
|
@ -2530,7 +2530,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
||||||
cmistake(u, ord, 10, MSG_MAGIC);
|
cmistake(u, ord, 10, MSG_MAGIC);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
param = findparam(s, u->faction->locale);
|
param = findparam(s, u->faction->locale);
|
||||||
}
|
}
|
||||||
if (param == P_REGION) {
|
if (param == P_REGION) {
|
||||||
|
@ -2547,7 +2547,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
||||||
"unit region command", u, u->region, ord));
|
"unit region command", u, u->region, ord));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
param = findparam(s, u->faction->locale);
|
param = findparam(s, u->faction->locale);
|
||||||
}
|
}
|
||||||
/* für Syntax ' REGION x y STUFE z '
|
/* für Syntax ' REGION x y STUFE z '
|
||||||
|
@ -2560,7 +2560,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
||||||
cmistake(u, ord, 10, MSG_MAGIC);
|
cmistake(u, ord, 10, MSG_MAGIC);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
s = getstrtok(token, sizeof(token));
|
s = gettoken(token, sizeof(token));
|
||||||
}
|
}
|
||||||
if (!s || !s[0] || strlen(s) == 0) {
|
if (!s || !s[0] || strlen(s) == 0) {
|
||||||
/* Fehler "Es wurde kein Zauber angegeben" */
|
/* Fehler "Es wurde kein Zauber angegeben" */
|
||||||
|
@ -2693,7 +2693,7 @@ static castorder *cast_cmd(unit * u, order * ord)
|
||||||
char **params = (char**)malloc(2 * sizeof(char *));
|
char **params = (char**)malloc(2 * sizeof(char *));
|
||||||
int p = 0, size = 2;
|
int p = 0, size = 2;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
s = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
if (!s || *s == 0)
|
if (!s || *s == 0)
|
||||||
break;
|
break;
|
||||||
if (p + 1 >= size) {
|
if (p + 1 >= size) {
|
||||||
|
|
22
src/move.c
22
src/move.c
|
@ -1156,7 +1156,7 @@ static void cycle_route(order * ord, unit * u, int gereist)
|
||||||
int bytes, cm = 0;
|
int bytes, cm = 0;
|
||||||
char tail[1024], *bufp = tail;
|
char tail[1024], *bufp = tail;
|
||||||
char neworder[2048];
|
char neworder[2048];
|
||||||
const char *token;
|
char token[128];
|
||||||
direction_t d = NODIRECTION;
|
direction_t d = NODIRECTION;
|
||||||
bool paused = false;
|
bool paused = false;
|
||||||
bool pause;
|
bool pause;
|
||||||
|
@ -1171,11 +1171,12 @@ static void cycle_route(order * ord, unit * u, int gereist)
|
||||||
|
|
||||||
neworder[0] = 0;
|
neworder[0] = 0;
|
||||||
for (cm = 0;; ++cm) {
|
for (cm = 0;; ++cm) {
|
||||||
|
const char *s;
|
||||||
const struct locale *lang = u->faction->locale;
|
const struct locale *lang = u->faction->locale;
|
||||||
pause = false;
|
pause = false;
|
||||||
token = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
if (token && *token) {
|
if (s && *s) {
|
||||||
d = get_direction(token, lang);
|
d = get_direction(s, lang);
|
||||||
if (d == D_PAUSE) {
|
if (d == D_PAUSE) {
|
||||||
pause = true;
|
pause = true;
|
||||||
}
|
}
|
||||||
|
@ -1448,11 +1449,12 @@ static void make_route(unit * u, order * ord, region_list ** routep)
|
||||||
region_list **iroute = routep;
|
region_list **iroute = routep;
|
||||||
region *current = u->region;
|
region *current = u->region;
|
||||||
region *next = NULL;
|
region *next = NULL;
|
||||||
const char *token = getstrtoken();
|
char token[128];
|
||||||
int error = movewhere(u, token, current, &next);
|
const char *s = gettoken(token, sizeof(token));
|
||||||
|
int error = movewhere(u, s, current, &next);
|
||||||
|
|
||||||
if (error != E_MOVE_OK) {
|
if (error != E_MOVE_OK) {
|
||||||
message *msg = movement_error(u, token, ord, error);
|
message *msg = movement_error(u, s, ord, error);
|
||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
add_message(&u->faction->msgs, msg);
|
add_message(&u->faction->msgs, msg);
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
|
@ -1471,10 +1473,10 @@ static void make_route(unit * u, order * ord, region_list ** routep)
|
||||||
iroute = &(*iroute)->next;
|
iroute = &(*iroute)->next;
|
||||||
|
|
||||||
current = next;
|
current = next;
|
||||||
token = getstrtoken();
|
s = gettoken(token, sizeof(token));
|
||||||
error = movewhere(u, token, current, &next);
|
error = movewhere(u, s, current, &next);
|
||||||
if (error) {
|
if (error) {
|
||||||
message *msg = movement_error(u, token, ord, error);
|
message *msg = movement_error(u, s, ord, error);
|
||||||
if (msg != NULL) {
|
if (msg != NULL) {
|
||||||
add_message(&u->faction->msgs, msg);
|
add_message(&u->faction->msgs, msg);
|
||||||
msg_release(msg);
|
msg_release(msg);
|
||||||
|
|
|
@ -132,6 +132,9 @@ char *parse_token(const char **str, char *lbuf, size_t len)
|
||||||
}
|
}
|
||||||
eatwhitespace_c(&ctoken);
|
eatwhitespace_c(&ctoken);
|
||||||
if (!*ctoken) {
|
if (!*ctoken) {
|
||||||
|
if (len > 0) {
|
||||||
|
*cursor = 0;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
while (*ctoken && cursor-len < lbuf-1) {
|
while (*ctoken && cursor-len < lbuf-1) {
|
||||||
|
@ -209,7 +212,7 @@ const char *getstrtoken(void)
|
||||||
return parse_token((const char **)&states->current_token, lbuf, MAXTOKENSIZE);
|
return parse_token((const char **)&states->current_token, lbuf, MAXTOKENSIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *getstrtok(char *lbuf, size_t bufsize)
|
const char *gettoken(char *lbuf, size_t bufsize)
|
||||||
{
|
{
|
||||||
return parse_token((const char **)&states->current_token, lbuf, bufsize);
|
return parse_token((const char **)&states->current_token, lbuf, bufsize);
|
||||||
}
|
}
|
||||||
|
@ -217,7 +220,7 @@ const char *getstrtok(char *lbuf, size_t bufsize)
|
||||||
int getid(void)
|
int getid(void)
|
||||||
{
|
{
|
||||||
char token[16];
|
char token[16];
|
||||||
const char *str = getstrtok(token, sizeof(token));
|
const char *str = gettoken(token, sizeof(token));
|
||||||
int i = str ? atoi36(str) : 0;
|
int i = str ? atoi36(str) : 0;
|
||||||
if (i < 0) {
|
if (i < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -22,7 +22,7 @@ extern "C" {
|
||||||
void parser_popstate(void);
|
void parser_popstate(void);
|
||||||
bool parser_end(void);
|
bool parser_end(void);
|
||||||
const char *getstrtoken(void);
|
const char *getstrtoken(void);
|
||||||
const char *getstrtok(char *lbuf, size_t bufsize);
|
const char *gettoken(char *lbuf, size_t bufsize);
|
||||||
int getid(void);
|
int getid(void);
|
||||||
#define getshipid() getid()
|
#define getshipid() getid()
|
||||||
#define getfactionid() getid()
|
#define getfactionid() getid()
|
||||||
|
|
|
@ -3,13 +3,21 @@
|
||||||
|
|
||||||
#include <CuTest.h>
|
#include <CuTest.h>
|
||||||
|
|
||||||
static void test_parser(CuTest *tc) {
|
static void test_gettoken(CuTest *tc) {
|
||||||
|
char token[128];
|
||||||
init_tokens_str("HELP ONE TWO THREE");
|
init_tokens_str("HELP ONE TWO THREE");
|
||||||
|
CuAssertStrEquals(tc, "HELP", gettoken(token, sizeof(token)));
|
||||||
|
CuAssertStrEquals(tc, "HELP", token);
|
||||||
|
CuAssertStrEquals(tc, "ONE", gettoken(token, sizeof(token)));
|
||||||
|
CuAssertStrEquals(tc, "TWO", gettoken(token, sizeof(token)));
|
||||||
|
CuAssertStrEquals(tc, "THREE", gettoken(token, sizeof(token)));
|
||||||
|
CuAssertPtrEquals(tc, NULL, (void *)gettoken(token, sizeof(token)));
|
||||||
|
CuAssertStrEquals(tc, "", token);
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_parser_suite(void)
|
CuSuite *get_parser_suite(void)
|
||||||
{
|
{
|
||||||
CuSuite *suite = CuSuiteNew();
|
CuSuite *suite = CuSuiteNew();
|
||||||
SUITE_ADD_TEST(suite, test_parser);
|
SUITE_ADD_TEST(suite, test_gettoken);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue