ddd
[Top][All Lists]
Advanced

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

more clean-up for ddd


From: Arnaud Desitter
Subject: more clean-up for ddd
Date: Fri, 12 Oct 2001 10:26:05 +0100

Hi,

Here is a quite big patch against ddd as in the CVS repository.
It includes the patch fixing the last big memory leaks of ddd. 
It was submitted in september, see for the log:
http://mail.gnu.org/pipermail/ddd/2001-September/001218.html

New changes:
- added compilation notes on HP-UX and SGI compilers on IRIX.
  [PROBLEMS]
- "string" changed to "const string&" in function arguments 
  where possible in order to avoid unnecessary copies. 
  That may provide a marginal improvement in memory consumption and
  run-time performance.
  [loads of files]
- added a few "const"s. That should help to move more objects in
  read-only memory. [many files]
- suppressed dangerous casts (typically "(string&)" applied to a 
  const string object). They were all unnecessary. [many files]
- a small adaptation to suppress a warning in 64 bit environment. 
  [DataDisp.C]
- modify the string class so that the const-ness is preserved properly
  by introducing a constSubString class.
  Also, I commented out some conversion operators.
  Hopefully, these changes will make it easier to use std::string at 
  some point.
  [strclass.C, strclass.h]

ddd, once patched, compiles on AIX/xlC 5.0, Solaris/CC 4.x and 5.x, 
IRIX/CC 7.3.x, OSF/cxx 6.2, HP-UX 11/aCC 3.13, Linux/g++ 2.9x.

Regards,
Arnaud

Index: PROBLEMS
===================================================================
RCS file: /cvsroot/ddd/ddd/PROBLEMS,v
retrieving revision 1.103
diff -u -r1.103 PROBLEMS
--- PROBLEMS    2001/04/24 17:24:38     1.103
+++ PROBLEMS    2001/10/12 08:55:13
@@ -15,6 +15,7 @@
       + GCC 3.0 prereleases
       + GCC and libg++
     * HP-UX
+    * Irix
     * LessTif
     * Linux
     * OSF/1
@@ -278,7 +279,6 @@
         From: LIBXM = -lXm
         To:   LIBXM = /usr/lib/Motif1.2_R6/libXm.a
     
-
 Reported by:  (various)
 
     Lutz Jaenicke <address@hidden> reports that he
@@ -303,6 +303,10 @@
       linking is not necessary in this setup.
       (Athena Widgets are only available as ".a" static libraries, so I
decided
       against include them.)
+    * To get the Athena Widgets, use:
+      ./configure \
+       --with-athena-includes=/usr/contrib/X11R6/include \
+       --with-athena-libraries=/usr/contrib/X11R6/lib
     * IMPORTANT: I just installed the latest aCC patch, released 
       around yesterday (2000/02/02)!!! Its number is PHSS_20959.
       Without it, linking failed with
@@ -374,6 +378,17 @@
     `-mmillicode-long-calls' when compiling.  It should permit fixes
     into shared library calls (these errors only occur with shared
     libraries).
+
+Irix
+====
+
+    To use the MIPSPro compilers with Motif 2.1, the configure line is:
+    env CC='cc -n32' CXX='CC -n32' \
+     CFLAGS='-O' CXXFLAGS='-O' \
+     ./configure \
+     --with-motif-includes=/usr/Motif-2.1/include \
+     --with-motif-libraries=/usr/Motif-2.1/lib32 \
+     --x-libraries=/usr/lib32
 
 LessTif
 =======
Index: ddd/DataDisp.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/DataDisp.C,v
retrieving revision 1.390
diff -u -r1.390 DataDisp.C
--- ddd/DataDisp.C      2001/07/30 19:45:32     1.390
+++ ddd/DataDisp.C      2001/10/12 08:55:18
@@ -3451,8 +3451,8 @@
 }
 
 void DataDisp::new_displaySQ (string display_expression,
-                             string scope, BoxPoint *p,
-                             string depends_on,
+                             const string& scope, BoxPoint *p,
+                             const string& depends_on,
                              DeferMode deferred, 
                              bool clustered, bool plotted,
                              Widget origin, bool verbose, bool do_prompt)
@@ -4420,8 +4420,10 @@
     info.prompt  = do_prompt;
     info.cmds    = cmds;
 
+    bool info_registered;
     bool ok = gdb->send_qu_array(cmds, dummy, cmds.size(), 
-                                refresh_displayOQAC, (void *)&info);
+                                refresh_displayOQAC, (void *)&info,
+                                info_registered);
 
     if (!ok || cmds.size() == 0)
     {
@@ -5670,7 +5672,8 @@
     // We refresh the list as soon as we return from the callback
     // (LessTif is sensitive about this)
     XtAppAddTimeOut(XtWidgetToApplicationContext(display_list_w),
-                   0, RefreshDisplayListCB, XtPointer(silent));
+                   0, RefreshDisplayListCB, 
+                   (silent ? XtPointer(1):XtPointer(0)) );
 }
 
 
@@ -5678,9 +5681,8 @@
 {
     (void) id;                 // Use it
 
-    // TODO dodgy cast. Use a pointer to bool and dereference it.
-    const bool silent = int(client_data);
-    int number_of_displays = disp_graph->count_all();
+    const bool silent = client_data?true:false;
+    const int number_of_displays = disp_graph->count_all();
 
     StringArray nums;
     StringArray states;
@@ -6440,8 +6442,10 @@
            info.verbose = false;
            info.prompt  = false;
            info.cmds    = cmds;
+           bool info_registered;
            ok = gdb->send_qu_array(cmds, dummy, cmds.size(), 
-                                   refresh_displayOQAC, (void *)&info);
+                                   refresh_displayOQAC, (void *)&info,
+                                   info_registered);
 
            sent = cmds.size() > 0;
        }
Index: ddd/DataDisp.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/DataDisp.h,v
retrieving revision 1.123
diff -u -r1.123 DataDisp.h
--- ddd/DataDisp.h      2000/12/19 00:27:08     1.123
+++ ddd/DataDisp.h      2001/10/12 08:55:18
@@ -294,9 +294,9 @@
     // If PLOTTED is set, plot display.
     // If ORIGIN is set, the last origin is set to ORIGIN.
     static void new_displaySQ(string display_expression,
-                             string scope,
+                             const string& scope,
                              BoxPoint *pos = 0,
-                             string depends_on = "",
+                             const string& depends_on = "",
                              DeferMode deferred = DeferAlways,
                              bool clustered = false,
                              bool plotted = false,
Index: ddd/GDBAgent.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/GDBAgent.C,v
retrieving revision 1.221
diff -u -r1.221 GDBAgent.C
--- ddd/GDBAgent.C      2001/07/30 19:45:32     1.221
+++ ddd/GDBAgent.C      2001/10/12 08:55:19
@@ -438,14 +438,17 @@
                           const VoidArray& qu_datas,
                           int      qu_count,
                           OQACProc on_qu_array_completion,
-                          void*    qa_data)
+                          void*    qa_data,
+                          bool&    qa_data_registered)
 {
+    qa_data_registered = false;
     state = BusyOnInitialCmds;
 
     if (qu_count > 0) {
        questions_waiting = true;
        init_qu_array(cmds, qu_datas, qu_count, 
                      on_qu_array_completion, qa_data);
+        qa_data_registered = true;
     }
 
     do_start(on_answer, on_answer_completion, user_data);
@@ -492,7 +495,7 @@
 }
 
 // Send CMD to GDB (unconditionally), associated with USER_DATA.
-bool GDBAgent::send_user_ctrl_cmd(string cmd, void *user_data)
+bool GDBAgent::send_user_ctrl_cmd(const string& cmd, void *user_data)
 {
     if (user_data)
        _user_data = user_data;
@@ -516,9 +519,11 @@
                                   int      qu_count,
                                   OQACProc on_qu_array_completion,
                                   void*    qa_data,
+                                  bool& qa_data_registered,
                                   string   user_cmd,
                                   void* user_data)
 {
+    qa_data_registered = false;
     if (state != ReadyWithPrompt) 
        return false;
 
@@ -529,6 +534,7 @@
        questions_waiting = true;
        init_qu_array(cmds, qu_datas, qu_count,
                      on_qu_array_completion, qa_data);
+        qa_data_registered = true;
     }
 
     // Process command
@@ -547,8 +553,10 @@
                              const VoidArray& qu_datas,
                              int      qu_count,
                              OQACProc on_qu_array_completion,
-                             void*    qa_data)
+                             void*    qa_data,
+                             bool& qa_data_registered)
 {
+    qa_data_registered = false;
     if (qu_count == 0)
        return true;
     if (state != ReadyWithPrompt)
@@ -559,6 +567,7 @@
     callHandlers(ReadyForCmd, (void *)false);
 
     init_qu_array(cmds, qu_datas, qu_count, on_qu_array_completion,
qa_data);
+    qa_data_registered = true;
     
     // Send first question
     write_cmd(cmd_array[0]);
@@ -653,7 +662,7 @@
     case XDB:
     {
        // Any line equal to `>' is a prompt.
-       unsigned beginning_of_line = answer.index('\n', -1) + 1;
+       const unsigned beginning_of_line = answer.index('\n', -1) + 1;
        if (beginning_of_line < answer.length()
            && answer.length() > 0
            && answer[beginning_of_line] == '>')
@@ -721,8 +730,8 @@
        }
 
        // Check for non-threaded prompt as the last line
-       int beginning_of_line = answer.index('\n', -1) + 1;
-       string possible_prompt = ((string &) answer).from(beginning_of_line);
+       const int beginning_of_line = answer.index('\n', -1) + 1;
+       const string possible_prompt = answer.from(beginning_of_line);
        if (possible_prompt.matches(rxjdbprompt_nothread))
        {
            last_prompt = possible_prompt;
@@ -734,7 +743,7 @@
        while (last_nl >= 0)
        {
            last_nl = answer.index('\n', last_nl - answer.length());
-           int beginning_of_line = last_nl + 1;
+           const int beginning_of_line = last_nl + 1;
 
            match_len = rxjdbprompt.match(answer.chars(), answer.length(), 
                                          beginning_of_line);
@@ -997,7 +1006,7 @@
            int eol = s.index('\n', warning) + 1;
            if (eol <= 0)
                eol = s.length();
-           s(warning, eol - warning) = "";
+           s.at(warning, eol - warning) = "";
        }
     }
 
@@ -1302,7 +1311,7 @@
        flush();
 
        // Ignore the last line (containing the `More' prompt)
-       int last_beginning_of_line = answer.index('\n', -1) + 1;
+       const int last_beginning_of_line = answer.index('\n', -1) + 1;
        answer.from(last_beginning_of_line) = "";
     }
 }
@@ -1671,7 +1680,7 @@
 }
 
 // DBX 3.0 wants `display -r' instead of `display' for C++
-string GDBAgent::display_command(string expr) const
+string GDBAgent::display_command(const string& expr) const
 {
     if (!has_display_command())
        return "";
@@ -1795,7 +1804,7 @@
 }
 
 // Some DBXes want `sh make' instead of `make'
-string GDBAgent::make_command(string args) const
+string GDBAgent::make_command(const string& args) const
 {
     string cmd;
     switch (type())
@@ -1890,7 +1899,7 @@
 }
 
 // Watch expressions
-string GDBAgent::watch_command(string expr, WatchMode w) const
+string GDBAgent::watch_command(const string& expr, WatchMode w) const
 {
     if ((has_watch_command() & w) != w)
        return "";
@@ -2052,7 +2061,7 @@
 }
 
 // Each debugger has its own way of echoing (sigh)
