pike.git / lib / master.pike.in

version» Context lines:

pike.git/lib/master.pike.in:1:   /* -*- Pike -*-    * -  * $Id: master.pike.in,v 1.136 2000/12/02 16:21:36 mast Exp $ +  * $Id: master.pike.in,v 1.137 2001/01/14 21:12:44 grubba Exp $    *    * Master-file for Pike.    *    * Based on master.pike 1.67.    */      // Some configurable parameters useful for debugging      #pike __REAL_VERSION__   #define PIKE_AUTORELOAD
pike.git/lib/master.pike.in:19:   #endif /* !defined(BT_MAX_STRING_LEN) || (BT_MAX_STRING_LEN <= 0) */   constant bt_max_string_len = BT_MAX_STRING_LEN;      // 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;      #ifndef PIKE_WARNINGS - #define PIKE_WARNINGS 0 + #define PIKE_WARNINGS 1   #endif /* PIKE_WARNINGS */      /*    * Functions begin here.    */      #ifdef PIKE_FAKEROOT   object o;   string fakeroot(string s)   {
pike.git/lib/master.pike.in:43:    if(glob(x,tmp1))    return s;   #endif    return PIKE_FAKEROOT+tmp1;   }   #else   #define fakeroot(X) X   #endif       -  + //! @global + //! Check if a path @[p] is fully qualified (ie not relative). + //! + //! @returns + //! Returns 1 if the path is absolute, 0 otherwise.   int is_absolute_path(string p)   {   #ifdef __NT__    p=replace(p,"\\","/");    if(sscanf(p,"%[a-zA-Z]:",string s) && sizeof(s)==1)    return 1;   #define IS_ABSOLUTE_PATH is_absolute_path   #else   #define IS_ABSOLUTE_PATH(X) ((X)[0]=='/')   #endif    return p[0]=='/';   }    -  + //! @global + //! 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. + //!   array(string) explode_path(string p)   {   #ifdef __NT__    p=replace(p,"\\","/");   #define EXPLODE_PATH(X) (replace((X),"\\","/")/"/")   #else   #define EXPLODE_PATH(X) ((X)/"/")   #endif    return p/"/";   }    -  + //! @global + //! Returns all but the last segment of a path. + //! + //! @seealso + //! @[basename()], @[explode_path()]   string dirname(string x)   {    array(string) tmp=EXPLODE_PATH(x);    return tmp[..sizeof(tmp)-2]*"/";   }    -  + //! @global + //! Returns the last segment of a path. + //! + //! @seealso + //! @[dirname()], @[explode_path()]   string basename(string x)   {    array(string) tmp=EXPLODE_PATH(x);    return tmp[-1];   }   #define DIRNAME dirname   #define BASENAME(X) (EXPLODE_PATH(X)[-1])      #define GETCWD_CACHE   #define FILE_STAT_CACHE
pike.git/lib/master.pike.in:125:      #define AUTORELOAD_CHECK_FILE(X)   #define AUTORELOAD_BEGIN()   #define AUTORELOAD_FINISH(VAR,CACHE,FILE)      #endif      int compat_major=-1;   int compat_minor=-1;    - program compile_string(string data, void|string name, object|void handler) + //! @global + //! Compile the Pike code in the string @[data] into a program. + //! If @[filename] is not specified, it will default to @tt{"-"@}. + //! + //! Functionally equal to @code{@[compile](@[cpp](@[source], @[filename]))@}. + //! + //! @seealso + //! @[compile()], @[cpp()], @[compile_file()] + //! + program compile_string(string source, void|string filename, +  object|void handler)   { -  return compile(cpp(data,name||"-", 0, handler, compat_major, compat_minor), +  return compile(cpp(source, filename||"-", 0, handler, +  compat_major, compat_minor),    handler,    compat_major,    compat_minor);   }         string master_read_file(string file)   {    object o=_static_modules.files()->Fd();    if(o->open(fakeroot(file),"r"))    return o->read();    return 0;   }    - program compile_file(string file, object|void handler) + //! @global + //! 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)   { -  AUTORELOAD_CHECK_FILE(file); -  return compile(cpp(master_read_file(file), -  file, 1, handler, compat_major, compat_minor), handler, -  compat_major, compat_minor ); +  AUTORELOAD_CHECK_FILE(filename); +  return compile(cpp(master_read_file(filename), +  filename, 1, handler, compat_major, compat_minor), +  handler, compat_major, compat_minor);   }         #ifdef GETCWD_CACHE   string current_path;   int cd(string s)   {    current_path=0;    return predef::cd(s);   }
pike.git/lib/master.pike.in:212:       return predef::file_stat(x);   }   #else   #define master_file_stat file_stat   #endif      mapping (string:string) environment=([]);       + //! @global + //! @decl string getenv(string varname) + //! @decl mapping(string:string) getenv() + //! + //! When called with no arguments, a mapping with all current envrionment + //! 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. + //!   string|mapping(string:string) getenv(string|void s)   {    if(!s) return environment + ([]);    return environment[s];   }      #if 0   variant mapping(string:string) getenv()   {    return environment + ([]);
pike.git/lib/master.pike.in:243:   }      mapping(string:string) getenv() |   string getenv(string s)   {    if(!s) return environment + ([]);    return environment[s];   }   #endif /* 0 */    - void putenv(string var, string val) + //! @global + //! Sets the environment variable @[varname] to @[value]. + //! + //! @seealso + //! @[getenv()] + //! + void putenv(string varname, string value)   { -  environment[var]=val; +  environment[varname] = value;   }    -  + //! @global   string normalize_path( string X )   {   #ifndef __NT__    return X;   #else    return replace(X,"\\","/");   #endif   }      mapping (string:program) programs=(["/master":object_program(this_object())]);
pike.git/lib/master.pike.in:474:    array bt = x[1];    werror ("%s%O\nOriginal error:\n%O\n", msg, bt, trace);    })    werror("%O\nOriginal error:\n%O\n",x,trace);    }) {    werror("sprintf() failed to write error.\n");    }    }   }    - object new(mixed prog, mixed ... args) + //! @global + //! @decl object new(string|program prog, mixed ... args) + //! @decl object clone(string|program prog, mixed ... args) + //! + //! 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)   {    if(stringp(prog))    {    if(program p=cast_to_program(prog,backtrace()[-2][0]))    return p(@args);    else    error(sprintf("new: failed to find program %s.\n",prog));    }    return prog(@args);   }
pike.git/lib/master.pike.in:825:    return values(cache);    }   };      // Variables mustn't be static to allow for replace_master().   // /grubba 1998-04-10   mapping(string:mixed) fc=([]);      object findmodule(string fullname)   { -  array stat; +     object o;    if(!zero_type(o=fc[fullname]))    {    return o;    }       if(Stat stat=master_file_stat(fakeroot(fullname+".pmod")))    {    if(stat[1]==-2)    return fc[fullname]=dirnode(fullname+".pmod");
pike.git/lib/master.pike.in:878:    array(string) pike_module_path=({});    array(string) pike_program_path=({});    int want_warnings = PIKE_WARNINGS;    string ver;       void create(mixed v)    {    ver=(string)v;    }    +  //! @global +  //! 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()] +  //!    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;    }    -  +  //! @global +  //! Remove a directory to search for include files. +  //! +  //! This function performs the reverse operation of @[add_include_path()]. +  //! +  //! @seealso +  //! @[add_include_path()] +  //!    void remove_include_path(string tmp)    {    tmp=normalize_path(combine_path_with_cwd(tmp));    pike_include_path-=({tmp});    }    -  +  //! @global +  //! Add a directory to search for modules. +  //! +  //! This is the same as the command line option @tt{-M@}. +  //! +  //! @seealso +  //! @[remove_module_path()] +  //!    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;    }       -  +  //! @global +  //! Remove a directory to search for modules. +  //! +  //! This function performs the reverse operation of @[add_module_path()]. +  //! +  //! @seealso +  //! @[add_module_path()] +  //!    void remove_module_path(string tmp)    {    tmp=normalize_path(combine_path_with_cwd(tmp));    pike_module_path-=({tmp});    }       -  +  //! @global +  //! Add a directory to search for programs. +  //! +  //! This is the same as the command line option @tt{-P@}. +  //! +  //! @seealso +  //! @[remove_program_path()] +  //!    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;    }       -  +  //! @global +  //! Remove a directory to search for programs. +  //! +  //! This function performs the reverse operation of @[add_program_path()]. +  //! +  //! @seealso +  //! @[add_program_path()] +  //!    void remove_program_path(string tmp)    {    tmp=normalize_path(combine_path_with_cwd(tmp));    pike_program_path-=({tmp});    }       mapping get_default_module()    {    /* This is an ugly kluge to avoid an infinite recursion.    * The infinite recursion occurs because this function is
pike.git/lib/master.pike.in:1131:    ({"ipath",tmp->HAS_ARG,({"-I","--include-path"})}),    ({"ppath",tmp->HAS_ARG,({"-P","--program-path"})}),    ({"showpaths",tmp->NO_ARG,"--show-paths"}),    ({"warnings",tmp->NO_ARG,({"-w","--warnings"})}),    ({"nowarnings",tmp->NO_ARG,({"-W", "--woff", "--no-warnings"})}),   #ifdef PIKE_AUTORELOAD    ({"autoreload",tmp->NO_ARG,({"--autoreload"})}),   #endif    ({"master",tmp->HAS_ARG,"-m"}),    ({"compiler_trace",tmp->NO_ARG,"--compiler-trace"}), +  ({"assembler_debug",tmp->MAY_HAVE_ARG,"--assembler-debug"}),    ({"optimizer_debug",tmp->MAY_HAVE_ARG,"--optimizer-debug"}),    ({"debug",tmp->MAY_HAVE_ARG,"--debug",0,1}),    ({"trace",tmp->MAY_HAVE_ARG,"--trace",0,1}),    ({"ignore",tmp->MAY_HAVE_ARG,"-Dqdatplr",0,1}),    ({"ignore",tmp->HAS_ARG,"-s"}),    }), 1);       /* Parse -M and -I backwards */    for(i=sizeof(q)-1;i>=0;i--)    {
pike.git/lib/master.pike.in:1186:    case "debug":    debug+=(int)q[i][1];    break;      #if constant(_compiler_trace)    case "compiler_trace":    _compiler_trace(1);    break;   #endif /* constant(_compiler_trace) */    + #if constant(_assembler_debug) +  case "assembler_debug": +  _assembler_debug((int)q[i][1]); +  break; + #endif /* constant(_assembler_debug) */ +    #if constant(_optimizer_debug)    case "optimizer_debug":    _optimizer_debug((int)q[i][1]);    break;   #endif /* constant(_optimizer_debug) */       case "trace":    trace+=(int)q[i][1];    break;   
pike.git/lib/master.pike.in:1767:    if (!catch (s = sprintf("%O",o)) && s != "object")    return s+"->"+name;    }    return name;   }      /* 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.    */ +  + //! @global + //! 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()] + //!   string describe_backtrace(mixed trace, void|int linewidth)   {    int e;    string ret;    int backtrace_len=((int)getenv("PIKE_BACKTRACE_LEN")) || bt_max_string_len;       if(!linewidth)    {    linewidth=99999;    catch
pike.git/lib/master.pike.in:1942:    -loop_start, loops)});    frames += tail;    }       ret += frames * "";    }       return ret;   }    - // Returns a short description of a backtrace, containing only the - // error message. + //! @global + //! 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()] + //!   string describe_error (mixed trace)   {    if((arrayp(trace) && sizeof(trace)==2 && stringp(trace[0])) ||    (objectp(trace) && trace->is_generic_error))    {    if (catch {    return trace[0] || "No error message.\n";    }) {    return "Error indexing backtrace!\n";    }