~ubuntu-branches/ubuntu/vivid/wesnoth-1.8/vivid

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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- perl -*-

sub readwml {
  my ($file) = @_;
  open (TRANS, $file) or die "cannot open $file";

  my (%trans, $key);

  while (<TRANS>) {
    next if m/^\s*\#/ and !defined $key;
    if (m/(\S+)\s*=\s*(?:_\s*)?\"(.*)\"\s*(?:\#.*)?$/) {
      # single-line
      die "nested key" if defined $key;

      $trans{$1} = $2;

    } elsif (m/(\S+)\s*=\s*(?:_\s*)?\s*\"(.*)/) {
      # start of multi-line
      die "nested key" if defined $key;

      $key = $1;
      $trans{$key} = $2 . "\n";

    } elsif (m/(.*)\"\s*(?:\#.*)?$/) {
      # end of multi-line
      die "end of string without a key" unless defined $key;

      $trans{$key} .= $1;
      $key = undef;
    } elsif (defined $key) {
      # part of multi-line
      $trans{$key} .= $_;
    }

  }

  close TRANS;

  return %trans;
}

sub stripfromwml {
  my ($file,@ids) = @_;

  open (TRANS, $file) or die "cannot open $file";

  my $key;

  while (<TRANS>) {
    if (m/(\S+)\s*=\s*\"(.*)\"\s*$/) {
      die "nested key" if defined $key;

      print main::OUTFD $_ unless grep ({ $_ eq $1 } @ids);

    } elsif (m/(\S+)\s*=\s*\"(.*)/) {
      die "nested key" if defined $key;

      $key = $1;
      print main::OUTFD $_ unless grep ({ $_ eq $key } @ids);

    } elsif (m/(.*)\"\s*$/) {
      die "end of string without a key" unless defined $key;

      print main::OUTFD $_ unless grep ({ $_ eq $key } @ids);
      $key = undef;
    } elsif (defined $key) {
      print main::OUTFD $_ unless grep ({ $_ eq $key } @ids);
    } else {
      print main::OUTFD $_;
    }

  }

  close TRANS;
}

sub raw2postring {
  my $str = shift;

  $str =~ s/\"\"/\\\"/mg;
  $str =~ s/^(.*)$/"$1\\n"/mg;
  $str =~ s/\n$/\n"\\n"/mg;
  $str =~ s/\\n\"$/\"\n/g;

  return $str;
}

1;