annotate libinterp/corefcn/oct-hist.cc @ 28088:8565d950a3ca stable

allow history_timestamp_format_string to be empty (bug #57843) * oct-hist.cc (history_system::timestamp_format_string): Allow value to be empty. Add tests.
author Mike Miller <mtmiller@octave.org>
date Mon, 17 Feb 2020 23:37:12 -0800
parents c20b7290c778
children 159b6a1eb408
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
3 // Copyright (C) 1993-2020 The Octave Project Developers
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
2939
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
25
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
26 /*
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
27
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
28 The functions listed below were adapted from similar functions from
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
29 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
30 Software Foundation, Inc.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
31
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
32 do_history edit_history_readline
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
33 do_edit_history edit_history_add_hist
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
34
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
35 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
37 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
38 # include "config.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
39 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
40
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
41 #include <cstdlib>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
42 #include <cstring>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
43
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
44 #include <fstream>
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
45 #include <string>
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
46
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
47 #include "cmd-hist.h"
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
48 #include "file-ops.h"
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
49 #include "lo-mappers.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2897
diff changeset
50 #include "oct-env.h"
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
51 #include "oct-time.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
52 #include "str-vec.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
53 #include "unistd-wrappers.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
54
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
55 #include "defun.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
56 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20983
diff changeset
57 #include "errwarn.h"
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
58 #include "event-manager.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
59 #include "input.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1690
diff changeset
60 #include "oct-hist.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20853
diff changeset
61 #include "ovl.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
62 #include "pager.h"
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
63 #include "parse.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
64 #include "sighandlers.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
65 #include "sysdep.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22051
diff changeset
66 #include "interpreter.h"
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
67 #include "interpreter-private.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
68 #include "unwind-prot.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
69 #include "utils.h"
2205
bd389b53befa [project @ 1996-05-15 06:15:45 by jwe]
jwe
parents: 2095
diff changeset
70 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
71
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
72 namespace octave
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
73 {
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
74 // Read the edited history lines from STREAM and return them
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
75 // one at a time. This can read unlimited length lines. The
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
76 // caller should free the storage.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
77
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
78 static char *
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
79 edit_history_readline (std::fstream& stream)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
80 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
81 char c;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
82 int line_len = 128;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
83 int lindex = 0;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
84 char *line = new char [line_len];
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
85 line[0] = '\0';
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
86
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
87 while (stream.get (c))
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
88 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
89 if (lindex + 2 >= line_len)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
90 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
91 char *tmp_line = new char [line_len += 128];
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
92 strcpy (tmp_line, line);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
93 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
94 line = tmp_line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
95 }
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
96
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
97 if (c == '\n')
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
98 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
99 line[lindex++] = '\n';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
100 line[lindex++] = '\0';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
101 return line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
102 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
103 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
104 line[lindex++] = c;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
105 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
106
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
107 if (! lindex)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
108 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
109 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
110 return nullptr;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
111 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
112
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
113 if (lindex + 2 >= line_len)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
114 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
115 char *tmp_line = new char [lindex+3];
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
116 strcpy (tmp_line, line);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
117 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
118 line = tmp_line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
119 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
120
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
121 // Finish with newline if none in file.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
122
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
123 line[lindex++] = '\n';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
124 line[lindex++] = '\0';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
125 return line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
126 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
127
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
128 static void
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
129 edit_history_add_hist (const std::string& line)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
130 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
131 if (! line.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
132 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
133 std::string tmp = line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
134
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
135 int len = tmp.length ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
136
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
137 if (len > 0 && tmp[len-1] == '\n')
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
138 tmp.resize (len - 1);
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
139
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
140 if (! tmp.empty ())
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
141 {
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
142 if (command_history::add (tmp))
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
143 {
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
144 event_manager& evmgr
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
145 = __get_event_manager__ ("edit_history_add_hist");
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
146
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
147 evmgr.append_history (tmp);
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
148 }
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
149 }
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
150 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
151 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
152
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
153 static bool
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
154 get_int_arg (const octave_value& arg, int& val)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
155 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
156 bool ok = true;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
157
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
158 if (arg.is_string ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
159 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
160 std::string tmp = arg.string_value ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
161
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
162 ok = sscanf (tmp.c_str (), "%d", &val) == 1;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
163 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
164 else if (arg.isnumeric ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
165 val = arg.int_value ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
166 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
167 ok = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
168
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
169 return ok;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
170 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
171
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
172 static std::string
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
173 mk_tmp_hist_file (const octave_value_list& args,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
174 bool insert_curr, const char *warn_for)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
175 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26485
diff changeset
176 string_vector hlist = command_history::list ();
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
177
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
178 int hist_count = hlist.numel () - 1; // switch to zero-based indexing
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
179
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
180 // The current command line is already part of the history list by
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
181 // the time we get to this point. Delete the cmd from the list when
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
182 // executing 'edit_history' so that it doesn't show up in the history
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
183 // but the actual commands performed will.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
184
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
185 if (! insert_curr)
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26485
diff changeset
186 command_history::remove (hist_count);
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
187
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
188 hist_count--; // skip last entry in history list
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
189
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
190 // If no numbers have been specified, the default is to edit the
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
191 // last command in the history list.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
192
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
193 int hist_beg = hist_count;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
194 int hist_end = hist_count;
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
195
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
196 bool reverse = false;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
197
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
198 // Process options.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
199
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
200 int nargin = args.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
201
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
202 if (nargin == 2)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
203 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
204 if (! get_int_arg (args(0), hist_beg)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
205 || ! get_int_arg (args(1), hist_end))
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
206 error ("%s: arguments must be integers", warn_for);
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
207
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
208 if (hist_beg < 0)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
209 hist_beg += (hist_count + 1);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
210 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
211 hist_beg--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
212 if (hist_end < 0)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
213 hist_end += (hist_count + 1);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
214 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
215 hist_end--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
216 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
217 else if (nargin == 1)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
218 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
219 if (! get_int_arg (args(0), hist_beg))
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
220 error ("%s: argument must be an integer", warn_for);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
221
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
222 if (hist_beg < 0)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
223 hist_beg += (hist_count + 1);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
224 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
225 hist_beg--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
226
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
227 hist_end = hist_beg;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
228 }
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
229
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
230 if (hist_beg > hist_count || hist_end > hist_count)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
231 error ("%s: history specification out of range", warn_for);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
232
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
233 if (hist_end < hist_beg)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
234 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
235 std::swap (hist_end, hist_beg);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
236 reverse = true;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
237 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
238
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26485
diff changeset
239 std::string name = sys::tempnam ("", "oct-");
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
240
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
241 std::fstream file (name.c_str (), std::ios::out);
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
242
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
243 if (! file)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
244 error ("%s: couldn't open temporary file '%s'", warn_for,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
245 name.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
246
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
247 if (reverse)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
248 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
249 for (int i = hist_end; i >= hist_beg; i--)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
250 file << hlist[i] << "\n";
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
251 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
252 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
253 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
254 for (int i = hist_beg; i <= hist_end; i++)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
255 file << hlist[i] << "\n";
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
256 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
257
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
258 file.close ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
259
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
260 return name;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
261 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
262
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
263 static void
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
264 unlink_cleanup (const char *file)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
265 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
266 octave_unlink_wrapper (file);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
267 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
268
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
269 history_system::history_system (interpreter& interp)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
270 : m_interpreter (interp), m_input_from_tmp_file (false),
26485
597fd034d212 restore default history file timestamp (bug #55329)
Mike Miller <mtmiller@octave.org>
parents: 26376
diff changeset
271 m_timestamp_format_string (default_timestamp_format ())
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
272 { }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
273
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
274 void history_system::initialize (bool read_history_file)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
275 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
276 command_history::initialize (read_history_file, default_file (),
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
277 default_size (),
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
278 sys::env::getenv ("OCTAVE_HISTCONTROL"));
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
279
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
280 event_manager& evmgr = m_interpreter.get_event_manager ();
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
281
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
282 evmgr.set_history (command_history::list ());
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
283 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
284
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
285 void history_system::write_timestamp (void)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
286 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
287 sys::localtime now;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
288
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
289 std::string timestamp = now.strftime (m_timestamp_format_string);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
290
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
291 if (! timestamp.empty ())
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
292 {
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
293 if (command_history::add (timestamp))
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
294 {
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
295 event_manager& evmgr = m_interpreter.get_event_manager ();
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
296
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
297 evmgr.append_history (timestamp);
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
298 }
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
299 }
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
300 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
301
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
302 octave_value
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
303 history_system::input_from_tmp_file (const octave_value_list& args,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
304 int nargout)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
305 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
306 return set_internal_variable (m_input_from_tmp_file, args, nargout,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
307 "input_from_tmp_file");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
308 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
309
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
310 octave_value
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
311 history_system::timestamp_format_string (const octave_value_list& args,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
312 int nargout)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
313 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
314 return set_internal_variable (m_timestamp_format_string, args, nargout,
28088
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
315 "timestamp_format_string");
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
316 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
317
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
318 // Display, save, or load history. Stolen and modified from bash.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
319 //
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
320 // Arg of -w FILENAME means write file, arg of -r FILENAME
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
321 // means read file, arg of -q means don't number lines. Arg of N
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
322 // means only display that many items.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
323
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
324 string_vector history_system::do_history (const octave_value_list& args,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
325 int nargout)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
326 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
327 bool numbered_output = nargout == 0;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
328
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
329 unwind_protect frame;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
330
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
331 string_vector hlist;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
332
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
333 frame.add_fcn (command_history::set_file, command_history::file ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
334
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
335 int nargin = args.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
336
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
337 // Number of history lines to show (-1 = all)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
338 int limit = -1;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
339
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
340 for (octave_idx_type i = 0; i < nargin; i++)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
341 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
342 octave_value arg = args(i);
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
343
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
344 std::string option;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
345
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
346 if (arg.is_string ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
347 option = arg.string_value ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
348 else if (arg.isnumeric ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
349 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
350 limit = arg.int_value ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
351 if (limit < 0)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
352 limit = -limit;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
353 continue;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
354 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
355 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
356 err_wrong_type_arg ("history", arg);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
357
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
358 event_manager& evmgr = m_interpreter.get_event_manager ();
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
359
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
360 if (option == "-r" || option == "-w" || option == "-a"
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
361 || option == "-n")
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
362 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
363 if (i < nargin - 1)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
364 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
365 std::string fname
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
366 = args(++i).xstring_value ("history: filename must be a string for %s option",
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
367 option.c_str ());
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
368
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
369 command_history::set_file (fname);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
370 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
371 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
372 command_history::set_file (default_file ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
373
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
374 if (option == "-a")
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
375 // Append 'new' lines to file.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
376 command_history::append ();
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
377
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
378 else if (option == "-w")
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
379 // Write entire history.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
380 command_history::write ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
381
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
382 else if (option == "-r")
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
383 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
384 // Read entire file.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
385 command_history::read ();
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
386 evmgr.set_history (command_history::list ());
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
387 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
388
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
389 else if (option == "-n")
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
390 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
391 // Read 'new' history from file.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
392 command_history::read_range ();
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
393 evmgr.set_history (command_history::list ());
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
394 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
395
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
396 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
397 panic_impossible ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
398
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
399 return hlist;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
400 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
401 else if (option == "-c")
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
402 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
403 command_history::clear ();
27263
99aa1bcb8848 rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 27261
diff changeset
404 evmgr.clear_history ();
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
405 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
406 else if (option == "-q")
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
407 numbered_output = false;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
408 else if (option == "--")
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
409 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
410 i++;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
411 break;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
412 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
413 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
414 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
415 // The last argument found in the command list that looks like
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
416 // an integer will be used
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
417 int tmp;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
418
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
419 if (sscanf (option.c_str (), "%d", &tmp) == 1)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
420 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
421 if (tmp > 0)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
422 limit = tmp;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
423 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
424 limit = -tmp;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
425 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
426
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
427 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
428 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
429 if (option.length () > 0 && option[0] == '-')
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
430 error ("history: unrecognized option '%s'", option.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
431 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
432 error ("history: bad non-numeric arg '%s'", option.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
433 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
434 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
435 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
436
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
437 hlist = command_history::list (limit, numbered_output);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
438
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
439 int len = hlist.numel ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
440
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
441 if (nargout == 0)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
442 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
443 for (octave_idx_type i = 0; i < len; i++)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
444 octave_stdout << hlist[i] << "\n";
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
445 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
446
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
447 return hlist;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
448 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
449
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
450 void history_system::do_edit_history (const octave_value_list& args)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
451 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
452 std::string name = mk_tmp_hist_file (args, false, "edit_history");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
453
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
454 if (name.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
455 return;
16016
9194bb707d63 Plug memory leak in edit_history.
Rik <rik@octave.org>
parents: 15990
diff changeset
456
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
457 // Call up our favorite editor on the file of commands.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
458
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
459 environment& env = m_interpreter.get_environment ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
460 std::string cmd = env.editor ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
461 cmd.append (R"( ")" + name + '"');
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
462
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
463 // Ignore interrupts while we are off editing commands. Should we
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
464 // maybe avoid using system()?
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
465
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
466 volatile interrupt_handler old_interrupt_handler
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
467 = ignore_interrupts ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
468
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
469 int status = system (cmd.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
470
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
471 set_interrupt_handler (old_interrupt_handler);
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
472
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 27546
diff changeset
473 // Check if text edition was successful. Abort the operation
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
474 // in case of failure.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
475 if (status != EXIT_SUCCESS)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
476 error ("edit_history: text editor command failed");
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
477
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
478 // Write the commands to the history file since source_file
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
479 // disables command line history while it executes.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
480
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
481 std::fstream file (name.c_str (), std::ios::in);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
482
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
483 char *line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
484 //int first = 1;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
485 while ((line = edit_history_readline (file)) != nullptr)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
486 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
487 // Skip blank lines.
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
488
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
489 if (line[0] == '\n')
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
490 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
491 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
492 continue;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
493 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
494
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
495 edit_history_add_hist (line);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
496
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
497 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
498 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
499
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
500 file.close ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
501
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
502 unwind_protect frame;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
503
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
504 frame.add_fcn (unlink_cleanup, name.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
505 frame.protect_var (m_input_from_tmp_file);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
506
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
507 m_input_from_tmp_file = true;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
508
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
509 // FIXME: instead of sourcing a file, we should just iterate through
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
510 // the list of commands, parsing and executing them one at a time as
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
511 // if they were entered interactively.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
512
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
513 source_file (name);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
514 }
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
515
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
516 void history_system::do_run_history (const octave_value_list& args)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
517 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
518 std::string name = mk_tmp_hist_file (args, false, "run_history");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
519
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
520 if (name.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
521 return;
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
522
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
523 unwind_protect frame;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
524
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
525 frame.add_fcn (unlink_cleanup, name.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
526 frame.protect_var (m_input_from_tmp_file);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
527
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
528 m_input_from_tmp_file = true;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
529
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
530 // FIXME: instead of sourcing a file, we should just iterate through
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
531 // the list of commands, parsing and executing them one at a time as
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
532 // if they were entered interactively.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
533
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
534 source_file (name);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
535 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
536
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
537 std::string history_system::default_file (void)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
538 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
539 std::string file;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
540
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
541 std::string env_file = sys::env::getenv ("OCTAVE_HISTFILE");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
542
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
543 if (! env_file.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
544 file = env_file;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
545
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
546 if (file.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
547 file = sys::file_ops::concat (sys::env::get_home_directory (),
27932
b018f553fd85 maint: Use Octave coding conventions in libinterp/
Rik <rik@octave.org>
parents: 27923
diff changeset
548 ".octave_hist");
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
549
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
550 return file;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
551 }
16431
5982d469f79b use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents: 16243
diff changeset
552
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
553 int history_system::default_size (void)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
554 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
555 int size = 1000;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
556
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
557 std::string env_size = sys::env::getenv ("OCTAVE_HISTSIZE");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
558
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
559 if (! env_size.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
560 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
561 int val;
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
562
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
563 if (sscanf (env_size.c_str (), "%d", &val) == 1)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
564 size = (val > 0 ? val : 0);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
565 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
566
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
567 return size;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
568 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
569
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
570 std::string history_system::default_timestamp_format (void)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
571 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
572 return
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
573 "# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <"
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
574 + sys::env::get_user_name ()
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
575 + '@'
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
576 + sys::env::get_host_name ()
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
577 + '>';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
578 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
579 }
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
580
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
581 DEFMETHOD (edit_history, interp, args, ,
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
582 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
583 @deftypefn {} {} edit_history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
584 @deftypefnx {} {} edit_history @var{cmd_number}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
585 @deftypefnx {} {} edit_history @var{first} @var{last}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
586 Edit the history list using the editor named by the variable @env{EDITOR}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
587
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
588 The commands to be edited are first copied to a temporary file. When you
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
589 exit the editor, Octave executes the commands that remain in the file. It
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
590 is often more convenient to use @code{edit_history} to define functions
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
591 rather than attempting to enter them directly on the command line.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
592 The block of commands is executed as soon as you exit the editor.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
593 To avoid executing any commands, simply delete all the lines from the buffer
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
594 before leaving the editor.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
595
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
596 When invoked with no arguments, edit the previously executed command;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
597 With one argument, edit the specified command @var{cmd_number};
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
598 With two arguments, edit the list of commands between @var{first} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
599 @var{last}. Command number specifiers may also be negative where -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
600 refers to the most recently executed command.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
601 The following are equivalent and edit the most recently executed command.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
602
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
603 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
604 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
605 edit_history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
606 edit_history -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
607 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
608 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
609
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
610 When using ranges, specifying a larger number for the first command than the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
611 last command reverses the list of commands before they are placed in the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
612 buffer to be edited.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
613 @seealso{run_history, history}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
614 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
615 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
616 // FIXME: should this be limited to the top-level context?
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
617
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
618 if (args.length () > 2)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
619 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
620
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
621 octave::history_system& history_sys = interp.get_history_system ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
622
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
623 history_sys.do_edit_history (args);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
624
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
625 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
626 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
627
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
628 DEFMETHOD (history, interp, args, nargout,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
629 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
630 @deftypefn {} {} history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
631 @deftypefnx {} {} history @var{opt1} @dots{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
632 @deftypefnx {} {@var{h} =} history ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
633 @deftypefnx {} {@var{h} =} history (@var{opt1}, @dots{})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
634 If invoked with no arguments, @code{history} displays a list of commands
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
635 that you have executed.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
636
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
637 Valid options are:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
638
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
639 @table @code
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
640 @item @var{n}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
641 @itemx -@var{n}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
642 Display only the most recent @var{n} lines of history.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
643
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
644 @item -c
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
645 Clear the history list.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
646
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
647 @item -q
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
648 Don't number the displayed lines of history. This is useful for cutting
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
649 and pasting commands using the X Window System.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
650
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
651 @item -r @var{file}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
652 Read the file @var{file}, appending its contents to the current
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
653 history list. If the name is omitted, use the default history file
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
654 (normally @file{~/.octave_hist}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
655
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
656 @item -w @var{file}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
657 Write the current history to the file @var{file}. If the name is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
658 omitted, use the default history file (normally @file{~/.octave_hist}).
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
659 @end table
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
660
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
661 For example, to display the five most recent commands that you have
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
662 typed without displaying line numbers, use the command
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
663 @kbd{history -q 5}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
664
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
665 If invoked with a single output argument, the history will be saved to that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
666 argument as a cell string and will not be output to screen.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
667 @seealso{edit_history, run_history}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
668 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
669 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
670 // FIXME: should this be limited to the top-level context?
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
671
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
672 octave::history_system& history_sys = interp.get_history_system ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
673
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
674 // Call do_history even if nargout is zero to display history list.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
675
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
676 string_vector hlist = history_sys.do_history (args, nargout);
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
677
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
678 return nargout > 0 ? ovl (Cell (hlist)) : ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
679 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
680
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
681 DEFMETHOD (run_history, interp, args, ,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
682 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
683 @deftypefn {} {} run_history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
684 @deftypefnx {} {} run_history @var{cmd_number}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
685 @deftypefnx {} {} run_history @var{first} @var{last}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
686 Run commands from the history list.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
687
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
688 When invoked with no arguments, run the previously executed command;
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
689
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
690 With one argument, run the specified command @var{cmd_number};
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
691
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
692 With two arguments, run the list of commands between @var{first} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
693 @var{last}. Command number specifiers may also be negative where -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
694 refers to the most recently executed command. For example, the command
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
695
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
696 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
697 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
698 run_history
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
699 OR
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
700 run_history -1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
701 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
702 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
703
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
704 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
705 executes the most recent command again.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
706 The command
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
707
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
708 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
709 run_history 13 169
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
710 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
711
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
712 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
713 executes commands 13 through 169.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
714
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
715 Specifying a larger number for the first command than the last command
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
716 reverses the list of commands before executing them.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
717 For example:
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
718
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
719 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
720 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
721 disp (1)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
722 disp (2)
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
723 run_history -1 -2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
724 @result{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
725 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
726 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
727 @end group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
728 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
729
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
730 @seealso{edit_history, history}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
731 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
732 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
733 // FIXME: should this be limited to the top-level context?
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
734
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
735 octave::history_system& history_sys = interp.get_history_system ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
736
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
737 if (args.length () > 2)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
738 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
739
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
740 history_sys.do_run_history (args);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
741
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
742 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
743 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
744
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
745 DEFUN (history_control, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
746 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
747 @deftypefn {} {@var{val} =} history_control ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
748 @deftypefnx {} {@var{old_val} =} history_control (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
749 Query or set the internal variable that specifies how commands are saved
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
750 to the history list.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
751
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
752 The default value is an empty character string, but may be overridden by the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
753 environment variable @w{@env{OCTAVE_HISTCONTROL}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
754
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
755 The value of @code{history_control} is a colon-separated list of values
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
756 controlling how commands are saved on the history list. If the list
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
757 of values includes @code{ignorespace}, lines which begin with a space
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
758 character are not saved in the history list. A value of @code{ignoredups}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
759 causes lines matching the previous history entry to not be saved.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
760 A value of @code{ignoreboth} is shorthand for @code{ignorespace} and
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
761 @code{ignoredups}. A value of @code{erasedups} causes all previous lines
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
762 matching the current line to be removed from the history list before that
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
763 line is saved. Any value not in the above list is ignored. If
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
764 @code{history_control} is the empty string, all commands are saved on
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
765 the history list, subject to the value of @code{history_save}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
766 @seealso{history_file, history_size, history_timestamp_format_string, history_save}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
767 @end deftypefn */)
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
768 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
769 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
770
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
771 std::string old_history_control = octave::command_history::histcontrol ();
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
772
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
773 std::string tmp = old_history_control;
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
774
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
775 retval = set_internal_variable (tmp, args, nargout, "history_control");
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
776
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
777 if (tmp != old_history_control)
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
778 octave::command_history::process_histcontrol (tmp);
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
779
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
780 return retval;
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
781 }
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
782
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
783 DEFUN (history_size, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
784 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
785 @deftypefn {} {@var{val} =} history_size ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
786 @deftypefnx {} {@var{old_val} =} history_size (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
787 Query or set the internal variable that specifies how many entries
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
788 to store in the history file.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
789
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
790 The default value is @code{1000}, but may be overridden by the environment
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
791 variable @w{@env{OCTAVE_HISTSIZE}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
792 @seealso{history_file, history_timestamp_format_string, history_save}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
793 @end deftypefn */)
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
794 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
795 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
796
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
797 int old_history_size = octave::command_history::size ();
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
798
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
799 int tmp = old_history_size;
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
800
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
801 retval = set_internal_variable (tmp, args, nargout,
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
802 "history_size", -1,
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
803 std::numeric_limits<int>::max ());
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
804
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
805 if (tmp != old_history_size)
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
806 octave::command_history::set_size (tmp);
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
807
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
808 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
809 }
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
810
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
811 DEFUN (history_file, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
812 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
813 @deftypefn {} {@var{val} =} history_file ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
814 @deftypefnx {} {@var{old_val} =} history_file (@var{new_val})
27546
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
815 Query or set the internal variable that specifies the name of the file used to
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
816 store command history.
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
817
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
818 All future commands issued during the current Octave session will be written to
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
819 this new file (if the current setting of @code{history_save} allows for this).
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
820
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
821 The default value is @file{~/.octave_hist}, but may be overridden by the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
822 environment variable @w{@env{OCTAVE_HISTFILE}}.
27546
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
823
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
824 Programming Notes:
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
825
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
826 If you want to permanently change the location of Octave's history file you
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
827 need to issue the @code{history_file} command in every new Octave session.
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
828 This can be achieved by using Octave's @file{.octaverc} startup file.
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
829
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
830 If you also want to read the saved history commands of past Octave sessions
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
831 from this different history file, then you need to use the additional command
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
832 @code{history -r} after setting the new value of the history file. Example
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
833 code in Octave's startup file to do this might look like this:
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
834
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
835 @example
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
836 @group
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
837 history_file ("~/new/.octave_hist");
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
838 if (exist (history_file ()))
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
839 history ("-r", history_file());
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
840 endif
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
841 @end group
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
842 @end example
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
843
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
844 @seealso{history, history_control, history_save, history_size, history_timestamp_format_string}
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
845 @end deftypefn */)
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
846 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
847 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
848
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
849 std::string old_history_file = octave::command_history::file ();
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
850
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
851 std::string tmp = old_history_file;
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
852
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
853 retval = set_internal_variable (tmp, args, nargout, "history_file");
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
854
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
855 if (tmp != old_history_file)
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
856 octave::command_history::set_file (tmp);
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
857
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
858 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
859 }
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
860
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
861 DEFMETHOD (history_timestamp_format_string, interp, args, nargout,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
862 doc: /* -*- texinfo -*-
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
863 @deftypefn {} {@var{val} =} history_timestamp_format_string ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
864 @deftypefnx {} {@var{old_val} =} history_timestamp_format_string (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
865 @deftypefnx {} {} history_timestamp_format_string (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
866 Query or set the internal variable that specifies the format string
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
867 for the comment line that is written to the history file when Octave
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
868 exits.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
869
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
870 The format string is passed to @code{strftime}. The default value is
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
871
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
872 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
873 "# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>"
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
874 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
875
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
876 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
877 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
878 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
879 @seealso{strftime, history_file, history_size, history_save}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
880 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
881 {
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
882 octave::history_system& history_sys = interp.get_history_system ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
883
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
884 return history_sys.timestamp_format_string (args, nargout);
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
885 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
886
28088
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
887 /*
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
888 %!test
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
889 %! history_timestamp_format_string ("# Example history marker", "local");
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
890 %! assert (history_timestamp_format_string (), "# Example history marker")
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
891 %!test <*57843>
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
892 %! history_timestamp_format_string ("", "local");
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
893 %! assert (history_timestamp_format_string (), "")
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
894 */
8565d950a3ca allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents: 27957
diff changeset
895
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
896 DEFUN (history_save, args, nargout,
21966
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
897 doc: /* -*- texinfo -*-
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
898 @deftypefn {} {@var{val} =} history_save ()
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
899 @deftypefnx {} {@var{old_val} =} history_save (@var{new_val})
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
900 @deftypefnx {} {} history_save (@var{new_val}, "local")
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
901 Query or set the internal variable that controls whether commands entered
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
902 on the command line are saved in the history file.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
903
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
904 When called from inside a function with the @qcode{"local"} option, the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
905 variable is changed locally for the function and any subroutines it calls.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
906 The original variable value is restored when exiting the function.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
907 @seealso{history_control, history_file, history_size, history_timestamp_format_string}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
908 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
909 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
910 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
911
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
912 bool old_history_save = ! octave::command_history::ignoring_entries ();
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
913
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
914 bool tmp = old_history_save;
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
915
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
916 retval = set_internal_variable (tmp, args, nargout, "history_save");
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
917
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
918 if (tmp != old_history_save)
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
919 octave::command_history::ignore_entries (! tmp);
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
920
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
921 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
922 }