Mercurial > hg > octave-nkf
diff src/debug.cc @ 3946:eab957395758
[project @ 2002-05-23 00:42:15 by jwe]
author | jwe |
---|---|
date | Thu, 23 May 2002 00:42:16 +0000 |
parents | d38c7538b954 |
children | b4f51bbf7557 |
line wrap: on
line diff
--- a/src/debug.cc +++ b/src/debug.cc @@ -27,8 +27,8 @@ #include <iostream> #include <fstream> #include <strstream> -#include <string> -#include <stdlib.h> +#include <cstring> +#include <cstdlib> #include "defun.h" #include "error.h" @@ -58,7 +58,7 @@ if (str.compare ("")) { symbol_record *ptr = curr_sym_tab->lookup (str); - + if (ptr && ptr->is_user_function ()) { octave_value tmp = ptr->def (); @@ -67,7 +67,7 @@ else { symbol_record *ptr = lookup_by_name (str, false); - + if (ptr && ptr->is_user_function ()) { octave_value tmp = ptr->def (); @@ -105,20 +105,20 @@ int result = -1; int nargin = args.length (); - + string_vector argv = args.make_argv ("dbstop"); if (error_state) return retval; if (nargin == 2) - { + { std::string symbol_name = argv[1]; std::string line_number = argv[2]; int line = atoi (line_number.c_str ()); - + octave_user_function *dbg_fcn = get_user_function (symbol_name); if (dbg_fcn) @@ -136,14 +136,14 @@ int line = atoi (line_number.c_str ()); octave_user_function *dbg_fcn = get_user_function (); - + if (dbg_fcn) { tree_statement_list *cmds = dbg_fcn->body (); result = cmds->set_breakpoint (line); } else - error ("unable to find the function requested\n"); + error ("unable to find the function requested\n"); } else error ("one argument when in a function and two when not\n"); @@ -175,13 +175,13 @@ std::string line_number; int line = -1; int nargin = args.length (); - + if (nargin != 1 && nargin != 2) { error ("need one or two arguements\n"); return retval; } - + string_vector argv = args.make_argv ("dbclear"); if (error_state) @@ -191,7 +191,7 @@ { octave_stdout << "2 input arguments\n"; symbol_name = argv[1]; - + octave_stdout << argv[1] << std::endl; line_number = argv[2]; @@ -210,12 +210,12 @@ if (line_number.compare("all") && line_number.compare("ALL")) line = atoi (line_number.c_str ()); - else + 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 (); @@ -261,7 +261,7 @@ } octave_user_function *dbg_fcn = get_user_function (symbol_name); - + if (dbg_fcn) { tree_statement_list *cmds = dbg_fcn->body (); @@ -271,7 +271,7 @@ RowVector vec (lst.length (), 0.0); for (int i = 0; i < lst.length (); i++) - { + { vec(i) = lst(i).double_value (); if (error_state) @@ -294,7 +294,7 @@ @seealso{dbclear, dbstatus, dbstop}") { octave_value retval; - + octave_user_function *dbg_fcn = curr_function; if (dbg_fcn) @@ -307,7 +307,7 @@ if (dbg_stmt) { - octave_stdout << "line " << dbg_stmt->line () << ", "; + octave_stdout << "line " << dbg_stmt->line () << ", "; octave_stdout << "column " << dbg_stmt->column () << std::endl; } else @@ -320,8 +320,8 @@ } // Copied and modified from the do_type command in help.cc -// Maybe we could share some code? -void +// Maybe we could share some code? +void do_dbtype(std::ostream& os, const std::string& name, int start, int end) { std::string ff = fcn_file_in_path (name); @@ -329,15 +329,15 @@ if (! ff.empty ()) { std::ifstream fs (ff.c_str (), std::ios::in); - + if (fs) - { + { char ch; int line = 1; - + if (line >= start && line <= end) os << line << "\t"; - + while (fs.get (ch)) { if (line >= start && line <= end) @@ -349,11 +349,11 @@ { line++; if (line >= start && line <= end) - os << line << "\t"; + os << line << "\t"; } } } - else + else os << "unable to open `" << ff << "' for reading!\n"; } else @@ -370,10 +370,10 @@ { octave_value retval; octave_user_function *dbg_fcn; - + int nargin = args.length (); string_vector argv = args.make_argv ("dbtype"); - + if (! error_state) { switch (nargin) @@ -382,99 +382,101 @@ dbg_fcn = get_user_function (); if (dbg_fcn) - do_dbtype(octave_stdout,dbg_fcn->function_name (), 0, INT_MAX); + do_dbtype (octave_stdout, dbg_fcn->function_name (), 0, INT_MAX); else - error("must be in a user function to give no arguments to dbtype\n"); + error ("must be in a user function to give no arguments to dbtype\n"); + break; - break; - case 1: // (dbtype func) || (dbtype start:end) + case 1: // (dbtype func) || (dbtype start:end) dbg_fcn = get_user_function (argv[1].c_str ()); if (dbg_fcn) - do_dbtype(octave_stdout,dbg_fcn->function_name (), 0, INT_MAX); + do_dbtype (octave_stdout, dbg_fcn->function_name (), 0, INT_MAX); else { dbg_fcn = get_user_function (""); if (dbg_fcn) { - char *str = (char *)malloc(strlen(argv[1].c_str ()) + 1); + char *str = malloc (strlen (argv[1].c_str ()) + 1); if (str) - memcpy(str, argv[1].c_str (), strlen(argv[1].c_str ()) + 1); - else - error("croaked\n"); - - char *ind = index(str,':'); - + memcpy (str, argv[1].c_str (), + strlen (argv[1].c_str ()) + 1); + else + error ("croaked\n"); + + char *ind = strchr (str, ':'); + if (ind) *ind = '\0'; else { - free(str); - error("if you specify lines it must be like `start:end`"); + free (str); + error ("if you specify lines it must be like `start:end`"); } ind++; - - int start = atoi(str); - int end = atoi(ind); - - free(str); + + int start = atoi (str); + int end = atoi (ind); + + free (str); str = NULL; ind = NULL; - + octave_stdout << "got start and end\n"; - + if (start > end) error("the start line must be less than the end line\n"); - + octave_stdout << "doing dbtype\n"; - do_dbtype(octave_stdout, dbg_fcn->function_name (), start, end); + do_dbtype (octave_stdout, dbg_fcn->function_name (), start, end); octave_stdout << "did dbtype\n"; } } break; - case 2: // (dbtype func start:end) + + case 2: // (dbtype func start:end) dbg_fcn = get_user_function (argv[1].c_str ()); if (dbg_fcn) { - - char *str = (char *)malloc(strlen(argv[2].c_str ()) + 1); + + char *str = malloc (strlen (argv[2].c_str ()) + 1); if (str) - memcpy(str, argv[2].c_str (), strlen(argv[2].c_str ()) + 1); + memcpy (str, argv[2].c_str (), strlen (argv[2].c_str ()) + 1); else - error("not enough memory\n"); + error ("not enough memory\n"); - - char *ind = index(str,':'); + + char *ind = strchr (str, ':'); if (ind) *ind = '\0'; else { - free(str); - error("if you specify lines it must be like `start:end`"); + free (str); + error ("if you specify lines it must be like `start:end`"); } ind++; - int start = atoi(str); - int end = atoi(ind); + int start = atoi (str); + int end = atoi (ind); - free(str); - ind = NULL; - str = NULL; + free (str); + ind = NULL; + str = NULL; if (start > end) - error("the start line must be less than the end line\n"); + error ("the start line must be less than the end line\n"); - do_dbtype(octave_stdout, dbg_fcn->function_name (), start, end); + do_dbtype (octave_stdout, dbg_fcn->function_name (), start, end); } + break; - break; default: - error("unacceptable number of arguments\n"); + error ("unacceptable number of arguments\n"); } }