#!/usr/bin/perl -w
# myeperl - Prepocessor for documents, embedded Perl.
# Copyright (C) Don Aug 23 19:01:36 MEST 2001 by Ingo Blechschmidt
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# Ingo Blechschmidt
# Arberstraße 5
# 86179 Augsburg
# E-Mail: iblech@web.de, http://www.way.to/uselinux/
# Tel.: +49 / 821 882955
#
# 

$mchar = '';
$mstarte = 0;
$tchar = '';
$tstring = '';

while(not eof STDIN) {
  $mchar = getc STDIN;
  if ($mstarte == 2) {
    $tchar = '';
    $tstring = '';
    while($tchar ne ']') {
      $tchar = getc STDIN;
      $tstring .= $tchar;
    }
    $tstring = substr($tstring, 0, length($tstring) - 2);
    #####
    # system("perl -e '$tstring' > /tmp/myeperl.tmp");
    # open(EPERL, '</tmp/myeperl.tmp') || die 'Can\' t open /tmp/myeperl.tmp!';
    # print <EPERL>;
    # close(EPERL);
    #####
    { eval("$tstring"); }
    #####
    $mstarte = 0;
    $mchar = ']'
  }
  if ($mchar eq '[' or $mchar eq '+') {
    $mstarte++;
  } elsif ($mchar eq ']') {
    # do nothing
  } else {
    print $mchar;
  }
}
