pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1: - /* $Id: master.pike.in,v 1.18 1998/04/23 18:35:55 marcus Exp $ + /* $Id: master.pike.in,v 1.19 1998/04/24 18:18:49 hubbe Exp $    *    * Master-file for Pike.    *    * Based on master.pike 1.67.    */      int is_absolute_path(string p)   {   #ifdef __NT__    p=replace(p,"\\","/");    if(sscanf(p,"%[a-zA-Z]:",string s) && sizeof(s)==1)    return 1; -  + #define IS_ABSOLUTE_PATH is_absolute_path + #else + #define IS_ABSOLUTE_PATH(X) ((X)[0]=='/')   #endif    return p[0]=='/';   }      string *explode_path(string p)   {   #ifdef __NT__    p=replace(p,"\\","/"); -  + #define EXPLODE_PATH(X) (replace((X),"\\","/")/"/") + #else + #define EXPLODE_PATH(X) ((X)/"/")   #endif    return p/"/";   }      string dirname(string x)   { -  string *tmp=explode_path(x); +  string *tmp=EXPLODE_PATH(x);    return tmp[..sizeof(tmp)-2]*"/";   }      string basename(string x)   { -  string *tmp=explode_path(x); +  string *tmp=EXPLODE_PATH(x);    return tmp[-1];   } -  + #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(mixed *trace);   object low_cast_to_object(string oname, string current_file);      string *pike_include_path=({});
pike.git/lib/master.pike.in:70:   }      string getcwd()   {    return current_path || (current_path=predef::getcwd());   }   #endif      string combine_path_with_cwd(string path)   { -  return combine_path(is_absolute_path(path)?"/":getcwd(),path); +  return combine_path(IS_ABSOLUTE_PATH(path)?"/":getcwd(),path);   }      #ifdef FILE_STAT_CACHE      #define FILE_STAT_CACHE_TIME 20      int invalidate_time;   mapping(string:multiset(string)) dir_cache = ([]);      mixed *master_file_stat(string x)   {    string file, dir=combine_path_with_cwd(x);    -  file=basename(dir); -  dir=dirname(dir); +  file=BASENAME(dir); +  dir=DIRNAME(dir);       multiset(string) d;    if(time() > invalidate_time)    {    dir_cache=([]);    invalidate_time=time()+FILE_STAT_CACHE_TIME;    }    if(zero_type(d=dir_cache[dir]))    {    if(string *tmp=get_dir(dir))
pike.git/lib/master.pike.in:179:   mapping (string:program) programs=(["/master":object_program(this_object())]);      #define capitalize(X) (upper_case((X)[..0])+(X)[1..])      static program low_findprog(string pname, string ext)   {    program ret;    array s;    string fname=pname+ext;    if(ret=programs[fname]) return ret; -  if( (s=master_file_stat(fname)) -  && s[1]>=0 ) +  if( (s=master_file_stat(fname)) && s[1]>=0 )    {    switch(ext)    {    case "":    case ".pike": -  +  if( (s=master_file_stat(fname+".o")) && s[1]>=0 ) +  { +  mixed err=catch { +  return decode_value(_static_modules.files()->Fd(fname+".o","r")->read(),Codec()); +  }; +  if(want_warnings) +  werror("Failed to decode %s.o\n",fname); +  }    if ( mixed e=catch { ret=compile_file(fname); } )    {    if(arrayp(e) &&    sizeof(e)==2 &&    arrayp(e[1]) &&    sizeof(e[1]) == sizeof(backtrace()))    e[1]=({});    throw(e);    }    break;
pike.git/lib/master.pike.in:237:      /* This function is called when the driver wants to cast a string    * to a program, this might be because of an explicit cast, an inherit    * or a implict cast. In the future it might receive more arguments,    * to aid the master finding the right program.    */   program cast_to_program(string pname, string current_file)   {    string ext;    string nname; -  array(string) tmp=explode_path(pname); +  array(string) tmp=EXPLODE_PATH(pname);       if(sscanf(reverse(tmp[-1]),"%s.%s",ext, nname))    {    ext="."+reverse(ext);    tmp[-1]=reverse(nname);    pname=tmp*"/";    }else{    ext="";    } -  if(is_absolute_path(pname)) +  if(IS_ABSOLUTE_PATH(pname))    {    pname=combine_path("/",pname);    return findprog(pname,ext);    }else{    string cwd;    if(current_file)    { -  cwd=dirname(current_file); +  cwd=DIRNAME(current_file);    }else{    cwd=getcwd();    }       if(program ret=findprog(combine_path(cwd,pname),ext))    return ret;       foreach(pike_program_path, string path)    if(program ret=findprog(combine_path(path,pname),ext))    return ret;
pike.git/lib/master.pike.in:442:   #endif       return fc[fullname]=UNDEFINED;   }      mixed handle_import(string what, string|void current_file)   {    string *tmp,path;    if(current_file)    { -  tmp=explode_path(current_file); +  tmp=EXPLODE_PATH(current_file);    tmp[-1]=what;    path=combine_path_with_cwd( tmp*"/");    }    return fc[path]=dirnode(path);   }      mixed resolv(string identifier, string|void current_file)   {    mixed ret;    string *tmp,path;
pike.git/lib/master.pike.in:492:    object tmp;    string a,b;    mixed *q;       foreach(env,a) if(sscanf(a,"%s=%s",a,b)) environment[a]=b;    add_constant("getenv",getenv);    add_constant("putenv",putenv);       add_constant("write",_static_modules.files()->_stdout->write);    -  add_program_path(getcwd()); // Rather important /Per -  +     // add path for architecture-shared files    add_include_path("¤share_prefix¤/include");    add_module_path("¤share_prefix¤/modules");       // add path for architecture-dependant files    add_include_path("¤lib_prefix¤/include");    add_module_path("¤lib_prefix¤/modules");       q=(getenv("PIKE_INCLUDE_PATH")||"")/":"-({""});    for(i=sizeof(q)-1;i>=0;i--) add_include_path(q[i]);
pike.git/lib/master.pike.in:616:    if (!tmp) {    werror("Couldn't find Hilfe.\n");    exit(1);    }    tmp->StdinHilfe();    exit(0);    } else {    argv=argv[1..];    }    +  argv[0]=combine_path_with_cwd(argv[0]);    program tmp=(program)argv[0];       if(!tmp)    {    werror("Pike: Couldn't find script to execute.\n");    exit(1);    }       object script=tmp();   
pike.git/lib/master.pike.in:649:      mixed inhibit_compile_errors;      void set_inhibit_compile_errors(mixed f)   {    inhibit_compile_errors=f;   }      string trim_file_name(string s)   { -  if(getenv("SHORT_PIKE_ERRORS")) return basename(s); +  if(getenv("SHORT_PIKE_ERRORS")) return BASENAME(s);    return s;   }      /*    * This function is called whenever a compiling error occurs,    * Nothing strange about it.    * Note that previous_object cannot be trusted in ths function, because    * the compiler calls this function.    */   void compile_error(string file,int line,string err)
pike.git/lib/master.pike.in:701:    * the compiler calls this function.    */   string handle_include(string f,    string current_file,    int local_include)   {    string *tmp, path;       if(local_include)    { -  tmp=explode_path(current_file); +  tmp=EXPLODE_PATH(current_file);    tmp[-1]=f;    path=combine_path_with_cwd(tmp*"/");    }    else    {    foreach(pike_include_path, path)    {    path=combine_path(path,f);    if(master_file_stat(path))    break;
pike.git/lib/master.pike.in:760:    }   }      string describe_program(program p)   {    string s;    if(!p) return 0;    if(s=search(programs,p))    {    if(sscanf(reverse(s),"%s.%s",string ext,string rest) && ext=="domp") -  return explode_path(reverse(rest))[-1]; +  return EXPLODE_PATH(reverse(rest))[-1];    return s;    }       if(functionp(p))    if(mixed tmp=function_object(p))    if(s=describe_program(object_program(tmp)))    return s+"."+function_name(p);    return 0;   }   
pike.git/lib/master.pike.in:850:    else    {    row="Destructed object";    }    ret+=row+"\n";    }    }       return ret;   } +  +  + class Codec + { +  mapping f=all_constants(); +  +  string nameof(mixed x) +  { +  if(mixed tmp=search(f,x)) +  return "efun:"+tmp; +  +  switch(sprintf("%t",x)) +  { +  case "program": +  if(mixed tmp=search(programs,x)) +  return tmp; +  +  if(mixed tmp=search(values(_static_modules), x)) +  return "_static_modules."+(indices(_static_modules)[tmp]); +  break; +  +  case "object": +  if(mixed tmp=search(objects,x)) +  if(tmp=search(programs,tmp)) +  return tmp; +  break; +  } +  return ([])[0]; +  } +  +  function functionof(string x) +  { +  if(sscanf(x,"efun:%s",x)) return f[x]; +  return 0; +  } +  +  object objectof(string x) +  { +  if(sscanf(x,"efun:%s",x)) return f[x]; +  return (object)x; +  } +  +  program programof(string x) +  { +  if(sscanf(x,"efun:%s",x)) return f[x]; +  +  return (program)x; +  } +  +  mixed encode_object(object x) +  { +  error("Cannot encode objects yet.\n"); +  } +  +  +  mixed decode_object(object x) +  { +  error("Cannot encode objects yet.\n"); +  } + }