GNU Octave  4.4.1
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-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 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <cstdlib>
28 
29 #include <algorithm>
30 #include <iostream>
31 #include <string>
32 
33 #include "dir-ops.h"
34 #include "file-ops.h"
35 #include "oct-env.h"
36 
37 #include "defaults.h"
38 #include "defun.h"
39 #include "error.h"
40 #include "file-ops.h"
41 #include "ovl.h"
42 #include "ov.h"
43 #include "variables.h"
44 #include "version.h"
45 
46 #include "default-defs.h"
47 
48 static bool initialized = false;
49 
52 
59 
64 
69 
74 
83 
85 
89 
91 
94 
97 
98 // Variables that name directories or files are substituted into source
99 // files with "${prefix}/" stripped from the beginning of the string.
100 
101 // All configure variables of this form should be specified as absolute
102 // directory names. The only ones that should not be absolute here are
103 // ones that have had "${prefix}/" or "${exec_prefix} stripped.
104 
105 static std::string
107 {
108  std::string retval = s;
109 
111 
113  retval = hd + dir_sep_char + s;
114 
115  if (dir_sep_char != '/')
116  std::replace (retval.begin (), retval.end (), '/', dir_sep_char);
117 
118  return retval;
119 }
120 
121 static void
123 {
126 
127  std::string oh = octave::sys::env::getenv ("OCTAVE_HOME");
128  std::string oeh = octave::sys::env::getenv ("OCTAVE_EXEC_HOME");
129 
130  // If OCTAVE_HOME is set in the enviornment, use that. Otherwise,
131  // default to ${prefix} from configure.
132 
133  Voctave_home = (oh.empty () ? op : oh);
134 
135  // If OCTAVE_EXEC_HOME is set in the environment, use that.
136  // Otherwise, if ${prefix} and ${exec_prefix} from configure are set
137  // to the same value, use OCTAVE_HOME from the environment if it is set.
138  // Othewise, default to ${exec_prefix} from configure.
139 
140  if (! oeh.empty ())
141  Voctave_exec_home = oeh;
142  else
143  {
144  if (op == oep && ! oh.empty ())
145  Voctave_exec_home = oh;
146  else
147  Voctave_exec_home = oep;
148  }
149 }
150 
151 static void
153 {
154  std::string lsf = octave::sys::env::getenv ("OCTAVE_SITE_INITFILE");
155 
156  if (lsf.empty ())
158  else
160 }
161 
162 static void
164 {
165  std::string sf = octave::sys::env::getenv ("OCTAVE_VERSION_INITFILE");
166 
167  if (sf.empty ())
168  Vsite_defaults_file = Vstartupfile_dir + "/octaverc";
169  else
170  Vsite_defaults_file = sf;
171 }
172 
173 static void
175 {
176  if (initialized)
177  return;
178 
179  // OCTAVE_HOME must be set first!
180 
181  set_octave_home ();
182 
189 
197 
205 
213 
222 
224 
228 
230 
235 
237 
239 
240  initialized = true;
241 }
242 
243 #define RETURN(VAR) \
244  if (! initialized) \
245  init_defaults (); \
246  return VAR;
247 
248 namespace octave
249 {
250  namespace config
251  {
254  {
255  return prepend_home_dir (Voctave_home, s);
256  }
257 
260  {
262  }
263 
265 
266  std::string release (void) { return OCTAVE_RELEASE; }
267 
269 
272 
281 
285 
290 
295 
304 
308 
310 
313 
316  }
317 }
318 
319 #undef RETURN
320 
321 DEFUN (OCTAVE_HOME, args, ,
322  doc: /* -*- texinfo -*-
323 @deftypefn {} {} OCTAVE_HOME ()
324 Return the name of the top-level Octave installation directory.
325 OCTAVE_HOME corresponds to the configuration variable @var{prefix}.
326 @seealso{EXEC_PATH, IMAGE_PATH, OCTAVE_EXEC_HOME}
327 @end deftypefn */)
328 {
329  if (args.length () != 0)
330  print_usage ();
331 
332  return ovl (octave::config::octave_home ());
333 }
334 
335 /*
336 %!assert (ischar (OCTAVE_HOME ()))
337 %!error OCTAVE_HOME (1)
338 */
339 
340 DEFUN (OCTAVE_EXEC_HOME, args, ,
341  doc: /* -*- texinfo -*-
342 @deftypefn {} {} OCTAVE_EXEC_HOME ()
343 Return the name of the top-level Octave installation directory for
344 architecture-dependent files. If not specified separately, the value
345 is the same as OCTAVE_HOME@. OCTAVE_EXEC_HOME corresponds to the
346 configuration variable @var{exec_prefix}.
347 @seealso{EXEC_PATH, IMAGE_PATH, OCTAVE_HOME}
348 @end deftypefn */)
349 {
350  if (args.length () != 0)
351  print_usage ();
352 
354 }
355 
356 /*
357 %!assert (ischar (OCTAVE_EXEC_HOME ()))
358 %!error OCTAVE_EXEC_HOME (1)
359 */
360 
361 DEFUNX ("OCTAVE_VERSION", FOCTAVE_VERSION, args, ,
362  doc: /* -*- texinfo -*-
363 @deftypefn {} {} OCTAVE_VERSION ()
364 Return the version number of Octave as a string.
365 @seealso{ver, version}
366 @end deftypefn */)
367 {
368  if (args.length () != 0)
369  print_usage ();
370 
371  return ovl (OCTAVE_VERSION);
372 }
373 
374 /*
375 %!assert (ischar (OCTAVE_VERSION ()))
376 %!error OCTAVE_VERSION (1)
377 */
std::string local_fcn_file_dir(void)
Definition: defaults.cc:293
std::string oct_fonts_dir(void)
Definition: defaults.cc:299
std::string info_dir(void)
Definition: defaults.cc:280
static std::string Vsite_defaults_file
Definition: defaults.cc:96
std::string oct_doc_dir(void)
Definition: defaults.cc:297
#define OCTAVE_OCTINCLUDEDIR
#define OCTAVE_ARCHLIBDIR
Definition: main.in.cc:52
static std::string Vlocal_oct_file_dir
Definition: defaults.cc:67
#define OCTAVE_LOCALAPIOCTFILEDIR
std::string oct_etc_dir(void)
Definition: defaults.cc:298
#define OCTAVE_MANDIR
std::string prepend_octave_exec_home(const std::string &s)
Definition: defaults.cc:259
#define OCTAVE_LOCALAPIARCHLIBDIR
static std::string Vlocal_fcn_file_dir
Definition: defaults.cc:72
static std::string Vstartupfile_dir
Definition: defaults.cc:93
OCTINTERP_API void print_usage(void)
Definition: defun.cc:54
static std::string Vlocal_ver_fcn_file_dir
Definition: defaults.cc:70
static std::string Vman1_dir
Definition: defaults.cc:87
#define OCTAVE_OCTFONTSDIR
#define OCTAVE_OCTLIBDIR
static std::string Vinclude_dir
Definition: defaults.cc:56
static std::string Voct_tests_dir
Definition: defaults.cc:82
static std::string Voctave_exec_home
Definition: defaults.cc:51
static std::string Vman_dir
Definition: defaults.cc:86
#define OCTAVE_EXEC_PREFIX
Definition: main.in.cc:64
static std::string Vlocal_api_arch_lib_dir
Definition: defaults.cc:61
std::string lib_dir(void)
Definition: defaults.cc:277
static std::string Vdata_dir
Definition: defaults.cc:54
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
Definition: defun.h:53
std::string oct_lib_dir(void)
Definition: defaults.cc:301
#define OCTAVE_STARTUPFILEDIR
std::string man_dir(void)
Definition: defaults.cc:305
std::string octave_exec_home(void)
Definition: defaults.cc:271
static std::string Vfcn_file_dir
Definition: defaults.cc:73
std::string man1_dir(void)
Definition: defaults.cc:306
char dir_sep_char(void)
Definition: file-ops.cc:224
std::string data_dir(void)
Definition: defaults.cc:274
static void init_defaults(void)
Definition: defaults.cc:174
#define OCTAVE_INFODIR
#define OCTAVE_LIBDIR
#define OCTAVE_LOCALSTARTUPFILEDIR
s
Definition: file-io.cc:2729
static std::string Vman1_ext
Definition: defaults.cc:88
std::string fcn_file_dir(void)
Definition: defaults.cc:294
static std::string Voct_data_dir
Definition: defaults.cc:75
static std::string getenv(const std::string &name)
Definition: oct-env.cc:235
#define OCTAVE_DATADIR
#define OCTAVE_VERSION
Definition: main.in.cc:48
std::string man1_ext(void)
Definition: defaults.cc:307
std::string bin_dir(void)
Definition: defaults.cc:273
#define OCTAVE_OCTETCDIR
std::string startupfile_dir(void)
Definition: defaults.cc:312
std::string local_site_defaults_file(void)
Definition: defaults.cc:314
std::string dataroot_dir(void)
Definition: defaults.cc:275
#define OCTAVE_BINDIR
Definition: main.in.cc:56
std::string oct_locale_dir(void)
Definition: defaults.cc:302
std::string prepend_octave_home(const std::string &s)
Definition: defaults.cc:253
#define OCTAVE_OCTDOCDIR
static std::string Vlib_dir
Definition: defaults.cc:57
static std::string Vlocal_arch_lib_dir
Definition: defaults.cc:62
std::string local_ver_fcn_file_dir(void)
Definition: defaults.cc:291
#define OCTAVE_LOCALFCNFILEDIR
std::string arch_lib_dir(void)
Definition: defaults.cc:279
#define OCTAVE_LOCALAPIFCNFILEDIR
static std::string Vlocal_api_fcn_file_dir
Definition: defaults.cc:71
#define OCTAVE_OCTFILEDIR
std::string local_api_arch_lib_dir(void)
Definition: defaults.cc:283
static std::string Vlocal_startupfile_dir
Definition: defaults.cc:92
std::string octave_home(void)
Definition: defaults.cc:270
std::string canonical_host_type(void)
Definition: defaults.cc:264
static std::string Vinfo_dir
Definition: defaults.cc:84
static std::string Vbin_dir
Definition: defaults.cc:53
static std::string Voct_fonts_dir
Definition: defaults.cc:78
static std::string Voctave_home
Definition: defaults.cc:50
std::string default_pager(void)
Definition: defaults.cc:268
std::string local_api_fcn_file_dir(void)
Definition: defaults.cc:292
static std::string Vlibexec_dir
Definition: defaults.cc:58
std::string local_oct_file_dir(void)
Definition: defaults.cc:288
#define OCTAVE_DATAROOTDIR
#define OCTAVE_OCTLOCALEDIR
std::string image_dir(void)
Definition: defaults.cc:309
std::string libexec_dir(void)
Definition: defaults.cc:278
static bool absolute_pathname(const std::string &s)
Definition: oct-env.cc:108
#define OCTAVE_FCNFILEDIR
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
Definition: defun.h:82
static std::string Voct_doc_dir
Definition: defaults.cc:76
static std::string Vlocal_ver_arch_lib_dir
Definition: defaults.cc:60
octave_value retval
Definition: data.cc:6246
static void set_site_defaults_file(void)
Definition: defaults.cc:163
static std::string Vlocal_site_defaults_file
Definition: defaults.cc:95
static const char dir_sep_char
Definition: shared-fcns.h:81
static std::string prepend_home_dir(const std::string &hd, const std::string &s)
Definition: defaults.cc:106
#define OCTAVE_DEFAULT_PAGER
std::string release(void)
Definition: defaults.cc:266
#define OCTAVE_LOCALVERARCHLIBDIR
#define OCTAVE_LOCALVERFCNFILEDIR
static bool initialized
Definition: defaults.cc:48
std::string oct_file_dir(void)
Definition: defaults.cc:289
std::string local_arch_lib_dir(void)
Definition: defaults.cc:284
std::string local_api_oct_file_dir(void)
Definition: defaults.cc:287
static std::string Vlocal_ver_oct_file_dir
Definition: defaults.cc:65
#define OCTAVE_MAN1DIR
#define OCTAVE_LOCALOCTFILEDIR
static void set_octave_home(void)
Definition: defaults.cc:122
std::string local_ver_oct_file_dir(void)
Definition: defaults.cc:286
static std::string Voct_file_dir
Definition: defaults.cc:68
OCTAVE_EXPORT octave_value_list OCTAVE_EXEC_HOME nd deftypefn *return ovl(octave::config::octave_home())
static std::string Voct_include_dir
Definition: defaults.cc:79
#define RETURN(VAR)
Definition: defaults.cc:243
#define OCTAVE_CANONICAL_HOST_TYPE
#define OCTAVE_LOCALARCHLIBDIR
#define OCTAVE_RELEASE
static void set_local_site_defaults_file(void)
Definition: defaults.cc:152
std::string include_dir(void)
Definition: defaults.cc:276
std::string oct_include_dir(void)
Definition: defaults.cc:300
static std::string Vdataroot_dir
Definition: defaults.cc:55
static std::string Voct_etc_dir
Definition: defaults.cc:77
#define OCTAVE_OCTDATADIR
std::string site_defaults_file(void)
Definition: defaults.cc:315
std::string oct_tests_dir(void)
Definition: defaults.cc:303
static std::string Voct_lib_dir
Definition: defaults.cc:80
#define OCTAVE_MAN1EXT
#define OCTAVE_INCLUDEDIR
#define OCTAVE_PREFIX
Definition: main.in.cc:60
std::string local_ver_arch_lib_dir(void)
Definition: defaults.cc:282
#define OCTAVE_LOCALVEROCTFILEDIR
static std::string Varch_lib_dir
Definition: defaults.cc:63
#define OCTAVE_LIBEXECDIR
#define OCTAVE_IMAGEDIR
static std::string Voct_locale_dir
Definition: defaults.cc:81
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
std::string oct_data_dir(void)
Definition: defaults.cc:296
std::string local_startupfile_dir(void)
Definition: defaults.cc:311
static std::string Vimage_dir
Definition: defaults.cc:90
#define OCTAVE_OCTTESTSDIR
static std::string Vlocal_api_oct_file_dir
Definition: defaults.cc:66