File: map-cc

package info (click to toggle)
choose-mirror 2.13etch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 1,208 kB
  • ctags: 120
  • sloc: perl: 1,199; ansic: 636; sh: 195; makefile: 123; python: 38
file content (32 lines) | stat: -rwxr-xr-x 917 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#! /usr/bin/perl -w
use strict;

my $iso3166xml = shift;

# Get mapping of country names to country codes (i.e. reverse of
# iso3166tab.py output).
my %iso3166rev;
open ISO3166TAB, '-|:utf8', './iso3166tab.py', "$iso3166xml"
    or die "open iso3166tab.py $iso3166xml: $!";
while (<ISO3166TAB>) {
    /^([A-Z]+)\t(.*)$/ or next;
    $iso3166rev{$2} = $1;
}
close ISO3166TAB;

# Stringtable output is easier to handle.
open SOURCESTRINGS, '-|:utf8', 'msgcat', '--stringtable-output', '-'
    or die "open msgcat for source: $!";
open TARGETSTRINGS, '|-:utf8', 'msgcat', '--stringtable-input', '-s', '-'
    or die "open msgcat for target: $!";
while (<SOURCESTRINGS>) {
    if (/^"(.+?)" = "(.*?)";$/) {
	if (exists $iso3166rev{$1}) {
	    print TARGETSTRINGS qq{"$iso3166rev{$1}" = "$2";\n};
	}
    } else {
	print TARGETSTRINGS;
    }
}
close SOURCESTRINGS;
close TARGETSTRINGS or die "close msgcat for target: $!";