1797
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1797
|
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 2, or (at your option) any |
|
10 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, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_cmd_hist_h) |
|
24 #define octave_cmd_hist_h 1 |
|
25 |
|
26 #include <string> |
|
27 |
|
28 #include "str-vec.h" |
|
29 |
|
30 class |
|
31 command_history |
|
32 { |
2926
|
33 protected: |
|
34 |
|
35 command_history (void) |
|
36 : ignoring_additions (false), lines_in_file (0), |
|
37 lines_this_session (0), xfile (), xsize (-1) { } |
|
38 |
1797
|
39 public: |
|
40 |
2926
|
41 virtual ~command_history (void) { } |
|
42 |
3504
|
43 static void set_file (const std::string&); |
1797
|
44 |
3504
|
45 static std::string file (void); |
1797
|
46 |
2926
|
47 static void set_size (int); |
1797
|
48 |
2926
|
49 static int size (void); |
|
50 |
|
51 static void ignore_entries (bool = true); |
1797
|
52 |
2926
|
53 static bool ignoring_entries (void); |
1797
|
54 |
3504
|
55 static void add (const std::string&); |
1797
|
56 |
2926
|
57 static void remove (int); |
|
58 |
|
59 static int where (void); |
1797
|
60 |
2926
|
61 static int length (void); |
1797
|
62 |
2926
|
63 static int max_input_history (void); |
1797
|
64 |
2926
|
65 static int base (void); |
1797
|
66 |
2926
|
67 static int current_number (void); |
1797
|
68 |
2926
|
69 static void stifle (int); |
1797
|
70 |
2926
|
71 static int unstifle (void); |
1797
|
72 |
2926
|
73 static int is_stifled (void); |
1797
|
74 |
2926
|
75 static void set_mark (int n); |
1797
|
76 |
2926
|
77 // Gag. This declaration has to match the Function typedef in |
|
78 // readline.h. |
1797
|
79 |
3519
|
80 static void goto_mark (void); |
2926
|
81 |
|
82 static void read (bool = true); |
2658
|
83 |
3504
|
84 static void read (const std::string&, bool = true); |
1797
|
85 |
2926
|
86 static void read_range (int = -1, int = -1, bool = true); |
2658
|
87 |
3504
|
88 static void read_range (const std::string&, int = -1, int = -1, |
2926
|
89 bool = true); |
1797
|
90 |
3504
|
91 static void write (const std::string& = std::string ()); |
1797
|
92 |
3504
|
93 static void append (const std::string& = std::string ()); |
1797
|
94 |
3504
|
95 static void truncate_file (const std::string& = std::string (), int = -1); |
1797
|
96 |
2926
|
97 static string_vector list (int = -1, bool = false); |
1797
|
98 |
3504
|
99 static std::string get_entry (int); |
1797
|
100 |
3504
|
101 static void replace_entry (int, const std::string&); |
1797
|
102 |
3504
|
103 static void clean_up_and_save (const std::string& = std::string (), int = -1); |
1797
|
104 |
|
105 private: |
|
106 |
2926
|
107 // No copying! |
|
108 |
|
109 command_history (const command_history&); |
|
110 |
|
111 command_history& operator = (const command_history&); |
|
112 |
|
113 static bool instance_ok (void); |
|
114 |
|
115 static void make_command_history (void); |
|
116 |
|
117 // The real thing. |
|
118 static command_history *instance; |
|
119 |
|
120 protected: |
|
121 |
|
122 // To use something other than the GNU history library, derive a new |
|
123 // class from command_history, overload these functions as |
|
124 // necessary, and make instance point to the new class. |
|
125 |
3504
|
126 virtual void do_set_file (const std::string&); |
2926
|
127 |
3504
|
128 virtual std::string do_file (void); |
2926
|
129 |
|
130 virtual void do_set_size (int); |
|
131 |
|
132 virtual int do_size (void); |
|
133 |
|
134 virtual void do_ignore_entries (bool); |
|
135 |
|
136 virtual bool do_ignoring_entries (void); |
|
137 |
3504
|
138 virtual void do_add (const std::string&); |
2926
|
139 |
|
140 virtual void do_remove (int); |
|
141 |
|
142 virtual int do_where (void); |
|
143 |
|
144 virtual int do_length (void); |
|
145 |
|
146 virtual int do_max_input_history (void); |
|
147 |
|
148 virtual int do_base (void); |
|
149 |
|
150 virtual int do_current_number (void); |
|
151 |
|
152 virtual void do_stifle (int); |
|
153 |
|
154 virtual int do_unstifle (void); |
|
155 |
|
156 virtual int do_is_stifled (void); |
|
157 |
|
158 virtual void do_set_mark (int); |
|
159 |
|
160 virtual void do_goto_mark (void); |
|
161 |
3504
|
162 virtual void do_read (const std::string&, bool); |
2926
|
163 |
3504
|
164 virtual void do_read_range (const std::string&, int, int, bool); |
2926
|
165 |
3504
|
166 virtual void do_write (const std::string&); |
2926
|
167 |
3504
|
168 virtual void do_append (const std::string&); |
2926
|
169 |
3504
|
170 virtual void do_truncate_file (const std::string&, int); |
2926
|
171 |
|
172 virtual string_vector do_list (int, bool); |
|
173 |
3504
|
174 virtual std::string do_get_entry (int); |
2926
|
175 |
3504
|
176 virtual void do_replace_entry (int, const std::string&); |
2926
|
177 |
3504
|
178 virtual void do_clean_up_and_save (const std::string&, int); |
2926
|
179 |
|
180 void error (int); |
|
181 |
3504
|
182 void error (const std::string&); |
1797
|
183 |
|
184 // TRUE means we are ignoring new additions. |
|
185 bool ignoring_additions; |
|
186 |
|
187 // The number of hisory lines we read from the history file. |
|
188 int lines_in_file; |
|
189 |
|
190 // The number of history lines we've saved so far. |
|
191 int lines_this_session; |
|
192 |
|
193 // The default history file. |
3504
|
194 std::string xfile; |
1797
|
195 |
|
196 // The number of lines of history to save. |
|
197 int xsize; |
|
198 }; |
|
199 |
|
200 #endif |
|
201 |
|
202 /* |
|
203 ;;; Local Variables: *** |
|
204 ;;; mode: C++ *** |
|
205 ;;; End: *** |
|
206 */ |