# HG changeset patch # User Matti Hamalainen # Date 1525454641 -10800 # Node ID a3c3591f9a74a3de229d37e554bc6f0154b65cbe # Parent f2a165403c69ddb4151c9b50e95cac702a7e2492 Clean up this script. diff -r f2a165403c69 -r a3c3591f9a74 docs/normalizeml.pl --- a/docs/normalizeml.pl Fri Nov 04 15:41:49 2016 +0200 +++ b/docs/normalizeml.pl Fri May 04 20:24:01 2018 +0300 @@ -4,9 +4,11 @@ # Programmed by Matti 'ccr' Hamalainen # (C) Copyright 2007,2009 Tecnic Software productions (TNSP) # +use utf8; use strict; use warnings; + sub dorep($$) { my $str = $_[0]; @@ -15,6 +17,7 @@ return $str; } + my %xmlentities = (); my $entMode = 0; my $entData; @@ -23,36 +26,51 @@ binmode(STDIN, ":utf8"); binmode(STDOUT, ":utf8"); -while () { - if (//) { +while (defined(my $line = )) +{ + if ($line =~ //) + { # Handle external entities my $name = $1; my $extfname = $2; local($/, *INFILE); - open(INFILE, "<", $extfname) or die("Could not open entity file '$extfname'.\n"); + open(INFILE, "<", $extfname) or die("Could not open entity file '".$extfname."'.\n"); $xmlentities{$name} = ; close(INFILE); - } elsif (//) { + } + elsif ($line =~ //) + { # One-line entities $xmlentities{$1} = $2; - } elsif (//) { + } + elsif ($entMode == 1) + { + if ($line =~ /^(.*)\">/) + { $entData .= $1; $xmlentities{$entName} = $entData; $entMode = 0; - } else { + } + else + { $entData .= $_; } - } else { + } + else + { # Expand entities for five levels at most - my $str = $_; - for (my $depth = 1; $depth < 5; $depth++) { - while (my ($k, $v) = each(%xmlentities)) { + my $str = $line; + for (my $depth = 1; $depth < 5; $depth++) + { + while (my ($k, $v) = each(%xmlentities)) + { $str =~ s/&$k;/$v/g; $str =~ s/&$k\s+([A-Za-z0-9 ]+);/dorep($v,$1)/eg; }