changeset 3019:92aa3d651723

[project @ 1997-06-03 22:07:16 by jwe]
author jwe
date Tue, 03 Jun 1997 22:10:41 +0000
parents 5708b8bb4f06
children f491f232cb09
files src/input.cc src/input.h src/load-save.cc src/octave.cc src/toplev.h
diffstat 5 files changed, 142 insertions(+), 146 deletions(-) [+]
line wrap: on
line diff
--- a/src/input.cc
+++ b/src/input.cc
@@ -76,17 +76,26 @@
 // String printed before echoed input (enabled by --echo-input).
 string Vps4;
 
+// Echo commands as they are executed?
+//
+//   1  ==>  echo commands read from script files
+//   2  ==>  echo commands from functions
+//   4  ==>  echo commands read from command line
+//
+// more than one state can be active at once.
+int Vecho_executing_commands;
+
 // Character to append after successful command-line completion attempts.
 static char Vcompletion_append_char;
 
 // Global pointer for eval().
 string current_eval_string;
 
-// Nonzero means get input from current_eval_string.
-int get_input_from_eval_string = 0;
+// TRUE means get input from current_eval_string.
+bool get_input_from_eval_string = false;
 
-// Nonzero means we're parsing a function file.
-int reading_fcn_file = 0;
+// TRUE means we're parsing a function file.
+bool reading_fcn_file = false;
 
 // Simple name of function file we are reading.
 string curr_fcn_file_name;
@@ -94,17 +103,17 @@
 // Full name of file we are reading.
 string curr_fcn_file_full_name;
 
-// Nonzero means we're parsing a script file.
-int reading_script_file = 0;
+// TRUE means we're parsing a script file.
+bool reading_script_file = false;
 
 // If we are reading from an M-file, this is it.
 FILE *ff_instream = 0;
 
-// Nonzero means this is an interactive shell.
-int interactive = 0;
+// TRUE means this is an interactive shell.
+bool interactive = false;
 
-// Nonzero means the user forced this shell to be interactive (-i).
-int forced_interactive = 0;
+// TRUE means the user forced this shell to be interactive (-i).
+bool forced_interactive = false;
 
 // Should we issue a prompt?
 int promptflag = 1;
@@ -787,6 +796,14 @@
   return status;
 }
 
