GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
oct-hist.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1993-2018 John W. Eaton
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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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, see
19 <https://www.gnu.org/licenses/>.
20 
21 */
22 
23 /*
24 
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 
34 #if defined (HAVE_CONFIG_H)
35 # include "config.h"
36 #endif
37 
38 #include <cstdlib>
39 #include <cstring>
40 
41 #include <fstream>
42 #include <string>
43 
44 #include "cmd-hist.h"
45 #include "file-ops.h"
46 #include "lo-mappers.h"
47 #include "octave-link.h"
48 #include "oct-env.h"
49 #include "oct-time.h"
50 #include "str-vec.h"
51 #include "unistd-wrappers.h"
52 
53 #include "defaults.h"
54 #include "defun.h"
55 #include "error.h"
56 #include "errwarn.h"
57 #include "input.h"
58 #include "oct-hist.h"
59 #include "ovl.h"
60 #include "pager.h"
61 #include "parse.h"
62 #include "sighandlers.h"
63 #include "sysdep.h"
64 #include "interpreter.h"
65 #include "unwind-prot.h"
66 #include "utils.h"
67 #include "variables.h"
68 
69 // TRUE means input is coming from temporary history file.
71 
72 static std::string
74 {
76 
77  std::string env_file = octave::sys::env::getenv ("OCTAVE_HISTFILE");
78 
79  if (! env_file.empty ())
80  file = env_file;
81 
82  if (file.empty ())
84  ".octave_hist");
85 
86  return file;
87 }
88 
89 static int
91 {
92  int size = 1000;
93 
94  std::string env_size = octave::sys::env::getenv ("OCTAVE_HISTSIZE");
95 
96  if (! env_size.empty ())
97  {
98  int val;
99 
100  if (sscanf (env_size.c_str (), "%d", &val) == 1)
101  size = (val > 0 ? val : 0);
102  }
103 
104  return size;
105 }
106 
107 static std::string
109 {
110  return
111  "# Octave " OCTAVE_VERSION ", %a %b %d %H:%M:%S %Y %Z <"
113  + '@'
115  + '>';
116 }
117 
118 // The format of the timestamp marker written to the history file when
119 // Octave exits.
122 
123 // Display, save, or load history. Stolen and modified from bash.
124 //
125 // Arg of -w FILENAME means write file, arg of -r FILENAME
126 // means read file, arg of -q means don't number lines. Arg of N
127 // means only display that many items.
128 
129 static string_vector
131 {
132  bool numbered_output = nargout == 0;
133 
135 
136  string_vector hlist;
137 
140 
141  int nargin = args.length ();
142 
143  // Number of history lines to show (-1 = all)
144  int limit = -1;
145 
146  for (octave_idx_type i = 0; i < nargin; i++)
147  {
148  octave_value arg = args(i);
149 
151 
152  if (arg.is_string ())
153  option = arg.string_value ();
154  else if (arg.isnumeric ())
155  {
156  limit = arg.int_value ();
157  if (limit < 0)
158  limit = -limit;
159  continue;
160  }
161  else
162  err_wrong_type_arg ("history", arg);
163 
164  if (option == "-r" || option == "-w" || option == "-a"
165  || option == "-n")
166  {
167  if (i < nargin - 1)
168  {
170  = args(++i).xstring_value ("history: filename must be a string for %s option",
171  option.c_str ());
172 
174  }
175  else
177 
178  if (option == "-a")
179  // Append 'new' lines to file.
181 
182  else if (option == "-w")
183  // Write entire history.
185 
186  else if (option == "-r")
187  {
188  // Read entire file.
191  }
192 
193  else if (option == "-n")
194  {
195  // Read 'new' history from file.
198  }
199 
200  else
201  panic_impossible ();
202 
203  return hlist;
204  }
205  else if (option == "-c")
206  {
209  }
210  else if (option == "-q")
211  numbered_output = false;
212  else if (option == "--")
213  {
214  i++;
215  break;
216  }
217  else
218  {
219  // The last argument found in the command list that looks like
220  // an integer will be used
221  int tmp;
222 
223  if (sscanf (option.c_str (), "%d", &tmp) == 1)
224  {
225  if (tmp > 0)
226  limit = tmp;
227  else
228  limit = -tmp;
229  }
230 
231  else
232  {
233  if (option.length () > 0 && option[0] == '-')
234  error ("history: unrecognized option '%s'", option.c_str ());
235  else
236  error ("history: bad non-numeric arg '%s'", option.c_str ());
237  }
238  }
239  }
240 
241  hlist = octave::command_history::list (limit, numbered_output);
242 
243  int len = hlist.numel ();
244 
245  if (nargout == 0)
246  {
247  for (octave_idx_type i = 0; i < len; i++)
248  octave_stdout << hlist[i] << "\n";
249  }
250 
251  return hlist;
252 }
253 
254 // Read the edited history lines from STREAM and return them
255 // one at a time. This can read unlimited length lines. The
256 // caller should free the storage.
257 
258 static char *
259 edit_history_readline (std::fstream& stream)
260 {
261  char c;
262  int line_len = 128;
263  int lindex = 0;
264  char *line = new char [line_len];
265  line[0] = '\0';
266 
267  while (stream.get (c))
268  {
269  if (lindex + 2 >= line_len)
270  {
271  char *tmp_line = new char [line_len += 128];
272  strcpy (tmp_line, line);
273  delete [] line;
274  line = tmp_line;
275  }
276 
277  if (c == '\n')
278  {
279  line[lindex++] = '\n';
280  line[lindex++] = '\0';
281  return line;
282  }
283  else
284  line[lindex++] = c;
285  }
286 
287  if (! lindex)
288  {
289  delete [] line;
290  return nullptr;
291  }
292 
293  if (lindex + 2 >= line_len)
294  {
295  char *tmp_line = new char [lindex+3];
296  strcpy (tmp_line, line);
297  delete [] line;
298  line = tmp_line;
299  }
300 
301  // Finish with newline if none in file.
302 
303  line[lindex++] = '\n';
304  line[lindex++] = '\0';
305  return line;
306 }
307 
308 static void
310 {
311  if (! line.empty ())
312  {
313  std::string tmp = line;
314 
315  int len = tmp.length ();
316 
317  if (len > 0 && tmp[len-1] == '\n')
318  tmp.resize (len - 1);
319 
320  if (! tmp.empty ())
323  }
324 }
325 
326 static bool
328 {
329  bool ok = true;
330 
331  if (arg.is_string ())
332  {
334 
335  ok = sscanf (tmp.c_str (), "%d", &val) == 1;
336  }
337  else if (arg.isnumeric ())
338  val = arg.int_value ();
339  else
340  ok = false;
341 
342  return ok;
343 }
344 
345 static std::string
347  bool insert_curr, const char *warn_for)
348 {
350 
351  int hist_count = hlist.numel () - 1; // switch to zero-based indexing
352 
353  // The current command line is already part of the history list by
354  // the time we get to this point. Delete the cmd from the list when
355  // executing 'edit_history' so that it doesn't show up in the history
356  // but the actual commands performed will.
357 
358  if (! insert_curr)
359  octave::command_history::remove (hist_count);
360 
361  hist_count--; // skip last entry in history list
362 
363  // If no numbers have been specified, the default is to edit the
364  // last command in the history list.
365 
366  int hist_beg = hist_count;
367  int hist_end = hist_count;
368 
369  bool reverse = false;
370 
371  // Process options.
372 
373  int nargin = args.length ();
374 
375  if (nargin == 2)
376  {
377  if (! get_int_arg (args(0), hist_beg)
378  || ! get_int_arg (args(1), hist_end))
379  error ("%s: arguments must be integers", warn_for);
380 
381  if (hist_beg < 0)
382  hist_beg += (hist_count + 1);
383  else
384  hist_beg--;
385  if (hist_end < 0)
386  hist_end += (hist_count + 1);
387  else
388  hist_end--;
389  }
390  else if (nargin == 1)
391  {
392  if (! get_int_arg (args(0), hist_beg))
393  error ("%s: argument must be an integer", warn_for);
394 
395  if (hist_beg < 0)
396  hist_beg += (hist_count + 1);
397  else
398  hist_beg--;
399 
400  hist_end = hist_beg;
401  }
402 
403  if (hist_beg > hist_count || hist_end > hist_count)
404  error ("%s: history specification out of range", warn_for);
405 
406  if (hist_end < hist_beg)
407  {
408  std::swap (hist_end, hist_beg);
409  reverse = true;
410  }
411 
412  std::string name = octave::sys::tempnam ("", "oct-");
413 
414  std::fstream file (name.c_str (), std::ios::out);
415 
416  if (! file)
417  error ("%s: couldn't open temporary file '%s'", warn_for,
418  name.c_str ());
419 
420  if (reverse)
421  {
422  for (int i = hist_end; i >= hist_beg; i--)
423  file << hlist[i] << "\n";
424  }
425  else
426  {
427  for (int i = hist_beg; i <= hist_end; i++)
428  file << hlist[i] << "\n";
429  }
430 
431  file.close ();
432 
433  return name;
434 }
435 
436 static void
437 unlink_cleanup (const char *file)
438 {
440 }
441 
442 static void
444 {
445  std::string name = mk_tmp_hist_file (args, false, "edit_history");
446 
447  if (name.empty ())
448  return;
449 
450  // Call up our favorite editor on the file of commands.
451 
452  octave::environment& env = interp.get_environment ();
453  std::string cmd = env.editor ();
454  cmd.append (R"( ")" + name + '"');
455 
456  // Ignore interrupts while we are off editing commands. Should we
457  // maybe avoid using system()?
458 
459  volatile octave::interrupt_handler old_interrupt_handler
461 
462  int status = system (cmd.c_str ());
463 
464  octave::set_interrupt_handler (old_interrupt_handler);
465 
466  // Check if text edition was successfull. Abort the operation
467  // in case of failure.
468  if (status != EXIT_SUCCESS)
469  error ("edit_history: text editor command failed");
470 
471  // Write the commands to the history file since source_file
472  // disables command line history while it executes.
473 
474  std::fstream file (name.c_str (), std::ios::in);
475 
476  char *line;
477  //int first = 1;
478  while ((line = edit_history_readline (file)) != nullptr)
479  {
480  // Skip blank lines.
481 
482  if (line[0] == '\n')
483  {
484  delete [] line;
485  continue;
486  }
487 
489 
490  delete [] line;
491  }
492 
493  file.close ();
494 
496 
497  frame.add_fcn (unlink_cleanup, name.c_str ());
499 
501 
502  // FIXME: instead of sourcing a file, we should just iterate through
503  // the list of commands, parsing and executing them one at a time as
504  // if they were entered interactively.
505 
507 }
508 
509 static void
511 {
512  std::string name = mk_tmp_hist_file (args, false, "run_history");
513 
514  if (name.empty ())
515  return;
516 
518 
519  frame.add_fcn (unlink_cleanup, name.c_str ());
521 
523 
524  // FIXME: instead of sourcing a file, we should just iterate through
525  // the list of commands, parsing and executing them one at a time as
526  // if they were entered interactively.
527 
529 }
530 
531 void
532 initialize_history (bool read_history_file)
533 {
534  octave::command_history::initialize (read_history_file,
537  octave::sys::env::getenv ("OCTAVE_HISTCONTROL"));
538 
540 }
541 
542 void
544 {
546 
547  std::string timestamp = now.strftime (Vhistory_timestamp_format_string);
548 
549  if (! timestamp.empty ())
550  if (octave::command_history::add (timestamp))
551  octave_link::append_history (timestamp);
552 }
553 
554 DEFMETHOD (edit_history, interp, args, ,
555  doc: /* -*- texinfo -*-
556 @deftypefn {} {} edit_history
557 @deftypefnx {} {} edit_history @var{cmd_number}
558 @deftypefnx {} {} edit_history @var{first} @var{last}
559 Edit the history list using the editor named by the variable @env{EDITOR}.
560 
561 The commands to be edited are first copied to a temporary file. When you
562 exit the editor, Octave executes the commands that remain in the file. It
563 is often more convenient to use @code{edit_history} to define functions
564 rather than attempting to enter them directly on the command line.
565 The block of commands is executed as soon as you exit the editor.
566 To avoid executing any commands, simply delete all the lines from the buffer
567 before leaving the editor.
568 
569 When invoked with no arguments, edit the previously executed command;
570 With one argument, edit the specified command @var{cmd_number};
571 With two arguments, edit the list of commands between @var{first} and
572 @var{last}. Command number specifiers may also be negative where -1
573 refers to the most recently executed command.
574 The following are equivalent and edit the most recently executed command.
575 
576 @example
577 @group
578 edit_history
579 edit_history -1
580 @end group
581 @end example
582 
583 When using ranges, specifying a larger number for the first command than the
584 last command reverses the list of commands before they are placed in the
585 buffer to be edited.
586 @seealso{run_history, history}
587 @end deftypefn */)
588 {
589  // FIXME: should this be limited to the top-level context?
590 
591  if (args.length () > 2)
592  print_usage ();
593 
594  do_edit_history (interp, args);
595 
596  return ovl ();
597 }
598 
599 DEFUN (history, args, nargout,
600  doc: /* -*- texinfo -*-
601 @deftypefn {} {} history
602 @deftypefnx {} {} history @var{opt1} @dots{}
603 @deftypefnx {} {@var{h} =} history ()
604 @deftypefnx {} {@var{h} =} history (@var{opt1}, @dots{})
605 If invoked with no arguments, @code{history} displays a list of commands
606 that you have executed.
607 
608 Valid options are:
609 
610 @table @code
611 @item @var{n}
612 @itemx -@var{n}
613 Display only the most recent @var{n} lines of history.
614 
615 @item -c
616 Clear the history list.
617 
618 @item -q
619 Don't number the displayed lines of history. This is useful for cutting
620 and pasting commands using the X Window System.
621 
622 @item -r @var{file}
623 Read the file @var{file}, appending its contents to the current
624 history list. If the name is omitted, use the default history file
625 (normally @file{~/.octave_hist}).
626 
627 @item -w @var{file}
628 Write the current history to the file @var{file}. If the name is
629 omitted, use the default history file (normally @file{~/.octave_hist}).
630 @end table
631 
632 For example, to display the five most recent commands that you have
633 typed without displaying line numbers, use the command
634 @kbd{history -q 5}.
635 
636 If invoked with a single output argument, the history will be saved to that
637 argument as a cell string and will not be output to screen.
638 @seealso{edit_history, run_history}
639 @end deftypefn */)
640 {
641  // FIXME: should this be limited to the top-level context?
642 
643  // Call do_history even if nargout is zero to display history list.
644 
645  string_vector hlist = do_history (args, nargout);
646 
647  return nargout > 0 ? ovl (Cell (hlist)) : ovl ();
648 }
649 
650 DEFUN (run_history, args, ,
651  doc: /* -*- texinfo -*-
652 @deftypefn {} {} run_history
653 @deftypefnx {} {} run_history @var{cmd_number}
654 @deftypefnx {} {} run_history @var{first} @var{last}
655 Run commands from the history list.
656 
657 When invoked with no arguments, run the previously executed command;
658 
659 With one argument, run the specified command @var{cmd_number};
660 
661 With two arguments, run the list of commands between @var{first} and
662 @var{last}. Command number specifiers may also be negative where -1
663 refers to the most recently executed command. For example, the command
664 
665 @example
666 @group
667 run_history
668  OR
669 run_history -1
670 @end group
671 @end example
672 
673 @noindent
674 executes the most recent command again.
675 The command
676 
677 @example
678 run_history 13 169
679 @end example
680 
681 @noindent
682 executes commands 13 through 169.
683 
684 Specifying a larger number for the first command than the last command
685 reverses the list of commands before executing them.
686 For example:
687 
688 @example
689 @group
690 disp (1)
691 disp (2)
692 run_history -1 -2
693 @result{}
694  2
695  1
696 @end group
697 @end example
698 
699 @seealso{edit_history, history}
700 @end deftypefn */)
701 {
702  // FIXME: should this be limited to the top-level context?
703 
704  if (args.length () > 2)
705  print_usage ();
706 
707  do_run_history (args);
708 
709  return ovl ();
710 }
711 
712 DEFUN (history_control, args, nargout,
713  doc: /* -*- texinfo -*-
714 @deftypefn {} {@var{val} =} history_control ()
715 @deftypefnx {} {@var{old_val} =} history_control (@var{new_val})
716 Query or set the internal variable that specifies how commands are saved
717 to the history list.
718 
719 The default value is an empty character string, but may be overridden by the
720 environment variable @w{@env{OCTAVE_HISTCONTROL}}.
721 
722 The value of @code{history_control} is a colon-separated list of values
723 controlling how commands are saved on the history list. If the list
724 of values includes @code{ignorespace}, lines which begin with a space
725 character are not saved in the history list. A value of @code{ignoredups}
726 causes lines matching the previous history entry to not be saved.
727 A value of @code{ignoreboth} is shorthand for @code{ignorespace} and
728 @code{ignoredups}. A value of @code{erasedups} causes all previous lines
729 matching the current line to be removed from the history list before that
730 line is saved. Any value not in the above list is ignored. If
731 @code{history_control} is the empty string, all commands are saved on
732 the history list, subject to the value of @code{history_save}.
733 @seealso{history_file, history_size, history_timestamp_format_string, history_save}
734 @end deftypefn */)
735 {
737 
738  std::string old_history_control = octave::command_history::histcontrol ();
739 
740  std::string tmp = old_history_control;
741 
742  retval = set_internal_variable (tmp, args, nargout, "history_control");
743 
744  if (tmp != old_history_control)
746 
747  return retval;
748 }
749 
750 DEFUN (history_size, args, nargout,
751  doc: /* -*- texinfo -*-
752 @deftypefn {} {@var{val} =} history_size ()
753 @deftypefnx {} {@var{old_val} =} history_size (@var{new_val})
754 Query or set the internal variable that specifies how many entries
755 to store in the history file.
756 
757 The default value is @code{1000}, but may be overridden by the environment
758 variable @w{@env{OCTAVE_HISTSIZE}}.
759 @seealso{history_file, history_timestamp_format_string, history_save}
760 @end deftypefn */)
761 {
763 
764  int old_history_size = octave::command_history::size ();
765 
766  int tmp = old_history_size;
767 
769  "history_size", -1,
771 
772  if (tmp != old_history_size)
774 
775  return retval;
776 }
777 
778 DEFUN (history_file, args, nargout,
779  doc: /* -*- texinfo -*-
780 @deftypefn {} {@var{val} =} history_file ()
781 @deftypefnx {} {@var{old_val} =} history_file (@var{new_val})
782 Query or set the internal variable that specifies the name of the
783 file used to store command history.
784 
785 The default value is @file{~/.octave_hist}, but may be overridden by the
786 environment variable @w{@env{OCTAVE_HISTFILE}}.
787 @seealso{history_size, history_save, history_timestamp_format_string}
788 @end deftypefn */)
789 {
791 
792  std::string old_history_file = octave::command_history::file ();
793 
794  std::string tmp = old_history_file;
795 
796  retval = set_internal_variable (tmp, args, nargout, "history_file");
797 
798  if (tmp != old_history_file)
800 
801  return retval;
802 }
803 
804 DEFUN (history_timestamp_format_string, args, nargout,
805  doc: /* -*- texinfo -*-
806 @deftypefn {} {@var{val} =} history_timestamp_format_string ()
807 @deftypefnx {} {@var{old_val} =} history_timestamp_format_string (@var{new_val})
808 @deftypefnx {} {} history_timestamp_format_string (@var{new_val}, "local")
809 Query or set the internal variable that specifies the format string
810 for the comment line that is written to the history file when Octave
811 exits.
812 
813 The format string is passed to @code{strftime}. The default value is
814 
815 @example
816 "# Octave VERSION, %a %b %d %H:%M:%S %Y %Z <USER@@HOST>"
817 @end example
818 
819 When called from inside a function with the @qcode{"local"} option, the
820 variable is changed locally for the function and any subroutines it calls.
821 The original variable value is restored when exiting the function.
822 @seealso{strftime, history_file, history_size, history_save}
823 @end deftypefn */)
824 {
825  return SET_INTERNAL_VARIABLE (history_timestamp_format_string);
826 }
827 
828 DEFUN (history_save, args, nargout,
829  doc: /* -*- texinfo -*-
830 @deftypefn {} {@var{val} =} history_save ()
831 @deftypefnx {} {@var{old_val} =} history_save (@var{new_val})
832 @deftypefnx {} {} history_save (@var{new_val}, "local")
833 Query or set the internal variable that controls whether commands entered
834 on the command line are saved in the history file.
835 
836 When called from inside a function with the @qcode{"local"} option, the
837 variable is changed locally for the function and any subroutines it calls.
838 The original variable value is restored when exiting the function.
839 @seealso{history_control, history_file, history_size, history_timestamp_format_string}
840 @end deftypefn */)
841 {
843 
844  bool old_history_save = ! octave::command_history::ignoring_entries ();
845 
846  bool tmp = old_history_save;
847 
848  retval = set_internal_variable (tmp, args, nargout, "history_save");
849 
850  if (tmp != old_history_save)
852 
853  return retval;
854 }
static void write(const std::string &="")
Definition: cmd-hist.cc:725
static std::string histcontrol(void)
Definition: cmd-hist.cc:571
Definition: Cell.h:37
For example cd octave end example noindent changes the current working directory to file
Definition: dirfns.cc:124
octave_value editor(const octave_value_list &args, int nargout)
Definition: environment.cc:71
static void read(bool=true)
Definition: cmd-hist.cc:698
int int_value(bool req_int=false, bool frc_str_conv=false) const
Definition: ov.h:793
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
Definition: defun.h:135
fname
Definition: load-save.cc:767
static void do_edit_history(octave::interpreter &interp, const octave_value_list &args)
Definition: oct-hist.cc:443
std::string string_value(bool force=false) const
Definition: ov.h:955
static void clear(void)
Definition: cmd-hist.cc:621
OCTINTERP_API void print_usage(void)
Definition: defun.cc:54
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the system(carriage-return linefeed on Windows). The default when no mode is specified is binary. Additionally
std::string tempnam(const std::string &dir, const std::string &pfx)
Definition: file-ops.cc:638
octave::sys::time now
Definition: data.cc:6251
static std::string Vhistory_timestamp_format_string
Definition: oct-hist.cc:121
static string_vector do_history(const octave_value_list &args, int nargout)
Definition: oct-hist.cc:130
static void unlink_cleanup(const char *file)
Definition: oct-hist.cc:437
static void set_size(int)
Definition: cmd-hist.cc:578
void add_fcn(void(*fcn)(void))
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:53
void error(const char *fmt,...)
Definition: error.cc:578
#define SET_INTERNAL_VARIABLE(NM)
Definition: variables.h:109
static void ignore_entries(bool=true)
Definition: cmd-hist.cc:592
static std::string default_history_timestamp_format(void)
Definition: oct-hist.cc:108
environment & get_environment(void)
Definition: interpreter.h:149
static bool add(const std::string &)
Definition: cmd-hist.cc:606
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
Definition: file-io.cc:587
octave_value arg
Definition: pr-output.cc:3244
static void do_run_history(const octave_value_list &args)
Definition: oct-hist.cc:510
static std::string getenv(const std::string &name)
Definition: oct-env.cc:235
static void edit_history_add_hist(const std::string &line)
Definition: oct-hist.cc:309
#define OCTAVE_VERSION
Definition: main.in.cc:48
void initialize_history(bool read_history_file)
Definition: oct-hist.cc:532
OCTINTERP_API void source_file(const std::string &file_name, const std::string &context="", bool verbose=false, bool require_file=true, const std::string &warn_for="")
return ovl()
bool swap
Definition: load-save.cc:738
std::string concat(const std::string &dir, const std::string &file)
Definition: file-ops.cc:344
nd deftypefn *std::string name
Definition: sysdep.cc:647
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
Definition: ov-usr-fcn.cc:997
option
Definition: call-stack.cc:659
static std::string get_home_directory(void)
Definition: oct-env.cc:143
static string_vector list(int=-1, bool=false)
Definition: cmd-hist.cc:746
void octave_history_write_timestamp(void)
Definition: oct-hist.cc:543
static std::string mk_tmp_hist_file(const octave_value_list &args, bool insert_curr, const char *warn_for)
Definition: oct-hist.cc:346
int octave_unlink_wrapper(const char *nm)
static std::string get_host_name(void)
Definition: oct-env.cc:185
static std::string get_user_name(void)
Definition: oct-env.cc:178
double tmp
Definition: data.cc:6252
octave_value retval
Definition: data.cc:6246
#define panic_impossible()
Definition: error.h:40
static void read_range(int=-1, int=-1, bool=true)
Definition: cmd-hist.cc:711
interrupt_handler ignore_interrupts(void)
Definition: sighandlers.cc:334
static void initialize(bool, const std::string &, int, const std::string &)
Definition: cmd-hist.cc:529
end deftypefn *return set_internal_variable(Vsvd_driver, args, nargout, "svd_driver", driver_names)
void err_wrong_type_arg(const char *name, const char *s)
Definition: errwarn.cc:162
octave::unwind_protect frame
Definition: graphics.cc:12190
charNDArray max(char d, const charNDArray &m)
Definition: chNDArray.cc:227
#define octave_stdout
Definition: pager.h:174
bool input_from_tmp_history_file
Definition: oct-hist.cc:70
static bool get_int_arg(const octave_value &arg, int &val)
Definition: oct-hist.cc:327
static void set_file(const std::string &)
Definition: cmd-hist.cc:546
interrupt_handler set_interrupt_handler(const volatile interrupt_handler &h, bool restart_syscalls)
Definition: sighandlers.cc:345
static int default_history_size(void)
Definition: oct-hist.cc:90
octave_idx_type length(void) const
Definition: ovl.h:96
static bool ignoring_entries(void)
Definition: cmd-hist.cc:599
args.length() nargin
Definition: file-io.cc:589
for i
Definition: data.cc:5264
bool is_string(void) const
Definition: ov.h:577
static std::string default_history_file(void)
Definition: oct-hist.cc:73
static char * edit_history_readline(std::fstream &stream)
Definition: oct-hist.cc:259
octave_idx_type numel(void) const
Number of elements in the array.
Definition: Array.h:366
static int size(void)
Definition: cmd-hist.cc:585
static void append(const std::string &="")
Definition: cmd-hist.cc:732
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Definition: utils.cc:888
static void remove(int)
Definition: cmd-hist.cc:614
static std::string file(void)
Definition: cmd-hist.cc:557
bool isnumeric(void) const
Definition: ov.h:723
static void process_histcontrol(const std::string &)
Definition: cmd-hist.cc:564