changeset 1355:94697d007075

[project @ 1995-09-05 20:04:15 by jwe]
author jwe
date Tue, 05 Sep 1995 20:07:21 +0000
parents 5b54091471dd
children 8b51c1738882
files src/Makefile.in src/dirfns.cc src/lex.l src/octave.cc src/pr-output.h src/pt-const.cc src/pt-const.h src/strfns.cc src/tc-rep.h src/toplev.h
diffstat 10 files changed, 316 insertions(+), 257 deletions(-) [+]
line wrap: on
line diff
--- a/src/Makefile.in	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/Makefile.in	Tue Sep 05 20:07:21 1995 +0000
@@ -61,14 +61,15 @@
 	defun-int.h dirfns.h dynamic-ld.h error.h file-io.h fnmatch.h \
 	getopt.h gripes.h help.h idx-vector.h input.h lex.h \
 	load-save.h mappers.h missing-math.h octave.h octave-hist.h \
-	oct-map.h oct-obj.h pager.h parse.h pathsearch.h pr-output.h \
-	procstream.h sighandlers.h statdefs.h symtab.h sysdep.h \
-	systime.h token.h tree-base.h tree-cmd.h tree-const.h \
-	tree-expr.h tree-misc.h	tree-plot.h tc-inlines.h tc-rep.h \
-	unwind-prot.h user-prefs.h utils.h variables.h version.h \
-	xdiv.h xpow.h Map.h SLStack.h Stack.h
+	oct-map.h oct-obj.h oct-str.h pager.h parse.h pathlen.h \
+	pathsearch.h pr-output.h procstream.h sighandlers.h \
+	statdefs.h symtab.h sysdep.h sysdir.h systime.h syswait.h \
+	token.h tree-base.h tree-cmd.h tree-const.h tree-expr.h \
+	tree-misc.h tree-plot.h tc-inlines.h tc-rep.h unwind-prot.h \
+	user-prefs.h utils.h variables.h version.h xdiv.h xpow.h \
+	Map.h SLStack.h Stack.h 
 
-TI_SRC := Array-tc.cc Map-tc.cc DLList-fi.cc \
+TI_SRC := Array-string.cc Array-tc.cc Map-tc.cc DLList-fi.cc \
 	SLList-expr.cc SLList-misc.cc SLList-plot.cc SLList-tc.cc \
 	SLStack-i.cc SLStack-pc.cc SLStack-sym.cc SLStack-tok.cc \
 	SLStack-tm.cc SLStack-ue.cc SLStack-ui.cc
@@ -79,8 +80,8 @@
 	dynamic-ld.cc erf.c erfc.c error.cc file-io.cc fnmatch.c \
 	getopt.c getopt1.c gripes.cc help.cc idx-vector.cc \
 	input.cc lex.l load-save.cc mappers.cc octave.cc \
-	octave-hist.cc oct-map.cc oct-obj.cc pager.cc parse.y \
-	pr-output.cc procstream.cc resource.cc sighandlers.cc \
+	octave-hist.cc oct-map.cc oct-obj.cc oct-str.cc pager.cc \
+	parse.y pr-output.cc procstream.cc resource.cc sighandlers.cc \
 	strcasecmp.c strncase.c strfns.cc strftime.c symtab.cc \
 	sysdep.cc tempname.c timefns.cc tempnam.c token.cc \
 	tree-base.cc tree-cmd.cc tree-const.cc tree-expr.cc \
--- a/src/dirfns.cc	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/dirfns.cc	Tue Sep 05 20:07:21 1995 +0000
@@ -44,44 +44,22 @@
 #include <cstdlib>
 #include <cstring>
 
-#include <sys/types.h>
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
 #include <strstream.h>
-#include <sys/param.h>
 
-// This mess suggested by the autoconf manual.
-// unistd.h defines _POSIX_VERSION on POSIX.1 systems.
-#if defined (HAVE_DIRENT_H) || defined (_POSIX_VERSION)
-#include <dirent.h>
-#define NLENGTH(dirent) (strlen((dirent)->d_name))
-#else
-#define dirent direct
-#define NLENGTH(dirent) ((dirent)->d_namlen)
-#if defined (HAVE_SYS_NDIR_H)
-#include <sys/ndir.h>
-#endif
-#if defined (HAVE_SYS_DIR_H)
-#include <sys/dir.h>
-#endif
-#if defined (HAVE_NDIR_H)
-#include <ndir.h>
-#endif
-#endif
-
+#include "defun.h"
+#include "dirfns.h"
+#include "error.h"
+#include "oct-obj.h"
+#include "octave.h"
+#include "pager.h"
+#include "pathlen.h"
+#include "procstream.h"
 #include "statdefs.h"
