* configure.pl checks version of Encode.pm. Reported by Chris Stone.
[BackupPC.git] / makeDist
1 #!/bin/perl
2 #
3 # makeDist: Build a BackupPC distribution
4 #
5 # DESCRIPTION
6 #
7 #   This script should be run with no arguments to build a
8 #   distribution.  The $Version and $ReleaseDate should be
9 #   edited below to specify the version name and the release
10 #   date.  The distribution is createede in the sub-directory
11 #   dist.  The dsitribution is in the file name:
12 #
13 #           dist/BackupPC-$Version.tar.gz.
14 #
15 #   Often the language files are not up to date, and makeDist
16 #   exits after complaining about the lang files being inconsistent.
17 #   Use the -l option to turn off that behavior.
18 #
19 # AUTHOR
20 #   Craig Barratt <cbarratt@users.sourceforge.net>
21 #
22 # COPYRIGHT
23 #   Copyright (C) 2001-2006  Craig Barratt
24 #
25 #   This program is free software; you can redistribute it and/or modify
26 #   it under the terms of the GNU General Public License as published by
27 #   the Free Software Foundation; either version 2 of the License, or
28 #   (at your option) any later version.
29 #
30 #   This program is distributed in the hope that it will be useful,
31 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
32 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 #   GNU General Public License for more details.
34 #
35 #   You should have received a copy of the GNU General Public License
36 #   along with this program; if not, write to the Free Software
37 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38 #
39 #========================================================================
40 #
41
42 use strict;
43 use File::Path;
44 use File::Copy;
45 use Getopt::Std;
46 use lib "./lib";
47 use BackupPC::Lib;
48 use BackupPC::Config::Meta qw(:all);
49
50 my $bpc;
51 die("BackupPC::Lib->new failed\n")
52         if ( !($bpc = BackupPC::Lib->new(".", ".", "./conf", 1)) );
53
54 umask(0022);
55
56 my $Version     = "3.0.0beta2";
57 my $ReleaseDate = "31 Oct 2006";
58 my $DistDir     = "dist/BackupPC-$Version";
59
60 my @PerlSrc = qw(
61     bin/BackupPC
62     bin/BackupPC_archive
63     bin/BackupPC_archiveHost
64     bin/BackupPC_attribPrint
65     bin/BackupPC_dump
66     bin/BackupPC_fixupBackupSummary
67     bin/BackupPC_link
68     bin/BackupPC_nightly
69     bin/BackupPC_restore
70     bin/BackupPC_sendEmail
71     bin/BackupPC_serverMesg
72     bin/BackupPC_trashClean
73     bin/BackupPC_tarExtract
74     bin/BackupPC_tarCreate
75     bin/BackupPC_tarPCCopy
76     bin/BackupPC_compressPool
77     bin/BackupPC_zipCreate
78     bin/BackupPC_zcat
79     lib/BackupPC/Attrib.pm
80     lib/BackupPC/Config.pm
81     lib/BackupPC/FileZIO.pm
82     lib/BackupPC/Lib.pm
83     lib/BackupPC/PoolWrite.pm
84     lib/BackupPC/Storage.pm
85     lib/BackupPC/View.pm
86     lib/BackupPC/CGI/AdminOptions.pm
87     lib/BackupPC/CGI/Archive.pm
88     lib/BackupPC/CGI/ArchiveInfo.pm
89     lib/BackupPC/CGI/Browse.pm
90     lib/BackupPC/CGI/DirHistory.pm
91     lib/BackupPC/CGI/EditConfig.pm
92     lib/BackupPC/CGI/EmailSummary.pm
93     lib/BackupPC/CGI/GeneralInfo.pm
94     lib/BackupPC/CGI/HostInfo.pm
95     lib/BackupPC/CGI/Lib.pm
96     lib/BackupPC/CGI/LOGlist.pm
97     lib/BackupPC/CGI/Queue.pm
98     lib/BackupPC/CGI/ReloadServer.pm
99     lib/BackupPC/CGI/RestoreFile.pm
100     lib/BackupPC/CGI/RestoreInfo.pm
101     lib/BackupPC/CGI/Restore.pm
102     lib/BackupPC/CGI/RSS.pm
103     lib/BackupPC/CGI/StartServer.pm
104     lib/BackupPC/CGI/StartStopBackup.pm
105     lib/BackupPC/CGI/StopServer.pm
106     lib/BackupPC/CGI/Summary.pm
107     lib/BackupPC/CGI/View.pm
108     lib/BackupPC/Config/Meta.pm
109     lib/BackupPC/Lang/de.pm
110     lib/BackupPC/Lang/en.pm
111     lib/BackupPC/Lang/es.pm
112     lib/BackupPC/Lang/fr.pm
113     lib/BackupPC/Lang/it.pm
114     lib/BackupPC/Lang/nl.pm
115     lib/BackupPC/Lang/pt_br.pm
116     lib/BackupPC/Storage/Text.pm
117     lib/BackupPC/Xfer/Archive.pm
118     lib/BackupPC/Xfer/BackupPCd.pm
119     lib/BackupPC/Xfer/Smb.pm
120     lib/BackupPC/Xfer/Tar.pm
121     lib/BackupPC/Xfer/Rsync.pm
122     lib/BackupPC/Xfer/RsyncDigest.pm
123     lib/BackupPC/Xfer/RsyncFileIO.pm
124     lib/BackupPC/Zip/FileMember.pm
125     cgi-bin/BackupPC_Admin
126 );
127
128 my %opts;
129 if ( !getopts("l", \%opts) || @ARGV != 0 ) {
130     print("usage: $0 [-l]\n");
131     exit(1);
132 }
133
134 #
135 # Check config parameters
136 #
137 my $ConfVars = {};
138 my $errCnt;
139
140 $errCnt += CheckConfigParams("conf/config.pl", $ConfVars, 0);
141
142 $errCnt += CheckConfigParams("doc-src/BackupPC.pod", $ConfVars, 1);
143
144 $errCnt += CheckMetaDataVsConfig($ConfVars, "lib/BackupPC/Config/Meta.pm");
145
146 $errCnt += CheckEditorVsConfig($ConfVars, "lib/BackupPC/CGI/EditConfig.pm");
147
148 #
149 # These config parameters are not used in the code, so ignore them.
150 #
151 $ConfVars->{BackupPCUser} = 2;
152 $ConfVars->{CgiDir}       = 2;
153 $ConfVars->{TopDir}       = 2;
154 $ConfVars->{LogDir}       = 2;
155 $ConfVars->{ConfDir}      = 2;
156 $ConfVars->{InstallDir}   = 2;
157 $ConfVars->{CgiImageDir}  = 2;
158
159 #
160 # These config parameters are used in the code to be backward compatible,
161 # but are not present in the current config file, so ignore them.
162 #
163 $ConfVars->{BlackoutHourBegin} = 2;
164 $ConfVars->{BlackoutHourEnd}   = 2;
165 $ConfVars->{BlackoutWeekDays}  = 2;
166 $ConfVars->{RsyncLogLevel}     = 2;
167
168 foreach my $file ( @PerlSrc ) {
169     $errCnt += CheckConfigParams($file, $ConfVars, 1);
170 }
171 if ( !$opts{l} ) {
172     $errCnt += CheckLangUsage();
173     $errCnt += CheckLangTags();
174 }
175 if ( $errCnt ) {
176     print("Exiting because of errors\n");
177     exit(1)
178 }
179
180 $errCnt = 0;
181 foreach my $var ( sort(keys(%$ConfVars) ) ) {
182     next if ( $ConfVars->{$var} >= 2 || $var =~ /^\$/ );
183     printf("Unused config parameter $var\n");
184     $errCnt++;
185 }
186 if ( $errCnt ) {
187     print("Exiting because of errors\n");
188     exit(1)
189 }
190
191 rmtree($DistDir, 0, 0);
192 mkpath($DistDir, 0, 0777);
193
194 foreach my $dir ( qw(bin doc conf images init.d/src cgi-bin
195                      lib/BackupPC/CGI
196                      lib/BackupPC/Config
197                      lib/BackupPC/Lang
198                      lib/BackupPC/Storage
199                      lib/BackupPC/Xfer
200                      lib/BackupPC/Zip
201                 ) ) {
202     mkpath("$DistDir/$dir", 0, 0777);
203 }
204
205 my %ConfName;
206 my $ConfPod = config2pod();
207 rmtree("doc", 0, 0);
208 mkpath("doc", 0, 0777);
209 InstallFile("doc-src/BackupPC.pod", "doc/BackupPC.pod");
210
211 use Pod::Html;
212 pod2html("doc/BackupPC.pod",
213         "--backlink=Back to Top",
214         "--header",
215         "--title=BackupPC",
216         "--outfile=doc/BackupPC.html");
217
218 foreach my $file ( (@PerlSrc,
219             <images/*>,
220             qw(
221                 conf/config.pl
222                 conf/hosts
223                 conf/BackupPC_stnd.css
224                 conf/BackupPC_stnd_orig.css
225                 init.d/README
226                 init.d/src/debian-backuppc
227                 init.d/src/gentoo-backuppc
228                 init.d/src/gentoo-backuppc.conf
229                 init.d/src/linux-backuppc
230                 init.d/src/slackware-backuppc
231                 init.d/src/solaris-backuppc
232                 init.d/src/suse-backuppc
233                 doc/BackupPC.pod
234                 doc/BackupPC.html
235                 README
236                 LICENSE
237                 ChangeLog
238                 configure.pl
239         )) ) {
240     InstallFile("$file", "$DistDir/$file");
241 }
242 rmtree("doc", 0, 0);
243 system("cd dist ; tar zcf BackupPC-$Version.tar.gz BackupPC-$Version");
244 print("Distribution written to dist/BackupPC-$Version.tar.gz\n");
245 unlink("pod2htmd.x~~");
246 unlink("pod2htmi.x~~");
247 unlink("pod2htmd.tmp");
248 unlink("pod2htmi.tmp");
249
250 ###########################################################################
251 # Subroutines
252 ###########################################################################
253
254 sub InstallFile
255 {
256     my($file, $dest) = @_;
257
258     unlink($dest) if ( -d $dest );
259     if ( $file =~ /\.gif/ ) {
260         die("can't copy($file, $dest)\n") unless copy($file, $dest);
261     } else {
262         open(FILE, $file)   || die("can't open $file for reading\n");
263         open(OUT, ">$dest") || die("can't open $dest for writing\n");
264         binmode(FILE);
265         binmode(OUT);
266         while ( <FILE> ) {
267             s/^([#*\s]+)Version \d+\.\d+[\.\w]*, released \d+ \w+ \d{4}\.?/$1Version __VERSION__, released __RELEASEDATE__./;
268             s/__VERSION__/$Version/g;
269             s/__RELEASEDATE__/$ReleaseDate/g;
270             if ( $file =~ /BackupPC\.html$/ ) {
271                 #
272                 # fixup for perl 5.6.x
273                 #
274                 if ( !/A NAME="item_(%|_)24Conf/i ) {
275                     s/\$Conf{([^}]*)}/
276                         defined($ConfName{$1})
277                             ? "\L<A HREF=\"#$ConfName{$1}\">\E\$Conf{$1}<\/A>"
278                             : "\$Conf{$1}"/eg;
279                 }
280                 s/<(A NAME="item_(%|_)24Conf(%|_)7B(.*?)(%|_)7D).*?">/\L<A NAME="item_%24Conf%7b$4%7d">/ig;
281                 s/^<DD>/<DD><P>/;
282                 #
283                 # Fixup for perl 5.8.x first one no longer needed after
284                 # fix in CSS)
285                 #
286 #               if ( /^<\/dt>/ ) {
287 #                   $_ .= <FILE>;
288 #                   s/^(<\/dt>\n<dd>)/$1<p>/s;
289 #               }
290                 s/^<li><\/li>/<li>/;
291             }
292             if ( /__CONFIGPOD__/ ) {
293                 print OUT $ConfPod;
294             } elsif ( /^use lib ".*BackupPC\/lib";/
295                     || /^use lib "\/home\/pcbackup\/install\/lib";/ ) {
296                 print OUT "use lib \"__INSTALLDIR__/lib\";\n";
297             } elsif ( $file =~ /Lib.pm/ && /^(\s*\$topDir\s*=\s*)'.*'(\s*if\s.*)/ ) {
298                 print OUT "$1'__TOPDIR__'$2\n";
299             } elsif ( $file =~ /Lib.pm/ && /^(\s*\$installDir\s*=\s*)'.*'(\s*if\s.*)/ ) {
300                 print OUT "$1'__INSTALLDIR__'$2\n";
301             } elsif ( $file =~ /Lib.pm/ && /^(\s*my \$useFHS\s*=\s*)\d;/ ) {
302                 print OUT "${1}0;\n";
303             } elsif ( $file =~ /Lib.pm/ && /(.*Version *=> .*)'[\w\d\.]+',/ ) {
304                 print OUT "$1'$Version',\n";
305             } elsif ( $file =~ /configure.pl/ && /__CONFIGURE_BIN_LIST__/ ) {
306                 print OUT "        ", join("\n        ", grep(/^bin\//, @PerlSrc)), "\n";
307             } elsif ( $file =~ /configure.pl/ && /__CONFIGURE_LIB_LIST__/ ) {
308                 print OUT "        ", join("\n        ", grep(/^lib\//, @PerlSrc)), "\n";
309             } elsif ( $file =~ /BackupPC_Admin/ && /(my *\$installDir *= *)'.*'/ ) {
310                 print OUT "$1'__INSTALLDIR__/lib';\n";
311             } else {
312                 print OUT;
313             }
314         }
315         close(FILE);
316         close(OUT);
317     }
318     if ( -x $file ) {
319         chmod(0555, $dest);
320     } else {
321         chmod(0444, $dest);
322     }
323 }
324
325 sub config2pod
326 {
327     open(C, "conf/config.pl") || die("can't open conf/config.pl");
328     binmode(C);
329     my($str, $out, $getHdr, @conf);
330     my $first = 1;
331     while ( <C> ) {
332         chomp;
333         s/ +$//;
334         if ( /^#########################/ ) {
335             if ( $getHdr ) {
336                 $str =~ s/\n.*//sg;
337                 $out .= "=back\n\n" if ( !$first );
338                 $out .= "=head2 $str\n\n=over 4\n\n";
339                 $str = "";
340                 $first = 0;
341             }
342             $getHdr = !$getHdr;
343             next;
344         }
345         if ( /^#/ ) {
346             s/# ?//;
347             next if ( $str eq "" && /^$/ );
348             $str .= $_ . "\n";
349             $str .= "\n" if ( $str =~ /examples?:\n$/i );
350         } elsif ( /^\$Conf{([^}]*)/ ) {
351             my $var = $1;
352             s/  +/ /g;
353             s/;\s*#.*/;/;
354             if ( !s/\[$/[ ... ];/ && !s/<<'EOF'/.../ ) {
355                 s/([^;])\s*$/$1 .../;
356             }
357             push(@conf, $_);
358             my $text = "\$Conf{$var}";
359             $text =~ s/\s+/_/sg;
360             $text =~ s{(\W)}{sprintf("%%%02X", ord($1) )}gxe;
361             $text = substr($text, 0, 50);
362             $ConfName{$var} = "item_$text";
363         } elsif ( /^$/ ) {
364             if ( $str ne "" && @conf ) {
365                 $out .= "=item " . join("\n\n=item ", @conf) . "\n\n";
366                 $out .= $str;
367                 $out .= "\n" if ( $str !~ /\n$/ );
368             }
369             $str = "";
370             @conf = ();
371         }
372     }
373     if ( $str ne "" && @conf ) {
374         $out .= "=item " . join("\n\n=item ", @conf) . "\n\n";
375         $out .= $str;
376         $out .= "\n" if ( $str !~ /\n$/ );
377     }
378     $out .= "=back\n\n" if ( !$first );
379     return $out;
380 }
381
382 sub CheckConfigParams
383 {
384     my($file, $vars, $check) = @_;
385     my $errors;
386
387     open(F, $file) || die("can't open $file\n");
388     binmode(F);
389     if ( $check ) {
390         while ( <F> ) {
391             s/\$(self|bpc)->{Conf}{([^}\$]+)}/if ( !defined($vars->{$2}) ) {
392                     print("Unexpected Conf var $2 in $file\n");
393                     $errors++;
394                 } else {
395                     $vars->{$2}++;
396                 }/eg;
397             s/\$[Cc]onf(?:->)?{([^}\$]+)}/if ( !defined($vars->{$1}) ) {
398                     print("Unexpected Conf var $1 in $file\n");
399                     $errors++;
400                 } else {
401                     $vars->{$1}++;
402                 }/eg;
403             s/UserCommandRun\("([^"]*)"/if ( !defined($vars->{$1}) ) {
404                     print("Unexpected Conf var $1 in $file\n");
405                     $errors++;
406                 } else {
407                     $vars->{$1}++;
408                 }/eg;
409         }
410     } else {
411         while ( <F> ) {
412             s/^[^#]*\$self->{Conf}{([^}]*)/$vars->{$1} = 1;/eg;
413             s/^[^#]*\$Conf{([^}]*)/$vars->{$1} = 1;/eg;
414         }
415     }
416     close(F);
417     return $errors;
418 }
419
420 sub CheckMetaDataVsConfig
421 {
422     my($confVars, $file) = @_;
423     my $done = {};
424     my $errors;
425
426     #
427     # Check that the meta file mentions all the config
428     # parameters
429     #
430     open(F, $file) || die("can't open $file");
431
432     while ( <F> ) {
433         next if ( !/^\s{4}(\w+)\s+=>/ );
434         if ( $confVars->{$1} ) {
435             $done->{$1} = 1;
436             next;
437         }
438         next if ( $1 eq "Hosts" );
439         print("$file has $1 but missing from conf/config.pl\n");
440         $errors++;
441     }
442     close(F);
443     foreach my $v ( keys(%$confVars) ) {
444         next if ( $done->{$v} );
445         print("$file missing $v from conf/config.pl\n");
446         $errors++;
447     }
448
449     #
450     # Do extra checks that the CgiUserConfigEdit hash in the Meta
451     # file matches the config file
452     #
453     foreach my $p ( keys(%{$ConfigMeta{CgiUserConfigEdit}{child}}) ) {
454         if ( !defined($bpc->{Conf}{CgiUserConfigEdit}{$p}) ) {
455             print("lib/BackupPC/Config/Meta.pm has $p in CgiUserConfigEdit,"
456                 . " but conf/config.pl CgiUserConfigEdit does not\n");
457             $errors++;
458         }
459     }
460     foreach my $p ( keys(%{$bpc->{Conf}{CgiUserConfigEdit}}) ) {
461         if ( !defined($ConfigMeta{CgiUserConfigEdit}{child}{$p}) ) {
462             print("conf/config.pl CgiUserConfigEdit has $p, but"
463                 . " lib/BackupPC/Config/Meta.pm does not\n");
464             $errors++;
465         }
466     }
467     return $errors;
468 }
469
470 sub CheckEditorVsConfig
471 {
472     my($confVars, $file) = @_;
473     my $done = {};
474     my $errors;
475
476     #
477     # Check that the config editor file mentions all the config
478     # parameters
479     #
480     open(F, $file) || die("can't open $file");
481
482     while ( <F> ) {
483         next if ( !/name\s*=>\s*"(\w+)"/ );
484         if ( $confVars->{$1} ) {
485             $done->{$1} = 1;
486             next;
487         }
488         next if ( $1 eq "Hosts" );
489         print("$file has $1 but missing from conf/config.pl\n");
490         $errors++;
491     }
492     close(F);
493     foreach my $v ( keys(%$confVars) ) {
494         next if ( $done->{$v} );
495         print("$file missing $v from conf/config.pl\n");
496         $errors++;
497     }
498     return $errors;
499 }
500
501 #
502 # Make sure that every lang variable in cgi-bin/BackupPC_Admin matches
503 # the strings in each lib/BackupPC/Lang/*.pm file.  This makes sure
504 # we didn't miss any translations in any of the languages.
505 #
506 sub CheckLangUsage
507 {
508     my $errors;
509     my $vars = {};
510
511     foreach my $file ( (
512                 qw(cgi-bin/BackupPC_Admin bin/BackupPC_sendEmail),
513                 <lib/BackupPC/CGI/*pm>,
514                 <lib/BackupPC/Lang/en.pm>,
515             ) ) {
516         open(F, $file) || die("can't open $file");
517         binmode(F);
518         while ( <F> ) {
519             next if ( /^\s*#/ );
520             s/\$Lang->{([^}]*)}/$vars->{$1} = 1;/eg;
521             s/(text|comment)\s*=>\s*"(CfgEdit_.*)"/$vars->{$2} = 1;/eg;
522         }
523         close(F);
524     }
525
526     foreach my $f ( <lib/BackupPC/Lang/*.pm> ) {
527         my $done = {};
528         open(F, $f) || die("can't open $f\n");
529         binmode(F);
530         while ( <F> ) {
531             s/#.*//g;
532             s/\$Lang{([^}]*)}/
533                     my $var = $1;
534                     next if ( $var =~ m{^(Reason_|Status_|backupType_|Disabled_)} );
535                     next if ( $var eq "Documentation" );
536                     if ( !defined($vars->{$var}) ) {
537                         print("Unexpected Lang var $var in $f\n");
538                         $errors++;
539                     } else {
540                         $done->{$var} = 1;
541                     }/eg;
542         }
543         close(F);
544         foreach my $v ( keys(%$vars) ) {
545             #
546             # skip "variables" with "$", since they are like expressions
547             #
548             next if ( $v =~ /\$/ );
549             if ( !defined($done->{$v}) ) {
550                 print("Lang var $v missing from $f\n");
551                 $errors++;
552             }
553         }
554     }
555     return $errors;
556 }
557
558 #
559 # Pedantically check that all the html tags in each language file
560 # match.
561 #
562 sub CheckLangTags
563 {
564     my($en, $enVars) = LangParse("lib/BackupPC/Lang/en.pm");
565     my($errors);
566
567     foreach my $lang ( qw(fr.pm de.pm es.pm it.pm nl.pm) ) {
568         my($d, $dVars) = LangParse("lib/BackupPC/Lang/$lang");
569         foreach my $v1 ( @$en ) {
570             my $v2 = shift(@$d);
571             if ( $v1->{var} ne $v2->{var} ) {
572                 print("Botch: got $lang var $v2->{var} vs en.pm $v1->{var}\n");
573                 exit;
574             }
575             my $t1 = LangTextStrip($v1->{val});
576             my $t2 = LangTextStrip($v2->{val});
577             if ( $t1 ne $t2 ) {
578                 my $i;
579                 for ( $i = 0 ; $i < length($t1) ; $i++ ) {
580                     last if ( substr($t1, 0, $i) ne substr($t2, 0, $i) );
581                 }
582                 print("$v1->{var}: ($i) got en.pm $t1\nvs $lang $t2\n\n");
583                 $errors++;
584             }
585         }
586     }
587     return $errors;
588 }
589
590 sub LangTextStrip
591 {
592     my($t) = @_;
593
594     $t = "" if ( $t !~ /<.*>/ );
595     $t =~ s/^[^<]*</</s;
596     $t =~ s/([}>])[^<]*</$1</g;
597     $t =~ s/>[^<]*$/>/;
598     $t =~ s/(value=)"[^"]*"/$1""/sg;
599     $t =~ s/({h[12]\()"[^"]*"/$1""/g;
600     $t =~ s/ENG[\s\n]*//sg;
601     $t =~ s/^(<<EOF;\n)[^<]*/$1/g;
602     return $t;
603 }
604
605 sub LangParse
606 {
607     my($file) = @_;
608     open(C, $file) || die("can't open $file");
609     binmode(C);
610     my($out, @lang, $var);
611     my $comment = 1;
612     my $allVars = {};
613     my $endLine = undef;
614     while ( <C> ) {
615         if ( /^#/ && !defined($endLine) ) {
616             if ( $comment ) {
617                 $out .= $_;
618             } else {
619                 if ( $out ne "" ) {
620                     $allVars->{$var} = @lang if ( defined($var) );
621                     push(@lang, {
622                         text => $out,
623                         var => $var,
624                     });
625                 }
626                 $var = undef;
627                 $comment = 1;
628                 $out = $_;
629             }
630         } elsif ( /^\s*\$Lang\{([^}]*)/ ) {
631             $comment = 0;
632             if ( defined($var) ) {
633                 $allVars->{$var} = @lang if ( defined($var) );
634                 push(@lang, {
635                     text => $out,
636                     var => $var,
637                 });
638                 $out = $_;
639             } else {
640                 $out .= $_;
641             }
642             $var = $1;
643             $endLine = $1 if ( /^\s*\$Lang\{[^}]*} *= *<<(.*);/ );
644             $endLine = $1 if ( /^\s*\$Lang\{[^}]*} *= *<<'(.*)';/ );
645         } else {
646             $endLine = undef if ( defined($endLine) && /^\Q$endLine[\n\r]*$/ );
647             $out .= $_;
648         }
649     }
650     if ( $out ne "" ) {
651         $allVars->{$var} = @lang if ( defined($var) );
652         push(@lang, {
653             text => $out,
654             var  => $var,
655         });
656     }
657     close(C);
658     foreach my $v ( @lang ) {
659         if ( $v->{text} =~ /\$Lang{$v->{var}}\s*=\s*(.*)/s ) {
660             $v->{val} = $1;
661         }
662     }
663     return (\@lang, $allVars);
664 }