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