rnd-20140828-1-src
authorHolger Schemel <info@artsoft.org>
Thu, 28 Aug 2014 09:24:37 +0000 (11:24 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 09:01:41 +0000 (11:01 +0200)
* added command line options "--version" / "-V" to show program version
  (also shows SDL library versions when prefixed with "--debug" option)

ChangeLog
src/conftime.h
src/libgame/misc.c
src/libgame/misc.h
src/libgame/system.c
src/libgame/system.h
src/main.c

index b58b9423da9af3a28f2aa47196785977e1c0d4c4..515f53bba9e79ff170f033f113ea969f54111956 100644 (file)
--- 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
 
index 9a502daa15c8e0715dc05dcbadc9e1e0af53eb3d..3affe7c9ba881e303dec43ae7b68cc6cc6edefce 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2014-08-27 13:39"
+#define COMPILE_DATE_STRING "2014-08-28 11:08"
index 39a55435f9720611e17fa1b04218f7e4bee349ab..dbcd7fdb608661b55e9a9acaff9f6b7b960c08be 100644 (file)
@@ -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)
index 98cc3fe12670a6a60d67fc18b063d9b976e8ab4f..b2b0c0cfc62de30577f2e1ead356fab006a3938f 100644 (file)
@@ -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);
index 3f466bccd0578aa7e37daac5760112efa8a5a53b..f8a606801c1bf6b8a14c28f59e39f65dd69be61b 100644 (file)
@@ -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;
index af8772b143b29a6ff0e627b6801ad2a0cdab3861..e9b4cb510802a73c9dfbce395eae22919321b50b 100644 (file)
@@ -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);
index ae56447ba7d7fc9babfcddd3bbee4e74d15bd6c4..ce0233c7ca3a810eac1438b5143664c7098c3e7b 100644 (file)
@@ -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();