# -*- python -*-
Import('env')

import re

# The following python subroutine and the subsequent scons command
# shows how to do general template filling. This system should perhaps
# be put in a separate directory, or even be made part of scons.
def patch_src(env, target, source):
    out = open(str(target[0]), "wb")
    inp = open(str(source[0]), "r")

    in_area = 0
    for line in inp.readlines():
        if in_area:
            line = re.sub('G_TYPE_OBJECT',
                          'GTK_TYPE_ADJUSTMENT',
                          line)
            if re.search(r'\);', line):
                in_area=0
        else:
            if re.search(r"object_signals\[SET_SCROLL_ADJUSTMENTS_SIGNAL\]",line):
                in_area=1

        out.write(line)
        
    out.close()
    inp.close()

env.Library("gtkimageviewer_local",
            ["gtk-image-viewer-fixed.c"])

env.Command("gtk-image-viewer-fixed.c",
            ["gtk-image-viewer.c"],
            patch_src)

for gob in ("gtk-image-viewer",
            ) :
    env.Command([gob + ".c",
                 gob + ".h",
                 gob + "-private.h"
                 ],
                [gob + ".gob"],
                ["gob2 -o ${SOURCES.dir} $SOURCES"]
                )

