GNU Octave  4.2.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
octave.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2002-2017 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 the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any 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, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if ! defined (octave_octave_h)
24 #define octave_octave_h 1
25 
26 #include "octave-config.h"
27 
28 #if defined (__cplusplus)
29 
30 #include <list>
31 #include <string>
32 
33 #include <str-vec.h>
34 
35 namespace octave
36 {
37  // Command line arguments. See also options-usage.h.
38 
39  class OCTINTERP_API cmdline_options
40  {
41  public:
42 
43  cmdline_options (void);
44 
45  cmdline_options (int argc, char **argv);
46 
47  cmdline_options (const cmdline_options& opts);
48 
49  cmdline_options& operator = (const cmdline_options& opts);
50 
51  bool force_gui (void) const { return m_force_gui; }
52  bool forced_interactive (void) const { return m_forced_interactive; }
53  bool forced_line_editing (void) const { return m_forced_line_editing; }
54  bool inhibit_startup_message (void) const { return m_inhibit_startup_message; }
55  bool line_editing (void) const { return m_line_editing; }
56  bool no_gui (void) const { return m_no_gui; }
57  bool no_window_system (void) const { return m_no_window_system; }
58  bool persist (void) const { return m_persist; }
59  bool read_history_file (void) const { return m_read_history_file; }
60  bool read_init_files (void) const { return m_read_init_files; }
61  bool read_site_files (void) const { return m_read_site_files; }
62  bool set_initial_path (void) const { return m_set_initial_path; }
63  bool traditional (void) const { return m_traditional; }
64  bool verbose_flag (void) const { return m_verbose_flag; }
65  std::string code_to_eval (void) const { return m_code_to_eval; }
66  std::list<std::string> command_line_path (void) const { return m_command_line_path; }
67  std::string exec_path (void) const { return m_exec_path; }
68  std::string image_path (void) const { return m_image_path; }
69  string_vector all_args (void) const { return m_all_args; }
70  string_vector remaining_args (void) const { return m_remaining_args; }
71 
72  void force_gui (bool arg) { m_force_gui = arg; }
73  void forced_line_editing (bool arg) { m_forced_line_editing = arg; }
74  void forced_interactive (bool arg) { m_forced_interactive = arg; }
75  void inhibit_startup_message (bool arg) { m_inhibit_startup_message = arg; }
76  void line_editing (bool arg) { m_line_editing = arg; }
77  void no_gui (bool arg) { m_no_gui = arg; }
78  void no_window_system (bool arg) { m_no_window_system = arg; }
79  void persist (bool arg) { m_persist = arg; }
80  void read_history_file (bool arg) { m_read_history_file = arg; }
81  void read_init_files (bool arg) { m_read_init_files = arg; }
82  void read_site_files (bool arg) { m_read_site_files = arg; }
83  void set_initial_path (bool arg) { m_set_initial_path = arg; }
84  void traditional (bool arg) { m_traditional = arg; }
85  void verbose_flag (bool arg) { m_verbose_flag = arg; }
86  void code_to_eval (const std::string& arg) { m_code_to_eval = arg; }
87  void command_line_path (const std::list<std::string>& arg) { m_command_line_path = arg; }
88  void exec_path (const std::string& arg) { m_exec_path = arg; }
89  void image_path (const std::string& arg) { m_image_path = arg; }
90  void all_args (const string_vector& arg) { m_all_args = arg; }
91  void remaining_args (const string_vector& arg) { m_remaining_args = arg; }
92 
93  private:
94 
95  // If TRUE, force the GUI to start.
96  // (--force-gui)
97  bool m_force_gui = false;
98 
99  // TRUE means the user forced this shell to be interactive.
100  // (--interactive, -i)
101  bool m_forced_interactive = false;
102 
103  // If TRUE, force readline command line editing.
104  // (--line-editing)
105  bool m_forced_line_editing = false;
106 
107  // TRUE means we don't print the usual startup message.
108  // (--quiet; --silent; -q)
109  bool m_inhibit_startup_message = false;
110 
111  // TRUE means we are using readline.
112  // (--no-line-editing)
113  bool m_line_editing = true;
114 
115  // If TRUE don't start the GUI.
116  // (--no-gui)
117  bool m_no_gui = false;
118 
119  // If TRUE, ignore the window system even if it is available.
120  // (--no-window-system, -W)
121  bool m_no_window_system = false;
122 
123  // If TRUE, don't exit after evaluating code given by --eval option.
124  // (--persist)
125  bool m_persist = false;
126 
127  // If TRUE, initialize history list from saved history file.
128  // (--no-history; -H)
129  bool m_read_history_file = true;
130 
131  // TRUE means we read ~/.octaverc and ./.octaverc.
132  // (--norc; --no-init-file; -f)
133  bool m_read_init_files = true;
134 
135  // TRUE means we read the site-wide octaverc files.
136  // (--norc; --no-site-file; -f)
137  bool m_read_site_files = true;
138 
139  // TRUE means we set the initial path to configured defaults.
140  // (--no-init-path)
141  bool m_set_initial_path = true;
142 
143  // If TRUE use traditional (maximally MATLAB compatible) settings
144  // (--traditional)
145  bool m_traditional = false;
146 
147  // If TRUE, print verbose info in some cases.
148  // (--verbose; -V)
149  bool m_verbose_flag = false;
150 
151  // The code to evaluate at startup
152  // (--eval CODE)
153  std::string m_code_to_eval;
154 
155  // The value of "path" specified on the command line.
156  // (--path; -p)
157  std::list<std::string> m_command_line_path;
158 
159  // The value for "EXEC_PATH" specified on the command line.
160  // (--exec-path)
161  std::string m_exec_path;
162 
163  // The value for "IMAGE_PATH" specified on the command line.
164  // (--image-path)
165  std::string m_image_path;
166 
167  // All arguments passed to the argc, argv constructor.
168  string_vector m_all_args;
169 
170  // Arguments remaining after parsing.
171  string_vector m_remaining_args;
172  };
173 
174  // The application object contains a pointer to the current
175  // interpreter and the interpreter contains a pointer back to the
176  // application context so we need a forward declaration for one (or
177  // both) of them...
178 
179  class interpreter;
180 
181  // Base class for an Octave application.
182 
184  {
185  public:
186 
187  application (const cmdline_options& opts = cmdline_options ());
188 
189  application (int argc, char **argv);
190 
191  virtual ~application (void);
192 
193  void set_program_names (const std::string& pname);
194 
195  void intern_argv (const string_vector& args);
196 
197  cmdline_options options (void) const { return m_options; }
198 
199  bool have_script_file (void) const { return m_have_script_file; }
200 
201  bool is_octave_program (void) const { return m_is_octave_program; }
202 
203  virtual void create_interpreter (void);
204 
205  virtual int execute_interpreter (void);
206 
207  virtual int execute (void) = 0;
208 
209  virtual bool gui_running (void) const { return false; }
210  virtual void gui_running (bool) { }
211 
212  void program_invocation_name (const std::string& nm) { m_program_invocation_name = nm; }
213 
214  void program_name (const std::string& nm) { m_program_name = nm; }
215 
216  void forced_interactive (bool arg) { m_options.forced_interactive (arg); }
217 
218  void interactive (bool arg);
219 
220  // Should be an error if instance is 0.
221  static application *app (void) { return instance; }
222 
223  static std::string program_invocation_name (void) { return instance->m_program_invocation_name; }
224 
225  static std::string program_name (void) { return instance->m_program_name; }
226 
227  static string_vector argv (void) { return instance->m_argv; }
228 
229  static bool is_gui_running (void) { return instance->gui_running (); }
230 
231  static interpreter *the_interpreter (void) { return instance->m_interpreter; }
232 
233  // Convenience functions.
234 
235  static bool forced_interactive (void);
236  static bool interactive (void);
237 
238  private:
239 
240  // No copying, at least not yet...
241 
242  application (const application&);
243 
244  application& operator = (const application&);
245 
246  // The application instance; There should be only one.
247  static application *instance;
248 
249  void init (void);
250 
251  protected:
252 
253  // The name used to invoke Octave.
254  std::string m_program_invocation_name;
255 
256  // The last component of octave_program_invocation_name.
257  std::string m_program_name;
258 
259  // The current argument vector (may change if we are running a
260  // script with --persist because after the script is done, the
261  // arguments revert to the full list given to the octave
262  // interpreter at startup.
263  string_vector m_argv;
264 
265  cmdline_options m_options;
266 
267  // TRUE if there is a command line argument that looks like the
268  // name of a file to execute.
269  bool m_have_script_file = false;
270 
271  // TRUE if this is a program and no interpreter and interaction is
272  // needed. For example, an octave program with shebang line, or code
273  // from eval without persist.
274  bool m_is_octave_program = false;
275 
276  // If TRUE, the GUI should be started.
277  bool m_gui_running = false;
278 
279  interpreter *m_interpreter = 0;
280  };
281 
282  class OCTINTERP_API cli_application : public application
283  {
284  public:
285 
286  cli_application (const cmdline_options& opts = cmdline_options ())
287  : application (opts)
288  { }
289 
290  cli_application (int argc, char **argv)
291  : application (argc, argv)
292  { }
293 
294  ~cli_application (void) { }
295 
296  int execute (void);
297 
298  private:
299 
300  // No copying, at least not yet...
301 
302  cli_application (const cli_application&);
303 
304  cli_application& operator = (const cli_application&);
305  };
306 
307  class OCTINTERP_API embedded_application : public application
308  {
309  public:
310 
311  embedded_application (const cmdline_options& opts = cmdline_options ())
312  : application (opts)
313  { }
314 
315  embedded_application (int argc, char **argv)
316  : application (argc, argv)
317  { }
318 
319  ~embedded_application (void) { }
320 
321  void create_interpreter (void);
322 
323  int execute (void);
324 
325  private:
326 
327  // No copying, at least not yet...
328 
329  embedded_application (const embedded_application&);
330 
331  embedded_application& operator = (const embedded_application&);
332  };
333 }
334 
335 #endif
336 
337 #if defined (__cplusplus)
338 extern "C" {
339 #endif
340 
341 extern OCTINTERP_API int octave_main (int argc, char **argv, int embedded);
342 
343 #if defined (__cplusplus)
344 }
345 #endif
346 
347 #endif
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
int argc
Definition: load-save.cc:633
OCTINTERP_API int octave_main(int argc, char **argv, int embedded)
Definition: octave.cc:446
octave_value arg
Definition: pr-output.cc:3440
string_vector argv
Definition: load-save.cc:635
JNIEnv void * args
Definition: ov-java.cc:67
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
#define OCTINTERP_API
Definition: mexproto.h:69
std::string pname
Definition: graphics.cc:11207
OCTAVE_EXPORT octave_value_list only variables visible in the local scope are displayed The following are valid options
Definition: variables.cc:1859
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:854