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