Roxen.git / server / modules / scripting / piketag.pike

version» Context lines:

Roxen.git/server/modules/scripting/piketag.pike:1:   // This is a roxen module. Copyright © 1996 - 2000, Roxen IS.   //   // Adds support for inline pike in documents.   //   // Example:   // <pike>   // return "Hello world!\n";   // </pike>    - constant cvs_version = "$Id: piketag.pike,v 2.7 2000/07/17 19:18:39 jhs Exp $"; + constant cvs_version = "$Id: piketag.pike,v 2.8 2000/08/09 02:33:09 per Exp $";   constant thread_safe=1;      inherit "module";   #include <module.h>      constant module_type = MODULE_PARSER;   constant module_name = "Pike tag";   constant module_doc =   #"This module adds a new tag, &lt;pike&gt;&lt;/pike&gt;. It makes it   possible to insert some pike code directly in the document. <br>
Roxen.git/server/modules/scripting/piketag.pike:73:    void output(mixed ... args)    {    if(!sizeof(args))    return;    if(sizeof(args) > 1)    data += sprintf(@args);    else    data += args[0];    }    +  void write(mixed ... args) +  { +  if(!sizeof(args)) +  return; +  if(sizeof(args) > 1) +  data += sprintf(@args); +  else +  data += args[0]; +  } +     string flush()    {    string r = data;    data ="";    return r;    }       constant seteuid=0;    constant setegid=0;    constant setuid=0;    constant setgid=0;    constant call_out=0;    constant all_constants=0;    constant Privs=0;   }      string functions(string page, int line)   { -  add_constant( "__magic_helpers", Helpers ); -  return -  "inherit __magic_helpers;\n" +  add_constant( "__ps_magic_helpers", Helpers ); +  return "inherit __ps_magic_helpers;\n" +    "#"+line+" \""+replace(page,"\"","\\\"")+"\"\n";   }      // Preamble   string pre(string what, object id)   { -  if(search(what, "parse(") != -1) +  if(search(what, " parse(") != -1)    return functions(id->not_query, id->misc->line); -  if(search(what, "return") != -1) +     return functions(id->not_query, id->misc->line) + -  "string|int parse(RequestID id, mapping defines, object file, mapping args) { "; -  else -  return functions(id->not_query, id->misc->line) + -  "string|int parse(RequestID id, mapping defines, object file, mapping args) { return "; +  "string|int parse(RequestID id) { ";   }      // Will be added at the end...   string post(string what)   { -  if(search(what, "parse(") != -1) +  if(search(what, " parse(") != -1)    return ""; -  if (!strlen(what) || what[-1] != ';') -  return ";}"; -  else +     return "}";   }      private static mapping(string:program) program_cache = ([]);    -  + string simple_pi_tag_pike( string tag, mapping m, string s,RequestID id ) + { +  return simpletag_pike( tag, ([]), s, id ); + } +    // Compile and run the contents of the tag (in s) as a pike   // program. - string container_pike(string tag, mapping m, string s, RequestID request_id, -  object file, mapping defs) + string simpletag_pike(string tag, mapping m, string s,RequestID request_id )   {    program p;    object o;    string res;    mixed err;       request_id->misc->cacheable=0;       object e = ErrorContainer();    master()->set_inhibit_compile_errors(e);    if(err=catch    {    s = pre(s,request_id)+s+post(s);    p = program_cache[s];       if (!p)    {    // Not in the program cache. -  +  object key = Roxen.add_scope_constants();    p = compile_string(s, "Pike-tag("+request_id->not_query+":"+    request_id->misc->line+")"); -  +  destruct( key ); +     if (sizeof(program_cache) > query("program_cache_limit"))    {    array a = indices(program_cache);    int i;       // Zap somewhere between 25 & 50% of the cache.    for(i = query("program_cache_limit")/2; i > 0; i--)    m_delete(program_cache, a[random(sizeof(a))]);    }    program_cache[s] = p;    }    })    {    master()->set_inhibit_compile_errors(0);    return reporterr(sprintf("Error compiling <pike> tag in %s:\n" -  "%s\n\n", request_id->not_query, s), +  "%s\n\n", request_id->not_query, +  s),    e->get());    }    master()->set_inhibit_compile_errors(0);       if(err = catch{ -  res = (o=p())->parse(request_id, defs, file, m); +  res = (o=p())->parse(request_id);    })    {    return (res || "") + (o && o->flush() || "") +    reporterr ("Error in <pike> tag in " + request_id->not_query + ":\n",    (describe_backtrace (err) / "\n")[0..1] * "\n");    }       res = (res || "") + (o && o->flush() || "");       if(o)    destruct(o);       return res;   }