#!/usr/bin/perl

use strict;
use warnings;

my $check = 0;
my $buf   = "";

while ( <> )
{
   if ( $check == 1 )
   {
      if ( /#if defined HAVE_CONFIG_H/ )
      {
         $buf .= "\n";
      }

      $check = 0;
   }

   $buf .= $_;

   if ( /^!! SOURCE/ )
   {
      $check = 1;
   }
}

$_ = $buf;

if ( (m/src2tex/) and (! m/HAVE_CONFIG_H/) )
{
   s/^!! SOURCE/!! SOURCE\n\n#if defined HAVE_CONFIG_H\n#include "config.h"\n#endif/m;
}

print $_;


syntax highlighted by Code2HTML, v. 0.9.1