summaryrefslogtreecommitdiff
path: root/sys/src/cmd/wikifs/wiki2text.c
blob: 33b33fc6994ba70cc51a82b14bce244abfee3cfb (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
#include <u.h>
#include <libc.h>
#include <bio.h>
#include <String.h>
#include <thread.h>
#include "wiki.h"

char *wikidir = ".";

void
usage(void)
{
	fprint(2, "usage: wiki2text [-d dir] wikifile\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	int i;
	Biobuf *b;
	String *h;
	Whist *doc;

	ARGBEGIN{
	default:
		usage();
	case 'd':
		wikidir = EARGF(usage());
		break;
	}ARGEND

	if(argc != 1)
		usage();

	if((b = Bopen(argv[0], OREAD)) == nil)
		sysfatal("Bopen: %r");

	if((doc = Brdwhist(b)) == nil)
		sysfatal("Brdwtxt: %r");

	h = nil;
	for(i=0; i<doc->ndoc; i++){
		print("__________________ %d ______________\n", i);
		if((h = pagetext(s_reset(h), doc->doc[i].wtxt, 1)) == nil)
			sysfatal("wiki2html: %r");
		write(1, s_to_c(h), s_len(h));
	}
	exits(0);
}