-#include "procstream.h"
+#include "sysdep.h"
+#include "sysdir.h"
 #include "tree-const.h"
 #include "tree-plot.h"
-#include "oct-obj.h"
-#include "sysdep.h"
-#include "octave.h"
-#include "dirfns.h"
-#include "pager.h"
-#include "error.h"
 #include "utils.h"
-#include "defun.h"
 
 extern "C"
 {
@@ -89,10 +67,6 @@
 extern char *strerror (int);
 }
 
-#ifndef MAXPATHLEN
-#define MAXPATHLEN 1024
-#endif
-
 // Temp storage for a path.
 static char tdir[MAXPATHLEN];
 
--- a/src/lex.l	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/lex.l	Tue Sep 05 20:07:21 1995 +0000
@@ -38,23 +38,23 @@
 
 #include "SLStack.h"
 
+#include "error.h"
 #include "input.h"
-#include "token.h"
-#include "user-prefs.h"
-#include "variables.h"
+#include "lex.h"
 #include "octave.h"
+#include "parse.h"
 #include "symtab.h"
-#include "error.h"
-#include "utils.h"
+#include "token.h"
 #include "tree-base.h"
+#include "tree-cmd.h"
+#include "tree-const.h"
 #include "tree-expr.h"
-#include "tree-cmd.h"
 #include "tree-misc.h"
 #include "tree-plot.h"
-#include "tree-const.h"
+#include "user-prefs.h"
+#include "utils.h"
+#include "variables.h"
 #include "y.tab.h"
-#include "parse.h"
-#include "lex.h"
 
 // Stack to hold tokens so that we can delete them when the parser is
 // reset and avoid growing forever just because we are stashing some
--- a/src/octave.cc	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/octave.cc	Tue Sep 05 20:07:21 1995 +0000
@@ -27,55 +27,55 @@
 #include <config.h>
 #endif
 
+#include <cassert>
+#include <csetjmp>
+#include <csignal>
+#include <cstdlib>
+#include <cstring>
+#include <ctime>
+
+#include <fstream.h>
+#include <iostream.h>
+#include <strstream.h>
+
+#ifdef HAVE_UNISTD_H
 #include <sys/types.h>
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
 #endif
-#include <sys/stat.h>
-#include <time.h>
+
 #include <pwd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <assert.h>
-#include <iostream.h>
-#include <strstream.h>
-#include <fstream.h>
-
-extern "C"
-{
-#include <setjmp.h>
-}
 
 #include "getopt.h"
 
 #include "lo-error.h"
 
-#include "sighandlers.h"
-#include "variables.h"
-#include "error.h"
+#include "builtins.h"
+#include "defaults.h"
+#include "defun.h"
 #include "dynamic-ld.h"
-#include "tree-misc.h"
-#include "tree-const.h"
-#include "tree-plot.h"
-#include "utils.h"
+#include "error.h"
+#include "file-io.h"
+#include "help.h"
 #include "input.h"
-#include "pager.h"
 #include "lex.h"
-#include "help.h"
+#include "oct-str.h"
+#include "octave-hist.h"
 #include "octave.h"
+#include "pager.h"
 #include "parse.h"
-#include "defaults.h"
-#include "user-prefs.h"
+#include "pathsearch.h"
 #include "procstream.h"
+#include "sighandlers.h"
+#include "statdefs.h"
+#include "sysdep.h"
+#include "tree-const.h"
+#include "tree-misc.h"
+#include "tree-plot.h"
 #include "unwind-prot.h"
-#include "octave-hist.h"
-#include "pathsearch.h"
-#include "builtins.h"
+#include "user-prefs.h"
+#include "utils.h"
+#include "variables.h"
 #include "version.h"
-#include "file-io.h"
-#include "sysdep.h"
-#include "defun.h"
 
 #if !defined (HAVE_ATEXIT) && defined (HAVE_ON_EXIT)
 extern "C" { int on_exit (); }
