#!/usr/bin/python
import os,re

os.chdir("csharp_standard")

l=[]
for n in os.listdir('.'):
	if n[0]>='0' and n[0]<='9' and n.endswith('.htm'):
		t=n[:-4].split('.')
		s=[0,0,0,0,n,n[:-4]]
		for i in range(len(t)):
			s[i]=int(t[i])
		l.append(tuple(s))
l.sort()

r= """
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Hyperlinked ECMA C# Language Specification</title>
<meta name="author" content="Jon Jagger" />
<link rel="stylesheet" href="ecma334.css"></link>
</head>
<body>
<span class="heading">ECMA-334 C# Language Specification</span>
<br/>
<span style="font-size:150%;">
Formatted in one big (1.6Mb) html page by Antony Lesuisse.
<br/>
<br/>
</span>
(generated from the <a href="http://www.jaggersoft.com/csharp_standard/">Jon
Jagger</a> splitted version). I took the splitted html catted all the files
together using a small python script csharp_join.py.

"""

t=file('toc.htm').read()
mo=re.search(r'(\<span class="toc-line">.*)<span class=\"ruler\"\>',t,re.DOTALL)
if mo:
	r+='\n\n<a name="toc"/>\n'
	r+='<br/><br/><br/><span class="heading">Table of Contents</span>\n'
	r+=mo.group(1)
else:
	raise ''

for i in l:
	t=file(i[4]).read()
	mo=re.search(r'(\<span class=\"clause-number\"\>.*)<span class=\"ruler\"\>',t,re.DOTALL)
	if mo:
		r+='\n\n<a name="%s"/>\n'%i[5]
		r+='<br/><br/><br/>\n\n<span class="clause-depth">'
		r+=mo.group(1)
	else:
		raise ''


t=file('ErrorsAndTypos.htm').read()
mo=re.search(r'(<span class="heading">.*)$',t,re.DOTALL)
if mo:
	r+=mo.group(1)
else:
	raise ''

p=re.compile(r'<a href="([0-9.]*?).htm[^>]*?>')
r=p.sub(r'<a href="#\1">',r)

file("../csharp_ecma344.html","w").write(r)