-string GDBAgent::echo_command(string text) const
+string GDBAgent::echo_command(const string& text) const
 {
     switch (type())
     {
@@ -2079,7 +2088,7 @@
 }
 
 // Prefer `ptype' on `whatis' in GDB
-string GDBAgent::whatis_command(string text) const
+string GDBAgent::whatis_command(const string& text) const
 {
     switch (type())
     {
@@ -2193,7 +2202,7 @@
 }
 
 // Set ignore count of breakpoint BP to COUNT
-string GDBAgent::ignore_command(string bp, int count) const
+string GDBAgent::ignore_command(const string& bp, int count) const
 {
     switch (type())
     {
@@ -2219,7 +2228,7 @@
 }
 
 // Set condition of breakpoint BP to EXPR
-string GDBAgent::condition_command(string bp, string expr) const
+string GDBAgent::condition_command(const string& bp, const string&
expr) const
 {
     switch (type())
     {
@@ -2238,7 +2247,7 @@
 }
 
 // Return shell escape command
-string GDBAgent::shell_command(string cmd) const
+string GDBAgent::shell_command(const string& cmd) const
 {
     switch (type())
     {
@@ -2358,7 +2367,7 @@
 }
 
 // Return command to debug PROGRAM
-string GDBAgent::debug_command(string program, string args) const
+string GDBAgent::debug_command(const string& program, string args)
const
 {
     if (args != "" && !args.contains(' ', 0))
        args = " " + args;
@@ -2425,7 +2434,7 @@
 
 
 // Return a command that does nothing.
-string GDBAgent::nop_command(string comment) const
+string GDBAgent::nop_command(const string& comment) const
 {
     if (type() == JDB)
        return " ";
@@ -2578,7 +2587,7 @@
 }
 
 // Dereference an expression.
-string GDBAgent::dereferenced_expr(string expr) const
+string GDBAgent::dereferenced_expr(const string& expr) const
 {
     switch (program_language())
     {
@@ -2665,7 +2674,7 @@
 }
 
 // Give the index of an expression.
-string GDBAgent::index_expr(string expr, string index) const
+string GDBAgent::index_expr(const string& expr, const string& index)
const
 {
     switch (program_language())
     {
@@ -2734,7 +2743,7 @@
 }
 
 // Return assignment command
-string GDBAgent::assign_command(string var, string expr) const
+string GDBAgent::assign_command(const string& var, const string& expr)
const
 {
     string cmd;
 
@@ -2922,7 +2931,7 @@
     static struct {
        const char *name;
        ProgramLanguage language;
-    } language_table[] = {
+    } const language_table[] = {
        { "fortran", LANGUAGE_FORTRAN },
        { "f",       LANGUAGE_FORTRAN }, // F77, F90, F
        { "java",    LANGUAGE_JAVA },
Index: ddd/GDBAgent.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/GDBAgent.h,v
retrieving revision 1.124
diff -u -r1.124 GDBAgent.h
--- ddd/GDBAgent.h      2001/01/26 09:24:09     1.124
+++ ddd/GDBAgent.h      2001/10/12 08:55:19
@@ -249,12 +249,13 @@
                     const VoidArray& user_datas,
                     int      qu_count,
                     OQACProc on_qu_array_completion,
-                    void*    qa_data);
+                    void*    qa_data,
+                    bool&    qa_data_registered);
 
     // true iff command was sent.
     // If user_data == 0, _user_data remains unchanged.
     bool send_user_cmd      (string cmd, void* user_data = 0);  
-    bool send_user_ctrl_cmd (string cmd, void* user_data = 0);
+    bool send_user_ctrl_cmd (const string& cmd, void* user_data = 0);
 
 
     // Order of tasks:
@@ -270,6 +271,7 @@
                             int      qu_count,
                             OQACProc on_qu_array_completion,
                             void*    qa_data,
+                            bool&    qa_data_registered,
                             string user_cmd,
                             void* user_data = 0);
 
@@ -277,7 +279,8 @@
                        const VoidArray& qu_datas,
                        int      qu_count,
                        OQACProc on_qu_array_completion,
-                       void*    qa_data);
+                       void*    qa_data,
+                       bool&    qa_data_registered);
 
 
     // Resources
@@ -678,20 +681,20 @@
                                                    // -----------------------
     string print_command(string expr = "",          // print|output EXP
                         bool internal = true) const;
-    string assign_command(string var,               // set variable VAR
= EXPR
-                         string expr) const;
-    string display_command(string expr = "") const; // display EXPR
+    string assign_command(const string& var,               // set
variable VAR = EXPR
+                         const string& expr) const;
+    string display_command(const string& expr = "") const; // display
EXPR
     string where_command(int count = 0) const;     // where COUNT
     string pwd_command() const;                            // pwd
     string frame_command(int number) const;         // frame NUMBER
     string relative_frame_command(int offset) const;// up|down OFFSET
     string frame_command() const;                   // frame
     string func_command() const;                    // func
-    string echo_command(string text) const;         // echo TEXT
-    string whatis_command(string expr) const;       // whatis EXPR
-    string dereferenced_expr(string expr) const;    // *EXPR
+    string echo_command(const string& text) const;         // echo TEXT
+    string whatis_command(const string& expr) const;       // whatis
EXPR
+    string dereferenced_expr(const string& expr) const;    // *EXPR
     string address_expr(string expr) const;         // &EXPR
-    string index_expr(string expr, string index) const; // EXPR[INDEX]
+    string index_expr(const string& expr, const string& index) const;
// EXPR[INDEX]
     int default_index_base() const;                 // 0 in C, else 1
     string member_separator() const;                // " = " in C
 
@@ -700,24 +703,24 @@
     string info_display_command() const;           // info display
     string disassemble_command(string start, string end = "") const;
                                                     // disassemble
START END
-    string make_command(string target) const;       // make TARGET
+    string make_command(const string& target) const;       // make
TARGET
     string jump_command(string pc) const;           // jump PC
     string regs_command(bool all = true) const;            // info registers
-    string watch_command(string expr, WatchMode w = WATCH_CHANGE)
const;
+    string watch_command(const string& expr, WatchMode w =
WATCH_CHANGE) const;
                                                    // watch EXPR
     string kill_command() const;                    // kill
     string enable_command(string bp = "") const;    // enable BP
     string disable_command(string bp = "") const;   // disable BP
     string delete_command(string bp = "") const;    // delete BP
-    string ignore_command(string bp, int count) const; 
+    string ignore_command(const string& bp, int count) const; 
                                                     // ignore BP COUNT
-    string condition_command(string bp, string expr) const; 
+    string condition_command(const string& bp, const string& expr)
const; 
                                                    // cond BP EXPR
-    string shell_command(string cmd) const;        // shell CMD
-    string debug_command(string file = "",          // file FILE
+    string shell_command(const string& cmd) const;         // shell CMD
+    string debug_command(const string& file = "",          // file FILE
                         string args = "") const;
     string signal_command(int sig) const;           // signal SIG
-    string nop_command(string comment = "") const;  // # comment
+    string nop_command(const string& comment = "") const;  // # comment
 
     // Bring VALUE of VAR into a form understood by DDD
     void munch_value(string& value, const string& var) const;
Index: ddd/HelpCB.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/HelpCB.C,v
retrieving revision 1.124
diff -u -r1.124 HelpCB.C
--- ddd/HelpCB.C        2001/07/30 19:45:32     1.124
+++ ddd/HelpCB.C        2001/10/12 08:55:21
@@ -1065,7 +1065,7 @@
            int start_of_title = the_text.index("\n\n", source) + 2;
            int end_of_title   = the_text.index("\n", start_of_title);
            string title = 
-               the_text(start_of_title, end_of_title - start_of_title);
+               the_text.at(start_of_title, end_of_title - start_of_title);
 
            // Fetch indent level, using the underline characters
            int start_of_underline = the_text.index('\n', start_of_title) + 1;
@@ -1334,7 +1334,7 @@
                    if (is_title)
                    {
                        titles += 
-                           the_text(start_of_line, source - start_of_line);
+                           the_text.at(start_of_line, source - start_of_line);
                        positions += start_of_line;
                    }
                }
@@ -2452,8 +2452,12 @@
        }
     }
 
-    XmStringFree(tip_values.tipString);
-    XmStringFree(doc_values.documentationString);
+    // CvtStringToXmString and friends should be responsible of
+    // the memory management.
+    // XmStringFree(tip_values.tipString);
+    // tip_values.tipString = 0;
+    // XmStringFree(doc_values.documentationString);
+    // doc_values.documentationString = 0;
 }
 
 
Index: ddd/LiterateA.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/LiterateA.C,v
retrieving revision 1.32
diff -u -r1.32 LiterateA.C
--- ddd/LiterateA.C     2001/07/30 19:45:32     1.32
+++ ddd/LiterateA.C     2001/10/12 08:55:21
@@ -334,7 +334,7 @@
 {
   // TODO is this correction all right ?
     if (data[length] != '\0'){
-      string s1(data,length);
+      const string s1(data,length);
       const char *data_l = s1.chars();
       DataLength dl(data_l, length);
       
Index: ddd/PosBuffer.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/PosBuffer.C,v
retrieving revision 1.95
diff -u -r1.95 PosBuffer.C
--- ddd/PosBuffer.C     2001/07/30 19:45:32     1.95
+++ ddd/PosBuffer.C     2001/10/12 08:55:21
@@ -107,7 +107,7 @@
     while (index < int(answer.length()) && !isspace(answer[index]))
        index++;
 
-    buffer = ((string&)answer).at(start, index - start);
+    buffer = answer.at(start, index - start);
 }
 
 // Store first function name in ANSWER after INDEX in BUFFER
Index: ddd/SourceView.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/SourceView.C,v
retrieving revision 1.466
diff -u -r1.466 SourceView.C
--- ddd/SourceView.C    2001/07/30 19:45:32     1.466
+++ ddd/SourceView.C    2001/10/12 08:55:24
@@ -265,7 +265,7 @@
     };
 };
 
-static const _XtString text_cmd_labels[] =
+static const _XtString const text_cmd_labels[] =
 {
     "Print ", 
     "Display ", 
@@ -463,7 +463,7 @@
     if (eol < 0)
        eol = s.length();
 
-    string first_line = ((string&)s).at(pos, eol - pos);
+    const string first_line = s.at(pos, eol - pos);
     int i = 0;
     while (i < int(first_line.length()) && isspace(first_line[i]))
        i++;
@@ -562,7 +562,7 @@
                                   XtPointer client_data,
                                   XtPointer)
 {
-    string address = *((string *)client_data);
+    const string address = *((const string *)client_data);
     create_bp(address, w);
 }
 
@@ -570,7 +570,7 @@
                                        XtPointer client_data,
                                        XtPointer)
 {
-    string address = *((string *)client_data);
+    const string address = *((const string *)client_data);
     create_temp_bp(address, w);
 }
 
@@ -791,7 +791,7 @@
                                           XtPointer client_data,
                                           XtPointer)
 {
-    string address = *((string *)client_data);
+    const string address = *((const string *)client_data);
     temp_n_cont(address, w);
 }
 
@@ -846,7 +846,7 @@
                                     XtPointer client_data,
                                     XtPointer)
 {
-    string address = *((string *)client_data);
+    const string address = *((const string *)client_data);
     move_pc(address, w);
 }
 
@@ -1369,7 +1369,7 @@
                                     XtPointer client_data,
                                     XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     create_bp(fortranize(*word_ptr, true), w);
 }
 
@@ -1377,7 +1377,7 @@
                                     XtPointer client_data, 
                                     XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     clear_bp(fortranize(*word_ptr, true), w);
 }
 
@@ -1389,7 +1389,7 @@
                                     XtPointer client_data, 
                                     XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     assert(word_ptr->length() > 0);
 
     gdb_command(gdb->print_command(fortranize(*word_ptr), false), w);
