From: Holger Schemel Date: Thu, 28 Aug 2014 09:24:37 +0000 (+0200) Subject: rnd-20140828-1-src X-Git-Tag: 4.0.0.0-rc1~358 X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=commitdiff_plain;h=7b447f4c902beff72ad385a99cd723eb7d1ea369 rnd-20140828-1-src * added command line options "--version" / "-V" to show program version (also shows SDL library versions when prefixed with "--debug" option) --- diff --git a/ChangeLog b/ChangeLog index b58b9423..515f53bb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2014-08-28 + * added command line options "--version" / "-V" to show program version + (also shows SDL library versions when prefixed with "--debug" option) + 2014-08-27 * error file set to unbuffered to prevent truncation in case of crashes diff --git a/src/conftime.h b/src/conftime.h index 9a502daa..3affe7c9 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2014-08-27 13:39" +#define COMPILE_DATE_STRING "2014-08-28 11:08" diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 39a55435..dbcd7fdb 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -765,7 +765,9 @@ boolean strSuffixLower(char *s, char *suffix) /* command line option handling functions */ /* ------------------------------------------------------------------------- */ -void GetOptions(char *argv[], void (*print_usage_function)(void)) +void GetOptions(char *argv[], + void (*print_usage_function)(void), + void (*print_version_function)(void)) { char *ro_base_path = RO_BASE_PATH; char *rw_base_path = RW_BASE_PATH; @@ -862,13 +864,22 @@ void GetOptions(char *argv[], void (*print_usage_function)(void)) option_len = strlen(option); if (strEqual(option, "-")) + { Error(ERR_EXIT_HELP, "unrecognized option '%s'", option); + } else if (strncmp(option, "-help", option_len) == 0) { print_usage_function(); exit(0); } + else if (strncmp(option, "-version", option_len) == 0 || + strncmp(option, "-V", option_len) == 0) + { + print_version_function(); + + exit(0); + } else if (strncmp(option, "-display", option_len) == 0) { if (option_arg == NULL) diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 98cc3fe1..b2b0c0cf 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -166,7 +166,9 @@ boolean strSuffix(char *, char *); boolean strPrefixLower(char *, char *); boolean strSuffixLower(char *, char *); -void GetOptions(char **, void (*print_usage_function)(void)); +void GetOptions(char **, + void (*print_usage_function)(void), + void (*print_version_function)(void)); void SetError(char *, ...); char *GetError(void); diff --git a/src/libgame/system.c b/src/libgame/system.c index 3f466bcc..f8a60680 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -93,6 +93,8 @@ void InitProgramInfo(char *argv0, program.version_major = VERSION_MAJOR(program_version); program.version_minor = VERSION_MINOR(program_version); program.version_patch = VERSION_PATCH(program_version); + program.version_build = VERSION_BUILD(program_version); + program.version_ident = program_version; program.error_filename = getErrorFilename(ERROR_BASENAME); program.error_file = stderr; diff --git a/src/libgame/system.h b/src/libgame/system.h index af8772b1..e9b4cb51 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -679,6 +679,8 @@ struct ProgramInfo int version_major; int version_minor; int version_patch; + int version_build; + int version_ident; char *(*window_title_function)(void); void (*exit_message_function)(char *, va_list); diff --git a/src/main.c b/src/main.c index ae56447b..ce0233c7 100644 --- a/src/main.c +++ b/src/main.c @@ -5580,6 +5580,7 @@ static void print_usage() " -n, --network network multiplayer game\n" " --serveronly only start network server\n" " -v, --verbose verbose mode\n" + " -V, --version show program version\n" " --debug display debugging information\n" " --debug-x11-sync enable X11 synchronous mode\n" " -e, --execute COMMAND execute batch COMMAND\n" @@ -5600,6 +5601,45 @@ static void print_usage() program.command_basename); } +static void print_version() +{ + printf("%s %d.%d.%d.%d\n", + PROGRAM_TITLE_STRING, + PROGRAM_VERSION_MAJOR, + PROGRAM_VERSION_MINOR, + PROGRAM_VERSION_PATCH, + PROGRAM_VERSION_BUILD); + + if (options.debug) + { + SDL_version sdl_version; + + SDL_VERSION(&sdl_version); + printf("- SDL %d.%d.%d\n", + sdl_version.major, + sdl_version.minor, + sdl_version.patch); + + SDL_IMAGE_VERSION(&sdl_version); + printf("- SDL_image %d.%d.%d\n", + sdl_version.major, + sdl_version.minor, + sdl_version.patch); + + SDL_MIXER_VERSION(&sdl_version); + printf("- SDL_mixer %d.%d.%d\n", + sdl_version.major, + sdl_version.minor, + sdl_version.patch); + + SDL_NET_VERSION(&sdl_version); + printf("- SDL_net %d.%d.%d\n", + sdl_version.major, + sdl_version.minor, + sdl_version.patch); + } +} + int main(int argc, char *argv[]) { InitProgramInfo(argv[0], USERDATA_DIRECTORY, USERDATA_DIRECTORY_UNIX, @@ -5611,7 +5651,7 @@ int main(int argc, char *argv[]) InitExitFunction(CloseAllAndExit); InitPlatformDependentStuff(); - GetOptions(argv, print_usage); + GetOptions(argv, print_usage, print_version); OpenAll(); EventLoop();