std.h: Don't use `extern` in function prototypes
[sunny256-utils.git] / xml-to-lisp
blob2bdb185c957234acb1dae8e7d38714233493f2fa
1 #!/usr/bin/env perl
3 #=======================================================================
4 # xml-to-lisp
5 # File ID: e6461d24-5d49-11df-8e5d-90e6ba3022ac
6 # Converts an XML file to Lisp.
7 # Created by Gene Michael Stover (gene at acm.org)
8 # Tweaks by Øyvind A. Holm <sunny@sunbase.org>.
9 #=======================================================================
11 $| = 1;
13 use strict;
14 use warnings;
15 use XML::Parser;
16 use Data::Dumper;
18 my $indent = 0;
20 sub print_indent () {
21 foreach my $i (1 .. $indent) {
22 print " ";
26 ###
27 ### Callback functions.
28 ### "cb" stands for "call back".
29 ###
31 sub cb_start {
32 my $expat = shift;
33 my $element = shift;
34 my @attrval = (@_);
35 print "\n";
36 print_indent;
37 print "((";
38 print $element;
39 foreach my $i (0 .. $#attrval) {
40 if ($i % 2 == 0) {
41 print " (", $attrval[$i];
42 } else {
43 print ' . "', $attrval[$i], '")';
46 print ")";
47 $indent += 2;
50 sub cb_end {
51 my $expat = shift;
52 my $element = shift;
53 $indent -= 2;
54 print ")";
57 sub cb_char {
58 my $expat = shift;
59 my $str = shift;
60 chomp $str;
61 if (length $str > 0) {
62 print " \"";
63 print $str;
64 print '"';
68 ###
69 ### Main
70 ###
72 my $xml = new XML::Parser (Handlers => {Start => \&cb_start,
73 End => \&cb_end,
74 Char => \&cb_char});
75 if ($xml->parse (join "", <>)) {
76 } else {
77 print "error: XML parsefile failed\n";
78 exit 1;
81 ### --- end of file ---