Add version option for gnits automake mode
[hvgrip.git] / src / main.c
index ffe94c7..ba35a4b 100644 (file)
@@ -21,7 +21,9 @@
  */
 
 #include <config.h>
-#include <gnome.h>
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <popt.h>
 #include <stdlib.h>
 
 #include "grip.h"
@@ -40,6 +42,7 @@ static int force_small=FALSE;
 static int local_mode=FALSE;
 static int no_redirect=FALSE;
 static int verbose=FALSE;
+static int version=FALSE;
 
 struct poptOption options[] = {
   { 
@@ -114,6 +117,16 @@ struct poptOption options[] = {
     N_("Run in verbose (debug) mode"),
     NULL
   },
+  {
+    "version",
+    '\0',
+    POPT_ARG_NONE,
+    &version,
+    0,
+    N_("Print version number"),
+    NULL
+  },
+  POPT_AUTOHELP
   {
     NULL,
     '\0',
@@ -145,19 +158,37 @@ void Debug(char *fmt,...)
 
 int Cmain(int argc, char* argv[])
 {
+  poptContext context;
+  int status;
+
   /* Unbuffer stdout */
   setvbuf(stdout, 0, _IONBF, 0);
 
   /* setup locale, i18n */
   gtk_set_locale();
-  bindtextdomain(GETTEXT_PACKAGE,GNOMELOCALEDIR);
-  textdomain(GETTEXT_PACKAGE);
+  bindtextdomain(PACKAGE_TARNAME, LOCALEDIR);
+  textdomain(PACKAGE_TARNAME);
+
+  gtk_init(&argc, &argv);
+  context = poptGetContext(NULL, argc, (const char **) argv, options, 0);
+  status = poptGetNextOpt(context);
+  if (status != -1) {
+    fprintf(stderr, "Error with option [%s]:\n  %s\n",
+           poptBadOption(context, POPT_BADOPTION_NOALIAS),
+           poptStrerror(status));
+
+    /* Print a short usage message. */
+    poptPrintUsage(context, stderr, 0);
 
-  gnome_program_init(PACKAGE,VERSION,LIBGNOMEUI_MODULE,argc,argv, 
-                    GNOME_PARAM_POPT_TABLE,options,
-                    GNOME_PROGRAM_STANDARD_PROPERTIES,NULL);
+    exit(1);
+  }
+
+  if (version) {
+    printf("%s\n", PACKAGE_VERSION);
+    exit(0);
+  }
 
-  bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF8");
+  bind_textdomain_codeset(PACKAGE_TARNAME, "UTF8");
   setenv("CHARSET","UTF-8",1);
 
   do_debug=verbose;