Index: src/idl-compiler/orbit-idl-main.c
===================================================================
RCS file: /cvs/gnome/ORBit2/src/idl-compiler/orbit-idl-main.c,v
retrieving revision 1.32
diff -p -u -u -p -r1.32 orbit-idl-main.c
--- src/idl-compiler/orbit-idl-main.c	10 Mar 2005 12:05:21 -0000	1.32
+++ src/idl-compiler/orbit-idl-main.c	12 May 2006 21:25:27 -0000
@@ -29,10 +29,14 @@
 #include <errno.h>
 #include <glib.h>
 #include <libIDL/IDL.h>
-#include <popt.h>
+#include <glib/goption.h>
+#include <glib/gi18n.h>
 
 #include "orbit-idl2.h"
 
+/* FIXME: this program doesn't seem to support i18n? */
+#define GETTEXT_PACKAGE NULL
+
 /* Settings made from the command line (prefaced with cl_) */
 static gboolean cl_disable_stubs = FALSE,
   cl_disable_skels = FALSE,
@@ -54,124 +58,140 @@ static char *cl_backend_dir = NULL;
 static gboolean cl_onlytop = FALSE;
 static char *cl_deps_file = NULL;
 static char *cl_output_directory = "";
+static char **idl_files = NULL;
 
 #define BASE_CPP_ARGS "-D__ORBIT_IDL__ "
 static GString *cl_cpp_args;
 
-static char *c_output_formatter = NULL;
+/* Callbacks for goption */
 
