GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
cmd-hist.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_cmd_hist_h)
24 #define octave_cmd_hist_h 1
25 
26 #include "octave-config.h"
27 
28 #include <string>
29 
30 #include "str-vec.h"
31 
32 namespace octave
33 {
34  class
35  OCTAVE_API
37  {
38  protected:
39 
41  : initialized (false), ignoring_additions (false), history_control (0),
42  lines_in_file (0), lines_this_session (0), xfile (), xsize (-1) { }
43 
44  public:
45 
46  virtual ~command_history (void) { }
47 
48  static void initialize (bool, const std::string&, int, const std::string&);
49 
50  static bool is_initialized (void);
51 
52  static void set_file (const std::string&);
53 
54  static std::string file (void);
55 
56  static void process_histcontrol (const std::string&);
57 
58  static std::string histcontrol (void);
59 
60  static void set_size (int);
61 
62  static int size (void);
63 
64  static void ignore_entries (bool = true);
65 
66  static bool ignoring_entries (void);
67 
68  static bool add (const std::string&);
69 
70  static void remove (int);
71 
72  static void clear (void);
73 
74  static int where (void);
75 
76  static int length (void);
77 
78  static int max_input_history (void);
79 
80  static int base (void);
81 
82  static int current_number (void);
83 
84  static void stifle (int);
85 
86  static int unstifle (void);
87 
88  static int is_stifled (void);
89 
90  static void set_mark (int n);
91 
92  // Gag. This declaration has to match the Function typedef in
93  // readline.h.
94 
95  static int goto_mark (void);
96 
97  static void read (bool = true);
98 
99  static void read (const std::string&, bool = true);
100 
101  static void read_range (int = -1, int = -1, bool = true);
102 
103  static void read_range (const std::string&, int = -1, int = -1,
104  bool = true);
105 
106  static void write (const std::string& = "");
107 
108  static void append (const std::string& = "");
109 
110  static void truncate_file (const std::string& = "", int = -1);
111 
112  static string_vector list (int = -1, bool = false);
113 
114  static std::string get_entry (int);
115 
116  static void replace_entry (int, const std::string&);
117 
118  static void clean_up_and_save (const std::string& = "", int = -1);
119 
120  private:
121 
122  // No copying!
123 
125 
126  command_history& operator = (const command_history&);
127 
128  static bool instance_ok (void);
129 
130  static void make_command_history (void);
131 
132  // The real thing.
134 
135  static void cleanup_instance (void) { delete instance; instance = 0; }
136 
137  protected:
138 
139  // To use something other than the GNU history library, derive a new
140  // class from command_history, overload these functions as
141  // necessary, and make instance point to the new class.
142 
143  virtual void do_set_file (const std::string&);
144 
145  virtual std::string do_file (void);
146 
147  virtual void do_process_histcontrol (const std::string&);
148 
149  virtual std::string do_histcontrol (void) const { return ""; }
150 
151  virtual void do_initialize (bool, const std::string&, int,
152  const std::string&);
153 
154  virtual bool do_is_initialized (void) const;
155 
156  virtual void do_set_size (int);
157 
158  virtual int do_size (void) const;
159 
160  virtual void do_ignore_entries (bool);
161 
162  virtual bool do_ignoring_entries (void) const;
163 
164  virtual bool do_add (const std::string&);
165 
166  virtual void do_remove (int);
167 
168  virtual void do_clear (void);
169 
170  virtual int do_where (void) const;
171 
172  virtual int do_length (void) const;
173 
174  virtual int do_max_input_history (void) const;
175 
176  virtual int do_base (void) const;
177 
178  virtual int do_current_number (void) const;
179 
180  virtual void do_stifle (int);
181 
182  virtual int do_unstifle (void);
183 
184  virtual int do_is_stifled (void) const;
185 
186  virtual void do_set_mark (int);
187 
188  virtual int do_goto_mark (void);
189 
190  virtual void do_read (const std::string&, bool);
191 
192  virtual void do_read_range (const std::string&, int, int, bool);
193 
194  virtual void do_write (const std::string&) const;
195 
196  virtual void do_append (const std::string&);
197 
198  virtual void do_truncate_file (const std::string&, int) const;
199 
200  virtual string_vector do_list (int, bool) const;
201 
202  virtual std::string do_get_entry (int) const;
203 
204  virtual void do_replace_entry (int, const std::string&);
205 
206  virtual void do_clean_up_and_save (const std::string&, int);
207 
208  void error (int, const std::string& msg = "") const;
209 
210  void error (const std::string&) const;
211 
212  // TRUE means we have initialized the history filename and number of
213  // lines to save.
215 
216  // TRUE means we are ignoring new additions.
218 
219  // Bitmask for history control options. See oct-rl-hist.h.
221 
222  // The number of history lines we read from the history file.
224 
225  // The number of history lines we've saved so far.
227 
228  // The default history file.
230 
231  // The number of lines of history to save.
232  int xsize;
233  };
234 }
235 
236 #if defined (OCTAVE_USE_DEPRECATED_FUNCTIONS)
237 
238 OCTAVE_DEPRECATED ("use 'octave::command_history' instead")
239 typedef octave::command_history command_history;
240 
241 #endif
242 
243 #endif
static void cleanup_instance(void)
Definition: cmd-hist.h:135
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:120
The value of lines which begin with a space character are not saved in the history list A value of all commands are saved on the history list
Definition: oct-hist.cc:728
void error(const char *fmt,...)
Definition: error.cc:570
virtual ~command_history(void)
Definition: cmd-hist.h:46
static command_history * instance
Definition: cmd-hist.h:133
virtual std::string do_histcontrol(void) const
Definition: cmd-hist.h:149
is false
Definition: cellfun.cc:398
bool append
Definition: load-save.cc:1582
OCTAVE_EXPORT octave_value_list any number nd example oindent prints the prompt xample Pick a any number!nd example oindent and waits for the user to enter a value The string entered by the user is evaluated as an so it may be a literal a variable or any other valid Octave code The number of return their size
Definition: input.cc:871
static void initialize(void)
Definition: mkoctfile.cc:123
static void clear(octave::dynamic_library &oct_file)
Definition: dynamic-ld.cc:230
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:854