main.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 "awiki.h"
  10. int debug;
  11. int mapfd;
  12. char *email;
  13. char *dir;
  14. void
  15. usage(void)
  16. {
  17. fprint(2, "usage: Wiki [-e email] [dir]\n");
  18. exits("usage");
  19. }
  20. void
  21. threadmain(int argc, char **argv)
  22. {
  23. char *s;
  24. Dir *d;
  25. rfork(RFNAMEG);
  26. ARGBEGIN{
  27. case 'D':
  28. debug++;
  29. break;
  30. case 'e':
  31. email = EARGF(usage());
  32. break;
  33. default:
  34. usage();
  35. break;
  36. }ARGEND
  37. if(argc > 1)
  38. usage();
  39. if(argc == 1)
  40. dir = argv[0];
  41. else
  42. dir = "/mnt/wiki";
  43. if(chdir(dir) < 0){
  44. fprint(2, "chdir(%s) fails: %r\n", dir);
  45. threadexitsall(nil);
  46. }
  47. if((mapfd = open("map", ORDWR)) < 0){
  48. fprint(2, "open(map): %r\n");
  49. threadexitsall(nil);
  50. }
  51. if((d = dirstat("1")) == nil){
  52. fprint(2, "dirstat(%s/1) fails: %r\n", dir);
  53. threadexitsall(nil);
  54. }
  55. s = emalloc(strlen(d->name)+2);
  56. strcpy(s, d->name);
  57. strcat(s, "/");
  58. wikiopen(s, nil);
  59. threadexits(nil);
  60. }