+static int
+echo_executing_commands (void)
+{
+  Vecho_executing_commands = check_preference ("echo_executing_commands"); 
+
+  return 0;
+}
+
 void
 symbols_of_input (void)
 {
@@ -801,6 +818,10 @@
 
   DEFVAR (completion_append_char, " ", 0, completion_append_char,
     "the string to append after successful command-line completion attempts");
+
+  DEFVAR (echo_executing_commands, static_cast<double> (ECHO_OFF), 0,
+	  echo_executing_commands,
+    "echo commands as they are executed");
 }
 
 /*
--- a/src/input.h
+++ b/src/input.h
@@ -36,11 +36,11 @@
 // Global pointer for eval().
 extern string current_eval_string;
 
-// Nonzero means get input from current_eval_string.
-extern int get_input_from_eval_string;
+// TRUE means get input from current_eval_string.
+extern bool get_input_from_eval_string;
 
-// Nonzero means we're parsing a function file.
-extern int reading_fcn_file;
+// TRUE means we're parsing a function file.
+extern bool reading_fcn_file;
 
 // Simple name of function file we are reading.
 extern string curr_fcn_file_name;
@@ -48,17 +48,17 @@
 // Full name of file we are reading.
 extern string curr_fcn_file_full_name;
 
-// Nonzero means we're parsing a script file.
-extern int reading_script_file;
+// TRUE means we're parsing a script file.
+extern bool reading_script_file;
 
 // If we are reading from an M-file, this is it.
 extern FILE *ff_instream;
 
-// Nonzero means this is an interactive shell.
-extern int interactive;
+// TRUE means this is an interactive shell.
+extern bool interactive;
 
-// Nonzero means the user forced this shell to be interactive (-i).
-extern int forced_interactive;
+// TRUE means the user forced this shell to be interactive (-i).
+extern bool forced_interactive;
 
 // Should we issue a prompt?
 extern int promptflag;
@@ -75,6 +75,16 @@
 
 extern string Vps4;
 
+enum echo_state
+{
+  ECHO_OFF = 0,
+  ECHO_SCRIPTS = 1,
+  ECHO_FUNCTIONS = 2,
+  ECHO_CMD_LINE = 4
+};
+
+extern int Vecho_executing_commands;
+
 #endif
 
 /*
--- a/src/load-save.cc
+++ b/src/load-save.cc
@@ -78,7 +78,7 @@
     LS_UNKNOWN,
   };
 
-// Return nonzero if S is a valid identifier.
+// Return TRUE if S is a valid identifier.
 
 static bool
 valid_identifier (const char *s)
@@ -103,8 +103,8 @@
 // functions that are already available?
 
 // Install a variable with name NAME and the value specified TC in the
-// symbol table.  If FORCE is nonzero, replace any existing definition
-// for NAME.  If GLOBAL is nonzero, make the variable global.
+// symbol table.  If FORCE is TRUE, replace any existing definition
+// for NAME.  If GLOBAL is TRUE, make the variable global.
 //
 // Assumes TC is defined.
 
@@ -116,10 +116,10 @@
 
   symbol_record *lsr = curr_sym_tab->lookup (name);
 
-  int is_undefined = 1;
-  int is_variable = 0;
-  int is_function = 0;
-  int is_global = 0;
+  bool is_undefined = true;
+  bool is_variable = false;
+  bool is_function = false;
+  bool is_global = false;
 
   if (lsr)
     {
@@ -332,16 +332,16 @@
 }
 
 // Match KEYWORD on stream IS, placing the associated value in VALUE,
-// returning 1 if successful and 0 otherwise.
+// returning TRUE if successful and FALSE otherwise.
 //
 // Input should look something like:
 //
 //  [ \t]*keyword[ \t]*int-value.*\n
 
-static int
+static bool
 extract_keyword (istream& is, const char *keyword, int& value)
 {
-  int status = 0;
+  bool status = false;
   value = 0;
 
   char c;
@@ -374,7 +374,7 @@
 	      if (c != '\n')
 		is >> value;
 	      if (is)
-		status = 1;
+		status = true;
 	      while (is.get (c) && c != '\n')
 		; // Skip to beginning of next line;
 	      break;
@@ -386,7 +386,7 @@
 
 // Extract one value (scalar, matrix, string, etc.) from stream IS and
 // place it in TC, returning the name of the variable.  If the value
-// is tagged as global in the file, return nonzero in GLOBAL.
+// is tagged as global in the file, return TRUE in GLOBAL.
 //
 // FILENAME is used for error messages.
 //
@@ -463,7 +463,7 @@
 // arbitrary comments, etc.  Someone should fix that.
 
 static char *
-read_ascii_data (istream& is, const string& filename, int& global,
+read_ascii_data (istream& is, const string& filename, bool& global,
 		 octave_value& tc)
 {
   // Read name for this entry or break on EOF.
@@ -521,7 +521,8 @@
 	}
       else if (strncmp (ptr, "matrix", 6) == 0)
 	{
-	  int nr = 0, nc = 0;
+	  int nr = 0;
+	  int nc = 0;
 
 	  if (extract_keyword (is, "rows", nr) && nr >= 0
 	      && extract_keyword (is, "columns", nc) && nc >= 0)
@@ -554,7 +555,8 @@
 	}
       else if (strncmp (ptr, "complex matrix", 14) == 0)
 	{
-	  int nr = 0, nc = 0;
+	  int nr = 0;
+	  int nc = 0;
 
 	  if (extract_keyword (is, "rows", nr) && nr > 0
 	      && extract_keyword (is, "columns", nc) && nc > 0)
@@ -658,8 +660,8 @@
 
 // Extract one value (scalar, matrix, string, etc.) from stream IS and
 // place it in TC, returning the name of the variable.  If the value
-// is tagged as global in the file, return nonzero in GLOBAL.  If SWAP
-// is nonzero, swap bytes after reading.
+// is tagged as global in the file, return TRUE in GLOBAL.  If SWAP
+// is TRUE, swap bytes after reading.
 //
 // The data is expected to be in the following format:
 //
@@ -727,14 +729,15 @@
 // FILENAME is used for error messages.
 
 static char *
-read_binary_data (istream& is, int swap,
+read_binary_data (istream& is, bool swap,
 		  oct_mach_info::float_format fmt,
-		  const string& filename, int& global,
+		  const string& filename, bool& global,
 		  octave_value& tc, char *&doc)
 {
   char tmp = 0;
 
-  FOUR_BYTE_INT name_len = 0, doc_len = 0;
+  FOUR_BYTE_INT name_len = 0;
+  FOUR_BYTE_INT doc_len = 0;
   char *name = 0;
 
   doc = 0;
@@ -1056,14 +1059,14 @@
 }
 
 // Read LEN elements of data from IS in the format specified by
-// PRECISION, placing the result in DATA.  If SWAP is nonzero, swap
+// PRECISION, placing the result in DATA.  If SWAP is TRUE, swap
 // the bytes of each element before copying to DATA.  FLT_FMT
 // specifies the format of the data if we are reading floating point
 // numbers.
 
 static void
 read_mat_binary_data (istream& is, double *data, int precision,
-		      int len, int swap,
+		      int len, bool swap,
 		      oct_mach_info::float_format flt_fmt)
 {
   switch (precision)
@@ -1098,12 +1101,12 @@
 }
 
 static int
-read_mat_file_header (istream& is, int& swap, FOUR_BYTE_INT& mopt, 
+read_mat_file_header (istream& is, bool& swap, FOUR_BYTE_INT& mopt, 
 		      FOUR_BYTE_INT& nr, FOUR_BYTE_INT& nc,
 		      FOUR_BYTE_INT& imag, FOUR_BYTE_INT& len,
 		      int quiet = 0)
 {
-  swap = 0;
+  swap = false;
 
   // We expect to fail here, at the beginning of a record, so not
   // being able to read another mopt value should not result in an
@@ -1135,12 +1138,12 @@
 // Gag me.
 
   if (oct_mach_info::words_big_endian () && mopt == 0)
-    swap = 1;
+    swap = true;
 
   // mopt is signed, therefore byte swap may result in negative value.
 
   if (mopt > 9999 || mopt < 0)
-    swap = 1;
+    swap = true;
 
   if (swap)
     {
@@ -1257,7 +1260,11 @@
   Matrix re;
   oct_mach_info::float_format flt_fmt = oct_mach_info::unknown;
   char *name = 0;
-  int swap = 0, type = 0, prec = 0, mach = 0, dlen = 0;
+  bool swap = false;
+  int type = 0;
+  int prec = 0;
+  int mach = 0;
+  int dlen = 0;
 
   FOUR_BYTE_INT mopt, nr, nc, imag, len;
 
@@ -1353,7 +1360,7 @@
   return 0;
 }
 
-// Return nonzero if NAME matches one of the given globbing PATTERNS.
+// Return TRUE if NAME matches one of the given globbing PATTERNS.
 
 static bool
 matches_patterns (const string_vector& patterns, int pat_idx,
@@ -1370,9 +1377,9 @@
 }
 
 static int
-read_binary_file_header (istream& is, int& swap,
+read_binary_file_header (istream& is, bool& swap,
 			 oct_mach_info::float_format& flt_fmt,
-			 int quiet = 0) 
+			 bool quiet = false)
 {
   int magic_len = 10;
   char magic [magic_len+1];
@@ -1417,10 +1424,11 @@
       return retval;
     }
 
-  int swap;
   oct_mach_info::float_format flt_fmt = oct_mach_info::unknown;
 
-  if (read_binary_file_header (file, swap, flt_fmt, 1) == 0)
+  bool swap = false;
+
+  if (read_binary_file_header (file, swap, flt_fmt, true) == 0)
     retval = LS_BINARY;
   else
     {
@@ -1469,9 +1477,9 @@
 }
 
 static octave_value_list
-do_load (istream& stream, const string& orig_fname, int force,
+do_load (istream& stream, const string& orig_fname, bool force,
 	 load_save_format format, oct_mach_info::float_format flt_fmt,
-	 int list_only, int swap, int verbose, const string_vector& argv,
+	 bool list_only, bool swap, bool verbose, const string_vector& argv,
 	 int argv_idx, int argc, int nargout)
 {
   octave_value_list retval;
@@ -1480,7 +1488,7 @@
   int count = 0;
   for (;;)
     {
-      int global = 0;
+      bool global = false;
       octave_value tc;
 
       char *name = 0;
@@ -1612,31 +1620,30 @@
   if (error_state)
     return retval;
 
-  int force = 0;
-
   // It isn't necessary to have the default load format stored in a
   // user preference variable since we can determine the type of file
   // as we are reading.
 
   load_save_format format = LS_UNKNOWN;
 
-  int list_only = 0;
-  int verbose = 0;
+  bool force = false;
+  bool list_only = false;
+  bool verbose = false;
 
   int i;
   for (i = 1; i < argc; i++)
     {
       if (argv[i] == "-force" || argv[i] == "-f")
 	{
-	  force++;
+	  force = true;
 	}
       else if (argv[i] == "-list" || argv[i] == "-l")
 	{
-	  list_only = 1;
+	  list_only = true;
 	}
       else if (argv[i] == "-verbose" || argv[i] == "-v")
 	{
-	  verbose = 1;
+	  verbose = true;
 	}
       else if (argv[i] == "-ascii" || argv[i] == "-a")
 	{
@@ -1664,7 +1671,7 @@
 
   oct_mach_info::float_format flt_fmt = oct_mach_info::unknown;
 
-  int swap = 0;
+  bool swap = false;
 
   if (argv[i] == "-")
     {
@@ -1727,9 +1734,9 @@
   return retval;
 }
 
-// Return nonzero if PATTERN has any special globbing chars in it.
-
-static int
+// Return TRUE if PATTERN has any special globbing chars in it.
+
+static bool
 glob_pattern_p (const string& pattern)
 {
   int open = 0;
@@ -1744,7 +1751,7 @@
 	{
 	case '?':
 	case '*':
-	  return 1;
+	  return true;
 
 	case '[':	// Only accept an open brace if there is a close
 	  open++;	// brace to match it.  Bracket expressions must be
@@ -1752,19 +1759,19 @@
 
 	case ']':
 	  if (open)
-	    return 1;
+	    return true;
 	  continue;
 	  
 	case '\\':
 	  if (i == len - 1)
-	    return 0;
+	    return false;
 
 	default:
 	  continue;
 	}
     }
 
-  return 0;
+  return false;
 }
 
 // MAX_VAL and MIN_VAL are assumed to have integral values even though
@@ -1798,7 +1805,7 @@
 static bool
 save_binary_data (ostream& os, const octave_value& tc,
 		  const string& name, const string& doc,
-		  int mark_as_global, int save_as_floats) 
+		  bool mark_as_global, bool save_as_floats) 
 {
   FOUR_BYTE_INT name_len = name.length ();
 
@@ -1993,7 +2000,7 @@
     {
       unwind_protect::begin_frame ("save_mat_binary_data");
       unwind_protect_int (Vimplicit_str_to_num_ok);
-      Vimplicit_str_to_num_ok = 1;
+      Vimplicit_str_to_num_ok = true;
       Matrix m = tc.matrix_value ();
       os.write (m.data (), 8 * len);
       unwind_protect::run_frame ("save_mat_binary_data");
@@ -2101,7 +2108,7 @@
 // flag MARK_AS_GLOBAL on stream OS in the plain text format described
 // above for load_ascii_data.  If NAME is empty, the name: line is not
 // generated.  PRECISION specifies the number of decimal digits to print. 
-// If STRIP_NAN_AND_INF is nonzero, rows containing NaNs are deleted,
+// If STRIP_NAN_AND_INF is TRUE, rows containing NaNs are deleted,
 // and Infinite values are converted to +/-OCT_RBV (A Real Big Value,
 // but not so big that gnuplot can't handle it when trying to compute
 // axis ranges, etc.).
@@ -2276,11 +2283,11 @@
 }
 
 // Save variables with names matching PATTERN on stream OS in the
-// format specified by FMT.  If SAVE_BUILTINS is nonzero, also save
+// format specified by FMT.  If SAVE_BUILTINS is TRUE, also save
 // builtin variables with names that match PATTERN.
 
 static int
-save_vars (ostream& os, const string& pattern, int save_builtins,
+save_vars (ostream& os, const string& pattern, bool save_builtins,
 	   load_save_format fmt, int save_as_floats)
 {
   int count;
@@ -2357,8 +2364,8 @@
 
 static void
 save_vars (const string_vector& argv, int argv_idx, int argc,
-	   ostream& os, int save_builtins, load_save_format fmt,
-	   int save_as_floats) 
+	   ostream& os, bool save_builtins, load_save_format fmt,
+	   bool save_as_floats) 
 {
   write_binary_header (os, fmt);
 
@@ -2397,7 +2404,7 @@
 
   if (file)
     {
-      save_vars (string_vector (), 0, 0, file, 0, format, 0);
+      save_vars (string_vector (), 0, 0, file, false, format, false);
       message (0, "save to `%s' complete", fname);
     }
   else
@@ -2422,9 +2429,9 @@
   // Here is where we would get the default save format if it were
   // stored in a user preference variable.
 
-  int save_builtins = 0;
-
-  int save_as_floats = 0;
+  bool save_builtins = false;
+
+  bool save_as_floats = false;
 
   load_save_format format = get_default_save_format ();
 
@@ -2446,11 +2453,11 @@
       else if (argv[i] == "-float-binary" || argv[i] == "-f")
 	{
 	  format = LS_BINARY;
-	  save_as_floats = 1;
+	  save_as_floats = true;
 	}
       else if (argv[i] == "-save-builtins")
 	{
-	  save_builtins = 1;
+	  save_builtins = true;
 	}
       else
 	break;
@@ -2517,12 +2524,12 @@
 
 // If TC is matrix, save it on stream OS in a format useful for
 // making a 3-dimensional plot with gnuplot.  If PARAMETRIC is
-// nonzero, assume a parametric 3-dimensional plot will be generated.
+// TRUE, assume a parametric 3-dimensional plot will be generated.
 
 bool
 save_three_d (ostream& os, const octave_value& tc, bool parametric)
 {
-  int fail = 0;
+  bool fail = false;
 
   int nr = tc.rows ();
   int nc = tc.columns ();
@@ -2568,7 +2575,7 @@
   else
     {
       ::error ("for now, I can only save real matrices in 3D format");
-      fail = 1;
+      fail = true;
     }
 
   return (os && ! fail);
--- a/src/octave.cc
+++ b/src/octave.cc
@@ -47,6 +47,7 @@
 #include "file-stat.h"
 #include "lo-error.h"
 #include "oct-env.h"
+#include "pathsearch.h"
 #include "str-vec.h"
 
 #include <defaults.h>
@@ -60,7 +61,6 @@
 #include "ops.h"
 #include "toplev.h"
 #include "parse.h"
-#include "pathsearch.h"
 #include "pt-plot.h"
 #include "procstream.h"
 #include "prog-args.h"
@@ -79,15 +79,6 @@
 #define atexit on_exit
 #endif
 
-// Don't redefine the variables if glibc already has.
-#if defined (HAVE_PROGRAM_INVOCATION_NAME) || defined (WITH_KPATHSEARCH)
-extern char *program_invocation_name;
-extern char *program_invocation_short_name;
-#else
-char *program_invocation_name;
-char *program_invocation_short_name;
-#endif
-
 // The command-line options.
 static string_vector octave_argv;
 
@@ -99,15 +90,15 @@
 // (--norc; --no-site-file; -f)
 static bool read_site_files = true;
 
-// Nonzero means we don't print the usual startup message.
+// TRUE means we don't print the usual startup message.
 // (--quiet; --silent; -q)
 static bool inhibit_startup_message = false;
 
-// Nonzero means we turn on compatibility options.
+// TRUE means we turn on compatibility options.
 // (--traditional)
 static bool traditional = false;
 
-// If nonzero, print verbose info in some cases.
+// If TRUE, print verbose info in some cases.
 // (--verbose; -V)
 static bool verbose_flag = false;
 
@@ -152,7 +143,7 @@
     { "traditional",      prog_args::no_arg,       0, TRADITIONAL_OPTION },
     { "verbose",          prog_args::no_arg,       0, 'V' },
     { "version",          prog_args::no_arg,       0, 'v' },
-    { 0,                  0,                 0, 0 }
+    { 0,                  0,                       0, 0 }
   };
 
 // Store the command-line options for later use.
@@ -160,18 +151,6 @@
 static void
 intern_argv (int argc, char **argv)
 {
-  octave_env::set_program_name (argv[0]);
-
-  // XXX FIXME XXX -- Kpathsea needs this.
-
-#if ! defined (HAVE_PROGRAM_INVOCATION_NAME)
-  program_invocation_name
-    = strsave (octave_env::get_program_invocation_name () . c_str ());
-
-  program_invocation_short_name
-    = strsave (octave_env::get_program_name () . c_str ());
-#endif
-
   if (argc > 1)
     {
       // Skip program name in argv.
@@ -219,9 +198,9 @@
   // XXX FIXME XXX -- need to make it possible to set this in startup
   // files.
 
-  unwind_protect_int (input_from_startup_file);
+  unwind_protect_bool (input_from_startup_file);
 
-  input_from_startup_file = 1;
+  input_from_startup_file = true;
 
   int verbose = (verbose_flag && ! inhibit_startup_message);
 
@@ -367,9 +346,11 @@
 int
 main (int argc, char **argv)
 {
+  octave_env::set_program_name (argv[0]);
+
   // The order of these calls is important.  The call to
   // install_defaults must come before install_builtins because
-  // default variable values must be available for the varaibles to be
+  // default variable values must be available for the variables to be
   // installed, and the call to install_builtins must come before the
   // options are processed because some command line options override
   // defaults by calling bind_builtin_variable.
@@ -420,7 +401,7 @@
 	  break;
 
 	case 'i':
-	  forced_interactive = 1;
+	  forced_interactive = true;
 	  break;
 
 	case 'p':
@@ -463,7 +444,7 @@
 	  break;
 
 	case NO_LINE_EDITING_OPTION:
-	  line_editing = 0;
+	  line_editing = false;
 	  break;
 
 	case NO_SITE_FILE_OPTION:
@@ -517,10 +498,13 @@
   // script.
 
   int last_arg_idx = args.optind ();
+
   int remaining_args = argc - last_arg_idx;
+
   if (remaining_args > 0)
     {
-      reading_script_file = 1;
+      reading_script_file = true;
+
       curr_fcn_file_name = argv[last_arg_idx];
       curr_fcn_file_full_name = curr_fcn_file_name;
 
@@ -528,7 +512,7 @@
 
       if (infile)
 	{
-	  input_from_command_line_file = 1;
+	  input_from_command_line_file = true;
 
 	  bind_builtin_variable ("program_invocation_name",
 				 curr_fcn_file_name);
@@ -575,7 +559,7 @@
     }
 
   if (! interactive)
-    line_editing = 0;
+    line_editing = false;
 
   int retval = main_loop ();
 
--- a/src/toplev.h
+++ b/src/toplev.h
@@ -36,44 +36,18 @@
 extern void
 clean_up_and_exit (int) GCC_ATTR_NORETURN;
 
-extern void
-parse_and_execute (FILE *f);
-
-extern void
-parse_and_execute (const string& s, bool verbose = false,
-		   const char *warn_for = 0);
-
-extern octave_value
-eval_string (const string&, bool silent, int& parse_status);
-
 extern int
 main_loop (void);
 
 extern void
 do_octave_atexit (void);
 
-// Nonzero means we are using readline.
-extern int line_editing;
-
-// Nonzero means we printed messages about reading startup files.
-extern int reading_startup_message_printed;
-
-// Nonzero means we are exiting via the builtin exit or quit functions.
-extern int quitting_gracefully;
-
 // Current command to execute.
 extern tree_statement_list *global_command;
 
 // Pointer to function that is currently being evaluated.
 extern octave_user_function *curr_function;
 
-// Nonzero means input is coming from startup file.
-extern int input_from_startup_file;
-
-// Nonzero means that input is coming from a file that was named on
-// the command line.
-extern int input_from_command_line_file;
-
 #endif
 
 /*