comparison src/defaults.cc @ 4217:301cc4cf87e9

[project @ 2002-12-05 03:33:01 by jwe]
author jwe
date Thu, 05 Dec 2002 03:33:01 +0000
parents 41e7fa40ff4c
children fc9a075d10fb
comparison
equal deleted inserted replaced
4216:e613ffa9f0e6 4217:301cc4cf87e9
35 #endif 35 #endif
36 #include <unistd.h> 36 #include <unistd.h>
37 #endif 37 #endif
38 38
39 #include "oct-env.h" 39 #include "oct-env.h"
40 #include "file-stat.h"
40 #include "pathsearch.h" 41 #include "pathsearch.h"
42 #include "str-vec.h"
41 43
42 #include <defaults.h> 44 #include <defaults.h>
43 #include "defun.h" 45 #include "defun.h"
44 #include "error.h" 46 #include "error.h"
45 #include "file-ops.h" 47 #include "file-ops.h"
46 #include "gripes.h" 48 #include "gripes.h"
47 #include "help.h" 49 #include "help.h"
48 #include "oct-obj.h" 50 #include "oct-obj.h"
49 #include "ov.h" 51 #include "ov.h"
52 #include "parse.h"
50 #include "toplev.h" 53 #include "toplev.h"
54 #include "unwind-prot.h"
51 #include "variables.h" 55 #include "variables.h"
52 #include <version.h> 56 #include <version.h>
53 57
54 std::string Voctave_home; 58 std::string Voctave_home;
55 59
82 std::string Vimagepath; 86 std::string Vimagepath;
83 87
84 std::string Vlocal_site_defaults_file; 88 std::string Vlocal_site_defaults_file;
85 std::string Vsite_defaults_file; 89 std::string Vsite_defaults_file;
86 90
91 // Each element of A and B should be directory names. For each
92 // element of A not in the list B, execute SCRIPT_FILE in that
93 // directory if it exists.
94
95 static void
96 maybe_add_or_del_packages (const string_vector& a,
97 const string_vector& b,
98 const std::string script_file)
99 {
100 if (! octave_interpreter_ready)
101 return;
102
103 unwind_protect::begin_frame ("maybe_add_or_del_packages");
104
105 unwind_protect_bool (input_from_startup_file);
106
107 input_from_startup_file = true;
108
109 int a_len = a.length ();
110 int b_len = b.length ();
111
112 for (int i = 0; i < a_len; i++)
113 {
114 std::string a_dir = a[i];
115
116 bool found = false;
117
118 for (int j = 0; j < b_len; j++)
119 {
120 if (b[j] == a_dir)
121 {
122 found = true;
123 break;
124 }
125 }
126
127 if (! found)
128 {
129 std::string file = a_dir + file_ops::dir_sep_str + script_file;
130
131 file_stat fs = file_stat (file);
132
133 if (fs.exists ())
134 parse_and_execute (file);
135
136 if (error_state)
137 return;
138 }
139 }
140
141 unwind_protect::run_frame ("maybe_add_or_del_packages");
142 }
143
144 static void
145 update_load_path_dir_path (void)
146 {
147 string_vector old_dirs = Vload_path_dir_path.all_directories ();
148
149 Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path);
150
151 string_vector new_dirs = Vload_path_dir_path.all_directories ();
152
153 maybe_add_or_del_packages (old_dirs, new_dirs, "PKG_DEL");
154
155 if (! error_state)
156 maybe_add_or_del_packages (new_dirs, old_dirs, "PKG_ADD");
157 }
158
159 void
160 execute_default_pkg_add_files (void)
161 {
162 string_vector old_dirs;
163 string_vector new_dirs = Vload_path_dir_path.all_directories ();
164
165 maybe_add_or_del_packages (new_dirs, old_dirs, "PKG_ADD");
166 }
167
87 static std::string 168 static std::string
88 subst_octave_home (const std::string& s) 169 subst_octave_home (const std::string& s)
89 { 170 {
90 std::string retval; 171 std::string retval;
91 172
189 270
190 std::string oct_path = octave_env::getenv ("OCTAVE_PATH"); 271 std::string oct_path = octave_env::getenv ("OCTAVE_PATH");
191 272
192 Vload_path = oct_path.empty () ? std::string (":") : oct_path; 273 Vload_path = oct_path.empty () ? std::string (":") : oct_path;
193 274
194 Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path); 275 update_load_path_dir_path ();
195 } 276 }
196 277
197 static void 278 static void
198 set_default_info_file (void) 279 set_default_info_file (void)
199 { 280 {
421 // || s.find ("::") != NPOS)) 502 // || s.find ("::") != NPOS))
422 // warning ("LOADPATH will ignore default load path"); 503 // warning ("LOADPATH will ignore default load path");
423 504
424 Vload_path = s; 505 Vload_path = s;
425 506
426 Vload_path_dir_path = dir_path (Vload_path, Vdefault_load_path); 507 update_load_path_dir_path ();
508 }
509
510 return status;
511 }
512
513 static int
514 default_load_path (void)
515 {
516 int status = 0;
517
518 std::string s = builtin_string_variable ("DEFAULT_LOADPATH");
519
520 if (s.empty ())
521 {
522 gripe_invalid_value_specified ("DEFAULT_LOADPATH");
523 status = -1;
524 }
525 else
526 {
527 Vdefault_load_path = s;
528
529 update_load_path_dir_path ();
427 } 530 }
428 531
429 return status; 532 return status;
430 } 533 }
431 534
494 \n\ 597 \n\
495 @xref{Organization of Functions}, for a description of the function file\n\ 598 @xref{Organization of Functions}, for a description of the function file\n\
496 directories that are distributed with Octave.\n\ 599 directories that are distributed with Octave.\n\
497 @end defvr"); 600 @end defvr");
498 601
499 DEFCONST (DEFAULT_LOADPATH, Vdefault_load_path, 602 DEFVAR (DEFAULT_LOADPATH, Vdefault_load_path, default_load_path,
500 "-*- texinfo -*-\n\ 603 "-*- texinfo -*-\n\
501 @defvr {Built-in Variable} DEFAULT_LOADPATH\n\ 604 @defvr {Built-in Variable} DEFAULT_LOADPATH\n\
502 A colon separated list of directories in which to search for function\n\ 605 A colon separated list of directories in which to search for function\n\
503 files by default. The value of this variable is also automatically\n\ 606 files by default. The value of this variable is also automatically\n\
504 substituted for leading, trailing, or doubled colons that appear in the\n\ 607 substituted for leading, trailing, or doubled colons that appear in the\n\