@@ -132,6 +132,9 @@
 // Nonzero means input is coming from startup file.
 int input_from_startup_file = 0;
 
+// The command-line options.
+Octave_str_obj octave_argv;
+
 // Top level context (?)
 jmp_buf toplevel;
 
@@ -190,11 +193,33 @@
     { 0,                  0,                 0, 0 }
   };
 
+// Store the command-line options for later use.
+
+static void
+intern_argv (int argc, char **argv)
+{
+  if (argc > 1)
+    {
+      octave_argv.resize (argc-1);
+      for (int i = 1; i < argc; i++)
+	octave_argv.elem (i-1) = argv[i];
+    }
+
+  tree_constant *tmp = new tree_constant (octave_argv);
+  bind_builtin_variable ("argv", tmp, 1, 1, 0);
+}
+
 // Initialize some global variables for later use.
 
 static void
 initialize_globals (char *name)
 {
+  raw_prog_name = strsave (name);
+  char *tmp = strrchr (raw_prog_name, '/');
+  prog_name = tmp ? strsave (tmp+1) : strsave (raw_prog_name);
+
+  kpse_set_progname (name);
+
   struct passwd *entry = getpwuid (getuid ());
   if (entry)
     user_name = strsave (entry->pw_name);
@@ -260,11 +285,6 @@
 	putenv (strsave ("TEXMF=" OCTAVE_DATADIR "/octave"));
     }
 
-  raw_prog_name = strsave (name);
-  prog_name = strsave ("octave");
-
-  kpse_set_progname (name);
-
   load_path = default_path ();
 
   info_file = default_info_file ();
