# $Id: makemanual.awk,v 1.1 2009/05/17 18:23:45 nicm Exp $
#
# Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
# OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

BEGIN {
	c1 = 0;
	c2 = 0;
	h1 = 0;
	h2 = 0;
}

/^##[^#]/ {
	c1++;
	c2 = 0;
	print (c1 substr($0, 3));
	next;
}

/^%%[^%]/ {
	c2++;
	print (c1 "." c2 substr($0, 3));
	next;
}

/^\*\*\*/ {
	s = substr($0, 5) " ";
	while (length(s) < 80) {
		s = s "=";
	}

	print (s);
	next;
}

/^###/ {
	h1++;
	h2 = 0;

	s = h1 substr($0, 4) " ";
	while (length(s) < 80) {
		s = s "=";
	}

	print (s);
	next;
}

/^%%%/ {
	h2++;

	s = h1 "." h2 substr($0, 4) " ";
	while (length(s) < 80) {
		s = s "-";
	}

	print (s);
	next;
}

/^.*$/ {
	print ($0);
}
