summaryrefslogtreecommitdiffhomepage
path: root/build/i18n-html2lua.pl
blob: c6b893eee480f5257e65492e658c7e3e974a2f15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/perl

@ARGV || die "Usage: $0 template1.htm [... templateN.htm]\n";


my %tags;

foreach my $file ( @ARGV )
{
	if( open F, "< $file" )
	{
		local $/ = undef;

		my $data = <F>;

		while( $data =~ m/ <%: -? (\w+) (.*?) %> /sgx )
		{
			my ( $key, $val ) = ( $1, $2 );

			if( $key && $val )
			{
				$val =~ s/\s+/ /sg;
				$val =~ s/^\s+//;
				$val =~ s/\s+$//;

				$tags{$key} = $val;
			}
			else
			{
				$tags{$key} ||= '';
			}
		}

		close F;
	}
}

foreach my $key ( sort keys %tags )
{
	if( $val =~ /'/ )
	{
		printf "%s = [[%s]]\n", $key, $tags{$key};
	}
	else
	{
		printf "%s = '%s'\n", $key, $tags{$key};
	}
}