Rename run-tests.pl to gpst.t, at last
[gpstools.git] / wpt-dupdesc
blob65cae7ea8a08c6bea0e84402a8f8c71642653796
1 #!/usr/bin/env perl
3 #=======================================================================
4 # wpt-dupdesc
5 # File ID: c3b793a4-6225-11e1-bae9-37679d2dbe43
6 # [Description]
8 # Character set: UTF-8
9 # ©opyleft 2012– Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 3 or later, see end of
11 # file for legal stuff.
12 #=======================================================================
14 use strict;
15 use warnings;
16 use Getopt::Long;
18 local $| = 1;
20 our $Debug = 0;
22 our %Opt = (
24 'debug' => 0,
25 'help' => 0,
26 'verbose' => 0,
27 'version' => 0,
31 our $progname = $0;
32 $progname =~ s/^.*\/(.*?)$/$1/;
33 our $VERSION = '0.00';
35 Getopt::Long::Configure('bundling');
36 GetOptions(
38 'debug' => \$Opt{'debug'},
39 'help|h' => \$Opt{'help'},
40 'verbose|v+' => \$Opt{'verbose'},
41 'version' => \$Opt{'version'},
43 ) || die("$progname: Option error. Use -h for help.\n");
45 $Opt{'debug'} && ($Debug = 1);
46 $Opt{'help'} && usage(0);
47 if ($Opt{'version'}) {
48 print_version();
49 exit(0);
52 my $slurp = join('', <>);
54 $slurp =~ s/(<wpt\b.*?<\/wpt>)/process_wpt($1)/gse;
55 print $slurp;
57 sub process_wpt {
58 my $txt = shift;
59 my ($name, $cmt, $desc) = ('', '', '');
60 $txt =~ /<name>(.*?)<\/name>/ && ($name = $1);
61 $txt =~ /<cmt>(.*?)<\/cmt>/ && ($cmt = $1);
62 $txt =~ /<desc>(.*?)<\/desc>/ && ($desc = $1);
63 if ($desc eq $cmt || $desc eq $name) {
64 $txt =~ s/<desc>.*<\/desc>.*?</</s;
66 if ($cmt eq $name) {
67 $txt =~ s/<cmt>.*<\/cmt>.*?</</s;
69 return($txt);
72 sub print_version {
73 # Print program version {{{
74 print("$progname v$VERSION\n");
75 return;
76 # }}}
77 } # print_version()
79 sub usage {
80 # Send the help message to stdout {{{
81 my $Retval = shift;
83 if ($Opt{'verbose'}) {
84 print("\n");
85 print_version();
87 print(<<"END");
89 Usage: $progname [options] [file [files [...]]]
91 Remove <desc> from <wpt> if it's identical to <cmt> or <name>, and <cmt>
92 if it's identical to <name>.
94 Options:
96 -h, --help
97 Show this help.
98 -v, --verbose
99 Increase level of verbosity. Can be repeated.
100 --version
101 Print version information.
102 --debug
103 Print debugging messages.
106 exit($Retval);
107 # }}}
108 } # usage()
110 sub msg {
111 # Print a status message to stderr based on verbosity level {{{
112 my ($verbose_level, $Txt) = @_;
114 if ($Opt{'verbose'} >= $verbose_level) {
115 print(STDERR "$progname: $Txt\n");
117 return;
118 # }}}
119 } # msg()
121 sub D {
122 # Print a debugging message {{{
123 $Debug || return;
124 my @call_info = caller;
125 chomp(my $Txt = shift);
126 my $File = $call_info[1];
127 $File =~ s#\\#/#g;
128 $File =~ s#^.*/(.*?)$#$1#;
129 print(STDERR "$File:$call_info[2] $$ $Txt\n");
130 return('');
131 # }}}
132 } # D()
134 __END__
136 # Plain Old Documentation (POD) {{{
138 =pod
140 =head1 NAME
144 =head1 SYNOPSIS
146 [options] [file [files [...]]]
148 =head1 DESCRIPTION
152 =head1 OPTIONS
154 =over 4
156 =item B<-h>, B<--help>
158 Print a brief help summary.
160 =item B<-v>, B<--verbose>
162 Increase level of verbosity. Can be repeated.
164 =item B<--version>
166 Print version information.
168 =item B<--debug>
170 Print debugging messages.
172 =back
174 =head1 BUGS
178 =head1 AUTHOR
180 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
182 =head1 COPYRIGHT
184 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
185 This is free software; see the file F<COPYING> for legalese stuff.
187 =head1 LICENCE
189 This program is free software: you can redistribute it and/or modify it
190 under the terms of the GNU General Public License as published by the
191 Free Software Foundation, either version 3 of the License, or (at your
192 option) any later version.
194 This program is distributed in the hope that it will be useful, but
195 WITHOUT ANY WARRANTY; without even the implied warranty of
196 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
197 See the GNU General Public License for more details.
199 You should have received a copy of the GNU General Public License along
200 with this program.
201 If not, see L<http://www.gnu.org/licenses/>.
203 =head1 SEE ALSO
205 =cut
207 # }}}
209 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :