pike.git / bin / htmlify_docs.lpc

version» Context lines:

pike.git/bin/htmlify_docs.lpc:3:   // Parse BMML (Black Magic Markup Language) to HTML   // Written by Fredrik Hubinette, dark sourceror and inventor of BMML      mapping efuns = all_efuns();   mapping pages = ([]);   mapping short_descs = ([]);   mapping keywords = ([]);   mapping subpages = ([]);      string new_path; + int writepages;    -  +    /*    * Implode an array of strings to an english 'list'    * ie. ({"foo","bar","gazonk"}) beomces "foo bar, gazonk"    */   string implode_nicely(string *foo)   {    switch(sizeof(foo))    {    case 0: return "";    case 1: return foo[0];
pike.git/bin/htmlify_docs.lpc:233:      string short(string s)   {    return short_descs[s] ? " - "+short_descs[s] : "";   }         inherit "/precompiled/regexp":is_example;      list(string) indexes_done=(<>); - string mkindex(string topic, int head) + string mkindex(string topic, int usehead)   {    string head;    string a,ret;    ret="";       indexes_done[topic]=1;       switch(topic)    { -  +  case "pages": +  head="<b>All pages:</b>\n"; +  ret="<ul>\n"; +  foreach(sort_array(m_indices(pages)),a) +  ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n"; +  +  ret+="</ul>\n"; +  break; +     case "programs":    head="<b>Builtin programs:</b>\n";    ret="<ul>\n";    foreach(sort_array(m_indices(pages)),a)    { -  if(-1 == search(a,"/")) continue; +  if(a[0]!='/') continue;       ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n";    }       ret+="</ul>\n";    break;    -  +  case "examples": +  head="<b>examples:</b>\n"; +  ret="<ul>\n"; +  foreach(sort_array(m_indices(pages)),a) +  { +  if(search(a,"example")==-1) continue; +  +  ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n"; +  } +  +  ret+="</ul>\n"; +  break; +     case "other":    head="<b>Other pages</b>\n";    ret="<ul>\n"; -  foreach(sort_array(m_indices(pages) - `+(@m_values(keywords))),a) +  foreach(sort_array(m_indices(pages) - +  map_array(`|(@m_values(keywords)),html_quote) - +  map_array(m_indices(all_efuns()),html_quote)),a)    { -  if(-1 != search(a,"/")) continue; +  if(a[0]=='/') continue; +  if(a[0..4]=="index") continue; +  if(search(a,"example")!=-1) continue;    ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n";    }    ret+="</ul>\n";    break;       case "efuns":    head="<b>All builtin functions:</b>\n";    ret="<ul>\n";    foreach(sort_array(m_indices(all_efuns())),a)    {    a=html_quote(a);    if(pages[a])    {    ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n";    }else{ -  +  if(writepages)    perror("Warning: no page for function: "+a+".\n");    }    }    ret+="</ul>\n";    break;       default:    if(!keywords[topic])    {    perror("Unknown keyword "+topic+".\n");    return "";    }       head="<a name="+topic+">";    head+="<b>"+capitalize(topic)+"</a>";    head+=short(topic);    head+="</b>\n";    ret="<ul>\n"; -  foreach(keywords[topic],a) +  foreach(sort_array(keywords[topic]),a)    {    a=html_quote(a);    ret+="<li><a href="+pages[a]+">"+a+"</a>"+ short(a) +"\n";    }    ret+="</ul></a>\n";    break;    }    -  if(head) ret=head+ret; +  if(usehead) ret=head+ret;       return ret;   }    - int writepages; -  +    /* Convert a page */   string convert_page(string path, string fname)   {    string output, short;    int headno;    string cont, section, name, part;       output="";       cont=read_bytes(path);
pike.git/bin/htmlify_docs.lpc:395:    perror("Warning: Unknown header: "+type+".\n");    rest=magic(rest,0);    break;       case "KEYWORDS":    a=replace(rest,({"\n"," ","\t"}),({"","",""}))/",";    b=({});    foreach(a,a)    {    // fixme!! -  keywords[a] = ( keywords[a] || ({}) ) + ({ name }); +  keywords[a] = ( keywords[a] || ({}) ) | ({ name });    b+=({ "<a href=index.html#"+a+">"+a+"</a>" });    }    rest=implode_nicely(b);    break;       case "SEE ALSO":    rest=replace(rest,({"\n"," ","\t"}),({"","",""}));    a=rest/",";    b=({});    foreach(a,a)
pike.git/bin/htmlify_docs.lpc:448:    case "RELATED FUNCTIONS":    a=name;    sscanf(rest,"%*skeyword %[a-z/A-Z0-9]",a);    rest=mkindex(a, 0);    }       sections[headno]="<dt>"+    smallcaps(type)+    "<dd>\n"+rest+"\n<p>";    } +  if(keywords[part_name]) +  { +  sections+=({"<dt>"+ +  smallcaps("RELATED PAGES")+"\n"+ +  mkindex(part_name,0)+"<p>"}); +  }    parts[partno]="<dl>\n"+implode(sections,"\n")+"\n</dl>\n";    if(part_name)    {    parts[partno]="<a name="+part_name+">\n"+    parts[partno]+    "\n</a>\n";    }    }    output=mkdocument(implode(parts,"<hr noshade size=1>\n"),"uLPC: "+name);    }
pike.git/bin/htmlify_docs.lpc:472:    int section;       pages[(path[..strlen(path)-6]/"/")[-1]]=fippel_path(path);       cont=replace(cont,"$version",version());    cont=html_quote(cont);    sections=explode(cont,"\n\n");       for(section=0;section<sizeof(sections);section++)    { -  string tmp,pre,a; +  string tmp,pre,a,b;    tmp=sections[section];    sscanf(tmp,"%[\t ]",pre);       switch(pre)    {    case "": -  tmp="<h1><center>"+tmp+"</center></h1>"; +     title=tmp; -  +  tmp="<h1><center>"+tmp+"</center></h1>";    break;       case " ":    sscanf(tmp," %s",tmp);    tmp="<h2>"+tmp+"</h2>";    break;       case " ":    sscanf(tmp," %s",tmp);    tmp=replace(tmp,"\n ","\n");
pike.git/bin/htmlify_docs.lpc:503:       case "\t":    sscanf(tmp,"\t%s %s",pre, a);    switch(pre)    {    case "KEYWORD_INDEX":    sscanf(a,"%s\n",a);    tmp=mkindex(a, 1);    break;    +  case "KEYWORD_LIST": +  sscanf(a,"%s\n",a); +  tmp=mkindex(a, 0); +  break; +  +  case "LINK": +  sscanf(a,"%s %s",a,b); +  tmp="<a href="+a+".html>"+b+"</a>"; +  break; +     default:    perror("Unknown directive: "+pre+".\n");    }       } -  +  sections[section]=tmp;    }    cont=implode(sections,"\n<p>\n");       return mkdocument(cont, title || "uLPC manual");    }    else if(path[strlen(path)-5..]==".html")    {    pages[(path[..strlen(path)-6]/"/")[-1]]=fippel_path(path);       if(sscanf(cont,"<title>%s</title>",part))
pike.git/bin/htmlify_docs.lpc:664:    is_example::create("^(" LINE ")+$");       new_path=combine_path(getcwd(),argv[2]);    cd(argv[1]);       write("Scanning pages for links and keywords.\n");    writepages=0;    traversedir(".",scanfiles);       write("Writing html files.\n"); -  writepages=0; +  writepages=1;    traversedir(".",scanfiles);       foreach(indices(keywords) - indices(indexes_done),np)    {    perror("Keywords never indexed: "+np+"\n");    }   }