summaryrefslogtreecommitdiff
path: root/acme/wiki/src/main.c
blob: f76cafff92ab256bb8360cb7969227fbddab2901 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include "awiki.h"

int debug;
int mapfd;
char *email;
char *dir;

void
usage(void)
{
	fprint(2, "usage: Wiki [-e email] [dir]\n");
	exits("usage");
}

void
threadmain(int argc, char **argv)
{
	char *s;
	Dir *d;

	rfork(RFNAMEG);
	ARGBEGIN{
	case 'D':
		debug++;
		break;
	case 'e':
		email = EARGF(usage());
		break;
	default:
		usage();
		break;
	}ARGEND

	if(argc > 1)
		usage();
	if(argc == 1)
		dir = argv[0];
	else
		dir = "/mnt/wiki";

	if(chdir(dir) < 0){
		fprint(2, "chdir(%s) fails: %r\n", dir);
		threadexitsall(nil);
	}

	if((mapfd = open("map", ORDWR)) < 0){
		fprint(2, "open(map): %r\n");
		threadexitsall(nil);
	}

	if((d = dirstat("1")) == nil){
		fprint(2, "dirstat(%s/1) fails: %r\n", dir);
		threadexitsall(nil);
	}
	s = emalloc(strlen(d->name)+2);
	strcpy(s, d->name);
	strcat(s, "/");
	wikiopen(s, nil);
	threadexits(nil);
}