1
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1
|
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 |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1
|
21 |
2939
|
22 */ |
|
23 |
|
24 /* |
|
25 |
1
|
26 The functions listed below were adapted from similar functions from |
|
27 GNU Bash, the Bourne Again SHell, copyright (C) 1987, 1989, 1991 Free |
|
28 Software Foundation, Inc. |
|
29 |
|
30 do_history edit_history_readline |
|
31 do_edit_history edit_history_add_hist |
|
32 |
|
33 */ |
|
34 |
240
|
35 #ifdef HAVE_CONFIG_H |
1192
|
36 #include <config.h> |
1
|
37 #endif |
|
38 |
1343
|
39 #include <cstdlib> |
|
40 #include <cstring> |
|
41 |
1750
|
42 #include <string> |
|
43 |
3503
|
44 #include <fstream> |
1350
|
45 |
|
46 #ifdef HAVE_UNISTD_H |
2442
|
47 #ifdef HAVE_SYS_TYPES_H |
1
|
48 #include <sys/types.h> |
2442
|
49 #endif |
1
|
50 #include <unistd.h> |
|
51 #endif |
1350
|
52 |
1799
|
53 #include "cmd-hist.h" |
1802
|
54 #include "file-ops.h" |
3016
|
55 #include "lo-mappers.h" |
2926
|
56 #include "oct-env.h" |
5305
|
57 #include "oct-time.h" |
1755
|
58 #include "str-vec.h" |
|
59 |
2492
|
60 #include <defaults.h> |
1352
|
61 #include "defun.h" |
1
|
62 #include "error.h" |
3016
|
63 #include "gripes.h" |
1
|
64 #include "input.h" |
1742
|
65 #include "oct-hist.h" |
1750
|
66 #include "oct-obj.h" |
1352
|
67 #include "pager.h" |
3018
|
68 #include "parse.h" |
1352
|
69 #include "sighandlers.h" |
1690
|
70 #include "sysdep.h" |
1750
|
71 #include "toplev.h" |
1352
|
72 #include "unwind-prot.h" |
|
73 #include "utils.h" |
2205
|
74 #include "variables.h" |
1
|
75 |
3018
|
76 // TRUE means input is coming from temporary history file. |
|
77 bool input_from_tmp_history_file = false; |
168
|
78 |
5305
|
79 static std::string |
1
|
80 default_history_file (void) |
|
81 { |
3523
|
82 std::string file; |
1
|
83 |
3523
|
84 std::string env_file = octave_env::getenv ("OCTAVE_HISTFILE"); |
1755
|
85 |
2926
|
86 if (! env_file.empty ()) |
6141
|
87 file = env_file; |
1
|
88 |
1755
|
89 if (file.empty ()) |
|
90 { |
3523
|
91 std::string home_dir = octave_env::get_home_directory (); |
2926
|
92 |
|
93 if (! home_dir.empty ()) |
1969
|
94 { |
2926
|
95 file = home_dir; |
1969
|
96 file.append ("/.octave_hist"); |
|
97 } |
1755
|
98 else |
|
99 file = ".octave_hist"; |
|
100 } |
1
|
101 |
|
102 return file; |
|
103 } |
|
104 |
5794
|
105 // Where history is saved. |
|
106 static std::string Vhistory_file = default_history_file (); |
|
107 |
5305
|
108 static int |
|
109 default_history_size (void) |
|
110 { |
|
111 int size = 1024; |
|
112 |
|
113 std::string env_size = octave_env::getenv ("OCTAVE_HISTSIZE"); |
|
114 |
|
115 if (! env_size.empty ()) |
|
116 { |
|
117 int val; |
|
118 |
|
119 if (sscanf (env_size.c_str (), "%d", &val) == 1) |
|
120 size = val > 0 ? val : 0; |
|
121 } |
|
122 |
|
123 return size; |
|
124 } |
|
125 |
5794
|
126 // The number of lines to keep in the history file. |
|
127 static int Vhistory_size = default_history_size (); |
|
128 |
5305
|
129 static std::string |
|
130 default_history_timestamp_format (void) |
|
131 { |
|
132 return |
|
133 std::string ("# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <") |
|
134 + octave_env::get_user_name () |
|
135 + std::string ("@") |
|
136 + octave_env::get_host_name () |
|
137 + std::string (">"); |
|
138 } |
|
139 |
5794
|
140 // The format of the timestamp marker written to the history file when |
|
141 // Octave exits. |
|
142 static std::string Vhistory_timestamp_format_string |
|
143 = default_history_timestamp_format (); |
|
144 |
|
145 // TRUE if we are saving history. |
|
146 bool Vsaving_history = true; |
|
147 |
581
|
148 // Display, save, or load history. Stolen and modified from bash. |
|
149 // |
|
150 // Arg of -w FILENAME means write file, arg of -r FILENAME |
|
151 // means read file, arg of -q means don't number lines. Arg of N |
|
152 // means only display that many items. |
|
153 |
1755
|
154 static void |
|
155 do_history (int argc, const string_vector& argv) |
1
|
156 { |
|
157 int numbered_output = 1; |
|
158 |
1755
|
159 int i; |
|
160 for (i = 1; i < argc; i++) |
1
|
161 { |
3523
|
162 std::string option = argv[i]; |
2435
|
163 |
|
164 if (option == "-r" || option == "-w" || option == "-a" |
|
165 || option == "-n") |
1
|
166 { |
1755
|
167 if (i < argc - 1) |
5872
|
168 command_history::set_file (argv[i+1]); |
1
|
169 |
2435
|
170 if (option == "-a") |
|
171 // Append `new' lines to file. |
2926
|
172 command_history::append (); |
2435
|
173 |
|
174 else if (option == "-w") |
|
175 // Write entire history. |
2926
|
176 command_history::write (); |
777
|
177 |
2435
|
178 else if (option == "-r") |
|
179 // Read entire file. |
2926
|
180 command_history::read (); |
777
|
181 |
2435
|
182 else if (option == "-n") |
|
183 // Read `new' history from file. |
2926
|
184 command_history::read_range (); |
777
|
185 |
2435
|
186 else |
|
187 panic_impossible (); |
|
188 |
1
|
189 return; |
|
190 } |
1755
|
191 else if (argv[i] == "-q") |
1
|
192 numbered_output = 0; |
1755
|
193 else if (argv[i] == "--") |
1
|
194 { |
1755
|
195 i++; |
1
|
196 break; |
|
197 } |
|
198 else |
|
199 break; |
|
200 } |
|
201 |
1799
|
202 int limit = -1; |
1
|
203 |
1755
|
204 if (i < argc) |
1
|
205 { |
1755
|
206 if (sscanf (argv[i].c_str (), "%d", &limit) != 1) |
1
|
207 { |
1755
|
208 if (argv[i][0] == '-') |
|
209 error ("history: unrecognized option `%s'", argv[i].c_str ()); |
1
|
210 else |
1755
|
211 error ("history: bad non-numeric arg `%s'", argv[i].c_str ()); |
1799
|
212 |
1
|
213 return; |
|
214 } |
|
215 |
|
216 if (limit < 0) |
|
217 limit = -limit; |
1799
|
218 } |
1
|
219 |
2926
|
220 string_vector hlist = command_history::list (limit, numbered_output); |
1
|
221 |
1799
|
222 int len = hlist.length (); |
|
223 |
2095
|
224 for (i = 0; i < len; i++) |
|
225 octave_stdout << hlist[i] << "\n"; |
1
|
226 } |
|
227 |
581
|
228 // Read the edited history lines from STREAM and return them |
|
229 // one at a time. This can read unlimited length lines. The |
2434
|
230 // caller should free the storage. |
581
|
231 |
1
|
232 static char * |
3551
|
233 edit_history_readline (std::fstream& stream) |
1
|
234 { |
|
235 char c; |
|
236 int line_len = 128; |
|
237 int lindex = 0; |
|
238 char *line = new char [line_len]; |
|
239 line[0] = '\0'; |
|
240 |
|
241 while (stream.get (c)) |
|
242 { |
|
243 if (lindex + 2 >= line_len) |
|
244 { |
|
245 char *tmp_line = new char [line_len += 128]; |
|
246 strcpy (tmp_line, line); |
|
247 delete [] line; |
|
248 line = tmp_line; |
|
249 } |
|
250 |
|
251 if (c == '\n') |
|
252 { |
|
253 line[lindex++] = '\n'; |
|
254 line[lindex++] = '\0'; |
|
255 return line; |
|
256 } |
|
257 else |
|
258 line[lindex++] = c; |
|
259 } |
|
260 |
|
261 if (! lindex) |
|
262 { |
|
263 delete [] line; |
529
|
264 return 0; |
1
|
265 } |
|
266 |
|
267 if (lindex + 2 >= line_len) |
|
268 { |
|
269 char *tmp_line = new char [lindex+3]; |
|
270 strcpy (tmp_line, line); |
|
271 delete [] line; |
|
272 line = tmp_line; |
|
273 } |
|
274 |
1358
|
275 // Finish with newline if none in file. |
1
|
276 |
|
277 line[lindex++] = '\n'; |
|
278 line[lindex++] = '\0'; |
|
279 return line; |
|
280 } |
|
281 |
581
|
282 // Use `command' to replace the last entry in the history list, which, |
|
283 // by this time, is `run_history blah...'. The intent is that the |
1799
|
284 // new command becomes the history entry, and that `fc' should never |
581
|
285 // appear in the history list. This way you can do `run_history' to |
|
286 // your heart's content. |
|
287 |
64
|
288 static void |
3523
|
289 edit_history_repl_hist (const std::string& command) |
64
|
290 { |
1799
|
291 if (! command.empty ()) |
|
292 { |
2926
|
293 string_vector hlist = command_history::list (); |
64
|
294 |
1799
|
295 int len = hlist.length (); |
64
|
296 |
1799
|
297 if (len > 0) |
|
298 { |
|
299 int i = len - 1; |
64
|
300 |
3523
|
301 std::string histent = command_history::get_entry (i); |
64
|
302 |
1799
|
303 if (! histent.empty ()) |
|
304 { |
3523
|
305 std::string cmd = command; |
64
|
306 |
1799
|
307 int cmd_len = cmd.length (); |
64
|
308 |
1799
|
309 if (cmd[cmd_len - 1] == '\n') |
|
310 cmd.resize (cmd_len - 1); |
64
|
311 |
1799
|
312 if (! cmd.empty ()) |
2926
|
313 command_history::replace_entry (i, cmd); |
1799
|
314 } |
64
|
315 } |
|
316 } |
|
317 } |
|
318 |
1
|
319 static void |
3523
|
320 edit_history_add_hist (const std::string& line) |
1
|
321 { |
1799
|
322 if (! line.empty ()) |
1
|
323 { |
3523
|
324 std::string tmp = line; |
1
|
325 |
1799
|
326 int len = tmp.length (); |
|
327 |
|
328 if (len > 0 && tmp[len-1] == '\n') |
|
329 tmp.resize (len - 1); |
|
330 |
|
331 if (! tmp.empty ()) |
2926
|
332 command_history::add (tmp); |
1
|
333 } |
|
334 } |
|
335 |
3536
|
336 static std::string |
1755
|
337 mk_tmp_hist_file (int argc, const string_vector& argv, |
2804
|
338 int insert_curr, const char *warn_for) |
1
|
339 { |
3523
|
340 std::string retval; |
1
|
341 |
2926
|
342 string_vector hlist = command_history::list (); |
1
|
343 |
1799
|
344 int hist_count = hlist.length (); |
1
|
345 |
1358
|
346 // The current command line is already part of the history list by |
|
347 // the time we get to this point. Delete it from the list. |
1
|
348 |
|
349 hist_count -= 2; |
1799
|
350 |
64
|
351 if (! insert_curr) |
2926
|
352 command_history::remove (hist_count); |
1799
|
353 |
1
|
354 hist_count--; |
|
355 |
1358
|
356 // If no numbers have been specified, the default is to edit the |
|
357 // last command in the history list. |
1
|
358 |
|
359 int hist_end = hist_count; |
|
360 int hist_beg = hist_count; |
|
361 int reverse = 0; |
|
362 |
1358
|
363 // Process options. |
1
|
364 |
|
365 int usage_error = 0; |
|
366 if (argc == 3) |
|
367 { |
1755
|
368 if (sscanf (argv[1].c_str (), "%d", &hist_beg) != 1 |
|
369 || sscanf (argv[2].c_str (), "%d", &hist_end) != 1) |
1
|
370 usage_error = 1; |
|
371 else |
|
372 { |
|
373 hist_beg--; |
|
374 hist_end--; |
|
375 } |
|
376 } |
|
377 else if (argc == 2) |
|
378 { |
1755
|
379 if (sscanf (argv[1].c_str (), "%d", &hist_beg) != 1) |
1
|
380 usage_error = 1; |
|
381 else |
|
382 { |
|
383 hist_beg--; |
|
384 hist_end = hist_beg; |
|
385 } |
|
386 } |
|
387 |
|
388 if (hist_beg < 0 || hist_end < 0 || hist_beg > hist_count |
|
389 || hist_end > hist_count) |
|
390 { |
64
|
391 error ("%s: history specification out of range", warn_for); |
1799
|
392 return retval; |
1
|
393 } |
|
394 |
|
395 if (usage_error) |
|
396 { |
64
|
397 usage ("%s [first] [last]", warn_for); |
1799
|
398 return retval; |
1
|
399 } |
|
400 |
|
401 if (hist_end < hist_beg) |
|
402 { |
|
403 int t = hist_end; |
|
404 hist_end = hist_beg; |
|
405 hist_beg = t; |
|
406 reverse = 1; |
|
407 } |
|
408 |
3523
|
409 std::string name = file_ops::tempnam ("", "oct-"); |
1
|
410 |
3551
|
411 std::fstream file (name.c_str (), std::ios::out); |
64
|
412 |
1
|
413 if (! file) |
|
414 { |
1755
|
415 error ("%s: couldn't open temporary file `%s'", warn_for, |
|
416 name.c_str ()); |
1799
|
417 return retval; |
1
|
418 } |
|
419 |
|
420 if (reverse) |
|
421 { |
|
422 for (int i = hist_end; i >= hist_beg; i--) |
1799
|
423 file << hlist[i] << "\n"; |
1
|
424 } |
|
425 else |
|
426 { |
|
427 for (int i = hist_beg; i <= hist_end; i++) |
1799
|
428 file << hlist[i] << "\n"; |
1
|
429 } |
|
430 |
|
431 file.close (); |
|
432 |
1755
|
433 return name; |
64
|
434 } |
|
435 |
1755
|
436 static void |
|
437 do_edit_history (int argc, const string_vector& argv) |
64
|
438 { |
3523
|
439 std::string name = mk_tmp_hist_file (argc, argv, 0, "edit_history"); |
64
|
440 |
1755
|
441 if (name.empty ()) |
64
|
442 return; |
|
443 |
1358
|
444 // Call up our favorite editor on the file of commands. |
1
|
445 |
5794
|
446 std::string cmd = VEDITOR; |
4469
|
447 cmd.append (" \""); |
1799
|
448 cmd.append (name); |
4469
|
449 cmd.append ("\""); |
1
|
450 |
1358
|
451 // Ignore interrupts while we are off editing commands. Should we |
|
452 // maybe avoid using system()? |
1
|
453 |
2705
|
454 volatile octave_interrupt_handler old_interrupt_handler |
2554
|
455 = octave_ignore_interrupts (); |
1443
|
456 |
1799
|
457 system (cmd.c_str ()); |
1443
|
458 |
2554
|
459 octave_set_interrupt_handler (old_interrupt_handler); |
1
|
460 |
1358
|
461 // Write the commands to the history file since parse_and_execute |
|
462 // disables command line history while it executes. |
1
|
463 |
3551
|
464 std::fstream file (name.c_str (), std::ios::in); |
1
|
465 |
|
466 char *line; |
64
|
467 int first = 1; |
529
|
468 while ((line = edit_history_readline (file)) != 0) |
1
|
469 { |
1358
|
470 // Skip blank lines. |
1
|
471 |
|
472 if (line[0] == '\n') |
|
473 { |
|
474 delete [] line; |
|
475 continue; |
|
476 } |
|
477 |
64
|
478 if (first) |
|
479 { |
|
480 first = 0; |
|
481 edit_history_repl_hist (line); |
|
482 } |
|
483 else |
|
484 edit_history_add_hist (line); |
1
|
485 } |
|
486 |
|
487 file.close (); |
|
488 |
1358
|
489 // Turn on command echo, so the output from this will make better |
|
490 // sense. |
1
|
491 |
2985
|
492 unwind_protect::begin_frame ("do_edit_history"); |
3018
|
493 |
2205
|
494 unwind_protect_int (Vecho_executing_commands); |
3018
|
495 unwind_protect_bool (input_from_tmp_history_file); |
|
496 |
2205
|
497 Vecho_executing_commands = ECHO_CMD_LINE; |
3018
|
498 input_from_tmp_history_file = true; |
1
|
499 |
2897
|
500 parse_and_execute (name); |
1
|
501 |
2985
|
502 unwind_protect::run_frame ("do_edit_history"); |
1
|
503 |
1358
|
504 // Delete the temporary file. Should probably be done with an |
|
505 // unwind_protect. |
1
|
506 |
1755
|
507 unlink (name.c_str ()); |
1
|
508 } |
|
509 |
1755
|
510 static void |
|
511 do_run_history (int argc, const string_vector& argv) |
64
|
512 { |
3523
|
513 std::string name = mk_tmp_hist_file (argc, argv, 1, "run_history"); |
64
|
514 |
1755
|
515 if (name.empty ()) |
64
|
516 return; |
|
517 |
1799
|
518 // Turn on command echo so the output from this will make better |
1358
|
519 // sense. |
64
|
520 |
2985
|
521 unwind_protect::begin_frame ("do_run_history"); |
3018
|
522 |
2205
|
523 unwind_protect_int (Vecho_executing_commands); |
3018
|
524 unwind_protect_bool (input_from_tmp_history_file); |
|
525 |
2205
|
526 Vecho_executing_commands = ECHO_CMD_LINE; |
3018
|
527 input_from_tmp_history_file = true; |
64
|
528 |
2897
|
529 parse_and_execute (name); |
64
|
530 |
2985
|
531 unwind_protect::run_frame ("do_run_history"); |
64
|
532 |
1799
|
533 // Delete the temporary file. |
|
534 |
5775
|
535 // FIXME -- should probably be done using an unwind_protect. |
64
|
536 |
1755
|
537 unlink (name.c_str ()); |
64
|
538 } |
|
539 |
5305
|
540 void |
5794
|
541 initialize_history (void) |
|
542 { |
5872
|
543 command_history::set_file (Vhistory_file); |
5800
|
544 command_history::set_size (Vhistory_size); |
|
545 |
5794
|
546 command_history::read (false); |
|
547 } |
|
548 |
|
549 void |
5305
|
550 octave_history_write_timestamp (void) |
|
551 { |
|
552 octave_localtime now; |
|
553 |
|
554 std::string timestamp = now.strftime (Vhistory_timestamp_format_string); |
|
555 |
|
556 if (! timestamp.empty ()) |
|
557 command_history::add (timestamp); |
|
558 } |
|
559 |
4208
|
560 DEFCMD (edit_history, args, , |
3332
|
561 "-*- texinfo -*-\n\ |
|
562 @deffn {Command} edit_history options\n\ |
|
563 If invoked with no arguments, @code{edit_history} allows you to edit the\n\ |
|
564 history list using the editor named by the variable @code{EDITOR}. The\n\ |
|
565 commands to be edited are first copied to a temporary file. When you\n\ |
|
566 exit the editor, Octave executes the commands that remain in the file.\n\ |
|
567 It is often more convenient to use @code{edit_history} to define functions \n\ |
|
568 rather than attempting to enter them directly on the command line.\n\ |
|
569 By default, the block of commands is executed as soon as you exit the\n\ |
|
570 editor. To avoid executing any commands, simply delete all the lines\n\ |
|
571 from the buffer before exiting the editor.\n\ |
|
572 \n\ |
|
573 The @code{edit_history} command takes two optional arguments specifying\n\ |
|
574 the history numbers of first and last commands to edit. For example,\n\ |
|
575 the command\n\ |
529
|
576 \n\ |
3332
|
577 @example\n\ |
|
578 edit_history 13\n\ |
|
579 @end example\n\ |
|
580 \n\ |
|
581 @noindent\n\ |
|
582 extracts all the commands from the 13th through the last in the history\n\ |
|
583 list. The command\n\ |
|
584 \n\ |
|
585 @example\n\ |
|
586 edit_history 13 169\n\ |
|
587 @end example\n\ |
|
588 \n\ |
|
589 @noindent\n\ |
|
590 only extracts commands 13 through 169. Specifying a larger number for\n\ |
|
591 the first command than the last command reverses the list of commands\n\ |
|
592 before placing them in the buffer to be edited. If both arguments are\n\ |
|
593 omitted, the previous command in the history list is used.\n\ |
3333
|
594 @end deffn") |
529
|
595 { |
2086
|
596 octave_value_list retval; |
529
|
597 |
1755
|
598 int argc = args.length () + 1; |
|
599 |
1968
|
600 string_vector argv = args.make_argv ("edit_history"); |
1755
|
601 |
|
602 if (error_state) |
|
603 return retval; |
529
|
604 |
|
605 do_edit_history (argc, argv); |
|
606 |
|
607 return retval; |
|
608 } |
|
609 |
4208
|
610 DEFCMD (history, args, , |
3332
|
611 "-*- texinfo -*-\n\ |
|
612 @deffn {Command} history options\n\ |
|
613 If invoked with no arguments, @code{history} displays a list of commands\n\ |
|
614 that you have executed. Valid options are:\n\ |
|
615 \n\ |
|
616 @table @code\n\ |
|
617 @item -w @var{file}\n\ |
|
618 Write the current history to the file @var{file}. If the name is\n\ |
|
619 omitted, use the default history file (normally @file{~/.octave_hist}).\n\ |
529
|
620 \n\ |
3332
|
621 @item -r @var{file}\n\ |
|
622 Read the file @var{file}, replacing the current history list with its\n\ |
|
623 contents. If the name is omitted, use the default history file\n\ |
|
624 (normally @file{~/.octave_hist}).\n\ |
|
625 \n\ |
3499
|
626 @item @var{n}\n\ |
|
627 Only display the most recent @var{n} lines of history.\n\ |
3332
|
628 \n\ |
|
629 @item -q\n\ |
|
630 Don't number the displayed lines of history. This is useful for cutting\n\ |
|
631 and pasting commands if you are using the X Window System.\n\ |
|
632 @end table\n\ |
|
633 \n\ |
|
634 For example, to display the five most recent commands that you have\n\ |
|
635 typed without displaying line numbers, use the command\n\ |
|
636 @kbd{history -q 5}.\n\ |
3333
|
637 @end deffn") |
529
|
638 { |
2086
|
639 octave_value_list retval; |
529
|
640 |
1755
|
641 int argc = args.length () + 1; |
|
642 |
1968
|
643 string_vector argv = args.make_argv ("history"); |
1755
|
644 |
|
645 if (error_state) |
|
646 return retval; |
529
|
647 |
|
648 do_history (argc, argv); |
|
649 |
|
650 return retval; |
|
651 } |
|
652 |
4208
|
653 DEFCMD (run_history, args, , |
3332
|
654 "-*- texinfo -*-\n\ |
|
655 @deffn {Command} run_history [first] [last]\n\ |
|
656 Similar to @code{edit_history}, except that the editor is not invoked,\n\ |
|
657 and the commands are simply executed as they appear in the history list.\n\ |
3333
|
658 @end deffn") |
529
|
659 { |
2086
|
660 octave_value_list retval; |
529
|
661 |
1755
|
662 int argc = args.length () + 1; |
|
663 |
1968
|
664 string_vector argv = args.make_argv ("run_history"); |
1755
|
665 |
|
666 if (error_state) |
|
667 return retval; |
529
|
668 |
|
669 do_run_history (argc, argv); |
|
670 |
|
671 return retval; |
|
672 } |
|
673 |
5794
|
674 DEFUN (history_size, args, nargout, |
|
675 "-*- texinfo -*-\n\ |
|
676 @deftypefn {Built-in Function} {@var{val} =} history_size ()\n\ |
|
677 @deftypefnx {Built-in Function} {@var{old_val} =} history_size (@var{new_val})\n\ |
|
678 Query or set the internal variable that specifies how many entries\n\ |
|
679 to store in the history file. The default value is @code{1024},\n\ |
|
680 but may be overridden by the environment variable @code{OCTAVE_HISTSIZE}.\n\ |
|
681 @seealso{history_file, history_timestamp_format, saving_history}\n\ |
|
682 @end deftypefn") |
3016
|
683 { |
5800
|
684 int saved_history_size = Vhistory_size; |
|
685 |
|
686 octave_value retval |
|
687 = SET_INTERNAL_VARIABLE_WITH_LIMITS (history_size, -1, INT_MAX); |
|
688 |
|
689 if (Vhistory_size != saved_history_size) |
|
690 command_history::set_size (Vhistory_size); |
|
691 |
|
692 return retval; |
3016
|
693 } |
|
694 |
5794
|
695 DEFUN (history_file, args, nargout, |
|
696 "-*- texinfo -*-\n\ |
|
697 @deftypefn {Built-in Function} {@var{val} =} history_file ()\n\ |
|
698 @deftypefnx {Built-in Function} {@var{old_val} =} history_file (@var{new_val})\n\ |
|
699 Query or set the internal variable that specifies the name of the\n\ |
|
700 file used to store command history. The default value is\n\ |
|
701 @code{\"~/.octave_hist\"}, but may be overridden by the environment\n\ |
|
702 variable @code{OCTAVE_HISTFILE}.\n\ |
|
703 @seealso{history_size, saving_history, history_timestamp_format_string}\n\ |
|
704 @end deftypefn") |
5305
|
705 { |
5794
|
706 std::string saved_history_file = Vhistory_file; |
5305
|
707 |
5794
|
708 octave_value retval = SET_INTERNAL_VARIABLE (history_file); |
5305
|
709 |
5794
|
710 if (Vhistory_file != saved_history_file) |
5872
|
711 command_history::set_file (Vhistory_file); |
5305
|
712 |
5800
|
713 return retval; |
3016
|
714 } |
|
715 |
5794
|
716 DEFUN (history_timestamp_format_string, args, nargout, |
|
717 "-*- texinfo -*-\n\ |
|
718 @deftypefn {Built-in Function} {@var{val} =} history_timestamp_format_string ()\n\ |
|
719 @deftypefnx {Built-in Function} {@var{old_val} =} history_timestamp_format_string (@var{new_val})\n\ |
|
720 Query or set the internal variable that specifies the the format string\n\ |
|
721 for the comment line that is written to the history file when Octave\n\ |
|
722 exits. The format string is passed to @code{strftime}. The default\n\ |
|
723 value is\n\ |
5305
|
724 \n\ |
|
725 @example\n\ |
|
726 \"# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>\"\n\ |
|
727 @end example\n\ |
5794
|
728 @seealso{strftime, history_file, history_size, saving_history}\n\ |
|
729 @end deftypefn") |
|
730 { |
|
731 return SET_INTERNAL_VARIABLE (history_timestamp_format_string); |
|
732 } |
5305
|
733 |
5794
|
734 DEFUN (saving_history, args, nargout, |
|
735 "-*- texinfo -*-\n\ |
|
736 @deftypefn {Built-in Function} {@var{val} =} saving_history ()\n\ |
|
737 @deftypefnx {Built-in Function} {@var{old_val} =} saving_history (@var{new_val})\n\ |
|
738 Query or set the internal variable that controls whether commands entered\n\ |
|
739 on the command line are saved in the history file.\n\ |
|
740 @seealso{history_file, history_size, history_timestamp_format}.\n\ |
|
741 @end deftypefn") |
|
742 { |
|
743 octave_value retval = SET_INTERNAL_VARIABLE (saving_history); |
|
744 |
|
745 command_history::ignore_entries (! Vsaving_history); |
|
746 |
|
747 return retval; |
3016
|
748 } |
|
749 |
1
|
750 /* |
|
751 ;;; Local Variables: *** |
|
752 ;;; mode: C++ *** |
|
753 ;;; End: *** |
|
754 */ |