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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
#!/usr/bin/env perl
$indent_level = 0;
sub print_xml_line
{
my ($text) = @_;
print " " x $indent_level;
print $text . "\n";
}
sub xml_enter
{
$indent_level += 2;
}
sub xml_leave
{
$indent_level -= 2;
}
sub xml_quote
{
my $in = $_[0];
my $out = "";
my @xe;
my $joined = 0;
my @xml_entities = ( "<", '<', ">", '>', "'", '\'', """, '"', "&", '&' );
my @clist = split (//, $in);
while (@clist)
{
# Find character and join its entity equivalent.
# If none found, simply join the character.
$joined = 0; # Cumbersome.
for (@xe = @xml_entities; @xe && !$joined; )
{
if ($xe [1] eq $clist [0]) { $out = join ('', $out, $xe [0]); $joined = 1; }
shift @xe; shift @xe;
}
if (!$joined) { $out = join ('', $out, $clist [0]); }
shift @clist;
}
return $out;
}
sub convert_about
{
&print_xml_line ("<comment>");
while (<STDIN>)
{
chomp;
s/^[ \t]+//;
s/[ \\]+$//;
if (/^\#/) { next; }
if (/^\}/) { last; }
s/\\n\\n/\n/g;
s/\\n/\n/g;
print &xml_quote ($_) . "\n";
}
&print_xml_line ("</comment>");
}
sub convert
{
while (<STDIN>)
{
chomp;
s/^[ \t]+//;
s/[ \\]+$//;
if (/^\#/ || /^$/) { next; }
if (/^StartEntry: *(.*)/)
{
&print_xml_line ("<printerdef id='" . &xml_quote ($1) . "'>");
&xml_enter;
}
elsif (/^EndEntry/)
{
&xml_leave;
&print_xml_line ("</printerdef>\n");
}
elsif (/^GSDriver: *(.*)/)
{
&print_xml_line ("<gsdriver name='" . &xml_quote ($1) . "'/>");
}
elsif (/^Description: *{ *(.*) *}/)
{
&print_xml_line ("<description>" . &xml_quote ($1) . "</description>");
}
elsif (/^About:/)
{
&convert_about ();
}
elsif (/^Resolu?tion: *\{ *([a-zA-Z0-9]+) *\} *\{ *([a-zA-Z0-9]+) *\}/)
{
&print_xml_line ("<resolution x='" . &xml_quote ($1) . "' y='" . &xml_quote ($2) . "'/>");
}
elsif (/^BitsPerPixel: *\{ *([^\} ]+) *\} *\{ *([^\}]+)\}/)
{
&print_xml_line ("<mode id='" . &xml_quote ($1) . "'>" . &xml_quote ($2) . "</mode>");
}
else
{
print "\t*** " . $_ . "\n";
}
}
}
&convert ();
|