#!/usr/bin/python

# Copyright is GPL.

# Unfortunately texinfo 4.0f that are in Debian woody are buggy,
# so we have to fix things.

import sys
fn = sys.argv[1]

f = open(fn, 'r')
s = f.readline()
b = ""
while s != "":
    # I know my bad documentation files!
    s = s[:-1]
    for x in range(2, 6):
        if s.startswith('<h%i>' % x) and s.endswith('</h%i>' % (x-1)):
            s = s[:-5] + '</h%i>' % x
    b += s + "\n"
    s = f.readline()
f.close()
f = open(fn, 'w')
f.write(b)
f.close()
