annotate libinterp/corefcn/oct-hist.cc @ 27956:2310164737b3 stable

fix many spelling errors (bug #57613)
author John W. Eaton <jwe@octave.org>
date Fri, 17 Jan 2020 13:15:27 -0600
parents 8c9924a425db
children c20b7290c778
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
3 Copyright (C) 1993-2019 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6653
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
19 <https://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
2939
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
21 */
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
22
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
23 /*
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
24
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 The functions listed below were adapted from similar functions from
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 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
27 Software Foundation, Inc.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
28
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
29 do_history edit_history_readline
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
30 do_edit_history edit_history_add_hist
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 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
33
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
34 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
35 # include "config.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
38 #include <cstdlib>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
39 #include <cstring>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
40
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
41 #include <fstream>
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
42 #include <string>
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
43
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
44 #include "cmd-hist.h"
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
45 #include "file-ops.h"
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
46 #include "lo-mappers.h"
16431
5982d469f79b use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents: 16243
diff changeset
47 #include "octave-link.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2897
diff changeset
48 #include "oct-env.h"
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
49 #include "oct-time.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
50 #include "str-vec.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
51 #include "unistd-wrappers.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
52
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
53 #include "defun.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
54 #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
55 #include "errwarn.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
56 #include "input.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1690
diff changeset
57 #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
58 #include "ovl.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
59 #include "pager.h"
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
60 #include "parse.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
61 #include "sighandlers.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
62 #include "sysdep.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22051
diff changeset
63 #include "interpreter.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
64 #include "unwind-prot.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
65 #include "utils.h"
2205
bd389b53befa [project @ 1996-05-15 06:15:45 by jwe]
jwe
parents: 2095
diff changeset
66 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
67
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
68 namespace octave
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
69 {
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
70 // 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
71 // 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
72 // caller should free the storage.
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 static char *
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
75 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
76 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
77 char c;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
78 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
79 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
80 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
81 line[0] = '\0';
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
82
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
83 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
84 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
85 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
86 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
87 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
88 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
89 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
90 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
91 }
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
92
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
93 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
94 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
95 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
96 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
97 return line;
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 else
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++] = c;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
101 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
102
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
103 if (! lindex)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
104 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
105 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
106 return nullptr;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
107 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
108
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
109 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
110 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
111 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
112 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
113 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
114 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
115 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
116
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
117 // 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
118
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
119 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
120 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
121 return line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
122 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
123
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
124 static void
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
125 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
126 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
127 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
128 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
129 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
130
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
131 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
132
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
133 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
134 tmp.resize (len - 1);
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
135
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
136 if (! tmp.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
137 if (octave::command_history::add (tmp))
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
138 octave_link::append_history (tmp);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
139 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
140 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
141
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
142 static bool
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
143 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
144 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
145 bool ok = true;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
146
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
147 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
148 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
149 std::string tmp = arg.string_value ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
150
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
151 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
152 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
153 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
154 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
155 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
156 ok = false;
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 return ok;
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
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
161 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
162 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
163 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
164 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
165 string_vector hlist = octave::command_history::list ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
166
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
167 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
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 // 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
170 // 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
171 // 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
172 // but the actual commands performed will.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
173
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
174 if (! insert_curr)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
175 octave::command_history::remove (hist_count);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
176
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
177 hist_count--; // skip last entry in history list
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
178
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
179 // 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
180 // 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
181
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
182 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
183 int hist_end = hist_count;
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
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 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
186
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
187 // Process options.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
188
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
189 int nargin = args.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
190
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
191 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
192 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
193 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
194 || ! 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
195 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
196
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
197 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
198 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
199 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
200 hist_beg--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
201 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
202 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
203 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
204 hist_end--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
205 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
206 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
207 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
208 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
209 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
210
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
211 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
212 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
213 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
214 hist_beg--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
215
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
216 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
217 }
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
218
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
219 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
220 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
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_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
223 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
224 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
225 reverse = true;
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
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
228 std::string name = octave::sys::tempnam ("", "oct-");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
229
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
230 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
231
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
232 if (! file)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
233 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
234 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
235
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
236 if (reverse)
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 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
239 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
240 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
241 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
242 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
243 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
244 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
245 }
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 file.close ();
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 return name;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
250 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
251
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
252 static void
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
253 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
254 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
255 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
256 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
257
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
258 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
259 : 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
260 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
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 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
264 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
265 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
266 default_size (),
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
267 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
268
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
269 octave_link::set_history (command_history::list ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
270 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
271
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
272 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
273 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
274 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
275
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
276 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
277
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
278 if (! timestamp.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
279 if (command_history::add (timestamp))
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
280 octave_link::append_history (timestamp);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
281 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
282
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
283 octave_value
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
284 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
285 int nargout)
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 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
288 "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
289 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
290
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
291 octave_value
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
292 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
293 int nargout)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
294 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
295 return set_internal_variable (m_timestamp_format_string, args, nargout,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
296 "timestamp_format_string", false);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
297 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
298
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
299 // 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
300 //
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
301 // 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
302 // 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
303 // 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
304
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
305 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
306 int nargout)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
307 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
308 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
309
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
310 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
311
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
312 string_vector hlist;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
313
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
314 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
315
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
316 int nargin = args.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
317
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
318 // 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
319 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
320
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
321 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
322 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
323 octave_value arg = args(i);
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
324
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
325 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
326
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
327 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
328 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
329 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
330 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
331 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
332 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
333 limit = -limit;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
334 continue;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
335 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
336 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
337 err_wrong_type_arg ("history", arg);
10066
2cd940306a06 make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents: 9377
diff changeset
338
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
339 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
340 || option == "-n")
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 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
343 {
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 fname
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
345 = 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
346 option.c_str ());
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
347
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
348 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
349 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
350 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
351 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
352
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
353 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
354 // 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
355 command_history::append ();
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
356
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
357 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
358 // 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
359 command_history::write ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
360
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
361 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
362 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
363 // 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
364 command_history::read ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
365 octave_link::set_history (command_history::list ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
366 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
367
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
368 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
369 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
370 // 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
371 command_history::read_range ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
372 octave_link::set_history (command_history::list ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
373 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
374
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
375 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
376 panic_impossible ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
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 return hlist;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
379 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
380 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
381 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
382 command_history::clear ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
383 octave_link::clear_history ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
384 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
385 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
386 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
387 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
388 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
389 i++;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
390 break;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
391 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
392 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
393 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
394 // 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
395 // 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
396 int tmp;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
397
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
398 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
399 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
400 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
401 limit = tmp;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
402 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
403 limit = -tmp;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
404 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
405
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
406 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
407 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
408 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
409 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
410 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
411 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
412 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
413 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
414 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
415
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
416 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
417
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
418 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
419
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
420 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
421 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
422 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
423 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
424 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
425
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
426 return hlist;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
427 }
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 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
430 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
431 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
432
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
433 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
434 return;
16016
9194bb707d63 Plug memory leak in edit_history.
Rik <rik@octave.org>
parents: 15990
diff changeset
435
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
436 // 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
437
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
438 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
439 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
440 cmd.append (R"( ")" + name + '"');
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
441
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
442 // 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
443 // 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
444
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
445 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
446 = ignore_interrupts ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
447
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
448 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
449
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
450 set_interrupt_handler (old_interrupt_handler);
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
451
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 27546
diff changeset
452 // 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
453 // 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
454 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
455 error ("edit_history: text editor command failed");
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
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 // 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
458 // 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
459
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
460 std::fstream file (name.c_str (), std::ios::in);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
461
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
462 char *line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
463 //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
464 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
465 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
466 // 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
467
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
468 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
469 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
470 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
471 continue;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
472 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
473
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
474 edit_history_add_hist (line);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
475
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
476 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
477 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
478
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
479 file.close ();
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 unwind_protect frame;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
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 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
484 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
485
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
486 m_input_from_tmp_file = true;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
487
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
488 // 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
489 // 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
490 // 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
491
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
492 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
493 }
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
494
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
495 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
496 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
497 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
498
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
499 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
500 return;
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
501
25994
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;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
503
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 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
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 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
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 file;
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 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
521
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
522 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
523 file = env_file;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
524
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
525 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
526 file = sys::file_ops::concat (sys::env::get_home_directory (),
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
527 ".octave_hist");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
528
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
529 return file;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
530 }
16431
5982d469f79b use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents: 16243
diff changeset
531
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
532 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
533 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
534 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
535
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
536 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
537
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
538 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
539 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
540 int val;
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
541
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
542 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
543 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
544 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
545
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
546 return size;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
547 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
548
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
549 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
550 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
551 return
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
552 "# 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
553 + 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
554 + '@'
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
555 + 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
556 + '>';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
557 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
558 }
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
559
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
560 DEFMETHOD (edit_history, interp, args, ,
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
561 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
562 @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
563 @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
564 @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
565 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
566
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
567 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
568 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
569 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
570 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
571 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
572 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
573 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
574
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
575 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
576 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
577 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
578 @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
579 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
580 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
581
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
582 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
583 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
584 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
585 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
586 @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
587 @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
588
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
589 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
590 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
591 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
592 @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
593 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
594 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
595 // 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
596
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
597 if (args.length () > 2)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
598 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
599
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
600 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
601
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
602 history_sys.do_edit_history (args);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
603
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
604 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
605 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
606
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
607 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
608 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
609 @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
610 @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
611 @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
612 @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
613 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
614 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
615
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
616 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
617
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
618 @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
619 @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
620 @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
621 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
622
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
623 @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
624 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
625
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
626 @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
627 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
628 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
629
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
630 @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
631 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
632 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
633 (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
634
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
635 @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
636 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
637 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
638 @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
639
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
640 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
641 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
642 @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
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 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
645 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
646 @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
647 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
648 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
649 // 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
650
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
651 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
652
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
653 // 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
654
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
655 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
656
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
657 return nargout > 0 ? ovl (Cell (hlist)) : ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
658 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
659
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
660 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
661 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
662 @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
663 @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
664 @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
665 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
666
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
667 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
668
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
669 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
670
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
671 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
672 @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
673 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
674
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
675 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
676 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
677 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
678 OR
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
679 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
680 @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
681 @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
682
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
683 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
684 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
685 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
686
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
687 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
688 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
689 @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
690
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
691 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
692 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
693
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
694 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
695 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
696 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
697
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
698 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
699 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
700 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
701 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
702 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
703 @result{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
704 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
705 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
706 @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
707 @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
708
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
709 @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
710 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
711 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
712 // 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
713
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
714 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
715
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
716 if (args.length () > 2)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
717 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
718
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
719 history_sys.do_run_history (args);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
720
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
721 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
722 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
723
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
724 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
725 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
726 @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
727 @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
728 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
729 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
730
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
731 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
732 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
733
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
734 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
735 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
736 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
737 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
738 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
739 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
740 @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
741 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
742 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
743 @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
744 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
745 @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
746 @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
747 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
748 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
749
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
750 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
751
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
752 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
753
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
754 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
755
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
756 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
757 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
758
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
759 return retval;
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
760 }
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
761
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
762 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
763 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
764 @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
765 @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
766 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
767 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
768
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
769 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
770 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
771 @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
772 @end deftypefn */)
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
773 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
774 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
775
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
776 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
777
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
778 int tmp = old_history_size;
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
779
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
780 retval = set_internal_variable (tmp, args, nargout,
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
781 "history_size", -1,
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
782 std::numeric_limits<int>::max ());
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
783
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
784 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
785 octave::command_history::set_size (tmp);
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
786
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
787 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
788 }
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
789
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
790 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
791 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
792 @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
793 @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
794 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
795 store command history.
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
796
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
797 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
798 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
799
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
800 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
801 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
802
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
803 Programming Notes:
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
804
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
805 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
806 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
807 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
808
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
809 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
810 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
811 @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
812 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
813
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
814 @example
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
815 @group
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
816 history_file ("~/new/.octave_hist");
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
817 if (exist (history_file ()))
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
818 history ("-r", history_file());
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
819 endif
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
820 @end group
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
821 @end example
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
822
8c9924a425db doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents: 26485
diff changeset
823 @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
824 @end deftypefn */)
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
825 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
826 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
827
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
828 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
829
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
830 std::string tmp = old_history_file;
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
831
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
832 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
833
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
834 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
835 octave::command_history::set_file (tmp);
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
836
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
837 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
838 }
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
839
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
840 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
841 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
842 @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
843 @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
844 @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
845 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
846 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
847 exits.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
848
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
849 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
850
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
851 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
852 "# 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
853 @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
854
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
855 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
856 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
857 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
858 @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
859 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
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 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
862
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
863 return history_sys.timestamp_format_string (args, nargout);
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
864 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
865
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
866 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
867 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
868 @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
869 @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
870 @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
871 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
872 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
873
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
874 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
875 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
876 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
877 @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
878 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
879 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
880 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
881
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
882 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
883
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
884 bool tmp = old_history_save;
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
885
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
886 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
887
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
888 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
889 octave::command_history::ignore_entries (! tmp);
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
890
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
891 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
892 }