#! /usr/bin/perl

use strict;

my ($f, $h, $g, $l);
my @a;

while (<>) {
  if (/\/\*\\[ \t]+[cC][uU][tT][ \t]+([^ \t]+)[ \t]+\\\*\//) {
    $f = $1;
    print "$f";
    open $h, ">$f" || die "can not write file $f";
    while (($l = <>) !~ /\/\*\\[ \t]*[eE][nN][dD][cC][uU][tT][ \t]*\\\*\//) {
      if ($l =~ /\/\*\\[ \t]+[pP][uU][tT][ \t]+(.+)\\\*\//) {
        print $h "$1\n";
	next;
      }
      if ($l =~ /\/\*\\[ \t]+[gG][eE][tT][ \t]+([^ \t]+)[ \t]+\\\*\//) {
        open $g, "<$1" || die "can not read file $1";
	print ":$1";
	@a = <$g>;
	close $g;
	print $h @a;
	next;
      }
      print $h "$l";
    }
    close $f;
    print "\n";
  }
}
exit(0);
