diff src/debug.cc @ 6646:bd0a70c3f2db

[project @ 2007-05-22 02:27:43 by jwe]
author jwe
date Tue, 22 May 2007 02:27:43 +0000
parents 8c67f8be341d
children 673686daec87
line wrap: on
line diff
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -87,14 +87,15 @@
 
 DEFCMD (dbstop, args, ,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {rline =} dbstop (func, line)\n\
+@deftypefn {Loadable Function} {rline =} dbstop (func, line, @dots{})\n\
 Set a breakpoint in a function\n\
 @table @code\n\
 @item func\n\
 String representing the function name.  When already in debug\n\
 mode this should be left out and only the line should be given.\n\
 @item line\n\
-Line you would like the breakpoint to be set on\n\
+Line you would like the breakpoint to be set on. Multiple\n\
+lines might be given as seperate arguments or as a vector.\n\
 @end table\n\
 \n\
 The rline returned is the real line that the breakpoint was set at.\n\
@@ -102,118 +103,152 @@
 @end deftypefn")
 {
   octave_value retval;
-
-  int result = -1;
   int nargin = args.length ();
+  int idx = 0;
+  std::string symbol_name = "";
 
-  string_vector argv = args.make_argv ("dbstop");
-
-  if (error_state)
-    return retval;
+  if (nargin != 1 && args(0).is_string())
+    {
+      symbol_name = args(0).string_value ();
+      idx = 1;
+    }
 
-  if (nargin == 2)
-    {
-      std::string symbol_name = argv[1];
-
-      std::string line_number = argv[2];
+  octave_user_function *dbg_fcn = get_user_function (symbol_name);
 
-      int line = atoi (line_number.c_str ());
+  if (dbg_fcn)
+    {
+      octave_idx_type nsize = 10;
+      RowVector results (nsize);
+      octave_idx_type nr = 0;
 
-      octave_user_function *dbg_fcn = get_user_function (symbol_name);
+      tree_statement_list *cmds = dbg_fcn->body ();
 
-      if (dbg_fcn)
+      for (int i = idx; i < nargin; i++)
 	{
-	  tree_statement_list *cmds = dbg_fcn->body ();
-	  result = cmds->set_breakpoint (line);
-	}
-      else
-	error ("dbstop: unable to find the function requested\n");
-    }
-  else if (nargin == 1)
-    {
-      std::string line_number = argv[1];
+	  if (args(i).is_string ())
+	    {
+	      int line = atoi (args(i).string_value ().c_str ());
+
+	      if (error_state)
+		break;
+
+	      if (nr == nsize)
+		{
+		  nsize *= 2;
+		  results.resize (nsize);
+		}
+
+	      results(nr++) = cmds->set_breakpoint (line);
+	    }
+	  else
+	    {
+	      const NDArray arg = args(i).array_value ();
+
+	      if (error_state)
+		break;
 
-      int line = atoi (line_number.c_str ());
+	      for (octave_idx_type j = 0; j < arg.nelem(); j++)
+		{
+		  int line = static_cast<int> (arg.elem (j));
+
+		  if (error_state)
+		    break;
 
-      octave_user_function *dbg_fcn = get_user_function ();
+		  if (nr == nsize)
+		    {
+		      nsize *= 2;
+		      results.resize (nsize);
+		    }
 
-      if (dbg_fcn)
+		  results(nr++) = cmds->set_breakpoint (line);
+		}
+
+	      if (error_state)
+		break;
+	    }
+	}
+
+      if (! error_state)
 	{
-	  tree_statement_list *cmds = dbg_fcn->body ();
-	  result = cmds->set_breakpoint (line);
+	  results.resize (nr);
+	  retval = results;
 	}
-      else
-	error ("dbstop: unable to find the function requested\n");	
     }
   else
-    error ("dbstop: one argument when in a function and two when not\n");
-
-  retval = result;
+    error ("dbstop: unable to find the function requested\n");
 
   return retval;
 }
 
 DEFCMD (dbclear, args, ,
   "-*- texinfo -*-\n\
-@deftypefn {Loadable Function} {} dbclear (func, line)\n\
+@deftypefn {Loadable Function} {} dbclear (func, line, @dots{})\n\
 Delete a breakpoint in a function\n\
 @table @code\n\
 @item func\n\
 String representing the function name.  When already in debug\n\
 mode this should be left out and only the line should be given.\n\
 @item line\n\
-Line where you would like to remove the the breakpoint\n\
+Line where you would like to remove the the breakpoint. Multiple\n\
+lines might be given as seperate arguments or as a vector.\n\
 @end table\n\
 No checking is done to make sure that the line you requested is really\n\
-a breakpoint.   If you get the wrong line nothing will happen.\n\
+a breakpoint. If you get the wrong line nothing will happen.\n\
 @seealso{dbstop, dbstatus, dbwhere}\n\
 @end deftypefn")
 {
   octave_value retval;
-
+  int nargin = args.length ();
+  int idx = 0;
   std::string symbol_name = "";
-  std::string line_number;
+
+  if (nargin != 1 && args(0).is_string())
+    {
+      symbol_name = args(0).string_value ();
+      idx = 1;
+    }
 
-  int line = -1;
-  int nargin = args.length ();
+  octave_user_function *dbg_fcn = get_user_function (symbol_name);
+
+  if (dbg_fcn)
+    {
+      tree_statement_list *cmds = dbg_fcn->body ();
 
-  string_vector argv = args.make_argv ("dbclear");
+      for (int i = idx; i < nargin; i++)
+	{
+	  if (args(i).is_string ())
+	    {
+	      int line = atoi (args(i).string_value ().c_str ());
 
-  if (error_state)
-    return retval;
+	      if (error_state)
+		break;
+
+	      cmds->delete_breakpoint (line);
+	    }
+	  else
+	    {
+	      const NDArray arg = args(i).array_value ();
+
+	      if (error_state)
+		break;
 
-  if (nargin == 1 || nargin == 2)
-    {
-      if (nargin == 2)
-	{
-	  symbol_name = argv[1];
+	      for (octave_idx_type j = 0; j < arg.nelem (); j++)
+		{
+		  int line = static_cast<int> (arg.elem (j));
+
+		  if (error_state)
+		    break;
 
-	  octave_stdout << argv[1] << std::endl;
-	  line_number = argv[2];
+		  cmds->delete_breakpoint (line);
+		}
+
+	      if (error_state)
+		break;
+	    }
 	}
-      else if (nargin == 1)
-	{
-	  line_number = argv[1];
-	}
-
-      if (line_number.compare ("all") && line_number.compare ("ALL"))
-	line = atoi (line_number.c_str ());
-      else
-	line = -1;
-
-      octave_stdout << "symbol_name = " << symbol_name << std::endl;
-      octave_user_function *dbg_fcn = get_user_function (symbol_name);
-
-      if (dbg_fcn)
-	{
-	  tree_statement_list *cmds = dbg_fcn->body ();
-	  cmds->delete_breakpoint (line);
-	}
-      else
-	error ("dbclear: unable to find the function requested\n");
     }
   else
-    error ("dbclear: expecting one or two arguements\n");
+    error ("dbclear: unable to find the function requested\n");
 
   return retval;
 }
@@ -350,7 +385,7 @@
   else
     os << "dbtype: unknown function " << name << "\n";
 
-  os.flush();
+  os.flush ();
 }
 
 DEFCMD (dbtype, args, ,