Mercurial > octave
annotate libinterp/corefcn/oct-hist.cc @ 29950:6549fa7558ba
eliminate some unnecessary octave:: namespace tags
Where possible, remove octave:: namespace tags used inside a
"namespace octave" block.
Files affected: event-manager.cc, hook-fcn.cc, input.cc,
latex-text-renderer.cc, oct-hist.cc, sysdep.cc, cdef-object.cc,
cdef-object.h, oct-parse.yy, pt-eval.cc, CollocWt.cc, oct-convn.cc,
oct-norm.cc, file-ops.cc.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 13 Aug 2021 14:08:16 -0400 |
parents | 7854d5752dd2 |
children | 32c3a5805893 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 // |
29358
0a5b15007766
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
28467
diff
changeset
|
3 // Copyright (C) 1993-2021 The Octave Project Developers |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
4 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
7 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
8 // This file is part of Octave. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
9 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
13 // (at your option) any later version. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
14 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
18 // GNU General Public License for more details. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
19 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 // |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
2939 | 25 |
26 /* | |
27 | |
1 | 28 The functions listed below were adapted from similar functions from |
29 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free | |
30 Software Foundation, Inc. | |
31 | |
32 do_history edit_history_readline | |
33 do_edit_history edit_history_add_hist | |
34 | |
35 */ | |
36 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
37 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
38 # include "config.h" |
1 | 39 #endif |
40 | |
1343 | 41 #include <cstdlib> |
42 #include <cstring> | |
43 | |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
44 #include <fstream> |
1750 | 45 #include <string> |
46 | |
1799 | 47 #include "cmd-hist.h" |
1802 | 48 #include "file-ops.h" |
3016 | 49 #include "lo-mappers.h" |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28088
diff
changeset
|
50 #include "lo-sysdep.h" |
2926 | 51 #include "oct-env.h" |
5305 | 52 #include "oct-time.h" |
1755 | 53 #include "str-vec.h" |
21910
4d723ba06b4a
provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents:
21748
diff
changeset
|
54 #include "unistd-wrappers.h" |
1755 | 55 |
1352 | 56 #include "defun.h" |
1 | 57 #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
|
58 #include "errwarn.h" |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
59 #include "event-manager.h" |
1 | 60 #include "input.h" |
1742 | 61 #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
|
62 #include "ovl.h" |
1352 | 63 #include "pager.h" |
3018 | 64 #include "parse.h" |
1352 | 65 #include "sighandlers.h" |
1690 | 66 #include "sysdep.h" |
22094
9203833cab7d
move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents:
22051
diff
changeset
|
67 #include "interpreter.h" |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
68 #include "interpreter-private.h" |
1352 | 69 #include "unwind-prot.h" |
70 #include "utils.h" | |
2205 | 71 #include "variables.h" |
1 | 72 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
73 namespace octave |
1 | 74 { |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
75 // 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
|
76 // 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
|
77 // caller should free the storage. |
1 | 78 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
79 static char * |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
80 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
|
81 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
82 char c; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
83 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
|
84 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
|
85 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
|
86 line[0] = '\0'; |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11572
diff
changeset
|
87 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
88 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
|
89 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
90 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
|
91 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
92 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
|
93 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
|
94 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
95 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
|
96 } |
1799 | 97 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
98 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
|
99 { |
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++] = '\n'; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
101 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
|
102 return line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
103 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
104 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
105 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
|
106 } |
1 | 107 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
108 if (! lindex) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
109 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
110 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
111 return nullptr; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
112 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
113 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
114 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
|
115 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
116 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
|
117 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
|
118 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
119 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
|
120 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
121 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
122 // 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
|
123 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
124 line[lindex++] = '\n'; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
125 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
|
126 return line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
127 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
128 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
129 static void |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
130 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
|
131 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
132 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
|
133 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
134 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
|
135 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
136 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
|
137 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
138 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
|
139 tmp.resize (len - 1); |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
140 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
141 if (! tmp.empty ()) |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
142 { |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
143 if (command_history::add (tmp)) |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
144 { |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
145 event_manager& evmgr |
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
146 = __get_event_manager__ ("edit_history_add_hist"); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
147 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
148 evmgr.append_history (tmp); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
149 } |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
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 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
152 } |
15823
bc7a130bbdfb
allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents:
15817
diff
changeset
|
153 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
154 static bool |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
155 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
|
156 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
157 bool ok = true; |
1 | 158 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
159 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
|
160 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
161 std::string tmp = arg.string_value (); |
1 | 162 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
163 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
|
164 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
165 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
|
166 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
|
167 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
168 ok = false; |
1 | 169 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
170 return ok; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
171 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
172 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
173 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
|
174 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
|
175 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
|
176 { |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26485
diff
changeset
|
177 string_vector hlist = command_history::list (); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
178 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
179 int hist_count = hlist.numel () - 1; // switch to zero-based indexing |
1799 | 180 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
181 // 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
|
182 // 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
|
183 // 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
|
184 // but the actual commands performed will. |
1 | 185 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
186 if (! insert_curr) |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26485
diff
changeset
|
187 command_history::remove (hist_count); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
188 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
189 hist_count--; // skip last entry in history list |
1 | 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 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
|
192 // 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
|
193 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
194 int hist_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
|
195 int hist_end = hist_count; |
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 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
|
198 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
199 // Process options. |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
200 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
201 int nargin = args.length (); |
1 | 202 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
203 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
|
204 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
205 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
|
206 || ! 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
|
207 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
|
208 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
209 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
|
210 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
|
211 else |
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--; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
213 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
|
214 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
|
215 else |
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--; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
217 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
218 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
|
219 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
220 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
|
221 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
|
222 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
223 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
|
224 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
|
225 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
226 hist_beg--; |
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 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
|
229 } |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
230 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
231 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
|
232 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
|
233 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
234 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
|
235 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
236 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
|
237 reverse = true; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
238 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
239 |
27102
84ff9953faa1
where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26485
diff
changeset
|
240 std::string name = sys::tempnam ("", "oct-"); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
241 |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28088
diff
changeset
|
242 std::ofstream file = sys::ofstream (name.c_str (), std::ios::out); |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
243 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
244 if (! file) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
245 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
|
246 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
|
247 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
248 if (reverse) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
249 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
250 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
|
251 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
|
252 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
253 else |
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 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
|
256 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
|
257 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
258 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
259 file.close (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
260 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
261 return name; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
262 } |
1 | 263 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
264 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
|
265 : 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
|
266 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
|
267 { } |
1 | 268 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
269 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
|
270 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
271 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
|
272 default_size (), |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
273 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
|
274 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
275 event_manager& evmgr = m_interpreter.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
276 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
277 evmgr.set_history (command_history::list ()); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
278 } |
1 | 279 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
280 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
|
281 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
282 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
|
283 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
284 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
|
285 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
286 if (! timestamp.empty ()) |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
287 { |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
288 if (command_history::add (timestamp)) |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
289 { |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
290 event_manager& evmgr = m_interpreter.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
291 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
292 evmgr.append_history (timestamp); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
293 } |
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
294 } |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
295 } |
1 | 296 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
297 octave_value |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
298 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
|
299 int nargout) |
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 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
|
302 "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
|
303 } |
1 | 304 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
305 octave_value |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
306 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
|
307 int nargout) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
308 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
309 return set_internal_variable (m_timestamp_format_string, args, nargout, |
28088
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
310 "timestamp_format_string"); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
311 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
312 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
313 // 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
|
314 // |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
315 // 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
|
316 // 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
|
317 // 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
|
318 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
319 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
|
320 int nargout) |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
321 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
322 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
|
323 |
28857
43ad651cf5a0
eliminate unnecessary uses of octave:: namespace qualifier
John W. Eaton <jwe@octave.org>
parents:
28854
diff
changeset
|
324 unwind_action restore_history_filename |
28850
445e5ac1f58d
in unwind_action objects, capture variables in lambda expressions when possible
John W. Eaton <jwe@octave.org>
parents:
28823
diff
changeset
|
325 ([] (const std::string& old_filename) |
28823
26cfccfee9a0
Replace unwind_protect with more efficient constructs (bug #59192).
Rik <rik@octave.org>
parents:
28467
diff
changeset
|
326 { |
26cfccfee9a0
Replace unwind_protect with more efficient constructs (bug #59192).
Rik <rik@octave.org>
parents:
28467
diff
changeset
|
327 command_history::set_file (old_filename); |
26cfccfee9a0
Replace unwind_protect with more efficient constructs (bug #59192).
Rik <rik@octave.org>
parents:
28467
diff
changeset
|
328 }, command_history::file ()); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
329 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
330 string_vector hlist; |
1 | 331 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
332 int nargin = args.length (); |
1 | 333 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
334 // 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
|
335 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
|
336 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
337 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
|
338 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
339 octave_value arg = args(i); |
64 | 340 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
341 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
|
342 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
343 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
|
344 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
|
345 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
|
346 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
347 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
|
348 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
|
349 limit = -limit; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
350 continue; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
351 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
352 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
353 err_wrong_type_arg ("history", arg); |
10066
2cd940306a06
make unwind_protect frames local
Jaroslav Hajek <highegg@gmail.com>
parents:
9377
diff
changeset
|
354 |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
355 event_manager& evmgr = m_interpreter.get_event_manager (); |
27261
dccdc3b001a2
eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents:
27102
diff
changeset
|
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 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
|
358 || option == "-n") |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
359 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
360 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
|
361 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
362 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
|
363 = 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
|
364 option.c_str ()); |
64 | 365 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
366 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
|
367 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
368 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
369 command_history::set_file (default_file ()); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
370 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
371 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
|
372 // 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
|
373 command_history::append (); |
64 | 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 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
|
376 // 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
|
377 command_history::write (); |
1 | 378 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
379 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
|
380 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
381 // 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
|
382 command_history::read (); |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
383 evmgr.set_history (command_history::list ()); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
384 } |
1 | 385 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
386 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
|
387 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
388 // 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
|
389 command_history::read_range (); |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
390 evmgr.set_history (command_history::list ()); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
391 } |
1 | 392 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
393 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
394 panic_impossible (); |
1 | 395 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
396 return hlist; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
397 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
398 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
|
399 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
400 command_history::clear (); |
27263
99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
27261
diff
changeset
|
401 evmgr.clear_history (); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
402 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
403 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
|
404 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
|
405 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
|
406 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
407 i++; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
408 break; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
409 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
410 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
411 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
412 // 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
|
413 // 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
|
414 int tmp; |
1 | 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 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
|
417 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
418 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
|
419 limit = tmp; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
420 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
421 limit = -tmp; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
422 } |
1 | 423 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
424 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
425 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
426 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
|
427 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
|
428 else |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
429 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
|
430 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
431 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
432 } |
1 | 433 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
434 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
|
435 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
436 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
|
437 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
438 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
|
439 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
440 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
|
441 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
|
442 } |
1 | 443 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
444 return hlist; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
445 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
446 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
447 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
|
448 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
449 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
|
450 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
451 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
|
452 return; |
16016 | 453 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
454 // 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
|
455 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
456 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
|
457 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
|
458 cmd.append (R"( ")" + name + '"'); |
1 | 459 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
460 // 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
|
461 // 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
|
462 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
463 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
|
464 = ignore_interrupts (); |
1 | 465 |
29950
6549fa7558ba
eliminate some unnecessary octave:: namespace tags
John W. Eaton <jwe@octave.org>
parents:
29359
diff
changeset
|
466 int status = sys::system (cmd); |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
467 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
468 set_interrupt_handler (old_interrupt_handler); |
3018 | 469 |
27956
2310164737b3
fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents:
27546
diff
changeset
|
470 // 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
|
471 // 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
|
472 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
|
473 error ("edit_history: text editor command failed"); |
3018 | 474 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
475 // 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
|
476 // 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
|
477 |
28467
159b6a1eb408
Use wide character overload to open file streams on Windows.
Markus Mützel <markus.muetzel@gmx.de>
parents:
28088
diff
changeset
|
478 std::fstream file = sys::fstream (name.c_str (), std::ios::in); |
1 | 479 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
480 char *line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
481 //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
|
482 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
|
483 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
484 // 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
|
485 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
486 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
|
487 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
488 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
489 continue; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
490 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
491 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
492 edit_history_add_hist (line); |
1 | 493 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
494 delete [] line; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
495 } |
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 file.close (); |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
498 |
29253
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
499 int(*unlink_fptr)(const std::string&) = octave::sys::unlink; |
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
500 unwind_action unlink_action (unlink_fptr, name); |
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
501 unwind_protect_var<bool> upv (m_input_from_tmp_file, true); |
64 | 502 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
503 // 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
|
504 // 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
|
505 // 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
|
506 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
507 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
|
508 } |
3018 | 509 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
510 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
|
511 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
512 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
|
513 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
514 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
|
515 return; |
3018 | 516 |
29253
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
517 int(*unlink_fptr)(const std::string&) = octave::sys::unlink; |
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
518 unwind_action unlink_action (unlink_fptr, name); |
28913793f678
prefer unwind_action over unwind_protect in more places
John W. Eaton <jwe@octave.org>
parents:
29141
diff
changeset
|
519 unwind_protect_var<bool> upv (m_input_from_tmp_file, true); |
64 | 520 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
521 // 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
|
522 // 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
|
523 // 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
|
524 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
525 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
|
526 } |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
527 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
528 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
|
529 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
530 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
|
531 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
532 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
|
533 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
534 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
|
535 file = env_file; |
64 | 536 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
537 if (file.empty ()) |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
538 { |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
539 // Default to $DATA/octave/history, where $DATA is the platform- |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
540 // dependent location for (roaming) user data files. |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
541 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
542 std::string user_data_dir = sys::env::get_user_data_directory (); |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
543 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
544 std::string hist_dir = user_data_dir + sys::file_ops::dir_sep_str () |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
545 + "octave"; |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
546 |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
547 file = sys::env::make_absolute ("history", hist_dir); |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
548 } |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
549 |
25994
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 file; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
552 } |
16431
5982d469f79b
use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents:
16243
diff
changeset
|
553 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
554 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
|
555 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
556 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
|
557 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
558 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
|
559 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
560 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
|
561 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
562 int val; |
5794 | 563 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
564 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
|
565 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
|
566 } |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
567 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
568 return size; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
569 } |
5305 | 570 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
571 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
|
572 { |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
573 return |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
574 "# 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
|
575 + 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
|
576 + '@' |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
577 + 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
|
578 + '>'; |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
579 } |
5305 | 580 } |
581 | |
23719
69a111259a2c
eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
582 DEFMETHOD (edit_history, interp, args, , |
69a111259a2c
eliminate some global variables
John W. Eaton <jwe@octave.org>
parents:
23586
diff
changeset
|
583 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
|
584 @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
|
585 @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
|
586 @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
|
587 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
|
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 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 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
|
596 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 @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
|
601 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
|
602 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
|
603 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
604 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
605 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
606 edit_history |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
607 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
|
608 @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
|
609 @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
|
610 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
611 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
|
612 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
|
613 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
|
614 @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
|
615 @end deftypefn */) |
529 | 616 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
617 // 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
|
618 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
619 if (args.length () > 2) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
620 print_usage (); |
529 | 621 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
622 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
|
623 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
624 history_sys.do_edit_history (args); |
529 | 625 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
626 return ovl (); |
529 | 627 } |
628 | |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
629 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
|
630 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
|
631 @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
|
632 @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
|
633 @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
|
634 @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
|
635 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
|
636 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
|
637 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
638 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
|
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 @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
|
641 @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
|
642 @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
|
643 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
|
644 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
645 @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
|
646 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
|
647 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
648 @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
|
649 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
|
650 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
|
651 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
652 @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
|
653 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
|
654 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
|
655 (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
|
656 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
657 @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
|
658 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
|
659 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
|
660 @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
|
661 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
662 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
|
663 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
|
664 @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
|
665 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
666 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
|
667 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
|
668 @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
|
669 @end deftypefn */) |
529 | 670 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
671 // 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
|
672 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
673 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
|
674 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
675 // Call do_history even if nargout is zero to display history list. |
529 | 676 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
677 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
|
678 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
679 return nargout > 0 ? ovl (Cell (hlist)) : ovl (); |
529 | 680 } |
681 | |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
682 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
|
683 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
|
684 @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
|
685 @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
|
686 @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
|
687 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
|
688 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
689 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
|
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 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
|
692 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
693 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
|
694 @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
|
695 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
|
696 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
697 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
698 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
699 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
|
700 OR |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
701 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
|
702 @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
|
703 @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
|
704 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
705 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
706 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
|
707 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
|
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 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
710 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
|
711 @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
|
712 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
713 @noindent |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
714 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
|
715 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
716 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
|
717 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
|
718 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
|
719 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
720 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
721 @group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
722 disp (1) |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
723 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
|
724 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
|
725 @result{} |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
726 2 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
727 1 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
728 @end group |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
729 @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
|
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 @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
|
732 @end deftypefn */) |
529 | 733 { |
23723
ab8831d346c1
revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents:
23719
diff
changeset
|
734 // 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
|
735 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
736 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
|
737 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
738 if (args.length () > 2) |
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
739 print_usage (); |
529 | 740 |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
741 history_sys.do_run_history (args); |
529 | 742 |
20983
004fa31be0b7
use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents:
20962
diff
changeset
|
743 return ovl (); |
529 | 744 } |
745 | |
11486
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
746 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
|
747 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
|
748 @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
|
749 @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
|
750 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
|
751 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
|
752 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
753 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
|
754 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
|
755 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
756 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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 @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
|
763 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
|
764 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
|
765 @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
|
766 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
|
767 @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
|
768 @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
|
769 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
770 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
771 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
772 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
|
773 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
774 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
|
775 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
776 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
|
777 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
778 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
|
779 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
|
780 |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
781 return retval; |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
782 } |
a1deab9a6e71
bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents:
11405
diff
changeset
|
783 |
5794 | 784 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
|
785 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
|
786 @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
|
787 @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
|
788 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
|
789 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
|
790 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
791 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
|
792 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
|
793 @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
|
794 @end deftypefn */) |
3016 | 795 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
796 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
797 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
798 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
|
799 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
800 int tmp = old_history_size; |
5800 | 801 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
802 retval = set_internal_variable (tmp, args, nargout, |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
803 "history_size", -1, |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
804 std::numeric_limits<int>::max ()); |
5800 | 805 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
806 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
|
807 octave::command_history::set_size (tmp); |
5800 | 808 |
809 return retval; | |
3016 | 810 } |
811 | |
5794 | 812 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
|
813 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
|
814 @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
|
815 @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
|
816 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
|
817 store command history. |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
818 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
819 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
|
820 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
|
821 |
28854
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
822 The default value is @file{@w{@env{$DATA}}/octave/history}, where |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
823 @w{@env{$DATA}} is the platform-specific location for (roaming) user data files |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
824 (e.g. @w{@env{$XDG_DATA_HOME}} or, if that is not set, @file{~/.local/share} on |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
825 Unix-like operating systems or @w{@env{%APPDATA%}} on Windows). The default |
491433ba8612
Move history file location to inside XDG_CONFIG_HOME or APPDATA (bug #57463).
Markus Mützel <markus.muetzel@gmx.de>
parents:
28850
diff
changeset
|
826 value may be overridden by the 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
|
827 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
828 Programming Notes: |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
829 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
830 If you 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
|
831 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
|
832 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
|
833 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
834 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
|
835 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
|
836 @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
|
837 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
|
838 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
839 @example |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
840 @group |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
841 history_file ("~/new/.octave_hist"); |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
842 if (exist (history_file ())) |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
843 history ("-r", history_file()); |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
844 endif |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
845 @end group |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
846 @end example |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
847 |
8c9924a425db
doc: Clarify documentation of history_file (bug #57027)
Hartmut Gimpel <hg_code@gmx.de>
parents:
26485
diff
changeset
|
848 @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
|
849 @end deftypefn */) |
5305 | 850 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
851 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
852 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
853 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
|
854 |
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
855 std::string tmp = old_history_file; |
5305 | 856 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
857 retval = set_internal_variable (tmp, args, nargout, "history_file"); |
5305 | 858 |
12989
00235a6446da
eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents:
12642
diff
changeset
|
859 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
|
860 octave::command_history::set_file (tmp); |
5305 | 861 |
5800 | 862 return retval; |
3016 | 863 } |
864 | |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
865 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
|
866 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
|
867 @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
|
868 @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
|
869 @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
|
870 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
|
871 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
|
872 exits. |
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 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
|
875 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
876 @example |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
877 "# 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
|
878 @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
|
879 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
880 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
|
881 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
|
882 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
|
883 @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
|
884 @end deftypefn */) |
5794 | 885 { |
25994
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
886 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
|
887 |
f881d3e271d2
eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents:
25440
diff
changeset
|
888 return history_sys.timestamp_format_string (args, nargout); |
5794 | 889 } |
5305 | 890 |
28088
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
891 /* |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
892 %!test |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
893 %! history_timestamp_format_string ("# Example history marker", "local"); |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
894 %! assert (history_timestamp_format_string (), "# Example history marker") |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
895 %!test <*57843> |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
896 %! history_timestamp_format_string ("", "local"); |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
897 %! assert (history_timestamp_format_string (), "") |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
898 */ |
8565d950a3ca
allow history_timestamp_format_string to be empty (bug #57843)
Mike Miller <mtmiller@octave.org>
parents:
27957
diff
changeset
|
899 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
900 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
|
901 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
|
902 @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
|
903 @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
|
904 @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
|
905 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
|
906 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
|
907 |
112b20240c87
move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents:
21910
diff
changeset
|
908 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
|
909 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
|
910 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
|
911 @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
|
912 @end deftypefn */) |
5794 | 913 { |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
914 octave_value retval; |
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
915 |
21748
176536b15d68
use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents:
21743
diff
changeset
|
916 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
|
917 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
918 bool tmp = old_history_save; |
5794 | 919 |
17345
91691d74845d
oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents:
17281
diff
changeset
|
920 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
|
921 |
16876
9e0618443c2b
Rename saving_history() to history_save().
Rik <rik@octave.org>
parents:
16687
diff
changeset
|
922 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
|
923 octave::command_history::ignore_entries (! tmp); |
5794 | 924 |
925 return retval; | |
3016 | 926 } |