[Nemiver-list] Little patch
- From: "Emre Turkay" <emreturkay domain hid>
- To: nemiver-list domain hid
- Subject: [Nemiver-list] Little patch
- Date: Fri, 1 Feb 2008 10:46:14 +0200
Here goes a little patch, making main () function a little more readable.
Emre Turkay
Index: src/main.cc
===================================================================
--- src/main.cc (revision 719)
+++ src/main.cc (working copy)
@@ -159,60 +159,35 @@
}
}
-int
-main (int a_argc, char *a_argv[])
+//***************************
+//parse command line options
+//***************************
+void parse_command_line(int& a_argc, char** a_argv)
{
- bindtextdomain (GETTEXT_PACKAGE, NEMIVERLOCALEDIR) ;
- bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8") ;
- textdomain (GETTEXT_PACKAGE) ;
- Initializer::do_init () ;
- Gtk::Main gtk_kit (a_argc, a_argv);
-
- //***************************
- //parse command line options
- //***************************
typedef SafePtr<GOptionContext,
- GOptionContextRef,
- GOptionContextUnref> GOptionContextSafePtr ;
+ GOptionContextRef,
+ GOptionContextUnref> GOptionContextSafePtr ;
GOptionContextSafePtr context ;
context.reset (g_option_context_new
(_(" [<prog-to-debug> [prog-args]]")));
#if GLIB_CHECK_VERSION (2, 12, 0)
g_option_context_set_summary (context.get (),
- _("A C/C++ debugger for GNOME")) ;
+ _("A C/C++ debugger for GNOME")) ;
#endif
g_option_context_set_help_enabled (context.get (), true) ;
g_option_context_add_main_entries (context.get (),
- entries,
- GETTEXT_PACKAGE) ;
+ entries,
+ GETTEXT_PACKAGE) ;
//g_option_context_add_group (context.get (), gtk_get_option_group (true)) ;
g_option_context_set_ignore_unknown_options (context.get (), true) ;
g_option_context_parse (context.get (), &a_argc, &a_argv, 0) ;
+}
- // intialize gnome libraries
- gnome_program_init (PACKAGE, PACKAGE_VERSION,
- LIBGNOME_MODULE, a_argc, a_argv,
- GNOME_PROGRAM_STANDARD_PROPERTIES, NULL);
-
- NEMIVER_TRY
-
- //**********************************
- //load the workbench dynamic module
- //**********************************
- DynamicModuleManager module_manager ;
-
- IWorkbenchSafePtr workbench =
- module_manager.load_iface<IWorkbench> ("workbench", "IWorkbench");
- s_workbench = workbench.get () ;
- LOG_D ("workbench refcount: " << (int) s_workbench->get_refcount (),
- "refcount-domain") ;
- s_workbench->do_init (gtk_kit) ;
- LOG_D ("workbench refcount: " << (int) s_workbench->get_refcount (),
- "refcount-domain") ;
-
- //********************************
- //<process command line arguments>
- //********************************
+//********************************
+//process command line arguments
+//********************************
+bool process_command_line(int& a_argc, char** a_argv, int &a_return)
+{
if (gv_log_debugger_output) {
LOG_STREAM.enable_domain ("gdbmi-output-domain") ;
}
@@ -236,14 +211,16 @@
(DBGPERSPECTIVE_PLUGIN_NAME));
if (!debug_persp) {
cerr << "Could not get the debugging perspective" << endl ;
- return -1 ;
+ a_return = -1;
+ return false;
}
int pid = atoi (gv_process_to_attach_to) ;
if (!pid) {
IProcMgrSafePtr proc_mgr = IProcMgr::create () ;
if (!proc_mgr) {
cerr << "Could not create proc mgr" << endl ;
- return -1 ;
+ a_return = -1;
+ return false;
}
IProcMgr::Process process ;
if (!proc_mgr->get_process_from_name (gv_process_to_attach_to,
@@ -254,7 +231,8 @@
<< "'"
<< endl
;
- return -1 ;
+ a_return = -1;
+ return false;
}
pid = process.pid () ;
}
@@ -264,7 +242,8 @@
<< "'"
<< endl
;
- return -1 ;
+ a_return = -1;
+ return false;
} else {
debug_persp->attach_to_program (pid) ;
}
@@ -288,10 +267,12 @@
<< "\n"
;
}
- return 0 ;
+ a_return = 0;
+ return false;
} else {
cerr << "Could not find the debugger perpective plugin" ;
- return -1 ;
+ a_return = -1;
+ return false;
}
}
@@ -302,7 +283,8 @@
if (debug_persp) {
debug_persp->session_manager ().delete_sessions () ;
}
- return 0 ;
+ a_return = 0;
+ return false;
}
if (gv_execute_session) {
@@ -329,9 +311,10 @@
cerr << "Could not find session of number "
<< gv_execute_session
<< "\n";
- return -1 ;
+ a_return = -1;
+ return false;
}
- goto run_app ;
+ return true;
}
}
@@ -351,17 +334,18 @@
} else {
cerr << "Could not find any sessions"
<< "\n";
- return -1 ;
+ a_return = -1;
+ return false;
}
- goto run_app ;
+ return true;
}
}
-
if (a_argc > 1) {
if (a_argv[1][0] == '-') {
std::cerr << "unknown option " << a_argv[1] << "\n";
- return 0;
+ a_return = 0;
+ return false;
}
UString prog_args ;
for (int i=1 ; i < a_argc ;++i) {
@@ -395,18 +379,50 @@
debug_persp->execute_program (prog_args, env) ;
} else {
cerr << "Could not find the debugger perspective plugin\n" ;
- return -1 ;
+ a_return = -1;
+ return false;
}
- goto run_app ;
-
}
- //********************************
- //</process command line arguments>
- //********************************
+ return true ;
+}
+int
+main (int a_argc, char *a_argv[])
+{
+ bindtextdomain (GETTEXT_PACKAGE, NEMIVERLOCALEDIR) ;
+ bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8") ;
+ textdomain (GETTEXT_PACKAGE) ;
+ Initializer::do_init () ;
+ Gtk::Main gtk_kit (a_argc, a_argv);
-run_app:
+ parse_command_line(a_argc, a_argv);
+ // intialize gnome libraries
+ gnome_program_init (PACKAGE, PACKAGE_VERSION,
+ LIBGNOME_MODULE, a_argc, a_argv,
+ GNOME_PROGRAM_STANDARD_PROPERTIES, NULL);
+
+ NEMIVER_TRY
+
+ //**********************************
+ //load the workbench dynamic module
+ //**********************************
+ DynamicModuleManager module_manager ;
+
+ IWorkbenchSafePtr workbench =
+ module_manager.load_iface<IWorkbench> ("workbench", "IWorkbench");
+ s_workbench = workbench.get () ;
+ LOG_D ("workbench refcount: " << (int) s_workbench->get_refcount (),
+ "refcount-domain") ;
+ s_workbench->do_init (gtk_kit) ;
+ LOG_D ("workbench refcount: " << (int) s_workbench->get_refcount (),
+ "refcount-domain") ;
+
+ int retval;
+ if (process_command_line(a_argc, a_argv, retval) != true) {
+ return retval;
+ }
+
//intercept ctrl-c/SIGINT
signal (SIGINT, sigint_handler) ;
gtk_kit.run (s_workbench->get_root_window ()) ;
[Date Prev][
Date Next] [Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]