#!/usr/bin/awk -f

BEGIN {
	FS=" "
	LF=1
}

function paragraph() {
	printf("<p>\n")
	while (1) {
		getline
		if (($0 == "EOF") || ($0 == "macr PP")) {break}
		if ($1 == "text") {
			if (LF == 1) {printf "<br>"}
			LF = 1
			# $1 = ""
			# print
			for (x=2; x <= NF; x++) {
				printf("%s", $x)
				if (x != NF) {printf " "}
			}
		}
		# italics
		else if ($1 == "sita") {
			printf(" <i>")
			LF = 0
		}
		else if ($1 == "eita") {
			printf("</i>")
			LF = 0
		}
		# bold
		else if ($1 == "sbld") {
			printf(" <b>")
			LF = 0
		}
		else if ($1 == "ebld") {
			printf("</b>")
			LF = 0
		}
		# underline
		else if ($1 == "sund") {
			printf(" <u>")
			LF = 0
		}
		else if ($1 == "eund") {
			printf("</u>")
			LF = 0
		}
		# striken
		else if ($1 == "sstk") {
			printf(" <del>")
			LF = 0
		}
		else if ($1 == "estk") {
			printf("</del>")
			LF = 0
		}
		# unordered list
		else if ($0 == "macr UL") {
			printf(" <ul>")
			while (1) {
				getline
				if (($0 == "EOF") || ($0 == "macr PP")) {break}
				if ($0 != "macr UL") {
					$1=""
					printf("<li>%s</li>", $0)
				}
			}
			printf("</ul>")
		}
		# ordered list
		else if ($0 == "macr OL") {
			printf(" <ol>")
			while (1) {
				getline
				if (($0 == "EOF") || ($0 == "macr PP")) {break}
				if ($0 != "macr OL") {
					$1=""
					printf("<li>%s</li>", $0)
				}
			}
			printf("</OL>")
		}
	}
	printf("</p>\n")
   	return
}

/^macr TL$/{
	getline
	$1 = ""
	printf("<title>%s</title>\n", $0)
	printf("<h1>%s</h1>\n", $0)
}

/^macr AU$/{
	getline
	$1 = ""
	printf("<p>By%s</p>\n", $0)
}

/^macr PP$/{
	paragraph()
	if ($0 == "macr PP") {paragraph()}
}