#!/usr/bin/python

import re
import sys

re_img = re.compile("(\<imagedata\s(\w+=\".*?\"\s*)*?)/>")
def img_repl_func(m):
    ret = m.groups()[0].replace(".png", ".ps")
    ret = ret.replace("../png", "../../png")
    return ret + ">"
for fn in sys.argv[1:]:
    f = file(fn, 'r')
    s =f.read()
    f.close()
    m = re_img.search(s)
    if m:
        s = re_img.sub(img_repl_func, s)
    f = file(fn, 'w')
    f.write(s)
    f.close()
