92a42c1996-02-26Fredrik Hübinette (Hubbe) #!/usr/local/bin/ulpc // 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;
06a71c1996-03-29Fredrik Hübinette (Hubbe) int writepages;
549f8b1996-05-02Fredrik Hübinette (Hubbe) string docdir;
06a71c1996-03-29Fredrik Hübinette (Hubbe) 
92a42c1996-02-26Fredrik Hübinette (Hubbe)  /* * 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]; default: return foo[0..sizeof(foo)-2]*", "+" and "+foo[-1]; } } /* * Make a 'header' */ string smallcaps(string foo) { string *ret; ret=({"<b>"}); foreach(explode(foo," "),foo) { ret+=({"<font size=+1>"+foo[0..0]+"</font><font size=-1>"+foo[1..0x7fffffff]+"</font>"}); } return implode(ret," ")+"</b>"; } /* * convert original path to internal format */ string fippel_path(string path) { sscanf(path,"./%s",path);
99b6701996-03-24Fredrik Hübinette (Hubbe)  path=replace(path,"/","_");
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  if(path[strlen(path)-5..]==".bmml") path=path[..strlen(path)-6];
99b6701996-03-24Fredrik Hübinette (Hubbe)  if(path[strlen(path)-5..]!=".html") path+=".html";
549f8b1996-05-02Fredrik Hübinette (Hubbe)  return docdir+path;
92a42c1996-02-26Fredrik Hübinette (Hubbe) }
99b6701996-03-24Fredrik Hübinette (Hubbe) /* * Three step conversion process... */
92a42c1996-02-26Fredrik Hübinette (Hubbe) 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")+({}); for(e=0;e<sizeof(tmp);e++) { tmp[e]=explode(tmp[e],"\t"); if(sscanf(tmp[e][0],"%*[ ]%s",tmp2) && tmp2=="") { int q; for(q=e-1;q>0;q--) { if(!tmp[q]) continue; if(sizeof(tmp[q])>=sizeof(tmp[e])) { for(d=1;d<sizeof(tmp[e]);d++) { tmp[q][d]+=" "+tmp[e][d]; } tmp[e]=0; } break; } } } tmp-=({0}); for(e=0;e<sizeof(tmp);e++) { tmp[e]=implode(tmp[e]," </td><td> "); } return "<table border=0 cellpadding=0 cellspacing=0>\n<tr valign=top><td>"+ implode(tmp,"<br></td></tr>\n<tr valign=top><td>")+ "<br></td></tr>\n</table>\n"; } } string more_magic(string s, int quote) { int e; string *tmp; int *ilevel=({0}); string output=""; string accumulator=""; if(!quote && -1==search("\n"+s,"\n ") && -1==search(s,"\t")) { return s; } #define FLUSH() output+=even_more_magic(accumulator,ilevel[-1]); accumulator="" #define POP() output+="</dl>"; ilevel=ilevel[0..sizeof(ilevel)-2] tmp=explode(s,"\n"); for(e=0;e<sizeof(tmp);e++) { string spaces, rest; sscanf(tmp[e],"%[ ]%s",spaces,rest); if(strlen(spaces) > ilevel[-1]) { FLUSH(); output+="<dl><dt><dd>"; ilevel+=({ strlen(spaces) }); } else if(strlen(spaces) < ilevel[-1]) { FLUSH(); while(strlen(spaces) < ilevel[-1] && strlen(spaces) <= ilevel[-2]) { POP(); } } accumulator+=rest+"\n"; } FLUSH(); while(sizeof(ilevel)>1) { POP(); } return output; } string magic(string s, int quote) { string *ret; ret=({}); 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>"); }
99b6701996-03-24Fredrik Hübinette (Hubbe)  /* * Magic to convert SYNTAX sections */
92a42c1996-02-26Fredrik Hübinette (Hubbe) inherit "/precompiled/regexp" : lastident; inherit "/precompiled/regexp" : megamagic; string syntax_magic(string s) { string *tmp; int e; while(tmp=megamagic::split(s)) { s=tmp[0]+"<I>"+tmp[1]+"</I>"+tmp[2]; } tmp=explode(s,"\n"); for(e=0;e<sizeof(tmp);e++) { string a,b; if(sscanf(tmp[e],"%s(%s",a,b) && strlen(b)>1 && b[-1]==';' && b[-2]==')') { string *tmp2; int d; tmp2=explode(b[0..strlen(b)-3],","); for(d=0;d<sizeof(tmp2);d++) { string *tmp3; // perror("<"+tmp2[d]+">"); if(tmp3=lastident::split(tmp2[d])) { 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>"; }
99b6701996-03-24Fredrik Hübinette (Hubbe)  /* HTML quoting / unquoting */
92a42c1996-02-26Fredrik Hübinette (Hubbe) string html_quote(string s) {
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  return replace(s,({"uLPC","&","<",">"}),({"µLPC","&amp;","&lt;","&gt;"}));
92a42c1996-02-26Fredrik Hübinette (Hubbe) } string html_unquote(string s) { return replace(s,({"&amp;","&lt;","&gt;"}),({"&","<",">"})); }
57145a1996-03-22Fredrik Hübinette (Hubbe) string mkdocument(string s,string title) { return ("<html>"+ "<title>"+ html_quote(title)+ "</title>"+ "<body bgcolor=\"#A0E0C0\">"+ s+ "</body>"+ "</html>"); }
8e20461996-03-28Fredrik Hübinette (Hubbe) string short(string s) { return short_descs[s] ? " - "+short_descs[s] : ""; }
99b6701996-03-24Fredrik Hübinette (Hubbe) inherit "/precompiled/regexp":is_example;
f5c90a1996-03-24Fredrik Hübinette (Hubbe) list(string) indexes_done=(<>);
9d66451996-03-31Fredrik Hübinette (Hubbe) list(string) pages_done=(<>);
3d669e1996-06-22Fredrik Hübinette (Hubbe) void done(string a) { pages_done[a]=1; }
06a71c1996-03-29Fredrik Hübinette (Hubbe) string mkindex(string topic, int usehead)
f5c90a1996-03-24Fredrik Hübinette (Hubbe) { string head; string a,ret; ret=""; indexes_done[topic]=1; switch(topic) {
06a71c1996-03-29Fredrik Hübinette (Hubbe)  case "pages": head="<b>All pages:</b>\n"; ret="<ul>\n"; foreach(sort_array(m_indices(pages)),a)
9d66451996-03-31Fredrik Hübinette (Hubbe)  { ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n"; }
06a71c1996-03-29Fredrik Hübinette (Hubbe)  ret+="</ul>\n"; break;
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  case "programs": head="<b>Builtin programs:</b>\n"; ret="<ul>\n"; foreach(sort_array(m_indices(pages)),a) {
06a71c1996-03-29Fredrik Hübinette (Hubbe)  if(a[0]!='/') continue;
3d669e1996-06-22Fredrik Hübinette (Hubbe)  done(a);
06a71c1996-03-29Fredrik Hübinette (Hubbe)  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;
3d669e1996-06-22Fredrik Hübinette (Hubbe)  done(a);
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  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";
3d669e1996-06-22Fredrik Hübinette (Hubbe) // perror(sprintf("all pages: %O\n",sort(m_indices(pages)))); // perror(sprintf("pages done: %O\n",sort(m_indices(pages_done))));
9d66451996-03-31Fredrik Hübinette (Hubbe)  foreach(sort_array(m_indices(pages) - indices(pages_done) ),a)
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  {
06a71c1996-03-29Fredrik Hübinette (Hubbe)  if(a[0..4]=="index") continue;
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  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);
3d669e1996-06-22Fredrik Hübinette (Hubbe)  done(a);
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  if(pages[a]) { ret+="<li><a href="+pages[a]+">"+a+"</a>"+short(a)+"\n"; }else{
06a71c1996-03-29Fredrik Hübinette (Hubbe)  if(writepages) perror("Warning: no page for function: "+a+".\n");
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  } } ret+="</ul>\n"; break; default: if(!keywords[topic]) {
3d669e1996-06-22Fredrik Hübinette (Hubbe)  if(writepages) perror("Unknown keyword "+topic+".\n");
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  return ""; } head="<a name="+topic+">";
8e20461996-03-28Fredrik Hübinette (Hubbe)  head+="<b>"+capitalize(topic)+"</a>"; head+=short(topic);
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  head+="</b>\n"; ret="<ul>\n";
06a71c1996-03-29Fredrik Hübinette (Hubbe)  foreach(sort_array(keywords[topic]),a)
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  { a=html_quote(a);
3d669e1996-06-22Fredrik Hübinette (Hubbe)  done(a);
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  ret+="<li><a href="+pages[a]+">"+a+"</a>"+ short(a) +"\n"; } ret+="</ul></a>\n"; break; }
06a71c1996-03-29Fredrik Hübinette (Hubbe)  if(usehead) ret=head+ret;
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  return ret; }
99b6701996-03-24Fredrik Hübinette (Hubbe) /* Convert a page */
92a42c1996-02-26Fredrik Hübinette (Hubbe) string convert_page(string path, string fname) { string output, short; int headno; string cont, section, name, part; output=""; cont=read_bytes(path);
8e20461996-03-28Fredrik Hübinette (Hubbe) // perror("foo: "+path[strlen(path)-5..]+".\n");
92a42c1996-02-26Fredrik Hübinette (Hubbe)  if(sscanf(cont,"NAME\n\t%s - %s\n",name,short)) { int partno;
99b6701996-03-24Fredrik Hübinette (Hubbe)  cont=html_quote(cont);
8e20461996-03-28Fredrik Hübinette (Hubbe)  path=fippel_path(path);
99b6701996-03-24Fredrik Hübinette (Hubbe)  short_descs[html_quote(name)]=short;
8e20461996-03-28Fredrik Hübinette (Hubbe)  pages[html_quote(name)]=path;
92a42c1996-02-26Fredrik Hübinette (Hubbe)  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]; if(!strlen(part)) continue; sections=explode(part,"\n\n");
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  /* Merge sections that does not have a header together */
92a42c1996-02-26Fredrik Hübinette (Hubbe)  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--; } } for(headno=0;headno<sizeof(sections);headno++) { string type, rest; mixed a, b; sscanf(sections[headno],"%s\n%s",type,rest); switch(type) { case "NAME": if(sscanf(rest,"\t%s - %s",part_name,b)!=2) perror("Warning NAME section broken!\n"); rest="\t<tt>"+part_name+"</tt> - "+b;
8e20461996-03-28Fredrik Hübinette (Hubbe)  if(partno) { subpages[fname+"-&gt;"+part_name]=path+"#"+part_name; }
f16bd31996-05-01Fredrik Hübinette (Hubbe)  case "RETURN VALUE": case "RETURN VALUES":
92a42c1996-02-26Fredrik Hübinette (Hubbe)  case "DESCRIPTION": case "NOTA BENE": case "BUGS": rest=magic(rest,0); break; default: perror("Warning: Unknown header: "+type+".\n"); rest=magic(rest,0); break; case "KEYWORDS": a=replace(rest,({"\n"," ","\t"}),({"","",""}))/","; b=({}); foreach(a,a) {
06a71c1996-03-29Fredrik Hübinette (Hubbe)  keywords[a] = ( keywords[a] || ({}) ) | ({ name });
18da781996-04-02Fredrik Hübinette (Hubbe)  if(pages[a]) { b+=({ "<a href="+pages[a]+">"+a+"</a>" }); }else{ b+=({ a }); }
92a42c1996-02-26Fredrik Hübinette (Hubbe)  } rest=implode_nicely(b); break; case "SEE ALSO": rest=replace(rest,({"\n"," ","\t"}),({"","",""})); a=rest/","; b=({}); foreach(a,a) { string tmp; tmp=a;
9d66451996-03-31Fredrik Hübinette (Hubbe)  if(a[0]!='`' && a[0]!='/') a=explode(a,"/")[-1];
92a42c1996-02-26Fredrik Hübinette (Hubbe)  if(pages[a]) { b+=({ "<a href="+pages[a]+">" + a + "</a>" }); }else if(subpages[a]){ b+=({ "<a href="+subpages[a]+">" + a + "</a>" }); }else if(subpages[fname+"-&gt;"+a]){ b+=({ "<a href="+subpages[name+"-&gt;"+a]+">" + a + "</a>" }); }else{
8e20461996-03-28Fredrik Hübinette (Hubbe)  if(writepages)
9d66451996-03-31Fredrik Hübinette (Hubbe)  perror(path+": Warning, unlinked SEE ALSO: "+a+"\n");
92a42c1996-02-26Fredrik Hübinette (Hubbe)  b+=({ tmp }); } } rest=implode_nicely(b); break; 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>";
8e20461996-03-28Fredrik Hübinette (Hubbe)  break;
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  case "RELATED FUNCTIONS": a=name;
9d66451996-03-31Fredrik Hübinette (Hubbe) 
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  sscanf(rest,"%*skeyword %[a-z/A-Z0-9]",a); rest=mkindex(a, 0);
92a42c1996-02-26Fredrik Hübinette (Hubbe)  } sections[headno]="<dt>"+ smallcaps(type)+ "<dd>\n"+rest+"\n<p>"; }
06a71c1996-03-29Fredrik Hübinette (Hubbe)  if(keywords[part_name]) { sections+=({"<dt>"+ smallcaps("RELATED PAGES")+"\n"+ mkindex(part_name,0)+"<p>"}); }
92a42c1996-02-26Fredrik Hübinette (Hubbe)  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"; } }
57145a1996-03-22Fredrik Hübinette (Hubbe)  output=mkdocument(implode(parts,"<hr noshade size=1>\n"),"uLPC: "+name);
92a42c1996-02-26Fredrik Hübinette (Hubbe)  }
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  else if(path[strlen(path)-5..]==".bmml") { string *sections; string title; int section;
8e20461996-03-28Fredrik Hübinette (Hubbe)  pages[(path[..strlen(path)-6]/"/")[-1]]=fippel_path(path);
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  cont=replace(cont,"$version",version()); cont=html_quote(cont); sections=explode(cont,"\n\n"); for(section=0;section<sizeof(sections);section++) {
06a71c1996-03-29Fredrik Hübinette (Hubbe)  string tmp,pre,a,b;
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  tmp=sections[section];
8e20461996-03-28Fredrik Hübinette (Hubbe)  sscanf(tmp,"%[\t ]",pre);
f5c90a1996-03-24Fredrik Hübinette (Hubbe) 
8e20461996-03-28Fredrik Hübinette (Hubbe)  switch(pre)
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  { case "": title=tmp;
06a71c1996-03-29Fredrik Hübinette (Hubbe)  tmp="<h1><center>"+tmp+"</center></h1>";
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  break; case " ": sscanf(tmp," %s",tmp); tmp="<h2>"+tmp+"</h2>"; break; case " ": sscanf(tmp," %s",tmp); tmp=replace(tmp,"\n ","\n");
8e20461996-03-28Fredrik Hübinette (Hubbe)  tmp=more_magic(tmp,0);
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  break; case "\t": sscanf(tmp,"\t%s %s",pre, a); switch(pre) { case "KEYWORD_INDEX":
8e20461996-03-28Fredrik Hübinette (Hubbe)  sscanf(a,"%s\n",a);
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  tmp=mkindex(a, 1);
8e20461996-03-28Fredrik Hübinette (Hubbe)  break;
f5c90a1996-03-24Fredrik Hübinette (Hubbe) 
06a71c1996-03-29Fredrik Hübinette (Hubbe)  case "KEYWORD_LIST": sscanf(a,"%s\n",a); tmp=mkindex(a, 0); break; case "LINK": sscanf(a,"%s %s",a,b);
3d669e1996-06-22Fredrik Hübinette (Hubbe)  done((a/"/")[-1]);
18da781996-04-02Fredrik Hübinette (Hubbe)  tmp="<a href="+fippel_path(a)+">"+b+"</a>"; break; case "TAG": pages[a]=fippel_path(path)+"#"+a;
3d669e1996-06-22Fredrik Hübinette (Hubbe)  done(a);
18da781996-04-02Fredrik Hübinette (Hubbe)  tmp="<a name="+a+">";
06a71c1996-03-29Fredrik Hübinette (Hubbe)  break;
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  default: perror("Unknown directive: "+pre+".\n"); } }
06a71c1996-03-29Fredrik Hübinette (Hubbe)  sections[section]=tmp;
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  } cont=implode(sections,"\n<p>\n"); return mkdocument(cont, title || "uLPC manual"); }
99b6701996-03-24Fredrik Hübinette (Hubbe)  else if(path[strlen(path)-5..]==".html") {
8e20461996-03-28Fredrik Hübinette (Hubbe)  pages[(path[..strlen(path)-6]/"/")[-1]]=fippel_path(path);
99b6701996-03-24Fredrik Hübinette (Hubbe)  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;
8e20461996-03-28Fredrik Hübinette (Hubbe)  pages[(path/"/")[-1]]=fippel_path(path);
99b6701996-03-24Fredrik Hübinette (Hubbe)  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],"_"," ")); }
8e20461996-03-28Fredrik Hübinette (Hubbe)  else
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  {
8e20461996-03-28Fredrik Hübinette (Hubbe)  if(writepages) { string tmp; int l, i; foreach(cont/"\n", tmp) { if(is_example::match(tmp+"\n")) { l++; }else{ i++; } } if(l > i*2) {
9d66451996-03-31Fredrik Hübinette (Hubbe)  int err;
8e20461996-03-28Fredrik Hübinette (Hubbe)  l=0; foreach(cont/"\n", tmp) { l++; if(!is_example::match(tmp+"\n")) { perror(path+":"+l+": not on example form.\n");
9d66451996-03-31Fredrik Hübinette (Hubbe)  if(++err == 5) break;
8e20461996-03-28Fredrik Hübinette (Hubbe)  } } } perror("Warning: not converting "+path+".\n"); } output="";
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  }
8e20461996-03-28Fredrik Hübinette (Hubbe)  return output;
f5c90a1996-03-24Fredrik Hübinette (Hubbe) }
92a42c1996-02-26Fredrik Hübinette (Hubbe) void scanfiles(string path, string fname) { string nf,np;
8e20461996-03-28Fredrik Hübinette (Hubbe)  nf=convert_page(path, fname);
92a42c1996-02-26Fredrik Hübinette (Hubbe) 
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  if(nf && strlen(nf) && writepages)
92a42c1996-02-26Fredrik Hübinette (Hubbe)  { np=combine_path(new_path,fippel_path(path));
99b6701996-03-24Fredrik Hübinette (Hubbe) // write("Writing "+np+".\n");
92a42c1996-02-26Fredrik Hübinette (Hubbe)  if(file_size(np)>=0) rm (np); write_file(np,nf); } }
99b6701996-03-24Fredrik Hübinette (Hubbe) /** Traverse directory **/
549f8b1996-05-02Fredrik Hübinette (Hubbe) void traversedir(string path)
92a42c1996-02-26Fredrik Hübinette (Hubbe) { string file;
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  foreach(get_dir(path) - ({"CVS","RCS",".cvsignore"}),file)
92a42c1996-02-26Fredrik Hübinette (Hubbe)  { 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) {
ca24371996-05-16Fredrik Hübinette (Hubbe)  traversedir(tmp);
92a42c1996-02-26Fredrik Hübinette (Hubbe)  }else{
549f8b1996-05-02Fredrik Hübinette (Hubbe)  scanfiles(tmp,file);
92a42c1996-02-26Fredrik Hübinette (Hubbe)  } } }
549f8b1996-05-02Fredrik Hübinette (Hubbe) void dodocs(string path, int module) { cd(path);
ca24371996-05-16Fredrik Hübinette (Hubbe)  perror("Doing "+path+"\n");
549f8b1996-05-02Fredrik Hübinette (Hubbe)  if(!module) { docdir=""; }else{ docdir="module"+module; if(sscanf(reverse(path),"cod/%s",docdir)) { sscanf(docdir,"%s/",docdir); docdir=reverse(docdir); } docdir+="_"; } traversedir("."); }
92a42c1996-02-26Fredrik Hübinette (Hubbe) int main(int argc, string *argv) { string np;
549f8b1996-05-02Fredrik Hübinette (Hubbe)  int e; if(argc < 3) { perror("Usage: html_docs.lpc to_path from_path [module_doc_path ...]\n"); exit(0); }
92a42c1996-02-26Fredrik Hübinette (Hubbe) 
ca24371996-05-16Fredrik Hübinette (Hubbe) // perror(sprintf("argv = %O\n",argv));
99b6701996-03-24Fredrik Hübinette (Hubbe)  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 ")+$");
92a42c1996-02-26Fredrik Hübinette (Hubbe) 
549f8b1996-05-02Fredrik Hübinette (Hubbe)  for(e=1;e<sizeof(argv);e++) argv[e]=combine_path(getcwd(),argv[e]);
f5c90a1996-03-24Fredrik Hübinette (Hubbe) 
ca24371996-05-16Fredrik Hübinette (Hubbe)  new_path=argv[1];
8e20461996-03-28Fredrik Hübinette (Hubbe)  write("Scanning pages for links and keywords.\n");
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  writepages=0;
549f8b1996-05-02Fredrik Hübinette (Hubbe)  for(e=2;e<sizeof(argv);e++) dodocs(argv[e],e-2);
f5c90a1996-03-24Fredrik Hübinette (Hubbe) 
8e20461996-03-28Fredrik Hübinette (Hubbe)  write("Writing html files.\n");
06a71c1996-03-29Fredrik Hübinette (Hubbe)  writepages=1;
549f8b1996-05-02Fredrik Hübinette (Hubbe)  for(e=2;e<sizeof(argv);e++) dodocs(argv[e],e-2);
f5c90a1996-03-24Fredrik Hübinette (Hubbe)  foreach(indices(keywords) - indices(indexes_done),np) { perror("Keywords never indexed: "+np+"\n"); }
92a42c1996-02-26Fredrik Hübinette (Hubbe) }