pike.git / bin / htmlify_docs.lpc

version» Context lines:

pike.git/bin/htmlify_docs.lpc:38:    }    return implode(ret," ")+"</b>";   }      /*    * convert original path to internal format    */   string fippel_path(string path)   {    sscanf(path,"./%s",path); -  return replace(path,"/","_")+".html"; +  path=replace(path,"/","_"); +  if(path[strlen(path)-5..]!=".html") path+=".html"; +  +  return path;   }    -  + /* +  * Three step conversion process... +  */   string even_more_magic(string block, int indent)   {    if(-1==search(block,"\t"))    {    return replace(block,"\n","<br>\n");    }else{    int e,d;    mixed tmp,tmp2;       tmp=explode(block,"\n")+({});
pike.git/bin/htmlify_docs.lpc:150:    foreach(explode(s,"\n\n"),s)    {    sscanf(s,"\t%s",s);    s=replace(s,"\n\t","\n");    ret += ({ more_magic(s, quote) });    }       return implode(ret,"\n<p>");   }    +  + /* +  * Magic to convert SYNTAX sections +  */   inherit "/precompiled/regexp" : lastident;   inherit "/precompiled/regexp" : megamagic;      string syntax_magic(string s)   {    string *tmp;    int e;       while(tmp=megamagic::split(s))    {
pike.git/bin/htmlify_docs.lpc:188:    tmp2[d]=tmp3[0]+"<I>"+tmp3[1]+"</I>"+tmp3[2];    }    }    tmp[e]=a+"("+implode(tmp2,",")+");";    }    }    s=implode(tmp,"\n");    return "<tt>"+magic(s,1)+"</tt>";   }    +  + /* HTML quoting / unquoting */ +    string html_quote(string s)   {    return replace(s,({"&","<",">"}),({"&amp;","&lt;","&gt;"}));   }      string html_unquote(string s)   {    return replace(s,({"&amp;","&lt;","&gt;"}),({"&","<",">"}));   }   
pike.git/bin/htmlify_docs.lpc:210:    return ("<html>"+    "<title>"+    html_quote(title)+    "</title>"+    "<body bgcolor=\"#A0E0C0\">"+    s+    "</body>"+    "</html>");   }    + inherit "/precompiled/regexp":is_example; +  + /* 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);    -  cont=html_quote(cont); -  +     if(sscanf(cont,"NAME\n\t%s - %s\n",name,short))    {    int partno;    -  short_descs[name]=short; +  cont=html_quote(cont); +  short_descs[html_quote(name)]=short;       string *parts=explode(cont,"============================================================================\n");    for(partno=0;partno<sizeof(parts);partno++)    {    string part_name="error";    string *sections;    string part;    int section;       part=parts[partno];
pike.git/bin/htmlify_docs.lpc:339:    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..]==".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; +  int pre,p; +  +  if(sscanf(cont,"%*[0-9.] %s\n",part)==2) +  short_descs[(path/"/")[-1]]=part; +  +  tmp=""; +  pre=2; +  cont=html_quote(cont); +  foreach(cont/"\n"+({"."}),line) +  { +  if(strlen(line)) +  { +  switch(line[0]) +  { +  case ' ': p=0; sscanf(line," %s",line); break; +  case '\t': p=1; sscanf(line,"\t",line); break; +  default: p=2; break; +  } +  +  if(p!=pre) +  { +  switch(pre) +  { +  case 2: output+="<h2>"+tmp+"</h2>"; break; +  case 1: +  if(tmp[-1]=='\n' && tmp[-2]=='\n') +  tmp=tmp[..strlen(tmp)-2]; +  output+="<pre>\n"+tmp+"</pre>\n"; +  break; +  case 0: output+=replace(tmp,"\n\n","\n<p>\n"); break; +  } +  pre=p; +  tmp=""; +  } +  } +  tmp+=line+"\n"; +  } +  output=mkdocument(output,"uLPC: "+ +  replace(explode(fname,"/")[-1],"_"," ")); +  }    return output;   }    -  +    void scanfiles(string path, string fname)   {    string nf,np;    nf=convert_page(path, fname);       if(nf && strlen(nf))    {    np=combine_path(new_path,fippel_path(path)); -  write("Writing "+np+".\n"); + // write("Writing "+np+".\n");    if(file_size(np)>=0)    rm (np);    write_file(np,nf);    }   }    -  + /* +  * Pre-read all files and sort out where to link it to +  */   void scanlinks(string path, string fname)   {    string cont,name;    cont=read_bytes(path);    cont=html_quote(cont);       if(sscanf(cont,"NAME\n\t%s -",name))    {    path=fippel_path(path);    pages[name]=path;
pike.git/bin/htmlify_docs.lpc:378:    int e;    string *parts=explode(cont,"============================================================================\n");    for(e=1;e<sizeof(parts);e++)    {    string part_name;    if(sscanf(parts[e],"NAME\n\t%s -",part_name))    {    subpages[fname+"-&gt;"+part_name]=path+"#"+part_name;    }    } +  } +  else if(path[strlen(path)-5..]==".html") +  { +  pages[(path[..strlen(path)-6]/"/")[-1]]=fippel_path(path); +  } +  else if(is_example::match(cont)) +  { +  pages[(path/"/")[-1]]=fippel_path(path); +  } +  else +  { +  string tmp; +  int l, i; +  +  foreach(cont/"\n", tmp) +  { +  if(is_example::match(tmp+"\n")) +  { +  l++;    }else{ -  +  i++; +  } +  } +  +  if(l > i*2) +  { +  l=0; +  foreach(cont/"\n", tmp) +  { +  l++; +  if(!is_example::match(tmp+"\n")) +  { +  perror(path+":"+l+": not on example form.\n"); +  } +  } +  }    perror("Warning: not converting "+path+".\n");    }   }    -  +  + /** Traverse directory **/   void traversedir(string path,function fun)   {    string file;    foreach(get_dir(path) - ({"CVS","RCS"}),file)    {    string tmp;    if(file[-1]=='~') continue;    if(file[0]=='#' && file[-1]=='#') continue;    if(file[0]=='.' && file[1]=='#') continue;   
pike.git/bin/htmlify_docs.lpc:404:       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); -  if(short_descs[b]) ret+=" - "+short_descs[b]; +  ret+=short(b);    ret+="</h2><dd>\n";    ret+="<ul>\n";    foreach(keywords[b],a)    { -  ret+="<li><a href="+pages[a]+">"+a+"</a> - "+short_descs[a]+"\n"; +  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_descs[a]+"\n"; +  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_descs[a]+"\n"; +  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_descs[a]+"\n"; +  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][a-z_0-9]*)&gt;(.*)$"); -  lastident::create("^(.*[^<>a-z_0-9])([a-z_0-9][a-z_0-9]*)([^<>a-z_0-9]*)$"); +  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");    traversedir(".",scanfiles);       write("Making index.\n");    np=combine_path(new_path,"index.html");    if(file_size(np)>=0)    rm(np);    write_file(np,mkindex());   }