gpst: %Cmd: Remove it, unused
[gpstools.git] / plass
blob4bd415271981c734ecce2745be26aca9037f5854
1 #!/usr/bin/perl
3 #=======================================================================
4 # plass
5 # File ID: 8e329af6-42a0-11e2-bef5-fefdb24f8e10
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 exit(main(%Opt));
54 sub main {
55 # {{{
56 my %Opt = @_;
57 my $Retval = 0;
58 defined($ARGV[0]) || (warn("$progname: Name not specified\n"), return 1);
59 my $name = $ARGV[0];
60 my $dist = defined($ARGV[1]) ? $ARGV[1] : '0.00050';
61 msg(0, "name = '$name'");
62 msg(0, "dist = '$dist'");
64 system(sprintf("psql gps -c \"%s\" | less", <<END));
65 SELECT id, date, coor, name, dist
66 FROM logg
67 WHERE (
68 SELECT coor
69 FROM wayp
70 WHERE name LIKE '$name'
71 LIMIT 1
72 )::point <-> coor <= $dist
73 ORDER BY id;
74 END
76 return($Retval);
77 # }}}
78 } # main()
80 sub print_version {
81 # Print program version {{{
82 print("$progname v$VERSION\n");
83 return;
84 # }}}
85 } # print_version()
87 sub usage {
88 # Send the help message to stdout {{{
89 my $Retval = shift;
91 if ($Opt{'verbose'}) {
92 print("\n");
93 print_version();
95 print(<<"END");
97 Usage: $progname [options] name [dist]
99 Options:
101 -h, --help
102 Show this help.
103 -v, --verbose
104 Increase level of verbosity. Can be repeated.
105 --version
106 Print version information.
107 --debug
108 Print debugging messages.
111 exit($Retval);
112 # }}}
113 } # usage()
115 sub msg {
116 # Print a status message to stderr based on verbosity level {{{
117 my ($verbose_level, $Txt) = @_;
119 if ($Opt{'verbose'} >= $verbose_level) {
120 print(STDERR "$progname: $Txt\n");
122 return;
123 # }}}
124 } # msg()
126 sub D {
127 # Print a debugging message {{{
128 $Debug || return;
129 my @call_info = caller;
130 chomp(my $Txt = shift);
131 my $File = $call_info[1];
132 $File =~ s#\\#/#g;
133 $File =~ s#^.*/(.*?)$#$1#;
134 print(STDERR "$File:$call_info[2] $$ $Txt\n");
135 return('');
136 # }}}
137 } # D()
139 __END__
141 # Plain Old Documentation (POD) {{{
143 =pod
145 =head1 NAME
149 =head1 SYNOPSIS
151 [options] [file [files [...]]]
153 =head1 DESCRIPTION
157 =head1 OPTIONS
159 =over 4
161 =item B<-h>, B<--help>
163 Print a brief help summary.
165 =item B<-v>, B<--verbose>
167 Increase level of verbosity. Can be repeated.
169 =item B<--version>
171 Print version information.
173 =item B<--debug>
175 Print debugging messages.
177 =back
179 =head1 BUGS
183 =head1 AUTHOR
185 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
187 =head1 COPYRIGHT
189 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
190 This is free software; see the file F<COPYING> for legalese stuff.
192 =head1 LICENCE
194 This program is free software: you can redistribute it and/or modify it
195 under the terms of the GNU General Public License as published by the
196 Free Software Foundation, either version 3 of the License, or (at your
197 option) any later version.
199 This program is distributed in the hope that it will be useful, but
200 WITHOUT ANY WARRANTY; without even the implied warranty of
201 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
202 See the GNU General Public License for more details.
204 You should have received a copy of the GNU General Public License along
205 with this program.
206 If not, see L<http://www.gnu.org/licenses/>.
208 =head1 SEE ALSO
210 =cut
212 # }}}
214 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :