From f6e976296e529e4e2aeb255cccee0ba53e69dbba Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Sep 2014 09:56:15 +0200 Subject: [PATCH 1/3] change to the right directory before running previews. --- s/cron/previews.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/s/cron/previews.sh b/s/cron/previews.sh index 91f0444fd..0d74640c6 100644 --- a/s/cron/previews.sh +++ b/s/cron/previews.sh @@ -1,5 +1,6 @@ -#!/bin/bash +#!/bin/sh +cd $ERESSEA/git s/preview build s/preview version for game in 2 3 4 ; do From c5be92a7fcffcba4860999542131b9ffd2cecb98 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Sep 2014 10:03:48 +0200 Subject: [PATCH 2/3] fix preview scripts to auto-checkout master --- s/cron/previews.sh | 12 ++++++------ s/preview | 8 ++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/s/cron/previews.sh b/s/cron/previews.sh index 0d74640c6..7c9f8bb95 100644 --- a/s/cron/previews.sh +++ b/s/cron/previews.sh @@ -1,9 +1,9 @@ #!/bin/sh - -cd $ERESSEA/git -s/preview build -s/preview version +[ -z $ERESSEA ] && ERESSEA=$HOME/eressea +SRC=$ERESSEA/git +$SRC/s/preview build master +$SRC/s/preview version for game in 2 3 4 ; do - s/preview -g $game run && \ - s/preview -g $game send + $SRC/s/preview -g $game run && \ + $SRC/s/preview -g $game send done diff --git a/s/preview b/s/preview index a8893cc11..b22b34e76 100755 --- a/s/preview +++ b/s/preview @@ -23,6 +23,7 @@ function build() { assert_dir $SOURCE cd $SOURCE git pull || abort "failed to update source. do you have local changes?" +[ -z $1 ] || git checkout $1 s/build || abort "build failed." } @@ -87,7 +88,9 @@ zip="$turn-$1.zip" zip -q -u $zip $turn-$1.?r email=$(grep "faction=$1:" reports.txt | cut -d: -f2 | sed 's/email=//') echo "sending reports to $1 / $email" -cat /dev/null | mutt -F $ERESSEA/etc/muttrc -s "Testauswertung Spiel $game Partei $1" -a $zip -- $email +info=/dev/null +[ -e ../email.txt ] && info=../email.txt +cat $info | mutt -F $ERESSEA/etc/muttrc -s "Testauswertung Spiel $game Partei $1" -a $zip -- $email } game=0 @@ -128,7 +131,8 @@ case "$1" in version ;; "build") - build + shift + build $* ;; "setup") setup From b4f6e3c21d933176ead6db7d4434e71150bc006e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 21 Sep 2014 16:43:17 +0200 Subject: [PATCH 3/3] fix remaining getstrtoken uses without null-check. Conflicts: src/economy.c src/items.c src/kernel/config.c src/laws.c --- s/preview | 2 +- src/economy.c | 8 +++-- src/items.c | 73 +++++++++++++++++++++++------------------- src/kernel/build.c | 78 +++++++++++++++++++++++---------------------- src/kernel/config.c | 6 ++-- src/laws.c | 3 +- src/study.c | 3 +- 7 files changed, 96 insertions(+), 77 deletions(-) diff --git a/s/preview b/s/preview index b22b34e76..ff3a7c1ee 100755 --- a/s/preview +++ b/s/preview @@ -22,8 +22,8 @@ exit $2 # otherwise function build() { assert_dir $SOURCE cd $SOURCE -git pull || abort "failed to update source. do you have local changes?" [ -z $1 ] || git checkout $1 +git pull || abort "failed to update source. do you have local changes?" s/build || abort "build failed." } diff --git a/src/economy.c b/src/economy.c index 86fb14a3d..9899b8c58 100644 --- a/src/economy.c +++ b/src/economy.c @@ -1823,7 +1823,8 @@ int make_cmd(unit * u, struct order *ord) cmistake(u, ord, 275, MSG_PRODUCE); } else { - direction_t d = get_direction(getstrtoken(), u->faction->locale); + const char * s = getstrtoken(); + direction_t d = s ? get_direction(s, u->faction->locale) : NODIRECTION; if (d != NODIRECTION) { build_road(r, u, m, d); } @@ -2060,6 +2061,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord) attrib *a; const item_type *itype = NULL; const luxury_type *ltype = NULL; + const char *s; + if (u->ship && is_guarded(r, u, GUARD_CREWS)) { cmistake(u, ord, 69, MSG_INCOME); return; @@ -2134,7 +2137,8 @@ static void buy(unit * u, request ** buyorders, struct order *ord) /* die Menge der verkauften Güter merken */ a->data.i += n; - itype = finditemtype(getstrtoken(), u->faction->locale); + s = getstrtoken(); + itype = s ? finditemtype(s, u->faction->locale) : 0; if (itype != NULL) { ltype = resource2luxury(itype->rtype); if (ltype == NULL) { diff --git a/src/items.c b/src/items.c index 2a4c81568..8292c4ebe 100644 --- a/src/items.c +++ b/src/items.c @@ -32,39 +32,48 @@ #define MAXGAIN 15 static int use_studypotion(struct unit *u, const struct item_type *itype, int amount, - struct order *ord) -{ - if (getkeyword(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) { - /* TODO: message */ - } 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; - if (amount > MAXGAIN) - amount = MAXGAIN; - teach->value += amount * 30; - if (teach->value > MAXGAIN * 30) { - teach->value = MAXGAIN * 30; - } - i_change(&u->items, itype, -amount); - return 0; + struct order *ord) +{ + if (getkeyword(u->thisorder) == K_STUDY) { + skill_t sk = NOSKILL; + skill *sv = 0; + const char * s = getstrtoken(); + attrib *a; + teaching_info *teach; + + init_tokens(u->thisorder); + skip_token(); + if (s) { + sk = get_skill(s, u->faction->locale); + sv = unit_skill(u, sk); + } + if (sv) { + if (sv->level > 2) { + /* TODO: message */ + return EUNUSABLE; + } else if (study_cost(u, sk) > 0) { + /* TODO: message */ + return EUNUSABLE; + } + } + + a = a_find(u->attribs, &at_learning); + if (a == NULL) { + a = a_add(&u->attribs, a_new(&at_learning)); + } + + teach = (teaching_info *) a->data.v; + if (amount > MAXGAIN) { + amount = MAXGAIN; + } + teach->value += amount * 30; + if (teach->value > MAXGAIN * 30) { + teach->value = MAXGAIN * 30; + } + i_change(&u->items, itype, -amount); + return 0; } - } - return EUNUSABLE; + return EUNUSABLE; } /* END studypotion */ diff --git a/src/kernel/build.c b/src/kernel/build.c index 0763cbe16..575500b3d 100644 --- a/src/kernel/build.c +++ b/src/kernel/build.c @@ -90,47 +90,49 @@ ship *getship(const struct region * r) static void destroy_road(unit * u, int nmax, struct order *ord) { - direction_t d = get_direction(getstrtoken(), u->faction->locale); - unit *u2; - region *r = u->region; - short n = (short)nmax; + const char *s = getstrtoken(); + direction_t d = s ? get_direction(s, u->faction->locale) : NODIRECTION; + if (d == NODIRECTION) { + /* Die Richtung wurde nicht erkannt */ + cmistake(u, ord, 71, MSG_PRODUCE); + } else { + unit *u2; + region *r = u->region; + short road, n = (short)nmax; + + if (nmax > SHRT_MAX) { + n = SHRT_MAX; + } else if (nmax < 0) { + n = 0; + } - if (nmax > SHRT_MAX) - n = SHRT_MAX; - else if (nmax < 0) - n = 0; + for (u2 = r->units; u2; u2 = u2->next) { + if (u2->faction != u->faction && is_guard(u2, GUARD_TAX) + && cansee(u2->faction, u->region, u, 0) + && !alliedunit(u, u2->faction, HELP_GUARD)) { + cmistake(u, ord, 70, MSG_EVENT); + return; + } + } - for (u2 = r->units; u2; u2 = u2->next) { - if (u2->faction != u->faction && is_guard(u2, GUARD_TAX) - && cansee(u2->faction, u->region, u, 0) - && !alliedunit(u, u2->faction, HELP_GUARD)) { - cmistake(u, ord, 70, MSG_EVENT); - return; + road = rroad(r, d); + n = _min(n, road); + if (n != 0) { + region *r2 = rconnect(r, d); + int willdo = eff_skill(u, SK_ROAD_BUILDING, r) * u->number; + willdo = _min(willdo, n); + if (willdo == 0) { + /* TODO: error message */ + } + if (willdo > SHRT_MAX) + road = 0; + else + road = road - (short)willdo; + rsetroad(r, d, road); + ADDMSG(&u->faction->msgs, msg_message("destroy_road", + "unit from to", u, r, r2)); + } } - } - - if (d == NODIRECTION) { - /* Die Richtung wurde nicht erkannt */ - cmistake(u, ord, 71, MSG_PRODUCE); - } else { - short road = rroad(r, d); - n = _min(n, road); - if (n != 0) { - region *r2 = rconnect(r, d); - int willdo = eff_skill(u, SK_ROAD_BUILDING, r) * u->number; - willdo = _min(willdo, n); - if (willdo == 0) { - /* TODO: error message */ - } - if (willdo > SHRT_MAX) - road = 0; - else - road = road - (short)willdo; - rsetroad(r, d, road); - ADDMSG(&u->faction->msgs, msg_message("destroy_road", - "unit from to", u, r, r2)); - } - } } int destroy_cmd(unit * u, struct order *ord) diff --git a/src/kernel/config.c b/src/kernel/config.c index 5fe492633..435c78dca 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -1142,7 +1142,8 @@ unsigned int getuint(void) int getint(void) { - return atoi((const char *)getstrtoken()); + const char * s = getstrtoken(); + return s ? atoi(s) : 0; } const struct race *findrace(const char *s, const struct locale *lang) @@ -1213,7 +1214,8 @@ bool isparam(const char *s, const struct locale * lang, param_t param) param_t getparam(const struct locale * lang) { - return findparam(getstrtoken(), lang); + const char *s = getstrtoken(); + return s ? findparam(s, lang) : NOPARAM; } faction *findfaction(int n) diff --git a/src/laws.c b/src/laws.c index 34f8ca08b..27c28a67e 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2359,9 +2359,10 @@ int banner_cmd(unit * u, struct order *ord) { init_tokens(ord); skip_token(); + const char * s = getstrtoken(); free(u->faction->banner); - u->faction->banner = _strdup(getstrtoken()); + u->faction->banner = s ? _strdup(s) : 0; add_message(&u->faction->msgs, msg_message("changebanner", "value", u->faction->banner)); diff --git a/src/study.c b/src/study.c index 28fe9f9e3..ecff06624 100644 --- a/src/study.c +++ b/src/study.c @@ -59,7 +59,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. static skill_t getskill(const struct locale *lang) { - return get_skill(getstrtoken(), lang); + const char * s = getstrtoken(); + return s ? get_skill(s, lang) : NOSKILL; } magic_t getmagicskill(const struct locale * lang)