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