pike.git / lib / modules / Tools.pmod / Standalone.pmod / pike_to_html.pike

version» Context lines:

pike.git/lib/modules/Tools.pmod/Standalone.pmod/pike_to_html.pike:13:   The generated HTML will be written to stdout.      Usage:    pike -x pike_to_html \"path to file or string of code\"   ";      string delimiters = ",;:.>-+=()|[]&%#!<>^~*/`{}\\";   string res_words = "if|else|while|for|foreach|do|return|continue|break|"    "switch|case|default|goto|catch|lambda|gauge|inherit|import";   string type = "enum|float|int|typedef|void|object|class|mapping|string|" -  "array|multiset|mixed|function|program|bool"; +  "array|multiset|mixed|function|program|bool|auto";   string modifiers = "public|protected|private|static|constant|local|final|" -  "optional|variant"; +  "optional|variant|inline";   string constants = "UNDEFINED|__LINE__|__FILE__|__DIR__|__func__|"    "__VERSION__|__MAJOR__|__MINOR__|__BUILD__|"    "__REAL_VERSION__|__REAL_MAJOR__|__REAL_MINOR__|"    "__REAL_BUILD__|__DATE__|__TIME__|__AUTO_BIGNUM__|__NT__|"    "__PIKE__|__amigaos__|true|false|this|this_program"; -  + string known_macros = "if|ifdef|define|elif|else|endif|pike|require|include";      string namespaces = #"ADT -  + Apple   Arg   Array   Audio   Builtin   Bz2   Cache   Calendar   Charset   Colors   CommonLog -  + Concurrent   Crypto   DVB   Debug   DefaultCompilerEnvironment   Error   Filesystem   Float   Function   Fuse   GDK
pike.git/lib/modules/Tools.pmod/Standalone.pmod/pike_to_html.pike:111:   Unicode   VCDiff   Val   Web   Yabu   Yp   ZXID   _Ffmpeg   __builtin";    - protected multiset(string) delims, reserved, types, consts, ns, mods; + protected multiset(string) delims, reserved, types, consts, ns, mods, macros;      final int(0..1) main(int argc, array(string) argv)   {    if (argc == 1) {    werror("Missing argument.%s\n", HELP);    return 1;    }       string h = #"<!doctype html>   <html>
pike.git/lib/modules/Tools.pmod/Standalone.pmod/pike_to_html.pike:196:   //!   //! @param code   string convert(string code)   {    delims = (multiset)(delimiters/1);    reserved = (multiset)(res_words/"|");    types = (multiset)(type/"|");    consts = (multiset)(constants/"|");    ns = (multiset)(namespaces/"\n");    mods = (multiset)(modifiers/"|"); +  macros = (multiset)(known_macros/"|"); +     return make_html(Parser.Pike.split(code));   }      #define ADDTAG(TYP) add("<span class='" + TYP + "'>" + \    replace(tok, ([ "&" : "&amp;", \    "<" : "&lt;", \    ">" : "&gt;" ])) + "</span>")   #define ADD() add(replace(tok, ([ "&" : "&amp;", "<" : "&lt;", ">" : "&gt;" ])))    -  + protected string first_non_white(array(string) s) + { +  for (int i; i < sizeof(s); i++) { +  if (!(< " ", "\t", "\n" >)[s[i]]) +  return s[i]; +  } + }      protected string make_html(array(string) tokens)   {    String.Buffer buf = String.Buffer();    function add = buf->add;       tokens = ({ 0 }) + tokens + ({ " ", " " });       int i;    int len = sizeof(tokens) - 2;
pike.git/lib/modules/Tools.pmod/Standalone.pmod/pike_to_html.pike:257:    case '/':    ADDTAG("comment");    break;       case '#':    if (tok[1] == '"') {    ADDTAG("string");    }    else {    array(string) ntoks = Parser.Pike.split(tok[1..]); +  +  if (!macros[first_non_white(ntoks)]) { +  add("#", make_html(ntoks)); +  break; +  } +     tok = "#" + ntoks[0];    ADDTAG("macro");       if (ntoks[-1] == "\n")    ntoks = ntoks[..<1];       if (sizeof(ntoks) > 2 && (< "<", "\"" >)[ntoks[2]]) {    tok = ntoks[2..]*"";    add(ntoks[1]);    ADDTAG("string");    }    else if (ntoks[0] == "!") {    tok = ntoks[1..]*"";    ADDTAG("macro");    }    else if (sizeof(ntoks) > 1) { -  add("<span class='nested'>", make_html(ntoks[1..]), "</span>"); +  tok = ""; +  if (ntoks[-1][-1] == '\n' && tokens[i+1] == "\n") { +  ntoks[-1] = ntoks[-1][..<1];    } -  +  add(make_html(ntoks[1..]));    } -  +  }       break;       default:    ADD();    break;    }    } -  else ADD(); +  else { +  ADD();    }    } -  +  }       return buf->get();   }