-/* Callbacks for popt */
-static void
-cl_libIDL_version_callback(poptContext con, enum poptCallbackReason reason,
-			   const struct poptOption *opt, char *arg,
-			   void *data)
+static gboolean
+cl_libIDL_version_callback (const char *option_name,
+			    const char *value,
+			    gpointer data,
+			    GError **error)
 {
-  g_print("libIDL %s (CORBA %s)",
+  g_print("libIDL %s (CORBA %s)\n",
 	  IDL_get_libver_string(),
 	  IDL_get_IDLver_string());
-
   exit(0);
 }
 
-static void
-cl_cpp_callback(poptContext con, enum poptCallbackReason reason,
-		const struct poptOption *opt, char *arg,
-		void *data)
-{
-  g_assert(opt!=NULL);
-
-  if(opt->shortName=='D')
-    g_string_append(cl_cpp_args, "-D");
-  else if(opt->shortName=='I')
-    g_string_append(cl_cpp_args, "-I");
+static gboolean
+cl_cpp_define_callback (const char *option_name,
+			const char *value,
+			gpointer data,
+			GError **error)
+{
+  g_string_append_printf (cl_cpp_args, "-D%s ", value);
+  return TRUE;
+}
 
-  g_string_append(cl_cpp_args, arg);
-  g_string_append_c(cl_cpp_args, ' ');
+static gboolean
+cl_cpp_include_callback (const char *option_name,
+			 const char *value,
+			 gpointer data,
+			 GError **error)
+{
+  g_string_append_printf (cl_cpp_args, "-I%s ", value);
+  return TRUE;
 }
 
-static const
-struct poptOption cl_libIDL_callback_options[] = {
-  {NULL, '\0', POPT_ARG_CALLBACK, (void *)cl_libIDL_version_callback,
-   0, NULL, NULL},
-  {"libIDL-version", '\0', POPT_ARG_NONE, NULL, 0,
-   "Show version of libIDL used.", NULL},
-  {NULL, '\0', 0, NULL, 0, NULL, NULL}
+static gboolean
+cl_version_callback (const char *option_name,
+		     const char *value,
+		     gpointer data,
+		     GError **error)
+{
+  g_print ("orbit-idl-2 %s - serial %d\n",
+           VERSION, ORBIT_CONFIG_SERIAL);
+  exit(0);
+}
+
+static gboolean
+cl_c_output_formatter_callback (const char *option_name,
+				const char *value,
+				gpointer data,
+				GError **error)
+{
+  g_warning ("Do not use the 'c-output-formatter' option. It is ignored and will soon go away.");
+  return TRUE;
+}
+
+static const GOptionEntry cl_libIDL_goptions[] = {
+  { "libIDL-version", 0, 0, G_OPTION_ARG_CALLBACK, cl_libIDL_version_callback, N_("Show version of libIDL used"), NULL },
+  { NULL }
 };
 
-static const
-struct poptOption cl_cpp_callback_options[] = {
-  {NULL, '\0', POPT_ARG_CALLBACK, (void *)cl_cpp_callback, 0, NULL, NULL},
-  {"define", 'D', POPT_ARGFLAG_ONEDASH | POPT_ARG_STRING, NULL, 0,
-   "Define value in preprocessor", NULL},
-  {"include", 'I', POPT_ARGFLAG_ONEDASH | POPT_ARG_STRING, NULL, 0,
-   "Add search path for include files", NULL},
-  {NULL, '\0', 0, NULL, 0, NULL, NULL}
+static const GOptionEntry cl_cpp_goptions[] = {
+  { "define", 'D', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, cl_cpp_define_callback, N_("Define value in preprocessor"), N_("DEFINE") },
+  { "include", 'I', G_OPTION_FLAG_FILENAME, G_OPTION_ARG_CALLBACK, cl_cpp_include_callback, N_("Add search path for include files"), N_("DIR") },
+  { NULL }
 };
 
-static
-struct poptOption options[] = {
-  {NULL, '\0', POPT_ARG_INCLUDE_TABLE, &cl_cpp_callback_options, 0, NULL, NULL},
-  {NULL, '\0', POPT_ARG_INCLUDE_TABLE, &cl_libIDL_callback_options, 0, NULL, NULL},
-  {"version", 'v', POPT_ARG_NONE, &cl_output_version, 0, "Output compiler version and serial", NULL},
-  {"lang", 'l', POPT_ARG_STRING, &cl_output_lang, 0, "Output language (default is C)", NULL},
-  {"debug", 'd', POPT_ARG_INT, &cl_debuglevel, 0, "Debug level 0 to 4", NULL},
-  {"idlwarnlevel", '\0', POPT_ARG_INT, &cl_idlwarnlevel, 0, "IDL warning level 0 to 4, default is 2", NULL},
-  {"showcpperrors", '\0', POPT_ARG_NONE, &cl_showcpperrors, 0, "Show CPP errors", NULL},
-  {"nostubs", '\0', POPT_ARG_NONE, &cl_disable_stubs, 0, "Don't output stubs", NULL},
-  {"noskels", '\0', POPT_ARG_NONE, &cl_disable_skels, 0, "Don't output skels", NULL},
-  {"nocommon", '\0', POPT_ARG_NONE, &cl_disable_common, 0, "Don't output common", NULL},
-  {"noheaders", '\0', POPT_ARG_NONE, &cl_disable_headers, 0, "Don't output headers", NULL},
-  {"noidata", '\0', POPT_ARG_NONE, &cl_disable_idata, 0, "Don't generate Interface type data", NULL},
-  {"imodule", 'i', POPT_ARG_NONE, &cl_enable_imodule, 0, "Output only an imodule file", NULL},
-  {"add-imodule", '\0', POPT_ARG_NONE, &cl_add_imodule, 0, "Output an imodule file", NULL},
-  {"skeleton-impl", '\0', POPT_ARG_NONE, &cl_enable_skeleton_impl, 0, "Output skeleton implementation", NULL},
-  {"backenddir", '\0', POPT_ARG_STRING, &cl_backend_dir, 0, "Override IDL backend library directory", "DIR"},
-  {"c-output-formatter", '\0', POPT_ARG_STRING, &c_output_formatter, 0, "DEPRECATED and IGNORED", "PROGRAM"},
-  {"onlytop", '\0', POPT_ARG_NONE, &cl_onlytop, 0, "Inhibit includes", NULL},
-  {"pidl", '\0', POPT_ARG_NONE, &cl_is_pidl, 0, "Treat as Pseudo IDL", NULL},
-  {"nodefskels", '\0', POPT_ARG_NONE, &cl_disable_defs_skels, 0, "Don't output defs for skels in header", NULL},
-  {"deps", '\0', POPT_ARG_STRING, &cl_deps_file, 0, "Generate dependency info suitable for inclusion in Makefile", "FILENAME"},
-  {"headerguardprefix", '\0', POPT_ARG_STRING, &cl_header_guard_prefix, 0, "Prefix for #ifdef header guards. Sometimes useful to avoid conflicts.", NULL},
-  {"output-dir", '\0', POPT_ARG_STRING, &cl_output_directory, 0, "Where to put generated files. This directory must exist.", NULL},
-  POPT_AUTOHELP
-  {NULL, '\0', 0, NULL, 0, NULL, NULL}
+static const GOptionEntry goptions[] = {
+  { "version", 'v', 0, G_OPTION_ARG_CALLBACK, cl_version_callback, N_("Output compiler version and serial"), NULL },
+  { "lang", 'l', 0, G_OPTION_ARG_STRING, &cl_output_lang, N_("Output language (default is C)"), N_("LANG") },
+  { "debug", 'd', 0, G_OPTION_ARG_INT, &cl_debuglevel, N_("Debug level (0 to 4)"), N_("LEVEL") },
+  { "idlwarnlevel", 0, 0, G_OPTION_ARG_INT, &cl_idlwarnlevel, N_("IDL warning level (0 to 4, default is 2)"), N_("LEVEL") },
+  { "showcpperrors", 0, 0, G_OPTION_ARG_NONE, &cl_showcpperrors, N_("Show CPP errors"), NULL },
+  { "nostubs", 0, 0, G_OPTION_ARG_NONE, &cl_disable_stubs, N_("Don't output stubs"), NULL },
+  { "noskels", 0, 0, G_OPTION_ARG_NONE, &cl_disable_skels, N_("Don't output skels"), NULL },
+  { "nocommon", 0, 0, G_OPTION_ARG_NONE, &cl_disable_common, N_("Don't output common"), NULL },
+  { "noheaders", 0, 0, G_OPTION_ARG_NONE, &cl_disable_headers, N_("Don't output headers"), NULL },
+  { "noidata", 0, 0, G_OPTION_ARG_NONE, &cl_disable_idata, N_("Don't generate Interface type data"), NULL },
+  { "imodule", 'i', 0, G_OPTION_ARG_NONE, &cl_enable_imodule, N_("Output only an imodule file"), NULL },
+  { "add-imodule", 0, 0, G_OPTION_ARG_NONE, &cl_add_imodule, N_("Output an imodule file"), NULL },
+  { "skeleton-impl", 0, 0, G_OPTION_ARG_NONE, &cl_enable_skeleton_impl, N_("Output skeleton implementation"), NULL },
+  { "backenddir", 0, 0, G_OPTION_ARG_FILENAME, &cl_backend_dir, N_("Override IDL backend library directory"), N_("DIR") },
+  { "c-output-formatter", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_CALLBACK, &cl_c_output_formatter_callback, "DEPRECATED and IGNORED", "PROGRAM" },
+  { "onlytop", 0, 0, G_OPTION_ARG_NONE, &cl_onlytop, N_("Inhibit includes"), NULL },
+  { "pidl", 0, 0, G_OPTION_ARG_NONE, &cl_is_pidl, N_("Treat as Pseudo IDL"), NULL },
+  { "nodefskels", 0, 0, G_OPTION_ARG_NONE, &cl_disable_defs_skels, N_("Don't output defs for skels in header"), NULL },
+  { "deps", 0, 0,  G_OPTION_ARG_FILENAME, &cl_deps_file, N_("Generate dependency info suitable for inclusion in Makefile"), N_("FILENAME") },
+  { "headerguardprefix", 0, 0, G_OPTION_ARG_STRING, &cl_header_guard_prefix, N_("Prefix for #ifdef header guards. Sometimes useful to avoid conflicts."), N_("PREFIX") },
+  { "output-dir", 0, 0, G_OPTION_ARG_FILENAME, &cl_output_directory, N_("Where to put generated files. This directory must exist."), N_("DIR") },
+  { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &idl_files, NULL, N_("<IDL files>") },
+  { NULL }
 };
 
 /********** main routines **********/
-int main(int argc, const char *argv[])
+int main(int argc, char *argv[])
 {
-  poptContext pcon;
-  int rc, retval = 0;
-  const char *arg;
+  GOptionContext *context;
+  GOptionGroup *group;
+  GError *error = NULL;
   OIDL_Run_Info rinfo;
+  char *arg;
+  int retval = 0;
 
   /* Argument parsing, etc. */
   cl_cpp_args = g_string_new("-D__ORBIT_IDL__ ");
 
-  pcon = poptGetContext ("orbit-idl-2", argc, argv, options, 0);
-  poptSetOtherOptionHelp (pcon, "<IDL files>");
+  context = g_option_context_new ("");
+  g_option_context_add_main_entries (context, goptions, GETTEXT_PACKAGE);
 
-  if(argc < 2) {
-  	poptPrintUsage(pcon, stdout, 0);
-	return 0;
+  group = g_option_group_new ("libIDL", N_("libIDL options"), N_("Show libIDL options"), NULL, NULL);
+  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+  g_option_group_add_entries (group, cl_libIDL_goptions);
+  g_option_context_add_group (context, group);
+
+  group = g_option_group_new ("cpp", N_("Preprocessor options"), N_("Show preprocessor options"), NULL, NULL);
+  g_option_group_set_translation_domain (group, GETTEXT_PACKAGE);
+  g_option_group_add_entries (group, cl_cpp_goptions);
+  g_option_context_add_group (context, group);
+
+  if (!g_option_context_parse (context, &argc, &argv, &error)) {
+    g_print ("orbit-idl-2: %s\n", error->message);
+    g_error_free (error);
+    exit (1);
   }
 
-  if((rc=poptGetNextOpt(pcon)) < -1) {
-    g_print ("orbit-idl-2: bad argument %s: %s\n", 
-    		poptBadOption(pcon, POPT_BADOPTION_NOALIAS),
-		poptStrerror(rc));
-    exit(0);
+  if (!idl_files) {
+    g_print ("No input files given!\n");
+    exit (1);
   }
 
-  if (cl_output_version) {
-	  printf ("orbit-idl-2 %s - serial %d\n\n",
-		  VERSION, ORBIT_CONFIG_SERIAL);
-	  exit (0);
-  }
-
-  if (c_output_formatter != NULL)
-	  g_warning ("Please do not use the 'c-output-formatter' option. It is ignored and will soon go away.");
-
   /* Prep our run info for the backend */
   rinfo.cpp_args = cl_cpp_args->str;
   rinfo.debug_level = cl_debuglevel;
@@ -213,14 +233,14 @@ int main(int argc, const char *argv[])
 	  cl_enable_imodule ? "imodule" : "");
 	   
   /* Do it */
-  while((arg=poptGetArg(pcon))!=NULL) {
-    rinfo.input_filename = g_strdup (arg); /* g_path_get_basename(arg); - what !? */
+  while ((arg = *(idl_files++))) {
+    g_print ("Processing file %s\n", arg);
+    rinfo.input_filename = arg;
     if (!orbit_idl_to_backend(arg, &rinfo)) {
       g_warning("%s compilation failed", arg);
       retval = 1;
     }
-    g_free(rinfo.input_filename);
   }
 
-  return retval;
+  exit (retval);
 }
