2203
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2203
|
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 2, or (at your option) any |
|
10 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, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
2203
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <cstdlib> |
|
29 |
3503
|
30 #include <iostream> |
2203
|
31 #include <string> |
|
32 |
|
33 #ifdef HAVE_UNISTD_H |
2442
|
34 #ifdef HAVE_SYS_TYPES_H |
2203
|
35 #include <sys/types.h> |
2442
|
36 #endif |
2203
|
37 #include <unistd.h> |
|
38 #endif |
|
39 |
5814
|
40 #include "dir-ops.h" |
2926
|
41 #include "oct-env.h" |
4217
|
42 #include "file-stat.h" |
3174
|
43 #include "pathsearch.h" |
4217
|
44 #include "str-vec.h" |
2926
|
45 |
2492
|
46 #include <defaults.h> |
2203
|
47 #include "defun.h" |
|
48 #include "error.h" |
3040
|
49 #include "file-ops.h" |
2203
|
50 #include "gripes.h" |
|
51 #include "help.h" |
5395
|
52 #include "input.h" |
5832
|
53 #include "load-path.h" |
3185
|
54 #include "oct-obj.h" |
2390
|
55 #include "ov.h" |
4217
|
56 #include "parse.h" |
2203
|
57 #include "toplev.h" |
4217
|
58 #include "unwind-prot.h" |
2203
|
59 #include "variables.h" |
2492
|
60 #include <version.h> |
2203
|
61 |
3523
|
62 std::string Voctave_home; |
2203
|
63 |
3523
|
64 std::string Vbin_dir; |
|
65 std::string Vinfo_dir; |
|
66 std::string Vdata_dir; |
|
67 std::string Vlibexec_dir; |
|
68 std::string Varch_lib_dir; |
|
69 std::string Vlocal_arch_lib_dir; |
5909
|
70 std::string Vlocal_api_arch_lib_dir; |
3597
|
71 std::string Vlocal_ver_arch_lib_dir; |
5814
|
72 |
|
73 std::string Vlocal_ver_oct_file_dir; |
|
74 std::string Vlocal_api_oct_file_dir; |
|
75 std::string Vlocal_oct_file_dir; |
2203
|
76 |
5814
|
77 std::string Vlocal_ver_fcn_file_dir; |
|
78 std::string Vlocal_api_fcn_file_dir; |
|
79 std::string Vlocal_fcn_file_dir; |
|
80 |
|
81 std::string Voct_file_dir; |
|
82 std::string Vfcn_file_dir; |
|
83 |
|
84 std::string Vimage_dir; |
4447
|
85 |
2203
|
86 // The path that will be searched for programs that we execute. |
|
87 // (--exec-path path) |
5794
|
88 static std::string VEXEC_PATH; |
2203
|
89 |
|
90 // Name of the editor to be invoked by the edit_history command. |
5794
|
91 std::string VEDITOR; |
2203
|
92 |
5814
|
93 static std::string VIMAGE_PATH; |
2203
|
94 |
3523
|
95 std::string Vlocal_site_defaults_file; |
|
96 std::string Vsite_defaults_file; |
2203
|
97 |
4776
|
98 // Name of the FFTW wisdom program. |
5794
|
99 std::string Vfftw_wisdom_program; |
4773
|
100 |
3535
|
101 static std::string |
3523
|
102 subst_octave_home (const std::string& s) |
2203
|
103 { |
3523
|
104 std::string retval; |
2203
|
105 |
3523
|
106 std::string prefix = OCTAVE_PREFIX; |
2203
|
107 |
|
108 retval = s; |
|
109 |
|
110 if (Voctave_home != prefix) |
|
111 { |
5275
|
112 octave_idx_type len = prefix.length (); |
2203
|
113 size_t start = 0; |
2522
|
114 while ((start = retval.find (prefix, start)) != NPOS) |
2203
|
115 { |
|
116 retval.replace (start, len, Voctave_home); |
2522
|
117 start += len; |
2203
|
118 } |
|
119 } |
|
120 |
|
121 return retval; |
|
122 } |
|
123 |
|
124 static void |
|
125 set_octave_home (void) |
|
126 { |
3523
|
127 std::string oh = octave_env::getenv ("OCTAVE_HOME"); |
2203
|
128 |
3523
|
129 Voctave_home = oh.empty () ? std::string (OCTAVE_PREFIX) : oh; |
2203
|
130 } |
|
131 |
|
132 static void |
|
133 set_default_info_dir (void) |
|
134 { |
|
135 Vinfo_dir = subst_octave_home (OCTAVE_INFODIR); |
|
136 } |
|
137 |
|
138 static void |
3141
|
139 set_default_data_dir (void) |
|
140 { |
|
141 Vdata_dir = subst_octave_home (OCTAVE_DATADIR); |
|
142 } |
|
143 |
|
144 static void |
|
145 set_default_libexec_dir (void) |
|
146 { |
|
147 Vlibexec_dir = subst_octave_home (OCTAVE_LIBEXECDIR); |
|
148 } |
|
149 |
|
150 static void |
2203
|
151 set_default_arch_lib_dir (void) |
|
152 { |
|
153 Varch_lib_dir = subst_octave_home (OCTAVE_ARCHLIBDIR); |
|
154 } |
|
155 |
|
156 static void |
2439
|
157 set_default_local_arch_lib_dir (void) |
|
158 { |
|
159 Vlocal_arch_lib_dir = subst_octave_home (OCTAVE_LOCALARCHLIBDIR); |
|
160 } |
|
161 |
|
162 static void |
5909
|
163 set_default_local_api_arch_lib_dir (void) |
|
164 { |
|
165 Vlocal_api_arch_lib_dir = subst_octave_home (OCTAVE_LOCALAPIARCHLIBDIR); |
|
166 } |
|
167 |
|
168 static void |
3597
|
169 set_default_local_ver_arch_lib_dir (void) |
|
170 { |
|
171 Vlocal_ver_arch_lib_dir = subst_octave_home (OCTAVE_LOCALVERARCHLIBDIR); |
|
172 } |
|
173 |
|
174 static void |
5814
|
175 set_default_local_ver_oct_file_dir (void) |
|
176 { |
|
177 Vlocal_ver_oct_file_dir = subst_octave_home (OCTAVE_LOCALVEROCTFILEDIR); |
|
178 } |
|
179 |
|
180 static void |
|
181 set_default_local_api_oct_file_dir (void) |
|
182 { |
|
183 Vlocal_api_oct_file_dir = subst_octave_home (OCTAVE_LOCALAPIOCTFILEDIR); |
|
184 } |
|
185 |
|
186 static void |
|
187 set_default_local_oct_file_dir (void) |
|
188 { |
|
189 Vlocal_oct_file_dir = subst_octave_home (OCTAVE_LOCALOCTFILEDIR); |
|
190 } |
|
191 |
|
192 static void |
|
193 set_default_local_ver_fcn_file_dir (void) |
|
194 { |
|
195 Vlocal_ver_fcn_file_dir = subst_octave_home (OCTAVE_LOCALVERFCNFILEDIR); |
|
196 } |
|
197 |
|
198 static void |
|
199 set_default_local_api_fcn_file_dir (void) |
|
200 { |
|
201 Vlocal_api_fcn_file_dir = subst_octave_home (OCTAVE_LOCALAPIFCNFILEDIR); |
|
202 } |
|
203 |
|
204 static void |
|
205 set_default_local_fcn_file_dir (void) |
|
206 { |
|
207 Vlocal_fcn_file_dir = subst_octave_home (OCTAVE_LOCALFCNFILEDIR); |
|
208 } |
|
209 |
|
210 static void |
2203
|
211 set_default_fcn_file_dir (void) |
|
212 { |
|
213 Vfcn_file_dir = subst_octave_home (OCTAVE_FCNFILEDIR); |
|
214 } |
|
215 |
|
216 static void |
5814
|
217 set_default_image_dir (void) |
|
218 { |
|
219 Vimage_dir = subst_octave_home (OCTAVE_IMAGEDIR); |
|
220 } |
|
221 |
|
222 static void |
5397
|
223 set_default_oct_file_dir (void) |
|
224 { |
|
225 Voct_file_dir = subst_octave_home (OCTAVE_OCTFILEDIR); |
|
226 } |
|
227 |
|
228 static void |
2203
|
229 set_default_bin_dir (void) |
|
230 { |
|
231 Vbin_dir = subst_octave_home (OCTAVE_BINDIR); |
|
232 } |
|
233 |
5814
|
234 void |
|
235 set_exec_path (const std::string& path) |
4447
|
236 { |
5814
|
237 VEXEC_PATH = Vlocal_ver_arch_lib_dir + dir_path::path_sep_str |
5909
|
238 + Vlocal_api_arch_lib_dir + dir_path::path_sep_str |
5777
|
239 + Vlocal_arch_lib_dir + dir_path::path_sep_str |
|
240 + Varch_lib_dir + dir_path::path_sep_str |
4447
|
241 + Vbin_dir; |
5814
|
242 |
|
243 // This is static so that even if set_exec_path is called more than |
|
244 // once, shell_path is the original PATH from the environment, |
|
245 // before we start modifying it. |
|
246 static std::string shell_path = octave_env::getenv ("PATH"); |
|
247 |
|
248 if (! shell_path.empty ()) |
|
249 VEXEC_PATH += dir_path::path_sep_str + shell_path; |
|
250 |
|
251 std::string tpath = path; |
|
252 |
|
253 if (tpath.empty ()) |
|
254 tpath = octave_env::getenv ("OCTAVE_EXEC_PATH"); |
|
255 |
|
256 if (! tpath.empty ()) |
|
257 VEXEC_PATH = tpath + dir_path::path_sep_str + VEXEC_PATH; |
|
258 |
|
259 octave_env::putenv ("PATH", VEXEC_PATH); |
|
260 } |
|
261 |
|
262 void |
|
263 set_image_path (const std::string& path) |
|
264 { |
|
265 VIMAGE_PATH = "."; |
|
266 |
|
267 std::string tpath = path; |
|
268 |
|
269 if (tpath.empty ()) |
|
270 tpath = octave_env::getenv ("OCTAVE_IMAGE_PATH"); |
|
271 |
|
272 if (! tpath.empty ()) |
|
273 VIMAGE_PATH += dir_path::path_sep_str + tpath; |
|
274 |
5832
|
275 tpath = genpath (Vimage_dir, ""); |
|
276 |
|
277 if (! tpath.empty ()) |
|
278 VIMAGE_PATH += dir_path::path_sep_str + tpath; |
5814
|
279 } |
|
280 |
2203
|
281 static void |
|
282 set_default_info_file (void) |
|
283 { |
3523
|
284 std::string std_info_file = subst_octave_home (OCTAVE_INFOFILE); |
2512
|
285 |
3523
|
286 std::string oct_info_file = octave_env::getenv ("OCTAVE_INFO_FILE"); |
2203
|
287 |
2926
|
288 Vinfo_file = oct_info_file.empty () ? std_info_file : oct_info_file; |
2203
|
289 } |
|
290 |
|
291 static void |
|
292 set_default_info_prog (void) |
|
293 { |
3523
|
294 std::string oct_info_prog = octave_env::getenv ("OCTAVE_INFO_PROGRAM"); |
2203
|
295 |
2926
|
296 if (oct_info_prog.empty ()) |
5794
|
297 Vinfo_program = "info"; |
2926
|
298 else |
5794
|
299 Vinfo_program = std::string (oct_info_prog); |
2203
|
300 } |
|
301 |
4773
|
302 static void |
4776
|
303 set_default_fftw_wisdom_prog (void) |
4773
|
304 { |
4776
|
305 std::string oct_wisdom_prog = octave_env::getenv ("OCTAVE_FFTW_WISDOM_PROGRAM"); |
4773
|
306 |
|
307 if (oct_wisdom_prog.empty ()) |
5794
|
308 Vfftw_wisdom_program = "fftw-wisdom"; |
4773
|
309 else |
5794
|
310 Vfftw_wisdom_program = std::string (oct_wisdom_prog); |
4773
|
311 } |
|
312 |
2203
|
313 static void |
|
314 set_default_editor (void) |
|
315 { |
5794
|
316 VEDITOR = "emacs"; |
2203
|
317 |
3523
|
318 std::string env_editor = octave_env::getenv ("EDITOR"); |
2203
|
319 |
2926
|
320 if (! env_editor.empty ()) |
5794
|
321 VEDITOR = env_editor; |
2203
|
322 } |
|
323 |
|
324 static void |
|
325 set_local_site_defaults_file (void) |
|
326 { |
5781
|
327 std::string lsf = octave_env::getenv ("OCTAVE_LOCAL_SITE_INITFILE"); |
|
328 |
|
329 if (lsf.empty ()) |
|
330 { |
|
331 Vlocal_site_defaults_file = subst_octave_home (OCTAVE_LOCALSTARTUPFILEDIR); |
|
332 Vlocal_site_defaults_file.append ("/octaverc"); |
|
333 } |
|
334 else |
|
335 Vlocal_site_defaults_file = lsf; |
2203
|
336 } |
|
337 |
|
338 static void |
|
339 set_site_defaults_file (void) |
|
340 { |
5781
|
341 std::string sf = octave_env::getenv ("OCTAVE_SITE_INITFILE"); |
|
342 |
|
343 if (sf.empty ()) |
|
344 { |
|
345 Vsite_defaults_file = subst_octave_home (OCTAVE_STARTUPFILEDIR); |
|
346 Vsite_defaults_file.append ("/octaverc"); |
|
347 } |
|
348 else |
|
349 Vsite_defaults_file = sf; |
2203
|
350 } |
|
351 |
|
352 void |
|
353 install_defaults (void) |
|
354 { |
|
355 // OCTAVE_HOME must be set first! |
|
356 |
|
357 set_octave_home (); |
|
358 |
|
359 set_default_info_dir (); |
|
360 |
3141
|
361 set_default_data_dir (); |
|
362 |
|
363 set_default_libexec_dir (); |
|
364 |
2203
|
365 set_default_arch_lib_dir (); |
|
366 |
5909
|
367 set_default_local_ver_arch_lib_dir (); |
|
368 set_default_local_api_arch_lib_dir (); |
2439
|
369 set_default_local_arch_lib_dir (); |
|
370 |
5814
|
371 set_default_local_ver_oct_file_dir (); |
|
372 set_default_local_api_oct_file_dir (); |
|
373 set_default_local_oct_file_dir (); |
2203
|
374 |
5814
|
375 set_default_local_ver_fcn_file_dir (); |
|
376 set_default_local_api_fcn_file_dir (); |
|
377 set_default_local_fcn_file_dir (); |
|
378 |
|
379 set_default_fcn_file_dir (); |
5397
|
380 set_default_oct_file_dir (); |
|
381 |
5814
|
382 set_default_image_dir (); |
|
383 |
2203
|
384 set_default_bin_dir (); |
|
385 |
5814
|
386 set_exec_path (); |
4447
|
387 |
5814
|
388 set_image_path (); |
2203
|
389 |
|
390 set_default_info_file (); |
|
391 |
|
392 set_default_info_prog (); |
|
393 |
4776
|
394 set_default_fftw_wisdom_prog (); |
4773
|
395 |
2203
|
396 set_default_editor (); |
|
397 |
|
398 set_local_site_defaults_file (); |
|
399 |
|
400 set_site_defaults_file (); |
|
401 } |
|
402 |
5794
|
403 DEFUN (EDITOR, args, nargout, |
|
404 "-*- texinfo -*-\n\ |
|
405 @deftypefn {Built-in Function} {@var{val} =} EDITOR ()\n\ |
|
406 @deftypefnx {Built-in Function} {@var{old_val} =} EDITOR (@var{new_val})\n\ |
|
407 Query or set the internal variable that specifies the editor to\n\ |
|
408 use with the @code{edit_history} command. If the environment\n\ |
|
409 variable @code{EDITOR} is set when Octave starts, its\n\ |
|
410 value is used as the default. Otherwise, @code{EDITOR} is set to\n\ |
|
411 @code{\"emacs\"}.\n\ |
|
412 @seealso{edit_history}\n\ |
|
413 @end deftypefn") |
2203
|
414 { |
5794
|
415 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EDITOR); |
2203
|
416 } |
|
417 |
5794
|
418 DEFUN (EXEC_PATH, args, nargout, |
|
419 "-*- texinfo -*-\n\ |
|
420 @deftypefn {Built-in Function} {@var{val} =} EXEC_PATH ()\n\ |
|
421 @deftypefnx {Built-in Function} {@var{old_val} =} EXEC_PATH (@var{new_val})\n\ |
|
422 Query or set the internal variable that specifies a colon separated\n\ |
|
423 list of directories to search when executing external programs.\n\ |
|
424 Its initial value is taken from the environment variable\n\ |
|
425 @code{OCTAVE_EXEC_PATH} (if it exists) or @code{PATH}, but that\n\ |
|
426 value can be overridden by the command line argument\n\ |
5814
|
427 @code{--exec-path PATH}. At startup, an additional set of\n\ |
|
428 directories (including the shell PATH) is appended to the path\n\ |
|
429 specified in the environment or on the command line. If you use\n\ |
|
430 the @code{EXEC_PATH} function to modify the path, you should take\n\ |
|
431 care to preserve these additional directories.\n\ |
5794
|
432 @end deftypefn") |
4217
|
433 { |
5794
|
434 std::string saved_exec_path = VEXEC_PATH; |
4217
|
435 |
5794
|
436 octave_value retval = SET_NONEMPTY_INTERNAL_STRING_VARIABLE (EXEC_PATH); |
4217
|
437 |
5794
|
438 if (VEXEC_PATH != saved_exec_path) |
5814
|
439 octave_env::putenv ("PATH", VEXEC_PATH); |
2203
|
440 |
5794
|
441 return retval; |
2203
|
442 } |
|
443 |
5794
|
444 DEFUN (fftw_wisdom_program, args, nargout, |
3301
|
445 "-*- texinfo -*-\n\ |
5794
|
446 @deftypefn {Built-in Function} {@var{val} =} FFTW_WISDOM_PROGRAM ()\n\ |
|
447 @deftypefnx {Built-in Function} {@var{old_val} =} FFTW_WISDOM_PROGRAM (@var{new_val})\n\ |
|
448 Query or set the internal variable that specifies the FFTW wisdom\n\ |
|
449 program to use to create wisdom data to accelerate Fourier transforms.\n\ |
|
450 If the environment variable @code{OCTAVE_WISDOM_PROGRAM} is set when\n\ |
|
451 Octave starts, its value is used as the default. Otherwise,\n\ |
|
452 @code{WISDOM_PROGRAM} is set to @code{\"fftw-wisdom\"}.\n\ |
|
453 @end deftypefn") |
|
454 { |
|
455 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (fftw_wisdom_program); |
|
456 } |
2203
|
457 |
5814
|
458 DEFUN (IMAGE_PATH, args, nargout, |
5794
|
459 "-*- texinfo -*-\n\ |
5814
|
460 @deftypefn {Built-in Function} {@var{val} =} IMAGE_PATH ()\n\ |
|
461 @deftypefnx {Built-in Function} {@var{old_val} =} IMAGE_PATH (@var{new_val})\n\ |
5794
|
462 Query or set the internal variable that specifies a colon separated\n\ |
|
463 list of directories in which to search for image files.\n\ |
|
464 @end deftypefn") |
|
465 { |
5814
|
466 return SET_NONEMPTY_INTERNAL_STRING_VARIABLE (IMAGE_PATH); |
5794
|
467 } |
|
468 |
5780
|
469 DEFUN (OCTAVE_HOME, args, , |
|
470 "-*- texinfo -*-\n\ |
|
471 @deftypefn {Built-in Function} {} OCTAVE_HOME ()\n\ |
|
472 Return the name of the top-level Octave installation directory.\n\ |
|
473 @end deftypefn") |
|
474 { |
|
475 octave_value retval; |
2831
|
476 |
5780
|
477 if (args.length () == 0) |
|
478 retval = Voctave_home; |
|
479 else |
5823
|
480 print_usage (); |
5780
|
481 |
|
482 return retval; |
5749
|
483 } |
3446
|
484 |
5749
|
485 DEFUNX ("OCTAVE_VERSION", FOCTAVE_VERSION, args, , |
|
486 "-*- texinfo -*-\n\ |
|
487 @deftypefn {Built-in Function} {} OCTAVE_VERSION ()\n\ |
|
488 Return the version number of Octave, as a string.\n\ |
|
489 @end deftypefn") |
|
490 { |
|
491 octave_value retval; |
|
492 |
|
493 int nargin = args.length (); |
|
494 |
|
495 if (nargin == 0) |
|
496 retval = OCTAVE_VERSION; |
|
497 else |
5823
|
498 print_usage (); |
5749
|
499 |
|
500 return retval; |
2203
|
501 } |
|
502 |
|
503 /* |
|
504 ;;; Local Variables: *** |
|
505 ;;; mode: C++ *** |
|
506 ;;; End: *** |
|
507 */ |