[2821] | 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";
|
---|
[2829] | 16 | my $installshield = 'C:/My Installations/is_gsdl_cdrom/String Tables/0009-English/value.shl';
|
---|
[2821] | 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;
|
---|
[2836] | 31 | $value =~ s/\n/\\n/gs;
|
---|
| 32 | $value =~ s/\t/\\t/gs;
|
---|
[2821] | 33 | if (defined ($texthash->{'install_sh'}->{$key})) {
|
---|
| 34 | print STDERR "ERROR: $1 already defined\n";
|
---|
| 35 | }
|
---|
| 36 | $texthash->{'install_sh'}->{$key} = $value;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | # now grab the text from the macro files
|
---|
| 41 | $texthash->{'macros'} = {};
|
---|
| 42 |
|
---|
| 43 | # english.dm
|
---|
| 44 | &grab_macros("$macrosdir/english.dm");
|
---|
| 45 | # english2.dm
|
---|
| 46 | &grab_macros("$macrosdir/english2.dm");
|
---|
| 47 |
|
---|
[2829] | 48 |
|
---|
| 49 | # text from installshield installation
|
---|
| 50 | $texthash->{'installshield'} = {};
|
---|
| 51 | open (ISHIELD, $installshield) || die;
|
---|
| 52 | my $line = "";
|
---|
| 53 | my $textserver = {};
|
---|
| 54 | while (defined ($line = <ISHIELD>)) {
|
---|
| 55 | next unless ($line =~ /\w/);
|
---|
| 56 | last if $line =~ /^\[General\]/;
|
---|
| 57 | next if $line =~ /^\[/;
|
---|
| 58 |
|
---|
[2836] | 59 | $line =~ s/\n/\\n/gs;
|
---|
| 60 | $line =~ s/\t/\\t/gs;
|
---|
| 61 |
|
---|
[2829] | 62 | if ($line =~ /^(TEXT_SERVERTXT_\d+)=(.*)$/) {
|
---|
| 63 | $textserver->{$1} = $2;
|
---|
| 64 | } else {
|
---|
| 65 | $line =~ /^([^=]+)=(.*)$/;
|
---|
| 66 | $texthash->{'installshield'}->{$1} = $2;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 | close ISHIELD;
|
---|
| 70 | my $tserver = "";
|
---|
| 71 | foreach my $stext (sort keys %{$textserver}) {
|
---|
| 72 | $tserver .= $textserver->{$stext};
|
---|
| 73 | }
|
---|
| 74 | $texthash->{'installshield'}->{'TEXT_SERVERTXT'} = $tserver;
|
---|
| 75 |
|
---|
[2821] | 76 | # print out the result
|
---|
| 77 | foreach my $type (keys (%$texthash)) {
|
---|
| 78 | print STDOUT "type:\t$type\n";
|
---|
| 79 | foreach my $key (sort keys (%{$texthash->{$type}})) {
|
---|
| 80 | print STDOUT "$key\t$texthash->{$type}->{$key}\n";
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | sub grab_macros {
|
---|
| 85 | my ($filename) = @_;
|
---|
| 86 |
|
---|
| 87 | my $line = "";
|
---|
| 88 | my $pack = "Global";
|
---|
| 89 | my $macroname = "";
|
---|
| 90 | my $macrovalue = "";
|
---|
| 91 | open (FILE, $filename) || die;
|
---|
| 92 | while (defined ($line = <FILE>)) {
|
---|
| 93 | if ($line =~ /^package (\w+)/) {
|
---|
| 94 | $pack = $1;
|
---|
| 95 | $macroname = "";
|
---|
| 96 | $macrovalue = "";
|
---|
| 97 | next;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | if ($line =~ /^_([^_\s]+)_\s*(?:\[[^\]]*\])?\s*\{(.*)$/s) {
|
---|
| 101 | die "ERROR 1\n" if ($macroname ne "" || $macrovalue ne "");
|
---|
| 102 | $macroname = $1;
|
---|
| 103 | $macrovalue = $2 if defined $2;
|
---|
| 104 | if ($macrovalue =~ s/^(.*?)(?<!\\)\}/$1/) {
|
---|
| 105 | &addmacro($pack, \$macroname, \$macrovalue);
|
---|
| 106 | }
|
---|
| 107 | } elsif ($macroname ne "") {
|
---|
| 108 | if ($line =~ /^(.*?)(?<!\\)\}/) {
|
---|
| 109 | $macrovalue .= $1 if defined $1;
|
---|
| 110 | &addmacro($pack, \$macroname, \$macrovalue);
|
---|
| 111 | } else {
|
---|
| 112 | $macrovalue .= $line;
|
---|
| 113 | }
|
---|
| 114 | } elsif ($line =~ /^\#\# \"([^\"]+)\" \#\# \w+ \#\# (\w+) \#\#/) {
|
---|
| 115 | my $imagename = "image:$2";
|
---|
| 116 | my $imagetext = $1;
|
---|
| 117 | &addmacro($pack, \$imagename, \$imagetext);
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 | close FILE;
|
---|
| 121 | }
|
---|
| 122 |
|
---|
| 123 | sub addmacro {
|
---|
| 124 | my ($pack, $nameref, $valref) = @_;
|
---|
| 125 |
|
---|
| 126 | if ($$nameref !~ /^(httpicon|width|height)/) {
|
---|
| 127 |
|
---|
| 128 | my $name = "$pack:$$nameref";
|
---|
| 129 |
|
---|
| 130 | if (defined ($texthash->{'macros'}->{$name})) {
|
---|
| 131 | print STDERR "ERROR: $name already defined\n";
|
---|
| 132 | }
|
---|
| 133 |
|
---|
[2836] | 134 |
|
---|
| 135 | $$valref =~ s/\n/\\n/gs;
|
---|
| 136 | $$valref =~ s/\t/\\t/gs;
|
---|
| 137 |
|
---|
[2821] | 138 | $texthash->{'macros'}->{$name} = $$valref;
|
---|
| 139 | }
|
---|
| 140 |
|
---|
| 141 | else {
|
---|
| 142 | # print STDERR "ignoring $$nameref\n";
|
---|
| 143 | }
|
---|
| 144 |
|
---|
| 145 | $$nameref = "";
|
---|
| 146 | $$valref = "";
|
---|
| 147 | }
|
---|