wiki2text.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <bio.h>
  12. #include <String.h>
  13. #include <thread.h>
  14. #include "wiki.h"
  15. char *wikidir = ".";
  16. void
  17. usage(void)
  18. {
  19. fprint(2, "usage: wiki2text [-d dir] wikifile\n");
  20. exits("usage");
  21. }
  22. void
  23. main(int argc, char **argv)
  24. {
  25. int i;
  26. Biobuf *b;
  27. String *h;
  28. Whist *doc;
  29. ARGBEGIN{
  30. default:
  31. usage();
  32. case 'd':
  33. wikidir = EARGF(usage());
  34. break;
  35. }ARGEND
  36. if(argc != 1)
  37. usage();
  38. if((b = Bopen(argv[0], OREAD)) == nil)
  39. sysfatal("Bopen: %r");
  40. if((doc = Brdwhist(b)) == nil)
  41. sysfatal("Brdwtxt: %r");
  42. h = nil;
  43. for(i=0; i<doc->ndoc; i++){
  44. print("__________________ %d ______________\n", i);
  45. if((h = pagetext(s_reset(h), doc->doc[i].wtxt, 1)) == nil)
  46. sysfatal("wiki2html: %r");
  47. write(1, s_to_c(h), s_len(h));
  48. }
  49. exits(0);
  50. }