@@ -478,7 +498,7 @@
 int
 main (int argc, char **argv)
 {
-// The order of these calls is important, and initialize globals must
+// The order of these calls is important, and initialize_globals must
 // come before the options are processed because some command line
 // options override defaults.
 
@@ -587,14 +607,17 @@
   current_command_number = 1;
 
 // If there is an extra argument, see if it names a file to read.
+// Additional arguments are taken as command line options for the
+// script.
 
   int remaining_args = argc - optind;
-  if (remaining_args > 1)
+  if (remaining_args > 0)
     {
-      usage ();
-    }
-  else if (remaining_args == 1)
-    {
+      if (remaining_args == 1)
+	intern_argv (argc, argv);
+      else
+	intern_argv (remaining_args, argv+optind);
+
       reading_script_file = 1;
       curr_fcn_file_name = argv[optind];
       FILE *infile = get_input_from_file (curr_fcn_file_name);
@@ -608,12 +631,14 @@
     }
   else
     {
-      switch_to_buffer (create_buffer (get_input_from_stdin ()));
-
-// Is input coming from a terminal?  If so, we are probably
-// interactive.
+      // Is input coming from a terminal?  If so, we are probably
+      // interactive.
 
       interactive = (isatty (fileno (stdin)) && isatty (fileno (stdout)));
+
+      intern_argv (argc, argv);
+
+      switch_to_buffer (create_buffer (get_input_from_stdin ()));
     }
 
 // Force input to be echoed if not really interactive, but the user
--- a/src/pr-output.h	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/pr-output.h	Tue Sep 05 20:07:21 1995 +0000
@@ -30,6 +30,7 @@
 class Complex;
 class ComplexMatrix;
 class Range;
+class Octave_str_obj;
 
 extern void octave_print_internal (ostream& os, double d,
 				   int pr_as_read_syntax = 0);
@@ -46,6 +47,9 @@
 extern void octave_print_internal (ostream& os, const Range& r,
 				   int pr_as_read_syntax = 0);
 
+extern void octave_print_internal (ostream& os, Octave_str_obj& s,
+				   int pr_as_read_syntax = 0);
+
 extern void set_format_style (int argc, char **argv);
 
 // XXX FIXME XXX -- these should probably be somewhere else.
--- a/src/pt-const.cc	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/pt-const.cc	Tue Sep 05 20:07:21 1995 +0000
@@ -29,16 +29,18 @@
 #include <config.h>
 #endif
 
-#include <string.h>
+#include <cstring>
+
 #include <iostream.h>
 #include <strstream.h>
 
-#include "tree-const.h"
-#include "user-prefs.h"
-#include "pager.h"
 #include "error.h"
 #include "gripes.h"
 #include "oct-map.h"
+#include "oct-str.h"
+#include "pager.h"
+#include "tree-const.h"
+#include "user-prefs.h"
 
 // The following three variables could be made static members of the
 // tree_constant class.
@@ -310,7 +312,7 @@
   int nr = val.rows ();
   int nc = val.columns ();
   return (val.is_scalar_type ()
-	  || val.is_string ()
+	  || (val.is_string () && nr <= 1)
 	  || (val.is_matrix_type ()
 	      && ((nr == 1 && nc == 1)
 		  || nr == 0
@@ -363,8 +365,9 @@
 // #include <config.h>
 // #endif
 
-#include <ctype.h>
-// #include <string.h>
+#include <cctype>
+// #include <cstring>
+
 #include <fstream.h>
 // #include <iostream.h>
 
@@ -644,7 +647,14 @@
 
 TC_REP::tree_constant_rep (const char *s)
 {
-  string = strsave (s);
+  str_obj = new Octave_str_obj (s);
+  type_tag = string_constant;
+  orig_text = 0;
+}
+
+TC_REP::tree_constant_rep (const Octave_str_obj& s)
+{
+  str_obj = new Octave_str_obj (s);
   type_tag = string_constant;
   orig_text = 0;
 }
@@ -742,7 +752,7 @@
       break;
 
     case string_constant:
-      string = strsave (t.string);
+      str_obj = new Octave_str_obj (*(t.str_obj));
       break;
 
     case complex_matrix_constant:
@@ -786,7 +796,7 @@
       break;
 
     case string_constant:
-      delete [] string;
+      delete str_obj;
       break;
 
     case range_constant:
@@ -851,6 +861,9 @@
       break;
 
     case string_constant:
+      retval = str_obj->num_strings ();
+      break;
+
     case range_constant:
       retval = (columns () > 0);
       break;
@@ -891,7 +904,7 @@
       break;
 
     case string_constant:
-      retval = strlen (string);
+      retval = str_obj->max_length ();
       break;
 
     case range_constant:
@@ -926,31 +939,19 @@
   switch (type_tag)
     {
     case scalar_constant:
-      {
-	double status = (scalar != 0.0);
-	retval = tree_constant (status);
-      }
+      retval = (double) (scalar != 0.0);
       break;
 
     case matrix_constant:
-      {
-	Matrix m = matrix->all ();
-	retval = tree_constant (m);
-      }
+      retval = matrix->all ();
       break;
 
     case complex_scalar_constant:
-      {
-	double status = (*complex_scalar != 0.0);
-	retval = tree_constant (status);
-      }
+      retval = (double) (*complex_scalar != 0.0);
       break;
 
     case complex_matrix_constant:
-      {
-	Matrix m = complex_matrix->all ();
-	retval = tree_constant (m);
-      }
+      retval = complex_matrix->all ();
       break;
 
     default:
@@ -982,31 +983,19 @@
   switch (type_tag)
     {
     case scalar_constant:
-      {
-	double status = (scalar != 0.0);
-	retval = tree_constant (status);
-      }
+      retval = (double) (scalar != 0.0);
       break;
 
     case matrix_constant:
-      {
-	Matrix m = matrix->any ();
-	retval = tree_constant (m);
-      }
+      retval = matrix->any ();
       break;
 
     case complex_scalar_constant:
-      {
-	double status = (*complex_scalar != 0.0);
-	retval = tree_constant (status);
-      }
+      retval = (double) (*complex_scalar != 0.0);
       break;
 
     case complex_matrix_constant:
-      {
-	Matrix m = complex_matrix->any ();
-	retval = tree_constant (m);
-      }
+      retval = complex_matrix->any ();
       break;
 
     default:
@@ -1162,9 +1151,11 @@
 	if (flag < 0)
 	  warn_implicit_conversion ("string", "real scalar");
 
-	int len = strlen (string);
-	if (flag && (len == 1 || (len > 1 && user_pref.do_fortran_indexing)))
-	  retval = toascii ((int) string[0]);
+	int len = str_obj->max_length ();
+	if (flag
+	    && ((str_obj->num_strings () == 1 && len == 1)
+		|| (len > 1 && user_pref.do_fortran_indexing)))
+	  retval = toascii ((int) str_obj->elem (0, 0));
 	else
 	  gripe_invalid_conversion ("string", "real scalar");
       }
@@ -1235,17 +1226,24 @@
 
 	if (flag)
 	  {
-	    int len = strlen (string);
-
-	    if (len > 0)
+	    int nr = str_obj->num_strings ();
+	    int nc = str_obj->max_length ();
+
+	    if (nr > 0 && nc > 0)
 	      {
-		retval.resize (1, len);
-
-		for (int i = 0; i < len; i++)
-		  retval.elem (0, i) = toascii ((int) string[i]);
+		retval.resize (nr, nc);
+
+		for (int i = 0; i < nr; i++)
+		  {
+		    for (int j = 0; j < nc; j++)
+		      {
+			int c = (int) str_obj->elem (i, j);
+			retval.elem (i, j) = toascii (c);
+		      }
+		  }
 	      }
 	    else
-	      retval = Matrix ();
+	      retval = Matrix ();  // XXX FIXME XXX -- is this correct?
 	  }
 	else
 	  gripe_invalid_conversion ("string", "real matrix");
@@ -1303,9 +1301,11 @@
 	if (flag < 0)
 	  warn_implicit_conversion ("string", "complex scalar");
 
-	int len = strlen (string);
-	if (flag && (len == 1 || (len > 1 && user_pref.do_fortran_indexing)))
-	  retval = toascii ((int) string[0]);
+	int len = str_obj->max_length ();
+	if (flag
+	    && ((str_obj->num_strings () == 1 && len == 1)
+		|| (len > 1 && user_pref.do_fortran_indexing)))
+	  retval = toascii ((int) str_obj->elem (0, 0));
 	else
 	  gripe_invalid_conversion ("string", "complex scalar");
       }
@@ -1363,17 +1363,22 @@
 
 	if (flag)
 	  {
-	    int len = strlen (string);
-
-	    retval.resize (1, len);
-
-	    if (len > 1)
+	    int nr = str_obj->num_strings ();
+	    int nc = str_obj->max_length ();
+
+	    if (nr > 0 && nc > 0)
 	      {
-		for (int i = 0; i < len; i++)
-		  retval.elem (0, i) = toascii ((int) string[i]);
+		retval.resize (nr, nc);
+
+		for (int i = 0; i < nr; i++)
+		  {
+		    for (int j = 0; j < nc; j++)
+		      {
+			int c = (int) str_obj->elem (i, j);
+			retval.elem (i, j) = toascii (c);
+		      }
+		  }
 	      }
-	    else if (len == 1)
-	      retval.elem (0, 0) = toascii ((int) string[0]);
 	    else
 	      panic_impossible ();
 	  }
@@ -1394,11 +1399,23 @@
   return retval;
 }
 
-char *
+Octave_str_obj
+TC_REP::all_strings (void) const
+{
+  if (type_tag == string_constant)
+    return *str_obj;
+  else
+    {
+      gripe_invalid_conversion (type_as_string (), "string");
+      return 0;
+    }
+}
+
+const char *
 TC_REP::string_value (void) const
 {
   if (type_tag == string_constant)
-    return string;
+    return str_obj->elem (0).c_str ();  // XXX FIXME??? XXX
   else
     {
       gripe_invalid_conversion (type_as_string (), "string");
@@ -1553,7 +1570,7 @@
 	    char s[2];
 	    s[0] = (char) i;
 	    s[1] = '\0';
-	    retval = tree_constant (s);
+	    retval = s;
 	  }
       }
       break;
@@ -1564,40 +1581,51 @@
 	if (rows () == 0 && columns () == 0)
 	  {
 	    char s = '\0';
-	    retval = tree_constant (&s);
+	    retval = &s;
 	  }
 	else
 	  {
-	    ColumnVector v = vector_value ();
-	    int len = v.length ();
-	    if (len == 0)
+	    Matrix m = matrix_value ();
+
+	    int nr = m.rows ();
+	    int nc = m.columns ();
+
+	    if (nr == 0 || nc == 0)
 	      {
 		char s = '\0';
-		retval = tree_constant (&s);
+		retval = &s;
 	      }
 	    else
 	      {
-		char *s = new char [len+1];
-		s[len] = '\0';
-		for (int i = 0; i < len; i++)
+		Octave_str_obj s (nr);
+
+		for (int i = 0; i < nr; i++)
 		  {
-		    double d = v.elem (i);
-
-		    if (xisnan (d))
+		    char buf[nc+1];
+		    buf[nc] = '\0';
+
+		    for (int j = 0; j < nc; j++)
 		      {
-			::error ("invalid conversion from NaN to character");
-			delete [] s;
-			return retval;
+			double d = m.elem (i, j);
+
+			if (xisnan (d))
+			  {
+			    ::error ("invalid conversion from NaN to character");
+			    return retval;
+			  }
+			else
+			  {
+			    // Warn about out of range conversions?
+
+			    int ival = NINT (d);
+			    buf[j] = (char) ival;
+			  }
 		      }
-		    else
-		      {
-			int ival = NINT (d);
-// Warn about out of range conversions?
-			s[i] = (char) ival;
-		      }
+
+		    s.elem (i).assign (buf, nc);
 		  }
-		retval = tree_constant (s);
-		delete [] s;
+
+		retval = s;
 	      }
 	  }
       }
@@ -1628,13 +1656,13 @@
 		s[i] = (char) ival;
 	      }
 	  }
