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