lib/scripts/yxml
author bulwahn
Wed, 08 Dec 2010 14:25:08 +0100
changeset 41078 051251fde456
parent 35022 c844b93dd147
permissions -rwxr-xr-x
adding more efficient implementations for quantifiers in Enum
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35022
c844b93dd147 modernized perl scripts: prefer standalone executables;
wenzelm
parents: 29145
diff changeset
     1
#!/usr/bin/env perl
26575
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     2
#
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     3
# Author: Makarius
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     4
#
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     5
# yxml.pl - simple XML to YXML converter
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     6
#
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     7
35022
c844b93dd147 modernized perl scripts: prefer standalone executables;
wenzelm
parents: 29145
diff changeset
     8
use warnings;
26575
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
     9
use strict;
35022
c844b93dd147 modernized perl scripts: prefer standalone executables;
wenzelm
parents: 29145
diff changeset
    10
26575
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    11
use XML::Parser;
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    12
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    13
binmode(STDOUT, ":utf8");
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    14
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    15
sub handle_start {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    16
  print chr(5), chr(6), $_[1];
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    17
  for (my $i = 2; $i <= $#_; $i++) {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    18
    print ($i % 2 == 0 ? chr(6) : "=");
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    19
    print $_[$i];
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    20
  }
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    21
  print chr(5);
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    22
}
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    23
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    24
sub handle_end {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    25
  print chr(5), chr(6), chr(5);
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    26
}
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    27
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    28
sub handle_char {
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    29
  print $_[1];
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    30
}
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    31
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    32
my $parser = new XML::Parser(Handlers =>
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    33
  {Start => \&handle_start,
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    34
    End => \&handle_end,
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    35
    Char => \&handle_char});
042617a1c86c support for YXML notation -- XML done right;
wenzelm
parents:
diff changeset
    36
26593
8375332b3c96 minimal error handling;
wenzelm
parents: 26575
diff changeset
    37
$parser->parse(*STDIN) or die $!;