-	retval = tree_constant (s);
+	retval = s;
 	delete [] s;
       }
       break;
 
     case string_constant:
-      retval = string;
+      retval = *str_obj;
       break;
 
     default:
@@ -1719,31 +1747,41 @@
       {
 	if (! force_str_conv && ! user_pref.implicit_str_to_num_ok)
 	  {
-	    ::error ("failed to convert `%s' to a numeric type --", string);
+	    ::error ("failed to convert `%s' to a numeric type --", str_obj);
 	    ::error ("default conversion turned off");
 
 	    return;
 	  }
 
-	int len = strlen (string);
-	if (len > 1)
-	  {
-	    type_tag = matrix_constant;
-	    Matrix *tm = new Matrix (1, len);
-	    for (int i = 0; i < len; i++)
-	      tm->elem (0, i) = toascii ((int) string[i]);
-	    matrix = tm;
-	  }
-	else if (len == 1)
+	int nr = str_obj->num_strings ();
+	int nc = str_obj->max_length ();
+
+	if (nr == 1 && nc == 1)
 	  {
 	    type_tag = scalar_constant;
-	    scalar = toascii ((int) string[0]);
+	    scalar = toascii ((int) str_obj->elem (0, 0));
 	  }
-	else if (len == 0)
+	else if (nr == 0 || nc == 0)
 	  {
 	    type_tag = matrix_constant;
 	    matrix = new Matrix (0, 0);
 	  }
+	else if (nr > 0 && nc > 0)
+	  {
+	    type_tag = matrix_constant;
+
+	    Matrix *tm = new Matrix (nr, nc);
+
+	    for (int i = 0; i < nr; i++)
+	      {
+		for (int j = 0; j < nc; j++)
+		  {
+		    int c = (int) str_obj->elem (i, j);
+		    tm->elem (i, j) = toascii (c);
+		  }
+	      }
+	    matrix = tm;
+	  }
 	else
 	  panic_impossible ();
       }
