pike.git / bin / htmlify_docs.lpc

version» Context lines:

pike.git/bin/htmlify_docs.lpc:39:    return implode(ret," ")+"</b>";   }      /*    * convert original path to internal format    */   string fippel_path(string path)   {    sscanf(path,"./%s",path);    path=replace(path,"/","_"); +  if(path[strlen(path)-5..]==".bmml") path=path[..strlen(path)-6];    if(path[strlen(path)-5..]!=".html") path+=".html";       return path;   }      /*    * Three step conversion process...    */   string even_more_magic(string block, int indent)   {
pike.git/bin/htmlify_docs.lpc:203:    }    s=implode(tmp,"\n");    return "<tt>"+magic(s,1)+"</tt>";   }         /* HTML quoting / unquoting */      string html_quote(string s)   { -  return replace(s,({"&","<",">"}),({"&amp;","&lt;","&gt;"})); +  return replace(s,({"uLPC","&","<",">"}),({"µLPC","&amp;","&lt;","&gt;"}));   }      string html_unquote(string s)   {    return replace(s,({"&amp;","&lt;","&gt;"}),({"&","<",">"}));   }      string mkdocument(string s,string title)   {    return ("<html>"+
pike.git/bin/htmlify_docs.lpc:225:    html_quote(title)+    "</title>"+    "<body bgcolor=\"#A0E0C0\">"+    s+    "</body>"+    "</html>");   }      inherit "/precompiled/regexp":is_example;    + list(string) indexes_done=(<>); + string mkindex(string topic, int head) + { +  string head; +  string a,ret; +  ret=""; +  +  indexes_done[topic]=1; +  +  switch(topic) +  { +  case "programs": +  head="<b>Builtin programs:</b>\n"; +  ret="<ul>\n"; +  foreach(sort_array(m_indices(pages)),a) +  { +  if(-1 == search(a,"/")) 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) +  { +  if(-1 != search(a,"/")) 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{ +  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(b)+"</a>"; +  head+=short(b); +  head+="</b>\n"; +  ret="<ul>\n"; +  foreach(keywords[b],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; +  +  return ret; + } +    /* 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:256:    string part_name="error";    string *sections;    string part;    int section;       part=parts[partno];    if(!strlen(part)) continue;       sections=explode(part,"\n\n");    +  /* Merge sections that does not have a header together */    for(section=0;section<sizeof(sections);section++)    {    if(!strlen(sections[section]) ||    sections[section][0] < 'A' ||    sections[section][0] > 'Z')    {    sections[section-1]+="\n\n"+sections[section];    sections=sections[0..section-1]+sections[section+1..0x7fffffff];    section--;    }
pike.git/bin/htmlify_docs.lpc:338:    case "SYNTAX":    case "SYNTAX EXAMPLE":    rest=syntax_magic(rest);    break;       case "EXAMPLES":    case "EXAMPLE":    case "DIRECTIVE":    case "PREPROCESSOR DIRECTIVES":    rest="<tt>"+magic(rest,1)+"</tt>"; +  +  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>";    }    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);    } -  +  else if(path[strlen(path)-5..]==".bmml") +  { +  string *sections; +  string title; +  int section; +  +  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; +  tmp=sections[section]; +  sscanf(tmp,"%[\t ]",per); +  +  switch(space) +  { +  case "": +  tmp="<h1><center>"+tmp+"</center></h1>"; +  title=tmp; +  break; +  +  case " ": +  sscanf(tmp," %s",tmp); +  tmp="<h2>"+tmp+"</h2>"; +  break; +  +  case " ": +  sscanf(tmp," %s",tmp); +  tmp=replace(tmp,"\n ","\n"); +  tmp=more_magic(tmp); +  break; +  +  case "\t": +  sscanf(tmp,"\t%s %s",pre, a); +  switch(pre) +  { +  case "KEYWORD_INDEX": +  tmp=mkindex(a, 1); +  +  default: +  perror("Unknown directive: "+pre+".\n"); +  } +  +  } +  } +  cont=implode(sections,"\n<p>\n"); +  +  return mkdocument(cont, title || "uLPC manual"); +  }    else if(path[strlen(path)-5..]==".html")    {    if(sscanf(cont,"<title>%s</title>",part))    short_descs[(path/"/")[-1]]=part;    output=cont;    }    else if(is_example::match(cont))    {    /** Hmm, this looks like an example file to me... */    string line,tmp;
pike.git/bin/htmlify_docs.lpc:408:    }    tmp+=line+"\n";    }    output=mkdocument(output,"uLPC: "+    replace(explode(fname,"/")[-1],"_"," "));    }    return output;   }       + string short(string s) + { +  return short_descs[s] ? " - "+short_descs[s] : ""; + } +  + string convert_dot_bmml(string path, string fname) + { +  string output; +  +  output=""; +  +  if(path[strlen(path)-5..]==".bmml") +  { +  } +  return 0; + } +  + int writepages; +    void scanfiles(string path, string fname)   {    string nf,np; -  nf=convert_page(path, fname); +  nf=convert(path, fname);    -  if(nf && strlen(nf)) +  if(nf && strlen(nf) && writepages)    {    np=combine_path(new_path,fippel_path(path));   // write("Writing "+np+".\n");    if(file_size(np)>=0)    rm (np);    write_file(np,nf);    }   }      /*
pike.git/bin/htmlify_docs.lpc:492:    }    perror("Warning: not converting "+path+".\n");    }   }         /** Traverse directory **/   void traversedir(string path,function fun)   {    string file; -  foreach(get_dir(path) - ({"CVS","RCS"}),file) +  foreach(get_dir(path) - ({"CVS","RCS",".cvsignore"}),file)    {    string tmp;    if(file[-1]=='~') continue;    if(file[0]=='#' && file[-1]=='#') continue;    if(file[0]=='.' && file[1]=='#') continue;       tmp=path+"/"+file;       if(file_size(tmp)==-2)    {    traversedir(tmp,fun);    }else{    fun(tmp,file);    }    }   }    - string short(string s) - { -  return short_descs[s] ? " - "+short_descs[s] : ""; - } - /** Create an index for our newly created stuff **/ - string mkindex() - { -  string ret; -  string a,b; -  mapping tmp=pages+([]); -  -  ret=""; -  -  ret+="<H1>"+version()+" index</h1>\n"; -  -  ret+="<H2><b>Keyword lists</b></H2>\n<dl>\n"; -  foreach(sort_array(m_indices(keywords)),b) -  { -  ret+="<a name="+b+">"; -  ret+="<dt><h2>"+capitalize(b); -  ret+=short(b); -  ret+="</h2><dd>\n"; -  ret+="<ul>\n"; -  foreach(keywords[b],a) -  { -  a=html_quote(a); -  ret+="<li><a href="+pages[a]+">"+a+"</a>"+ short(a) +"\n"; -  m_delete(tmp,a); -  } -  ret+="</ul></a>\n"; -  } -  ret+="</dl>\n"; -  -  ret+="<H1>All builtin functions:</H1>\n<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{ -  perror("Warning: no page for function: "+a+".\n"); -  } -  m_delete(tmp,a); -  } -  ret+="</ul>\n"; -  -  ret+="</dl><H1>Builtin programs:</H1>\n<ul>\n"; -  foreach(sort_array(m_indices(tmp)),a) -  { -  if(-1 == search(a,"/")) continue; -  -  ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n"; -  m_delete(tmp,a); -  } -  -  ret+="</ul>\n"; -  -  ret+="<H1>Other pages</H1>\n<ul>\n"; -  foreach(sort_array(m_indices(tmp)),a) -  { -  ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n"; -  } -  -  ret+="</ul>\n"; -  return mkdocument(ret,"uLPC documentation index"); - } -  +    int main(int argc, string *argv)   {    string np;       megamagic::create("^(.*)&lt;([a-z_0-9]+)&gt;(.*)$");    lastident::create("^(.*[^<>a-z_0-9])([a-z_0-9]+)([^<>a-z_0-9]*)$");      #define BEGIN1 "[0-9]+(\\.[0-9]+)*(\\.|) "   #define BEGIN2 "\t"   #define BEGIN3 " "   #define LEND "[^\n]*"   #define LINE "(" BEGIN1 LEND ")|(" BEGIN2 LEND ")|(" BEGIN3 LEND ")|()\n"       is_example::create("^(" LINE ")+$");       write("Scanning links.\n");    new_path=combine_path(getcwd(),argv[2]);    cd(argv[1]);    traversedir(".",scanlinks); -  write("Processing pages.\n"); +  +  write("Scanning pages.\n"); +  writepages=0;    traversedir(".",scanfiles);    -  write("Making index.\n"); -  np=combine_path(new_path,"index.html"); -  if(file_size(np)>=0) -  rm(np); -  write_file(np,mkindex()); +  write("Writing html.\n"); +  writepages=0; +  traversedir(".",scanfiles); +  +  foreach(indices(keywords) - indices(indexes_done),np) +  { +  perror("Keywords never indexed: "+np+"\n");    } -  + }