pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1:   // -*- Pike -*-   //   // Master Control Program for Pike.   //   // This file is part of Pike. For copyright information see COPYRIGHT.   // Pike is distributed under GPL, LGPL and MPL. See the file COPYING   // for more information.   // - // $Id: master.pike.in,v 1.439 2008/06/07 06:48:19 grubba Exp $ + // $Id: master.pike.in,v 1.440 2008/06/07 10:52:03 grubba Exp $      #pike __REAL_VERSION__   //#pragma strict_types      // Some programs destroys character pairs beginning with the currency   // symbol when running in chinese locale.   #if "ยค/" != "\244/"   #error "master.pike.in is corrupted."   #endif   
pike.git/lib/master.pike.in:170:   #ifdef FILE_STAT_CACHE    extern int invalidate_time;    extern mapping(string:multiset(string)) dir_cache;    local array(mixed) master_file_stat(string x)    {    Stat st = global::master_file_stat(x);    return st && (array)st;    }   #endif    +  //! @decl mapping(string:array(string)) environment +  //!    //! Mapping containing the environment variables.    //!    //! The mapping currently has the following structure:    //! @mapping    //! @member array(string) index    //! Note that the index is @[lower_case()]'d on NT.    //! @array    //! @elem string varname    //! Variable name with case intact.    //! @elem string value
pike.git/lib/master.pike.in:196:    //! and @[putenv()] instead. This mapping is not publicly    //! accessible in pikes newer than 7.6.    //!    //! @note    //! This mapping is not compatible with @[Process.create_process()];    //! use the mapping returned from calling @[getenv()] without arguments    //! instead.    //!    //! @bugs    //! This mapping is not the real environment; it is just a copy of -  //! the environment made at startup. -  local mapping(string:array(string)) environment; +  //! the environment made at startup. Pike does attempt to keep +  //! track of changes in the mapping and to reflect them in the +  //! real environment, but avoid accessing this mapping if at all +  //! possible.    -  local string|mapping(string:string) getenv(string|void s) +  string|mapping(string:string) getenv(string|void s); +  void putenv(string|void varname, string|void value); +  +  // compat_environment is the mapping returned by `environment +  // (if any). +  // compat_environment_copy is used to keep track of any changes +  // performed destructively on the compat_environment mapping. +  // Both should be zero if not in use. +  static mapping(string:array(string)) compat_environment; +  static mapping(string:array(string)) compat_environment_copy; +  + #pragma no_deprecation_warnings +  local __deprecated__(mapping(string:array(string))) `environment()    { -  if(!s) return [mapping(string:string)]aggregate_mapping( @(values(environment)*({}) ) ); +  if (compat_environment) return compat_environment; +  compat_environment_copy = ([]);   #ifdef __NT__ -  s = lower_case(s); +  // Can't use the cached environment returned by getenv(), since +  // variable names have been lowercased there. +  foreach((array(array(string)))Builtin._getenv(), array(string) pair) { +  compat_environment_copy[lower_case(pair[0])] = pair; +  } + #else +  foreach((array(array(string)))getenv(), array(string) pair) { +  compat_environment_copy[pair[0]] = pair; +  }   #endif -  return environment[s] && environment[s][1]; +  return compat_environment = copy_value(compat_environment_copy);    }    -  local void putenv(string varname, string|void value) +  local void `environment=(__deprecated__(mapping(string:array(string))) +  new_env)    { -  // Try to update the real enviroment too, but ignore errors since -  // the fake environment could accommodate wide strings, strings -  // with NULs etc. -  catch {Builtin._putenv (varname, value);}; -  string index = varname; - #ifdef __NT__ -  index = lower_case(varname); -  if (environment[index] && environment[index][0]) -  varname = environment[index][0]; - #endif -  if (value) { -  environment[index] = ({ varname, value }); -  } else { -  m_delete(environment, index); +  compat_environment = new_env; +  if (!new_env) compat_environment_copy = 0;    } -  } + #pragma deprecation_warnings       void add_include_path(string tmp);    void remove_include_path(string tmp);    void add_module_path(string tmp);    void remove_module_path(string tmp);    void add_program_path(string tmp);    void remove_program_path(string tmp);    mapping(string:program|NoValue) programs;   #if constant(_static_modules.Builtin.mutex)    extern object compilation_mutex;
pike.git/lib/master.pike.in:1020:    void|int force_update)   {    // Variants doesn't seem to work well yet.    if (stringp (var)) {    if (!environment || force_update) {   #ifdef __NT__    set_lc_env (Builtin._getenv());   #else    environment = Builtin._getenv();   #endif +  // Kill the compat environment if forced. +  compat_environment = compat_environment_copy = 0;    }      #ifdef __NT__ -  return environment[lower_case (var)]; - #else -  return environment[var]; +  var = lower_case(var);   #endif -  +  +  if (compat_environment) { +  array(string) res; +  if (!equal(res = compat_environment[var], compat_environment_copy[var])) { +  // Something has messed with the compat environment mapping. +  putenv(var, res && res[1]);    } -  +  }    -  +  return environment[var]; +  } +     else {    force_update = var;       mapping(string:string) res;       if (force_update) {    res = Builtin._getenv();   #ifdef __NT__    set_lc_env (res);   #else    environment = res + ([]);   #endif -  +  // Kill the compat environment if forced. +  compat_environment = compat_environment_copy = 0;    }       else { -  +  if (compat_environment && +  !equal(compat_environment, compat_environment_copy)) { +  foreach(compat_environment; var; array(string) pair) { +  if (!equal(pair, compat_environment_copy[var])) { +  putenv(pair[0], pair[1]); +  } +  } +  foreach(compat_environment_copy; var; array(string) pair) { +  if (!compat_environment[var]) { +  putenv(pair[0]); +  } +  } +  }   #ifdef __NT__    // Can't use the cached environment since variable names have been    // lowercased there.    res = Builtin._getenv();    if (!environment) set_lc_env (res);   #else    if (!environment) environment = Builtin._getenv();    res = environment + ([]);   #endif    }
pike.git/lib/master.pike.in:1077:   //! @expr{'='@} characters.   //!   //! @note   //! On NT the environment variable name is case insensitive.   //!   //! @seealso   //! @[getenv()]   //!   {    Builtin._putenv (varname, value); +  if (compat_environment) { +  string lvarname = varname; + #ifdef __NT__ +  lvarname = lower_case(varname); + #endif +  if (value) { +  compat_environment[lvarname] = +  (compat_environment_copy[lvarname] = ({ varname, value })) + ({}); +  } else { +  m_delete(compat_environment, lvarname); +  m_delete(compat_environment_copy, lvarname); +  } +  }    if (environment) {   #ifdef __NT__    varname = lower_case (varname);   #endif    if (value) environment[varname] = value;    else m_delete (environment, varname);    }   }      
pike.git/lib/master.pike.in:1875:   #if constant(__embedded_resource_directory)    // for use with embedded interpreters    // add path for architecture-dependant files    add_include_path(__embedded_resource_directory + "/lib/include");    add_module_path(__embedded_resource_directory + "/lib/modules");    add_module_path(__embedded_resource_directory + "/" + replace(uname()->machine, " ", "_") + "/modules");      #endif       system_module_path=pike_module_path; -  if (master() && master() != this_object()) { -  // getenv() and putenv() will get confused if we don't do this. -  // This is only for pike <= 7.6 compat. -  if (mapping e = (master()->environment || -  (master()->get_compat_master && -  master()->get_compat_master(7,6)->environment))) -  Pike_7_6_master::environment = e; +    } - } +          //! This function is called whenever a inherit is called for.   //! It is supposed to return the program to inherit.   //! The first argument is the argument given to inherit, and the second   //! is the file name of the program currently compiling. Note that the   //! file name can be changed with #line, or set by compile_string, so   //! it can not be 100% trusted to be a filename.   //! previous_object(), can be virtually anything in this function, as it   //! is called from the compiler.