pike.git / bin / mkxml.pike

version» Context lines:

pike.git/bin/mkxml.pike:1: - /* $Id: mkxml.pike,v 1.30 2001/07/20 04:18:18 nilsson Exp $ */ + /* $Id: mkxml.pike,v 1.31 2001/07/25 21:20:08 nilsson Exp $ */      string LENA_PATH = "../autodoc/image_ill.pnm";   string makepic1;   string makepic2;      mapping parse=([ " appendix":([]) ]);   int illustration_counter;      #define error(X) throw( ({ (X), backtrace()[0..sizeof(backtrace())-2] }) )   
pike.git/bin/mkxml.pike:226:    !parse[what])    {    q=prefix+what;    }    else    q=what;       return "<ref to="+linkify(q)+">"+htmlify(stuff)+"</ref>";   }    - array(string) tag_preserve_ws(Parser.HTML p, mapping args, string c) { -  return ({ sprintf("<%s%{ %s='%s'%}>%s</%s>", p->tag_name(), -  (array)args, safe_newlines(p->clone()->finish(c)->read()), -  p->tag_name()) }); - } + Parser.HTML parser;      string fixdesc(string s,string prefix,void|string where)   {    s = stripws(replace(s, "<p>", "\n"));    -  Parser.HTML p = Parser.HTML(); +  parser->set_extra(where);    -  p->add_containers( ([ "pre":tag_preserve_ws, -  "table":tag_preserve_ws, -  "execute":tag_preserve_ws, -  "ul":tag_preserve_ws ]) ); -  -  p->add_container("illustration", -  lambda(Parser.HTML p, mapping args, string c) -  { -  c = replace(c, ([ "&gt;":">" ])); -  string name; -  sscanf(where, "file='%s'", name); -  name = (name/"/")[-1]; -  array err; -  object g; -  err = catch { -  g = compile_string(makepic1 + c + -  makepic2)(name+(illustration_counter++), args->type); -  }; -  if(err) { -  werror("%O\n", where); -  throw(err); -  } -  -  return ({ g->make() }); -  -  // return ({ sprintf("<illustration %s%{ %s='%s'%}>%s</illustration>", -  // name, (array)args, replace(c, "lena()", "src")) }); -  }); -  -  p->add_container("data_description", -  lambda(Parser.HTML p, mapping args, string c) -  { -  if(args->type=="mapping") { -  Parser.HTML i = Parser.HTML()-> -  add_container("elem", -  lambda(Parser.HTML p, mapping args, string c) -  { -  if(!args->type) -  throw("mkxml: Type attribute missing on elem tag."); -  if(args->type!="int" && args->type!="float" && -  args->type!="string") -  throw("mkxml: Unknown type "+args->type+" in elem type attribute.\n"); -  if(!args->name) -  throw("mkxml: Name attribute missing on elem tag."); -  return "<group>\n<member><type><" + args->type + -  "/></type><index>\"" + args->name + "\"</index></member>\n" -  "<text><p>" + c + "</p></text>\n</group>\n"; -  }); -  return ({ "<mapping>\n " + -  safe_newlines(i->finish(c)->read()) + -  "</mapping>\n " }); -  } -  throw("mkxml: Unknown data_description type "+args->type+".\n"); -  }); -  -  s = p->finish(s)->read(); +  s = parser->finish(s)->read();    s = "<p>" + (s/"\n\n")*"</p>\n\n<p>" + "</p>";    s = htmlify(s);       if (where)    return "<source-position " + where + file_version + "/>\n"+s;       return s;   }      
pike.git/bin/mkxml.pike:519:    i++;    continue;    }       // Find name    string n = "";    i++;    for (; i<sizeof(in); i++) {    if(in[i]==')') {    if(!sizeof(String.trim_all_whites(n))) -  throw( ({ "Empty argument name.\n", backtrace() }) ); +  throw( ({ "Empty argument name. ("+in+")\n", backtrace() }) );    return res + "<argument name=" + S(n) + "><type>" + t +    "</type></argument>\n";    }    if(in[i]==',') {    if(!sizeof(String.trim_all_whites(n))) -  throw( ({ "Empty argument name.\n", backtrace() }) ); +  throw( ({ "Empty argument name. ("+in+")\n", backtrace() }) );    res += "<argument name=" + S(n) + "><type>" + t +    "</type></argument>\n";    break;    }    if(in[i]==' ') {    if(n=="...") {    n = "";    t = "<varargs>" + t + "</varargs>";    }    }
pike.git/bin/mkxml.pike:557:    " <arguments>"+paramlist(params)+"\n </arguments>\n");    }    else    {    f->write("<typevalue>"+doctype(rv)+"</typevalue>\n");    }       f->write("</"+enttype+">");   }    - Parser.HTML html2xml; -  +    void document(string enttype,    mapping huh,string name,string prefix,    object f)   {    array(string) names;       if (huh->names)    names=map(indices(huh->names),addprefix,name);    else    names=({name});
pike.git/bin/mkxml.pike:738:    lambda(string s)    {    return "<ref>"+htmlify(s)+"</ref>";    })*", ",    prefix,0);    res+="</text></group>\n";    }       if (res!="")    { -  res=html2xml->finish(res)->read(); +     f->write("<doc>\n"+res+"\n</doc>\n");    }      // ---childs----       if (huh->constants)    {    foreach(huh->constants,mapping m)    {    sscanf(m->decl,"%s %s",string type,string name);
pike.git/bin/mkxml.pike:830:    case "class":    case "module":    f->write("</"+enttype+">\n\n");    break;    default:    f->write("</docgroup>\n\n");    break;    }   }    - array(string) tag_quote_args(Parser.HTML p, mapping args) { -  return ({ sprintf("<%s%{ %s='%s'%}>", p->tag_name(), (array)args) }); - } -  +    void make_doc_files()   { -  html2xml=Parser.HTML(); -  html2xml->add_tag("br",lambda(mixed...) { return ({"<br/>"}); }); -  html2xml->add_tag("wbr",lambda(mixed...) { return ({"<br/>"}); }); -  -  html2xml->add_tags( ([ "dl":tag_quote_args, -  "dt":tag_quote_args, -  "dd":tag_quote_args, -  "table":tag_quote_args, -  "tr":tag_quote_args, -  "th":tag_quote_args, -  "td":tag_quote_args, -  "a":tag_quote_args, -  "ref":tag_quote_args ]) ); -  -  html2xml->add_container( -  "text", -  lambda(Parser.HTML p,mapping args,string cont) -  { -  cont=p->clone()->finish(cont)->read(); -  string res="<text><p>"+cont+"</p></text>"; -  string t; -  do -  { -  t=res; -  res=replace(res,"<p></p>",""); -  res=replace(res,"<br/></p>","</p>"); -  } -  while (t!=res); -  return ({res}); -  }); -  -  html2xml->add_container("link", -  lambda(Parser.HTML p, mapping args, string c) -  { -  return ({ sprintf("<ref%{ %s=\"%s\"%}>%s</ref>", (array)args, c) }); -  }); -  -  html2xml->add_container("execute", -  lambda(Parser.HTML p, mapping args, string c) -  { -  return ({ c }); -  }); -  +     Stdio.stderr->write("modules: "+sort(indices(parse)-({" appendix"}))*", "+"\n");       Stdio.stdout->write("<module name=''>\n");       foreach (sort(indices(parse)-({"_order", " appendix"})),string module)    document("module",parse[module],module,module+".", Stdio.stdout);       if(appendixM)    foreach(parse[" appendix"]->_order, string title)    document("appendix",parse[" appendix"][title],title,"", Stdio.stdout);
pike.git/bin/mkxml.pike:945:      string safe_newlines(string in) {    string old;    do {    old = in;    in = replace(in, "\n\n", "\n \n");    } while(old!=in);    return in;   }    + array(string) tag_quote_args(Parser.HTML p, mapping args) { +  return ({ sprintf("<%s%{ %s='%s'%}>", p->tag_name(), (array)args) }); + } +  + array(string) tag_preserve_ws(Parser.HTML p, mapping args, string c) { +  return ({ sprintf("<%s%{ %s='%s'%}>%s</%s>", p->tag_name(), +  (array)args, safe_newlines(p->clone()->finish(c)->read()), +  p->tag_name()) }); + } +    void create() {    -  +  parser = Parser.HTML(); +  +  Parser.HTML p = Parser.HTML(); +  +  parser->add_containers( ([ "pre":tag_preserve_ws, +  "table":tag_preserve_ws, +  "execute":tag_preserve_ws, +  "ul":tag_preserve_ws ]) ); +  +  parser->add_container("illustration", +  lambda(Parser.HTML p, mapping args, string c, string where) +  { +  c = replace(c, ([ "&gt;":">" ])); +  string name; +  sscanf(where, "file='%s'", name); +  name = (name/"/")[-1]; +  array err; +  object g; +  err = catch { +  g = compile_string(makepic1 + c + +  makepic2)(name+(illustration_counter++), args->type); +  }; +  if(err) { +  werror("%O\n", where); +  array rows = (makepic1+c+makepic2)/"\n"; +  werror("******\n"); +  for(int i; i<sizeof(rows); i++) +  werror("%04d: %s\n", i, rows[i]); +  werror("******\n"); +  throw(err); +  } +  +  return ({ g->make() }); +  }); +  +  parser->add_container("data_description", +  lambda(Parser.HTML p, mapping args, string c) +  { +  if(args->type=="mapping") { +  Parser.HTML i = Parser.HTML()-> +  add_container("elem", +  lambda(Parser.HTML p, mapping args, string c) +  { +  if(!args->type) +  throw("mkxml: Type attribute missing on elem tag."); +  if(args->type!="int" && args->type!="float" && +  args->type!="string") +  throw("mkxml: Unknown type "+args->type+" in elem type attribute.\n"); +  if(!args->name) +  throw("mkxml: Name attribute missing on elem tag."); +  return "<group>\n<member><type><" + args->type + +  "/></type><index>\"" + args->name + "\"</index></member>\n" +  "<text><p>" + c + "</p></text>\n</group>\n"; +  }); +  return ({ "<mapping>\n " + +  safe_newlines(i->finish(c)->read()) + +  "</mapping>\n " }); +  } +  throw("mkxml: Unknown data_description type "+args->type+".\n"); +  }); +  +  parser->add_tag("br",lambda(mixed...) { return ({"<br/>"}); }); +  parser->add_tag("wbr",lambda(mixed...) { return ({"<br/>"}); }); +  +  parser->add_tags( ([ "dl":tag_quote_args, +  "dt":tag_quote_args, +  "dd":tag_quote_args, +  "tr":tag_quote_args, +  "th":tag_quote_args, +  "td":tag_quote_args, +  "ref":tag_quote_args ]) ); +  +  parser->add_container( +  "text", +  lambda(Parser.HTML p,mapping args, string c) +  { +  c=p->clone()->finish(c)->read(); +  string res="<text><p>"+c+"</p></text>"; +  string t; +  do +  { +  t=res; +  res=replace(res,"<p></p>",""); +  res=replace(res,"<br/></p>","</p>"); +  } +  while (t!=res); +  return ({res}); +  }); +  +  parser->add_container("link", +  lambda(Parser.HTML p, mapping args, string c) +  { +  return ({ sprintf("<ref%{ %s=\"%s\"%}>%s</ref>", (array)args, c) }); +  }); +  +  parser->add_container("a", +  lambda(Parser.HTML p, mapping args, string c) +  { +  return ({ sprintf("<url%{ %s=\"%s\"%}>%s</url>", (array)args, c) }); +  }); +  +  parser->add_container("execute", +  lambda(Parser.HTML p, mapping args, string c) +  { +  return ({ c }); +  }); +     array tmp = __FILE__/"/";    string file = tmp[..sizeof(tmp)-2]*"/";    LENA_PATH = combine_path(file, LENA_PATH);       makepic1 = #"    string fn;       void create(string _fn, void|string type) {    fn = _fn;    string ext;
pike.git/bin/mkxml.pike:971:    object lena() {    object i = Image.load(\"" + LENA_PATH + #"\");    return i;    }       object|string render() {   ";       makepic2 = #";    } +     string make() {    object|string o=render(); -  if(stringp(o)) { +  if(objectp(o)) +  o=Image.PNG.encode(o); +     Stdio.write_file(fn, o); -  werror(\"Wrote %s\\n\", fn); +  werror(\"Wrote %s.\\n\", fn);    return \"<image>\"+fn+\"</image>\";    } -  -  Stdio.write_file(fn, Image.PNG.encode(o)); -  werror(\"Wrote %s.\\n\", fn); -  return \"<image width='\"+o->xsize()+\"' height='\"+o->ysize()+\"'>\"+fn+\"</image>\"; -  } +    ";       nowM = parse;   }