annotate libinterp/corefcn/oct-hist.cc @ 27261:dccdc3b001a2

eliminate static functions from octave_link class * octave-link.h, octave-link. (class octave_link): Convert all static data and functions to normal data members and member functions. Change all uses. * interpreter-private.h, interpreter-private.cc (__get_octave_link__): New function. * interpreter.h, interpreter.cc (interpreter::m_octave_link): New data member. (interpreter::get_octave_link): New function.
author John W. Eaton <jwe@octave.org>
date Wed, 17 Jul 2019 14:09:20 -0400
parents 84ff9953faa1
children 99aa1bcb8848
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
1 /*
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25994
diff changeset
3 Copyright (C) 1993-2019 John W. Eaton
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
4
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
6
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
7 Octave is free software: you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
8 under the terms of the GNU General Public License as published by
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
10 (at your option) any later version.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22407
diff changeset
15 GNU General Public License for more details.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
16
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6653
diff changeset
18 along with Octave; see the file COPYING. If not, see
24534
194eb4bd202b maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents: 23829
diff changeset
19 <https://www.gnu.org/licenses/>.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
20
2939
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
21 */
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
22
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
23 /*
f2feebf0eb7d [project @ 1997-05-06 16:36:34 by jwe]
jwe
parents: 2936
diff changeset
24
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
25 The functions listed below were adapted from similar functions from
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
26 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
27 Software Foundation, Inc.
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
28
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
29 do_history edit_history_readline
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
30 do_edit_history edit_history_add_hist
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
31
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
32 */
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
33
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
34 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21200
diff changeset
35 # include "config.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
36 #endif
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
37
1343
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
38 #include <cstdlib>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
39 #include <cstring>
94bedeb289e5 [project @ 1995-09-04 00:29:21 by jwe]
jwe
parents: 1321
diff changeset
40
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
41 #include <fstream>
1750
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
42 #include <string>
fd0d12493223 [project @ 1996-01-13 09:31:07 by jwe]
jwe
parents: 1742
diff changeset
43
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
44 #include "cmd-hist.h"
1802
8173b1fa052d [project @ 1996-01-29 06:10:18 by jwe]
jwe
parents: 1799
diff changeset
45 #include "file-ops.h"
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
46 #include "lo-mappers.h"
16431
5982d469f79b use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents: 16243
diff changeset
47 #include "octave-link.h"
2926
66ef74ee5d9f [project @ 1997-05-05 03:20:52 by jwe]
jwe
parents: 2897
diff changeset
48 #include "oct-env.h"
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
49 #include "oct-time.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
50 #include "str-vec.h"
21910
4d723ba06b4a provide wrappers for some unistd.h functions
John W. Eaton <jwe@octave.org>
parents: 21748
diff changeset
51 #include "unistd-wrappers.h"
1755
3a9462b655f1 [project @ 1996-01-22 04:47:22 by jwe]
jwe
parents: 1750
diff changeset
52
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
53 #include "defun.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
54 #include "error.h"
21100
e39e05d90788 Switch gripe_XXX to either err_XXX or warn_XXX naming scheme.
Rik <rik@octave.org>
parents: 20983
diff changeset
55 #include "errwarn.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
56 #include "input.h"
1742
a02f140ed897 [project @ 1996-01-12 11:09:39 by jwe]
jwe
parents: 1690
diff changeset
57 #include "oct-hist.h"
20940
48b2ad5ee801 maint: Rename oct-obj.[cc|h] to ovl.[cc|h] for clarity.
Rik <rik@octave.org>
parents: 20853
diff changeset
58 #include "ovl.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
59 #include "pager.h"
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
60 #include "parse.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
61 #include "sighandlers.h"
1690
a38bd8df9d33 [project @ 1996-01-05 21:36:24 by jwe]
jwe
parents: 1670
diff changeset
62 #include "sysdep.h"
22094
9203833cab7d move new interpreter class to separate file
John W. Eaton <jwe@octave.org>
parents: 22051
diff changeset
63 #include "interpreter.h"
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
64 #include "interpreter-private.h"
1352
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
65 #include "unwind-prot.h"
19c10b8657d5 [project @ 1995-09-05 08:11:57 by jwe]
jwe
parents: 1350
diff changeset
66 #include "utils.h"
2205
bd389b53befa [project @ 1996-05-15 06:15:45 by jwe]
jwe
parents: 2095
diff changeset
67 #include "variables.h"
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
68
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
69 namespace octave
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
70 {
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
71 // 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
72 // 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
73 // caller should free the storage.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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 static char *
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
76 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
77 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
78 char c;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
79 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
80 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
81 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
82 line[0] = '\0';
11586
12df7854fa7c strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 11572
diff changeset
83
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
84 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
85 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
86 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
87 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
88 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
89 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
90 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
91 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
92 }
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
93
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
94 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
95 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
96 line[lindex++] = '\n';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
97 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
98 return line;
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 else
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++] = c;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
102 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
103
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
104 if (! lindex)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
105 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
106 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
107 return nullptr;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
108 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
109
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
110 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
111 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
112 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
113 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
114 delete [] line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
115 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
116 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
117
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
118 // 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
119
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
120 line[lindex++] = '\n';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
121 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
122 return line;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
123 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
124
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
125 static void
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
126 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
127 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
128 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
129 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
130 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
131
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
132 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
133
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
134 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
135 tmp.resize (len - 1);
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
136
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
137 if (! tmp.empty ())
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
138 {
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
139 if (command_history::add (tmp))
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
140 {
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
141 octave_link& olnk
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
142 = __get_octave_link__ ("edit_history_add_hist");
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
143
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
144 olnk.append_history (tmp);
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
145 }
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
146 }
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
147 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
148 }
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
149
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
150 static bool
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
151 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
152 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
153 bool ok = true;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
154
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
155 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
156 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
157 std::string tmp = arg.string_value ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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 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
160 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
161 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
162 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
163 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
164 ok = false;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
165
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
166 return ok;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
167 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
168
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
169 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
170 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
171 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
172 {
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26485
diff changeset
173 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
174
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
175 int hist_count = hlist.numel () - 1; // switch to zero-based indexing
1799
1881b2a7d1e2 [project @ 1996-01-29 05:10:48 by jwe]
jwe
parents: 1766
diff changeset
176
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
177 // 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
178 // 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
179 // 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
180 // but the actual commands performed will.
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
181
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
182 if (! insert_curr)
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26485
diff changeset
183 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
184
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
185 hist_count--; // skip last entry in history list
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
186
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
187 // 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
188 // 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
189
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
190 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
191 int hist_end = hist_count;
15823
bc7a130bbdfb allow history commands to take numeric arguments
John W. Eaton <jwe@octave.org>
parents: 15817
diff changeset
192
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
193 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
194
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
195 // Process options.
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
196
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
197 int nargin = args.length ();
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
198
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
199 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
200 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
201 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
202 || ! 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
203 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
204
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
205 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
206 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
207 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
208 hist_beg--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
209 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
210 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
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_end--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
213 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
214 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
215 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
216 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
217 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
218
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
219 if (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
220 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
221 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
222 hist_beg--;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
223
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
224 hist_end = hist_beg;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
225 }
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
226
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
227 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
228 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
229
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
230 if (hist_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
231 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
232 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
233 reverse = true;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
234 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
235
27102
84ff9953faa1 where possible, eliminate octave:: namespace qualifier inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26485
diff changeset
236 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
237
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
238 std::fstream file (name.c_str (), std::ios::out);
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
239
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
240 if (! file)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
241 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
242 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
243
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
244 if (reverse)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
245 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
246 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
247 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
248 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
249 else
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
250 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
251 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
252 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
253 }
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 file.close ();
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
256
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
257 return name;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
258 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
259
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
260 static void
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
261 unlink_cleanup (const char *file)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
262 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
263 octave_unlink_wrapper (file);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
264 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
265
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
266 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
267 : 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
268 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
269 { }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
270
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
271 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
272 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
273 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
274 default_size (),
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
275 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
276
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
277 octave_link& olnk = m_interpreter.get_octave_link ();
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
278
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
279 olnk.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
280 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
281
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
282 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
283 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
284 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
285
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
286 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
287
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
288 if (! timestamp.empty ())
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
289 {
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
290 if (command_history::add (timestamp))
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
291 {
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
292 octave_link& olnk = m_interpreter.get_octave_link ();
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 olnk.append_history (timestamp);
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
295 }
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
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 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
298
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
299 octave_value
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
300 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
301 int nargout)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
302 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
303 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
304 "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
305 }
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
306
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
307 octave_value
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
308 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
309 int nargout)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
310 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
311 return set_internal_variable (m_timestamp_format_string, args, nargout,
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
312 "timestamp_format_string", false);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
313 }
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 // 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
316 //
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
317 // 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
318 // 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
319 // 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
320
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
321 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
322 int nargout)
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
323 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
324 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
325
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
326 unwind_protect frame;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
327
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
328 string_vector hlist;
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
329
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
330 frame.add_fcn (command_history::set_file, command_history::file ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
331
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
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
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
355 octave_link& olnk = m_interpreter.get_octave_link ();
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
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
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
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
374
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
375 else 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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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 ();
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
383 olnk.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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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 ();
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
390 olnk.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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
395
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
396 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 ();
27261
dccdc3b001a2 eliminate static functions from octave_link class
John W. Eaton <jwe@octave.org>
parents: 27102
diff changeset
401 olnk.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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
415
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
416 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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
9194bb707d63 Plug memory leak in edit_history.
Rik <rik@octave.org>
parents: 15990
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
465
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
466 int status = system (cmd.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
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
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
469
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
470 // Check if text edition was successfull. Abort the operation
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
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
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
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
478 std::fstream file (name.c_str (), std::ios::in);
1
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
78fd87e624cb [project @ 1993-08-08 01:13:40 by jwe]
jwe
parents:
diff changeset
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
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
499 unwind_protect frame;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
500
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
501 frame.add_fcn (unlink_cleanup, name.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
502 frame.protect_var (m_input_from_tmp_file);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
503
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
504 m_input_from_tmp_file = true;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
505
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
506 // 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
507 // 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
508 // 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
509
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
510 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
511 }
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
512
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
513 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
514 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
515 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
516
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
517 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
518 return;
3018
5708b8bb4f06 [project @ 1997-06-03 21:48:05 by jwe]
jwe
parents: 3016
diff changeset
519
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
520 unwind_protect frame;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
521
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
522 frame.add_fcn (unlink_cleanup, name.c_str ());
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
523 frame.protect_var (m_input_from_tmp_file);
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
524
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
525 m_input_from_tmp_file = true;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
526
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
527 // 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
528 // 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
529 // 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
530
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
531 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
532 }
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
533
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
534 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
535 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
536 std::string file;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
537
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
538 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
539
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
540 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
541 file = env_file;
64
bd04d91a7a4a [project @ 1993-08-15 05:08:48 by jwe]
jwe
parents: 1
diff changeset
542
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
543 if (file.empty ())
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
544 file = sys::file_ops::concat (sys::env::get_home_directory (),
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
545 ".octave_hist");
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
546
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
547 return file;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
548 }
16431
5982d469f79b use signal for setting, appending to, and clearing history widget
John W. Eaton <jwe@octave.org>
parents: 16243
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 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
551 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
552 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
553
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
554 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
555
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
556 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
557 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
558 int val;
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
559
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
560 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
561 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
562 }
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
563
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
564 return size;
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
565 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
566
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
567 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
568 {
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
569 return
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
570 "# 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
571 + 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
572 + '@'
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
573 + 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
574 + '>';
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
575 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
576 }
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
577
23719
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
578 DEFMETHOD (edit_history, interp, args, ,
69a111259a2c eliminate some global variables
John W. Eaton <jwe@octave.org>
parents: 23586
diff changeset
579 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
580 @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
581 @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
582 @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
583 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
584
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
585 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
586 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
587 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
588 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
589 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
590 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
591 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
592
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
593 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
594 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
595 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
596 @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
597 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
598 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
599
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
600 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
601 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
602 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
603 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
604 @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
605 @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
606
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
607 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
608 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
609 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
610 @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
611 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
612 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
613 // 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
614
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
615 if (args.length () > 2)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
616 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
617
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
618 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
619
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
620 history_sys.do_edit_history (args);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
621
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
622 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
623 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
624
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
625 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
626 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
627 @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
628 @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
629 @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
630 @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
631 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
632 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
633
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
634 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
635
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
636 @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
637 @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
638 @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
639 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
640
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 -c
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
642 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
643
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
644 @item -q
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
645 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
646 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
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 -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
649 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
650 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
651 (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
652
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
653 @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
654 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
655 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
656 @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
657
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
658 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
659 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
660 @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
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 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
663 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
664 @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
665 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
666 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
667 // 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
668
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
669 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
670
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
671 // Call do_history even if nargout is zero to display history list.
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
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 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
674
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
675 return nargout > 0 ? ovl (Cell (hlist)) : ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
676 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
677
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
678 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
679 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
680 @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
681 @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
682 @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
683 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
684
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
685 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
686
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
687 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
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 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
690 @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
691 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
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
694 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
695 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
696 OR
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
697 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
698 @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
699 @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
700
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
701 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
702 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
703 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
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
706 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
707 @end example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
708
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
709 @noindent
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
710 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
711
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
712 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
713 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
714 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
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 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
717 @group
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
718 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
719 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
720 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
721 @result{}
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
722 2
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
723 1
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
724 @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
725 @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
726
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
727 @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
728 @end deftypefn */)
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
729 {
23723
ab8831d346c1 revamp echo command and move related variables inside tree_evaluator class
John W. Eaton <jwe@octave.org>
parents: 23719
diff changeset
730 // 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
731
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
732 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
733
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
734 if (args.length () > 2)
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
735 print_usage ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
736
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
737 history_sys.do_run_history (args);
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
738
20983
004fa31be0b7 use print_usage instead of usage
John W. Eaton <jwe@octave.org>
parents: 20962
diff changeset
739 return ovl ();
529
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
740 }
7ea224e713cd [project @ 1994-07-20 18:54:27 by jwe]
jwe
parents: 296
diff changeset
741
11486
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
742 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
743 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
744 @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
745 @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
746 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
747 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
748
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
749 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
750 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
751
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
752 The 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
753 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
754 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
755 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
756 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
757 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
758 @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
759 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
760 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
761 @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
762 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
763 @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
764 @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
765 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
766 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
767
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
768 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
769
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
770 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
771
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
772 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
773
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
774 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
775 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
776
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
777 return retval;
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
778 }
a1deab9a6e71 bash-like history control
Pascal Dupuis <Pascal.Dupuis@worldonline.be> and John W. Eaton <jwe@octave.org>
parents: 11405
diff changeset
779
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
780 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
781 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
782 @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
783 @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
784 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
785 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
786
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
787 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
788 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
789 @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
790 @end deftypefn */)
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
791 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
792 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
793
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
794 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
795
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
796 int tmp = old_history_size;
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
797
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
798 retval = set_internal_variable (tmp, args, nargout,
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
799 "history_size", -1,
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
800 std::numeric_limits<int>::max ());
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
801
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
802 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
803 octave::command_history::set_size (tmp);
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
804
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
805 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
806 }
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
807
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
808 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
809 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
810 @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
811 @deftypefnx {} {@var{old_val} =} history_file (@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
812 Query or set the internal variable that specifies the name of the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
813 file used to store command history.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
814
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
815 The default value is @file{~/.octave_hist}, but may be overridden by the
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
816 environment variable @w{@env{OCTAVE_HISTFILE}}.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
817 @seealso{history_size, history_save, 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
818 @end deftypefn */)
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
819 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
820 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
821
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
822 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
823
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
824 std::string tmp = old_history_file;
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
825
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
826 retval = set_internal_variable (tmp, args, nargout, "history_file");
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
827
12989
00235a6446da eliminate duplication of internal variables controlling command history
John W. Eaton <jwe@octave.org>
parents: 12642
diff changeset
828 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
829 octave::command_history::set_file (tmp);
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
830
5800
e8be7fe586f9 [project @ 2006-05-10 06:50:45 by jwe]
jwe
parents: 5794
diff changeset
831 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
832 }
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
833
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
834 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
835 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
836 @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
837 @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
838 @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
839 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
840 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
841 exits.
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
842
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
843 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
844
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
845 @example
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
846 "# 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
847 @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
848
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
849 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
850 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
851 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
852 @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
853 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
854 {
25994
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
855 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
856
f881d3e271d2 eliminate global and file-scope static variables in oct-hist.cc
John W. Eaton <jwe@octave.org>
parents: 25440
diff changeset
857 return history_sys.timestamp_format_string (args, nargout);
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
858 }
5305
539428e4606a [project @ 2005-04-26 02:59:08 by jwe]
jwe
parents: 4469
diff changeset
859
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
860 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
861 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
862 @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
863 @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
864 @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
865 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
866 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
867
112b20240c87 move docstrings in C++ files out of C strings and into comments
John W. Eaton <jwe@octave.org>
parents: 21910
diff changeset
868 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
869 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
870 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
871 @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
872 @end deftypefn */)
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
873 {
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
874 octave_value retval;
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
875
21748
176536b15d68 use namespace for command_editor and command_history classes
John W. Eaton <jwe@octave.org>
parents: 21743
diff changeset
876 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
877
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
878 bool tmp = old_history_save;
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
879
17345
91691d74845d oct-hist.cc: Wrap code lines > 80 characters.
Rik <rik@octave.org>
parents: 17281
diff changeset
880 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
881
16876
9e0618443c2b Rename saving_history() to history_save().
Rik <rik@octave.org>
parents: 16687
diff changeset
882 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
883 octave::command_history::ignore_entries (! tmp);
5794
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
884
1138ced03f14 [project @ 2006-05-08 20:23:04 by jwe]
jwe
parents: 5775
diff changeset
885 return retval;
3016
f512c16826d1 [project @ 1997-06-03 03:16:13 by jwe]
jwe
parents: 2985
diff changeset
886 }