- # Do we have to run LaTeX two times? This is needed if
- # the template contains page references.
- $two_passes = 0;
-
- # first we generate a tmpfile
- # read file and replace ${pre}variable${suf}
- while ($_ = shift) {
-
- $par = "";
- $var = $_;
-
- # Switch ${pre}analyse${suf} for template checking
- # If ${pre}analyse${suf} is set in the template, you'll find the
- # parsed output in the user Directory for analysing
- # Latex errors
- # ${pre}analyse${suf} is a switch (allways off, on if set), not a Variable
- # Set $form->{analysing}="" for system state: never analyse.
- # Set $form->{analysing}="1" for system state: ever analyse.
- $self->{analysing} = "1" if (/${pre}analyse${suf}/ && !defined $self->{analysing});
-
- $two_passes = 1 if (/\\pageref/);
-
- # { Moritz Bunkus
- # detect pagebreak block and its parameters
- if (/\s*${pre}pagebreak ([0-9]+) ([0-9]+) ([0-9]+)${suf}/) {
- $chars_per_line = $1;
- $lines_on_first_page = $2;
- $lines_on_second_page = $3;
-
- while ($_ = shift) {
- last if (/\s*${pre}end pagebreak${suf}/);
- $pagebreak .= $_;
- }
- }
-
- # } Moritz Bunkus
-
- if (/\s*${pre}foreach /) {
-
- # this one we need for the count
- chomp $var;
- $var =~ s/\s*${pre}foreach (.+?)${suf}/$1/;
- while ($_ = shift) {
- last if (/\s*${pre}end /);
-
- # store line in $par
- $par .= $_;
- }
-
- # display contents of $self->{number}[] array
- for $i (0 .. $#{ $self->{$var} }) {
-
- # { Moritz Bunkus
- # Try to detect whether a manual page break is necessary
- # but only if there was a ${pre}pagebreak ...${suf} block before
-
- if ($chars_per_line) {
- my $lines =
- int(length($self->{"description"}[$i]) / $chars_per_line + 0.95);
- my $lpp;
-
- my $_description = $self->{"description"}[$i];
- while ($_description =~ /\\newline/) {
- $lines++;
- $_description =~ s/\\newline//;
- }
- $self->{"description"}[$i] =~ s/(\\newline\s?)*$//;
-
- if ($current_page == 1) {
- $lpp = $lines_on_first_page;
- } else {
- $lpp = $lines_on_second_page;
- }
-
- # Yes we need a manual page break -- or the user has forced one
- if (
- (($current_line + $lines) > $lpp)
- || ($self->{"_forced_pagebreaks"}
- && grep(/^${current_row}$/, @{ $self->{"_forced_pagebreaks"} }))
- ) {
- my $pb = $pagebreak;
-
- # replace the special variables ${pre}sumcarriedforward${suf}
- # and ${pre}lastpage${suf}
-
- my $psum = $self->format_amount($myconfig, $sum, 2);
- $pb =~ s/${pre}sumcarriedforward${suf}/$psum/g;
- $pb =~ s/${pre}lastpage${suf}/$current_page/g;
-
- # only "normal" variables are supported here
- # (no ${pre}if, no ${pre}foreach, no ${pre}include)
-
- $pb =~ s/${pre}(.+?)${suf}/$self->{$1}/g;
-
- # page break block is ready to rock
- print(OUT $pb);
- $current_page++;
- $current_line = 1;
- }
- $current_line += $lines;
- $current_row++;
- }
- $sum += $self->parse_amount($myconfig, $self->{"linetotal"}[$i]);
-
- # } Moritz Bunkus
-
- # don't parse par, we need it for each line
- $_ = $par;
- s/${pre}(.+?)${suf}/$self->{$1}[$i]/mg;
- print OUT;
- }
- next;
- }
-
- # if not comes before if!
- if (/\s*${pre}if not /) {
-
- # check if it is not set and display
- chop;
- s/\s*${pre}if not (.+?)${suf}/$1/;
-
- unless ($self->{$_}) {
- while ($_ = shift) {
- last if (/\s*${pre}end /);
-
- # store line in $par
- $par .= $_;
- }
-
- $_ = $par;
-
- } else {
- while ($_ = shift) {
- last if (/\s*${pre}end /);
- }
- next;
- }
- }
-
- if (/\s*${pre}if /) {
-
- # check if it is set and display
- chop;
- s/\s*${pre}if (.+?)${suf}/$1/;
-
- if ($self->{$_}) {
- while ($_ = shift) {
- last if (/\s*${pre}end /);
-
- # store line in $par
- $par .= $_;
- }
-
- $_ = $par;
-
- } else {
- while ($_ = shift) {
- last if (/\s*${pre}end /);
- }
- next;
- }
- }
-
- # check for ${pre}include filename${suf}
- if (/\s*${pre}include /) {
-
- # get the directory/filename
- chomp $var;
- $var =~ s/\s*${pre}include (.+?)${suf}/$1/;
-
- # mangle filename on basedir
- $var =~ s/^(\/|\.\.)//g;
-
- # prevent the infinite loop!
- next if ($self->{"$var"});
-
- open(INC, "$self->{templates}/$var")
- or $self->error($self->cleanup . "$self->{templates}/$var : $!");
- unshift(@_, <INC>);
- close(INC);
-
- $self->{"$var"} = 1;
-
- next;
- }
-
- s/${pre}(.+?)${suf}/$self->{$1}/g;
- s/<nobr><\/nobr>/ /g;
- print OUT;