pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1:   /* -*- Pike -*-    * -  * $Id: master.pike.in,v 1.126 2000/08/27 18:29:26 mirar Exp $ +  * $Id: master.pike.in,v 1.127 2000/08/29 14:46:36 mast Exp $    *    * Master-file for Pike.    *    * Based on master.pike 1.67.    */      // Some configurable parameters useful for debugging      #define PIKE_AUTORELOAD   
pike.git/lib/master.pike.in:87:   }   #define DIRNAME dirname   #define BASENAME(X) (EXPLODE_PATH(X)[-1])      #define GETCWD_CACHE   #define FILE_STAT_CACHE      #define UNDEFINED (([])[0])   #define error(X) throw( ({ (X), backtrace()/*[0..sizeof(backtrace())-2]*/ }) )    - string describe_backtrace(array trace); - object low_cast_to_object(string oname, string current_file); -  +    array(string) pike_include_path=({});   array(string) pike_module_path=({});   array(string) pike_program_path=({});   int want_warnings = PIKE_WARNINGS;      #ifdef PIKE_AUTORELOAD      int autoreload_on;   int newest;   
pike.git/lib/master.pike.in:1392:       return path;   }      string read_include(string f)   {    AUTORELOAD_CHECK_FILE(f)    return master_read_file(f);   }    + class Describer + {    int clipped=0;    int canclip=0; -  +  mapping(mixed:int|string) ident = ([]); +  int identcount = 0;    - // FIXME - string stupid_describe(mixed m, int maxlen) +  void identify_parts (mixed stuff)    { -  string typ; +  if (arrayp (stuff)) { +  if (!ident[stuff]++) +  foreach (stuff, mixed elem) +  identify_parts (elem); +  } +  else if (multisetp (stuff)) { +  if (!ident[stuff]++) +  foreach (indices (stuff), mixed elem) +  identify_parts (elem); +  } +  else if (mappingp (stuff)) { +  if (!ident[stuff]++) +  foreach (indices (stuff), mixed elem) +  identify_parts (elem), identify_parts (stuff[elem]); +  } +  else if (objectp (stuff)) +  ident[stuff]++; +  } +  +  string describe (mixed m, int maxlen) +  { +  if (stringp (ident[m])) return ident[m]; +  else if (intp (ident[m]) && ident[m] > 1) +  ident[m] = "@" + identcount++; +  +  string res, typ;    if (catch (typ=sprintf("%t",m)))    typ = "object"; // Object with a broken _sprintf(), probably.    switch(typ)    {    case "int":    case "float":    return (string)m;       case "string":    canclip++;
pike.git/lib/master.pike.in:1426:    }    clipped++;    if(maxlen>10)    {    return sprintf("%O+[%d]",m[..maxlen-5],sizeof(m)-(maxlen-5));    }else{    return "string["+sizeof(m)+"]";    }       case "array": -  if(!sizeof(m)) return "({})"; +  if(!sizeof(m)) res = "({})"; +  else {    if(maxlen<5)    {    clipped++; -  return "array["+sizeof(m)+"]"; +  res = "array["+sizeof(m)+"]";    } -  +  else {    canclip++; -  return "({" + stupid_describe_comma_list(m,maxlen-2) +"})"; +  res = "({" + describe_comma_list(m,maxlen-2) +"})"; +  } +  } +  break;       case "mapping": -  if(!sizeof(m)) return "([])"; -  return "mapping["+sizeof(m)+"]"; +  if(!sizeof(m)) res = "([])"; +  else res = "mapping["+sizeof(m)+"]"; +  break;       case "multiset": -  if(!sizeof(m)) return "(<>)"; -  return "multiset["+sizeof(m)+"]"; +  if(!sizeof(m)) res = "(<>)"; +  else res = "multiset["+sizeof(m)+"]"; +  break;       case "function":    if(string tmp=describe_program(m)) return tmp; -  if(object o=function_object(m)) -  return (describe_object(o)||"")+"->"+function_name(m); +  if(object o=function_object(m)) { +  string s = describe_object(o); +  if (s && s != "object") return s+"->"+function_name(m); +  else return function_name(m); +  }    else {    string tmp;    if (catch (tmp = function_name(m)))    // The function object has probably been destructed.    return "function";    return tmp || "function";    }       case "program":    if(string tmp=describe_program(m)) return tmp;    return typ;       default:    if (objectp(m)) -  if(string tmp=describe_object(m)) return tmp; +  if(string tmp=describe_object(m)) { +  res = tmp; +  break; +  }    return typ;    } -  +  +  if (stringp (ident[m])) +  return ident[m] + "=" + res; +  return res;    }    - string stupid_describe_comma_list(array x, int maxlen) +  string describe_comma_list(array x, int maxlen)   {    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;   
pike.git/lib/master.pike.in:1489:    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]=stupid_describe(x[e],len); +  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)
pike.git/lib/master.pike.in:1561:    }else{    len=newlen;    done++;    break;    }    }    }       return ret;   } + }      string describe_object(object o)   {    string s;    if(!o) return 0;    if (!catch (s = sprintf("%O",o)) && s != "object") return s;    if(( s=describe_program(object_program(o)) ))    return s+"()";    return 0;   }
pike.git/lib/master.pike.in:1604:   /* It is possible that this should be a real efun,    * it is currently used by handle_error to convert a backtrace to a    * readable message.    */   string describe_backtrace(mixed trace, void|int linewidth)   {    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;    };    if(linewidth<10) linewidth=99999;    }   
pike.git/lib/master.pike.in:1632:    return "Error indexing backtrace!\n";    }    }else{    ret="";    }       if(!arrayp(trace))    {    ret+="No backtrace.\n";    }else{ +  Describer desc = Describer(); +  desc->identify_parts (trace); +     for(e = sizeof(trace)-1; e>=0; e--)    {    mixed tmp;    string row;    if( arrayp(trace[e]) &&    (sizeof(trace[e]) > 2) &&    (trace[e][2] == _main) &&    (sizeof(trace)>1) )    continue;    if (mixed err=catch {
pike.git/lib/master.pike.in:1690:    data = s + "->";    }    data += function_name(tmp[2]);    }    else if (stringp(tmp[2])) {    data= tmp[2];    } else    data ="unknown function";       data+="("+ -  stupid_describe_comma_list(tmp[3..], backtrace_len)+ +  desc->describe_comma_list(tmp[3..], backtrace_len)+    ")";       if(sizeof(pos)+sizeof(data) < linewidth-4)    {    row=sprintf("%s: %s",pos,data);    }else{    row=sprintf("%s:\n%s",pos,sprintf(" %*-/s",linewidth-6,data));    }    } else {    row = pos;