wiki2html.c 916 B

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