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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
|
#!/usr/bin/perl
## ----------------------------------------------------------------------
## Debian update-perl-sax-parsers version 0.1
## ----------------------------------------------------------------------
## Copyright (C) 2001 Ardo van Rangelrooij <ardo@debian.org>.
##
## This is free software; see the GNU General Public Licence version 2
## or later for copying conditions. There is NO warranty.
## ----------------------------------------------------------------------
## ----------------------------------------------------------------------
use File::Spec ();
use XML::SAX ();
## ----------------------------------------------------------------------
$0 =~ m|[^/]+$|;
$name = $&;
## ----------------------------------------------------------------------
while ( $ARGV[0] =~ m/^--/ )
{
$_ = shift( @ARGV );
last if $_ eq '--';
if ( $_ eq '--add' )
{
$add = 1;
}
elsif ( $_ eq '--remove' )
{
$remove = 1;
}
elsif ( $_ eq '--update' )
{
$update = 1;
}
elsif ( $_ eq '--quiet' )
{
$quiet = 1;
}
elsif ( $_ eq '--test' )
{
$debug = 1;
}
elsif ( $_ eq '--help' )
{
&usage;
exit 0;
}
elsif ( $_ eq '--version' )
{
&version;
exit 0;
}
else
{
print STDERR "$name: unknown option \`$_'\n";
&usage;
exit 1;
}
}
## ----------------------------------------------------------------------
if ( ( $add || $remove ) && ! @ARGV )
{
print STDERR "$name: too few arguments\n";
exit 1;
}
## ----------------------------------------------------------------------
$parser_module = shift( @ARGV ) if $add || $remove;
## ----------------------------------------------------------------------
if ( @ARGV )
{
print STDERR "$name: too many arguments\n";
exit 1;
}
## ----------------------------------------------------------------------
print STDERR "$name: test mode - Perl SAX parsers file will not be updated\n"
if $debug && ! $quiet;
## ----------------------------------------------------------------------
my $PARSER_DETAILS_DIR = "/etc/XML/SAX/ParserDetails.d";
my $PARSER_DETAILS_FILE = "/etc/XML/SAX/ParserDetails.ini";
## ----------------------------------------------------------------------
if ( $add )
{
print "$name: adding Perl SAX parser module info file of $parser_module...\n"
unless $quiet;
XML::SAX->save_parsers_debian( $parser_module );
}
elsif ( $remove )
{
print "$name: removing Perl SAX parser module info file of $parser_module...\n"
unless $quiet;
my $parser_file = File::Spec->catfile( $PARSER_DETAILS_DIR, $parser_module);
unlink( $parser_file );
}
elsif ( $update )
{
print "$name: updating overall Perl SAX parser modules info file...\n"
unless $quiet;
open( PARSER_DETAILS_FILE, ">$PARSER_DETAILS_FILE" )
|| die "Cannot write to $PARSER_DETAILS_FILE: $!";
opendir( PARSER_DETAILS_DIR, $PARSER_DETAILS_DIR )
|| die "Cannot access $PARSER_DETAILS_DIR: $!";
while ( defined( $parser_details = readdir( PARSER_DETAILS_DIR ) ) )
{
next if $parser_details =~ /^\.\.?$/; # skip . and ..
open( PARSER_DETAILS, "$PARSER_DETAILS_DIR/$parser_details" )
|| die "Cannot read from $parser_details: $!";
while ( <PARSER_DETAILS> ) { print PARSER_DETAILS_FILE; }
close( PARSER_DETAILS );
}
closedir( PARSER_DETAILS_DIR );
close( PARSER_DETAILS_FILE );
}
## ----------------------------------------------------------------------
exit 0;
## ----------------------------------------------------------------------
sub usage
{
print STDERR <<END;
Usage:
$name <options> --add <parser_module>
$name <options> --remove <parser_module>
$name <options> --update
Options:
--quiet be quiet
--test do not modify any files, enables debugging mode
--version display version number
--help display this help text (usage)
END
}
## ----------------------------------------------------------------------
sub version
{
print "Debian $name version 0.1\n";
}
## ----------------------------------------------------------------------
|