[nemiver] Properly handle empty cmd line



commit 39e0d0208b1158c62cc44872e8578f648c071a22
Author: Dodji Seketeli <dodji redhat com>
Date:   Sat Nov 21 23:01:35 2009 +0100

    Properly handle empty cmd line
    
    	* src/main.cc (parse_command_line): Make it clear that this edits
    	the command line and lets it become the command like of the
    	inferior. So handle the case where there is no inferior on the
    	command line, i.e. when nemiver is launched with no argument.
    	(process_gui_options): Do not try to debug an inferior when there
    	is none.

 src/main.cc |   23 +++++++++++++++++++----
 1 files changed, 19 insertions(+), 4 deletions(-)
---
diff --git a/src/main.cc b/src/main.cc
index 1265f2d..6de615b 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -211,6 +211,8 @@ init_option_context ()
     return context.release ();
 }
 
+// Parse the command line and edits it
+// to make it contain the command line of the inferior program.
 static void
 parse_command_line (int& a_argc,
                     char** a_argv)
@@ -218,6 +220,13 @@ parse_command_line (int& a_argc,
     GOptionContextSafePtr context (init_option_context ());
     THROW_IF_FAIL (context);
 
+    if (a_argc == 1) {
+        // We have no inferior program so edit the command like accordingly.
+        a_argc = 0;
+        a_argv[0] = 0;
+        return;
+    }
+
     // Split the command like in two parts. One part is made of the options
     // for Nemiver itself, and the other part is the options relevant to
     // the inferior.
@@ -416,7 +425,12 @@ process_gui_options (int& a_argc, char** a_argv)
     }
 
     vector<UString> prog_args;
-    UString prog_path = a_argv[0];
+    UString prog_path;
+    // Here, a_argc is the argument count of the inferior program.
+    // It's zero if there is there is no inferior program.
+    // Otherwise it equals the number of arguments to the inferior program + 1
+    if (a_argc > 0)
+        prog_path = a_argv[0];
     for (int i = 1; i < a_argc; ++i) {
         prog_args.push_back (Glib::locale_to_utf8 (a_argv[i]));
     }
@@ -443,9 +457,10 @@ process_gui_options (int& a_argc, char** a_argv)
                 env[name] = value;
             }
         }
-        debug_persp->execute_program (prog_path,
-                                      prog_args,
-                                      env);
+        if (!prog_path.empty ())
+            debug_persp->execute_program (prog_path,
+                                          prog_args,
+                                          env);
     } else {
         cerr << "Could not find the debugger perspective plugin\n";
         return false;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]