-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtexi2xml.pl
executable file
·55 lines (46 loc) · 1.48 KB
/
texi2xml.pl
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
#!/usr/bin/perl
# texi2xml: Convert a .texi file into a XML file accessible to itstool
# Copyright (C) {2018} {Gunter Königsmann}
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# SPDX-License-Identifier: GPL-3.0+
print "<?xml version=\"1.0\"?>\n";
print "<!DOCTYPE texifile [\n";
print "<!ELEMENT texifile (paragraph)>\n";
print "<!ELEMENT paragraph (#PCDATA)>\n";
print "]>\n";
print "<texifile>\n";
$lastline = "";
$paragraph = "";
# Read the file line by line
while (my $line = <>) {
# Skip duplicate blank lines
if (($line ne "\n") || ($line ne $lastline))
{
# Is this the last line of a paragraph?
if($line eq "\n")
{
print "<paragraph>";
print $paragraph;
print "</paragraph>\n";
}
else
{
# Excape spacial chars for XML
$line =~ s/&/&/g;
$line =~ s/</</g;
$line =~ s/>/>/g;
$paragraph .= $line;
}
}
$lastline = $line;
}
print "</texifile>\n";