@@ -1398,7 +1398,7 @@
 void SourceView::text_popup_print_refCB (Widget w, 
                                         XtPointer client_data, XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     assert(word_ptr->length() > 0);
 
     gdb_command(gdb->print_command(deref(fortranize(*word_ptr)),
false), w);
@@ -1411,7 +1411,7 @@
                                     XtPointer client_data, 
                                     XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     assert(word_ptr->length() > 0);
 
     gdb_command(gdb->watch_command(fortranize(*word_ptr)), w);
@@ -1420,7 +1420,7 @@
 void SourceView::text_popup_watch_refCB (Widget w, 
                                         XtPointer client_data, XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     assert(word_ptr->length() > 0);
 
     gdb_command(gdb->watch_command(deref(fortranize(*word_ptr))), w);
@@ -1431,7 +1431,7 @@
 //
 void SourceView::text_popup_dispCB (Widget w, XtPointer client_data,
XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     assert(word_ptr->length() > 0);
 
     gdb_command("graph display " + fortranize(*word_ptr), w);
@@ -1440,7 +1440,7 @@
 void SourceView::text_popup_disp_refCB (Widget w, 
                                        XtPointer client_data, XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     assert(word_ptr->length() > 0);
 
     gdb_command("graph display " + deref(fortranize(*word_ptr)), w);
@@ -1451,7 +1451,7 @@
 void SourceView::text_popup_whatisCB (Widget w, XtPointer client_data, 
                                      XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     assert(word_ptr->length() > 0);
 
     gdb_command(gdb->whatis_command(fortranize(*word_ptr)), w);
@@ -1461,7 +1461,7 @@
 //
 void SourceView::text_popup_lookupCB (Widget, XtPointer client_data,
XtPointer)
 {
-    string* word_ptr = (string*)client_data;
+    const string* word_ptr = (const string*)client_data;
     lookup(fortranize(*word_ptr, true));
 }
 
@@ -1598,7 +1598,7 @@
                                  XtPointer client_data, 
                                  XtPointer call_data)
 {
-    string& text = current_text(text_w);
+    const string& text = current_text(text_w);
     if (text == "")
        return;
 
@@ -1759,7 +1759,7 @@
        if (startPos < XmTextPosition(text.length())
            && endPos < XmTextPosition(text.length()))
        {
-           s = text(startPos, endPos - startPos);
+           s = text.at((int)startPos, (int)(endPos - startPos));
        }
 
        while (s.contains('\n'))
@@ -1771,7 +1771,7 @@
 }
 
 
-BreakPoint *SourceView::breakpoint_at(string arg)
+BreakPoint *SourceView::breakpoint_at(const string& arg)
 {
     MapRef ref;
     for (BreakPoint* bp = bp_map.first(ref); bp != 0; bp =
bp_map.next(ref))
@@ -1814,7 +1814,7 @@
     return 0;
 }
 
-BreakPoint *SourceView::watchpoint_at(string expr)
+BreakPoint *SourceView::watchpoint_at(const string& expr)
 {
     for (int trial = 0; trial <= 2; trial++)
     {
@@ -1863,7 +1863,7 @@
 // Show position POS in TEXT_W, scrolling nicely
 void SourceView::ShowPosition(Widget text_w, XmTextPosition pos, bool
fromTop)
 {
-    string& text = current_text(text_w);
+    const string& text = current_text(text_w);
     if (text.length() == 0)
        return;                 // No position to show
 
@@ -3156,7 +3156,7 @@
 {
     startpos = endpos = pos;
 
-    string& text = current_text(text_w);
+    const string& text = current_text(text_w);
 
     XmTextPosition line_pos = pos;
     if (line_pos < XmTextPosition(text.length()))
@@ -3238,9 +3238,13 @@
                                   XmTextPosition& startpos,
                                   XmTextPosition& endpos)
 {
-    string& text = current_text(text_w);
+    const string& text = current_text(text_w);
     if (text == "")
+      {
+        startpos = 0;
+        endpos = 0;
        return "";
+      }
 
     if (!XmTextGetSelectionPosition(text_w, &startpos, &endpos)
        || pos < startpos
@@ -3793,7 +3797,7 @@
 }
 
 
-void SourceView::_show_execution_position(string file, int line, 
+void SourceView::_show_execution_position(const string& file, int line, 
                                          bool silent, bool stopped)
 {
     last_execution_file = file;
@@ -4189,7 +4193,7 @@
        {
            int end_line = info_output.index('\n', line);
            if (end_line >= 0)
-               info_output(line, end_line - line) = "";
+               info_output.at(line, end_line - line) = "";
        }
     }
 
@@ -4748,7 +4752,7 @@
                                 address, in_text, bp_nr))
                line_nr = line_count;
 
-           string occurrence = current_source(pos, matchlen);
+           string occurrence = current_source.at(pos, matchlen);
            msg = "Found " + quote(occurrence) + " in " + line_of_cursor();
            if (wraps)
                msg += " (wrapped)";
@@ -7822,7 +7826,7 @@
     if (!ok)
        return 0;
 
-    string& text = current_text(text_w);
+    const string& text = current_text(text_w);
     XmTextPosition second = text.index('\n', top) + 1;
     Position second_x, second_y;
     ok = XmTextPosToXY(text_w, second, &second_x, &second_y);
@@ -9293,7 +9297,7 @@
     if (eol < 0)
        eol = s.length();
 
-    string addr = ((string&)s).at(idx, eol - idx);
+    string addr = s.at(idx, eol - idx);
     return addr.through(rxaddress);
 }
 
@@ -9308,7 +9312,7 @@
     if (eol < 0)
        eol = s.length();
 
-    string addr = ((string&)s).at(idx, eol - idx);
+    string addr = s.at(idx, eol - idx);
     return addr.through(rxaddress);
 }
 
@@ -9331,10 +9335,10 @@
 // Process output of `disassemble' command
 void SourceView::process_disassemble(const string& disassemble_output)
 {
-    int count             = ((string&)disassemble_output).freq('\n') +
1;
+    int count             = disassemble_output.freq('\n') + 1;
     string *code_list     = new string[count];
 
-    split((string &)disassemble_output, code_list, count, '\n');
+    split(disassemble_output, code_list, count, '\n');
 
     string indented_code;
     for (int i = 0; i < count; i++)
@@ -9695,7 +9699,7 @@
 
 
 // Some DBXes require `{ COMMAND; }', others `{ COMMAND }'.
-string SourceView::command_list(string cmd)
+string SourceView::command_list(const string& cmd)
 {
     if (gdb->has_when_semicolon())
        return "{ " + cmd + "; }";
Index: ddd/SourceView.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/SourceView.h,v
retrieving revision 1.151
diff -u -r1.151 SourceView.h
--- ddd/SourceView.h    2000/12/21 02:05:08     1.151
+++ ddd/SourceView.h    2001/10/12 08:55:24
@@ -195,7 +195,7 @@
                              int make_false, Widget origin);
 
     // Set condition of breakpoints NRS to COND.
-    inline static void set_bps_cond(IntArray& nrs, string cond,
+    inline static void set_bps_cond(IntArray& nrs, const string& cond,
                                    Widget origin = 0)
     {
        _set_bps_cond(nrs, cond, -1, origin);
@@ -402,7 +402,7 @@
     static int    last_execution_line;
     static string last_execution_pc;
     static string last_shown_pc;
-    static void _show_execution_position (string file, int line, 
+    static void _show_execution_position (const string& file, int line, 
                                          bool silent, bool stopped);
 
     // Last frame position
@@ -837,7 +837,7 @@
     static string delete_command(int bp_nr);
 
     // Return `{ COMMAND; }'
-    static string command_list(string cmd);
+    static string command_list(const string& cmd);
 
     // Return current directory
     static string pwd() { return current_pwd; }
@@ -872,10 +872,10 @@
     static string bp_pos(int num);
 
     // Return the breakpoint at POS (0 if none)
-    static BreakPoint *breakpoint_at(string pos);
+    static BreakPoint *breakpoint_at(const string& pos);
 
     // Return the watchpoint at EXPR (0 if none)
-    static BreakPoint *watchpoint_at(string expr);
+    static BreakPoint *watchpoint_at(const string& expr);
 
     // Get the word at position of EVENT
     static string get_word_at_event(Widget w,
Index: ddd/TTYAgent.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/TTYAgent.C,v
retrieving revision 1.65
diff -u -r1.65 TTYAgent.C
--- ddd/TTYAgent.C      2001/07/30 19:45:32     1.65
+++ ddd/TTYAgent.C      2001/10/12 08:55:24
@@ -675,7 +675,7 @@
 }
 
 #if SYNCHRONIZE_PARENT_AND_CHILD
-static const char TTY_INIT[] = { 'A', '\n' };
+static const char const TTY_INIT[] = { 'A', '\n' };
 #endif
 
 
Index: ddd/WhatNextCB.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/WhatNextCB.C,v
retrieving revision 1.21
diff -u -r1.21 WhatNextCB.C
--- ddd/WhatNextCB.C    2001/07/30 19:45:32     1.21
+++ ddd/WhatNextCB.C    2001/10/12 08:55:24
@@ -96,7 +96,7 @@
 
 // Return 1 if the signal specified in PROGRAM_STATE is passed to the
 // program; 0 if not, -1 if undecided.
-static int passed_to_program(string program_state)
+static int passed_to_program(const string& program_state)
 {
     string signal = program_state.from("SIG");
     signal = signal.through(rxalpha);
Index: ddd/args.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/args.C,v
retrieving revision 1.36
diff -u -r1.36 args.C
--- ddd/args.C  2001/07/30 19:45:32     1.36
+++ ddd/args.C  2001/10/12 08:55:24
@@ -486,7 +486,7 @@
 {
     RestartDebuggerCB(w, client_data, call_data);
 
-    string& cmd = *((string *)client_data);
+    const string& cmd = *((const string *)client_data);
     gdb_command(cmd, w);
 }
 
Index: ddd/buttons.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/buttons.C,v
retrieving revision 1.138
diff -u -r1.138 buttons.C
--- ddd/buttons.C       2001/07/30 19:45:32     1.138
+++ ddd/buttons.C       2001/10/12 08:55:25
@@ -552,7 +552,7 @@
     return value;
 }
 
-static void strip_through(string& s, string key)
+static void strip_through(string& s, const string& key)
 {
     int key_index = s.index(key);
     int nl_index  = s.index('\n');
Index: ddd/comm-manag.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/comm-manag.C,v
retrieving revision 1.286
diff -u -r1.286 comm-manag.C
--- ddd/comm-manag.C    2001/07/30 19:45:32     1.286
+++ ddd/comm-manag.C    2001/10/12 08:55:26
@@ -744,6 +744,7 @@
     while (dummy.size() < cmds.size())
        dummy += (void *)0;
 
+    bool extra_registered;
     gdb->start_plus (partial_answer_received,
                     command_completed,
                     cmd_data,
@@ -751,8 +752,12 @@
                     dummy,
                     cmds.size(),
                     extra_completed,
-                    (void *)extra_data);
+                    (void *)extra_data,
+                    extra_registered);
 
+    if (!extra_registered)
+      delete extra_data;
+
     // Enqueue restart and settings commands.  Since we're starting up
     // and don't care for detailed diagnostics, we allow the GDB
     // `source' command.
@@ -1013,7 +1018,6 @@
     command_was_cancelled = false;
     bool next_input_goes_to_debuggee = false;
 
-    // LEAK: Check whether EXTRA_DATA is always deleted
     ExtraData *extra_data = new ExtraData;
     extra_data->command       = cmd;
     extra_data->user_callback = extra_callback;
@@ -1839,18 +1843,23 @@
     extra_data->extra_commands = cmds;
 
     // Send commands
+    bool extra_registered;
     bool send_ok = gdb->send_user_cmd_plus(cmds, dummy, cmds.size(),
                                           extra_completed, (void*)extra_data,
+                                          extra_registered,
                                           cmd, (void *)cmd_data);
-
+    if (!extra_registered)
+      {
+       delete extra_data; 
+      }
+    
     if (!send_ok)
-    {
+      {
        // Deallocate resources
-       delete extra_data;
        delete cmd_data;
 
        post_gdb_busy(origin);
-    }
+      }
 }
 
 
@@ -2368,7 +2377,7 @@
 {
     string scope;
     if (gdb->has_func_command())
-       scope = ((string&)where_answer).before('\n'); // `func' output
+       scope = where_answer.before('\n'); // `func' output
     else
        scope = get_scope(where_answer); // `where' or `frame' output
 
@@ -3192,9 +3201,9 @@
 
     if (extra_data->refresh_user)
     {
-       StringArray answers(((string *)answers) + qu_count,
+       StringArray answers_(((string *)answers) + qu_count,
                            extra_data->n_refresh_user);
-       data_disp->process_user(answers);
+       data_disp->process_user(answers_);
        qu_count += extra_data->n_refresh_user;
     }
 
@@ -3254,7 +3263,7 @@
 
 static void AsyncAnswerHP(Agent *source, void *, void *call_data)
 {
-    string& answer = *((string *)call_data);
+    const string& answer = *((const string *)call_data);
     GDBAgent *gdb = ptr_cast(GDBAgent, source);
 
     if (gdb->type() == JDB && !exception_state)
@@ -3300,7 +3309,7 @@
     if (!gdb->has_debug_command())
     {
        // Load initial source
-       const char **argv = (const char**)saved_argv();
+       const char * const *argv = saved_argv();
        int argc = 0;
        while (argv[argc] != 0)
            argc++;
Index: ddd/complete.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/complete.C,v
retrieving revision 1.29
diff -u -r1.29 complete.C
--- ddd/complete.C      2001/07/30 19:45:32     1.29
+++ ddd/complete.C      2001/10/12 08:55:27
@@ -439,7 +439,7 @@
                        char c = last_word[i];
                        if (!isid(c))
                        {
-                           input(last_space + 1, 0) = '\'';
+                           input.at(last_space + 1, 0) = '\'';
                            break;
                        }
                    }
@@ -497,7 +497,7 @@
                    char c = input[i];
                    if (!isid(c))
                    {
-                       input(0, 0) = '\'';
+                       input.at(0, 0) = '\'';
                        break;
                    }
                }
Index: ddd/converters.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/converters.C,v
retrieving revision 1.47
diff -u -r1.47 converters.C
--- ddd/converters.C    2001/07/30 19:45:32     1.47
+++ ddd/converters.C    2001/10/12 08:55:27
@@ -82,7 +82,7 @@
        0xFF, 0xFF, 0xAA, 0xAA, 0xFF, 0xFF, 0x55, 0x55  }
 };
 
-static const _XtString bitmap_name_set[] =
+static const _XtString const bitmap_name_set[] =
 {
    "25_foreground",
    "50_foreground",
@@ -183,6 +183,25 @@
         return True;                                    \
     } while(0)
 
+#define donef(type,value,failure) \
+    do {                                                \
+        if (toVal->addr != 0) {                         \
+            if (toVal->size < sizeof(type)) {           \
+                toVal->size = sizeof(type);             \
+                failure;                                \
+                return False;                           \
+            }                                           \
+            *(type *)(toVal->addr) = (value);           \
+        }                                               \
+        else {                                          \
+            static type static_val;                     \
+            static_val = (value);                       \
+            toVal->addr = (XPointer)&static_val;        \
+        }                                               \
+                                                        \
+        toVal->size = sizeof(type);                     \
+        return True;                                    \
+    } while(0)
 
 // Return string of value.  If STRIP is set, strip leading and
 // trailing whitespace.
@@ -380,7 +399,7 @@
 static const string DELIMITER = ":";
 
 // add default search paths to path
-static void addDefaultPaths(string& path, string root)
+static void addDefaultPaths(string& path, const string& root)
 {
     path += DELIMITER + root + "/%L/%T/%N/" + BASENAME;
     path += DELIMITER + root + "/%l/%T/%N/" + BASENAME;
@@ -463,10 +482,15 @@
 }
 
 
-static void XmStringFreeCB(XtPointer client_data, XtIntervalId *)
+static void CvtStringToXmStringDestroy(XtAppContext  /* app */,
+                                      XrmValue*     to,
+                                      XtPointer     /* converter_data */,
+                                      XrmValue*     /* args */,
+                                      Cardinal*     /* num_args */
+                                      )
 {
-    XmString xs = (XmString)client_data;
-    XmStringFree(xs);
+  XmStringFree(*(XmString*)to->addr);
+  return;
 }
 
 // Convert String to XmString, using `@' for font specs: address@hidden TEXT'
@@ -588,17 +612,7 @@
        return False;
     }
 
-#if 0
-    // TARGET is no longer being referenced after its use.  Be sure to
-    // free it at the next occasion.
-    XtAppAddTimeOut(XtDisplayToApplicationContext(display),
-                   0, XmStringFreeCB, (XtPointer)target);
-#else
-    // It seems this applies to all Motif implementations...
-    (void) XmStringFreeCB;     // Use it
-#endif
-    
-    done(XmString, target);
+    donef(XmString,target,XmStringFree(target));
 }
 
 
@@ -662,6 +676,18 @@
     done(XFontStruct *, font);
 }
 
+static void
+CvtStringToXmFontListDestroy(XtAppContext  /* app */,
+                            XrmValue*     to,
+                            XtPointer     /* converter_data */,
+                            XrmValue*     /* args */,
+                            Cardinal*     /* num_args */
+                            )
+{   
+  XmFontListFree( *((XmFontList *) to->addr)) ;
+  return ;
+}
+
 // Convert String to FontList, relacing address@hidden@' by symbolic font
specs.
 static Boolean CvtStringToXmFontList(Display *display, 
                                     XrmValue *, Cardinal *, 
@@ -743,7 +769,7 @@
        return False;
     }
     
-    done(XmFontList, target);
+    donef(XmFontList,target,XmFontListFree(XmFontList));
 }
 
 #endif
@@ -1025,14 +1051,14 @@
 
     // String -> XmString
     XtSetTypeConverter(XmRString, XmRXmString, CvtStringToXmString,
-                      XtConvertArgList(0), 0, XtCacheNone,
-                      XtDestructor(0));
+                      XtConvertArgList(0), 0, (XtCacheNone | XtCacheRefCount),
+                      CvtStringToXmStringDestroy);
 
 #if OWN_FONT_CONVERTERS
     // String -> FontList
     XtSetTypeConverter(XmRString, XmRFontList, CvtStringToXmFontList,
-                      XtConvertArgList(0), 0, XtCacheAll,
-                      XtDestructor(0));
+                      XtConvertArgList(0), 0, (XtCacheAll | XtCacheRefCount),
+                      CvtStringToXmFontList);
 
     // String -> FontStruct
     XtSetTypeConverter(XmRString, XtRFontStruct, CvtStringToFontStruct,
Index: ddd/cook.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/cook.h,v
retrieving revision 1.8
diff -u -r1.8 cook.h
--- ddd/cook.h  2000/05/29 14:07:26     1.8
+++ ddd/cook.h  2001/10/12 08:55:27
@@ -56,7 +56,7 @@
 // Strip quotes
 inline string _unquote(const string& s)
 {
-    return ((string&)s).at(1, s.length() - 2);
+    return s.at(1, s.length() - 2);
 }
 
 // Enclose S in quotes QUOTE
@@ -75,8 +75,8 @@
 inline string unquote(const string& s, char quote)
 {
     if (s.length() > 0 && 
-       ((string&)s)[0] == quote && 
-       ((string&)s)[s.length() - 1] == quote)
+       s[0] == quote && 
+       s[s.length() - 1] == quote)
        return unquote(s);
     else
        return s;
Index: ddd/ddd.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/ddd.C,v
retrieving revision 1.632
diff -u -r1.632 ddd.C
--- ddd/ddd.C   2001/07/31 16:10:05     1.632
+++ ddd/ddd.C   2001/10/12 08:55:31
@@ -2342,7 +2342,7 @@
     if (debugger_type == DebuggerType(-1))
     {
        // Guess debugger type from args
-       DebuggerInfo info(argc, (const char**)argv);
+       DebuggerInfo info(argc, argv);
        debugger_type = info.type;
 
        if (!app_data.auto_debugger)
@@ -3295,7 +3295,7 @@
 #endif
 
     // Resources to ignore upon copying
-    static const char *do_not_copy[] = 
+    static const char * const do_not_copy[] = 
     { 
        XmNwidth, XmNheight,                  // Shell sizes
        XmNcolumns, XmNrows,                  // Text window sizes
@@ -7258,9 +7258,9 @@
 #if 0
        helpOnVersionExtraText += cr(); // place e-mail on separate line
 #endif
-       helpOnVersionExtraText += rm(cinfo(cinfo_lt, 1));
+       helpOnVersionExtraText += rm(cinfo.at(cinfo_lt, 1));
        helpOnVersionExtraText += 
-           tt(cinfo(cinfo_lt + 1, cinfo_gt - cinfo_lt - 1));
+           tt(cinfo.at(cinfo_lt + 1, cinfo_gt - cinfo_lt - 1));
        helpOnVersionExtraText += rm(cinfo.from(cinfo_gt));
     }
     else
Index: ddd/disp-read.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/disp-read.C,v
retrieving revision 1.113
diff -u -r1.113 disp-read.C
--- ddd/disp-read.C     2001/07/30 20:20:19     1.113
+++ ddd/disp-read.C     2001/10/12 08:55:32
@@ -893,7 +893,7 @@
 }
 
 // Remove and return "NR: " from DISPLAY.
-string get_info_disp_str (string& display_info, GDBAgent *gdb)
+string get_info_disp_str (const string& display_info, GDBAgent *gdb)
 {
     switch (gdb->type())
     {
@@ -1059,6 +1059,6 @@
 
     int start_of_name = index + 1;
 
-    return ((string &)where_output).at(start_of_name, 
-                                      end_of_name - start_of_name);
+    return where_output.at(start_of_name, 
+                          end_of_name - start_of_name);
 }
Index: ddd/disp-read.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/disp-read.h,v
retrieving revision 1.42
diff -u -r1.42 disp-read.h
--- ddd/disp-read.h     2000/12/19 12:37:16     1.42
+++ ddd/disp-read.h     2001/10/12 08:55:32
@@ -207,7 +207,7 @@
 string read_next_disp_info (string& gdb_answer, GDBAgent *gdb);
 
 // Remove and return "NR: " from DISPLAY.
-string get_info_disp_str (string& display, GDBAgent *gdb);
+string get_info_disp_str (const string& display, GDBAgent *gdb);
 
 // Check whether `disabled' entry in INFO_DISP_STR indicates an enabled
display
 bool disp_is_disabled (const string& info_disp_str, GDBAgent *gdb);
Index: ddd/environ.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/environ.C,v
retrieving revision 1.8
diff -u -r1.8 environ.C
--- ddd/environ.C       2001/07/30 19:45:32     1.8
+++ ddd/environ.C       2001/10/12 08:55:32
@@ -44,7 +44,7 @@
 static StringArray environment_names;
 
 // Put NAME=VALUE into the environment
-void put_environment(string name, string value)
+void put_environment(const string& name, const string& value)
 {
     const string env_s = name + "=" + value;
     char *env = new char[env_s.length() + 1];
Index: ddd/environ.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/environ.h,v
retrieving revision 1.5
diff -u -r1.5 environ.h
--- ddd/environ.h       1999/08/19 11:28:31     1.5
+++ ddd/environ.h       2001/10/12 08:55:32
@@ -36,7 +36,7 @@
 #include "strclass.h"
 
 // Put NAME=VALUE into the environment
-extern void put_environment(string name, string value);
+extern void put_environment(const string& name, const string& value);
 
 // Return NAME1=VALUE1 NAME2=VALUE2 for each name defined by
PUT_ENVIRONMENT
 extern string set_environment_command();
Index: ddd/exit.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/exit.C,v
retrieving revision 1.97
diff -u -r1.97 exit.C
--- ddd/exit.C  2001/07/30 22:18:28     1.97
+++ ddd/exit.C  2001/10/12 08:55:33
@@ -648,7 +648,7 @@
 static void PostXtErrorCB(XtPointer client_data, XtIntervalId *)
 {
     string *msg_ptr = (string *)client_data;
-    string msg = *msg_ptr;
+    const string msg = *msg_ptr;
     delete msg_ptr;
 
     const string title = msg.before('\v');
@@ -713,7 +713,7 @@
 static void PostXErrorCB(XtPointer client_data, XtIntervalId *)
 {
     string *msg_ptr = (string *)client_data;
-    string msg = *msg_ptr;
+    const string msg = *msg_ptr;
     delete msg_ptr;
 
     const string title = msg.before('\v');
Index: ddd/file.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/file.C,v
retrieving revision 1.88
diff -u -r1.88 file.C
--- ddd/file.C  2001/07/30 19:45:32     1.88
+++ ddd/file.C  2001/10/12 08:55:33
@@ -259,7 +259,7 @@
 
 
 // Synchronize file dialogs with current directory
-void process_cd(string pwd)
+void process_cd(const string& pwd)
 {
     current_file_filter = pwd + "/*";
 
Index: ddd/file.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/file.h,v
retrieving revision 1.18
diff -u -r1.18 file.h
--- ddd/file.h  2000/01/12 17:38:21     1.18
+++ ddd/file.h  2001/10/12 08:55:34
@@ -53,7 +53,7 @@
 void update_sources();
 
 // When entering `cd', change path in file selection boxes
-extern void process_cd(string pwd);
+extern void process_cd(const string& pwd);
 
 // Get the file name from the file selection box W
 string get_file(Widget w, XtPointer, XtPointer call_data);
Index: ddd/fortranize.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/fortranize.C,v
retrieving revision 1.8
diff -u -r1.8 fortranize.C
--- ddd/fortranize.C    1999/08/19 11:28:36     1.8
+++ ddd/fortranize.C    2001/10/12 08:55:34
@@ -72,7 +72,7 @@
 
 // Return ID in `fortranized' form -- that is, in lower/upper case and
 // with appended `_'.  If GLOBALS_FIRST is set, try global symbols
first.
-string _fortranize(const string& id, bool globals_first)
+static string _fortranize(const string& id, bool globals_first)
 {
     if (globals_first)
     {
Index: ddd/gdbinit.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/gdbinit.C,v
retrieving revision 1.44
diff -u -r1.44 gdbinit.C
--- ddd/gdbinit.C       2001/07/30 19:45:32     1.44
+++ ddd/gdbinit.C       2001/10/12 08:55:34
@@ -168,7 +168,7 @@
 // Show call in output window
 static void EchoTextCB(XtPointer client_data, XtIntervalId *)
 {
-    const string& gdb_call = *((string *)client_data);
+    const string& gdb_call = *((const string *)client_data);
     _gdb_out(gdb_call);
 }
 
@@ -217,7 +217,7 @@
        else
        {
            // Invoke GDB...
-           const string& gdb_call = *((string *)client_data);
+           const string& gdb_call = *((const string *)client_data);
            gdb->write(gdb_call.chars(), gdb_call.length());
 
            // Echoing should be disabled by now.  Echo call manually...
@@ -244,7 +244,7 @@
 
 // Return an appropriate debugger type from ARGC/ARGV.
 // Set ARG if debugger type could be deduced from an argument.
-DebuggerInfo::DebuggerInfo(int argc, const char *argv[])
+DebuggerInfo::DebuggerInfo(int argc, const char * const argv[])
     : type(DebuggerType(-1)),
       arg("")
 {
Index: ddd/gdbinit.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/gdbinit.h,v
retrieving revision 1.12
diff -u -r1.12 gdbinit.h
--- ddd/gdbinit.h       2000/12/11 12:21:48     1.12
+++ ddd/gdbinit.h       2001/10/12 08:55:34
@@ -50,7 +50,7 @@
     DebuggerType type;
     string arg;
 
-    DebuggerInfo(int argc, const char *argv[]);
+    DebuggerInfo(int argc, const char * const argv[]);
 };
 
 // Determine debugger type from given DEBUGGER_NAME
Index: ddd/java.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/java.C,v
retrieving revision 1.14
diff -u -r1.14 java.C
--- ddd/java.C  2001/07/30 19:45:32     1.14
+++ ddd/java.C  2001/10/12 08:55:34
@@ -427,7 +427,7 @@
                        int start = i;
                        while (start > 0 && isid(class_file[start - 1]))
                            start--;
-                       src_class = class_file(start, i - start);
+                       src_class = class_file.at(start, i - start);
 
                        // Search for this class file instead.
                        c = java_class_file(src_class, false);
@@ -441,7 +441,7 @@
                        while (start >= 0 && class_file[start] != '\001')
                            start--;
                        start += 3;     // Skip \001 LENGTH
-                       src_class = class_file(start, i - start);
+                       src_class = class_file.at(start, i - start);
                            
                        c = java_class_file(src_class, false);
                        if (c != "")
Index: ddd/options.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/options.C,v
retrieving revision 1.178
diff -u -r1.178 options.C
--- ddd/options.C       2001/07/30 22:18:28     1.178
+++ ddd/options.C       2001/10/12 08:55:35
@@ -1923,7 +1923,7 @@
 // Write state

//-----------------------------------------------------------------------------
 
-static bool is_fallback_value(string resource, string val)
+static bool is_fallback_value(const string& resource, string val)
 {
     static XrmDatabase default_db =
app_defaults(XtDisplay(find_shell()));
 
@@ -1945,7 +1945,7 @@
 
     if (success)
     {
-       char *str = (char *)xrmvalue.addr;
+       const char *str = (const char *)xrmvalue.addr;
        int len   = xrmvalue.size - 1; // includes the final `\0'
        default_val = string(str, len);
     }
@@ -1965,7 +1965,7 @@
     return val == default_val;
 }
 
-static string app_value(string resource, const string& value, 
+static string app_value(const string& resource, const string& value, 
                        bool check_default)
 {
     static String app_name  = 0;
Index: ddd/plotter.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/plotter.C,v
retrieving revision 1.47
diff -u -r1.47 plotter.C
--- ddd/plotter.C       2001/07/30 19:45:32     1.47
+++ ddd/plotter.C       2001/10/12 08:55:35
@@ -962,7 +962,7 @@
 
 
 // Create a new plot window
-PlotAgent *new_plotter(string name, DispValue *source)
+PlotAgent *new_plotter(const string& name, DispValue *source)
 {
     static int tics = 1;
 
@@ -1497,7 +1497,7 @@
     s.gsub("\\n", nl);
 
     if (s_ends_with_nl)
-       s(s.length() - 1, 0) = "\\n";
+       s.at((int)(s.length() - 1), 0) = "\\n";
 
     dddlog << prefix << s << '\n';
     dddlog.flush();
Index: ddd/plotter.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/plotter.h,v
retrieving revision 1.4
diff -u -r1.4 plotter.h
--- ddd/plotter.h       1999/08/19 11:28:47     1.4
+++ ddd/plotter.h       2001/10/12 08:55:35
@@ -39,7 +39,7 @@
 class DispValue;
 
 // Create a new plot window
-PlotAgent *new_plotter(string name, DispValue *src);
+PlotAgent *new_plotter(const string& name, DispValue *src);
 
 // Clear cached plot decorations
 void clear_plot_window_cache();
Index: ddd/print.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/print.C,v
retrieving revision 1.55
diff -u -r1.55 print.C
--- ddd/print.C 2001/07/30 19:45:33     1.55
+++ ddd/print.C 2001/10/12 08:55:35
@@ -92,7 +92,7 @@
 // Printing Dialog

//-----------------------------------------------------------------------------
 
-static string msg(string path, bool displays, bool to_file)
+static string msg(const string& path, bool displays, bool to_file)
 {
     string m = "Printing ";
     if (displays)
@@ -109,7 +109,7 @@
 }
 
 // Print to FILENAME according to given PrintGC
-static int print_to_file(string filename, PrintGC& gc, 
+static int print_to_file(const string& filename, PrintGC& gc, 
                         bool selectedOnly, bool displays)
 {
     string path = filename;
@@ -443,7 +443,7 @@
     print_target = PrintTarget((int)(long)client_data);
 }
 
-static void set_paper_size_string(string s)
+static void set_paper_size_string(const string& s)
 {
     Widget text = XmSelectionBoxGetChild(paper_size_dialog,
XmDIALOG_TEXT);
     XmTextSetString(text, CONST_CAST(char*,s.chars()));
@@ -605,7 +605,7 @@
     return abs(i - j) <= 2;
 }
 
-static void get_paper_size(string s, int& hsize, int& vsize)
+static void get_paper_size(const string& s, int& hsize, int& vsize)
 {
     char delim = '\0';
 
@@ -631,7 +631,7 @@
     vsize = points(s_vsize);
 }
 
-static bool set_paper_size(string s)
+static bool set_paper_size(const string& s)
 {
     int hsize, vsize;
     get_paper_size(s, hsize, vsize);
Index: ddd/select.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/select.C,v
retrieving revision 1.15
diff -u -r1.15 select.C
--- ddd/select.C        2001/07/30 19:45:33     1.15
+++ ddd/select.C        2001/10/12 08:55:36
@@ -164,7 +164,7 @@
 }
 
 // Select a file
-static void select_file(string& /* question */, string& reply)
+static void select_file(const string& /* question */, string& reply)
 {
     gdbOpenFileCB(find_shell(), 0, 0);
 
Index: ddd/session.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/session.C,v
retrieving revision 1.63
diff -u -r1.63 session.C
--- ddd/session.C       2001/07/30 20:21:15     1.63
+++ ddd/session.C       2001/10/12 08:55:36
@@ -192,7 +192,7 @@
     }
 };
 
-static int makedir(string name, ostream& msg, bool user_only = false)
+static int makedir(const string& name, ostream& msg, bool user_only =
false)
 {
     StreamAction action(msg, "Creating " + quote(name + "/"));
 
@@ -1198,7 +1198,7 @@
 static void ConfirmSmShutdownCB   (Widget w, XtPointer, XtPointer
call_data);
 static void CancelSmShutdownCB    (Widget w, XtPointer, XtPointer
call_data);
 
-static void ask(string text, const _XtString name,
+static void ask(const string& text, const _XtString name,
                XtCheckpointToken token, Widget w,
                XtCallbackProc yes, XtCallbackProc no);
 
@@ -1359,7 +1359,7 @@
 }
 
 // Create a confirmation dialog
-static void ask(string text, const _XtString name, XtCheckpointToken
token, Widget w,
+static void ask(const string& text, const _XtString name,
XtCheckpointToken token, Widget w,
                XtCallbackProc yes, XtCallbackProc no)
 {
     // Program is still running; request confirmation
Index: ddd/settings.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/settings.C,v
retrieving revision 1.135
diff -u -r1.135 settings.C
--- ddd/settings.C      2001/07/30 19:45:33     1.135
+++ ddd/settings.C      2001/10/12 08:55:37
@@ -168,7 +168,7 @@
 }
 
 // Issue `set' command
-static void gdb_set_command(string set_command, string value)
+static void gdb_set_command(const string& set_command, string value)
 {
     if (gdb->type() == GDB && value == "unlimited")
        value = "0";
@@ -688,7 +688,7 @@
 }
 
 // Process output of `show' command
-void process_show(string command, string value, bool init)
+void process_show(const string& command, string value, bool init)
 {
     if (settings_form == 0)
        return;
@@ -1158,7 +1158,7 @@
 
 
 // Get DBX documentation
-static string _get_dbx_help(string dbxenv, string base)
+static string _get_dbx_help(const string& dbxenv, const string& base)
 {
     string dbx_help;
     if (dbxenv == "dbxenv")
@@ -1258,7 +1258,7 @@
 }
 
 // Same, but for usage in help messages
-static string get_dbx_help(string dbxenv, string base, int width)
+static string get_dbx_help(const string& dbxenv, const string& base,
int width)
 {
     string dbx_help = _get_dbx_help(dbxenv, base);
     dbx_help = dbx_help.after(base);
@@ -1285,7 +1285,7 @@
     return dbx_help;
 }
 
-string get_dbx_help(string dbxenv, string base)
+string get_dbx_help(const string& dbxenv, const string& base)
 {
     return get_dbx_help(dbxenv, base, 60);
 }
@@ -1333,7 +1333,7 @@
     {"suppress_startup_message", "Suppress startup message below
release"}
 };
 
-static string get_dbx_doc(string dbxenv, string base)
+static string get_dbx_doc(const string& dbxenv, const string& base)
 {
     // Some specials
     for (int i = 0; i < int(XtNumber(dbx_translations)); i++)
@@ -2396,7 +2396,7 @@
 }
 
 // Fetch help for specific COMMAND
-static string get_help_line(string command, DebuggerType type)
+static string get_help_line(const string& command, DebuggerType type)
 {
     (void) type;
 
@@ -3410,7 +3410,7 @@
     menu = (String)XtNewString(s.chars());
 }
 
-static void remove_button(string name, const _XtString& menu)
+static void remove_button(const string& name, const _XtString& menu)
 {
     string s = string("\n") + menu;
     s.gsub("\n" + name + "\n", string("\n"));
Index: ddd/settings.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/settings.h,v
retrieving revision 1.29
diff -u -r1.29 settings.h
--- ddd/settings.h      2000/12/19 00:25:22     1.29
+++ ddd/settings.h      2001/10/12 08:55:37
@@ -46,7 +46,7 @@
 extern void dddPopupSettingsCB(Widget, XtPointer, XtPointer);
 
 // Process `show' output
-extern void process_show(string command, string value, bool init =
false);
+extern void process_show(const string& command, string value, bool init
= false);
 
 // True if settings might have changed
 extern bool need_settings();
@@ -59,7 +59,7 @@
                           unsigned long flags = SAVE_DEFAULT);
 
 // Get help on `DBXENV BASE'
-extern string get_dbx_help(string dbxenv, string base);
+extern string get_dbx_help(const string& dbxenv, const string& base);
 
 // Mark settings as `saved'
 extern void save_settings_state();
Index: ddd/shell.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/shell.C,v
retrieving revision 1.17
diff -u -r1.17 shell.C
--- ddd/shell.C 2001/07/30 19:45:33     1.17
+++ ddd/shell.C 2001/10/12 08:55:37
@@ -117,7 +117,7 @@
     return rsh;
 }
 
-string sh_command(string command, bool force_local)
+string sh_command(const string& command, bool force_local)
 {
     string ret = _sh_command(command, force_local);
     dddlog << "+  " << ret << "\n";
Index: ddd/shell.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/shell.h,v
retrieving revision 1.7
diff -u -r1.7 shell.h
--- ddd/shell.h 1999/08/19 11:28:54     1.7
+++ ddd/shell.h 2001/10/12 08:55:37
@@ -41,7 +41,7 @@
 extern string _sh_command(string command = "", 
                          bool force_local = false,
                          bool force_display_settings = false);
-extern string sh_command(string command = "", bool force_local =
false);
+extern string sh_command(const string& command = "", bool force_local =
false);
 extern string sh_quote(string s);
 
 // Host management
Index: ddd/strclass.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/strclass.C,v
retrieving revision 1.25
diff -u -r1.25 strclass.C
--- ddd/strclass.C      2001/07/30 19:45:33     1.25
+++ ddd/strclass.C      2001/10/12 08:55:37
@@ -903,43 +903,82 @@
     return _substr(first, len);
 }
 
+constSubString string::at(int first, int len) const
+{
+    return _substr(first, len);
+}
+
+#if 0
 subString string::operator() (int first, int len)
 {
     return _substr(first, len);
 }
+#endif
 
 subString string::before(int pos)
 {
     return _substr(0, pos);
 }
 
+constSubString string::before(int pos) const
+{
+    return _substr(0, pos);
+}
+
 subString string::through(int pos)
 {
     return _substr(0, pos+1);
 }
 
+constSubString string::through(int pos) const
+{
+    return _substr(0, pos+1);
+}
+
 subString string::after(int pos)
 {
     return _substr(pos + 1, length() - (pos + 1));
 }
 
+constSubString string::after(int pos) const
+{
+    return _substr(pos + 1, length() - (pos + 1));
+}
+
 subString string::from(int pos)
 {
     return _substr(pos, length() - pos);
 }
 
+constSubString string::from(int pos) const
+{
+    return _substr(pos, length() - pos);
+}
+
 subString string::at(const string& y, int startpos)
 {
     int first = search(startpos, length(), y.chars(), y.length());
     return _substr(first,  y.length());
 }
 
+constSubString string::at(const string& y, int startpos) const
+{
+    int first = search(startpos, length(), y.chars(), y.length());
+    return _substr(first,  y.length());
+}
+
 subString string::at(const subString& y, int startpos)
 {
     int first = search(startpos, length(), y.chars(), y.length());
     return _substr(first, y.length());
 }
 
+constSubString string::at(const constSubString& y, int startpos) const
+{
+    int first = search(startpos, length(), y.chars(), y.length());
+    return _substr(first, y.length());
+}
+
 subString string::at(const regex& r, int startpos)
 {
     int mlen;
@@ -947,6 +986,13 @@
     return _substr(first, mlen);
 }
 
+constSubString string::at(const regex& r, int startpos) const
+{
+    int mlen;
+    int first = r.search(chars(), length(), mlen, startpos);
+    return _substr(first, mlen);
+}
+
 subString string::at(const char* t, int startpos)
 {
     int tlen = slen(t);
@@ -954,24 +1000,49 @@
     return _substr(first, tlen);
 }
 
+constSubString string::at(const char* t, int startpos) const
+{
+    int tlen = slen(t);
+    int first = search(startpos, length(), t, tlen);
+    return _substr(first, tlen);
+}
+
 subString string::at(char c, int startpos)
 {
     int first = search(startpos, length(), c);
     return _substr(first, 1);
 }
 
+constSubString string::at(char c, int startpos) const
+{
+    int first = search(startpos, length(), c);
+    return _substr(first, 1);
+}
+
 subString string::before(const string& y, int startpos)
 {
     int last = search(startpos, length(), y.chars(), y.length());
     return _substr(0, last);
 }
 
+constSubString string::before(const string& y, int startpos) const
+{
+    int last = search(startpos, length(), y.chars(), y.length());
+    return _substr(0, last);
+}
+
 subString string::before(const subString& y, int startpos)
 {
     int last = search(startpos, length(), y.chars(), y.length());
     return _substr(0, last);
 }
 
+constSubString string::before(const constSubString& y, int startpos)
const
+{
+    int last = search(startpos, length(), y.chars(), y.length());
+    return _substr(0, last);
+}
+
 subString string::before(const regex& r, int startpos)
 {
     int mlen;
@@ -979,12 +1050,25 @@
     return _substr(0, first);
 }
 
+constSubString string::before(const regex& r, int startpos) const
+{
+    int mlen;
+    int first = r.search(chars(), length(), mlen, startpos);
+    return _substr(0, first);
+}
+
 subString string::before(char c, int startpos)
 {
     int last = search(startpos, length(), c);
     return _substr(0, last);
 }
 
+constSubString string::before(char c, int startpos) const
+{
+    int last = search(startpos, length(), c);
+    return _substr(0, last);
+}
+
 subString string::before(const char* t, int startpos)
 {
     int tlen = slen(t);
@@ -992,6 +1076,13 @@
     return _substr(0, last);
 }
 
+constSubString string::before(const char* t, int startpos) const
+{
+    int tlen = slen(t);
+    int last = search(startpos, length(), t, tlen);
+    return _substr(0, last);
+}
+
 subString string::through(const string& y, int startpos)
 {
     int last = search(startpos, length(), y.chars(), y.length());
@@ -1000,6 +1091,14 @@
     return _substr(0, last);
 }
 
+constSubString string::through(const string& y, int startpos) const
+{
+    int last = search(startpos, length(), y.chars(), y.length());
+    if (last >= 0)
+       last += y.length();
+    return _substr(0, last);
+}
+
 subString string::through(const subString& y, int startpos)
 {
     int last = search(startpos, length(), y.chars(), y.length());
@@ -1008,6 +1107,14 @@
     return _substr(0, last);
 }
 
+constSubString string::through(const constSubString& y, int startpos)
const
+{
+    int last = search(startpos, length(), y.chars(), y.length());
+    if (last >= 0)
+       last += y.length();
+    return _substr(0, last);
+}
+
 subString string::through(const regex& r, int startpos)
 {
     int mlen;
@@ -1017,6 +1124,15 @@
     return _substr(0, first);
 }
 
+constSubString string::through(const regex& r, int startpos) const
+{
+    int mlen;
+    int first = r.search(chars(), length(), mlen, startpos);
+    if (first >= 0)
+       first += mlen;
+    return _substr(0, first);
+}
+
 subString string::through(char c, int startpos)
 {
     int last = search(startpos, length(), c);
@@ -1025,6 +1141,14 @@
     return _substr(0, last);
 }
 
+constSubString string::through(char c, int startpos) const
+{
+    int last = search(startpos, length(), c);
+    if (last >= 0)
+       last += 1;
+    return _substr(0, last);
+}
+
 subString string::through(const char* t, int startpos)
 {
     int tlen = slen(t);
@@ -1034,6 +1158,15 @@
     return _substr(0, last);
 }
 
+constSubString string::through(const char* t, int startpos) const
+{
+    int tlen = slen(t);
+    int last = search(startpos, length(), t, tlen);
+    if (last >= 0)
+       last += tlen;
+    return _substr(0, last);
+}
+
 subString string::after(const string& y, int startpos)
 {
     int first = search(startpos, length(), y.chars(), y.length());
@@ -1042,6 +1175,14 @@
     return _substr(first, length() - first);
 }
 
+constSubString string::after(const string& y, int startpos) const
+{
+    int first = search(startpos, length(), y.chars(), y.length());
+    if (first >= 0)
+       first += y.length();
+    return _substr(first, length() - first);
+}
+
 subString string::after(const subString& y, int startpos)
 {
     int first = search(startpos, length(), y.chars(), y.length());
@@ -1050,6 +1191,14 @@
     return _substr(first, length() - first);
 }
 
+constSubString string::after(const constSubString& y, int startpos)
const
+{
+    int first = search(startpos, length(), y.chars(), y.length());
+    if (first >= 0)
+       first += y.length();
+    return _substr(first, length() - first);
+}
+
 subString string::after(char c, int startpos)
 {
     int first = search(startpos, length(), c);
@@ -1058,6 +1207,14 @@
     return _substr(first, length() - first);
 }
 
+constSubString string::after(char c, int startpos) const
+{
+    int first = search(startpos, length(), c);
+    if (first >= 0)
+       first += 1;
+    return _substr(first, length() - first);
+}
+
 subString string::after(const regex& r, int startpos)
 {
     int mlen;
@@ -1067,6 +1224,15 @@
     return _substr(first, length() - first);
 }
 
+constSubString string::after(const regex& r, int startpos) const
+{
+    int mlen;
+    int first = r.search(chars(), length(), mlen, startpos);
+    if (first >= 0) 
+       first += mlen;
+    return _substr(first, length() - first);
+}
+
 subString string::after(const char* t, int startpos)
 {
     int tlen = slen(t);
@@ -1076,18 +1242,39 @@
     return _substr(first, length() - first);
 }
 
+constSubString string::after(const char* t, int startpos) const
+{
+    int tlen = slen(t);
+    int first = search(startpos, length(), t, tlen);
+    if (first >= 0)
+       first += tlen;
+    return _substr(first, length() - first);
+}
+
 subString string::from(const string& y, int startpos)
 {
     int first = search(startpos, length(), y.chars(), y.length());
     return _substr(first, length() - first);
 }
 
+constSubString string::from(const string& y, int startpos) const
+{
+    int first = search(startpos, length(), y.chars(), y.length());
+    return _substr(first, length() - first);
+}
+
 subString string::from(const subString& y, int startpos)
 {
     int first = search(startpos, length(), y.chars(), y.length());
     return _substr(first, length() - first);
 }
 
+constSubString string::from(const constSubString& y, int startpos)
const
+{
+    int first = search(startpos, length(), y.chars(), y.length());
+    return _substr(first, length() - first);
+}
+
 subString string::from(const regex& r, int startpos)
 {
     int mlen;
@@ -1095,12 +1282,25 @@
     return _substr(first, length() - first);
 }
 
+constSubString string::from(const regex& r, int startpos) const
+{
+    int mlen;
+    int first = r.search(chars(), length(), mlen, startpos);
+    return _substr(first, length() - first);
+}
+
 subString string::from(char c, int startpos)
 {
     int first = search(startpos, length(), c);
     return _substr(first, length() - first);
 }
 
+constSubString string::from(char c, int startpos) const
+{
+    int first = search(startpos, length(), c);
+    return _substr(first, length() - first);
+}
+
 subString string::from(const char* t, int startpos)
 {
     int tlen = slen(t);
@@ -1108,6 +1308,12 @@
     return _substr(first, length() - first);
 }
 
+constSubString string::from(const char* t, int startpos) const
+{
+    int tlen = slen(t);
+    int first = search(startpos, length(), t, tlen);
+    return _substr(first, length() - first);
+}
 
 
 /*
@@ -1154,7 +1360,7 @@
     return i;
 }
 
-string join(string *src, int n, const string& separator) RETURNS(x)
+string join(const string *src, int n, const string& separator)
RETURNS(x)
 {
     RETURN_OBJECT(string, x);
     string sep = separator;
@@ -1539,6 +1745,14 @@
 }
 
 bool subString::OK() const
+{
+    // Check for legal string and pos and len outside bounds
+    if (!S.OK() || pos + len > S.rep->len)
+       S.error("subString invariant failure");
+    return true;
+}
+
+bool constSubString::OK() const
 {
     // Check for legal string and pos and len outside bounds
     if (!S.OK() || pos + len > S.rep->len)
Index: ddd/strclass.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/strclass.h,v
retrieving revision 1.37
diff -u -r1.37 strclass.h
--- ddd/strclass.h      2001/07/30 19:45:33     1.37
+++ ddd/strclass.h      2001/10/12 08:55:38
@@ -27,6 +27,7 @@
 // - output to stream issues *all* characters, including '\0'
 // - extra functions for `char *' provided (besides `const char *')
 // - `cat' with 4 arguments is not supported
+// - constSubString added to keep the const-ness.
 
 
 // Here's the libg++ documentation of Doug Lea, adapted for this class:
@@ -451,10 +452,55 @@
 
 class string;
 class subString;
+class constSubString;
 
+class constSubString
+{
+    friend class string;
+
+protected:
+
+    const string& S;           // The string I'm a constSubString of
+    unsigned int pos;          // Starting position in S's rep
+    unsigned int len;          // Length of subString
+
+    constSubString(const string& x, int p, int l);
+
+public:
+    // Note there are no public constructors. subStrings are always
+    // created via string operations
+    
+    // This one should be protected, but KCC keeps complaining about
this
+    constSubString(const constSubString& x);
+    constSubString(const subString& x);
+    ~constSubString();
+
+    // Return true if target appears anywhere in constSubString
+    bool contains(char c) const;
+    bool contains(const string& y) const;
+    bool contains(const constSubString& y) const;
+    bool contains(const char* t) const;
+    bool contains(char* t) const;
+    bool contains(const regex& r) const;
+
+    // Return true if target matches entire constSubString
+    bool matches(const regex& r) const;
+
+    // I/O 
+    //friend inline ostream& operator<<(ostream& s, const
constSubString& x);
+
+    // Status
+    unsigned int length() const;
+    bool empty() const;
+    const char* chars() const;
+
+    bool OK() const; 
+};
+
 class subString
 {
     friend class string;
+    friend class constSubString;
 
 protected:
 
@@ -464,7 +510,6 @@
 
     void assign(strRep*, const char*, int = -1);
     subString(string& x, int p, int l);
-    subString(const string& x, int p, int l);
 
 public:
     // Note there are no public constructors. subStrings are always
@@ -480,7 +525,7 @@
     subString& operator = (char* t);
     subString& operator = (char c);
 
-    // Return true iff target appears anywhere in subString
+    // Return true if target appears anywhere in subString
     bool contains(char c) const;
     bool contains(const string& y) const;
     bool contains(const subString& y) const;
@@ -488,7 +533,7 @@
     bool contains(char* t) const;
     bool contains(const regex& r) const;
 
-    // Return true iff target matches entire subString
+    // Return true if target matches entire subString
     bool matches(const regex& r) const;
 
     // I/O 
@@ -506,6 +551,7 @@
 class string
 {
     friend class subString;
+    friend class constSubString;
 
 protected:
     strRep* rep;        // Strings are pointers to their representations
@@ -520,7 +566,7 @@
     int _gsub(const char*, int, const char* ,int);
     int _gsub(const regex&, const char*, int);
     subString _substr(int, int);
-    const subString _substr(int, int) const;
+    constSubString _substr(int, int) const;
 
 private:
     // Don't get constructed or assigned from int
@@ -538,6 +584,7 @@
     string();
     string(const string& x);
     string(const subString&  x);
+    string(const constSubString&  x);
     string(const char* t);
     string(const char* t, int len);
     string(char c);
@@ -553,17 +600,20 @@
     string& operator = (char* y);
     string& operator = (char c);
     string& operator = (const subString& y);
+    string& operator = (const constSubString& y);
     string& operator = (ostrstream& os);
 
     // Concatenation
     string& operator += (const string& y); 
     string& operator += (const subString& y);
+    string& operator += (const constSubString& y);
     string& operator += (const char* t);
     string& operator += (char* t);
     string& operator += (char c);
 
     string& prepend(const string& y); 
     string& prepend(const subString& y);
+    string& prepend(const constSubString& y);
     string& prepend(const char* t);
     string& prepend(char* t);
     string& prepend(char c);
@@ -650,7 +700,9 @@
     // this leaves open the possiblility of indirectly modifying the
     // string through the subString
     subString at(int pos, int len);
+#if 0
     subString operator() (int pos, int len); // synonym for at
+#endif
 
     subString at(const string& x, int startpos = 0); 
     subString at(const subString&  x, int startpos = 0); 
@@ -692,47 +744,49 @@
     subString after(const regex& r, int startpos = 0);
 
     // Const versions
-    const subString at(int pos, int len) const;
-    const subString operator() (int pos, int len) const; // synonym for
at
+    constSubString at(int pos, int len) const;
+#if 0
+    constSubString operator() (int pos, int len) const; // synonym for
at
+#endif
 
-    const subString at(const string& x, int startpos = 0) const;
-    const subString at(const subString&  x, int startpos = 0) const;
-    const subString at(const char* t, int startpos = 0) const;
-    const subString at(char* t, int startpos = 0) const;
-    const subString at(char c, int startpos = 0) const;
-    const subString at(const regex& r, int startpos = 0) const;
-
-    const subString before(int pos) const;
-    const subString before(const string& x, int startpos = 0) const;
-    const subString before(const subString&   x, int startpos = 0)
const;
-    const subString before(const char* t, int startpos = 0) const;
-    const subString before(char* t, int startpos = 0) const;
-    const subString before(char c, int startpos = 0) const;
-    const subString before(const regex& r, int startpos = 0) const;
-
-    const subString through(int pos) const;
-    const subString through(const string& x, int startpos = 0) const;
-    const subString through(const subString& x, int startpos = 0)
const;
-    const subString through(const char* t, int startpos = 0) const;
-    const subString through(char* t, int startpos = 0) const;
-    const subString through(char c, int startpos = 0) const;
-    const subString through(const regex& r, int startpos = 0) const;
-
-    const subString from(int pos) const;
-    const subString from(const string& x, int startpos = 0) const;
-    const subString from(const subString& x, int startpos = 0) const;
-    const subString from(const char* t, int startpos = 0) const;
-    const subString from(char* t, int startpos = 0) const;
-    const subString from(char c, int startpos = 0) const;
-    const subString from(const regex& r, int startpos = 0) const;
-
-    const subString after(int pos) const;
-    const subString after(const string& x, int startpos = 0) const;
-    const subString after(const subString& x, int startpos = 0) const;
-    const subString after(const char* t, int startpos = 0) const;
-    const subString after(char* t, int startpos = 0) const;
-    const subString after(char c, int startpos = 0) const;
-    const subString after(const regex& r, int startpos = 0) const;
+    constSubString at(const string& x, int startpos = 0) const;
+    constSubString at(const constSubString&  x, int startpos = 0)
const;
+    constSubString at(const char* t, int startpos = 0) const;
+    constSubString at(char* t, int startpos = 0) const;
+    constSubString at(char c, int startpos = 0) const;
+    constSubString at(const regex& r, int startpos = 0) const;
+    
+    constSubString before(int pos) const;
+    constSubString before(const string& x, int startpos = 0) const;
+    constSubString before(const constSubString&   x, int startpos = 0)
const;
+    constSubString before(const char* t, int startpos = 0) const;
+    constSubString before(char* t, int startpos = 0) const;
+    constSubString before(char c, int startpos = 0) const;
+    constSubString before(const regex& r, int startpos = 0) const;
+    
+    constSubString through(int pos) const;
+    constSubString through(const string& x, int startpos = 0) const;
+    constSubString through(const constSubString& x, int startpos = 0)
const;
+    constSubString through(const char* t, int startpos = 0) const;
+    constSubString through(char* t, int startpos = 0) const;
+    constSubString through(char c, int startpos = 0) const;
+    constSubString through(const regex& r, int startpos = 0) const;
+    
+    constSubString from(int pos) const;
+    constSubString from(const string& x, int startpos = 0) const;
+    constSubString from(const constSubString& x, int startpos = 0)
const;
+    constSubString from(const char* t, int startpos = 0) const;
+    constSubString from(char* t, int startpos = 0) const;
+    constSubString from(char c, int startpos = 0) const;
+    constSubString from(const regex& r, int startpos = 0) const;
+    
+    constSubString after(int pos) const;
+    constSubString after(const string& x, int startpos = 0) const;
+    constSubString after(const constSubString& x, int startpos = 0)
const;
+    constSubString after(const char* t, int startpos = 0) const;
+    constSubString after(char* t, int startpos = 0) const;
+    constSubString after(char c, int startpos = 0) const;
+    constSubString after(const regex& r, int startpos = 0) const;
 
 
     // Deletion
@@ -772,7 +826,7 @@
                                int startpos = -1);
     // friend string replicate(char c, int n);
     friend string replicate(const string& y, int n);
-    friend string join(string *src, int n, const string& sep);
+    friend string join(const string *src, int n, const string& sep);
 
     // Simple builtin transformations
     friend inline string reverse(const string& x);
@@ -876,6 +930,10 @@
 inline bool         subString::empty() const { return len == 0; }
 inline const char*  subString::chars() const { return S.rep->s + pos; }
 
+inline unsigned int constSubString::length() const { return len; }
+inline bool         constSubString::empty() const { return len == 0; }
+inline const char*  constSubString::chars() const { return S.rep->s +
pos; }
+
 // Resources
 inline void string::consuming(bool set)
 {
@@ -931,6 +989,13 @@
 #endif
   {}
 
+inline string::string(const constSubString& y)
+  : rep(string_Salloc(0, y.chars(), y.length(), y.length()))
+#if STRING_CHECK_CONSUME
+    , consume(false) 
+#endif
+  {}
+
 inline string::string(char c) 
   : rep(string_Salloc(0, &c, 1, 1))
 #if STRING_CHECK_CONSUME
@@ -963,11 +1028,18 @@
   :S(x.S), pos(x.pos), len(x.len) {}
 inline subString::subString(string& x, int first, int l)
   :S(x), pos(first), len(l) {}
-inline subString::subString(const string& x, int first, int l)
-  :S((string &)x), pos(first), len(l) {}
 
 inline subString::~subString() {}
 
+inline constSubString::constSubString(const constSubString& x)
+  :S(x.S), pos(x.pos), len(x.len) {}
+inline constSubString::constSubString(const subString& x)
+  :S(x.S), pos(x.pos), len(x.len) {}
+inline constSubString::constSubString(const string& x, int first, int
l)
+  :S(x), pos(first), len(l) {}
+
+inline constSubString::~constSubString() {}
+
 // String Assignment
 
 inline string& string::operator = (const string& y)
@@ -1046,6 +1118,30 @@
     return *this;
 }
 
+inline string& string::operator = (const constSubString&  y)
+{
+    if (y.empty())
+    {
+       // Assignment of empty substring
+       rep->s += rep->len;
+       rep->len = 0;
+    }
+    else if (y.chars() >= &(rep->mem[0]) && 
+            y.chars() < &(rep->mem[0]) + rep->allocated)
+    {
+       // Assignment of self-substring
+       rep->s   = CONST_CAST(char *,y.chars());
+       rep->len = y.length();
+       rep->s[rep->len] = '\0';
+    }
+    else
+    {
+       assert(!consuming());
+       rep = string_Salloc(rep, y.chars(), y.length(), y.length());
+    }
+    return *this;
+}
+
 inline string& string::operator = (char c)
 {
     assert(!consuming());
@@ -1095,7 +1191,6 @@
     operator=(os);
 }
 
-
 // Substring assignments
 
 inline subString& subString::operator = (const char* ys)
@@ -1287,6 +1382,11 @@
     cat(*this, y, *this); return *this;
 }
 
+inline string& string::operator += (const constSubString& y)
+{
+    cat(*this, y, *this); return *this;
+}
+
 inline string& string::operator += (const char* y)
 {
     cat(*this, y, *this); return *this;
@@ -1798,37 +1898,36 @@
     return S.search(pos, pos+len, t) >= 0;
 }
 
-inline bool subString::contains(char* t) const
+inline bool constSubString::contains(char* t) const
 {   
     return S.search(pos, pos+len, t) >= 0;
 }
 
-inline bool subString::contains(const string& y) const
+inline bool constSubString::contains(const string& y) const
 {   
     return S.search(pos, pos+len, y.chars(), y.length()) >= 0;
 }
 
-inline bool subString::contains(const subString&  y) const
+inline bool constSubString::contains(const constSubString&  y) const
 {   
     return S.search(pos, pos+len, y.chars(), y.length()) >= 0;
 }
 
-inline bool subString::contains(char c) const
+inline bool constSubString::contains(char c) const
 {
     return S.search(pos, pos+len, 0, c) >= 0;
 }
 
-inline bool subString::contains(const regex& r) const
+inline bool constSubString::contains(const regex& r) const
 {
     int unused;  return r.search(chars(), len, unused, 0) >= 0;
 }
 
-inline bool subString::matches(const regex& r) const
+inline bool constSubString::matches(const regex& r) const
 {
     return unsigned(r.match(chars(), len, 0)) == len;
 }
 
-
 inline int string::gsub(const string& pat, const string& r)
 {
     return _gsub(pat.chars(), pat.length(), r.chars(), r.length());
@@ -1874,7 +1973,6 @@
     return _gsub(pat, -1, r, -1);
 }
 
-
 // `char *' => `const char *' wrappers
 
 inline subString string::after(char* t, int startpos)
@@ -1882,6 +1980,11 @@
     return after((const char *)t, startpos);
 }
 
+inline constSubString string::after(char* t, int startpos) const
+{
+    return after((const char *)t, startpos);
+}
+
 inline subString string::at(char* t, int startpos)
 {
     return at((const char *)t, startpos);
@@ -1892,6 +1995,11 @@
     return before((const char *)t, startpos);
 }
 
+inline constSubString string::before(char* t, int startpos) const
+{
+    return before((const char *)t, startpos);
+}
+
 inline void string::del(char* t, int startpos)
 {
     del((const char *)t, startpos);
@@ -1907,11 +2015,21 @@
     return from((const char *)t, startpos);
 }
 
+inline constSubString string::from(char* t, int startpos) const
+{
+    return from((const char *)t, startpos);
+}
+
 inline subString string::through(char* t, int startpos)
 {
     return through((const char *)t, startpos);
 }
 
+inline constSubString string::through(char* t, int startpos) const
+{
+    return through((const char *)t, startpos);
+}
+
 inline int compare(const subString& x, char* y)
 {
     return compare(x, (const char*)y);
@@ -1952,197 +2070,6 @@
     return -compare(y, x);
 }
 
-// Const wrappers
-inline const subString string::at(int pos, int len) const
-{
-    return ((string *)this)->at(pos, len);
-}
-
-inline const subString string::operator() (int pos, int len) const
-{
-    return ((string *)this)->operator()(pos, len);
-}
-
-inline const subString string::at(const string& x, int startpos) const
-{
-    return ((string *)this)->at(x, startpos);
-}
-
-inline const subString string::at(const subString&  x, int startpos)
const
-{
-    return ((string *)this)->at(x, startpos);
-}
-
-inline const subString string::at(const char* t, int startpos) const
-{
-    return ((string *)this)->at(t, startpos);
-}
-
-inline const subString string::at(char* t, int startpos) const
-{
-    return ((string *)this)->at(t, startpos);
-}
-
-inline const subString string::at(char c, int startpos) const
-{
-    return ((string *)this)->at(c, startpos);
-}
-
-inline const subString string::at(const regex& r, int startpos) const
-{
-    return ((string *)this)->at(r, startpos);
-}
-
-
-inline const subString string::before(int pos) const
-{
-    return ((string *)this)->before(pos);
-}
-
-inline const subString string::before(const string& x, int startpos)
const
-{
-    return ((string *)this)->before(x, startpos);
-}
-
-inline const subString string::before(const subString& x, int startpos) 
-    const
-{
-    return ((string *)this)->before(x, startpos);
-}
-
-inline const subString string::before(const char* t, int startpos)
const
-{
-    return ((string *)this)->before(t, startpos);
-}
-
-inline const subString string::before(char* t, int startpos) const
-{
-    return ((string *)this)->before(t, startpos);
-}
-
-inline const subString string::before(char c, int startpos) const
-{
-    return ((string *)this)->before(c, startpos);
-}
-
-inline const subString string::before(const regex& r, int startpos)
const
-{
-    return ((string *)this)->before(r, startpos);
-}
-
-
-inline const subString string::through(int pos) const
-{
-    return ((string *)this)->through(pos);
-}
-
-inline const subString string::through(const string& x, int startpos)
const
-{
-    return ((string *)this)->through(x, startpos);
-}
-
-inline const subString string::through(const subString& x, int
startpos) 
-    const
-{
-    return ((string *)this)->through(x, startpos);
-}
-
-inline const subString string::through(const char* t, int startpos)
const
-{
-    return ((string *)this)->through(t, startpos);
-}
-
-inline const subString string::through(char* t, int startpos) const
-{
-    return ((string *)this)->through(t, startpos);
-}
-
-inline const subString string::through(char c, int startpos) const
-{
-    return ((string *)this)->through(c, startpos);
-}
-
-inline const subString string::through(const regex& r, int startpos)
const
-{
-    return ((string *)this)->through(r, startpos);
-}
-
-
-inline const subString string::from(int pos) const
-{
-    return ((string *)this)->from(pos);
-}
-
-inline const subString string::from(const string& x, int startpos)
const
-{
-    return ((string *)this)->from(x, startpos);
-}
-
-inline const subString string::from(const subString& x, int startpos)
const
-{
-    return ((string *)this)->from(x, startpos);
-}
-
-inline const subString string::from(const char* t, int startpos) const
-{
-    return ((string *)this)->from(t, startpos);
-}
-
-inline const subString string::from(char* t, int startpos) const
-{
-    return ((string *)this)->from(t, startpos);
-}
-
-inline const subString string::from(char c, int startpos) const
-{
-    return ((string *)this)->from(c, startpos);
-}
-
-inline const subString string::from(const regex& r, int startpos) const
-{
-    return ((string *)this)->from(r, startpos);
-}
-
-
-inline const subString string::after(int pos) const
-{
-    return ((string *)this)->after(pos);
-}
-
-inline const subString string::after(const string& x, int startpos)
const
-{
-    return ((string *)this)->after(x, startpos);
-}
-
-inline const subString string::after(const subString& x, int startpos) 
-    const
-{
-    return ((string *)this)->after(x, startpos);
-}
-
-inline const subString string::after(const char* t, int startpos) const
-{
-    return ((string *)this)->after(t, startpos);
-}
-
-inline const subString string::after(char* t, int startpos) const
-{
-    return ((string *)this)->after(t, startpos);
-}
-
-inline const subString string::after(char c, int startpos) const
-{
-    return ((string *)this)->after(c, startpos);
-}
-
-inline const subString string::after(const regex& r, int startpos)
const
-{
-    return ((string *)this)->after(r, startpos);
-}
-
-
-
-
 // I/O
 
 inline ostream& operator<<(ostream& s, const string& x)
@@ -2204,12 +2131,12 @@
        return subString(*this, first, len);
 }
 
-inline const subString string::_substr(int first, int len) const
+inline constSubString string::_substr(int first, int len) const
 {
     if (first < 0 || len <= 0 || (unsigned)(first + len) > length())
-       return subString(_nilstring, 0, 0);
+       return constSubString(_nilstring, 0, 0);
     else 
-       return subString(*this, first, len);
+       return constSubString(*this, first, len);
 }
 
 #endif // _ICE_strclass_h
Index: ddd/tabs.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/tabs.C,v
retrieving revision 1.9
diff -u -r1.9 tabs.C
--- ddd/tabs.C  2001/01/09 18:15:22     1.9
+++ ddd/tabs.C  2001/10/12 08:55:38
@@ -47,7 +47,7 @@
        if (s[i] == '\t')
        {
            int offset = pos - i;
-           s(i, 1) = replicate(string(' '), offset);
+           s.at(i, 1) = replicate(string(' '), offset);
            return;
        }
     }
Index: ddd/tips.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/tips.C,v
retrieving revision 1.12
diff -u -r1.12 tips.C
--- ddd/tips.C  2001/07/30 21:10:59     1.12
+++ ddd/tips.C  2001/10/12 08:55:40
@@ -82,7 +82,7 @@
     return MString(values.tip, true);
 }
 
-static string app_value(string resource, const string& value)
+static string app_value(const string& resource, const string& value)
 {
     String app_name;
     String app_class;
Index: ddd/value-read.C
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/value-read.C,v
retrieving revision 1.100
diff -u -r1.100 value-read.C
--- ddd/value-read.C    2001/07/30 19:45:33     1.100
+++ ddd/value-read.C    2001/10/12 08:55:41
@@ -207,7 +207,7 @@
                while (j >= 0 && !isspace(value[j]))
                    j--;
                j++;
-               string first_member = value(j, end_of_member_name - j);
+               string first_member = value.at(j, end_of_member_name - j);
                strip_space(first_member);
                if (first_member.contains(rxint, 0) || 
                    first_member.contains(rxaddress, 0))
@@ -297,16 +297,16 @@
     return Simple;
 }
 
-DispValueType determine_type(const string& value)
+DispValueType determine_type(string& value)
 {
 #if LOG_DETERMINE_TYPE
     clog << quote(value);
 #endif
 
     const char *v = value.chars();
-    ((string &)value).consuming(true);
-    DispValueType type = _determine_type((string &)value);
-    ((string &)value) = v;
+    value.consuming(true);
+    DispValueType type = _determine_type(value);
+    value = v;
 
 #if LOG_DETERMINE_TYPE
     clog << " has type " << type << "\n";
Index: ddd/value-read.h
===================================================================
RCS file: /cvsroot/ddd/ddd/ddd/value-read.h,v
retrieving revision 1.25
diff -u -r1.25 value-read.h
--- ddd/value-read.h    2000/02/11 20:41:10     1.25
+++ ddd/value-read.h    2001/10/12 08:55:42
@@ -44,7 +44,7 @@
 #include <iostream.h>
 
 // Determine type of next element in VALUE
-DispValueType determine_type (const string& value);
+DispValueType determine_type (string& value);
 
 // Read single token from VALUE
 string read_token (string& value);

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]