diff --git a/src/buildno.h b/src/buildno.h deleted file mode 100644 index 72049c497..000000000 --- a/src/buildno.h +++ /dev/null @@ -1,3 +0,0 @@ -#define VERSION_MAJOR 3 -#define VERSION_MINOR 10 -#define VERSION_BUILD 0 diff --git a/src/creport.c b/src/creport.c index 39ecd9c2b..f2a29bb73 100644 --- a/src/creport.c +++ b/src/creport.c @@ -9,6 +9,7 @@ without prior permission by the authors of Eressea. #include #include +#include #include "buildno.h" #include "creport.h" #include "seen.h" @@ -1515,7 +1516,7 @@ report_computer(const char *filename, report_context * ctx, const char *charset) fprintf(F, "%d;Basis\n", 36); fprintf(F, "%d;Runde\n", turn); fprintf(F, "%d;Zeitalter\n", era); - fprintf(F, "\"%d.%d.%d\";Build\n", VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); + fprintf(F, "\"%s\";Build\n", ERESSEA_VERSION); if (mailto != NULL) { fprintf(F, "\"%s\";mailto\n", mailto); fprintf(F, "\"%s\";mailcmd\n", LOC(f->locale, "mailcmd")); diff --git a/src/kernel/save.c b/src/kernel/save.c index c0549ecdf..1abe684e5 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -18,6 +18,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include "save.h" #include @@ -1859,6 +1860,12 @@ static void clear_npc_orders(faction *f) } } +int version_no(const char *str) { + int maj = 0, min = 0, bld = 0; + sscanf(str, "%d.%d.%d", &maj, &min, &bld); + return (maj << 16) | (min << 8) | bld; +} + int writegame(const char *filename) { int n; @@ -1889,7 +1896,7 @@ int writegame(const char *filename) fstream_init(&strm, F); binstore_init(&store, &strm); - WRITE_INT(&store, VERSION_BUILD); + WRITE_INT(&store, version_no(ERESSEA_VERSION)); n = write_game(&gdata); binstore_done(&store); fstream_done(&strm); diff --git a/src/kernel/save.h b/src/kernel/save.h index 3cd443926..27dd56661 100644 --- a/src/kernel/save.h +++ b/src/kernel/save.h @@ -79,6 +79,7 @@ extern "C" { int write_game(struct gamedata *data); int read_game(struct gamedata *data); + int version_no(const char *str); /* test-only functions that give access to internal implementation details (BAD) */ void _test_write_password(struct gamedata *data, const struct faction *f); diff --git a/src/kernel/save.test.c b/src/kernel/save.test.c index ac356e89b..213543b77 100644 --- a/src/kernel/save.test.c +++ b/src/kernel/save.test.c @@ -312,6 +312,12 @@ static void test_read_password_external(CuTest *tc) { test_cleanup(); } +static void test_version_no(CuTest *tc) { + CuAssertIntEquals(tc, 0, version_no("0.0.0-devel")); + CuAssertIntEquals(tc, 0x10000, version_no("1.0.0-test")); + CuAssertIntEquals(tc, 0x10203, version_no("1.2.3-what.is.42")); +} + CuSuite *get_save_suite(void) { CuSuite *suite = CuSuiteNew(); @@ -324,5 +330,7 @@ CuSuite *get_save_suite(void) SUITE_ADD_TEST(suite, test_readwrite_dead_faction_group); SUITE_ADD_TEST(suite, test_read_password); SUITE_ADD_TEST(suite, test_read_password_external); + SUITE_ADD_TEST(suite, test_version_no); + return suite; } diff --git a/src/kernel/version.h b/src/kernel/version.h index 79251ab99..5b3bf0cf6 100644 --- a/src/kernel/version.h +++ b/src/kernel/version.h @@ -8,5 +8,9 @@ This program may not be used, modified or distributed without prior permission by the authors of Eressea. - */ + +#ifndef ERESSEA_VERSION +// the version number, if it was not passed to make with -D +#define ERESSEA_VERSION "3.10.0-devel" +#endif diff --git a/src/main.c b/src/main.c index 5aa5d7727..418e27f30 100644 --- a/src/main.c +++ b/src/main.c @@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include #include #include #include @@ -165,8 +166,8 @@ static int parse_args(int argc, char **argv, int *exitcode) if (strcmp(argi + 2, "version") == 0) { printf("\n%s PBEM host\n" "Copyright (C) 1996-2005 C. Schlittchen, K. Zedel, E. Rehling, H. Peters.\n\n" - "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %d.%d.%d\n\n", - game_name(), VERSION_MAJOR, VERSION_MINOR, VERSION_BUILD); + "Compilation: " __DATE__ " at " __TIME__ "\nVersion: %s\n\n", + game_name(), ERESSEA_VERSION); #ifdef USE_CURSES } else if (strcmp(argi + 2, "color") == 0) {