pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:48:   // Enables the out of date warning in low_findprog().   #ifndef OUT_OF_DATE_WARNING   #define OUT_OF_DATE_WARNING 1   #endif /* OUT_OF_DATE_WARNING */   constant out_of_date_warning = OUT_OF_DATE_WARNING;      // FIXME: PATH_SEPARATOR and UPDIR should probably be exported,   // or at least some functions that use them should be.   // cf Tools.Shoot.runpike.   // /grubba 2004-04-11 - #if defined(__NT__) || defined(__amigaos__) + #if defined(__NT__) || defined(__amigaos__) || defined(__OS2__)   #define PATH_SEPARATOR ";"   #else   #define PATH_SEPARATOR ":"   #endif      #ifdef __amigaos__   #define UPDIR "/"   #else   #define UPDIR "../"   #endif
pike.git/lib/master.pike.in:88:   // This integer variable should exist in any object that aspires to be   // the master. It gets set to 1 when the master is installed, and is   // therefore set in any object that is or has been the master. That   // makes the Encoder class encode references to the master and all   // ex-masters as references to the current master object.      // --- Functions begin here.      // Have to access some stuff without going through the resolver.   private object(_static_modules.Builtin) Builtin = _static_modules.Builtin(); - private constant Files = _static_modules.files; + private constant Files = _static_modules._Stdio;      #define Stat Files.Stat   #define capitalize(X) (upper_case((X)[..0])+(X)[1..])   #define trim_all_whites(X) (Builtin.string_trim_all_whites (X))      private function write = Files()->_stdout->write;   private function werror = Files()->_stderr->write;      // Tell Pike.count_memory this is global.   constant pike_cycle_depth = 0;
pike.git/lib/master.pike.in:124:   #define GET_MSG_DEPTH _msg_depth   #define INC_MSG_DEPTH() (++_msg_depth)   #define DEC_MSG_DEPTH() (--_msg_depth)   #endif      #endif      #ifdef RESOLV_DEBUG      #define GET_RESOLV_MSG_DEPTH GET_MSG_DEPTH - #define INC_RESOLV_MSG_DEPTH INC_MSG_DEPTH - #define DEC_RESOLV_MSG_DEPTH DEC_MSG_DEPTH + #define INC_RESOLV_MSG_DEPTH() INC_MSG_DEPTH() + #define DEC_RESOLV_MSG_DEPTH() DEC_MSG_DEPTH()      void resolv_debug (sprintf_format fmt, sprintf_args... args)   {    string pad = " " * GET_RESOLV_MSG_DEPTH;    if (sizeof (args)) fmt = sprintf (fmt, @args);    if (fmt[-1] == '\n')    fmt = pad + replace (fmt[..<1], "\n", "\n" + pad) + "\n";    else    fmt = pad + replace (fmt, "\n", "\n" + pad);    if (!werror) werror = Files()->_stderr->write;
pike.git/lib/master.pike.in:1009:   //! Check if a path @[p] is fully qualified (ie not relative).   //!   //! @returns   //! Returns 1 if the path is absolute, 0 otherwise.   int is_absolute_path(string p)   {   #ifdef __amigaos__   #define IS_ABSOLUTE_PATH(X) (search((X),":")>0)    return IS_ABSOLUTE_PATH(p);   #else - #ifdef __NT__ + #if defined(__NT__) || defined(__OS2__)    p=replace(p,"\\","/");    if(sscanf(p,"%[a-zA-Z]:%*c",string s)==2 && sizeof(s)==1)    return 1;   #define IS_ABSOLUTE_PATH is_absolute_path   #else   #define IS_ABSOLUTE_PATH(X) has_prefix((X),"/")   #endif    return has_prefix(p,"/");   #endif   }    - #ifdef __NT__ + #if defined(__NT__) || defined(__OS2__)   #define EXPLODE_PATH(X) (replace((X),"\\","/")/"/")   #else   #define EXPLODE_PATH(X) ((X)/"/")   #endif      //! @appears explode_path   //! Split a path @[p] into its components.   //!   //! This function divides a path into its components. This might seem like   //! it could be done by dividing the string on <tt>"/"</tt>, but that will
pike.git/lib/master.pike.in:1273:      #ifdef __NT__   protected void set_lc_env (mapping(string:string) env)   {    environment = ([]);    foreach (env; string var; string val)    environment[lower_case (var)] = val;   }   #endif    - //! @decl string getenv (string varname, void|int force_update) +    //! @decl mapping(string:string) getenv (void|int force_update)   //! - //! Queries the environment variables. The first variant returns the - //! value of a specific variable or zero if it doesn't exist in the - //! environment. The second variant returns the whole environment as a - //! mapping. Destructive operations on the mapping will not affect the - //! internal environment representation. + //! Queries the environment variables.   //! - //! A cached copy of the real environment is kept to make this - //! function quicker. If the optional flag @[force_update] is nonzero - //! then the real environment is queried and the cache is updated from - //! it. That can be necessary if the environment changes through other - //! means than @[putenv], typically from a C-level library. + //! @param force_update + //! A cached copy of the real environment is kept to make this + //! function quicker. If the optional flag @[force_update] is nonzero + //! then the real environment is queried and the cache is updated from + //! it. That can be necessary if the environment changes through other + //! means than @[putenv], typically from a C-level library.   //! -  + //! @returns + //! Returns the whole environment as a mapping. Destructive + //! operations on the mapping will not affect the internal + //! environment representation. + //!   //! Variable names and values cannot be wide strings nor contain   //! @expr{'\0'@} characters. Variable names also cannot contain   //! @expr{'='@} characters.   //!   //! @note   //! On NT the environment variable name is case insensitive.   //!   //! @seealso   //! @[putenv()] - string|mapping(string:string) getenv (void|int|string varname, -  void|int force_update) + mapping(string:string) getenv (void|int force_update)   { -  // Variants doesn't seem to work well yet. -  if (stringp (varname)) { -  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__ -  varname = lower_case(varname); - #endif -  -  if (compat_environment) { -  array(string) res; -  if (!equal(res = compat_environment[varname], -  compat_environment_copy[varname])) { -  // Something has messed with the compat environment mapping. -  putenv(varname, res && res[1]); -  } -  } -  -  return environment[varname]; -  } -  -  else { -  force_update = varname; -  +     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; varname; array(string) pair) { +  foreach(compat_environment; string varname; array(string) pair) {    if (!equal(pair, compat_environment_copy[varname])) {    putenv(pair[0], pair[1]);    }    } -  foreach(compat_environment_copy; varname; array(string) pair) { +  foreach(compat_environment_copy; string varname; array(string) pair) {    if (!compat_environment[varname]) {    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    }       return res;   } -  +  + //! @decl string getenv (string varname, void|int force_update) + //! + //! Query the value of a specific environment variable. + //! + //! @param varname + //! Environment variable to query. + //! + //! @param force_update + //! A cached copy of the real environment is kept to make this + //! function quicker. If the optional flag @[force_update] is nonzero + //! then the real environment is queried and the cache is updated from + //! it. That can be necessary if the environment changes through other + //! means than @[putenv], typically from a C-level library. + //! + //! @returns + //! Returns the value of the environment variable @[varname] + //! if it exists, and @expr{0@} (zero) otherwise. + //! + //! Variable names and values cannot be wide strings nor contain + //! @expr{'\0'@} characters. Variable names also cannot contain + //! @expr{'='@} characters. + //! + //! @note + //! On NT the environment variable name is case insensitive. + //! + //! @seealso + //! @[putenv()] + variant string getenv (string varname, void|int force_update) + { +  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__ +  varname = lower_case(varname); + #endif +  +  if (compat_environment) { +  array(string) res; +  if (!equal(res = compat_environment[varname], +  compat_environment_copy[varname])) { +  // Something has messed with the compat environment mapping. +  putenv(varname, res && res[1]); +  } +  } +  +  return environment[varname]; + } +    void putenv (string varname, void|string value)   //! Sets the environment variable @[varname] to @[value].   //!   //! If @[value] is omitted or zero, the environment variable   //! @[varname] is removed.   //!   //! @[varname] and @[value] cannot be wide strings nor contain   //! @expr{'\0'@} characters. @[varname] also cannot contain   //! @expr{'='@} characters.   //!
pike.git/lib/master.pike.in:2406:    int index;    foreach(paths; index; string other_fname) {    if (prio_from_filename(other_fname) <= prio) break;    }    file_paths[base] = paths[..index-1] + ({ fname }) + paths[index..];    }    }       class module_checker    { -  int `!() +  protected int `!()    {    resolv_debug ("dirnode(%O)->module_checker()->`!()\n",dirname);       if (mixed err = catch {    // Look up module.    if (module = cache["module"] || low_ind("module", 1)) {    /* This allows for `[] to have side effects first time    * it is called. (Specifically, the Calendar module uses    * this).    */
pike.git/lib/master.pike.in:2438:    // The error will then typically be:    // "Cannot call functions in unfinished objects."       // Pretend not to exist for now...    resolv_debug("dirnode(%O)->module_checker()->`!() => failure, doesn't exist\n",    dirname);    return 1;    }    }    -  mixed `[](string index) +  protected mixed `[](string index)    {    resolv_debug ("dirnode(%O)->module_checker()[%O] => %O\n",    dirname, index, module && module[index]);    return module && module[index];    } -  array(string) _indices() { if(module) return indices(module); } -  array _values() { if(module) return values(module); } +  protected array(string) _indices() { if(module) return indices(module); } +  protected array _values() { if(module) return values(module); }    }       protected mixed low_ind(string index, int(0..1)|void set_module)    {    array(string) paths;       INC_RESOLV_MSG_DEPTH();       if (!(paths = file_paths[index])) {    DEC_RESOLV_MSG_DEPTH();
pike.git/lib/master.pike.in:2573:    resolv_debug ("dirnode(%O)->ind(%O) => not found in module\n",    dirname, index);    }    else    resolv_debug ("dirnode(%O)->ind(%O) => no module\n", dirname, index);       DEC_RESOLV_MSG_DEPTH();    return low_ind(index);    }    -  mixed `[](string index) +  protected mixed `[](string index)    {    mixed ret;   #ifdef MODULE_TRACE    werror("%*nDirnode(%O) cache[%O] ?????\n",    sizeof(backtrace()),dirname,index);   #endif    if(!zero_type(ret=cache[index]))    {   #ifdef MODULE_TRACE    werror("%*nDirnode(%O) cache[%O] => %O%s\n",
pike.git/lib/master.pike.in:2653:    dirname, module, indices(module));    map(indices(module), safe_index);    }       map(indices(file_paths), safe_index);    _cache_full = (object_program(module) != __null_program);    resolv_debug ("dirnode(%O) => Cache %s.\n", dirname,    _cache_full?"full":"partially filled");    }    -  protected array(string) _indices() +  protected protected array(string) _indices()    {    fill_cache();    // Note: Cannot index cache at all here to filter out the    // ZERO_TYPE values since that can change the order in the    // mapping, and _indices() has to return the elements in the same    // order as a nearby _values() call.    return filter (indices (cache), map (values (cache), `!=, ZERO_TYPE));    }    -  protected array(mixed) _values() +  protected protected array(mixed) _values()    {    fill_cache();    return values(cache) - ({ZERO_TYPE});    }       void delete_value (mixed val)    {    if (string name = search (cache, val)) {    m_delete (cache, name);    _cache_full = 0;
pike.git/lib/master.pike.in:2801:    name && !has_value (name, "|") &&    (name == "predef::" ? index : name + "." + index));    }       DEC_RESOLV_MSG_DEPTH();    resolv_debug ("joinnode(%O)->ind(%O) => not found. Trying fallback %O\n",    joined_modules, index, fallback_module);    return fallback_module[index];    }    -  mixed `[](string index) +  protected mixed `[](string index)    {    mixed ret;    if (!zero_type(ret = cache[index])) {    if (ret != ZERO_TYPE) {    return ret;    }    return UNDEFINED;    }    ret = ind(index);   
pike.git/lib/master.pike.in:2848:    `[](index);    }    }    }    foreach(indices(fallback_module), string index) {    `[](index);    }    _cache_full = 1;    }    -  array(string) _indices() +  protected array(string) _indices()    {    fill_cache();    // Note: Cannot index cache at all here to filter out the    // ZERO_TYPE values since that can change the order in the    // mapping, and _indices() has to return the elements in the same    // order as a nearby _values() call.    return filter (indices (cache), map (values (cache), `!=, ZERO_TYPE));    }    -  array(mixed) _values() +  protected array(mixed) _values()    {    fill_cache();    return values(cache) - ({ZERO_TYPE});    }       void delete_value (mixed val)    {    if (string name = search (cache, val))    m_delete (cache, name);    for (int i = 0; i < sizeof (joined_modules); i++) {
pike.git/lib/master.pike.in:2881:    joined_modules = joined_modules[..i - 1] + joined_modules[i + 1..];    i--;    }    else if (objectp (o) && (o->is_resolv_dirnode || o->is_resolv_joinnode))    o->delete_value (val);    else if (string name = mappingp (o) && search (o, val))    m_delete (o, name);    }    }    -  int `== (mixed other) +  protected int `== (mixed other)    {    return objectp (other) && (other->is_resolv_joinnode == 1) &&    equal (mkmultiset (joined_modules), mkmultiset (other->joined_modules));    }       array(object) _encode()    {    return joined_modules;    }   
pike.git/lib/master.pike.in:3459:    //!    string read_include(string f)    {    AUTORELOAD_CHECK_FILE(f);    if (array|object err = catch {    return master_read_file (f);    })    compile_cb_rethrow (err);    }    -  string _sprintf(int t) +  protected string _sprintf(int t)    {    return t=='O' && sprintf("CompatResolver(%O)",ver);    }   }      inherit CompatResolver;      //!   class Pike06Resolver   {
pike.git/lib/master.pike.in:3737:       foreach(q, array opts)    {    switch(opts[0])    {    case "dumpversion":    write("%d.%d.%d\n", __REAL_MAJOR__, __REAL_MINOR__, __REAL_BUILD__);    exit(0);       case "version": -  exit(0, string_to_utf8(version() + " Copyright © 1994-2011 Linköping University\n" +  exit(0, string_to_utf8(version() + " Copyright © 1994-2013 Linköping University\n"    "Pike comes with ABSOLUTELY NO WARRANTY; This is free software and you are\n"    "welcome to redistribute it under certain conditions; read the files\n"    "COPYING and COPYRIGHT in the Pike distribution for more details.\n"));       case "help":    exit( 0, main_resolv("Tools.MasterHelp")->do_help(opts[1]) );       case "features":    postparseaction="features";    break;
pike.git/lib/master.pike.in:3783:       default:    exit(1, "Unknown path type %s\n", opts[1]);    }    exit(0);    }       exit(0, format_paths());       case "execute": - #ifdef __AUTO_BIGNUM__ +     main_resolv( "Gmp.bignum" ); - #endif /* __AUTO_BIGNUM__ */ -  +     random_seed((time() ^ (getpid()<<8)));    argv = tmp->get_args(argv,1);       program prog;    mixed compile_err = catch {;    if(cur_compat_ver <= Version(7,4))    prog = compile_string(    "mixed create(int argc, array(string) argv,array(string) env){"+    opts[1]+";}");    else if (intp (opts[1]))
pike.git/lib/master.pike.in:3854:    ret = 10;    }    if(stringp(ret)) {    write(ret);    if(ret[-1]!='\n') write("\n");    }    if(!intp(ret) || ret<0) ret=0;    exit(ret);       case "preprocess": - #ifdef __AUTO_BIGNUM__ +     main_resolv( "Gmp.bignum" ); - #endif /* __AUTO_BIGNUM__ */ +     write(cpp(master_read_file(opts[1]),opts[1]));    exit(0);    }    }       argv = tmp->get_args(argv,1);    }    else    cur_compat_ver = Version (compat_major, compat_minor);   
pike.git/lib/master.pike.in:3886:    "WWW...........http://pike.lysator.liu.se/\n"    "\n"    "pike binary..."+_pike_file_name+"\n"+    format_paths() + "\n"    "Features......"+    main_resolv( "Tools.Install.features" )()*"\n "+    "\n");    exit(0);    }    - #ifdef __AUTO_BIGNUM__ +     main_resolv( "Gmp.bignum" ); - #endif /* __AUTO_BIGNUM__ */ -  +     random_seed(time() ^ (getpid()<<8));       if(sizeof(argv)==1)    {    if(run_tool) {    werror("Pike -x specificed without tool name.\n"    "Available tools:\n");    mapping t = ([]);    int i;    object ts = main_resolv("Tools.Standalone",
pike.git/lib/master.pike.in:4030:    while(1)    Builtin.__backend(3600.0);    };    master()->handle_error(err);    }   }      #if constant(thread_local)   object inhibit_compile_errors = thread_local();    - void set_inhibit_compile_errors(mixed f) + //! Set the compile error, warning and exception behaviour. + //! + //! @param behaviour + //! The desired behaviour. One of: + //! @mixed + //! @type int(0..0) + //! Output compilation errors and warnings to @tt{stderr@}. + //! This is the default behaviour. + //! @type int(1..1) + //! Inhibit output of compilator diagnostics. + //! @type function(string, int, string:void) + //! Function to call for compilation errors. Compilation + //! warnings and exceptions are inhibited. + //! + //! The function will be called with the same arguments + //! as those passed to @[compile_error()]. + //! @type CompilationHandler + //! Compilation handler to use for diagnostics. + //! @endmixed + //! + //! @note + //! Note that the behaviour is thread local, and is not copied + //! to new threads when they are created. + //! + //! @seealso + //! @[get_inhibit_compile_errors()] + void set_inhibit_compile_errors(mixed behaviour)   { -  inhibit_compile_errors->set(f); +  inhibit_compile_errors->set(behaviour);   }    -  + //! Get the current compile error, warning and exception behaviour. + //! + //! See @[set_inhibit_compile_errors()] for details. + //! + //! @seealso + //! @[set_inhibit_compile_errors()]   mixed get_inhibit_compile_errors()   {    return inhibit_compile_errors->get();   }   #else /* !constant(thread_local) */   mixed inhibit_compile_errors;      void set_inhibit_compile_errors(mixed f)   {    inhibit_compile_errors=f;
pike.git/lib/master.pike.in:4088:   {    function(string:string) f=_trim_file_name_cb;    _trim_file_name_cb=s;    return f;   }         //! This function is called whenever a compile error occurs. @[line]   //! is zero for errors that aren't associated with any specific line.   //! @[err] is not newline terminated. + //! + //! @seealso + //! @[compile_warning()], @[compile_exception()], + //! @[get_inhibit_compile_errors()], @[set_inhibit_compile_errors()],   void compile_error(string file,int line,string err)   {    mixed val;    if(! (val = get_inhibit_compile_errors() ))    {    werror( "%s:%s:%s\n",trim_file_name(file),    line?(string)line:"-",err );    }    else if(objectp(val) ||    programp(val) ||
pike.git/lib/master.pike.in:4112:    } else if (callablep(val)) {    val(file, line, err);    }    }   }         //! This function is called whenever a compile warning occurs. @[line]   //! is zero for warnings that aren't associated with any specific   //! line. @[err] is not newline terminated. + //! + //! @seealso + //! @[compile_error()], @[compile_exception()], + //! @[get_inhibit_compile_errors()], @[set_inhibit_compile_errors()],   void compile_warning(string file,int line,string err)   {    mixed val;       if(!(val = get_inhibit_compile_errors() ))    {    if(want_warnings)    werror( "%s:%s: Warning: %s\n",trim_file_name(file),    line?(string)line:"-",err );    }    else if (objectp(val) && val->compile_warning) {    ([function(string,int,string:void)]([object]val)    ->compile_warning)(file, line, err);    }   }         //! This function is called when an exception is caught during   //! compilation. Its message is also reported to @[compile_error] if   //! this function returns zero. -  + //! + //! @seealso + //! @[compile_error()], @[compile_warning()], + //! @[get_inhibit_compile_errors()], @[set_inhibit_compile_errors()],   int compile_exception (array|object trace)   {    if (objectp (trace) && ([object]trace)->is_cpp_or_compilation_error)    // Errors thrown by cpp(), compile() or a compile callback should    // be reported as a normal compile error, so let the caller do    // just that.    return 0;    if (mixed val = get_inhibit_compile_errors()) {    if (objectp(val) && ([object]val)->compile_exception)    return ([function(object:int)]([object]val)
pike.git/lib/master.pike.in:4185:   }         protected object Charset;      //! This function is called by cpp() when it wants to do   //! character code conversion.   string decode_charset(string data, string charset)   {    if (!Charset) { -  object mod = [object]resolv("Locale"); -  -  Charset = [object](mod && mod["Charset"]); +  Charset = [object]resolv("Charset");    if (!Charset) -  compile_cb_error("Cannot handle charset - no Locale.Charset module found."); +  compile_cb_error("Cannot handle charset - no Charset module found.");    }       if (mixed err = catch {    object decoder = ([function(string:object)]Charset.decoder)(charset);    return ([function(void:string)]([function(string:object)]decoder->    feed)(data)->drain)();    })    compile_cb_rethrow (err);   }   
pike.git/lib/master.pike.in:5744:    if(maj==-1) maj = __REAL_MAJOR__;    if(min==-1) min = __REAL_MINOR__;    major = maj;    minor = min;    }      #define CMP(X) ((major - ([object]X)->major) || (minor - ([object]X)->minor))       //! Methods define so that version objects    //! can be compared and ordered. -  int `<(mixed v) { return objectp(v) && CMP(v) < 0; } -  int `>(mixed v) { return objectp(v) && CMP(v) > 0; } -  int `==(mixed v) { return objectp(v) && CMP(v)== 0; } -  int __hash() { return major * 4711 + minor ; } +  protected int `<(mixed v) { return objectp(v) && CMP(v) < 0; } +  protected int `>(mixed v) { return objectp(v) && CMP(v) > 0; } +  protected int `==(mixed v) { return objectp(v) && CMP(v)== 0; } +  protected int __hash() { return major * 4711 + minor ; }    -  string _sprintf(int t) { +  protected string _sprintf(int t) {    switch(t) {    case 's': return sprintf("%d.%d",major,minor);    case 'O': return sprintf("%O(%s)", this_program, this);    }    }       //! The version object can be casted into a string. -  mixed cast(string type) +  protected mixed cast(string type)    {    switch(type)    {    case "string":    return sprintf("%d.%d",major,minor);    }    }   }      //! Version information about the current Pike version.