pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1: - /* $Id: master.pike.in,v 1.60 1999/10/10 19:42:09 marcus Exp $ + /* $Id: master.pike.in,v 1.61 1999/10/15 23:07:40 hubbe 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:1108:   }      string read_include(string f)   {    AUTORELOAD_CHECK_FILE(f)    object o=_static_modules.files()->Fd();    if(o->open(f,"r"))    return o->read();   }    + int clipped=0; +    // FIXME   string stupid_describe(mixed m, int maxlen)   {    switch(string typ=sprintf("%t",m))    {    case "int":    case "float":    return (string)m;       case "string":    if(sizeof(m) < maxlen)    {    string t = sprintf("%O", m);    if (sizeof(t) < (maxlen + 2)) {    return t;    }    t = 0;    } -  +  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(maxlen<5) return "array["+sizeof(m)+"]"; +  if(maxlen<5) +  { +  clipped++; +  return "array["+sizeof(m)+"]"; +  }    return "({" + stupid_describe_comma_list(m,maxlen-2) +"})";       case "mapping":    if(!sizeof(m)) return "([])";    return "mapping["+sizeof(m)+"]";       case "multiset":    if(!sizeof(m)) return "(<>)";    return "multiset["+sizeof(m)+"]";   
pike.git/lib/master.pike.in:1170:       default:    return typ;    }   }      string stupid_describe_comma_list(array x, int maxlen)   {    string ret="";    +  if(!sizeof(x)) return "";    if(maxlen<0) return ",,,"+sizeof(x);    -  for(int pos=0;pos<sizeof(x);pos++) +  int clip=min(maxlen/2,sizeof(x)); +  int len=maxlen; +  +  while(1)    { -  string tmp=stupid_describe(x[pos],maxlen); -  if(pos) ret+=","; -  ret+=tmp; + // werror("len=%d\n",len); +  array(string) z=allocate(clip); +  array(int) isclipped=allocate(clip); +  for(int e=0;e<clip;e++) +  { +  clipped=0; +  z[e]=stupid_describe(x[e],len); +  isclipped[e]=clipped; +  }    -  if(sizeof(ret) >= maxlen) -  return ret+",,,"+(sizeof(x)-pos); +  while(1) +  { + // werror("clip=%d maxlen=%d\n",clip,maxlen); +  string ret = z[..clip-1]*","; + // werror("sizeof(ret)=%d z=%O isclipped=%O\n",sizeof(ret),z[..clip-1],isclipped[..clip-1]); +  if(sizeof(ret)<=maxlen+1) +  { +  int tmp=sizeof(x)-clip-1; + // werror("CLIPPED::::: %O\n",isclipped); +  clipped=`+(0,@isclipped); +  if(tmp>=0) +  { +  clipped++; +  ret+=",,,"+tmp;    }    return ret;    }    -  +  int last_newlen=len; +  int newlen; +  int clipsuggest; +  while(1) +  { +  int smallsize=0; +  int num_large=0; +  clipsuggest=0; +  +  for(int e=0;e<clip;e++) +  { + // werror("sizeof(z[%d])=%d len=%d\n",e,sizeof(z[e]),len); +  +  if(sizeof(z[e])>=last_newlen || isclipped[e]) +  num_large++; +  else +  smallsize+=sizeof(z[e]); +  +  if(num_large * 15 + smallsize < maxlen) clipsuggest=e+1; +  } +  + // werror("num_large=%d maxlen=%d smallsize=%d clippsuggest=%d\n",num_large,maxlen,smallsize,clipsuggest); +  newlen=num_large ? (maxlen-smallsize)/num_large : 0; +  + // werror("newlen=%d\n",newlen); +  +  if(newlen<8 || newlen >= last_newlen) break; +  last_newlen=newlen; + // werror("len decreased, retrying.\n"); +  } +  +  if(newlen < 8 && clip) +  { +  clip-= (clip/4) || 1; +  if(clip > clipsuggest) clip=clipsuggest; + // werror("clip decreased, retrying.\n"); +  }else{ +  len=newlen; +  break; +  } +  } +  } +  +  return ret; + } +    string describe_object(object o)   {    string s;    if(!o) return 0;    if(s=search(objects,object_program(o)))    {    if(sscanf(reverse(s),"%s.%s",string ext,string rest) && ext=="domp")    return EXPLODE_PATH(reverse(rest))[-1];    return s;    }
pike.git/lib/master.pike.in:1225:    if(s=_static_modules.Builtin()->program_defined(p))    return EXPLODE_PATH(s)[-1];       return 0;   }      /* 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) + string describe_backtrace(mixed trace, void|int linewidth)   {    int e;    string ret;    -  +  if(!linewidth) +  { +  linewidth=99999; +  catch +  { +  linewidth=_static_modules.files()->_stdin->tcgetattr()->columns; +  }; +  } +     if((arrayp(trace) && sizeof(trace)==2 && stringp(trace[0])) ||    (objectp(trace) && trace->is_generic_error))    {    if (catch {    ret = trace[0];    trace = trace[1];    }) {    return "Error indexing backtrace!\n";    }    }else{
pike.git/lib/master.pike.in:1252:       if(!arrayp(trace))    {    ret+="No backtrace.\n";    }else{    for(e = sizeof(trace)-1; e>=0; e--)    {    mixed tmp;    string row;    -  if (catch { +  if (mixed err=catch {    tmp = trace[e];    if(stringp(tmp))    { -  row = tmp; +  row=tmp;    }    else if(arrayp(tmp))    { -  row=""; -  if(sizeof(tmp)>=3) -  { -  if(functionp(tmp[2])) -  row = function_name(tmp[2]); -  else if (stringp(tmp[2])) { -  row = tmp[2]; -  } else -  row="unknown function"; -  -  row+="("+ -  stupid_describe_comma_list(tmp[3..], BT_MAX_STRING_LEN)+ -  ") in "; -  } -  +  string pos;    if(sizeof(tmp)>=2 && stringp(tmp[0]) && intp(tmp[1]))    { -  row+="line "+tmp[1]+" in "+trim_file_name(tmp[0]); +  pos=trim_file_name(tmp[0])+":"+tmp[1];    }else{    mixed desc="Unknown program";    if(sizeof(tmp)>=3 && functionp(tmp[2]))    {    catch {    if(mixed tmp=function_object(tmp[2]))    if(tmp=object_program(tmp))    if(tmp=describe_program(tmp))    desc=tmp;    };    } -  row+=desc; +  pos=desc;    } -  +  +  string data; +  +  if(sizeof(tmp)>=3) +  { +  if(functionp(tmp[2])) +  data = function_name(tmp[2]); +  else if (stringp(tmp[2])) { +  data= tmp[2]; +  } else +  data ="unknown function"; +  +  data+="("+ +  stupid_describe_comma_list(tmp[3..], BT_MAX_STRING_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="Destructed object";    }    }) { -  row = sprintf("Error indexing backtrace line %d!", e); +  row += sprintf("Error indexing backtrace line %d (%O)!", e, err[1]);    }    ret += row + "\n";    }    }       return ret;   }         class Codec