Revert "Merge branch 'use-trunc-rounding' into rounding-fixes"
[gpstools.git] / wpt-line
blob5a02102b01117a3113c131c16bca5d76084eaafc
1 #!/usr/bin/perl
3 #=======================================================================
4 # wpt-line
5 # File ID: c1b91d20-621b-11e1-8d08-23fe5446b5f1
6 # Convert <wpt> or other elements to/from single lines
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 'element' => 'wpt',
26 'help' => 0,
27 'split' => 0,
28 'verbose' => 0,
29 'version' => 0,
33 our $progname = $0;
34 $progname =~ s/^.*\/(.*?)$/$1/;
35 our $VERSION = '0.00';
37 Getopt::Long::Configure('bundling');
38 GetOptions(
40 'debug' => \$Opt{'debug'},
41 'element|e=s' => \$Opt{'element'},
42 'help|h' => \$Opt{'help'},
43 'split|s' => \$Opt{'split'},
44 'verbose|v+' => \$Opt{'verbose'},
45 'version' => \$Opt{'version'},
47 ) || die("$progname: Option error. Use -h for help.\n");
49 $Opt{'debug'} && ($Debug = 1);
50 $Opt{'help'} && usage(0);
51 if ($Opt{'version'}) {
52 print_version();
53 exit(0);
56 my $slurp = join('', <>);
58 if ($Opt{'split'}) {
59 $slurp =~ s/&lf;/\n/gs;
60 } else {
61 $slurp =~ s/(<$Opt{'element'}\b.*?<\/$Opt{'element'}>)/oneline($1)/gse;
64 print $slurp;
66 sub oneline {
67 my $txt = shift;
68 $txt =~ s/\n/&lf;/gs;
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 Convert <wpt> or other elements to/from single lines. For removing
92 duplicates, etc.
94 Options:
96 -e X, --element X
97 Convert lines between element X. Default: 'wpt'.
98 -h, --help
99 Show this help.
100 -s, --split
101 Split oneliners into several lines again.
102 -v, --verbose
103 Increase level of verbosity. Can be repeated.
104 --version
105 Print version information.
106 --debug
107 Print debugging messages.
110 exit($Retval);
111 # }}}
112 } # usage()
114 sub msg {
115 # Print a status message to stderr based on verbosity level {{{
116 my ($verbose_level, $Txt) = @_;
118 if ($Opt{'verbose'} >= $verbose_level) {
119 print(STDERR "$progname: $Txt\n");
121 return;
122 # }}}
123 } # msg()
125 sub D {
126 # Print a debugging message {{{
127 $Debug || return;
128 my @call_info = caller;
129 chomp(my $Txt = shift);
130 my $File = $call_info[1];
131 $File =~ s#\\#/#g;
132 $File =~ s#^.*/(.*?)$#$1#;
133 print(STDERR "$File:$call_info[2] $$ $Txt\n");
134 return('');
135 # }}}
136 } # D()
138 __END__
140 # Plain Old Documentation (POD) {{{
142 =pod
144 =head1 NAME
148 =head1 SYNOPSIS
150 [options] [file [files [...]]]
152 =head1 DESCRIPTION
156 =head1 OPTIONS
158 =over 4
160 =item B<-h>, B<--help>
162 Print a brief help summary.
164 =item B<-v>, B<--verbose>
166 Increase level of verbosity. Can be repeated.
168 =item B<--version>
170 Print version information.
172 =item B<--debug>
174 Print debugging messages.
176 =back
178 =head1 BUGS
182 =head1 AUTHOR
184 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
186 =head1 COPYRIGHT
188 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
189 This is free software; see the file F<COPYING> for legalese stuff.
191 =head1 LICENCE
193 This program is free software: you can redistribute it and/or modify it
194 under the terms of the GNU General Public License as published by the
195 Free Software Foundation, either version 3 of the License, or (at your
196 option) any later version.
198 This program is distributed in the hope that it will be useful, but
199 WITHOUT ANY WARRANTY; without even the implied warranty of
200 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
201 See the GNU General Public License for more details.
203 You should have received a copy of the GNU General Public License along
204 with this program.
205 If not, see L<http://www.gnu.org/licenses/>.
207 =head1 SEE ALSO
209 =cut
211 # }}}
213 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :