1 | #! /usr/bin/perl -w
|
---|
2 |
|
---|
3 | # extract_text.pl extracts the text from macro files, install scripts
|
---|
4 | # etc. for translation.
|
---|
5 |
|
---|
6 | # output is currently to a tab separated list, suitable for importing into
|
---|
7 | # excel.
|
---|
8 |
|
---|
9 |
|
---|
10 | BEGIN {
|
---|
11 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
12 | }
|
---|
13 |
|
---|
14 | my $installsh = "$ENV{'GSDLHOME'}/Install.sh";
|
---|
15 | my $macrosdir = "$ENV{'GSDLHOME'}/macros";
|
---|
16 | my $installshield = 'C:/My Installations/is_gsdl_cdrom/String Tables/0009-English/value.shl';
|
---|
17 |
|
---|
18 | my $texthash = {};
|
---|
19 |
|
---|
20 | # first extract all the itextn variables from Install.sh
|
---|
21 | open (INSTALLSH, $installsh) || die;
|
---|
22 | undef $/;
|
---|
23 | my $file = <INSTALLSH>;
|
---|
24 | $/ = "\n";
|
---|
25 | close INSTALLSH;
|
---|
26 |
|
---|
27 | $texthash->{'install_sh'} = {};
|
---|
28 | while ($file =~ s/^(itext\d+)=\"(.*?)(?<!\\)\"//sm) {
|
---|
29 | my $key = $1;
|
---|
30 | my $value = $2;
|
---|
31 | $value =~ s/\n+/ /gs;
|
---|
32 | if (defined ($texthash->{'install_sh'}->{$key})) {
|
---|
33 | print STDERR "ERROR: $1 already defined\n";
|
---|
34 | }
|
---|
35 | $texthash->{'install_sh'}->{$key} = $value;
|
---|
36 | }
|
---|
37 |
|
---|
38 |
|
---|
39 | # now grab the text from the macro files
|
---|
40 | $texthash->{'macros'} = {};
|
---|
41 |
|
---|
42 | # english.dm
|
---|
43 | &grab_macros("$macrosdir/english.dm");
|
---|
44 | # english2.dm
|
---|
45 | &grab_macros("$macrosdir/english2.dm");
|
---|
46 |
|
---|
47 |
|
---|
48 | # text from installshield installation
|
---|
49 | $texthash->{'installshield'} = {};
|
---|
50 | open (ISHIELD, $installshield) || die;
|
---|
51 | my $line = "";
|
---|
52 | my $textserver = {};
|
---|
53 | while (defined ($line = <ISHIELD>)) {
|
---|
54 | next unless ($line =~ /\w/);
|
---|
55 | last if $line =~ /^\[General\]/;
|
---|
56 | next if $line =~ /^\[/;
|
---|
57 |
|
---|
58 | if ($line =~ /^(TEXT_SERVERTXT_\d+)=(.*)$/) {
|
---|
59 | $textserver->{$1} = $2;
|
---|
60 | } else {
|
---|
61 | $line =~ /^([^=]+)=(.*)$/;
|
---|
62 | $texthash->{'installshield'}->{$1} = $2;
|
---|
63 | }
|
---|
64 | }
|
---|
65 | close ISHIELD;
|
---|
66 | my $tserver = "";
|
---|
67 | foreach my $stext (sort keys %{$textserver}) {
|
---|
68 | $tserver .= '\n' unless $tserver eq "";
|
---|
69 | $tserver .= $textserver->{$stext};
|
---|
70 | }
|
---|
71 | $texthash->{'installshield'}->{'TEXT_SERVERTXT'} = $tserver;
|
---|
72 |
|
---|
73 | # print out the result
|
---|
74 | foreach my $type (keys (%$texthash)) {
|
---|
75 | print STDOUT "type:\t$type\n";
|
---|
76 | foreach my $key (sort keys (%{$texthash->{$type}})) {
|
---|
77 | print STDOUT "$key\t$texthash->{$type}->{$key}\n";
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | sub grab_macros {
|
---|
82 | my ($filename) = @_;
|
---|
83 |
|
---|
84 | my $line = "";
|
---|
85 | my $pack = "Global";
|
---|
86 | my $macroname = "";
|
---|
87 | my $macrovalue = "";
|
---|
88 | open (FILE, $filename) || die;
|
---|
89 | while (defined ($line = <FILE>)) {
|
---|
90 | if ($line =~ /^package (\w+)/) {
|
---|
91 | $pack = $1;
|
---|
92 | $macroname = "";
|
---|
93 | $macrovalue = "";
|
---|
94 | next;
|
---|
95 | }
|
---|
96 |
|
---|
97 | if ($line =~ /^_([^_\s]+)_\s*(?:\[[^\]]*\])?\s*\{(.*)$/s) {
|
---|
98 | die "ERROR 1\n" if ($macroname ne "" || $macrovalue ne "");
|
---|
99 | $macroname = $1;
|
---|
100 | $macrovalue = $2 if defined $2;
|
---|
101 | if ($macrovalue =~ s/^(.*?)(?<!\\)\}/$1/) {
|
---|
102 | &addmacro($pack, \$macroname, \$macrovalue);
|
---|
103 | }
|
---|
104 | } elsif ($macroname ne "") {
|
---|
105 | if ($line =~ /^(.*?)(?<!\\)\}/) {
|
---|
106 | $macrovalue .= $1 if defined $1;
|
---|
107 | &addmacro($pack, \$macroname, \$macrovalue);
|
---|
108 | } else {
|
---|
109 | $macrovalue .= $line;
|
---|
110 | }
|
---|
111 | } elsif ($line =~ /^\#\# \"([^\"]+)\" \#\# \w+ \#\# (\w+) \#\#/) {
|
---|
112 | my $imagename = "image:$2";
|
---|
113 | my $imagetext = $1;
|
---|
114 | &addmacro($pack, \$imagename, \$imagetext);
|
---|
115 | }
|
---|
116 | }
|
---|
117 | close FILE;
|
---|
118 | }
|
---|
119 |
|
---|
120 | sub addmacro {
|
---|
121 | my ($pack, $nameref, $valref) = @_;
|
---|
122 |
|
---|
123 | if ($$nameref !~ /^(httpicon|width|height)/) {
|
---|
124 |
|
---|
125 | my $name = "$pack:$$nameref";
|
---|
126 |
|
---|
127 | if (defined ($texthash->{'macros'}->{$name})) {
|
---|
128 | print STDERR "ERROR: $name already defined\n";
|
---|
129 | }
|
---|
130 |
|
---|
131 | $$valref =~ s/\n+/ /gs;
|
---|
132 | $texthash->{'macros'}->{$name} = $$valref;
|
---|
133 | }
|
---|
134 |
|
---|
135 | else {
|
---|
136 | # print STDERR "ignoring $$nameref\n";
|
---|
137 | }
|
---|
138 |
|
---|
139 | $$nameref = "";
|
---|
140 | $$valref = "";
|
---|
141 | }
|
---|