1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1993-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING.  If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_oct_hist_h)
27 #define octave_oct_hist_h 1
28 
29 #include "octave-config.h"
30 
31 #include <string>
32 
33 #include "cmd-hist.h"
34 
35 #include "ovl.h"
36 
37 namespace octave
38 {
39   class interpreter;
40 
41   class history_system
42   {
43   public:
44 
45     history_system (interpreter& interp);
46 
47     history_system (const history_system&) = delete;
48 
49     history_system& operator = (const history_system&) = delete;
50 
51     ~history_system (void) = default;
52 
53     void initialize (bool read_history_file = false);
54 
55     void write_timestamp (void);
56 
57     octave_value input_from_tmp_file (const octave_value_list& args,
58                                       int nargout);
59 
input_from_tmp_file(void)60     bool input_from_tmp_file (void) const
61     {
62       return m_input_from_tmp_file;
63     }
64 
input_from_tmp_file(bool flag)65     bool input_from_tmp_file (bool flag)
66     {
67       return set (m_input_from_tmp_file, flag);
68     }
69 
70     octave_value timestamp_format_string (const octave_value_list& args,
71                                           int nargout);
72 
timestamp_format_string(void)73     std::string timestamp_format_string (void) const
74     {
75       return m_timestamp_format_string;
76     }
77 
timestamp_format_string(const std::string & file)78     std::string timestamp_format_string (const std::string& file)
79     {
80       return set (m_timestamp_format_string, file);
81     }
82 
83     string_vector
84     do_history (const octave_value_list& args = octave_value_list (),
85                 int nargout = 0);
86 
87     void do_edit_history (const octave_value_list& args = octave_value_list ());
88 
89     void do_run_history (const octave_value_list& args = octave_value_list ());
90 
91   private:
92 
93     interpreter& m_interpreter;
94 
95     // TRUE means input is coming from temporary history file.
96     bool m_input_from_tmp_file;
97 
98     // The format of the timestamp marker written to the history file when
99     // Octave exits.
100     std::string m_timestamp_format_string;
101 
102     static std::string default_file (void);
103 
104     static int default_size (void);
105 
106     static std::string default_timestamp_format (void);
107 
108     template <typename T>
set(T & var,const T & new_val)109     T set (T& var, const T& new_val)
110     {
111       T old_val = var;
112       var = new_val;
113       return old_val;
114     }
115   };
116 }
117 
118 #endif
119