]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - tools/cvs2sql.pl
git-svn-id: http://svn.ipfire.org/svn/ipfire/IPFire/source@16 ea5c0bd1-69bd-2848...
[people/teissler/ipfire-2.x.git] / tools / cvs2sql.pl
1 #!/usr/bin/perl
2 #
3 # This file is part of the IPCop Firewall.
4 #
5 # IPCop is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # IPCop is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with IPCop; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19 # Copyright (C) 2003-02-04 Mark Wormgoor <mark@wormgoor.com>
20 #
21
22 # Usage:
23 #
24 # ./tools/cvs2sql.pl | grep -e INSERT -e UPDATE > lang_data.sql
25 #
26
27 # Get time
28 ($sec, $min, $hour, $day, $month, $year, $weekday, $dayofyear, $isdst) = localtime(time);
29 $year += 1900;
30 if ($month < 10) { $month = "0" . $month; }
31 if ($day < 10) { $day = "0" . $day; }
32 if ($hour < 10) { $hour = "0" . $hour; }
33 if ($min < 10) { $min = "0" . $min; }
34 if ($sec < 10) { $sec = "0" . $sec; }
35 $lastchange = "$year$month$day$hour$sec";
36
37 # Read English install file
38 undef $/;
39 open (FILE, "langs/en/install/lang_en.c") or die "Couldn't open English language file";
40 $file = <FILE>;
41 close (FILE);
42 $file =~ s/"\s*\\\s*\n"//g;
43 $file =~ s/",/"/g;
44 $file =~ s/\\n/\\\\n/g;
45 $file =~ s/^.*(TR_[\w]+).*$/$1/gm;
46 $file =~ s/(TR_\w+)\n(.*$)/INSERT INTO Lang_Data (VarName, EN_Word, Section, LastChange) Values ("$1", $2, "SETUP", "$lastchange");/gm;
47 print "$file";
48
49 # Read English Perl file
50 do "langs/en/cgi-bin/en.pl" or die "Failed to open English web language file";
51 while( my ($key, $value) = each(%tr) ) {
52 $key = lc($key);
53 $value =~ s/\n//mg;
54 $value =~ s/\\*\"/\\"/g;
55 print "INSERT INTO Lang_Data (VarName, EN_Word, Section, LastChange) Values (\"$key\", \"$value\", \"WEB\", \"$lastchange\");\n";
56 }
57
58 # Other language install files
59 while (($trans = glob("langs/*/install/lang_*.c") )) {
60 if ( $trans =~ /lang_en.c/ ) { next; }
61 if ( $trans =~ /lang_el.c/ ) { next; }
62 open (FILE, "$trans") or die "Couldn't open language file: $trans";
63 $file = <FILE>;
64 close (FILE);
65 $trans =~ s/.*lang_(.*).c/$1/;
66 $trans = uc($trans);
67 $file =~ s/"\s*\\\s*\n"//g;
68 $file =~ s/",/"/g;
69 $file =~ s/\\n/\\\\n/g;
70 $file =~ s/^.*(TR_[\w]+).*$/$1/gm;
71 $file =~ s/(TR_\w+)\n(.*$)/UPDATE Lang_Data set ${trans}_Word = $2 where VarName = "$1";/gm;
72 print "$file";
73 }
74
75 # Other language perl files
76 while (($trans = glob("langs/*/cgi-bin/*.pl") )) {
77 if ( $trans =~ /en.pl/ ) { next; }
78 if ( $trans =~ /el.pl/ ) { next; }
79 %tr=();
80 do "$trans" or die "Failed to load translation file: $trans";
81 $trans =~ s/.*\/(\w+).pl/$1/;
82 $trans = uc($trans);
83 while( my ($key, $value) = each(%tr) ) {
84 $key = lc($key);
85 $value =~ s/\n//mg;
86 $value =~ s/\\*\"/\\"/g;
87 print "UPDATE Lang_Data set ${trans}_Word = \"$value\" where VarName = \"$key\";\n";
88 }
89 }