#!/usr/bin/env python

# Turn slinke.hhc into a web page for the rest of us.
# Run in directory containing slinke.hhc.
# Outputs "index.html" and "slinke.html" in same directory.
# Open "file:index.html" with your browser.

import re, string

fd = open('slinke.hhc')
f = fd.read()
fd.close()

# remove unsightly object tokens
f = re.sub('<OBJECT type="text/sitemap">','',f)
f = re.sub('</OBJECT>','',f)

# convert <param> entries into normal anchors
# assume "Name" and "Local" are always next to each other and in the same order
l = string.split(f, '\n')
for i in range(len(l)):
	t = l[i]

	if re.search('<param name="Local"', t):
		url = string.split(t, '"')[3]
		text = string.split(l[i-1],'"')[3]
		l[i-1] = ''
		l[i] = '<a href="%s" target="viewframe">%s</a>' % (url, text)


# dump remaining <param> entries
for i in range(len(l)):
	if re.search('<param name=', l[i]):
		l[i] = ''

# put lines back into one big string
f = string.join(l, '\n')

fd = open('slinke.html','w')
fd.write(f)
fd.close()

# write index file. uses frames.
fd = open('index.html','w')
fd.write('''
<html>
<title>Slink-e Documentation</title>
<frameset cols="50%,*">
<FRAME src="slinke.html" NAME="indexframe">
<FRAME src="fp/Slinke/setting.htm"  NAME="viewframe">
</frameset>
</html>
''')
fd.close()

