From 3c2ae7ca93bcde9a794bb74b515a4e3914455074 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 11 Aug 2014 12:02:16 +0200 Subject: [PATCH] preview script and logging cleanup 1. all log messages will be terminated with \n, whether the user provided it or not. 2. remove a bunch of print() calls from scripts to reduce clutter 3. replace printf calls with log_* calls to reduce clutter 4. add the new release preview script --- s/preview | 58 ++++++++++++++++++++++++ scripts/e3a/build.lua | 1 - scripts/eressea/astral.lua | 2 +- scripts/eressea/e2/init.lua | 2 +- scripts/eressea/e3/init.lua | 3 +- scripts/eressea/e4/init.lua | 3 +- scripts/eressea/init.lua | 4 +- scripts/run-turn.lua | 8 ++-- src/kernel/config.c | 8 ++-- src/kernel/jsonconf.c | 88 ++++++++++++++++++------------------- src/kernel/reports.c | 8 ++-- src/kernel/save.c | 7 +-- src/log.pkg | 2 +- src/log.pkg.c | 4 +- src/summary.c | 5 ++- src/util/log.c | 54 +++++++---------------- src/util/log.h | 1 - 17 files changed, 145 insertions(+), 113 deletions(-) create mode 100755 s/preview diff --git a/s/preview b/s/preview new file mode 100755 index 000000000..9833e3f89 --- /dev/null +++ b/s/preview @@ -0,0 +1,58 @@ +#!/bin/bash + +usage() { + echo "usage: $0 game-id" + exit 1 +} + +abort() { + echo $1 + [ -z $2 ] && exit -1 + exit $2 # otherwise +} + +[ -d $ERESSEA ] || abort "Invalid env variable ERESSEA ($ERESSEA)" + +GAME=$1 +LIVE=$ERESSEA/game-$GAME +SOURCE=$ERESSEA/git +TESTROOT=$LIVE/test +REBUILD=0 + +[ -d $LIVE ] || usage +[ -d $SOURCE ] || abort "missing source directory: $SOURCE" + +[ -f $LIVE/turn ] || abort "missing turn file" +let TURN=$(cat $LIVE/turn)-1 + +if [ $REBUILD ] ; then +cd $SOURCE +git pull || abort "failed to update source. do you have local changes?" +BUILD=$(grep BUILD src/build.h | awk '{ print $3 }') +s/build || abort "build failed." +fi + +echo "testing turn $TURN of game $GAME with build $BUILD" +mkdir -p $TESTROOT +cd $TESTROOT + +if [ ! -e eressea.ini ] ; then +cat >| eressea.ini <_name, locale_name(lang)); + log_error("no translation for terrain %s in locale %s", terrain->_name, locale_name(lang)); } } } @@ -1783,7 +1783,7 @@ void init_options_translation(const struct locale * lang) { addtoken(tokens, name, var); } else { - log_error_n("no translation for OPTION %s in locale %s", options[i], locale_name(lang)); + log_error("no translation for OPTION %s in locale %s", options[i], locale_name(lang)); } } } @@ -1818,7 +1818,7 @@ static void init_locale(const struct locale *lang) addtoken(tokens, name, var); } else { - log_error_n("no translation for magic school %s in locale %s", tok, locale_name(lang)); + log_error("no translation for magic school %s in locale %s", tok, locale_name(lang)); } tok = strtok(NULL, " "); } diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index a0aabc51c..3557992b9 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -89,7 +89,7 @@ static void json_maintenance_i(cJSON *json, maintenance *mt) { mt->number = child->valueint; } else { - log_error_n("maintenance contains unknown attribute %s", child->string); + log_error("maintenance contains unknown attribute %s", child->string); } break; case cJSON_String: @@ -97,7 +97,7 @@ static void json_maintenance_i(cJSON *json, maintenance *mt) { mt->rtype = rt_get_or_create(child->valuestring); } else { - log_error_n("maintenance contains unknown attribute %s", child->string); + log_error("maintenance contains unknown attribute %s", child->string); } break; case cJSON_Array: @@ -106,11 +106,11 @@ static void json_maintenance_i(cJSON *json, maintenance *mt) { mt->flags = json_flags(child, flags); } else { - log_error_n("maintenance contains unknown array %s", child->string); + log_error("maintenance contains unknown array %s", child->string); } break; default: - log_error_n("maintenance contains unknown attribute %s", child->string); + log_error("maintenance contains unknown attribute %s", child->string); } } } @@ -124,7 +124,7 @@ static void json_maintenance(cJSON *json, maintenance **mtp) { size = cJSON_GetArraySize(json); } else if (json->type != cJSON_Object) { - log_error_n("maintenance is not a json object or array (%d)", json->type); + log_error("maintenance is not a json object or array (%d)", json->type); return; } *mtp = mt = (struct maintenance *) calloc(sizeof(struct maintenance), size + 1); @@ -155,7 +155,7 @@ static void json_construction(cJSON *json, construction **consp) { return; } if (json->type != cJSON_Object) { - log_error_n("building %s is not a json object: %d", json->string, json->type); + log_error("building %s is not a json object: %d", json->string, json->type); return; } construction * cons = (construction *)calloc(sizeof(construction), 1); @@ -178,7 +178,7 @@ static void json_construction(cJSON *json, construction **consp) { } break; default: - log_error_n("building %s contains unknown attribute %s", json->string, child->string); + log_error("building %s contains unknown attribute %s", json->string, child->string); } } *consp = cons; @@ -187,7 +187,7 @@ static void json_construction(cJSON *json, construction **consp) { static void json_terrain(cJSON *json, terrain_type *ter) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("terrain %s is not a json object: %d", json->string, json->type); + log_error("terrain %s is not a json object: %d", json->string, json->type); return; } for (child=json->child;child;child=child->next) { @@ -199,11 +199,11 @@ static void json_terrain(cJSON *json, terrain_type *ter) { }; ter->flags = json_flags(child, flags); } else { - log_error_n("terrain %s contains unknown attribute %s", json->string, child->string); + log_error("terrain %s contains unknown attribute %s", json->string, child->string); } break; default: - log_error_n("terrain %s contains unknown attribute %s", json->string, child->string); + log_error("terrain %s contains unknown attribute %s", json->string, child->string); } } } @@ -214,7 +214,7 @@ static void json_building(cJSON *json, building_type *bt) { "nodestroy", "nobuild", "unique", "decay", "dynamic", "magic", "oneperturn", "namechange", 0 }; if (json->type != cJSON_Object) { - log_error_n("building %s is not a json object: %d", json->string, json->type); + log_error("building %s is not a json object: %d", json->string, json->type); return; } for (child=json->child;child;child=child->next) { @@ -244,10 +244,10 @@ static void json_building(cJSON *json, building_type *bt) { const struct building *, int))get_function(child->valuestring); break; } - log_error_n("building %s contains unknown attribute %s", json->string, child->string); + log_error("building %s contains unknown attribute %s", json->string, child->string); break; default: - log_error_n("building %s contains unknown attribute %s", json->string, child->string); + log_error("building %s contains unknown attribute %s", json->string, child->string); } } } @@ -258,7 +258,7 @@ static void json_item(cJSON *json, item_type *itype) { "herb", "cursed", "nodrop", "big", "animal", "vehicle", 0 }; if (json->type!=cJSON_Object) { - log_error_n("ship %s is not a json object: %d", json->string, json->type); + log_error("ship %s is not a json object: %d", json->string, json->type); return; } for (child=json->child;child;child=child->next) { @@ -272,17 +272,17 @@ static void json_item(cJSON *json, item_type *itype) { itype->capacity = child->valueint; break; } - log_error_n("item %s contains unknown attribute %s", json->string, child->string); + log_error("item %s contains unknown attribute %s", json->string, child->string); break; case cJSON_Array: if (strcmp(child->string, "flags")==0) { itype->flags = json_flags(child, flags); break; } - log_error_n("item %s contains unknown attribute %s", json->string, child->string); + log_error("item %s contains unknown attribute %s", json->string, child->string); case cJSON_Object: default: - log_error_n("item %s contains unknown attribute %s", json->string, child->string); + log_error("item %s contains unknown attribute %s", json->string, child->string); } } } @@ -290,7 +290,7 @@ static void json_item(cJSON *json, item_type *itype) { static void json_ship(cJSON *json, ship_type *st) { cJSON *child, *iter; if (json->type!=cJSON_Object) { - log_error_n("ship %s is not a json object: %d", json->string, json->type); + log_error("ship %s is not a json object: %d", json->string, json->type); return; } for (child=json->child;child;child=child->next) { @@ -300,7 +300,7 @@ static void json_ship(cJSON *json, ship_type *st) { if (strcmp(child->string, "construction")==0) { json_construction(child, &st->construction); } else { - log_error_n("ship %s contains unknown attribute %s", json->string, child->string); + log_error("ship %s contains unknown attribute %s", json->string, child->string); } break; case cJSON_Array: @@ -320,11 +320,11 @@ static void json_ship(cJSON *json, ship_type *st) { if (strcmp(child->string, "range")==0) { st->range = child->valueint; } else { - log_error_n("ship %s contains unknown attribute %s", json->string, child->string); + log_error("ship %s contains unknown attribute %s", json->string, child->string); } break; default: - log_error_n("ship %s contains unknown attribute %s", json->string, child->string); + log_error("ship %s contains unknown attribute %s", json->string, child->string); } } } @@ -345,7 +345,7 @@ static void json_race(cJSON *json, race *rc) { "giveunit", "getitem", 0 }; if (json->type != cJSON_Object) { - log_error_n("race %s is not a json object: %d", json->string, json->type); + log_error("race %s is not a json object: %d", json->string, json->type); return; } for (child=json->child;child;child=child->next) { @@ -401,7 +401,7 @@ static void json_race(cJSON *json, race *rc) { static void json_terrains(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("terrains is not a json object: %d", json->type); + log_error("terrains is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -412,7 +412,7 @@ static void json_terrains(cJSON *json) { static void json_buildings(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("buildings is not a json object: %d", json->type); + log_error("buildings is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -423,7 +423,7 @@ static void json_buildings(cJSON *json) { static void json_spells(cJSON *json) { cJSON *child; if (json->type != cJSON_Object) { - log_error_n("spells is not a json object: %d", json->type); + log_error("spells is not a json object: %d", json->type); return; } for (child = json->child; child; child = child->next) { @@ -452,7 +452,7 @@ static void json_spells(cJSON *json) { static void json_items(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("items is not a json object: %d", json->type); + log_error("items is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -468,7 +468,7 @@ static void json_items(cJSON *json) { static void json_ships(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("ships is not a json object: %d", json->type); + log_error("ships is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -479,7 +479,7 @@ static void json_ships(cJSON *json) { static void json_locale(cJSON *json, struct locale *lang) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("strings is not a json object: %d", json->type); + log_error("strings is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -492,7 +492,7 @@ static void json_locale(cJSON *json, struct locale *lang) { static void json_strings(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("strings is not a json object: %d", json->type); + log_error("strings is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -500,7 +500,7 @@ static void json_strings(cJSON *json) { struct locale *lang = get_or_create_locale(child->string); json_locale(child, lang); } else { - log_error_n("strings for locale `%s` are not a json object: %d", child->string, child->type); + log_error("strings for locale `%s` are not a json object: %d", child->string, child->type); } } } @@ -508,7 +508,7 @@ static void json_strings(cJSON *json) { static void json_direction(cJSON *json, struct locale *lang) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("directions for locale `%s` not a json object: %d", locale_name(lang), json->type); + log_error("directions for locale `%s` not a json object: %d", locale_name(lang), json->type); return; } for (child=json->child;child;child=child->next) { @@ -523,7 +523,7 @@ static void json_direction(cJSON *json, struct locale *lang) { init_direction(lang, dir, entry->valuestring); } } else { - log_error_n("invalid type %d for direction `%s`", child->type, child->string); + log_error("invalid type %d for direction `%s`", child->type, child->string); } } } @@ -532,7 +532,7 @@ static void json_direction(cJSON *json, struct locale *lang) { static void json_directions(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("directions is not a json object: %d", json->type); + log_error("directions is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -544,7 +544,7 @@ static void json_directions(cJSON *json) { static void json_skill(cJSON *json, struct locale *lang) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("skill for locale `%s` not a json object: %d", locale_name(lang), json->type); + log_error("skill for locale `%s` not a json object: %d", locale_name(lang), json->type); return; } for (child=json->child;child;child=child->next) { @@ -563,10 +563,10 @@ static void json_skill(cJSON *json, struct locale *lang) { } } } else { - log_error_n("invalid type %d for skill `%s`", child->type, child->string); + log_error("invalid type %d for skill `%s`", child->type, child->string); } } else { - log_error_n("unknown skill `%s` for locale `%s`", child->string, locale_name(lang)); + log_error("unknown skill `%s` for locale `%s`", child->string, locale_name(lang)); } } } @@ -574,7 +574,7 @@ static void json_skill(cJSON *json, struct locale *lang) { static void json_keyword(cJSON *json, struct locale *lang) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("keywords for locale `%s` not a json object: %d", locale_name(lang), json->type); + log_error("keywords for locale `%s` not a json object: %d", locale_name(lang), json->type); return; } for (child=json->child;child;child=child->next) { @@ -593,10 +593,10 @@ static void json_keyword(cJSON *json, struct locale *lang) { } } } else { - log_error_n("invalid type %d for keyword `%s`", child->type, child->string); + log_error("invalid type %d for keyword `%s`", child->type, child->string); } } else { - log_error_n("unknown keyword `%s` for locale `%s`", child->string, locale_name(lang)); + log_error("unknown keyword `%s` for locale `%s`", child->string, locale_name(lang)); } } } @@ -604,7 +604,7 @@ static void json_keyword(cJSON *json, struct locale *lang) { static void json_skills(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("skills is not a json object: %d", json->type); + log_error("skills is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -616,7 +616,7 @@ static void json_skills(cJSON *json) { static void json_keywords(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("keywords is not a json object: %d", json->type); + log_error("keywords is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -628,7 +628,7 @@ static void json_keywords(cJSON *json) { static void json_races(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("races is not a json object: %d", json->type); + log_error("races is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -639,7 +639,7 @@ static void json_races(cJSON *json) { void json_config(cJSON *json) { cJSON *child; if (json->type!=cJSON_Object) { - log_error_n("config is not a json object: %d", json->type); + log_error("config is not a json object: %d", json->type); return; } for (child=json->child;child;child=child->next) { @@ -673,7 +673,7 @@ void json_config(cJSON *json) { else if (strcmp(child->string, "terrains") == 0) { json_terrains(child); } else { - log_error_n("config contains unknown attribute %s", child->string); + log_error("config contains unknown attribute %s", child->string); } } init_locales(); diff --git a/src/kernel/reports.c b/src/kernel/reports.c index ad74ab13c..d9a5d0a41 100644 --- a/src/kernel/reports.c +++ b/src/kernel/reports.c @@ -1618,19 +1618,17 @@ int write_reports(faction * f, time_t ltime) if (errno) { char zText[64]; - puts(" ERROR"); - sprintf(zText, "Waiting %u seconds before we retry", backup/1000); + log_warning("retrying, error %d during reports for faction %s", errno, factionname(f)); + sprintf(zText, "waiting %u seconds before we retry", backup/1000); perror(zText); _sleep(backup); if (backup < maxbackup) { backup *= 2; } - } else if (verbosity >= 2) { - puts(" DONE"); } } while (errno); if (!gotit) { - log_warning("No report for faction %s!\n", factionid(f)); + log_warning("No report for faction %s!", factionid(f)); } ql_free(ctx.addresses); seen_done(ctx.seen); diff --git a/src/kernel/save.c b/src/kernel/save.c index d34c0a2bc..50df65f23 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -263,8 +263,7 @@ int readorders(const char *filename) perror(filename); return -1; } - if (verbosity >= 1) - puts(" - lese Befehlsdatei...\n"); + log_info("reading orders from %s", filename); /* TODO: recognize UTF8 BOM */ b = getbuf(F, enc_gamedata); @@ -333,9 +332,7 @@ int readorders(const char *filename) } fclose(F); - if (verbosity >= 1) - puts("\n"); - log_printf(stdout, " %d Befehlsdateien gelesen\n", nfactions); + log_info("done reading orders for %d factions", nfactions); return 0; } diff --git a/src/log.pkg b/src/log.pkg index c198aed03..447de4fca 100644 --- a/src/log.pkg +++ b/src/log.pkg @@ -2,7 +2,7 @@ $#include module eressea { module log { - void log_error_n @ error(const char *message); + void log_error @ error(const char *message); void log_debug @ debug(const char *message); void log_warning @ warning(const char *message); void log_info @ info(const char *message); diff --git a/src/log.pkg.c b/src/log.pkg.c index 22b2f20e1..c1620f8cd 100644 --- a/src/log.pkg.c +++ b/src/log.pkg.c @@ -25,7 +25,7 @@ static void tolua_reg_types (lua_State* tolua_S) { } -/* function: log_error_n */ +/* function: log_error */ static int tolua_log_eressea_log_error00(lua_State* tolua_S) { #ifndef TOLUA_RELEASE @@ -40,7 +40,7 @@ static int tolua_log_eressea_log_error00(lua_State* tolua_S) { const char* message = ((const char*) tolua_tostring(tolua_S,1,0)); { - log_error_n(message); + log_error(message); } } return 0; diff --git a/src/summary.c b/src/summary.c index 5eafa47ab..aeb313f6a 100644 --- a/src/summary.c +++ b/src/summary.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -160,7 +161,7 @@ void report_summary(summary * s, summary * o, bool full) fwrite(utf8_bom, 1, 3, F); } #endif - printf("Schreibe Zusammenfassung (parteien)...\n"); + log_info("writing summary to file: parteien.\n"); fprintf(F, "%s\n%s\n\n", game_name(), gamedate2(default_locale)); fprintf(F, "Auswertung Nr: %d\n\n", turn); fprintf(F, "Parteien: %s\n", pcomp(s->factions, o->factions)); @@ -303,7 +304,7 @@ void report_summary(summary * s, summary * o, bool full) fclose(F); if (full) { - printf("writing date & turn\n"); + log_info("writing date & turn\n"); writeturn(); } free(nmrs); diff --git a/src/util/log.c b/src/util/log.c index 8ef390242..4b3e358dd 100644 --- a/src/util/log.c +++ b/src/util/log.c @@ -169,6 +169,14 @@ static void _log_write(FILE * stream, int codepage, const char * prefix, const c } } +static void _log_writeln(FILE * stream, int codepage, const char * prefix, const char *format, va_list args) +{ + size_t len = strlen(format); + _log_write(stream, codepage, prefix, format, args); + if (format[len-1]!='\n') { + fputc('\n', stream); + } +} void log_debug(const char *format, ...) { const char * prefix = "DEBUG"; @@ -178,7 +186,7 @@ void log_debug(const char *format, ...) if (logfile && (log_flags & mask)) { va_list args; va_start(args, format); - _log_write(logfile, 0, prefix, format, args); + _log_writeln(logfile, 0, prefix, format, args); va_end(args); } @@ -188,7 +196,7 @@ void log_debug(const char *format, ...) if (!dupe) { va_list args; va_start(args, format); - _log_write(stderr, stdio_codepage, prefix, format, args); + _log_writeln(stderr, stdio_codepage, prefix, format, args); va_end(args); } } @@ -206,7 +214,7 @@ void log_warning(const char *format, ...) if (logfile && (log_flags & mask)) { va_list args; va_start(args, format); - _log_write(logfile, 0, prefix, format, args); + _log_writeln(logfile, 0, prefix, format, args); va_end(args); } @@ -216,37 +224,7 @@ void log_warning(const char *format, ...) if (!dupe) { va_list args; va_start(args, format); - _log_write(stderr, stdio_codepage, prefix, format, args); - va_end(args); - } - } - if (log_flags & LOG_FLUSH) { - log_flush(); - } -} - -void log_error_n(const char *format, ...) -{ - const char * prefix = "ERROR"; - const int mask = LOG_CPERROR; - - /* write to the logfile, always */ - if (logfile && (log_flags & mask)) { - va_list args; - va_start(args, format); - _log_write(logfile, 0, prefix, format, args); - fputc('\n', logfile); - va_end(args); - } - - /* write to stderr, if that's not the logfile already */ - if (logfile!=stderr && (log_stderr & mask)) { - int dupe = check_dupe(format, prefix); - if (!dupe) { - va_list args; - va_start(args, format); - _log_write(stderr, stdio_codepage, prefix, format, args); - fputc('\n', stderr); + _log_writeln(stderr, stdio_codepage, prefix, format, args); va_end(args); } } @@ -264,7 +242,7 @@ void log_error(const char *format, ...) if (logfile && (log_flags & mask)) { va_list args; va_start(args, format); - _log_write(logfile, 0, prefix, format, args); + _log_writeln(logfile, 0, prefix, format, args); va_end(args); } @@ -274,7 +252,7 @@ void log_error(const char *format, ...) if (!dupe) { va_list args; va_start(args, format); - _log_write(stderr, stdio_codepage, prefix, format, args); + _log_writeln(stderr, stdio_codepage, prefix, format, args); va_end(args); } } @@ -292,7 +270,7 @@ void log_info(const char *format, ...) if (logfile && (log_flags & mask)) { va_list args; va_start(args, format); - _log_write(logfile, 0, prefix, format, args); + _log_writeln(logfile, 0, prefix, format, args); va_end(args); } @@ -302,7 +280,7 @@ void log_info(const char *format, ...) if (!dupe) { va_list args; va_start(args, format); - _log_write(stderr, stdio_codepage, prefix, format, args); + _log_writeln(stderr, stdio_codepage, prefix, format, args); va_end(args); } } diff --git a/src/util/log.h b/src/util/log.h index 0ee5f970b..41849e533 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -22,7 +22,6 @@ extern "C" { /* use macros above instead of these: */ extern void log_warning(const char *format, ...); extern void log_error(const char *format, ...); - extern void log_error_n(const char *format, ...); extern void log_debug(const char *format, ...); extern void log_info(const char *format, ...); extern void log_printf(FILE * ios, const char *format, ...);