GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
defaults.cc
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 1996-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 (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cstdlib>
31 
32 #include <algorithm>
33 #include <string>
34 
35 #include "dir-ops.h"
36 #include "file-ops.h"
37 #include "oct-env.h"
38 
39 #include "defaults.h"
40 #include "defun.h"
41 #include "error.h"
42 #include "file-ops.h"
43 #include "ovl.h"
44 #include "ov.h"
45 #include "variables.h"
46 #include "version.h"
47 
48 #include "default-defs.h"
49 
50 namespace octave
51 {
52  namespace config
53  {
54  // Variables that name directories or files are substituted into source
55  // files with "${prefix}/" stripped from the beginning of the string.
56 
57  // All configure variables of this form should be specified as absolute
58  // directory names. The only ones that should not be absolute here are
59  // ones that have had "${prefix}/" or "${exec_prefix} stripped.
60 
61  static std::string
62  prepend_home_dir (const std::string& hd, const std::string& s)
63  {
64  std::string retval = s;
65 
67 
69  retval = hd + dir_sep_char + s;
70 
71  if (dir_sep_char != '/')
72  std::replace (retval.begin (), retval.end (), '/', dir_sep_char);
73 
74  return retval;
75  }
76 
77  static std::string get_octave_home (void)
78  {
79  std::string op = OCTAVE_PREFIX;
80 
81  std::string oh = sys::env::getenv ("OCTAVE_HOME");
82 
83  // If OCTAVE_HOME is set in the environment, use that. Otherwise,
84  // default to ${prefix} from configure.
85 
86  return oh.empty () ? op : oh;
87  }
88 
89  static std::string get_octave_exec_home (void)
90  {
91  std::string op = OCTAVE_PREFIX;
92  std::string oep = OCTAVE_EXEC_PREFIX;
93 
94  std::string oh = sys::env::getenv ("OCTAVE_HOME");
95  std::string oeh = sys::env::getenv ("OCTAVE_EXEC_HOME");
96 
97  // If OCTAVE_EXEC_HOME is set in the environment, use that.
98  // Otherwise, if ${prefix} and ${exec_prefix} from configure are set
99  // to the same value, use OCTAVE_HOME from the environment if it is set.
100  // Otherwise, default to ${exec_prefix} from configure.
101 
102  if (! oeh.empty ())
103  return oeh;
104 
105  if (op == oep && ! oh.empty ())
106  return oh;
107 
108  return oep;
109  }
110 
111  static std::string get_local_site_defaults_file (void)
112  {
113  std::string lsf = sys::env::getenv ("OCTAVE_SITE_INITFILE");
114 
115  return lsf.empty () ? local_startupfile_dir () + "/octaverc" : lsf;
116  }
117 
118  static std::string get_site_defaults_file (void)
119  {
120  std::string sf = sys::env::getenv ("OCTAVE_VERSION_INITFILE");
121 
122  return sf.empty () ? startupfile_dir () + "/octaverc" : sf;
123  }
124 
125  std::string prepend_octave_home (const std::string& s)
126  {
127  return prepend_home_dir (octave_home (), s);
128  }
129 
130  std::string prepend_octave_exec_home (const std::string& s)
131  {
132  return prepend_home_dir (octave_exec_home (), s);
133  }
134 
135  std::string canonical_host_type (void)
136  {
137  static const std::string s_canonical_host_type
139 
140  return s_canonical_host_type;
141  }
142 
143  std::string release (void)
144  {
145  static const std::string s_octave_release = OCTAVE_RELEASE;
146 
147  return s_octave_release;
148  }
149 
150  std::string default_pager (void)
151  {
152  static const std::string s_default_pager = OCTAVE_DEFAULT_PAGER;
153 
154  return s_default_pager;
155  }
156 
157  std::string octave_home (void)
158  {
159  static const std::string s_octave_home = get_octave_home ();
160 
161  return s_octave_home;
162  }
163 
164  std::string octave_exec_home (void)
165  {
166  static const std::string s_octave_exec_home = get_octave_exec_home ();
167 
168  return s_octave_exec_home;
169  }
170 
171  std::string bin_dir (void)
172  {
173  static const std::string s_bin_dir
175 
176  return s_bin_dir;
177  }
178 
179  std::string data_dir (void)
180  {
181  static const std::string s_data_dir
183 
184  return s_data_dir;
185  }
186 
187  std::string dataroot_dir (void)
188  {
189  static const std::string s_dataroot_dir
191 
192  return s_dataroot_dir;
193  }
194 
195  std::string include_dir (void)
196  {
197  static const std::string s_include_dir
199 
200  return s_include_dir;
201  }
202 
203  std::string lib_dir (void)
204  {
205  static const std::string s_lib_dir
207 
208  return s_lib_dir;
209  }
210 
211  std::string libexec_dir (void)
212  {
213  static const std::string s_libexec_dir
215 
216  return s_libexec_dir;
217  }
218 
219  std::string arch_lib_dir (void)
220  {
221  static const std::string s_arch_lib_dir
223 
224  return s_arch_lib_dir;
225  }
226 
227  std::string info_dir (void)
228  {
229  static const std::string s_info_dir
231 
232  return s_info_dir;
233  }
234 
235  std::string local_ver_arch_lib_dir (void)
236  {
237  static const std::string s_local_ver_arch_lib_dir
239 
240  return s_local_ver_arch_lib_dir;
241  }
242 
243  std::string local_api_arch_lib_dir (void)
244  {
245  static const std::string s_local_api_arch_lib_dir
247 
248  return s_local_api_arch_lib_dir;
249  }
250 
251  std::string local_arch_lib_dir (void)
252  {
253  static const std::string s_local_arch_lib_dir
255 
256  return s_local_arch_lib_dir;
257  }
258 
259  std::string local_ver_oct_file_dir (void)
260  {
261  static const std::string s_local_ver_oct_file_dir
263 
264  return s_local_ver_oct_file_dir;
265  }
266 
267  std::string local_api_oct_file_dir (void)
268  {
269  static const std::string s_local_api_oct_file_dir
271 
272  return s_local_api_oct_file_dir;
273  }
274 
275  std::string local_oct_file_dir (void)
276  {
277  static const std::string s_local_oct_file_dir
279 
280  return s_local_oct_file_dir;
281  }
282 
283  std::string oct_file_dir (void)
284  {
285  static const std::string s_oct_file_dir
287 
288  return s_oct_file_dir;
289  }
290 
291  std::string local_ver_fcn_file_dir (void)
292  {
293  static const std::string s_local_ver_fcn_file_dir
295 
296  return s_local_ver_fcn_file_dir;
297  }
298 
299  std::string local_api_fcn_file_dir (void)
300  {
301  static const std::string s_local_api_fcn_file_dir
303 
304  return s_local_api_fcn_file_dir;
305  }
306 
307  std::string local_fcn_file_dir (void)
308  {
309  static const std::string s_local_fcn_file_dir
311 
312  return s_local_fcn_file_dir;
313  }
314 
315  std::string fcn_file_dir (void)
316  {
317  static const std::string s_fcn_file_dir
319 
320  return s_fcn_file_dir;
321  }
322 
323  std::string oct_data_dir (void)
324  {
325  static const std::string s_oct_data_dir
327 
328  return s_oct_data_dir;
329  }
330 
331  std::string oct_doc_dir (void)
332  {
333  static const std::string s_oct_doc_dir
335 
336  return s_oct_doc_dir;
337  }
338 
339  std::string oct_etc_dir (void)
340  {
341  static const std::string s_oct_etc_dir
343 
344  return s_oct_etc_dir;
345  }
346 
347  std::string oct_fonts_dir (void)
348  {
349  static const std::string s_oct_fonts_dir
351 
352  return s_oct_fonts_dir;
353  }
354 
355  std::string oct_include_dir (void)
356  {
357  static const std::string s_oct_include_dir
359 
360  return s_oct_include_dir;
361  }
362 
363  std::string oct_lib_dir (void)
364  {
365  static const std::string s_oct_lib_dir
367 
368  return s_oct_lib_dir;
369  }
370 
371  std::string oct_locale_dir (void)
372  {
373  static const std::string s_oct_locale_dir
375 
376  return s_oct_locale_dir;
377  }
378 
379  std::string oct_tests_dir (void)
380  {
381  static const std::string s_oct_tests_dir
383 
384  return s_oct_tests_dir;
385  }
386 
387  std::string man_dir (void)
388  {
389  static const std::string s_man_dir
391 
392  return s_man_dir;
393  }
394 
395  std::string man1_dir (void)
396  {
397  static const std::string s_man1_dir
399 
400  return s_man1_dir;
401  }
402 
403  std::string man1_ext (void)
404  {
405  static const std::string s_man1_ext = OCTAVE_MAN1EXT;
406 
407  return s_man1_ext;
408  }
409 
410  std::string image_dir (void)
411  {
412  static const std::string s_image_dir
414 
415  return s_image_dir;
416  }
417 
418  std::string local_startupfile_dir (void)
419  {
420  static const std::string s_local_startupfile_dir
422 
423  return s_local_startupfile_dir;
424  }
425 
426  std::string startupfile_dir (void)
427  {
428  static const std::string s_startupfile_dir
430 
431  return s_startupfile_dir;
432  }
433 
434  std::string local_site_defaults_file (void)
435  {
436  static const std::string s_local_site_defaults_file
438 
439  return s_local_site_defaults_file;
440  }
441 
442  std::string site_defaults_file (void)
443  {
444  static const std::string s_site_defaults_file
446 
447  return s_site_defaults_file;
448  }
449  }
450 }
451 
452 
453 DEFUN (OCTAVE_HOME, args, ,
454  doc: /* -*- texinfo -*-
455 @deftypefn {} {} OCTAVE_HOME ()
456 Return the name of the top-level Octave installation directory.
457 OCTAVE_HOME corresponds to the configuration variable @var{prefix}.
458 @seealso{EXEC_PATH, IMAGE_PATH, OCTAVE_EXEC_HOME}
459 @end deftypefn */)
460 {
461  if (args.length () != 0)
462  print_usage ();
463 
464  return ovl (octave::config::octave_home ());
465 }
466 
467 /*
468 %!assert (ischar (OCTAVE_HOME ()))
469 %!error OCTAVE_HOME (1)
470 */
471 
472 DEFUN (OCTAVE_EXEC_HOME, args, ,
473  doc: /* -*- texinfo -*-
474 @deftypefn {} {} OCTAVE_EXEC_HOME ()
475 Return the name of the top-level Octave installation directory for
476 architecture-dependent files. If not specified separately, the value
477 is the same as OCTAVE_HOME@. OCTAVE_EXEC_HOME corresponds to the
478 configuration variable @var{exec_prefix}.
479 @seealso{EXEC_PATH, IMAGE_PATH, OCTAVE_HOME}
480 @end deftypefn */)
481 {
482  if (args.length () != 0)
483  print_usage ();
484 
486 }
487 
488 /*
489 %!assert (ischar (OCTAVE_EXEC_HOME ()))
490 %!error OCTAVE_EXEC_HOME (1)
491 */
492 
493 DEFUNX ("OCTAVE_VERSION", FOCTAVE_VERSION, args, ,
494  doc: /* -*- texinfo -*-
495 @deftypefn {} {} OCTAVE_VERSION ()
496 Return the version number of Octave as a string.
497 @seealso{ver, version}
498 @end deftypefn */)
499 {
500  if (args.length () != 0)
501  print_usage ();
502 
503  return ovl (OCTAVE_VERSION);
504 }
505 
506 /*
507 %!assert (ischar (OCTAVE_VERSION ()))
508 %!error OCTAVE_VERSION (1)
509 */
static std::string getenv(const std::string &name)
Definition: oct-env.cc:271
static bool absolute_pathname(const std::string &s)
Definition: oct-env.cc:112
#define OCTAVE_OCTLIBDIR
#define OCTAVE_LOCALSTARTUPFILEDIR
#define OCTAVE_LOCALVERFCNFILEDIR
#define OCTAVE_OCTINCLUDEDIR
#define OCTAVE_LOCALAPIOCTFILEDIR
#define OCTAVE_OCTDOCDIR
#define OCTAVE_LIBEXECDIR
#define OCTAVE_LOCALVEROCTFILEDIR
#define OCTAVE_OCTFONTSDIR
#define OCTAVE_OCTETCDIR
#define OCTAVE_OCTDATADIR
#define OCTAVE_OCTLOCALEDIR
#define OCTAVE_FCNFILEDIR
#define OCTAVE_MAN1EXT
#define OCTAVE_LOCALOCTFILEDIR
#define OCTAVE_LIBDIR
#define OCTAVE_MANDIR
#define OCTAVE_LOCALAPIARCHLIBDIR
#define OCTAVE_STARTUPFILEDIR
#define OCTAVE_INFODIR
#define OCTAVE_INCLUDEDIR
#define OCTAVE_OCTTESTSDIR
#define OCTAVE_DEFAULT_PAGER
#define OCTAVE_OCTFILEDIR
#define OCTAVE_LOCALARCHLIBDIR
#define OCTAVE_LOCALVERARCHLIBDIR
#define OCTAVE_IMAGEDIR
#define OCTAVE_LOCALFCNFILEDIR
#define OCTAVE_LOCALAPIFCNFILEDIR
#define OCTAVE_MAN1DIR
#define OCTAVE_DATADIR
#define OCTAVE_DATAROOTDIR
#define OCTAVE_RELEASE
OCTAVE_EXPORT octave_value_list FOCTAVE_VERSION(const octave_value_list &args, int)
Definition: defaults.cc:498
OCTINTERP_API void print_usage(void)
Definition: defun.cc:53
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:56
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
Definition: defun.h:85
#define OCTAVE_BINDIR
Definition: main.in.cc:60
#define OCTAVE_PREFIX
Definition: main.in.cc:64
#define OCTAVE_ARCHLIBDIR
Definition: main.in.cc:56
#define OCTAVE_VERSION
Definition: main.in.cc:52
#define OCTAVE_EXEC_PREFIX
Definition: main.in.cc:68
std::string local_site_defaults_file(void)
Definition: defaults.cc:434
std::string site_defaults_file(void)
Definition: defaults.cc:442
std::string local_ver_oct_file_dir(void)
Definition: defaults.cc:259
std::string local_fcn_file_dir(void)
Definition: defaults.cc:307
std::string octave_exec_home(void)
Definition: defaults.cc:164
std::string oct_data_dir(void)
Definition: defaults.cc:323
std::string oct_doc_dir(void)
Definition: defaults.cc:331
std::string oct_fonts_dir(void)
Definition: defaults.cc:347
std::string dataroot_dir(void)
Definition: defaults.cc:187
std::string image_dir(void)
Definition: defaults.cc:410
std::string default_pager(void)
Definition: defaults.cc:150
std::string canonical_host_type(void)
Definition: defaults.cc:135
std::string octave_home(void)
Definition: defaults.cc:157
std::string startupfile_dir(void)
Definition: defaults.cc:426
std::string local_ver_arch_lib_dir(void)
Definition: defaults.cc:235
std::string oct_file_dir(void)
Definition: defaults.cc:283
std::string local_arch_lib_dir(void)
Definition: defaults.cc:251
std::string arch_lib_dir(void)
Definition: defaults.cc:219
static std::string get_octave_home(void)
Definition: defaults.cc:77
std::string include_dir(void)
Definition: defaults.cc:195
std::string local_oct_file_dir(void)
Definition: defaults.cc:275
std::string info_dir(void)
Definition: defaults.cc:227
static std::string get_site_defaults_file(void)
Definition: defaults.cc:118
std::string local_api_oct_file_dir(void)
Definition: defaults.cc:267
std::string libexec_dir(void)
Definition: defaults.cc:211
std::string oct_lib_dir(void)
Definition: defaults.cc:363
std::string man_dir(void)
Definition: defaults.cc:387
std::string man1_ext(void)
Definition: defaults.cc:403
std::string local_api_arch_lib_dir(void)
Definition: defaults.cc:243
std::string man1_dir(void)
Definition: defaults.cc:395
std::string data_dir(void)
Definition: defaults.cc:179
std::string local_api_fcn_file_dir(void)
Definition: defaults.cc:299
std::string lib_dir(void)
Definition: defaults.cc:203
std::string oct_locale_dir(void)
Definition: defaults.cc:371
static std::string get_local_site_defaults_file(void)
Definition: defaults.cc:111
std::string prepend_octave_home(const std::string &s)
Definition: defaults.cc:125
static std::string get_octave_exec_home(void)
Definition: defaults.cc:89
std::string local_startupfile_dir(void)
Definition: defaults.cc:418
std::string prepend_octave_exec_home(const std::string &s)
Definition: defaults.cc:130
std::string oct_etc_dir(void)
Definition: defaults.cc:339
std::string bin_dir(void)
Definition: defaults.cc:171
std::string oct_include_dir(void)
Definition: defaults.cc:355
std::string fcn_file_dir(void)
Definition: defaults.cc:315
std::string oct_tests_dir(void)
Definition: defaults.cc:379
std::string release(void)
Definition: defaults.cc:143
std::string local_ver_fcn_file_dir(void)
Definition: defaults.cc:291
static std::string prepend_home_dir(const std::string &hd, const std::string &s)
Definition: defaults.cc:62
char dir_sep_char(void)
Definition: file-ops.cc:234
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
Definition: ovl.h:211
static const char dir_sep_char
Definition: shared-fcns.h:84
#define OCTAVE_CANONICAL_HOST_TYPE
Definition: version.in.h:53