@@ -1784,28 +1822,28 @@
   switch (type_tag)
     {
     case scalar_constant:
-      retval = tree_constant (scalar);
+      retval = scalar;
       break;
 
     case matrix_constant:
-      retval = tree_constant (*matrix);
+      retval = *matrix;
       break;
 
     case complex_scalar_constant:
-      retval = tree_constant (*complex_scalar);
+      retval = *complex_scalar;
       break;
 
     case complex_matrix_constant:
-      retval = tree_constant (*complex_matrix);
+      retval = *complex_matrix;
       break;
 
     case string_constant:
-      retval = tree_constant (string);
+      retval = *str_obj;
       retval.force_numeric (force_str_conv);
       break;
 
     case range_constant:
-      retval = tree_constant (*range);
+      retval = *range;
       retval.force_numeric (force_str_conv);
       break;
 
@@ -2107,7 +2145,7 @@
       break;
 
     case string_constant:
-      output_buf << string << "\n";
+      octave_print_internal (output_buf, *str_obj);
       break;
 
     case range_constant:
@@ -2200,13 +2238,7 @@
       break;
 
     case string_constant:
-      {
-	os << "\"";
-	char *s, *t = string;
-	while ((s = undo_string_escape (*t++)))
-	  os << s;
-	os << "\"";
-      }
+      octave_print_internal (os, *str_obj, 1);
       break;
 
     case range_constant:
@@ -2512,8 +2544,9 @@
 // #include <config.h>
 // #endif
 
-// #include <ctype.h>
-// #include <string.h>
+// #include <cctype>
+// #include <cstring>
+
 // #include <fstream.h>
 // #include <iostream.h>
 // #include <strstream.h>
@@ -2864,7 +2897,7 @@
 	if (iv.length () == 0)
 	  {
 	    Matrix mtmp;
-	    retval = tree_constant (mtmp);
+	    retval = mtmp;
 	  }
 	else
 	  retval = do_matrix_index (iv, j_arg);
@@ -2980,7 +3013,7 @@
 	if (mi.rows () == 0 || mi.columns () == 0)
 	  {
 	    Matrix mtmp;
-	    retval = tree_constant (mtmp);
+	    retval = mtmp;
 	  }
 	else
 	  {
@@ -3186,7 +3219,7 @@
 	if (mi.rows () == 0 || mi.columns () == 0)
 	  {
 	    Matrix mtmp;
-	    retval = tree_constant (mtmp);
+	    retval = mtmp;
 	  }
 	else
 	  {
@@ -3307,7 +3340,7 @@
 	if (jv.length () == 0)
 	  {
 	    Matrix mtmp;
-	    retval = tree_constant (mtmp);
+	    retval = mtmp;
 	  }
 	else
 	  {
@@ -3404,7 +3437,7 @@
 	if (jv.length () == 0)
 	  {
 	    Matrix mtmp;
-	    retval = tree_constant (mtmp);
+	    retval = mtmp;
 	  }
 	else
 	  {
@@ -3497,7 +3530,7 @@
 	if (jv.length () == 0)
 	  {
 	    Matrix mtmp;
-	    retval = tree_constant (mtmp);
+	    retval = mtmp;
 	  }
 	else
 	  {
@@ -3597,7 +3630,7 @@
 	if (jv.length () == 0)
 	  {
 	    Matrix mtmp;
-	    retval = tree_constant (mtmp);
+	    retval = mtmp;
 	  }
 	else
 	  {
@@ -3652,9 +3685,9 @@
   tree_constant retval;
 
   if (type_tag == matrix_constant)
-    retval = tree_constant (matrix->elem (i, j));
+    retval = matrix->elem (i, j);
   else
-    retval = tree_constant (complex_matrix->elem (i, j));
+    retval = complex_matrix->elem (i, j);
 
   return retval;
 }
@@ -4048,7 +4081,7 @@
       break;
 
     case string_constant:
-      retval = string;
+      retval = *str_obj;
       break;
 
     case magic_colon:
@@ -4073,8 +4106,9 @@
 // #include <config.h>
 // #endif
 
-// #include <ctype.h>
-// #include <string.h>
+// #include <cctype>
+// #include <cstring>
+
 // #include <fstream.h>
 // #include <iostream.h>
 // #include <strstream.h>
@@ -6163,7 +6197,7 @@
       break;
 
     case string_constant:
-      delete [] string;
+      delete str_obj;
       break;
 
     case range_constant:
@@ -6189,7 +6223,7 @@
       break;
 
     case string_constant:
-      string = strsave (rhs.string_value ());
+      str_obj = new Octave_str_obj (rhs.string_value ());
       break;
 
     case complex_matrix_constant:
--- a/src/pt-const.h	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/pt-const.h	Tue Sep 05 20:07:21 1995 +0000
@@ -28,16 +28,17 @@
 #pragma interface
 #endif
 
+#include <cstdlib>
+
 #include <iostream.h>
 
-#include <stdlib.h>
-
+#include "Range.h"
 #include "mx-base.h"
-#include "Range.h"
 
+#include "oct-obj.h"
+#include "oct-str.h"
 #include "tree-base.h"
 #include "tree-expr.h"
-#include "oct-obj.h"
 
 class idx_vector;
 class Octave_map;
@@ -83,8 +84,10 @@
 //                  ComplexRowVector
 //                  ComplexColumnVector
 // string           char* (null terminated)
-// range            double, double, dobule
+//                  Octave_str_obj
+// range            double, double, double
 //                  Range
+// map              Octave_map
 // magic colon      tree_constant::magic_colon
 // all_va_args      tree_constant::all_va_args
 
@@ -124,6 +127,9 @@
   tree_constant (const char *s) : tree_fvc ()
     { rep = new tree_constant_rep (s); rep->count = 1; }
 
+  tree_constant (const Octave_str_obj& s) : tree_fvc ()
+    { rep = new tree_constant_rep (s); rep->count = 1; }
+
   tree_constant (double base, double limit, double inc) : tree_fvc ()
     { rep = new tree_constant_rep (base, limit, inc); rep->count = 1; }
 
@@ -283,7 +289,10 @@
   ComplexMatrix complex_matrix_value (int force_string_conversion = 0) const
     { return rep->complex_matrix_value (force_string_conversion); }
 
-  char *string_value (void) const
+  Octave_str_obj all_strings (void) const
+    { return rep->all_strings (); }
+
+  const char *string_value (void) const
     { return rep->string_value (); }
 
   Range range_value (void) const
--- a/src/strfns.cc	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/strfns.cc	Tue Sep 05 20:07:21 1995 +0000
@@ -25,18 +25,17 @@
 #include <config.h>
 #endif
 
-#include <ctype.h>
-#include <string.h>
+#include <cctype>
 
 #include "dMatrix.h"
 
-#include "tree-const.h"
-#include "oct-obj.h"
+#include "defun.h"
 #include "error.h"
 #include "gripes.h"
-#include "defun.h"
+#include "help.h"
+#include "oct-obj.h"
+#include "tree-const.h"
 #include "utils.h"
-#include "help.h"
 
 DEFUN ("isstr", Fisstr, Sisstr, 1, 1,
   "isstr (X): return 1 if X is a string, 0 otherwise")
@@ -81,14 +80,21 @@
 
       if (arg.is_string ())
 	{
-	  char *str = args(0).string_value ();
+	  Octave_str_obj str = args(0).all_strings ();
 
-	  int len = strlen (str);
+	  int nr = str.num_strings ();
+	  int nc = str.max_length ();
+
+// XXX FIXME XXX -- should fill with user-specified value.
 
-	  Matrix m (1, len);
+	  Matrix m (nr, nc, 0);
 
-	  for (int i = 0; i < len; i++)
-	    m (0, i) = toascii (str[i]);
+	  for (int i = 0; i < nr; i++)
+	    {
+	      nc = str.elem (i).length ();
+	      for (int j = 0; j < nc; j++)
+		m (i, j) = toascii (str.elem (i) [j]);
+	    }
 
 	  retval = m;
 	}
--- a/src/tc-rep.h	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/tc-rep.h	Tue Sep 05 20:07:21 1995 +0000
@@ -69,6 +69,7 @@
   tree_constant_rep (const ComplexColumnVector& v, int pcv);
 
   tree_constant_rep (const char *s);
+  tree_constant_rep (const Octave_str_obj& s);
 
   tree_constant_rep (double base, double limit, double inc);
   tree_constant_rep (const Range& r);
@@ -186,7 +187,8 @@
   Matrix matrix_value (int force_string_conversion = 0) const;
   Complex complex_value (int force_string_conversion = 0) const;
   ComplexMatrix complex_matrix_value (int force_string_conversion = 0) const;
-  char *string_value (void) const;
+  Octave_str_obj all_strings (void) const;
+  const char *string_value (void) const;
   Range range_value (void) const;
   Octave_map map_value (void) const;
 
@@ -385,7 +387,7 @@
       Matrix *matrix;		      // A real matrix constant.
       Complex *complex_scalar;	      // A real scalar constant.
       ComplexMatrix *complex_matrix;  // A real matrix constant.
-      char *string;		      // A character string constant.
+      Octave_str_obj *str_obj;	      // A character string constant.
       Range *range;		      // A set of evenly spaced values.
       Octave_map *a_map;	      // An associative array.
 
--- a/src/toplev.h	Tue Sep 05 19:56:08 1995 +0000
+++ b/src/toplev.h	Tue Sep 05 20:07:21 1995 +0000
@@ -24,10 +24,11 @@
 #if !defined (octave_octave_h)
 #define octave_octave_h 1
 
-#include <stdio.h>
+#include <cstdio>
 
 class tree_statement_list;
 class tree_function;
+class Octave_str_obj;
 
 // Tell g++ that clean_up_and_exit doesn't return;
 
@@ -89,6 +90,9 @@
 // Nonzero means input is coming from startup file.
 extern int input_from_startup_file;
 
+// The command-line options.
+extern Octave_str_obj octave_argv;
+
 #endif
 
 /*