GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
cmd-hist.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_cmd_hist_h)
27#define octave_cmd_hist_h 1
28
29#include "octave-config.h"
30
31#include <string>
32
33#include "str-vec.h"
34
36
38{
39protected:
40
42 : m_initialized (false), m_ignoring_additions (false),
43 m_history_control (0), m_lines_in_file (0),
44 m_lines_this_session (0), m_file (), m_size (-1)
45 { }
46
47public:
48
49 OCTAVE_DISABLE_COPY_MOVE (command_history)
50
51 virtual ~command_history () = default;
52
53 static void initialize (bool, const std::string&, int, const std::string&);
54
55 static bool is_initialized ();
56
57 static void set_file (const std::string&);
58
59 static std::string file ();
60
61 static void process_histcontrol (const std::string&);
62
63 static std::string histcontrol ();
64
65 static void set_size (int);
66
67 static int size ();
68
69 static void ignore_entries (bool = true);
70
71 static bool ignoring_entries ();
72
73 static bool add (const std::string&);
74
75 static void remove (int);
76
77 static void clear ();
78
79 static int where ();
80
81 static int length ();
82
83 static int max_input_history ();
84
85 static int base ();
86
87 static int current_number ();
88
89 static void stifle (int);
90
91 static int unstifle ();
92
93 static int is_stifled ();
94
95 static void set_mark (int n);
96
97 // Gag. This declaration has to match the Function typedef in
98 // readline.h.
99
100 static int goto_mark ();
101
102 static void read (bool = true);
103
104 static void read (const std::string&, bool = true);
105
106 static void read_range (int = -1, int = -1, bool = true);
107
108 static void read_range (const std::string&, int = -1, int = -1,
109 bool = true);
110
111 static void write (const std::string& = "");
112
113 static void append (const std::string& = "");
114
115 static void truncate_file (const std::string& = "", int = -1);
116
117 static string_vector list (int = -1, bool = false);
118
119 static std::string get_entry (int);
120
121 static void replace_entry (int, const std::string&);
122
123 static void clean_up_and_save (const std::string& = "", int = -1);
124
125private:
126
127 static bool instance_ok ();
128
129 static void make_command_history ();
130
131 // The real thing.
132 static command_history *s_instance;
133
134 static void cleanup_instance ()
135 {
136 delete s_instance;
137 s_instance = nullptr;
138 }
139
140protected:
141
142 // To use something other than the GNU history library, derive a new
143 // class from command_history, overload these functions as
144 // necessary, and make instance point to the new class.
145
146 virtual void do_set_file (const std::string&);
147
148 virtual std::string do_file ();
149
150 virtual void do_process_histcontrol (const std::string&);
151
152 virtual std::string do_histcontrol () const { return ""; }
153
154 virtual void do_initialize (bool, const std::string&, int,
155 const std::string&);
156
157 virtual bool do_is_initialized () const;
158
159 virtual void do_set_size (int);
160
161 virtual int do_size () const;
162
163 virtual void do_ignore_entries (bool);
164
165 virtual bool do_ignoring_entries () const;
166
167 virtual bool do_add (const std::string&);
168
169 virtual void do_remove (int);
170
171 virtual void do_clear ();
172
173 virtual int do_where () const;
174
175 virtual int do_length () const;
176
177 virtual int do_max_input_history () const;
178
179 virtual int do_base () const;
180
181 virtual int do_current_number () const;
182
183 virtual void do_stifle (int);
184
185 virtual int do_unstifle ();
186
187 virtual int do_is_stifled () const;
188
189 virtual void do_set_mark (int);
190
191 virtual int do_goto_mark ();
192
193 virtual void do_read (const std::string&, bool);
194
195 virtual void do_read_range (const std::string&, int, int, bool);
196
197 virtual void do_write (const std::string&) const;
198
199 virtual void do_append (const std::string&);
200
201 virtual void do_truncate_file (const std::string&, int) const;
202
203 virtual string_vector do_list (int, bool) const;
204
205 virtual std::string do_get_entry (int) const;
206
207 virtual void do_replace_entry (int, const std::string&);
208
209 virtual void do_clean_up_and_save (const std::string&, int);
210
211 void error (int, const std::string& msg = "") const;
212
213 void error (const std::string&) const;
214
215 // TRUE means we have initialized the history filename and number of
216 // lines to save.
218
219 // TRUE means we are ignoring new additions.
221
222 // Bitmask for history control options. See oct-rl-hist.h.
224
225 // The number of history lines we read from the history file.
227
228 // The number of history lines we've saved so far.
230
231 // The default history file.
232 std::string m_file;
233
234 // The number of lines of history to save.
236};
237
238OCTAVE_END_NAMESPACE(octave)
239
240#endif
bool m_ignoring_additions
Definition cmd-hist.h:220
int m_lines_this_session
Definition cmd-hist.h:229
virtual std::string do_histcontrol() const
Definition cmd-hist.h:152
std::string m_file
Definition cmd-hist.h:232
int m_history_control
Definition cmd-hist.h:223
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003
#define OCTAVE_API
Definition main.in.cc:55