pike.git / bin / mkxml.pike

version» Context lines:

pike.git/bin/mkxml.pike:1: - /* $Id: mkxml.pike,v 1.24 2001/07/17 03:50:43 nilsson Exp $ */ + /* $Id: mkxml.pike,v 1.25 2001/07/17 08:38:24 nilsson Exp $ */    - import Stdio; - import Array; -  +    mapping parse=([ " appendix":([]) ]);   int illustration_counter;    - function verbose=werror; -  +    #define error(X) throw( ({ (X), backtrace()[0..sizeof(backtrace())-2] }) )      /*      module : mapping <- moduleM    "desc" : text    "see also" : array of references    "note" : mapping of "desc": text    "modules" : same as classes (below)    "classes" : mapping
pike.git/bin/mkxml.pike:36:      Quoting: Only '<' must be quoted as '&lt;'.      */      mapping moduleM, classM, methodM, argM, nowM, descM, appendixM;      mapping focM(mapping dest,string name,string line)   {    if (!dest->_order) dest->_order=({}); -  if (-1==search(dest->_order,name)) dest->_order+=({name}); +  if (!has_value(dest->_order,name)) dest->_order+=({name});    return dest[name] || (dest[name]=(["_line":line]));   }      string stripws(string s)   {    if (s=="") return s;       array lines = s / "\n";       lines = map(lines, lambda(string s) {
pike.git/bin/mkxml.pike:75:    if (nowM &&    (nowM==parse    || nowM==classM    || nowM==methodM    || nowM==moduleM)) return nowM;    else return nowM=methodM;   }      void report(string s)   { -  verbose("mkxml: "+s+"\n"); +  werror("mkxml: "+s+"\n");   }      #define complain(X) (X)      string file_version = "";      mapping keywords=   (["$Id":lambda(string arg, string line)    {    file_version = " version='Id: "+arg[..search(arg, "$")-1]+"'"; -  werror("mkxml: Version: "+file_version+"\n"); +     },    "appendix":lambda(string arg,string line) {    descM=nowM=appendixM=focM(parse[" appendix"],stripws(arg),line);    report("appendix "+arg);},    "module":lambda(string arg,string line)    { classM=descM=nowM=moduleM=focM(parse,stripws(arg),line);    methodM=0;    if (!nowM->classes) nowM->classes=(["_order":({})]);    if (!nowM->modules) nowM->modules=(["_order":({})]);    report("module "+arg); },
pike.git/bin/mkxml.pike:228:    !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(c), p->tag_name()) }); + } +    string fixdesc(string s,string prefix,string where)   {    s=htmlify(stripws(replace(s, "<p>", "\n")));       Parser.HTML p = Parser.HTML();    p->add_container("illustration",    lambda(Parser.HTML p, mapping args, string c)    {    return ({ sprintf("<illustration %s%{ %s='%s'%}>%s</illustration>",    where, (array)args, replace(c, "lena()", "src")) });    });    -  foreach( ({ "pre", "table", "execute", "ul" }), string tag) -  p->add_container(tag, -  lambda(Parser.HTML p, mapping args, string c) -  { -  return ({ sprintf("<%s%{ %s='%s'%}>%s</%s>", tag, -  (array)args, safe_newlines(c), tag) }); -  }); +  p->add_containers( ([ "pre":tag_preserve_ws, +  "table":tag_preserve_ws, +  "execute":tag_preserve_ws, +  "ul":tag_preserve_ws ]) );       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)
pike.git/bin/mkxml.pike:517:    mapping huh,string name,string prefix,    object f)   {    array(string) names;       if (huh->names)    names=map(indices(huh->names),addprefix,name);    else    names=({name});    -  verbose("mkxml: "+name+" : "+names*","+"\n"); +  report(name+" : "+names*",");       array v=name/".";    string canname=v[-1];    sscanf(canname,"%s->",canname);    sscanf(canname,"%s()",canname);       if (convname[canname]) canname=convname[canname];       switch (enttype)    {
pike.git/bin/mkxml.pike:716:    if (method_names[method_name])    {    // find it    foreach (huh->methods,method)    if ( method->names[method_name] )    {    document("method",method,prefix,prefix,f);    method_names-=method->names;    }    if (method_names[method_name]) -  stderr->write("failed to find "+method_name+" again, wierd...\n"); +  Stdio.stderr->write("failed to find "+method_name+" again, wierd...\n");    }    }       if (huh->classes)    {    foreach(huh->classes->_order,string n)    {   // f->write("\n\n\n<section title=\""+prefix+n+"\">\n");    document("class",huh->classes[n],    prefix+n,prefix+n+"->",f);
pike.git/bin/mkxml.pike:774:    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_tag("dl", -  lambda(Parser.HTML p, mapping args) -  { -  return ({ sprintf("<dl%{ %s='%s'%}>", (array)args) }); -  }); -  html2xml->add_tag("dt", -  lambda(Parser.HTML p, mapping args) -  { -  return ({ sprintf("<dt%{ %s='%s'%}>", (array)args) }); -  }); -  html2xml->add_tag("table", -  lambda(Parser.HTML p, mapping args) -  { -  return ({ sprintf("<table%{ %s='%s'%}>", (array)args) }); -  }); -  html2xml->add_tag("tr", -  lambda(Parser.HTML p, mapping args) -  { -  return ({ sprintf("<tr%{ %s='%s'%}>", (array)args) }); -  }); -  html2xml->add_tag("td", -  lambda(Parser.HTML p, mapping args) -  { -  return ({ sprintf("<td%{ %s='%s'%}>", (array)args) }); -  }); -  html2xml->add_tag("th", -  lambda(Parser.HTML p, mapping args) -  { -  return ({ sprintf("<th%{ %s='%s'%}>", (array)args) }); -  }); -  html2xml->add_tag("ref", -  lambda(Parser.HTML p, mapping args) -  { -  return ({ sprintf("<ref%{ %s='%s'%}>", (array)args) }); -  }); -  */ -  +     html2xml->add_container(    "text",    lambda(Parser.HTML p,mapping args,string cont)    { - // werror("%O\n",cont); +     cont=p->clone()->finish(cont)->read(); - // werror("---\n"); - // werror("%O\n",cont); +     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 });    });    -  stderr->write("modules: "+sort(indices(parse)-({" appendix"}))*", "+"\n"); +  Stdio.stderr->write("modules: "+sort(indices(parse)-({" appendix"}))*", "+"\n");    -  stdout->write("<module name=''>\n"); +  Stdio.stdout->write("<module name=''>\n");       foreach (sort(indices(parse)-({"_order", " appendix"})),string module) -  document("module",parse[module],module,module+".",stdout); +  document("module",parse[module],module,module+".", Stdio.stdout);       if(appendixM)    foreach(parse[" appendix"]->_order, string title) -  document("appendix",parse[" appendix"][title],title,"",stdout); +  document("appendix",parse[" appendix"][title],title,"", Stdio.stdout);    -  stdout->write("</module>\n"); +  Stdio.stdout->write("</module>\n");   }      void process_line(string s,string currentfile,int line)   {    s=getridoftabs(s);       int i;    if ((i=search(s,"**!"))!=-1 || (i=search(s,"//!"))!=-1)    {    string kw,arg;       sscanf(s[i+3..],"%*[ \t]%[^: \t\n\r]%*[: \t]%s",kw,arg);    if (keywords[kw])    {    string err;    if ( (err=keywords[kw](arg,"file='"+currentfile+"' line='"+line+"'")) )    { -  stderr->write("mkxml: "+ -  currentfile+"file='"+currentfile+"' line="+line); +  report(currentfile+"file='"+currentfile+"' line="+line);    exit(1);    }    }    else if (s[i+3..]!="")    {    string d=s[i+3..];    // sscanf(d,"%*[ \t]!%s",d);    // if (search(s,"$Id")!=-1) report("Id: "+d);    if (!descM) descM=methodM;    if (!descM)    { -  stderr->write("mkxml: "+ -  currentfile+" line "+line+ -  ": illegal description position\n"); +  report(currentfile+" line "+line+": illegal description position");    exit(1);    }    if (!descM->desc) descM->desc="";    else descM->desc+="\n";    d=getridoftabs(d);    descM->desc+=d;    }    else if (descM)    {    if (!descM->desc) descM->desc="";
pike.git/bin/mkxml.pike:913:    string old;    do {    old = in;    in = replace(in, "\n\n", "\n \n");    } while(old!=in);    return in;   }      int main(int ac,string *files)   { -  string s,t; +  string s,t,currentfile;    int line;    array(string) ss=({""});    object f;    -  string currentfile; -  +     nowM=parse;    -  stderr->write("reading and parsing data...\n"); -  +     files=files[1..];    -  if (sizeof(files) && files[0]=="--nonverbose") -  files=files[1..],verbose=lambda(){}; +  report("reading files...");    -  stderr->write("mkxml: reading files...\n"); -  +     for (;;)    {    int i;       if (!f)    {    if (!sizeof(files)) break; -  verbose("mkxml: reading "+files[0]+"...\n"); +     file_version = ""; -  f=File(); +  f=Stdio.File();    currentfile=files[0];    files=files[1..];    if (!f->open(currentfile,"r")) { f=0; continue; }    t=0;    ss=({""});    line=0;    }       if (sizeof(ss)<2)    {    if (t=="") { f=0; continue; }    t=f->read(8192);    if (!t)    { -  werror("mkxml: failed to read %O\n",currentfile); +  report(sprintf("failed to read %O",currentfile));    f=0;    continue;    }    s=ss[0];    ss=t/"\n";    ss[0]=s+ss[0];    }    s=ss[0]; ss=ss[1..];       line++;    process_line(s,currentfile,line);    }    - // stderr->write(sprintf("%O",parse)); +  report("making docs...\n");    -  stderr->write("mkxml: making docs...\n\n"); -  +     make_doc_files();       return 0;   }