pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1: - /* -*- Pike -*- -  * -  * $Id: master.pike.in,v 1.194 2002/03/10 02:53:12 mast Exp $ -  * -  * Master-file for Pike. -  * -  * Based on master.pike 1.67. -  */ + // + // Master Control Program for Pike. + // + // This file is part of Pike. For copyright information see COPYRIGHT. + // Pike is distributed as GPL (General Public License) + // See the files COPYING and DISCLAIMER for more information. + // + // $Id: master.pike.in,v 1.195 2002/04/27 22:18:40 nilsson Exp $    - // Some configurable parameters useful for debugging -  +    #pike __REAL_VERSION__ -  +  + // --- Some configurable parameters +    #define PIKE_AUTORELOAD -  + #define GETCWD_CACHE + #define FILE_STAT_CACHE    -  + // This define is search and replaced by bin/install.pike. + #undef PIKE_MODULE_RELOC +  + #ifndef PIKE_WARNINGS + #define PIKE_WARNINGS 0 + #endif /* PIKE_WARNINGS */ +  +  + // --- Global constants and variables +    // Used by describe_backtrace() et al.   #if !defined(BT_MAX_STRING_LEN) || (BT_MAX_STRING_LEN <= 0)   #undef BT_MAX_STRING_LEN   #define BT_MAX_STRING_LEN 200   #endif /* !defined(BT_MAX_STRING_LEN) || (BT_MAX_STRING_LEN <= 0) */   constant bt_max_string_len = BT_MAX_STRING_LEN;      //! @decl constant bt_max_string_len = 200   //! This constant contains the maximum length of a function entry in a   //! backtrace. Defaults to 200 if no BT_MAX_STRING_LEN define has been
pike.git/lib/master.pike.in:28:   #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;      //! @decl constant out_of_date_warning = 1   //! Should Pike complain about out of date compiled files.   //! 1 means yes and 0 means no. Controlled by the OUT_OF_DATE_WARNING   //! define.    - #ifndef PIKE_WARNINGS - #define PIKE_WARNINGS 0 - #endif /* PIKE_WARNINGS */ + //! If not zero compilation warnings will be written out on stderr. + int want_warnings = PIKE_WARNINGS;    - #undef PIKE_MODULE_RELOC + //! + int compat_major=-1;    - /* -  * Functions begin here. -  */ + //! + int compat_minor=-1;    -  +  + // --- Functions begin here. +  + #define error(X) throw( ({ (X), backtrace()/*[0..sizeof(backtrace())-2]*/ }) ) + #define Stat _static_modules.files.Stat + #define capitalize(X) (upper_case((X)[..0])+(X)[1..]) +    // FIXME: Should the pikeroot-things be private?   #ifdef PIKE_FAKEROOT   object o;   string fakeroot(string s)   {    string tmp1=combine_path_with_cwd(s);   #ifdef PIKE_FAKEROOT_OMIT    foreach(PIKE_FAKEROOT_OMIT/":", string x)    if(glob(x,tmp1))    return s;   #endif    return PIKE_FAKEROOT+tmp1;   }   #else   #define fakeroot(X) X - #endif + #endif // PIKE_FAKEROOT      #ifdef PIKE_MODULE_RELOC   string relocate_module(string s)   {    if(s[..1]=="/$" && (s+"/")[..20] == "/${PIKE_MODULE_PATH}/") {    string tmp = s[21..];    foreach(pike_module_path, string path) {    string s2 = fakeroot(sizeof(tmp)? combine_path(path, tmp) : path);    if(master_file_stat(s2))    return s2;
pike.git/lib/master.pike.in:88:    string s2 = combine_path(path, "");    if(s[..sizeof(s2)-1] == s2)    return "/${PIKE_MODULE_PATH}/"+s[sizeof(s2)..];    }    return s;   }   #ifdef fakeroot   #undef fakeroot   #endif   #define fakeroot relocate_module - #endif + #endif // PIKE_MODULE_RELOC         //! @appears is_absolute_path   //! 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 __NT__
pike.git/lib/master.pike.in:148:   //! @appears basename   //! Returns the last segment of a path.   //!   //! @seealso   //! @[dirname()], @[explode_path()]   string basename(string x)   {    array(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 error(X) throw( ({ (X), backtrace()/*[0..sizeof(backtrace())-2]*/ }) ) -  - //! - int want_warnings = PIKE_WARNINGS; -  +    #ifdef PIKE_AUTORELOAD      int autoreload_on;   int newest;      #define AUTORELOAD_CHECK_FILE(X) \    if(autoreload_on) if(mixed fnord=master_file_stat(X)) if(fnord[3]>newest) newest=fnord[3];      #define AUTORELOAD_BEGIN() \    int ___newest=newest; \
pike.git/lib/master.pike.in:189:    if(___newest > newest) newest=___newest;         mapping(string:int) load_time=([]);   #else      #define AUTORELOAD_CHECK_FILE(X)   #define AUTORELOAD_BEGIN()   #define AUTORELOAD_FINISH(VAR,CACHE,FILE)    - #endif + #endif // PIKE_AUTORELOAD    - //! - int compat_major=-1; -  - //! - int compat_minor=-1; -  +    //! @appears compile_string   //! Compile the Pike code in the string @[source] into a program.   //! If @[filename] is not specified, it will default to @tt{"-"@}.   //!   //! Functionally equal to @code{@[compile](@[cpp](@[source], @[filename]))@}.   //!   //! @seealso   //! @[compile()], @[cpp()], @[compile_file()]   //!   program compile_string(string source, void|string filename,
pike.git/lib/master.pike.in:237:   int cd(string s)   {    current_path=0;    return predef::cd(s);   }      string getcwd()   {    return current_path || (current_path=predef::getcwd());   } - #endif + #endif // GETCWD_CACHE      string combine_path_with_cwd(string path)   {    return combine_path(IS_ABSOLUTE_PATH(path)?"/":getcwd(),path);   }    - #define Stat _static_modules.files.Stat +    #ifdef FILE_STAT_CACHE      #define FILE_STAT_CACHE_TIME 20      int invalidate_time;   mapping(string:multiset(string)) dir_cache = ([]);      Stat master_file_stat(string x)   {    string file, dir=combine_path_with_cwd(x);       file=BASENAME(dir); -  dir=DIRNAME(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(array(string) tmp=get_dir(dir))
pike.git/lib/master.pike.in:287:      #ifdef __NT__    file=lower_case(file);   #endif    if(d && !d[file]) return 0;       return predef::file_stat(x);   }   #else   #define master_file_stat file_stat - #endif + #endif // FILE_STAT_CACHE      mapping (string:array(string)) environment=([]);         //! @decl string getenv(string varname)   //! @decl mapping(string:string) getenv()   //! @appears getenv   //!   //! When called with no arguments, a mapping with all current environment   //! variables will be returned.
pike.git/lib/master.pike.in:404:   {   #ifndef __NT__    return path;   #else    return replace(path,"\\","/");   #endif   }      mapping (string:program) programs=(["/master":object_program(this_object())]);    - #define capitalize(X) (upper_case((X)[..0])+(X)[1..]) -  +    array(string) query_precompiled_names(string fname)   {    // Filenames of potential precompiled files in priority order.   #ifdef PRECOMPILED_SEARCH_MORE    // Search for precompiled files in all module directories, not just    // in the one where the source file is. This is useful when running    // pike directly from the build directory.    fname = fakeroot (fname);    // FIXME: Not sure if this works correctly with the fakeroot and    // module relocation stuff.
pike.git/lib/master.pike.in:446:      #ifdef THREADED    object key;    // FIXME: The catch is needed, since we might be called in    // a context when threads are disabled.    // (compile() disables threads).    mixed err = catch {    key=compilation_mutex->lock(2);    };    if (err) { -  werror(sprintf("low_findprog: Caught spurious error:\n" -  "%s\n", describe_backtrace(err))); +  werror( "low_findprog: Caught spurious error:\n" +  "%s\n", describe_backtrace(err) );    }   #endif      #ifdef PIKE_MODULE_RELOC    fname = unrelocate_module(fname);   #endif      #ifdef PIKE_AUTORELOAD    if(!autoreload_on || load_time[fname]>=time())   #endif
pike.git/lib/master.pike.in:522:    if (handler && handler->compile_warning) {    handler->compile_warning(oname, 0,    "Compiled file is out of date\n");    } else {    compile_warning(oname, 0, "Compiled file is out of date\n");    }    }    }    }    - // werror("2.5: %O\n",fname); +     programs[fname]=ret=__empty_program();    if ( mixed e=catch {    ret=compile_file(fname,    handler,    ret,    mkobj? (objects[ret]=__null_program()) : 0);    } )    { - // werror("-3: %O\n",fname); +     ret=programs[fname]=0;    throw(e);    }    break;   #if constant(load_module)    case ".so":    if (fname == "") { -  werror(sprintf("low_findprog(\"%s\", \"%s\") => load_module(\"\")\n" -  "%s\n", pname, ext, describe_backtrace(backtrace()))); +  werror( "low_findprog(\"%s\", \"%s\") => load_module(\"\")\n" +  "%s\n", pname, ext, describe_backtrace(backtrace()) );    }       ret=load_module(fakeroot(fname));   #endif /* load_module */    }       AUTORELOAD_FINISH(ret,programs,fname);    - // werror("3: %O (%O)\n",fname, ret); +     return programs[fname]=ret;    }    return 0;   }      //   // This function is called by the compiler when a delayed compilation   // error occurs in the given program. It should remove all references   // to the program so that it can be freed.   //
pike.git/lib/master.pike.in:616:    array(string) tmp=EXPLODE_PATH(pname);       // werror("low_cast_to_program(%O, %O, %O, %O)\n",    // pname, current_file, handler, mkobj);       if(sscanf(reverse(tmp[-1]),"%s.%s",ext, nname))    {    ext="."+reverse(ext);    tmp[-1]=reverse(nname);    pname=tmp*"/"; -  }else{ +  } +  else {    ext="";    } -  +     if(IS_ABSOLUTE_PATH(pname))    {    if (programs[pname])    return programs[pname];    pname=combine_path("/",pname);    return findprog(pname,ext,handler,mkobj); -  }else{ +  } +  else {    string cwd;    if(current_file)    { -  cwd=DIRNAME(current_file); -  }else{ +  cwd=dirname(current_file); +  } +  else {    cwd=getcwd();    }       if(program ret=findprog(combine_path(cwd,pname),ext,handler,mkobj))    return ret;       foreach(pike_program_path, string path)    if(program ret=findprog(combine_path(path,pname),ext,handler,mkobj))    return ret;   
pike.git/lib/master.pike.in:1385:    }    tmp += ({ ret });    } else {    if (mixed new_ret = ret->_module_value) {    ret = new_ret;    }    if (!sizeof(tmp)) {    return ret;    } else {    // Ignore -  werror(sprintf("Ignoring file %O: %t for identifier %O\n", -  file, ret, identifier)); +  werror( "Ignoring file %O: %t for identifier %O\n", +  file, ret, identifier );    continue;    }    }    }    }    if (sizeof(tmp)) {    if (sizeof(tmp) == 1) {    return(tmp[0]);    }    return joinnode(tmp);
pike.git/lib/master.pike.in:1831:       argv[0]=combine_path_with_cwd(argv[0]);       program prog;       mixed err = catch {    prog=(program)argv[0];    };       if (err) { -  werror(sprintf("Pike: Failed to compile script:\n" -  "%s\n", stringp(err[0])?err[0]:describe_backtrace(err))); +  werror( "Pike: Failed to compile script:\n" +  "%s\n", stringp(err[0])?err[0]:describe_backtrace(err) );    exit(1);    }       // FIXME: Isn't the following code dead?    if(!prog)    {    werror("Pike: Couldn't find script to execute\n(%O)\n",argv[0]);    exit(1);    }   
pike.git/lib/master.pike.in:1937:      //! 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)   {    mixed val;    if(! (val = get_inhibit_compile_errors() ))    { -  werror(sprintf("%s:%s:%s\n",trim_file_name(file), -  line?(string)line:"-",err)); +  werror( "%s:%s:%s\n",trim_file_name(file), +  line?(string)line:"-",err );    }    else if(objectp(val) ||    programp(val) ||    functionp(val))    {    if (objectp(val) && val->compile_error) {    val->compile_error(file, line, err);    } else {    val(file, line, err);    }
pike.git/lib/master.pike.in:1964:   //! Nothing strange about it.   //! Note that previous_object cannot be trusted in ths function, because   //! the compiler calls this function.   void compile_warning(string file,int line,string err)   {    mixed val;       if(!(val = get_inhibit_compile_errors() ))    {    if(want_warnings) -  werror(sprintf("%s:%s: Warning: %s\n",trim_file_name(file), -  line?(string)line:"-",err)); -  } else if (objectp(val) && val->compile_warning) { +  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);    }   }         //! 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)   {