6d29bd2002-02-23Martin Nilsson #pike __REAL_VERSION__
9eaf1d2008-06-28Martin Nilsson // $Id: Local.pmod,v 1.11 2008/06/28 16:36:53 nilsson Exp $
6d29bd2002-02-23Martin Nilsson  //! @[Local] gives a local module namespace used for locally //! installed pike modules. Modules are searched for in //! the directory @tt{pike_modules@} which can be located in //! the user's home directory or profile directory, or in any //! of the system directories @tt{/opt/share, /usr/local/share, //! /opt@} or @tt{/usr/local/@}. The user's home directory is //! determined by examining the environment variable HOME, and
6dffbe2002-08-28Mikael Brandström //! if that fails the environment variable USERPROFILE. If the //! environment variable PIKE_LOCAL_PATH is set, the paths specified //! there will be searched first.
6d29bd2002-02-23Martin Nilsson //! @seealso
a5c9e32002-02-25Martin Nilsson //! @[Local.add_path()], @[Local.remove_path()]
6d29bd2002-02-23Martin Nilsson //!
46d51e2007-09-03Henrik Grubbström (Grubba) inherit __joinnode;
6d29bd2002-02-23Martin Nilsson 
9eaf1d2008-06-28Martin Nilsson protected array(string) local_path;
6d29bd2002-02-23Martin Nilsson 
9eaf1d2008-06-28Martin Nilsson protected void create()
46d51e2007-09-03Henrik Grubbström (Grubba) { ::create(({}));
6d29bd2002-02-23Martin Nilsson  // FIXME $prefix/pike_modules // FIXME All this should be controllable from .pikerc, when such a file is implemented...
46d51e2007-09-03Henrik Grubbström (Grubba) 
5e22182002-02-23Mikael Brandström  add_path("/usr/local/pike_modules"); add_path("/opt/pike_modules"); add_path("/opt/share/pike_modules"); add_path("/usr/local/share/pike_modules");
6dffbe2002-08-28Mikael Brandström 
46d51e2007-09-03Henrik Grubbström (Grubba)  string tmp;
ecbfe12003-04-27Martin Nilsson  if( (tmp=[string]getenv("HOME")) || (tmp=[string]getenv("USERPROFILE")) ) {
6d29bd2002-02-23Martin Nilsson  tmp = (tmp[-1]=='/'?tmp:tmp+"/")+"pike_modules/";
5e22182002-02-23Mikael Brandström  add_path(tmp);
6d29bd2002-02-23Martin Nilsson  }
6dffbe2002-08-28Mikael Brandström 
ecbfe12003-04-27Martin Nilsson  if(tmp = [string]getenv("PIKE_LOCAL_PATH") ) {
7751eb2002-08-28Mikael Brandström  array to_add=reverse(tmp/":"); // preserve order
6dffbe2002-08-28Mikael Brandström  add_path( to_add[*] ); }
6d29bd2002-02-23Martin Nilsson }
46d51e2007-09-03Henrik Grubbström (Grubba) //! @decl int(0..1) add_path(string path) //!
6d29bd2002-02-23Martin Nilsson //! This function prepends @[path] to the @[Local] module //! searchpath. //! //! @param path //! The path to the directory to be added. //! //! @returns //! Returns 1 on success, otherwise 0. //! This function removes @[path] from the @[Local] module //! searchpath. If @[path] is not in the search path, this is //! a noop. //! //! @param path //! The path to be removed. //!
46d51e2007-09-03Henrik Grubbström (Grubba) void remove_path(string path) { rem_path(path);
6d29bd2002-02-23Martin Nilsson }