3 #=======================================================================
5 # File ID: 76c6f804-1463-11de-aecb-000475e441b9
7 # Sorts the X elements in an XML file.
10 # ©opyleft 2009– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of
12 # file for legal stuff.
13 #=======================================================================
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = '0.1.0';
37 Getopt
::Long
::Configure
('bundling');
40 'help|h' => \
$Opt{'help'},
41 'quiet|q+' => \
$Opt{'quiet'},
42 'reverse|r' => \
$Opt{'reverse'},
43 'sort|s=s' => \
$Opt{'sort'},
44 'unique|u' => \
$Opt{'unique'},
45 'verbose|v+' => \
$Opt{'verbose'},
46 'version' => \
$Opt{'version'},
48 ) || die("$progname: Option error. Use -h for help.\n");
50 $Opt{'verbose'} -= $Opt{'quiet'};
51 $Opt{'help'} && usage
(0);
52 if ($Opt{'version'}) {
63 my $sortele = $Opt{'sort'} || die("$progname: -s/--sort not defined\n");
68 while (my $Curr = <>) {
69 if ($Curr =~ /<$sortele\b/) {
71 if ($Curr =~ /<\/$sortele>/) {
73 ?
($dupfree{$buf} = 1)
79 if ($Curr =~ /<\/$sortele>/) {
81 ?
($dupfree{$buf} = 1)
88 ?
reverse sort(keys %dupfree)
89 : sort(keys %dupfree));
107 # Print program version {{{
108 print("$progname $VERSION\n");
114 # Send the help message to stdout {{{
117 if ($Opt{'verbose'}) {
123 Usage: $progname [options] -s X [file [files [...]]]
125 Sorts the X elements in an XML file.
132 Be more quiet. Can be repeated to increase silence.
134 Sort in reverse order.
136 Sort file using element X.
138 Remove duplicated elements X.
140 Increase level of verbosity. Can be repeated.
142 Print version information.
150 # Print a status message to stderr based on verbosity level {{{
151 my ($verbose_level, $Txt) = @_;
153 if ($Opt{'verbose'} >= $verbose_level) {
154 print(STDERR
"$progname: $Txt\n");
162 # This program is free software; you can redistribute it and/or modify
163 # it under the terms of the GNU General Public License as published by
164 # the Free Software Foundation; either version 2 of the License, or (at
165 # your option) any later version.
167 # This program is distributed in the hope that it will be useful, but
168 # WITHOUT ANY WARRANTY; without even the implied warranty of
169 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
170 # See the GNU General Public License for more details.
172 # You should have received a copy of the GNU General Public License
173 # along with this program.
174 # If not, see L<http://www.gnu.org/licenses/>.
176 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :