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.273 2003/04/29 00:46:52 nilsson Exp $ + // $Id: master.pike.in,v 1.274 2003/04/30 00:58:20 nilsson Exp $      #pike __REAL_VERSION__      // Some programs destroys character pairs beginning with the currency   // symbol when running in chinese locale.   #if "ยค/" != "\244/"   #error "master.pike.in is corrupted."   #endif      // --- Some configurable parameters
pike.git/lib/master.pike.in:2241:   {    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) { -  val->compile_warning(file, line, err); +  ([function(string,int,string:void)]([object]val) +  ->compile_warning)(file, line, err);    }   }         //! This function is called when an exception is catched during   //! compilation. Its message is also reported to @[compile_error] if   //! this function returns zero.   int compile_exception (array|object trace)   {    if (objectp (trace) && -  (trace->is_cpp_error || trace->is_compilation_error)) +  ( ([object]trace)->is_cpp_error || +  ([object]trace)->is_compilation_error))    // Errors thrown directly by cpp() and compile() are normally not    // interesting; they've already been reported to compile_error.    return 1;    if (mixed val = get_inhibit_compile_errors()) { -  if (objectp (val) && val->compile_exception) -  return val->compile_exception (trace); +  if (objectp(val) && ([object]val)->compile_exception) +  return ([function(object:int)]([object]val) +  ->compile_exception)([object]trace);    }    else {    handle_error (trace);    return 1;    }    return 0;   }         //! Called for every runtime warning. The first argument identifies
pike.git/lib/master.pike.in:2294:    sprintf("%O", args[0][*]));   #endif    break;       default:    werror ("%s warning: %s %O\n", capitalize (where), what, args);    }   }       - static mixed _charset_mod; + static object _charset_mod;      //! This function is called by cpp() when it wants to do   //! character code conversion.   string decode_charset(string data, string charset)   {    // werror(sprintf("decode_charset(%O, %O)\n", data, charset));       if (!_charset_mod) { -  mixed mod = resolv("Locale"); +  object mod = [object]resolv("Locale");    -  _charset_mod = mod && mod["Charset"]; +  _charset_mod = [object](mod && mod["Charset"]);    if (!_charset_mod) {    compile_warning("-", 0, "No Locale.Charset module!");    return 0;    }    }       object decoder;       catch { -  decoder = _charset_mod->decoder(charset); +  decoder = ([function(string:object)]_charset_mod->decoder)(charset);    };       if (!decoder) {    compile_warning("-", 0, sprintf("Unknown charset %O!", charset));    return 0;    } -  return decoder->feed(data)->drain(); +  return ([function(void:string)]([function(string:object)]decoder-> +  feed)(data)->drain)();   }            class Describer   {    int clipped=0;    int canclip=0;    mapping(mixed:int|string) ident = ([]);    int identcount = 0;
pike.git/lib/master.pike.in:2351:    stuff = identify_stack[-1];    identify_stack = identify_stack[..sizeof (identify_stack) - 2];    if (objectp (stuff) || functionp (stuff) || programp (stuff))    ident[stuff]++;    else if (arrayp (stuff)) {    if (!ident[stuff]++)    identify_stack += stuff;    }    else if (multisetp (stuff)) {    if (!ident[stuff]++) -  identify_stack += indices (stuff); +  identify_stack += indices([multiset]stuff);    }    else if (mappingp (stuff)) {    if (!ident[stuff]++) -  identify_stack += indices (stuff) + values (stuff); +  identify_stack += indices([mapping]stuff) + values([mapping]stuff);    }       }    }       string describe_string (string m, int maxlen)    {    canclip++;    if(sizeof(m) < maxlen)    {
pike.git/lib/master.pike.in:2411:    }       string describe_multiset (multiset m, int maxlen)    {    if(!sizeof(m)) return "(<>)";    else return "multiset["+sizeof(m)+"]";    }       string describe (mixed m, int maxlen)    { -  if (stringp (ident[m])) return ident[m]; +  if (stringp (ident[m])) return [string]ident[m];    else if (intp (ident[m]) && ident[m] > 1)    ident[m] = "@" + identcount++;       string res;    if (catch (res=sprintf("%t",m)))    res = "object"; // Object with a broken _sprintf(), probably.    switch(res)    {    case "int":    case "float":    return (string)m;    case "string": -  return describe_string (m, maxlen); +  return describe_string ([string]m, maxlen);    case "array": -  res = describe_array (m, maxlen); +  res = describe_array ([array]m, maxlen);    break;    case "mapping": -  res = describe_mapping (m, maxlen); +  res = describe_mapping ([mapping]m, maxlen);    break;    case "multiset": -  res = describe_multiset (m, maxlen); +  res = describe_multiset ([multiset]m, maxlen);    break;    case "function": -  if (string tmp=describe_function(m)) res = tmp; +  if (string tmp=describe_function([function]m)) res = tmp;    break;    case "program": -  if(string tmp=describe_program(m)) res = tmp; +  if(string tmp=describe_program([program]m)) res = tmp;    break;    default:    /* object or type. */    if (catch {    if(string tmp=sprintf("%O", m)) res = tmp;    }) {    // Extra paranoia case.    res = sprintf("Instance of %O", _typeof(m));    }    break;
pike.git/lib/master.pike.in:2466:    {    string ret="";       if(!sizeof(x)) return "";    if(maxlen<0) return ",,,"+sizeof(x);       int clip=min(maxlen/2,sizeof(x));    int len=maxlen;    int done=0;    -  // int loopcount=0; -  +     while(1)    { -  // if(loopcount>10000) werror("len=%d\n",len); +     array(string) z=allocate(clip);    array(int) isclipped=allocate(clip);    array(int) clippable=allocate(clip);    for(int e=0;e<clip;e++)    {    clipped=0;    canclip=0;    z[e]=describe(x[e],len);    isclipped[e]=clipped;    clippable[e]=canclip;    }       while(1)    { -  // if(loopcount>10000) werror("clip=%d maxlen=%d\n",clip,maxlen); +     string ret = z[..clip-1]*","; -  // if(loopcount>10000) werror("sizeof(ret)=%d z=%O isclipped=%O done=%d\n",sizeof(ret),z[..clip-1],isclipped[..clip-1],done); +     if(done || sizeof(ret)<=maxlen+1)    {    int tmp=sizeof(x)-clip-1; -  // if(loopcount>10000) werror("CLIPPED::::: %O\n",isclipped); +     clipped=`+(0,@isclipped);    if(tmp>=0)    {    clipped++;    ret+=",,,"+tmp;    }    canclip++;    return ret;    }       int last_newlen=len;    int newlen;    int clipsuggest;    while(1)    { -  // if(loopcount++ > 20000) return ""; -  // if(!(loopcount & 0xfff)) werror("GNORK\n"); +     int smallsize=0;    int num_large=0;    clipsuggest=0;       for(int e=0;e<clip;e++)    { -  // if(loopcount>10000) werror("sizeof(z[%d])=%d len=%d\n",e,sizeof(z[e]),len); -  +     if((sizeof(z[e])>=last_newlen || isclipped[e]) && clippable[e])    num_large++;    else    smallsize+=sizeof(z[e]);       if(num_large * 15 + smallsize < maxlen) clipsuggest=e+1;    }    -  // if(loopcount>10000) werror("num_large=%d maxlen=%d smallsize=%d clippsuggest=%d\n",num_large,maxlen,smallsize,clipsuggest); +     newlen=num_large ? (maxlen-smallsize)/num_large : 0;    -  // if(loopcount>10000) werror("newlen=%d\n",newlen); -  +     if(newlen<8 || newlen >= last_newlen) break;    last_newlen=newlen; -  // if(loopcount>10000) werror("len decreased, retrying.\n"); +     }       if(newlen < 8 && clip)    {    clip-= (clip/4) || 1;    if(clip > clipsuggest) clip=clipsuggest; -  // if(loopcount>10000) werror("clip decreased, retrying.\n"); +     }else{    len=newlen;    done++;    break;    }    }    }       return ret;    }
pike.git/lib/master.pike.in:2618:   //!   //! @note   //! The returned description will end with a proper indexing method   //! currently either @expr{"."@} or @expr{"->"@}.   string describe_module(object|program mod, array(object)|void ret_obj)   {    if (!mod) return ""; // efun or function in gmp(0).    program parent_fun;    if (objectp(mod)) {    parent_fun = object_program(mod); -  if (ret_obj) ret_obj[0] = mod; +  if (ret_obj) ret_obj[0] = [object]mod;    } else if (intp(mod)) {    // Function in gmp -  if (ret_obj) ret_obj[0] = mod; +  if (ret_obj) ret_obj[0] = [object]mod;    return sprintf("%O->", mod);    }else { -  parent_fun = mod; -  if (objectp (mod = objects[parent_fun]) && ret_obj) ret_obj[0] = mod; +  parent_fun = [program]mod; +  if (objectp (mod = objects[parent_fun]) && ret_obj) +  ret_obj[0] = [object]mod;    }    if (mod) {    catch {    string res = sprintf("%O", mod);    if (res != "object" && res != "")    return (objectp (objects[parent_fun]) && programs["/master"] != parent_fun?    res+".":res+"->");    };    }    if (!object_program(parent_fun)) {
pike.git/lib/master.pike.in:2655:    parent_obj);    // werror("So far: %O parent_obj:%O\n", res, parent_obj);    object|program parent =    objectp (parent_obj[0]) ? parent_obj[0] : object_program(parent_fun);    if (mod && (objectp (parent) || parent)) {    // Object identified.    catch {    // Check if we're an object in parent.    int i = search(values(parent), mod);    if (i >= 0) { -  return res + indices(parent)[i] + "."; +  return res + [string]indices(parent)[i] + ".";    }    };    }       // We're cloned from something in parent.    if (string fun_name = function_name(parent_fun)) {    return res + fun_name + "()->";    }       // No such luck.    // Try identifying a clone of ourselves.    if (!mod && (objectp (parent) || parent)) {    catch {    // Check if there's a clone of parent_fun in parent_obj.    int i;    array(mixed) val = values(parent); -  array(string) ind = indices(parent); +  array(string) ind = [array(string)]indices(parent);    for (i=0; i < sizeof(val); i++) {    if (objectp(val[i]) && object_program(val[i]) == parent_fun) {    return res + ind[i] + ".";    }    }    };    }       // We're really out of luck here...    return res + (describe_program(parent_fun)||"unknown_program") + "()->";   }      //!   string describe_object(object o)   {    string s;    if(zero_type (o)) return 0; // Destructed.    -  function parent_fun = object_program(o); +  function(mixed...:void|object) parent_fun = +  [function(mixed...:void|object)]object_program(o);       /* Constant object? */    catch {    object|program parent_obj =    (function_object(parent_fun) || function_program(parent_fun));       if (objectp (parent_obj) || parent_obj) {    /* Check if we have a constant object. */    object tmp = objects[parent_obj];    if (objectp (tmp)) parent_obj = tmp;
pike.git/lib/master.pike.in:2715:    if (objectp(o)) {    i = search(values(parent_obj), o);    } else {    i = search(map(values(parent_obj),    lambda(mixed x) {    if (objectp(x)) return object_program(x);    return 0;    }), o);    }    if (i >= 0) { -  s = indices(parent_obj)[i]; +  s = [string]indices(parent_obj)[i];    return describe_module(parent_obj) + s;    }    }    };    if(objectp (objects[parent_fun]))    if(s=get_clean_program_path(parent_fun, "", "", "()"))    return s;    /* Try identifying the program. */    if(( s=describe_program(parent_fun) ))    return s+"()";       return 0;   }      //! - string describe_program(program p) + string describe_program(program|function p)   {    string s;    if(!p) return 0;    -  if(s=get_clean_program_path(p, "object_program(", ")", "")) +  if(programp(p) && +  (s=get_clean_program_path([program]p, "object_program(", ")", "")))    return s;    -  if(mixed tmp=(function_object(p) || function_program(p))) { +  if(object|program tmp=(function_object(p) || function_program(p))) {    if(s = function_name(p))    {    return describe_module(tmp) + s;    }    }       if(s=_static_modules.Builtin()->program_defined(p))    return EXPLODE_PATH(s)[-1];       return 0;
pike.git/lib/master.pike.in:2769:    if(string s=search(programs,f))    {    if(has_suffix(s, ".pmod"))    name = EXPLODE_PATH(s[..sizeof(s)-6])[-1];    else    name = trim_file_name(s);    }    else    if (catch (name = function_name (f))) name = "function";    -  object o = function_object(f); +  object o = function_object([function(mixed...:void|mixed)]f);    if(objectp (o)) { // Check if it's an object in a way that (hopefully) doesn't    // call any functions in it (neither `== nor `!).    string s;    if (!catch (s = sprintf("%O",o)) && s != "object")    return s+"->"+name;    }    return name;   }      /* It is possible that this should be a real efun,
pike.git/lib/master.pike.in:2805:   {    int e;    string ret = "";    int backtrace_len=((int)getenv("PIKE_BACKTRACE_LEN")) || bt_max_string_len;       if(!linewidth)    {    linewidth=99999;    catch    { -  linewidth=_static_modules.files()->_stdin->tcgetattr()->columns; +  linewidth=[int]_static_modules.files()->_stdin->tcgetattr()->columns;    };    if(linewidth<10) linewidth=99999;    }    -  if((arrayp(trace) && sizeof(trace)==2 && stringp(trace[0])) || -  (objectp(trace) && trace->is_generic_error)) +  if((arrayp(trace) && sizeof([array]trace)==2 && stringp(([array]trace)[0]))|| +  (objectp(trace) && ([object]trace)->is_generic_error))    {    if (catch { -  ret = trace[0] || "No error message!\n"; -  trace = trace[1]; +  ret = ([array(string)]trace)[0]; +  if(!stringp(ret)) +  ret = "No error message!\n"; +  trace = ([array]trace)[1];    }) {    return "Error indexing backtrace!\n";    }    if(!arrayp(trace))    return ret + "No backtrace.\n";    }else    if (!arrayp (trace))    return sprintf ("Unrecognized backtrace format: %O\n", trace);       {    Describer desc = Describer();    desc->identify_parts (trace); -  +  array trace = [array]trace;       int end = 0;    if( (sizeof(trace)>1) &&    arrayp(trace[0]) && -  (sizeof(trace[0]) > 2) && -  (trace[0][2] == _main)) +  (sizeof([array]trace[0]) > 2) && +  (([array]trace[0])[2] == _main))    end = 1;       mapping(string:int) prev_pos = ([]);    array(string) frames = ({});    int loop_start = 0, loop_next, loops;       for(e = sizeof(trace)-1; e>=end; e--)    {    mixed tmp;    string row;    if (array err=[array]catch { -  tmp = ([array]trace)[e]; +  tmp = trace[e];    if(stringp(tmp))    {    row=[string]tmp;    }    else if(arrayp(tmp))    {    array tmp = [array]tmp;    string pos;    if(sizeof(tmp)>=2 && stringp(tmp[0])) {    if (intp(tmp[1])) {
pike.git/lib/master.pike.in:2867:    } else {    pos = sprintf("%s:Bad line %t",    trim_file_name([string]tmp[0]), tmp[1]);    }    }else{    string desc="Unknown program";    if(sizeof(tmp)>=3 && functionp(tmp[2]))    {    catch    { -  if(mixed tmp=function_object([function]tmp[2])) +  if(mixed tmp=function_object([function(mixed...: +  void|mixed)]tmp[2]))    if(tmp=object_program(tmp))    if(tmp=describe_program([program]tmp))    desc=[string]tmp;    };    }    pos=desc;    }       string data;