#!/usr/bin/perl -w use strict; use warnings; use utf8; use open qw(:std :utf8); # Filter_3_01_replace_unknown_characters.pl # 2010-04-14 # Wolfgang Schmidle # what does it do? # input # output my $filtername = "Filter_3_01_replace_unknown_characters.pl"; # text input my @text; while(<>) { push @text, $_; } # read default parameters my $filter = "mpdl-workflow-settings.pl"; my $result = `perl $filter`; my $aux = ($result =~ m! aux=([^ ]+) ! ? $1 : "" ); while ($result =~ m! unknown=([^ ]+)!g) { push @ARGV, "$aux/$1"; } # read the "parameters" block my %unknown = (); my $inText = 0; my $inParameters = 0; foreach (@text) { last if m!) { chomp; s!#.*$!!; # remove comments s! +$!!; next if m!^$!; if (m!<(\d\d\d)> +see +<(\d\d\d)>(.*)!) { unless (exists $unknown{$2}) { die "invalid reference:\n$_\n"; } $unknown{$1} = "$unknown{$2} $3"; next; } if (m!<(\d\d\d)> *= *([^ ]+)!) { $unknown{$1} = $2; } } # do not replace codes whose meaning is unclear foreach my $code (keys %unknown) { if ($unknown{$code} =~ /\?/) { $unknown{$code} = "$code"; # in other words, do not replace this code } } # evaluate and remove the "unknown" block my $inUnknown = 0; foreach (@text) { last if m! *= *([^ ]+)!) { die "$filtername: unrecognised unknown character code:\n$_\n"; } $unknown{$1} = $2; $_ = ""; } } # go through the text foreach (@text) { s!<(\d\d\d)>!$unknown{$1}!g; } # text output print @text; # TO DO: