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