source: gsdl/trunk/bin/script/extract_text.pl@ 16378

Last change on this file since 16378 was 16378, checked in by kjdon, 16 years ago

I think I set these files to be executables

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
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
10BEGIN {
11 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
12}
13
14my $installsh = "$ENV{'GSDLHOME'}/Install.sh";
15my $macrosdir = "$ENV{'GSDLHOME'}/macros";
16my $installshield = 'C:/My Installations/is_gsdl_cdrom/String Tables/0009-English/value.shl';
17
18my $texthash = {};
19
20# first extract all the itextn variables from Install.sh
21open (INSTALLSH, $installsh) || die;
22undef $/;
23my $file = <INSTALLSH>;
24$/ = "\n";
25close INSTALLSH;
26
27$texthash->{'install_sh'} = {};
28while ($file =~ s/^(itext\d+)=\"(.*?)(?<!\\)\"//sm) {
29 my $key = $1;
30 my $value = $2;
31 $value =~ s/\n/\\n/gs;
32 $value =~ s/\t/\\t/gs;
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
48
49# text from installshield installation
50$texthash->{'installshield'} = {};
51open (ISHIELD, $installshield) || die;
52my $line = "";
53my $textserver = {};
54while (defined ($line = <ISHIELD>)) {
55 next unless ($line =~ /\w/);
56 last if $line =~ /^\[General\]/;
57 next if $line =~ /^\[/;
58
59 $line =~ s/\n/\\n/gs;
60 $line =~ s/\t/\\t/gs;
61
62 if ($line =~ /^(TEXT_SERVERTXT_\d+)=(.*)$/) {
63 $textserver->{$1} = $2;
64 } else {
65 $line =~ /^([^=]+)=(.*)$/;
66 $texthash->{'installshield'}->{$1} = $2;
67 }
68}
69close ISHIELD;
70my $tserver = "";
71foreach my $stext (sort keys %{$textserver}) {
72 $tserver .= $textserver->{$stext};
73}
74$texthash->{'installshield'}->{'TEXT_SERVERTXT'} = $tserver;
75
76# print out the result
77foreach 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
84sub 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
123sub 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
134
135 $$valref =~ s/\n/\\n/gs;
136 $$valref =~ s/\t/\\t/gs;
137
138 $texthash->{'macros'}->{$name} = $$valref;
139 }
140
141 else {
142# print STDERR "ignoring $$nameref\n";
143 }
144
145 $$nameref = "";
146 $$valref = "";
147}
Note: See TracBrowser for help on using the repository browser.