Plan 9 from Bell Labs’s /usr/web/sources/patch/applied/wikifs-tohtml-improvements/wiki2html.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#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: wiki2html [-hoDP ] [-d dir] wikifile\n");
	exits("usage");
}

void
main(int argc, char **argv)
{
	int t;
	int parse;
	String *h;
	Whist *doc;

	rfork(RFNAMEG);

	t = Tpage;
	ARGBEGIN{
	default:
		usage();
	case 'd':
		wikidir = EARGF(usage());
		break;
	case 'h':
		t = Thistory;
		break;
	case 'o':
		t = Toldpage;
		break;
	case 'D':
		t = Tdiff;
		break;
	case 'P':
		parse = 1;
	}ARGEND

	if(argc != 1)
		usage();

	if(parse) {
		//doc = getcurrentbyname(argv[0]);
		doc = getcurrent(atoi(argv[0]));
		if(doc) {
			printpage(doc->doc->wtxt);
			exits("");
		} else {
			exits("getbyname...");
		}
	}
	if(t == Thistory || t==Tdiff)
		doc = gethistory(atoi(argv[0]));
	else
		doc = getcurrent(atoi(argv[0]));

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

	if((h = tohtml(doc, doc->doc+doc->ndoc-1, t)) == nil)
		sysfatal("wiki2html: %r");

	write(1, s_to_c(h), s_len(h));
	exits(0);
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].