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