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

Last change on this file since 2821 was 2821, checked in by sjboddie, 22 years ago

wrote a quick perl script for extracting all the English text from macro
files, install scripts and stuff

  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 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";
16
17my $texthash = {};
18
19# first extract all the itextn variables from Install.sh
20open (INSTALLSH, $installsh) || die;
21undef $/;
22my $file = <INSTALLSH>;
23$/ = "\n";
24close INSTALLSH;
25
26$texthash->{'install_sh'} = {};
27while ($file =~ s/^(itext\d+)=\"(.*?)(?<!\\)\"//sm) {
28 my $key = $1;
29 my $value = $2;
30 $value =~ s/\n+/ /gs;
31 if (defined ($texthash->{'install_sh'}->{$key})) {
32 print STDERR "ERROR: $1 already defined\n";
33 }
34 $texthash->{'install_sh'}->{$key} = $value;
35}
36
37
38# now grab the text from the macro files
39$texthash->{'macros'} = {};
40
41# english.dm
42&grab_macros("$macrosdir/english.dm");
43# english2.dm
44&grab_macros("$macrosdir/english2.dm");
45
46# print out the result
47foreach my $type (keys (%$texthash)) {
48 print STDOUT "type:\t$type\n";
49 foreach my $key (sort keys (%{$texthash->{$type}})) {
50 print STDOUT "$key\t$texthash->{$type}->{$key}\n";
51 }
52}
53
54sub grab_macros {
55 my ($filename) = @_;
56
57 my $line = "";
58 my $pack = "Global";
59 my $macroname = "";
60 my $macrovalue = "";
61 open (FILE, $filename) || die;
62 while (defined ($line = <FILE>)) {
63 if ($line =~ /^package (\w+)/) {
64 $pack = $1;
65 $macroname = "";
66 $macrovalue = "";
67 next;
68 }
69
70 if ($line =~ /^_([^_\s]+)_\s*(?:\[[^\]]*\])?\s*\{(.*)$/s) {
71 die "ERROR 1\n" if ($macroname ne "" || $macrovalue ne "");
72 $macroname = $1;
73 $macrovalue = $2 if defined $2;
74 if ($macrovalue =~ s/^(.*?)(?<!\\)\}/$1/) {
75 &addmacro($pack, \$macroname, \$macrovalue);
76 }
77 } elsif ($macroname ne "") {
78 if ($line =~ /^(.*?)(?<!\\)\}/) {
79 $macrovalue .= $1 if defined $1;
80 &addmacro($pack, \$macroname, \$macrovalue);
81 } else {
82 $macrovalue .= $line;
83 }
84 } elsif ($line =~ /^\#\# \"([^\"]+)\" \#\# \w+ \#\# (\w+) \#\#/) {
85 my $imagename = "image:$2";
86 my $imagetext = $1;
87 &addmacro($pack, \$imagename, \$imagetext);
88 }
89 }
90 close FILE;
91}
92
93sub addmacro {
94 my ($pack, $nameref, $valref) = @_;
95
96 if ($$nameref !~ /^(httpicon|width|height)/) {
97
98 my $name = "$pack:$$nameref";
99
100 if (defined ($texthash->{'macros'}->{$name})) {
101 print STDERR "ERROR: $name already defined\n";
102 }
103
104 $$valref =~ s/\n+/ /gs;
105 $texthash->{'macros'}->{$name} = $$valref;
106 }
107
108 else {
109# print STDERR "ignoring $$nameref\n";
110 }
111
112 $$nameref = "";
113 $$valref = "";
114}
Note: See TracBrowser for help on using the repository browser.