1 #include <u.h> 2 #include <libc.h> 3 #include <bio.h> 4 #include <String.h> 5 #include <thread.h> 6 #include "wiki.h" 7 8 char *wikidir; 9 10 void usage(void)11usage(void) 12 { 13 fprint(2, "usage: wiki2html [-hoDP ] [-d dir] wikifile\n"); 14 exits("usage"); 15 } 16 17 void main(int argc,char ** argv)18main(int argc, char **argv) 19 { 20 int t; 21 int parse; 22 String *h; 23 Whist *doc; 24 25 rfork(RFNAMEG); 26 27 t = Tpage; 28 ARGBEGIN{ 29 default: 30 usage(); 31 case 'd': 32 wikidir = EARGF(usage()); 33 break; 34 case 'h': 35 t = Thistory; 36 break; 37 case 'o': 38 t = Toldpage; 39 break; 40 case 'D': 41 t = Tdiff; 42 break; 43 case 'P': 44 parse = 1; 45 }ARGEND 46 47 if(argc != 1) 48 usage(); 49 50 if(t == Thistory || t==Tdiff) 51 doc = gethistory(atoi(argv[0])); 52 else 53 doc = getcurrent(atoi(argv[0])); 54 55 if(doc == nil) 56 sysfatal("doc: %r"); 57 58 if(parse){ 59 printpage(doc->doc->wtxt); 60 exits(0); 61 } 62 if((h = tohtml(doc, doc->doc+doc->ndoc-1, t)) == nil) 63 sysfatal("wiki2html: %r"); 64 65 write(1, s_to_c(h), s_len(h)); 66 exits(0); 67 } 68