2f520e | 2002-04-28 | Martin Nilsson | | //
// 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.
//
|
b38f14 | 2002-04-30 | Martin Nilsson | | // $Id: master.pike.in,v 1.196 2002/04/30 15:59:20 nilsson Exp $
|
c896b4 | 1998-04-29 | Henrik Grubbström (Grubba) | |
|
a580e1 | 2000-09-27 | Fredrik Hübinette (Hubbe) | | #pike __REAL_VERSION__
|
2f520e | 2002-04-28 | Martin Nilsson | |
// --- Some configurable parameters
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | #define PIKE_AUTORELOAD
|
2f520e | 2002-04-28 | Martin Nilsson | | #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
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | |
|
c896b4 | 1998-04-29 | Henrik Grubbström (Grubba) | | // Used by describe_backtrace() et al.
#if !defined(BT_MAX_STRING_LEN) || (BT_MAX_STRING_LEN <= 0)
#undef BT_MAX_STRING_LEN
|
a85820 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | #define BT_MAX_STRING_LEN 200
|
c896b4 | 1998-04-29 | Henrik Grubbström (Grubba) | | #endif /* !defined(BT_MAX_STRING_LEN) || (BT_MAX_STRING_LEN <= 0) */
|
d4fd0a | 1999-12-06 | Henrik Grubbström (Grubba) | | constant bt_max_string_len = BT_MAX_STRING_LEN;
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //! @decl constant bt_max_string_len = 200
|
8a4985 | 2002-03-10 | Martin Stjernholm | | //! 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
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //! given.
|
97e5c7 | 2001-07-28 | Martin Nilsson | |
|
e115cb | 1999-12-09 | Henrik Grubbström (Grubba) | | // Enables the out of date warning in low_find_prog().
#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;
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //! @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.
|
97e5c7 | 2001-07-28 | Martin Nilsson | |
|
2f520e | 2002-04-28 | Martin Nilsson | | //! If not zero compilation warnings will be written out on stderr.
int want_warnings = PIKE_WARNINGS;
|
df2c63 | 2000-08-02 | Henrik Grubbström (Grubba) | |
|
2f520e | 2002-04-28 | Martin Nilsson | | //!
int compat_major=-1;
|
4839dd | 2001-09-02 | Marcus Comstedt | |
|
2f520e | 2002-04-28 | Martin Nilsson | | //!
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..])
|
c896b4 | 1998-04-29 | Henrik Grubbström (Grubba) | |
|
6df5a5 | 2001-11-07 | Martin Nilsson | | // FIXME: Should the pikeroot-things be private?
|
26f3da | 2000-07-11 | Fredrik Hübinette (Hubbe) | | #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
|
2f520e | 2002-04-28 | Martin Nilsson | | #endif // PIKE_FAKEROOT
|
26f3da | 2000-07-11 | Fredrik Hübinette (Hubbe) | |
|
4839dd | 2001-09-02 | Marcus Comstedt | | #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;
}
}
return fakeroot(s);
}
string unrelocate_module(string s)
{
if(s[..1]=="/$" && (s+"/")[..20] == "/${PIKE_MODULE_PATH}/")
return s;
foreach(pike_module_path, string path)
if(s == path)
return "/${PIKE_MODULE_PATH}";
else {
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
|
2f520e | 2002-04-28 | Martin Nilsson | | #endif // PIKE_MODULE_RELOC
|
4839dd | 2001-09-02 | Marcus Comstedt | |
|
26f3da | 2000-07-11 | Fredrik Hübinette (Hubbe) | |
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears is_absolute_path
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Check if a path @[p] is fully qualified (ie not relative).
//!
//! @returns
//! Returns 1 if the path is absolute, 0 otherwise.
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | int is_absolute_path(string p)
{
#ifdef __NT__
p=replace(p,"\\","/");
|
e49e54 | 2001-01-22 | Fredrik Hübinette (Hubbe) | | if(sscanf(p,"%[a-zA-Z]:%*c",string s)==2 && sizeof(s)==1)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return 1;
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | #define IS_ABSOLUTE_PATH is_absolute_path
#else
#define IS_ABSOLUTE_PATH(X) ((X)[0]=='/')
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | #endif
return p[0]=='/';
}
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears explode_path
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Split a path @[p] into its components.
//!
//! This function divides a path into its components. This might seem like
//! it could be done by dividing the string on <tt>"/"</tt>, but that will
//! not work on some operating systems.
//!
|
bbf470 | 2000-04-10 | Henrik Grubbström (Grubba) | | array(string) explode_path(string p)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
#ifdef __NT__
p=replace(p,"\\","/");
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | #define EXPLODE_PATH(X) (replace((X),"\\","/")/"/")
#else
#define EXPLODE_PATH(X) ((X)/"/")
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | #endif
return p/"/";
}
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears dirname
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Returns all but the last segment of a path.
//!
//! @seealso
//! @[basename()], @[explode_path()]
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | string dirname(string x)
{
|
afa129 | 2000-02-19 | Martin Nilsson | | array(string) tmp=EXPLODE_PATH(x);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return tmp[..sizeof(tmp)-2]*"/";
}
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears basename
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Returns the last segment of a path.
//!
//! @seealso
//! @[dirname()], @[explode_path()]
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | string basename(string x)
{
|
afa129 | 2000-02-19 | Martin Nilsson | | array(string) tmp=EXPLODE_PATH(x);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return tmp[-1];
}
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | #define BASENAME(X) (EXPLODE_PATH(X)[-1])
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | #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; \
newest=0
#define AUTORELOAD_FINISH(VAR, CACHE, FILE) \
if(autoreload_on) { \
if(CACHE [ FILE ] && newest <= load_time[FILE]) { \
VAR = CACHE [ FILE ]; \
} \
} \
load_time[FILE]=time(); \
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)
|
2f520e | 2002-04-28 | Martin Nilsson | | #endif // PIKE_AUTORELOAD
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears compile_string
|
56cd00 | 2001-10-28 | Martin Nilsson | | //! Compile the Pike code in the string @[source] into a program.
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! 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,
object|void handler)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
d2777c | 2001-03-26 | Henrik Grubbström (Grubba) | | return compile(cpp(source, filename||"-", 1, handler,
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | compat_major, compat_minor),
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | handler,
compat_major,
compat_minor);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //!
|
d8a6fc | 2000-03-25 | Fredrik Hübinette (Hubbe) | | string master_read_file(string file)
{
object o=_static_modules.files()->Fd();
|
26f3da | 2000-07-11 | Fredrik Hübinette (Hubbe) | | if(o->open(fakeroot(file),"r"))
|
d8a6fc | 2000-03-25 | Fredrik Hübinette (Hubbe) | | return o->read();
return 0;
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | #ifdef GETCWD_CACHE
string current_path;
int cd(string s)
{
current_path=0;
return predef::cd(s);
}
string getcwd()
{
return current_path || (current_path=predef::getcwd());
}
|
2f520e | 2002-04-28 | Martin Nilsson | | #endif // GETCWD_CACHE
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
string combine_path_with_cwd(string path)
{
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | return combine_path(IS_ABSOLUTE_PATH(path)?"/":getcwd(),path);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
#ifdef FILE_STAT_CACHE
#define FILE_STAT_CACHE_TIME 20
int invalidate_time;
mapping(string:multiset(string)) dir_cache = ([]);
|
61a424 | 2000-08-27 | Mirar (Pontus Hagland) | | Stat master_file_stat(string x)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
string file, dir=combine_path_with_cwd(x);
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | file=BASENAME(dir);
|
2f520e | 2002-04-28 | Martin Nilsson | | dir=dirname(dir);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
multiset(string) d;
if(time() > invalidate_time)
{
dir_cache=([]);
invalidate_time=time()+FILE_STAT_CACHE_TIME;
}
if(zero_type(d=dir_cache[dir]))
{
|
afa129 | 2000-02-19 | Martin Nilsson | | if(array(string) tmp=get_dir(dir))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
fc398b | 2001-05-31 | Fredrik Hübinette (Hubbe) | | #ifdef __NT__
tmp=map(tmp, lower_case);
#endif
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | d=dir_cache[dir]=aggregate_multiset(@tmp);
}else{
dir_cache[dir]=0;
}
}
|
fc398b | 2001-05-31 | Fredrik Hübinette (Hubbe) | | #ifdef __NT__
file=lower_case(file);
#endif
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | if(d && !d[file]) return 0;
return predef::file_stat(x);
}
#else
#define master_file_stat file_stat
|
2f520e | 2002-04-28 | Martin Nilsson | | #endif // FILE_STAT_CACHE
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
a71f83 | 2001-11-13 | Tomas Nilsson | | mapping (string:array(string)) environment=([]);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
fc398b | 2001-05-31 | Fredrik Hübinette (Hubbe) | |
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! @decl string getenv(string varname)
//! @decl mapping(string:string) getenv()
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears getenv
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //!
|
a71f83 | 2001-11-13 | Tomas Nilsson | | //! When called with no arguments, a mapping with all current environment
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! variables will be returned.
//!
//! If the @[varname] argument has been given, the value of the environment
//! variable with the name @[varname] will be returned. If no such
//! environment variable exists, @tt{0@} (zero) will be returned.
//!
|
a71f83 | 2001-11-13 | Tomas Nilsson | | //! On NT the environment variable name is case insensitive.
//!
|
944d5b | 1999-12-05 | Henrik Grubbström (Grubba) | | string|mapping(string:string) getenv(string|void s)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
a71f83 | 2001-11-13 | Tomas Nilsson | | if(!s) return aggregate_mapping( @(values(environment)*({}) ) );
#ifdef __NT__
s = lower_case(s);
#endif
return environment[s] && environment[s][1];
|
df2c63 | 2000-08-02 | Henrik Grubbström (Grubba) | | }
|
fc398b | 2001-05-31 | Fredrik Hübinette (Hubbe) | |
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears compile_file
|
fc398b | 2001-05-31 | Fredrik Hübinette (Hubbe) | | //! Compile the Pike code contained in the file @[filename] into a program.
//!
//! This function will compile the file @[filename] to a Pike program that can
//! later be instantiated. It is the same as doing
//! @code{@[compile_string](@[Stdio.read_file](@[filename]), @[filename])@}.
//!
//! @seealso
//! @[compile()], @[compile_string()], @[cpp()]
//!
program compile_file(string filename,
object|void handler,
void|program p,
void|object o)
{
AUTORELOAD_CHECK_FILE(filename);
return compile(cpp(master_read_file(filename),
filename,
1,
handler,
compat_major,
compat_minor),
handler,
compat_major,
compat_minor,
p,
o);
}
|
df2c63 | 2000-08-02 | Henrik Grubbström (Grubba) | | #if 0
variant mapping(string:string) getenv()
{
return environment + ([]);
}
variant string getenv(string s)
{
return environment[s];
}
function(:mapping(string:string))|function(string:string) getenv(s)
{
if(!s) return environment + ([]);
return environment[s];
}
|
b07e96 | 2001-07-27 | Martin Nilsson | | // mapping(string:string) getenv() |
|
df2c63 | 2000-08-02 | Henrik Grubbström (Grubba) | | string getenv(string s)
{
if(!s) return environment + ([]);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return environment[s];
}
|
df2c63 | 2000-08-02 | Henrik Grubbström (Grubba) | | #endif /* 0 */
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears putenv
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Sets the environment variable @[varname] to @[value].
//!
|
a71f83 | 2001-11-13 | Tomas Nilsson | | //! On NT the environment variable name is case insensitive.
//!
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! @seealso
//! @[getenv()]
//!
void putenv(string varname, string value)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
a71f83 | 2001-11-13 | Tomas Nilsson | | string index = varname;
#ifdef __NT__
index = lower_case(varname);
if (environment[index] && environment[index][0])
varname = environment[index][0];
#endif
environment[index] = ({ varname, value });
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears normalize_path
|
c57eda | 2001-08-29 | Martin Nilsson | | //! Replaces "\" with "/" if runing on MS Windows. It is
|
c2d49b | 2002-02-14 | Martin Nilsson | | //! adviced to use @[System.normalize_path] instead.
|
c57eda | 2001-08-29 | Martin Nilsson | | string normalize_path( string path )
|
4c3f7d | 2000-04-13 | Per Hedbor | | {
#ifndef __NT__
|
c57eda | 2001-08-29 | Martin Nilsson | | return path;
|
4c3f7d | 2000-04-13 | Per Hedbor | | #else
|
c57eda | 2001-08-29 | Martin Nilsson | | return replace(path,"\\","/");
|
4c3f7d | 2000-04-13 | Per Hedbor | | #endif
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
mapping (string:program) programs=(["/master":object_program(this_object())]);
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | array(string) query_precompiled_names(string fname)
{
// Filenames of potential precompiled files in priority order.
|
8a4985 | 2002-03-10 | Martin Stjernholm | | #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.
foreach (pike_module_path, string path)
if (has_prefix (fname, path))
return map (pike_module_path, `+, "/", fname[sizeof (path)..], ".o");
#endif
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | return ({ fname + ".o" });
}
|
633019 | 2000-02-10 | Fredrik Hübinette (Hubbe) | | #if constant(_static_modules.Builtin.mutex)
#define THREADED
object compilation_mutex = _static_modules.Builtin()->mutex();
#endif
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | static program low_findprog(string pname,
string ext,
object|void handler,
void|int mkobj)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
program ret;
|
61a424 | 2000-08-27 | Mirar (Pontus Hagland) | | Stat s;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | string fname=pname+ext;
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | |
|
633019 | 2000-02-10 | Fredrik Hübinette (Hubbe) | | #ifdef THREADED
|
3b1142 | 2000-02-13 | Henrik Grubbström (Grubba) | | object key;
// FIXME: The catch is needed, since we might be called in
// a context when threads are disabled.
// (compile() disables threads).
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | mixed err = catch {
|
3b1142 | 2000-02-13 | Henrik Grubbström (Grubba) | | key=compilation_mutex->lock(2);
};
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | if (err) {
|
2f520e | 2002-04-28 | Martin Nilsson | | werror( "low_findprog: Caught spurious error:\n"
"%s\n", describe_backtrace(err) );
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | }
|
633019 | 2000-02-10 | Fredrik Hübinette (Hubbe) | | #endif
|
4839dd | 2001-09-02 | Marcus Comstedt | | #ifdef PIKE_MODULE_RELOC
fname = unrelocate_module(fname);
#endif
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | #ifdef PIKE_AUTORELOAD
if(!autoreload_on || load_time[fname]>=time())
#endif
{
|
6e2ebb | 1999-12-28 | Martin Stjernholm | | if(!zero_type (ret=programs[fname])) return ret;
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | }
|
41ee48 | 2000-02-28 | Fredrik Hübinette (Hubbe) | | #ifdef __NT__
// Ugly kluge to work better with cygwin32
if(getenv("OSTYPE")=="cygwin32")
{
string tmp=fname[..1];
if((tmp=="//" || tmp=="\\\\") && (fname[3]=='/' || fname[3]=='\\'))
{
if(!master_file_stat(fname))
{
fname=fname[2..2]+":"+fname[3..];
}
}
}
#endif
|
26f3da | 2000-07-11 | Fredrik Hübinette (Hubbe) | | if( (s=master_file_stat(fakeroot(fname))) && s[1]>=0 )
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | AUTORELOAD_BEGIN();
|
14fc64 | 1999-11-26 | Henrik Grubbström (Grubba) | |
|
6e2ebb | 1999-12-28 | Martin Stjernholm | | #ifdef PIKE_AUTORELOAD
|
14fc64 | 1999-11-26 | Henrik Grubbström (Grubba) | | if (load_time[fname] > s[3])
|
6e2ebb | 1999-12-28 | Martin Stjernholm | | if (!zero_type (ret=programs[fname])) return ret;
#endif
|
14fc64 | 1999-11-26 | Henrik Grubbström (Grubba) | |
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | switch(ext)
{
case "":
case ".pike":
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | foreach(query_precompiled_names(fname), string oname) {
|
61a424 | 2000-08-27 | Mirar (Pontus Hagland) | | if(Stat s2=master_file_stat(fakeroot(oname)))
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | {
if(s2[1]>=0 && s2[3]>=s[3])
{
mixed err=catch {
AUTORELOAD_CHECK_FILE(oname);
return programs[fname] =
|
d8a6fc | 2000-03-25 | Fredrik Hübinette (Hubbe) | | decode_value(master_read_file(oname),
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | Codec(fname,mkobj));
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | };
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | | m_delete(programs, fname);
if (handler && handler->compile_warning) {
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | handler->compile_warning(oname, 0,
sprintf("Decode failed:\n"
|
88a2fa | 2001-08-16 | Martin Stjernholm | | "\t%s", describe_error(err)));
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | } else {
compile_warning(oname, 0,
sprintf("Decode failed:\n"
|
88a2fa | 2001-08-16 | Martin Stjernholm | | "\t%s", describe_error(err)));
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | }
|
e115cb | 1999-12-09 | Henrik Grubbström (Grubba) | | } else if (out_of_date_warning) {
|
280de7 | 2002-03-08 | Martin Stjernholm | | if (handler && handler->compile_warning) {
|
6d926c | 1999-11-26 | Henrik Grubbström (Grubba) | | handler->compile_warning(oname, 0,
"Compiled file is out of date\n");
} else {
compile_warning(oname, 0, "Compiled file is out of date\n");
}
|
10e16f | 1999-11-04 | Henrik Grubbström (Grubba) | | }
|
b08596 | 1998-05-19 | Fredrik Hübinette (Hubbe) | | }
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | |
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | programs[fname]=ret=__empty_program();
if ( mixed e=catch {
ret=compile_file(fname,
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | handler,
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | ret,
mkobj? (objects[ret]=__null_program()) : 0);
} )
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | ret=programs[fname]=0;
|
c46d68 | 2000-01-05 | Martin Stjernholm | | throw(e);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
break;
#if constant(load_module)
case ".so":
|
caa322 | 1998-04-15 | Henrik Grubbström (Grubba) | | if (fname == "") {
|
2f520e | 2002-04-28 | Martin Nilsson | | werror( "low_findprog(\"%s\", \"%s\") => load_module(\"\")\n"
"%s\n", pname, ext, describe_backtrace(backtrace()) );
|
caa322 | 1998-04-15 | Henrik Grubbström (Grubba) | | }
|
26f3da | 2000-07-11 | Fredrik Hübinette (Hubbe) | |
ret=load_module(fakeroot(fname));
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | #endif /* load_module */
}
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | |
AUTORELOAD_FINISH(ret,programs,fname);
|
6e2ebb | 1999-12-28 | Martin Stjernholm | |
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return programs[fname]=ret;
}
|
6e2ebb | 1999-12-28 | Martin Stjernholm | | return 0;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | //
|
a002d3 | 2002-03-01 | Martin Stjernholm | | // 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.
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | //
void unregister(program p)
{
|
a002d3 | 2002-03-01 | Martin Stjernholm | | if(string fname=search(programs,p)) {
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | m_delete(programs, fname);
|
a002d3 | 2002-03-01 | Martin Stjernholm | | // FIXME: The following assumes that programs are always stored
// with '/' as path separators, even on NT. Haven't checked if
// that always is the case.
fname = dirname (fname);
if (object n = fname != "" && fc[fname])
if (n->is_resolv_dirnode || n->is_resolv_joinnode)
n->delete_value (p);
}
|
c6cf60 | 2001-12-13 | Martin Stjernholm | | if (zero_type(objects[p]) != 1)
m_delete(objects, p);
foreach (fc; string name; mixed mod)
if (objectp(mod) && object_program(mod) == p)
m_delete(fc, name);
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | }
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | static program findprog(string pname,
string ext,
object|void handler,
void|int mkobj)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
switch(ext)
{
case ".pike":
case ".so":
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | return low_findprog(pname,ext,handler, mkobj);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
default:
pname+=ext;
return
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | low_findprog(pname,"", handler, mkobj) ||
low_findprog(pname,".pike", handler, mkobj) ||
low_findprog(pname,".so", handler, mkobj);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
}
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | program low_cast_to_program(string pname,
string current_file,
object|void handler,
void|int mkobj)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
string ext;
string nname;
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | array(string) tmp=EXPLODE_PATH(pname);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | // werror("low_cast_to_program(%O, %O, %O, %O)\n",
// pname, current_file, handler, mkobj);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | if(sscanf(reverse(tmp[-1]),"%s.%s",ext, nname))
{
ext="."+reverse(ext);
tmp[-1]=reverse(nname);
pname=tmp*"/";
|
2f520e | 2002-04-28 | Martin Nilsson | | }
else {
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | ext="";
}
|
2f520e | 2002-04-28 | Martin Nilsson | |
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | if(IS_ABSOLUTE_PATH(pname))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
941de6 | 2001-06-21 | Marcus Wellhardh | | if (programs[pname])
return programs[pname];
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | pname=combine_path("/",pname);
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | return findprog(pname,ext,handler,mkobj);
|
2f520e | 2002-04-28 | Martin Nilsson | | }
else {
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | string cwd;
if(current_file)
{
|
2f520e | 2002-04-28 | Martin Nilsson | | cwd=dirname(current_file);
}
else {
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | cwd=getcwd();
}
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | if(program ret=findprog(combine_path(cwd,pname),ext,handler,mkobj))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return ret;
foreach(pike_program_path, string path)
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | if(program ret=findprog(combine_path(path,pname),ext,handler,mkobj))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return ret;
return 0;
}
}
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | |
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //! 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.
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | program cast_to_program(string pname,
string current_file,
object|void handler)
{
return low_cast_to_program(pname, current_file, handler);
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //! This function is called when an error occurs that is not caught
//! with catch().
|
06d6d3 | 1999-12-13 | Henrik Grubbström (Grubba) | | void handle_error(array(mixed)|object trace)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
62e87b | 1998-04-14 | Fredrik Hübinette (Hubbe) | | if(mixed x=catch {
werror(describe_backtrace(trace));
|
d28a71 | 2001-07-02 | Henrik Grubbström (Grubba) | | }) {
|
9f7109 | 2000-11-20 | Martin Stjernholm | | // One reason for this might be too little stack space, which
// easily can occur for "out of stack" errors. It should help to
// tune up the STACK_MARGIN values in interpret.c then.
|
62e87b | 1998-04-14 | Fredrik Hübinette (Hubbe) | | werror("Error in handle_error in master object:\n");
|
9f7109 | 2000-11-20 | Martin Stjernholm | | if(catch {
|
d28a71 | 2001-07-02 | Henrik Grubbström (Grubba) | | catch {
if (catch {
string msg = x[0];
array bt = x[1];
werror("%s%O\n", msg, bt);
}) {
werror("%O\n", x);
}
};
werror("Original error:\n"
"%O\n", trace);
|
aa73fc | 1999-10-21 | Fredrik Hübinette (Hubbe) | | }) {
werror("sprintf() failed to write error.\n");
}
|
62e87b | 1998-04-14 | Fredrik Hübinette (Hubbe) | | }
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! @decl object new(string|program prog, mixed ... args)
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears new
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //!
//! Instantiate a program.
//!
//! A new instance of the class @[prog] will be created.
//! All global variables in the new object be initialized, and
//! then @[create()] will be called with @[args] as arguments.
//!
//! @note
//! These two functions are considered obsolete, use
//! @code{((program)@[prog])(@@@[args])@}
//! instead.
//!
//! @seealso
//! @[destruct()], @[compile_string()], @[compile_file()]
//!
object new(string|program prog, mixed ... args)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
if(stringp(prog))
|
67276c | 1999-04-08 | Fredrik Hübinette (Hubbe) | | {
if(program p=cast_to_program(prog,backtrace()[-2][0]))
return p(@args);
else
error(sprintf("new: failed to find program %s.\n",prog));
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return prog(@args);
}
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @decl object clone(string|program prog, mixed ... args)
//! @appears clone
//!
//! @seealso
//! @[new()]
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | function clone = new;
/* This array contains the names of the functions
* that a replacing master-object may want to override.
*/
constant master_efuns = ({
"basename",
"dirname",
"is_absolute_path",
"explode_path",
"compile_string",
"compile_file",
"add_include_path",
"remove_include_path",
"add_module_path",
"remove_module_path",
"add_program_path",
"remove_program_path",
"describe_backtrace",
|
a66ff2 | 2000-01-11 | Martin Stjernholm | | "describe_error",
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | "new",
"clone",
|
4c3f7d | 2000-04-13 | Per Hedbor | | "normalize_path",
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | "getenv",
"putenv",
#ifdef GETCWD_CACHE
"cd",
"getcwd",
#endif
});
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | /* Note that create is called before add_precompiled_program
*/
void create()
{
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | object o = this_object();
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | foreach(master_efuns, string e) {
if (o[e]) {
add_constant(e, o[e]);
} else {
throw(({ sprintf("Function %O is missing from master.pike.\n", e),
backtrace() }));
}
}
add_constant("strlen", sizeof);
add_constant("write", _static_modules.files()->_stdout->write);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
87f908 | 2001-03-12 | Fredrik Hübinette (Hubbe) | | #define CO(X) add_constant(#X,_static_modules.Builtin.__backend->X)
CO(call_out);
CO(_do_call_outs);
CO(find_call_out);
CO(remove_call_out);
CO(call_out_info);
|
e37a3e | 1999-10-09 | Fredrik Hübinette (Hubbe) | | #if "¤share_prefix¤"[0]!='¤'
// add path for architecture-dependant files
add_include_path("¤share_prefix¤/include");
add_module_path("¤share_prefix¤/modules");
#endif
#if "¤lib_prefix¤"[0]!='¤'
// add path for architecture-dependant files
add_include_path("¤lib_prefix¤/include");
add_module_path("¤lib_prefix¤/modules");
#endif
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
97e5c7 | 2001-07-28 | Martin Nilsson | |
//! This function is called whenever a inherit is called for.
//! It is supposed to return the program to inherit.
//! The first argument is the argument given to inherit, and the second
//! is the file name of the program currently compiling. Note that the
//! file name can be changed with #line, or set by compile_string, so
//! it can not be 100% trusted to be a filename.
//! previous_object(), can be virtually anything in this function, as it
//! is called from the compiler.
|
10e16f | 1999-11-04 | Henrik Grubbström (Grubba) | | program handle_inherit(string pname, string current_file, object|void handler)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
10e16f | 1999-11-04 | Henrik Grubbström (Grubba) | | return cast_to_program(pname, current_file, handler);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
mapping (program:object) objects=([object_program(this_object()):this_object()]);
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | object low_cast_to_object(string oname, string current_file,
object|void current_handler)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
program p;
object o;
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | p = low_cast_to_program(oname, current_file, current_handler, 1);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | if(!p) return 0;
if(!(o=objects[p])) o=objects[p]=p();
return o;
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //! This function is called when the drivers wants to cast a string
//! to an object because of an implict or explicit cast. This function
//! may also receive more arguments in the future.
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | object cast_to_object(string oname, string current_file)
{
if(object o=low_cast_to_object(oname, current_file))
return o;
|
ac0fed | 2000-03-25 | Fredrik Hübinette (Hubbe) | | error("Cast '"+oname+"' to object failed"+
|
b1693a | 2000-04-07 | Fredrik Hübinette (Hubbe) | | ((current_file && current_file!="-")?sprintf(" for '%s'",current_file):"")+".\n");
|
ac0fed | 2000-03-25 | Fredrik Hübinette (Hubbe) | | return 0;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | class dirnode
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | string dirname;
object|void handler;
|
481748 | 2000-05-11 | Martin Stjernholm | | constant is_resolv_dirnode = 1;
|
14bb59 | 2000-05-06 | Fredrik Hübinette (Hubbe) | | mixed module=module_checker();
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | mapping(string:mixed) cache=([]);
array(string) files;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | void create(string d, object|void h)
{
|
acd163 | 2001-12-17 | Henrik Grubbström (Grubba) | | #ifdef MODULE_TRACE
werror("%*ndirnode(%O,%O);\n",sizeof(backtrace())-1,d,h);
// werror(describe_backtrace( ({"HERE\n",backtrace()})));
#endif
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | dirname=d;
handler=h;
fc[dirname]=this_object();
if(dirname[sizeof(dirname)-5..]==".pmod")
fc[dirname[..sizeof(dirname)-6]]=this_object();
}
|
14bb59 | 2000-05-06 | Fredrik Hübinette (Hubbe) | | class module_checker
{
int `!()
{
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*ndirnode(%O)->module_checker()->`!()\n",sizeof(backtrace()),dirname);
#endif
|
fd4cb1 | 2001-12-16 | Martin Stjernholm | | if(module=findmodule(dirname+"/module", handler))
{
if(mixed tmp=module->_module_value)
module=tmp;
/* This allows for `[] to have side effects first time
* it is called. (Specifically, the Calendar module uses
* this
*/
cache=([]);
_cache_full=0;
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | }
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | |
|
14bb59 | 2000-05-06 | Fredrik Hübinette (Hubbe) | | return !module;
}
|
52c579 | 2000-05-23 | Fredrik Hübinette (Hubbe) | |
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | mixed `[](string index)
|
cd9971 | 2001-11-09 | Martin Stjernholm | | {
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*ndirnode(%O)->module_checker()[%O]\n",sizeof(backtrace()),dirname,index);
#endif
if(module) return module[index];
}
|
52c579 | 2000-05-23 | Fredrik Hübinette (Hubbe) | | array(string) _indices() { if(module) return indices(module); }
array _values() { if(module) return values(module); }
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | static mixed ind(string index)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*nDirnode(%O) ind[%O] -> ???\n",sizeof(backtrace()),dirname,index);
#endif
|
e11883 | 1999-12-22 | Per Hedbor | | if(module)
{
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*nDirnode(%O) module[%O] -> ???\n",sizeof(backtrace()),dirname,index);
#endif
|
cd9971 | 2001-11-09 | Martin Stjernholm | | mixed o;
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | // _describe(module);
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | if(!zero_type(o=module[index]))
{
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*nDirnode(%O) module[%O] -> %O\n",sizeof(backtrace()),dirname,index, o);
#endif
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | return o;
}
|
a2faf6 | 1999-12-01 | Martin Stjernholm | | }
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
e11883 | 1999-12-22 | Per Hedbor | | if( !files )
|
5be4aa | 2001-11-12 | Martin Stjernholm | | if (!(files = get_dir(fakeroot(dirname)))) {
werror ("Error listing module directory %O: %s\n",
dirname, strerror (errno()));
files = ({});
}
|
e11883 | 1999-12-22 | Per Hedbor | |
int ret;
foreach( files, string s )
{
if( search(s, index)!=-1 || search(index,s)!=-1 )
{
ret=1;
break;
}
}
if(!ret)
return UNDEFINED;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | index = dirname+"/"+index;
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*nDirnode(%O) findmodule(%O)\n",
sizeof(backtrace()), dirname, dirname+"/"+index);
#endif
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | if(object o=findmodule(index, handler))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
if(mixed tmp=o->_module_value) o=tmp;
return o;
}
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | if (program p=cast_to_program( index, 0, handler ))
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | {
// werror("dirnode(%O)[%O] -> %O\n",dirname,index,p);
return p;
}
|
2c0b29 | 2001-03-20 | Fredrik Hübinette (Hubbe) | | // werror("Returning UNDEFINED for %s\n",ind);
|
73e955 | 1999-12-28 | Martin Stjernholm | | return UNDEFINED;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | mixed `[](string index)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
mixed ret;
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*nDirnode(%O) cache[%O] ?????\n",sizeof(backtrace()),dirname,index);
#endif
if(!zero_type(ret=cache[index]))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*nDirnode(%O) cache[%O] -> %O\n",sizeof(backtrace()),dirname,index, ret);
#endif
|
cd9971 | 2001-11-09 | Martin Stjernholm | | if (ret != ZERO_TYPE) return ret;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return UNDEFINED;
}
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | ret=ind(index);
// Kluge!
if(ret == __placeholder_object) return ret;
|
cd9971 | 2001-11-09 | Martin Stjernholm | | cache[index] = zero_type(ret) ? ZERO_TYPE : ret;
return ret;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | |
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | static int _cache_full;
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | void fill_cache()
{
|
f4f08d | 1999-02-26 | Henrik Grubbström (Grubba) | | #ifdef RESOLV_DEBUG
werror(describe_backtrace(({ sprintf("Filling cache in dirnode %O\n",
dirname),
backtrace() })));
#endif /* RESOLV_DEBUG */
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | if (_cache_full) {
return;
}
if (module) {
foreach(indices(module), string index) {
cache[index] = module[index];
}
}
|
e11883 | 1999-12-22 | Per Hedbor | | if( !files )
|
5be4aa | 2001-11-12 | Martin Stjernholm | | if (!(files = get_dir(fakeroot(dirname)))) {
werror ("Error listing module directory %O: %s\n",
dirname, strerror (errno()));
files = ({});
}
|
e11883 | 1999-12-22 | Per Hedbor | | foreach(files, string fname) {
|
0e68e6 | 2000-02-04 | Henrik Grubbström (Grubba) | | mixed err = catch {
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | if (((< ".pike", ".pmod" >)[fname[sizeof(fname)-5..]]) &&
!zero_type(`[](fname[..sizeof(fname)-6]))) {
continue;
|
0e68e6 | 2000-02-04 | Henrik Grubbström (Grubba) | | } else if ((fname[sizeof(fname)-3..] == ".so") &&
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | !zero_type(`[](fname[..sizeof(fname)-4]))) {
continue;
}
};
|
0e68e6 | 2000-02-04 | Henrik Grubbström (Grubba) | | if (err) {
compile_warning(dirname+"."+fname, 0,
sprintf("Compilation failed:\n"
"%s\n",
describe_backtrace(err)));
}
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | }
_cache_full = 1;
}
array(string) _indices()
{
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | // werror("indices(%O) called\n", dirname);
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | fill_cache();
|
cd9971 | 2001-11-09 | Martin Stjernholm | | return indices(filter(cache, lambda(mixed x) {return cache[x] != ZERO_TYPE;}));
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | }
array(mixed) _values()
{
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | // werror("values(%O) called\n", dirname);
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | fill_cache();
|
cd9971 | 2001-11-09 | Martin Stjernholm | | return values(cache) - ({ZERO_TYPE});
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | }
|
52c579 | 2000-05-23 | Fredrik Hübinette (Hubbe) | |
|
a002d3 | 2002-03-01 | Martin Stjernholm | | void delete_value (mixed val)
{
if (string name = search (cache, val))
m_delete (cache, name);
}
|
52c579 | 2000-05-23 | Fredrik Hübinette (Hubbe) | | string _sprintf(int as)
{
return sprintf("master()->dirnode(%O)",dirname);
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | };
|
6e2ebb | 1999-12-28 | Martin Stjernholm | | static class ZERO_TYPE {};
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | class joinnode
{
|
481748 | 2000-05-11 | Martin Stjernholm | | constant is_resolv_joinnode = 1;
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | array(object|mapping) joined_modules;
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | mapping(string:mixed) cache=([]);
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | |
|
52c579 | 2000-05-23 | Fredrik Hübinette (Hubbe) | | string _sprintf(int as)
{
return sprintf("master()->joinnode(%O)",joined_modules);
}
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | void create(array(object|mapping) _joined_modules)
{
joined_modules = _joined_modules;
}
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | static mixed ind(string index)
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | {
array(mixed) res = ({});
|
ca051c | 1999-11-23 | Per Hedbor | | foreach(joined_modules, object|mapping o)
{
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | mixed ret;
|
ca051c | 1999-11-23 | Per Hedbor | | if (!zero_type(ret = o[index]))
{
|
8b307e | 1998-10-17 | Henrik Grubbström (Grubba) | | if (objectp(ret = o[index]) &&
|
3ad5d6 | 2000-05-13 | Martin Stjernholm | | (ret->is_resolv_dirnode || ret->is_resolv_joinnode))
|
ca051c | 1999-11-23 | Per Hedbor | | {
|
8b307e | 1998-10-17 | Henrik Grubbström (Grubba) | | // Only join directorynodes (or joinnodes).
res += ({ ret });
|
8cdeed | 2000-09-15 | Mirar (Pontus Hagland) | | } else if ( !zero_type(ret) ) {
|
ca051c | 1999-11-23 | Per Hedbor | | return (ret);
|
8b307e | 1998-10-17 | Henrik Grubbström (Grubba) | | } else {
// Ignore
continue;
}
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | }
}
|
ca051c | 1999-11-23 | Per Hedbor | | if (sizeof(res) > 1)
return joinnode(res);
else if (sizeof(res))
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | return res[0];
return UNDEFINED;
}
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | mixed `[](string index)
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | {
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | mixed ret;
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | if (!zero_type(ret = cache[index])) {
if (ret != ZERO_TYPE) {
return ret;
}
return UNDEFINED;
}
ret = ind(index);
if (zero_type(ret)) {
cache[index] = ZERO_TYPE;
} else {
cache[index] = ret;
}
return ret;
}
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | static int _cache_full;
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | void fill_cache()
{
|
f4f08d | 1999-02-26 | Henrik Grubbström (Grubba) | | #ifdef RESOLV_DEBUG
werror(describe_backtrace(({ "Filling cache in joinnode\n",
backtrace() })));
#endif /* RESOLV_DEBUG */
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | if (_cache_full) {
return;
}
|
c08426 | 2000-02-04 | Henrik Grubbström (Grubba) | | foreach(joined_modules, object|mapping|program o) {
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | foreach(indices(o), string index) {
if (zero_type(cache[index])) {
`[](index);
}
}
}
_cache_full = 1;
}
array(string) _indices()
{
fill_cache();
|
cd9971 | 2001-11-09 | Martin Stjernholm | | return indices(filter(cache, lambda(mixed x){ return cache[x] != ZERO_TYPE; }));
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | }
array(mixed) _values()
{
fill_cache();
|
cd9971 | 2001-11-09 | Martin Stjernholm | | return values(cache) - ({ZERO_TYPE});
|
3e4b81 | 1998-10-16 | Henrik Grubbström (Grubba) | | }
|
a002d3 | 2002-03-01 | Martin Stjernholm | |
void delete_value (mixed val)
{
if (string name = search (cache, val))
m_delete (cache, name);
for (int i = 0; i < sizeof (joined_modules); i++) {
object|mapping|program o = joined_modules[i];
if (o == val) {
joined_modules = joined_modules[..i - 1] + joined_modules[i + 1..];
i--;
}
else if (objectp (o) && (o->is_resolv_dirnode || o->is_resolv_joinnode))
o->delete_value (val);
else if (string name = mappingp (o) && search (o, val))
m_delete (o, name);
}
}
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | };
|
1792a7 | 1998-04-10 | Henrik Grubbström (Grubba) | | // Variables mustn't be static to allow for replace_master().
// /grubba 1998-04-10
mapping(string:mixed) fc=([]);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | object findmodule(string fullname, object|void handler)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
object o;
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | #ifdef MODULE_TRACE
werror("%*nfindmodule(%O)\n",sizeof(backtrace()),fullname);
#endif
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | if(!zero_type(o=fc[fullname]))
{
|
aa68b1 | 2001-03-19 | Fredrik Hübinette (Hubbe) | | // werror("fc[%O] -> %O\n",fullname, o);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return o;
}
|
61a424 | 2000-08-27 | Mirar (Pontus Hagland) | | if(Stat stat=master_file_stat(fakeroot(fullname+".pmod")))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
if(stat[1]==-2)
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | return dirnode(fullname+".pmod", handler);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | if(o = low_cast_to_object(fullname+".pmod", "/.", handler))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return fc[fullname]=o;
#if constant(load_module)
|
26f3da | 2000-07-11 | Fredrik Hübinette (Hubbe) | | if(master_file_stat(fakeroot(fullname+".so")))
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | return fc[fullname] = low_cast_to_object(fullname, "/.", handler);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | #endif
return fc[fullname]=UNDEFINED;
}
|
10e16f | 1999-11-04 | Henrik Grubbström (Grubba) | | mixed handle_import(string what, string|void current_file, object|void handler)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
afa129 | 2000-02-19 | Martin Nilsson | | array(string) tmp;
string path;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | if(current_file)
{
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | tmp=EXPLODE_PATH(current_file);
|
cc2c07 | 1998-04-19 | Fredrik Hübinette (Hubbe) | | tmp[-1]=what;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | path=combine_path_with_cwd( tmp*"/");
|
57b1af | 2001-12-13 | Henrik Grubbström (Grubba) | | } else {
path = combine_path_with_cwd(what);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
acd163 | 2001-12-17 | Henrik Grubbström (Grubba) | | #ifdef MODULE_TRACE
werror("%*nhandle_import(%O, %O, %O)\n",
sizeof(backtrace()), what, current_file, handler);
#endif /* MODULE_TRACE */
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | if (handler) {
return dirnode(path, handler);
}
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | if(fc[path]) return fc[path];
return dirnode(path);
|
cc2c07 | 1998-04-19 | Fredrik Hübinette (Hubbe) | | }
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
multiset no_resolv = (<>);
|
b07e96 | 2001-07-27 | Martin Nilsson | |
//!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | class CompatResolver
|
cc2c07 | 1998-04-19 | Fredrik Hübinette (Hubbe) | | {
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | array(string) pike_include_path=({});
array(string) pike_module_path=({});
array(string) pike_program_path=({});
|
374c90 | 2001-12-20 | Martin Stjernholm | | mapping(string:string) predefines = ([]);
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | int want_warnings = PIKE_WARNINGS;
string ver;
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //! The ComparResolver is initialized with a value that can be
//! casted into a "%d.%d" string, e.g. a version object.
void create(mixed version)
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | {
|
6df5a5 | 2001-11-07 | Martin Nilsson | | ver=(string)version;
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | }
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Add a directory to search for include files.
//!
//! This is the same as the command line option @tt{-I@}.
//!
//! @note
//! Note that the added directory will only be searched when using
//! < > to quote the included file.
//!
//! @seealso
//! @[remove_include_path()]
//!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | void add_include_path(string tmp)
{
tmp=normalize_path(combine_path_with_cwd(tmp));
pike_include_path-=({tmp});
pike_include_path=({tmp})+pike_include_path;
}
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | |
//! Remove a directory to search for include files.
//!
//! This function performs the reverse operation of @[add_include_path()].
//!
//! @seealso
//! @[add_include_path()]
//!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | void remove_include_path(string tmp)
{
tmp=normalize_path(combine_path_with_cwd(tmp));
pike_include_path-=({tmp});
}
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Add a directory to search for modules.
//!
//! This is the same as the command line option @tt{-M@}.
//!
//! @seealso
//! @[remove_module_path()]
//!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | void add_module_path(string tmp)
{
tmp=normalize_path(combine_path_with_cwd(tmp));
pike_module_path-=({tmp});
pike_module_path=({tmp})+pike_module_path;
}
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Remove a directory to search for modules.
//!
//! This function performs the reverse operation of @[add_module_path()].
//!
//! @seealso
//! @[add_module_path()]
//!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | void remove_module_path(string tmp)
{
tmp=normalize_path(combine_path_with_cwd(tmp));
pike_module_path-=({tmp});
}
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Add a directory to search for programs.
//!
//! This is the same as the command line option @tt{-P@}.
//!
//! @seealso
//! @[remove_program_path()]
//!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | void add_program_path(string tmp)
{
tmp=normalize_path(combine_path_with_cwd(tmp));
pike_program_path-=({tmp});
pike_program_path=({tmp})+pike_program_path;
}
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Remove a directory to search for programs.
//!
//! This function performs the reverse operation of @[add_program_path()].
//!
//! @seealso
//! @[add_program_path()]
//!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | void remove_program_path(string tmp)
{
tmp=normalize_path(combine_path_with_cwd(tmp));
pike_program_path-=({tmp});
}
|
374c90 | 2001-12-20 | Martin Stjernholm | | //! Add a define (without arguments) which will be implicitly
//! defined in @[cpp] calls.
void add_predefine (string name, string value)
{
predefines[name] = value;
}
//! Remove a define from the set that are implicitly defined in
//! @[cpp] calls.
void remove_predefine (string name)
{
m_delete (predefines, name);
}
//!
mapping get_predefines()
{
return predefines;
}
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | mapping get_default_module()
{
/* This is an ugly kluge to avoid an infinite recursion.
* The infinite recursion occurs because this function is
* called for every file when the compat_major/minor is set.
* This kluge could cause problems with threads if the
* compiler was threaded. -Hubbe
*/
int saved_compat_minor=compat_minor;
int saved_compat_major=compat_major;
compat_minor=-1;
compat_major=-1;
mixed x;
mixed err =catch {
|
acd163 | 2001-12-17 | Henrik Grubbström (Grubba) | | if(resolv("__default") && (x=resolv("__default.all_constants")))
x=x();
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | };
compat_major=saved_compat_major;
compat_minor=saved_compat_minor;
if(err) throw(err);
return x;
}
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //!
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | mixed resolv_base(string identifier, string|void current_file,
object|void current_handler)
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | {
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | // werror("Resolv_base(%O)\n",identifier);
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | array(mixed) tmp = ({});
|
b8cd05 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | string dir=current_file ? dirname(current_file) : "/";
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | |
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | foreach(pike_module_path, string path)
{
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | string file=combine_path(dir, path, identifier);
if(mixed ret=findmodule(file, current_handler)) {
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | if ((objectp(ret)) &&
(ret->is_resolv_dirnode || ret->is_resolv_joinnode)) {
if (mixed new_ret = ret->_module_value) {
ret = new_ret;
}
tmp += ({ ret });
} else {
if (mixed new_ret = ret->_module_value) {
ret = new_ret;
}
if (!sizeof(tmp)) {
return ret;
} else {
// Ignore
|
2f520e | 2002-04-28 | Martin Nilsson | | werror( "Ignoring file %O: %t for identifier %O\n",
file, ret, identifier );
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | continue;
}
}
}
|
8b307e | 1998-10-17 | Henrik Grubbström (Grubba) | | }
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | if (sizeof(tmp)) {
if (sizeof(tmp) == 1) {
return(tmp[0]);
|
8b307e | 1998-10-17 | Henrik Grubbström (Grubba) | | }
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | return joinnode(tmp);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | return UNDEFINED;
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | }
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
mapping resolv_cache = set_weak_flag( ([]), 1 );
|
6df5a5 | 2001-11-07 | Martin Nilsson | |
//!
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | mixed resolv(string identifier, string|void current_file,
object|void current_handler)
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | {
|
ff3875 | 2002-02-14 | Henrik Grubbström (Grubba) | | #ifdef RESOLV_DEBUG
werror("Resolv(%O)\n",identifier);
#endif /* RESOLV_DEBUG */
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | |
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | // FIXME: Support having the cache in the handler?
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | if( no_resolv[ identifier ] )
return UNDEFINED;
|
26ece2 | 2001-06-18 | Henrik Grubbström (Grubba) | | if (current_file && !stringp(current_file)) {
throw(({sprintf("resolv(%O, %O, %O): current_file is not a string!\n",
identifier, current_file, current_handler),
backtrace()}));
}
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | mixed ret;
string id=identifier+":"+(current_file ? dirname(current_file) : "-");
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | if( zero_type (ret = resolv_cache[id]) != 1 )
{
// werror("Resolv cached(%O) => %O (%d)\n",id,resolv_cache[id],zero_type(resolv_cache[id]));
return ret == ZERO_TYPE ? UNDEFINED : ret;
}
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | array(string) tmp=identifier/".";
|
34241f | 2001-05-24 | Henrik Grubbström (Grubba) | | ret=resolv_base(tmp[0], current_file, current_handler);
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | foreach(tmp[1..],string index) ret=ret[index];
resolv_cache[id] = zero_type (ret) ? ZERO_TYPE : ret;
return ret;
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //! This function is called whenever an #include directive is encountered
//! it receives the argument for #include and should return the file name
//! of the file to include
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | string handle_include(string f,
string current_file,
int local_include)
{
array(string) tmp;
string path;
if(local_include)
{
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(fakeroot(path)))
break;
else
path=0;
}
}
return path;
}
|
6df5a5 | 2001-11-07 | Martin Nilsson | |
//!
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | string read_include(string f)
{
AUTORELOAD_CHECK_FILE(f)
return master_read_file(f);
}
string _sprintf()
{
return sprintf("CompatResolver(%s)",ver);
|
94257b | 1998-10-16 | Henrik Grubbström (Grubba) | | }
|
7c11f4 | 1999-10-04 | Fredrik Hübinette (Hubbe) | | }
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | inherit CompatResolver;
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //! These are useful if you want to start other Pike processes
//! with the same options as this one was started with.
|
bfa62b | 1998-04-30 | Henrik Grubbström (Grubba) | | string _pike_file_name;
|
ac5184 | 1998-04-29 | Henrik Grubbström (Grubba) | | string _master_file_name;
|
b1d7d9 | 2002-01-07 | Martin Nilsson | | // Gets set to 1 if we're in async-mode (script->main() returned <0)
private int(0..1) _async=0;
|
53a32a | 2000-06-04 | Francesco Chemolli | |
|
b1d7d9 | 2002-01-07 | Martin Nilsson | | //! Returns 1 if we´re in async-mode, e.g. if the main method has
//! returned a negative number.
int(0..1) asyncp() {
|
53a32a | 2000-06-04 | Francesco Chemolli | | return _async;
}
|
45c726 | 2001-04-17 | Mirar (Pontus Hagland) | | #if constant(thread_create)
// this must be done in __init if someone inherits the master
static object _backend_thread=this_thread();
|
97e5c7 | 2001-07-28 | Martin Nilsson | |
//! The backend_thread() function is useful to determine if you are
//! the backend thread - important when doing async/sync protocols.
//! This method is only available if thread_create is present.
|
45c726 | 2001-04-17 | Mirar (Pontus Hagland) | | object backend_thread()
{
return _backend_thread;
}
#endif
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //! This function is called when all the driver is done with all setup
//! of modules, efuns, tables etc. etc. and is ready to start executing
//! _real_ programs. It receives the arguments not meant for the driver
//! and an array containing the environment variables on the same form as
//! a C program receives them.
|
afa129 | 2000-02-19 | Martin Nilsson | | void _main(array(string) orig_argv, array(string) env)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
afa129 | 2000-02-19 | Martin Nilsson | | array(string) argv=copy_value(orig_argv);
|
862fb4 | 1998-04-05 | Fredrik Hübinette (Hubbe) | | int i,debug,trace;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | object tmp;
string a,b;
|
afa129 | 2000-02-19 | Martin Nilsson | | array q;
|
a6b6df | 2001-01-19 | Mirar (Pontus Hagland) | | string postparseaction=0;
mixed v;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
ddd2af | 2001-12-29 | Martin Nilsson | | predefines = _static_modules.Builtin()->_take_over_initial_predefines();
|
bfa62b | 1998-04-30 | Henrik Grubbström (Grubba) | | _pike_file_name = orig_argv[0];
|
45c726 | 2001-04-17 | Mirar (Pontus Hagland) | | #if constant(thread_create)
_backend_thread = this_thread();
#endif
|
bfa62b | 1998-04-30 | Henrik Grubbström (Grubba) | |
|
d85416 | 1999-04-08 | Fredrik Hübinette (Hubbe) | | foreach(env,a)
{
if(sscanf(a,"%s=%s",a,b))
{
if(a=="") // Special hack for NT
{
sscanf(b,"%s=%s",a,b);
a="="+a;
}
|
a71f83 | 2001-11-13 | Tomas Nilsson | | putenv(a, b);
|
d7741a | 1999-08-06 | Fredrik Hübinette (Hubbe) | | }else{
werror("Broken environment var %s\n",a);
}
|
d85416 | 1999-04-08 | Fredrik Hübinette (Hubbe) | | }
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
624e85 | 1999-06-02 | Marcus Comstedt | |
|
e90a8b | 1999-06-01 | Mirar (Pontus Hagland) | | #ifndef NOT_INSTALLED
q=(getenv("PIKE_INCLUDE_PATH")||"")/":"-({""});
for(i=sizeof(q)-1;i>=0;i--) add_include_path(q[i]);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
e90a8b | 1999-06-01 | Mirar (Pontus Hagland) | | q=(getenv("PIKE_PROGRAM_PATH")||"")/":"-({""});
for(i=sizeof(q)-1;i>=0;i--) add_program_path(q[i]);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
e90a8b | 1999-06-01 | Mirar (Pontus Hagland) | | q=(getenv("PIKE_MODULE_PATH")||"")/":"-({""});
for(i=sizeof(q)-1;i>=0;i--) add_module_path(q[i]);
#endif
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
if(sizeof(argv)>1 && sizeof(argv[1]) && argv[1][0]=='-')
{
tmp=resolv("Getopt");
|
a7a45a | 1998-05-11 | Henrik Grubbström (Grubba) | |
if (!tmp) {
werror("master.pike: Couldn't resolv Getopt module.\n"
"Is your PIKE_MODULE_PATH environment variable set correctly?\n");
exit(1);
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
q=tmp->find_all_options(argv,({
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | ({"compat_version",tmp->HAS_ARG,({"-V","--compat"})}),
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | ({"version",tmp->NO_ARG,({"-v","--version"})}),
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | ({"help",tmp->NO_ARG,({"-h","--help"})}),
|
94c855 | 2001-01-19 | Mirar (Pontus Hagland) | | ({"features",tmp->NO_ARG,({"--features"})}),
|
a6b6df | 2001-01-19 | Mirar (Pontus Hagland) | | ({"info",tmp->NO_ARG,({"--info"})}),
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | ({"execute",tmp->HAS_ARG,({"-e","--execute"})}),
|
3d1446 | 2000-09-24 | Per Hedbor | | ({"debug_without",tmp->HAS_ARG,({"--debug-without"})}),
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | ({"preprocess",tmp->HAS_ARG,({"-E","--preprocess"})}),
({"modpath",tmp->HAS_ARG,({"-M","--module-path"})}),
({"ipath",tmp->HAS_ARG,({"-I","--include-path"})}),
({"ppath",tmp->HAS_ARG,({"-P","--program-path"})}),
|
2ea826 | 1998-05-12 | Martin Stjernholm | | ({"showpaths",tmp->NO_ARG,"--show-paths"}),
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | ({"warnings",tmp->NO_ARG,({"-w","--warnings"})}),
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | ({"nowarnings",tmp->NO_ARG,({"-W", "--woff", "--no-warnings"})}),
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | #ifdef PIKE_AUTORELOAD
({"autoreload",tmp->NO_ARG,({"--autoreload"})}),
#endif
|
ac5184 | 1998-04-29 | Henrik Grubbström (Grubba) | | ({"master",tmp->HAS_ARG,"-m"}),
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | ({"compiler_trace",tmp->NO_ARG,"--compiler-trace"}),
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | ({"assembler_debug",tmp->MAY_HAVE_ARG,"--assembler-debug"}),
|
e27a5c | 1999-11-19 | Henrik Grubbström (Grubba) | | ({"optimizer_debug",tmp->MAY_HAVE_ARG,"--optimizer-debug"}),
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | ({"debug",tmp->MAY_HAVE_ARG,"--debug",0,1}),
({"trace",tmp->MAY_HAVE_ARG,"--trace",0,1}),
|
e26bdd | 1999-12-13 | Per Hedbor | | ({"ignore",tmp->MAY_HAVE_ARG,"-Dqdatplr",0,1}),
|
ac5184 | 1998-04-29 | Henrik Grubbström (Grubba) | | ({"ignore",tmp->HAS_ARG,"-s"}),
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | }), 1);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
/* Parse -M and -I backwards */
for(i=sizeof(q)-1;i>=0;i--)
{
switch(q[i][0])
{
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | case "compat_version":
sscanf(q[i][1],"%d.%d",compat_major,compat_minor);
break;
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | #ifdef PIKE_AUTORELOAD
case "autoreload":
autoreload_on++;
#endif
|
3d1446 | 2000-09-24 | Per Hedbor | | case "debug_without":
foreach( q[i][1]/",", string feature )
{
switch( feature )
{
case "ttf":
no_resolv[ "_Image_TTF" ] = 1;
break;
case "zlib":
no_resolv[ "Gz" ] = 1;
break;
case "unisys":
no_resolv[ "_Image_GIF" ] = 1;
no_resolv[ "_Image_TIFF" ] = 1;
break;
case "threads":
// not really 100% correct, but good enough for most things.
no_resolv[ "Thread" ] = 1;
|
ff3875 | 2002-02-14 | Henrik Grubbström (Grubba) | | add_constant( "thread_create", UNDEFINED );
|
3d1446 | 2000-09-24 | Per Hedbor | | break;
default:
no_resolv[ feature ] = 1;
break;
}
}
break;
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | case "debug":
debug+=(int)q[i][1];
break;
|
862fb4 | 1998-04-05 | Fredrik Hübinette (Hubbe) | |
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | #if constant(_compiler_trace)
case "compiler_trace":
_compiler_trace(1);
break;
#endif /* constant(_compiler_trace) */
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | #if constant(_assembler_debug)
case "assembler_debug":
_assembler_debug((int)q[i][1]);
break;
#endif /* constant(_assembler_debug) */
|
e27a5c | 1999-11-19 | Henrik Grubbström (Grubba) | | #if constant(_optimizer_debug)
case "optimizer_debug":
_optimizer_debug((int)q[i][1]);
break;
#endif /* constant(_optimizer_debug) */
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | case "trace":
trace+=(int)q[i][1];
break;
|
862fb4 | 1998-04-05 | Fredrik Hübinette (Hubbe) | |
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | case "modpath":
add_module_path(q[i][1]);
break;
case "ipath":
add_include_path(q[i][1]);
break;
case "ppath":
add_program_path(q[i][1]);
break;
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | case "warnings":
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | want_warnings++;
break;
|
ac5184 | 1998-04-29 | Henrik Grubbström (Grubba) | |
|
098c8a | 2000-03-30 | Henrik Grubbström (Grubba) | | case "no-warnings":
want_warnings--;
break;
|
ac5184 | 1998-04-29 | Henrik Grubbström (Grubba) | | case "master":
_master_file_name = q[i][1];
break;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
}
|
afa129 | 2000-02-19 | Martin Nilsson | | foreach(q, array opts)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
switch(opts[0])
{
case "version":
|
b38f14 | 2002-04-30 | Martin Nilsson | | werror(version() + " Copyright © 1994-2002 Roxen Internet Software\n"
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | "Pike comes with ABSOLUTELY NO WARRANTY; This is free software and you are\n"
"welcome to redistribute it under certain conditions; Read the files\n"
|
b38f14 | 2002-04-30 | Martin Nilsson | | "COPYING and COPYRIGHT in the Pike distribution for more details.\n");
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | exit(0);
case "help":
werror("Usage: pike [-driver options] script [script arguments]\n"
"Driver options include:\n"
" -I --include-path=<p>: Add <p> to the include path\n"
" -M --module-path=<p> : Add <p> to the module path\n"
" -P --program-path=<p>: Add <p> to the program path\n"
" -e --execute=<cmd> : Run the given command instead of a script.\n"
" -h --help : see this message\n"
" -v --version : See what version of pike you have.\n"
|
94c855 | 2001-01-19 | Mirar (Pontus Hagland) | | " --features : List Pike features.\n"
|
a6b6df | 2001-01-19 | Mirar (Pontus Hagland) | | " --info : List information about the Pike build and setup.\n"
|
2ea826 | 1998-05-12 | Martin Stjernholm | | " --show-paths : See the paths and master that pike uses.\n"
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | " -s# : Set stack size\n"
" -m <file> : Use <file> as master object.\n"
" -d -d# : Increase debug (# is how much)\n"
" -t -t# : Increase trace level\n"
);
exit(0);
|
94c855 | 2001-01-19 | Mirar (Pontus Hagland) | |
case "features":
|
a6b6df | 2001-01-19 | Mirar (Pontus Hagland) | | postparseaction="features";
break;
case "info":
postparseaction="info";
|
94c855 | 2001-01-19 | Mirar (Pontus Hagland) | | break;
|
2ea826 | 1998-05-12 | Martin Stjernholm | |
case "showpaths":
werror("Include path : " + pike_include_path*"\n"
" " + "\n"
"Module path : " + pike_module_path*"\n"
" " + "\n"
"Program path : " + pike_program_path*"\n"
" " + "\n"
|
369271 | 1999-02-05 | Martin Stjernholm | | "Master file : " + (_master_file_name || __FILE__) + "\n");
|
2ea826 | 1998-05-12 | Martin Stjernholm | | exit(0);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
case "execute":
|
180872 | 2001-08-31 | Fredrik Hübinette (Hubbe) | | random_seed(time() ^ (getpid()<<8));
|
007a27 | 2002-02-09 | Mikael Brandström | | argv = tmp->get_args(argv,1);
|
f1a114 | 2001-02-23 | Fredrik Hübinette (Hubbe) | | if(trace) predef::trace(trace);
|
595c1a | 2002-02-09 | Mikael Brandström | | compile_string("mixed create(int argc, array(string) argv,array(string) env){"+
|
007a27 | 2002-02-09 | Mikael Brandström | | opts[1]+";}")(sizeof(argv),argv,env);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | exit(0);
|
fcf728 | 1998-04-28 | Fredrik Hübinette (Hubbe) | |
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | case "preprocess":
|
d8a6fc | 2000-03-25 | Fredrik Hübinette (Hubbe) | | _static_modules.files()->_stdout->write(cpp(master_read_file(opts[1]),
opts[1]));
|
c5cc2d | 1998-04-29 | Henrik Grubbström (Grubba) | | exit(0);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
}
|
caa322 | 1998-04-15 | Henrik Grubbström (Grubba) | | argv = tmp->get_args(argv,1);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
a6b6df | 2001-01-19 | Mirar (Pontus Hagland) | | switch (postparseaction)
|
94c855 | 2001-01-19 | Mirar (Pontus Hagland) | | {
|
a6b6df | 2001-01-19 | Mirar (Pontus Hagland) | | case "features":
v = resolv("Tools");
if (v) v = v["Install"];
if (v) v = v["features"];
if (!v)
{
werror("Could not resolv Tools.Install.features\n");
exit(1);
}
_static_modules.files()->_stdout->write(v()*"\n"+"\n");
exit(0);
case "info":
function w=_static_modules.files()->_stdout->write;
w("Software......Pike\n"
"Version......."+version()+"\n"
|
9c5c8f | 2001-04-07 | Martin Nilsson | | "WWW...........http://pike.roxen.com/\n"
|
a6b6df | 2001-01-19 | Mirar (Pontus Hagland) | | "\n");
w("pike binary..."+_pike_file_name+"\n");
w("master.pike..."+__FILE__+"\n");
w("Module path..." + pike_module_path*"\n"
" " + "\n"
"Include path.." + pike_include_path*"\n"
" " + "\n"
"Program path.." + pike_program_path*"\n"
" " + "\n"
"\n");
v = resolv("Tools");
if (v) v = v["Install"];
if (v) v = v["features"];
if (!v)
{
werror("Could not resolv Tools.Install.features\n");
exit(1);
}
w("Features......"+v()*"\n "+"\n");
exit(0);
|
94c855 | 2001-01-19 | Mirar (Pontus Hagland) | | }
|
180872 | 2001-08-31 | Fredrik Hübinette (Hubbe) | | random_seed(time() ^ (getpid()<<8));
|
9339fc | 2000-01-09 | Fredrik Hübinette (Hubbe) | |
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | if(sizeof(argv)==1)
{
|
caa322 | 1998-04-15 | Henrik Grubbström (Grubba) | | /* Attempt to resolv Tools.Hilfe.StdinHilfe */
tmp = resolv("Tools");
if (!tmp) {
werror("Couldn't find Tools.\n");
exit(1);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
caa322 | 1998-04-15 | Henrik Grubbström (Grubba) | | tmp = tmp["Hilfe"];
if (!tmp) {
werror("Couldn't find Hilfe.\n");
exit(1);
}
tmp->StdinHilfe();
exit(0);
} else {
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | argv=argv[1..];
}
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | argv[0]=combine_path_with_cwd(argv[0]);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
586d1c | 2000-09-04 | Fredrik Hübinette (Hubbe) | | program prog;
|
34fb3d | 1998-10-31 | Henrik Grubbström (Grubba) | |
mixed err = catch {
|
586d1c | 2000-09-04 | Fredrik Hübinette (Hubbe) | | prog=(program)argv[0];
|
34fb3d | 1998-10-31 | Henrik Grubbström (Grubba) | | };
if (err) {
|
2f520e | 2002-04-28 | Martin Nilsson | | werror( "Pike: Failed to compile script:\n"
"%s\n", stringp(err[0])?err[0]:describe_backtrace(err) );
|
34fb3d | 1998-10-31 | Henrik Grubbström (Grubba) | | exit(1);
}
// FIXME: Isn't the following code dead?
|
586d1c | 2000-09-04 | Fredrik Hübinette (Hubbe) | | if(!prog)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
62962b | 1999-06-01 | Mirar (Pontus Hagland) | | werror("Pike: Couldn't find script to execute\n(%O)\n",argv[0]);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | exit(1);
}
|
586d1c | 2000-09-04 | Fredrik Hübinette (Hubbe) | | object script=prog();
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
862fb4 | 1998-04-05 | Fredrik Hübinette (Hubbe) | | #if constant(_debug)
if(debug) _debug(debug);
#endif
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | if(!script->main)
{
werror("Error: "+argv[0]+" has no main().\n");
exit(1);
}
|
fcf728 | 1998-04-28 | Fredrik Hübinette (Hubbe) | | if(trace) predef::trace(trace);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | i=script->main(sizeof(argv),argv,env);
if(i >=0) exit(i);
|
53a32a | 2000-06-04 | Francesco Chemolli | | _async=1;
|
87f908 | 2001-03-12 | Fredrik Hübinette (Hubbe) | |
while(1)
{
mixed err=catch
{
while(1)
_static_modules.Builtin.__backend(3600.0);
};
master()->handle_error(err);
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | #if constant(thread_local)
object inhibit_compile_errors = thread_local();
void set_inhibit_compile_errors(mixed f)
{
inhibit_compile_errors->set(f);
}
|
71d995 | 1999-11-29 | Henrik Grubbström (Grubba) | |
mixed get_inhibit_compile_errors()
{
|
c2eb4a | 1999-11-29 | David Hedbor | | return inhibit_compile_errors->get();
|
71d995 | 1999-11-29 | Henrik Grubbström (Grubba) | | }
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | #else /* !constant(thread_local) */
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | mixed inhibit_compile_errors;
void set_inhibit_compile_errors(mixed f)
{
inhibit_compile_errors=f;
}
|
71d995 | 1999-11-29 | Henrik Grubbström (Grubba) | |
mixed get_inhibit_compile_errors()
{
|
c2eb4a | 1999-11-29 | David Hedbor | | return inhibit_compile_errors;
|
71d995 | 1999-11-29 | Henrik Grubbström (Grubba) | | }
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | #endif /* constant(thread_local) */
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
0024f9 | 2001-06-06 | Mirar (Pontus Hagland) | | static private function(string:string) _trim_file_name_cb=0;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | string trim_file_name(string s)
{
|
4839dd | 2001-09-02 | Marcus Comstedt | | #ifdef PIKE_MODULE_RELOC
s = relocate_module(s);
#endif
|
e37a3e | 1999-10-09 | Fredrik Hübinette (Hubbe) | | if(getenv("LONG_PIKE_ERRORS")) return s;
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | if(getenv("SHORT_PIKE_ERRORS")) return BASENAME(s);
|
0024f9 | 2001-06-06 | Mirar (Pontus Hagland) | |
if (_trim_file_name_cb) return _trim_file_name_cb(s);
|
df2c63 | 2000-08-02 | Henrik Grubbström (Grubba) | | /* getcwd() can fail, but since this is called from handle_error(),
* we don't want to fail, so we don't care about that.
*/
catch {
string cwd=getcwd();
if (sizeof(cwd) && (cwd[-1] != '/')) {
cwd += "/";
}
if(s[..sizeof(cwd)-1]==cwd) return s[sizeof(cwd)..];
};
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | return s;
}
|
0024f9 | 2001-06-06 | Mirar (Pontus Hagland) | | function(string:string) set_trim_file_name_callback(function(string:string) s)
{
function(string:string) f=_trim_file_name_cb;
_trim_file_name_cb=s;
return f;
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | |
//! 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.
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | void compile_error(string file,int line,string err)
{
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | mixed val;
|
311242 | 2000-03-27 | Per Hedbor | | if(! (val = get_inhibit_compile_errors() ))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
2f520e | 2002-04-28 | Martin Nilsson | | werror( "%s:%s:%s\n",trim_file_name(file),
line?(string)line:"-",err );
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | else if(objectp(val) ||
programp(val) ||
functionp(val))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | if (objectp(val) && val->compile_error) {
val->compile_error(file, line, err);
} else {
|
311242 | 2000-03-27 | Per Hedbor | | val(file, line, err);
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | }
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | |
//! This function is called whenever a compiling warning occurs.
//! Nothing strange about it.
//! Note that previous_object cannot be trusted in ths function, because
//! the compiler calls this function.
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | void compile_warning(string file,int line,string err)
{
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | mixed val;
|
311242 | 2000-03-27 | Per Hedbor | | if(!(val = get_inhibit_compile_errors() ))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
if(want_warnings)
|
2f520e | 2002-04-28 | Martin Nilsson | | werror( "%s:%s: Warning: %s\n",trim_file_name(file),
line?(string)line:"-",err );
}
else if (objectp(val) && val->compile_warning) {
|
01d3c9 | 1999-11-04 | Henrik Grubbström (Grubba) | | val->compile_warning(file, line, err);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | |
|
8594c8 | 2001-08-15 | Martin Stjernholm | | //! 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)
{
|
ad5304 | 2001-08-16 | Martin Stjernholm | | if (objectp (trace) &&
(trace->is_cpp_error || trace->is_compilation_error))
// Errors thrown directly by cpp() and compile() are normally not
// interesting; they've already been reported to compile_error.
|
5802de | 2001-08-16 | Martin Stjernholm | | return 1;
|
8594c8 | 2001-08-15 | Martin Stjernholm | | if (mixed val = get_inhibit_compile_errors()) {
if (objectp (val) && val->compile_exception)
return val->compile_exception (trace);
}
else {
handle_error (trace);
return 1;
}
return 0;
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //! Called for every runtime warning. The first argument identifies
//! where the warning comes from, the second identifies the specific
//! message, and the rest depends on that. See code below for currently
//! implemented warnings.
|
8f2306 | 2000-06-09 | Martin Stjernholm | | void runtime_warning (string where, string what, mixed... args)
{
if (want_warnings)
switch (where + "." + what) {
case "gc.bad_cycle":
// args[0] is an array containing the objects in the cycle
// which aren't destructed and have destroy() functions.
werror ("GC warning: Garbing cycle where destroy() will be called "
"in arbitrary order:\n%{ %s\n%}",
map (args[0], describe_object));
break;
default:
werror ("%s warning: %s %O\n", capitalize (where), what, args);
}
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
f4f08d | 1999-02-26 | Henrik Grubbström (Grubba) | | static mixed _charset_mod;
|
97e5c7 | 2001-07-28 | Martin Nilsson | |
//! This function is called by cpp() when it wants to do
//! character code conversion.
|
f4f08d | 1999-02-26 | Henrik Grubbström (Grubba) | | string decode_charset(string data, string charset)
{
|
db25e6 | 1999-02-26 | Henrik Grubbström (Grubba) | | // werror(sprintf("decode_charset(%O, %O)\n", data, charset));
|
f4f08d | 1999-02-26 | Henrik Grubbström (Grubba) | |
if (!_charset_mod) {
mixed mod = resolv("Locale");
_charset_mod = mod && mod["Charset"];
if (!_charset_mod) {
compile_warning("-", 0, "No Locale.Charset module!");
return 0;
}
}
object decoder;
catch {
decoder = _charset_mod->decoder(charset);
};
if (!decoder) {
compile_warning("-", 0, sprintf("Unknown charset %O!", charset));
return 0;
}
return decoder->feed(data)->drain();
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | class Describer
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
da0a82 | 2000-08-29 | Martin Stjernholm | | int clipped=0;
int canclip=0;
mapping(mixed:int|string) ident = ([]);
int identcount = 0;
void identify_parts (mixed stuff)
{
|
9f7109 | 2000-11-20 | Martin Stjernholm | | // Use an array as stack here instead of recursing directly; we
// might be pressed for stack space if the backtrace being
// described is a stack overflow.
array identify_stack = ({stuff});
while (sizeof (identify_stack)) {
stuff = identify_stack[-1];
identify_stack = identify_stack[..sizeof (identify_stack) - 2];
|
26ece2 | 2001-06-18 | Henrik Grubbström (Grubba) | | if (objectp (stuff) || functionp (stuff) || programp (stuff))
ident[stuff]++;
else if (arrayp (stuff)) {
|
9f7109 | 2000-11-20 | Martin Stjernholm | | if (!ident[stuff]++)
identify_stack += stuff;
}
else if (multisetp (stuff)) {
if (!ident[stuff]++)
identify_stack += indices (stuff);
}
else if (mappingp (stuff)) {
if (!ident[stuff]++)
identify_stack += indices (stuff) + values (stuff);
}
|
26ece2 | 2001-06-18 | Henrik Grubbström (Grubba) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | }
}
|
2602b8 | 2000-08-29 | Martin Stjernholm | | string describe_string (string m, int maxlen)
{
canclip++;
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)+"]";
}
}
string describe_array (array m, int maxlen)
{
if(!sizeof(m)) return "({})";
else {
if(maxlen<5)
{
clipped++;
return "array["+sizeof(m)+"]";
}
else {
canclip++;
return "({" + describe_comma_list(m,maxlen-2) +"})";
}
}
}
string describe_mapping (mapping m, int maxlen)
{
if(!sizeof(m)) return "([])";
else return "mapping["+sizeof(m)+"]";
}
string describe_multiset (multiset m, int maxlen)
{
if(!sizeof(m)) return "(<>)";
else return "multiset["+sizeof(m)+"]";
}
|
da0a82 | 2000-08-29 | Martin Stjernholm | | string describe (mixed m, int maxlen)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
da0a82 | 2000-08-29 | Martin Stjernholm | | if (stringp (ident[m])) return ident[m];
else if (intp (ident[m]) && ident[m] > 1)
ident[m] = "@" + identcount++;
string res, typ;
|
f645f0 | 2001-10-26 | Henrik Grubbström (Grubba) | | catch {
if (catch (typ=sprintf("%t",m)))
typ = "object"; // Object with a broken _sprintf(), probably.
switch(typ)
{
|
da0a82 | 2000-08-29 | Martin Stjernholm | | case "int":
case "float":
return (string)m;
case "string":
|
2602b8 | 2000-08-29 | Martin Stjernholm | | return describe_string (m, maxlen);
|
da0a82 | 2000-08-29 | Martin Stjernholm | | case "array":
|
2602b8 | 2000-08-29 | Martin Stjernholm | | res = describe_array (m, maxlen);
|
da0a82 | 2000-08-29 | Martin Stjernholm | | break;
case "mapping":
|
2602b8 | 2000-08-29 | Martin Stjernholm | | res = describe_mapping (m, maxlen);
|
da0a82 | 2000-08-29 | Martin Stjernholm | | break;
case "multiset":
|
2602b8 | 2000-08-29 | Martin Stjernholm | | res = describe_multiset (m, maxlen);
|
da0a82 | 2000-08-29 | Martin Stjernholm | | break;
case "function":
|
2602b8 | 2000-08-29 | Martin Stjernholm | | if (string tmp=describe_function(m)) res = tmp;
else res = typ;
break;
|
da0a82 | 2000-08-29 | Martin Stjernholm | | case "program":
|
2602b8 | 2000-08-29 | Martin Stjernholm | | if(string tmp=describe_program(m)) res = tmp;
else res = typ;
break;
|
da0a82 | 2000-08-29 | Martin Stjernholm | | default:
if (objectp(m))
if(string tmp=describe_object(m)) {
res = tmp;
break;
}
|
2602b8 | 2000-08-29 | Martin Stjernholm | | res = typ;
|
f645f0 | 2001-10-26 | Henrik Grubbström (Grubba) | | }
};
if (!res) {
// Extra paranoia case.
res = sprintf("Instance of %O", _typeof(m));
|
da0a82 | 2000-08-29 | Martin Stjernholm | | }
if (stringp (ident[m]))
return ident[m] + "=" + res;
return res;
}
|
e8ebc0 | 1999-08-27 | Fredrik Hübinette (Hubbe) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | string describe_comma_list(array x, int maxlen)
{
string ret="";
|
e8ebc0 | 1999-08-27 | Fredrik Hübinette (Hubbe) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | if(!sizeof(x)) return "";
if(maxlen<0) return ",,,"+sizeof(x);
|
5e0916 | 1999-10-15 | Fredrik Hübinette (Hubbe) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | int clip=min(maxlen/2,sizeof(x));
int len=maxlen;
int done=0;
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | // int loopcount=0;
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | |
while(1)
{
|
da0a82 | 2000-08-29 | Martin Stjernholm | | // 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++)
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | {
|
da0a82 | 2000-08-29 | Martin Stjernholm | | clipped=0;
canclip=0;
z[e]=describe(x[e],len);
isclipped[e]=clipped;
clippable[e]=canclip;
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | }
while(1)
{
|
da0a82 | 2000-08-29 | Martin Stjernholm | | // 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;
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | for(int e=0;e<clip;e++)
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | {
|
da0a82 | 2000-08-29 | Martin Stjernholm | | // if(loopcount>10000) werror("sizeof(z[%d])=%d len=%d\n",e,sizeof(z[e]),len);
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | |
|
5e0916 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | if((sizeof(z[e])>=last_newlen || isclipped[e]) && clippable[e])
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | num_large++;
else
smallsize+=sizeof(z[e]);
if(num_large * 15 + smallsize < maxlen) clipsuggest=e+1;
}
|
da0a82 | 2000-08-29 | Martin Stjernholm | | // 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;
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | // if(loopcount>10000) werror("newlen=%d\n",newlen);
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | if(newlen<8 || newlen >= last_newlen) break;
last_newlen=newlen;
// if(loopcount>10000) werror("len decreased, retrying.\n");
}
|
e8ebc0 | 1999-08-27 | Fredrik Hübinette (Hubbe) | |
|
da0a82 | 2000-08-29 | Martin Stjernholm | | 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;
}
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | }
}
|
da0a82 | 2000-08-29 | Martin Stjernholm | | return ret;
}
|
e8ebc0 | 1999-08-27 | Fredrik Hübinette (Hubbe) | | }
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //!
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | string describe_object(object o)
{
string s;
if(!o) return 0;
|
80e50f | 2000-03-23 | Martin Stjernholm | | if (!catch (s = sprintf("%O",o)) && s != "object") return s;
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | if(( s=describe_program(object_program(o)) ))
return s+"()";
return 0;
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //!
|
62e87b | 1998-04-14 | Fredrik Hübinette (Hubbe) | | string describe_program(program p)
{
string s;
if(!p) return 0;
if(s=search(programs,p))
{
|
01f027 | 2001-11-19 | Martin Nilsson | | if(has_suffix(s, ".pmod"))
return EXPLODE_PATH(s[..sizeof(s)-6])[-1];
|
e37a3e | 1999-10-09 | Fredrik Hübinette (Hubbe) | | return trim_file_name(s);
|
62e87b | 1998-04-14 | Fredrik Hübinette (Hubbe) | | }
|
e8ce5e | 2001-04-09 | Fredrik Hübinette (Hubbe) | | if(mixed tmp=function_object(p))
{
if(objectp(tmp))
{
|
337ad8 | 1998-04-15 | Fredrik Hübinette (Hubbe) | | if(s=describe_program(object_program(tmp)))
return s+"."+function_name(p);
|
e8ce5e | 2001-04-09 | Fredrik Hübinette (Hubbe) | | }
if(programp(tmp))
{
if(s=describe_program(tmp))
return s+"."+function_name(p);
}
}
|
bec57d | 1999-09-06 | Fredrik Hübinette (Hubbe) | | if(s=_static_modules.Builtin()->program_defined(p))
return EXPLODE_PATH(s)[-1];
|
62e87b | 1998-04-14 | Fredrik Hübinette (Hubbe) | | return 0;
}
|
97e5c7 | 2001-07-28 | Martin Nilsson | | //!
|
2602b8 | 2000-08-29 | Martin Stjernholm | | string describe_function (function f)
{
if (!f) return 0;
string name;
if(string s=search(programs,f))
{
|
01f027 | 2001-11-19 | Martin Nilsson | | if(has_suffix(s, ".pmod"))
name = EXPLODE_PATH(s[..sizeof(s)-6])[-1];
|
2602b8 | 2000-08-29 | Martin Stjernholm | | else
name = trim_file_name(s);
}
else
if (catch (name = function_name (f))) name = "function";
|
9f7109 | 2000-11-20 | Martin Stjernholm | | object o = function_object(f);
|
530e2c | 2000-12-02 | Martin Stjernholm | | if(objectp (o)) { // Check if it's an object in a way that (hopefully) doesn't
// call any functions in it (neither `== nor `!).
|
2602b8 | 2000-08-29 | Martin Stjernholm | | string s;
if (!catch (s = sprintf("%O",o)) && s != "object")
return s+"->"+name;
}
return name;
}
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | /* 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.
*/
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | |
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears describe_backtrace
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Returns a string containing a readable message that describes where
//! the backtrace was made.
//!
//! The argument @[trace] should normally be the return value from a call
//! to @[backtrace()], or a caught error.
//!
//! @seealso
//! @[backtrace()], @[describe_error()], @[catch()], @[throw()]
//!
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | string describe_backtrace(mixed trace, void|int linewidth)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
int e;
|
5be4aa | 2001-11-12 | Martin Stjernholm | | string ret = "";
|
d4fd0a | 1999-12-06 | Henrik Grubbström (Grubba) | | int backtrace_len=((int)getenv("PIKE_BACKTRACE_LEN")) || bt_max_string_len;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | if(!linewidth)
{
linewidth=99999;
catch
{
linewidth=_static_modules.files()->_stdin->tcgetattr()->columns;
};
|
fe8fb3 | 2000-01-15 | Fredrik Hübinette (Hubbe) | | if(linewidth<10) linewidth=99999;
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | }
|
f417dd | 1999-03-19 | Fredrik Hübinette (Hubbe) | | if((arrayp(trace) && sizeof(trace)==2 && stringp(trace[0])) ||
(objectp(trace) && trace->is_generic_error))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
a23272 | 1999-10-06 | Henrik Grubbström (Grubba) | | if (catch {
|
979848 | 1999-12-06 | Henrik Grubbström (Grubba) | | ret = trace[0] || "No error message!\n";
|
a23272 | 1999-10-06 | Henrik Grubbström (Grubba) | | trace = trace[1];
}) {
return "Error indexing backtrace!\n";
}
|
5be4aa | 2001-11-12 | Martin Stjernholm | | if(!arrayp(trace))
return ret + "No backtrace.\n";
}else
if (!arrayp (trace))
return sprintf ("Unrecognized backtrace format: %O\n", trace);
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | |
{
|
da0a82 | 2000-08-29 | Martin Stjernholm | | Describer desc = Describer();
desc->identify_parts (trace);
|
9f7109 | 2000-11-20 | Martin Stjernholm | | int end = 0;
if( (sizeof(trace)>1) &&
arrayp(trace[0]) &&
(sizeof(trace[0]) > 2) &&
(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--)
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
mixed tmp;
string row;
|
6e343b | 2001-03-14 | Martin Stjernholm | | if (mixed err=catch {
|
a23272 | 1999-10-06 | Henrik Grubbström (Grubba) | | tmp = trace[e];
if(stringp(tmp))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | row=tmp;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
a23272 | 1999-10-06 | Henrik Grubbström (Grubba) | | else if(arrayp(tmp))
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | {
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | string pos;
|
dbe79a | 1999-12-07 | Henrik Grubbström (Grubba) | | if(sizeof(tmp)>=2 && stringp(tmp[0])) {
if (intp(tmp[1])) {
|
9f7109 | 2000-11-20 | Martin Stjernholm | |
string exact_pos = tmp[0] + ":" + tmp[1];
|
dbe79a | 1999-12-07 | Henrik Grubbström (Grubba) | | pos=trim_file_name(tmp[0])+":"+tmp[1];
} else {
pos = sprintf("%s:Bad line %t", trim_file_name(tmp[0]), tmp[1]);
}
|
a23272 | 1999-10-06 | Henrik Grubbström (Grubba) | | }else{
mixed desc="Unknown program";
if(sizeof(tmp)>=3 && functionp(tmp[2]))
{
|
e11883 | 1999-12-22 | Per Hedbor | | catch
{
|
a23272 | 1999-10-06 | Henrik Grubbström (Grubba) | | if(mixed tmp=function_object(tmp[2]))
if(tmp=object_program(tmp))
if(tmp=describe_program(tmp))
desc=tmp;
};
}
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | pos=desc;
}
|
9f7109 | 2000-11-20 | Martin Stjernholm | |
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | string data;
if(sizeof(tmp)>=3)
{
|
dfca1f | 2000-08-22 | Martin Stjernholm | | if(functionp(tmp[2])) {
|
2602b8 | 2000-08-29 | Martin Stjernholm | | data = describe_function (tmp[2]);
|
dfca1f | 2000-08-22 | Martin Stjernholm | | }
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | else if (stringp(tmp[2])) {
data= tmp[2];
} else
data ="unknown function";
data+="("+
|
da0a82 | 2000-08-29 | Martin Stjernholm | | desc->describe_comma_list(tmp[3..], backtrace_len)+
|
ba20b1 | 1999-10-15 | Fredrik Hübinette (Hubbe) | | ")";
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));
}
|
dbe79a | 1999-12-07 | Henrik Grubbström (Grubba) | | } else {
row = pos;
|
62e87b | 1998-04-14 | Fredrik Hübinette (Hubbe) | | }
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
a23272 | 1999-10-06 | Henrik Grubbström (Grubba) | | else
{
|
979848 | 1999-12-06 | Henrik Grubbström (Grubba) | | if (tmp) {
|
e0e05f | 2000-03-23 | Martin Stjernholm | | if (catch (row = sprintf("%O", tmp)))
row = describe_program(object_program(tmp)) + " with broken _sprintf()";
|
979848 | 1999-12-06 | Henrik Grubbström (Grubba) | | } else {
row = "Destructed object";
}
|
a23272 | 1999-10-06 | Henrik Grubbström (Grubba) | | }
|
6e343b | 2001-03-14 | Martin Stjernholm | | }) {
row = sprintf("Error indexing backtrace line %d: %s (%O)!", e, err[0], err[1]);
}
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | |
int dup_frame;
if (!zero_type(dup_frame = prev_pos[row])) {
dup_frame -= sizeof(frames);
if (!loop_start) {
loop_start = dup_frame;
loop_next = dup_frame + 1;
loops = 0;
continue;
} else {
int new_loop = 0;
if (!loop_next) loop_next = loop_start, new_loop = 1;
if (dup_frame == loop_next++) {
loops += new_loop;
continue;
}
}
}
prev_pos[row] = sizeof(frames);
if (loop_start) {
array(string) tail;
if (!loop_next) tail = ({}), loops++;
else tail = frames[loop_start + sizeof(frames) ..
loop_next - 1 + sizeof(frames)];
if (loops)
frames += ({sprintf ("... last %d frames above repeated %d times ...\n",
-loop_start, loops)});
frames += tail;
prev_pos = ([]);
loop_start = 0;
}
|
9f7109 | 2000-11-20 | Martin Stjernholm | | frames += ({row + "\n"});
}
if (loop_start) {
// Want tail to contain a full loop rather than being empty; it
// looks odd when the repeat message ends the backtrace.
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | | array(string) tail = frames[loop_start + sizeof(frames) ..
loop_next - 1 + sizeof(frames)];
|
d48c1f | 2001-12-18 | Martin Stjernholm | | if (loops)
frames += ({sprintf("... last %d frames above repeated %d times ...\n",
-loop_start, loops)});
|
9f7109 | 2000-11-20 | Martin Stjernholm | | frames += tail;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
9f7109 | 2000-11-20 | Martin Stjernholm | |
ret += frames * "";
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
5be4aa | 2001-11-12 | Martin Stjernholm | | return ret;
|
ca2b07 | 1998-03-28 | Henrik Grubbström (Grubba) | | }
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | |
|
b07e96 | 2001-07-27 | Martin Nilsson | | //! @appears describe_error
|
8f4569 | 2001-01-14 | Henrik Grubbström (Grubba) | | //! Returns only the error message from a backtrace.
//!
//! If there is no error message in the backtrace, a fallback message
//! will be returned.
//!
//! @seealso
//! @[backtrace()], @[describe_backtrace()]
//!
|
a66ff2 | 2000-01-11 | Martin Stjernholm | | string describe_error (mixed trace)
{
if((arrayp(trace) && sizeof(trace)==2 && stringp(trace[0])) ||
(objectp(trace) && trace->is_generic_error))
{
if (catch {
|
51b0fb | 2000-03-20 | Martin Stjernholm | | return trace[0] || "No error message.\n";
|
a66ff2 | 2000-01-11 | Martin Stjernholm | | }) {
return "Error indexing backtrace!\n";
}
}
return sprintf ("Backtrace is of unknown type %t!\n", trace);
}
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | |
class Codec
{
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | string fname;
int mkobj;
program prog_to_mkobj;
void create(void|string f,void|int m)
{
fname=f;
mkobj=m;
}
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | | object __register_new_program(program p)
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | {
if(fname)
{
programs[fname]=prog_to_mkobj=p;
fname=0;
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | | if (mkobj)
return objects[p] || (objects[p]=__null_program());
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | }
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | | return 0;
|
eaa4da | 2001-10-04 | Fredrik Hübinette (Hubbe) | | }
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | mapping f=all_constants();
string nameof(mixed x)
{
if(mixed tmp=search(f,x))
return "efun:"+tmp;
|
51b0fb | 2000-03-20 | Martin Stjernholm | | if (programp(x)) {
if(mixed tmp=search(programs,x))
return tmp;
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | |
|
51b0fb | 2000-03-20 | Martin Stjernholm | | if(mixed tmp=search(values(_static_modules), x))
return "_static_modules."+(indices(_static_modules)[tmp]);
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
|
51b0fb | 2000-03-20 | Martin Stjernholm | | else if (objectp(x))
if(mixed tmp=search(objects,x))
if(tmp=search(programs,tmp))
return tmp;
|
ff3875 | 2002-02-14 | Henrik Grubbström (Grubba) | | return UNDEFINED;
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
function functionof(string x)
{
if(sscanf(x,"efun:%s",x)) return f[x];
|
b1693a | 2000-04-07 | Fredrik Hübinette (Hubbe) | | if(sscanf(x,"resolv:%s",x)) return resolv(x);
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | return 0;
}
object objectof(string x)
{
if(sscanf(x,"efun:%s",x)) return f[x];
|
b1693a | 2000-04-07 | Fredrik Hübinette (Hubbe) | | if(sscanf(x,"resolv:%s",x)) return resolv(x);
|
f84841 | 2001-08-29 | Marcus Comstedt | | if(sscanf(x,"mpath:%s",x))
foreach(pike_module_path, string path)
if(object ret=low_cast_to_object(combine_path(path,x),0))
return ret;
|
2f6176 | 1999-04-29 | Fredrik Hübinette (Hubbe) | | return cast_to_object(x,0);
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
program programof(string x)
{
if(sscanf(x,"efun:%s",x)) return f[x];
|
b1693a | 2000-04-07 | Fredrik Hübinette (Hubbe) | | if(sscanf(x,"resolv:%s",x)) return resolv(x);
|
f84841 | 2001-08-29 | Marcus Comstedt | | if(sscanf(x,"mpath:%s",x))
foreach(pike_module_path, string path)
if(program ret=cast_to_program(combine_path(path,x),0))
return ret;
|
2f6176 | 1999-04-29 | Fredrik Hübinette (Hubbe) | | return cast_to_program(x,0);
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
mixed encode_object(object x)
{
|
b1693a | 2000-04-07 | Fredrik Hübinette (Hubbe) | | if(x->_encode) return x->_encode();
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | error("Cannot encode objects yet.\n");
}
|
d28a71 | 2001-07-02 | Henrik Grubbström (Grubba) | | void decode_object(object o, mixed data)
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | {
|
b1693a | 2000-04-07 | Fredrik Hübinette (Hubbe) | | o->_decode(data);
|
471ed9 | 1998-04-24 | Fredrik Hübinette (Hubbe) | | }
}
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
|
5d6a56 | 2001-11-08 | Fredrik Hübinette (Hubbe) | |
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //! Contains version information about a Pike version.
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | class Version
{
|
6df5a5 | 2001-11-07 | Martin Nilsson | |
//! The major and minor parts of the version.
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | int major;
int minor;
|
6df5a5 | 2001-11-07 | Martin Nilsson | |
//! @decl void create(int major, int minor)
//! Set the version in the object.
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | void create(int maj, int min)
|
6df5a5 | 2001-11-07 | Martin Nilsson | | {
major = maj;
minor = min;
}
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
|
b8cd05 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | #define CMP(X) ((major - (X)->major) || (minor - (X)->minor))
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //! Methods define so that version objects
//! can be compared and ordered.
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | int `<(Version v) { return CMP(v) < 0; }
int `>(Version v) { return CMP(v) > 0; }
int `==(Version v) { return CMP(v)== 0; }
int _hash() { return major * 4711 + minor ; }
string _sprintf() { return sprintf("%d.%d",major,minor); }
|
6df5a5 | 2001-11-07 | Martin Nilsson | |
//! The version object can be casted into a string.
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | mixed cast(string type)
{
switch(type)
{
case "string":
return sprintf("%d.%d",major,minor);
}
}
}
|
6df5a5 | 2001-11-07 | Martin Nilsson | | //! Version information about the current Pike version.
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | Version currentversion=Version(__MAJOR__,__MINOR__);
|
6df5a5 | 2001-11-07 | Martin Nilsson | |
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | mapping(Version:CompatResolver) compat_handler_cache=set_weak_flag( ([]), 1);
CompatResolver get_compilation_handler(int major, int minor)
{
CompatResolver ret;
Version v=Version(major,minor);
if(v > currentversion)
{
/* do we want to make an error if major.minor > __MAJOR__.__MINOR ? */
return 0;
}
if(!zero_type(ret=compat_handler_cache[v])) return ret;
|
5be4aa | 2001-11-12 | Martin Stjernholm | | array files;
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | array(Version) available=({});
#if "¤share_prefix¤"[0]!='¤'
|
5be4aa | 2001-11-12 | Martin Stjernholm | | if (!(files = get_dir("¤share_prefix¤"))) {
werror ("Error listing directory %O: %s\n",
"¤share_prefix¤", strerror (errno()));
files = ({});
}
foreach(files, string ver)
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | {
if(sscanf(ver,"%d.%d",int maj, int min))
{
Version x=Version(maj, min) ;
if(x >= v)
available|=({ x });
}
}
#endif
#if "¤lib_prefix¤"[0]!='¤'
|
5be4aa | 2001-11-12 | Martin Stjernholm | | if (!(files = get_dir("¤lib_prefix¤"))) {
werror ("Error listing directory %O: %s\n",
"¤lib_prefix¤", strerror (errno()));
files = ({});
}
foreach(files, string ver)
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | {
if(sscanf(ver,"%d.%d",int maj, int min))
{
Version x=Version(maj, min) ;
if(x >= v)
available|=({ x });
}
}
#endif
sort(available);
#ifndef RESOLVER_HACK
/* We need to define RESOLVER_HACK when we add
* version-specific stuff in the CompatResolver.
* As long as all the compatibility is done in the
* module dierctories, RESOLVER_HACK can be undefined
*/
/* No compat needed */
if(!sizeof(available))
{
compat_handler_cache[v]=0;
return 0;
}
/* Same as available[0] */
if(ret=compat_handler_cache[available[0]])
return compat_handler_cache[v]=ret;
#endif
ret=CompatResolver(v);
|
b8cd05 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | /* Add default paths */
ret->pike_module_path=pike_module_path;
ret->pike_include_path=pike_include_path;
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
|
b8cd05 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | foreach(reverse(available), Version tmp)
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | {
string base;
#if "¤lib_prefix¤"[0]!='¤'
|
b8cd05 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | base=combine_path("¤lib_prefix¤",sprintf("%s",tmp));
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | ret->add_module_path(combine_path(base,"modules"));
ret->add_include_path(combine_path(base,"include"));
#endif
#if "¤share_prefix¤"[0]!='¤'
|
b8cd05 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | base=combine_path("¤share_prefix¤",sprintf("%s",tmp));
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | ret->add_module_path(combine_path(base,"modules"));
ret->add_include_path(combine_path(base,"include"));
#endif
}
|
b8cd05 | 2000-09-26 | Fredrik Hübinette (Hubbe) | | if( v <= Version(0,6))
ret->pike_module_path+=({"."});
|
a20af6 | 2000-09-26 | Fredrik Hübinette (Hubbe) | |
compat_handler_cache[v] = ret;
#ifndef RESOLVER_HACK
compat_handler_cache[available[0]] = ret; /* may be equal to 'v' */
#endif
return ret;
}
string _sprintf()
{
return "master()";
}
|