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