pike.git / src / modules / Image / mkdoc.pike

version» Context lines:

pike.git/src/modules/Image/mkdoc.pike:49:    || nowM==classM    || nowM==methodM    || nowM==moduleM)) return nowM;    else return nowM=methodM;   }      #define complain(X) (X)      mapping keywords=   (["module":lambda(string arg,int line) -  { nowM=moduleM=focM(parse,stripws(arg),line); classM=methodM=0; +  { descM=nowM=moduleM=focM(parse,stripws(arg),line); classM=methodM=0;    if (!nowM->classes) nowM->classes=([]); },    "class":lambda(string arg,int line)    { if (!moduleM) return complain("class w/o module"); -  nowM=classM=focM(moduleM->classes,stripws(arg),line); +  descM=nowM=classM=focM(moduleM->classes,stripws(arg),line);    methodM=0; },    "method":lambda(string arg,int line)    { if (!classM) return complain("method w/o class"); -  if (!nowM || methodM!=nowM || methodM->desc || methodM->args) +  if (!nowM || methodM!=nowM || methodM->desc || methodM->args || descM==methodM)    { if (!classM->methods) classM->methods=({});    classM->methods+=({methodM=nowM=(["decl":({}),"_line":line])}); } -  methodM->decl+=({stripws(arg)}); }, +  methodM->decl+=({stripws(arg)}); descM=0; },    "arg":lambda(string arg,int line)    {    if (!methodM) return complain("arg w/o method");    if (nowM!=argM || !argM)    { if (!methodM->args) methodM->args=({});    methodM->args+=({argM=nowM=(["args":({}),"_line":line])}); } -  argM->args+=({arg}); +  argM->args+=({arg}); descM=argM;    },    "note":lambda(string arg,int line)    {    if (!lower_nowM())    return complain("note w/o method, class or module"); -  nowM=nowM->note||(nowM->note=(["_line":line])); +  descM=nowM->note||(nowM->note=(["_line":line]));    },    "see":lambda(string arg,int line)    {    if (arg[0..4]!="also:")    return complain("see w/o 'also:'\n");    if (!lower_nowM())    return complain("see also w/o method, class or module");    nowM["see also"]=map(arg[5..]/",",stripws);    },    "returns":lambda(string arg)    {    if (!methodM)    return complain("returns w/o method"); -  nowM=0; +     methodM->returns=stripws(arg); -  +  descM=0; nowM=0;    }   ]);      string getridoftabs(string s)   {    string res="";    for (;;)    {    int i;    if ((i=search(s,"\t"))==-1) return res+s;
pike.git/src/modules/Image/mkdoc.pike:110:    s=s[i+1..];    res+=" "[(strlen(res)%8)..7];    }   }      string addprefix(string suffix,string prefix)   {    return prefix+suffix;   }    + #define urlify(S) (replace((S),({"%","&","'","\"","`"}), \ +  ({"%25","%26","%27","%22","%60"}))) + #define htmlify(S) (replace((S),({"&","\240"}),({"&amp;","&nbsp;"}))) +    string make_nice_reference(string refto,string my_prefix)   { -  return "<tt><a href=#>"+refto+"</a></tt>"; +  string my_module,my_class,link,s,t; +  +  if (sscanf(my_prefix,"%s.%s",my_module,my_class)==1) +  my_class=0; +  +  switch ((search(refto,"::")!=-1)+(search(refto,".")!=-1)*2) +  { +  case 0: if (refto!=my_module) link=my_prefix+"::"+refto; +  else link=refto; +  break; +  case 1: link=my_module+"."+refto; break; +  case 2: +  case 3: link=refto; break;    }    -  +  if (search(link,"::")!=-1) +  link=replace(link,"::",".html#"); +  else +  link+=".html"; +  return "<tt><a href="+urlify(link)+">"+refto+"</a></tt>"; + } +    object(File) make_file(string filename)   {    stdout->write("creating "+filename+"...\n");    if (file_size(filename)>0)    {    rm(filename+"~");    mv(filename,filename+"~");    }    object f=File();    if (!f->open(filename,"wtc"))
pike.git/src/modules/Image/mkdoc.pike:144:    s=stripws(s);       string t,u,v;    t=s; s="";    while (sscanf(t,"%s<ref>%s</ref>%s",t,u,v)==3)    {    s+=t+make_nice_reference(u,prefix);    t=v;    }    s+=t; -  return replace(s,"\n\n","\n\n<p>"); +  return htmlify(replace(s,"\n\n","\n\n<p>"));   }      string standard_doc(mapping info,string myprefix)   {    string res="";       if (info->desc && stripws(info->desc)!="") -  res+="\n\n<blockquote>\n"+info->desc+"\n</blockquote>\n"; +  res+="\n\n<blockquote>\n"+fixdesc(info->desc,myprefix)+ +  "\n</blockquote>\n";       if (info->note)    res+="\n\n<h4>NOTE</h4>\n<blockquote>\n"+ -  fixdesc(info->desc,myprefix)+"\n</blockquote>\n"; +  fixdesc(info->note->desc,myprefix)+"\n</blockquote>\n";       if (info["see also"])    {    res+=    "\n\n<h4>SEE ALSO</h4>\n<blockquote> " +    map(info["see also"],make_nice_reference,myprefix)*",\n " +    "\n</blockquote>\n";    }       return res;
pike.git/src/modules/Image/mkdoc.pike:181:    mapping info,    string prefix,    string *refs)   {    object f=make_file(file);    f->write("<title>Pike documentation: "+title+"</title>\n"+    "<h2>"+title+"</h2>\n"+    standard_doc(info,prefix));    if (sizeof(refs))    { -  f->write("<h3>More documentation:</h3>\n <i><tt>" + +  f->write("<h3>More documentation:</h3>\n <i>" +    map(map(refs,addprefix,prefix),    make_nice_reference,prefix)*"</tt></i><br>\n <i><tt>" + -  "</tt></i>\n\n"); +  "</i>\n\n");    }    f->close();   }      multiset(string) get_method_names(string *decls)   {    string decl,name;    multiset(string) names=(<>);    foreach (decls,decl)    {
pike.git/src/modules/Image/mkdoc.pike:209:   }      string synopsis_to_html(string s)   {    string type,name,arg;    if (sscanf(s,"%s%*[ \t]%s(%s",type,name,arg)!=4)    sscanf(s,"%s(%s",name,arg),type="";       return    type+" <b>"+name+"</b>("+ -  replace(arg,({","," "}),({", ","&nbsp"})); +  replace(arg,({","," "}),({", ","\240"}));   }      void document_method(object(File) f,    mapping method,    string prefix)   { -  +  string s; +     stdout->write("documenting "+prefix+" methods "+    sort(indices(method->names))*", "+"...\n");    -  f->write("\n<hr>\n" -  // anchors goes here -  "<h4>SYNOPSIS</h4>\n" +  f->write("\n<hr>\n"); +  +  foreach (sort(indices(method->names)),s) +  f->write("<a name="+urlify(s)+"> </a>\n"); +  +  f->write("<h4>SYNOPSIS</h4>\n"    "<blockquote>\n" -  "<tt>"+map(method->decl,synopsis_to_html)* -  "<br>\n"+ +  "<tt>"+htmlify(map(method->decl,synopsis_to_html)* +  "<br>\n")+    "</tt>\n</blockquote>\n\n");       if (method->desc && stripws(method->desc)!="")    {    f->write("<h4>DESCRIPTION</h4>\n"    "\n\n<blockquote>\n"+    fixdesc(method->desc,prefix)+    "\n</blockquote>\n");    }   
pike.git/src/modules/Image/mkdoc.pike:293:       multiset(string) method_names=(<>);    string *method_names_arr,method_name;    mapping method;       foreach (info->methods,method)    method_names|=(method->names=get_method_names(method->decl));       method_names_arr=sort(indices(method_names));    -  f->write("\n<hr>\n <i><tt>"+ -  map(method_names_arr,make_nice_reference,prefix)* -  "</tt></i><br>\n <i><tt>"+"</tt></i><br>\n\n"); + /* f->write("\n<hr>\n <i><tt>"+*/ + /* map(method_names_arr,make_nice_reference,prefix)**/ + /* "</tt></i><br>\n <i><tt>"+"</tt></i><br>\n\n");*/    // alphabetically       foreach (method_names_arr,method_name)    if (method_names[method_name])    {    // find it    foreach (info->methods,method)    if ( method->names[method_name] )    {    document_method(f,method,prefix);
pike.git/src/modules/Image/mkdoc.pike:370:    {    string err;    if ( (err=keywords[kw](arg,line)) )    {    stderr->write("Error on line "+line+": "+err+"\n");    return 1;    }    }    else    { -  if (!nowM && !(nowM=descM) ) +  if (!descM) descM=methodM; +  if (!descM)    {    stderr->write("Error on line "+line+": illegal description position\n");    return 1;    } -  if (!nowM->desc) nowM->desc=""; -  else nowM->desc+="\n"; +  if (!descM->desc) descM->desc=""; +  else descM->desc+="\n";    s=getridoftabs(s); -  nowM->desc+=s[search(s,"**!")+3..]; -  descM=nowM; nowM=0; +  descM->desc+=s[search(s,"**!")+3..];    }    }    }      // stderr->write(sprintf("%O",parse));       stdout->write("making docs...\n\n");       make_doc_files("doc/");    return 0;   }