From bug-octave-request at bevo dot che dot wisc dot edu Fri Oct 23 12:54:42 1998 Subject: [patch] extra colon feature + problem with default loadpath From: "John W. Eaton" To: Rafael Laboissiere Cc: bug-octave at bevo dot che dot wisc dot edu, Dirk Eddelbuettel Date: Fri, 23 Oct 1998 12:54:18 -0500 On 23-Oct-1998, Rafael Laboissiere wrote: | The solution found, implied changing a couple of files in version | 2.0.13. (BTW, guys, reading the Octave source is a great pleasure, and | making modifications to it are quite straightforward; Congrats!) | Essentially, what I did was to transfer the burden of default path | expansion from file src/defaults.cc to the method dir_path::init() [in | file liboctave/pathsearch.cc]. A new global variable Vload_path_default | is defined , that stores the default path. One problem with this solution is that it puts an Octave-specific variable (Vload_path_default) in liboctave. It also assumes that the dir_path class is only going to be used to expand LOADPATH, but it is also used to search files in other PATH-like variables. Automatically inserting the value of Vload_path_default in them is probably not right. | A new builtin function | Fload_path_default() was also created, which prints the default path | (this addition is fully optional, but is the only way that I could | imagine to get access to the value of the default path from the Octave | prompt). It would have also been possible to define a new built-in variable using DEFVAR. | The default value for Vload_path (and hence LOADPATH at startup) is set | to ":". This adds a nice feature to Octave, namely, that | initializations of LOADPATH in octave.conf or ~/.octaverc can safely | append/prepend values to LOADPATH, and the default path is still there. | As a counterexemple, the file /etc/octave.conf in a Debian system (Salut | Dirk !) has the line: | | LOADPATH = [ ":/usr/local/share/octave/site-m//", LOADPATH ]; | | With the current version of Octave, after initialization we get the | following value for LOADPATH: | | :/usr/local/share/octave/site-m//.:/usr/lib/octave/site/oct/i386-pc-linux-gnu//:/usr/share/octave/site/m//:/usr/lib/octave/2.0.13/oct/i386-pc-linux-gnu//:/usr/share/octave/2.0.13/m// | | whose second element is wrong (more on that below). I'm getting a bit confused here. | First, the bug: the environment variable OCTAVE_PATH, if it exists, is | intended to replace the default path (defined by #define | OCTAVE_FCNFILEPATH). I think there is some misunderstanding here. OCTAVE_PATH is not intended to provide a way to override the value of OCTAVE_FCNFILEPATH. It is just intended to be another way to specify the default value of LOADPATH from the environment. | However, as the function | maybe_add_default_load_path() uses the value OCTAVE_FCNFILEPATH, the | environment variable OCTAVE_PATH is useless. My design solves the | problem and allow the user to _really_ overriden the builtin default | path. I think the real problem is that if OCTAVE_PATH is found in the environment, maybe_add_default_load_path is not called on its value. Here is a fix for that: Fri Oct 23 12:07:32 1998 John W. Eaton * defaults.cc (set_default_path): If OCTAVE_PATH is set in the environment, call maybe_add_default_load_path on it. *** defaults.cc~ Tue Oct 20 20:57:45 1998 --- defaults.cc Fri Oct 23 12:19:09 1998 *************** *** 192,198 **** char *oct_path = getenv ("OCTAVE_PATH"); ! Vload_path = oct_path ? string (oct_path) : std_path; Vload_path_dir_path = dir_path (Vload_path); } --- 192,198 ---- char *oct_path = getenv ("OCTAVE_PATH"); ! Vload_path = oct_path ? maybe_add_default_load_path (oct_path) : std_path; Vload_path_dir_path = dir_path (Vload_path); } | The bad feature is illustrated above: at initialization, if LOADPATH | has leading or trailing colons, the default path is inserted in it. | With my new design, no insertion happens, the default path is kept | hidden, thanks to Vload_path_default. This means that the user gets | the value of LOADPATH that she asked for. Keeping the default path hidden may seem like a nice feature, but it will cause problems for things like this: file_in_path (LOADPATH, "foo") because file_in_path doesn't know that LOADPATH is special, so it can't know to insert the default path at the appropriate places. Thanks, jwe