3 #=======================================================================
5 # Add new waypoints or trackpoints to the database.
8 # ©opyleft 2008– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License version 2 or later, see end of
10 # file for legal stuff.
11 #=======================================================================
34 'database' => $Std{'database'},
37 'timezone' => $Std{'timezone'},
38 'type' => $Std{'type'},
46 $progname =~ s/^.*\/(.*?)$/$1/;
49 my $id_date = $rcs_id;
50 $id_date =~ s/^.*?\d+ (\d\d\d\d-.*?\d\d:\d\d:\d\d\S+).*/$1/;
52 push(@main::version_array
, $rcs_id);
54 Getopt
::Long
::Configure
("bundling");
57 "database|D=s" => \
$Opt{'database'},
58 "debug" => \
$Opt{'debug'},
59 "help|h" => \
$Opt{'help'},
60 "timezone|T=s" => \
$Opt{'timezone'},
61 "type|t=s" => \
$Opt{'type'},
62 "verbose|v+" => \
$Opt{'verbose'},
63 "version" => \
$Opt{'version'},
64 "waypoint|w" => \
$Opt{'waypoint'},
66 ) || die("$progname: Option error. Use -h for help.\n");
68 $Opt{'debug'} && ($Debug = 1);
69 $Opt{'help'} && usage
(0);
70 if ($Opt{'version'}) {
76 if (length($Opt{'timezone'})) {
77 if ($Opt{'timezone'} =~ /^[\+\-][0-2][0-9]{3}$/) {
78 $tz_str = $Opt{'timezone'};
79 } elsif ($Opt{'timezone'} =~ /^z$/i) {
80 $tz_str = $Opt{'timezone'};
81 } elsif ($Opt{'timezone'} =~ /^[a-z]+$/i) {
82 $tz_str = " $Opt{'timezone'}";
84 die("$progname: $Opt{'timezone'}: Invalid time zone\n");
88 for my $Currarg (@ARGV) {
89 for my $Currfile (glob($Currarg)) {
90 D
("Currfile = '$Currfile'");
91 if ($Opt{'type'} =~ /picture/) {
92 if ($Currfile =~ /\.jpg$/i) {
93 my $tz_str = length($Opt{'timezone'})
94 ?
"-T $Opt{'timezone'} "
97 "gpst-pic $tz_str$Currfile | psql -c \"COPY pictures (" .
106 ") FROM stdin\" $Opt{'database'}";
107 msg
(1, "Executing '$exec_str'...");
111 if ($Opt{'type'} =~ /track/) {
113 "gpst -o pgtab -d -rpt $Currfile | " .
114 "psql -a -c \"COPY logg (" .
124 ") FROM stdin\" $Opt{'database'}";
125 msg
(1, "Executing '$exec_str'...");
128 if ($Opt{'type'} =~ /waypoint/) {
130 "gpst -o pgwtab $Currfile | " .
131 "psql -a -c \"COPY wayp_new (" .
143 ") FROM stdin\" $Opt{'database'}";
144 msg
(1, "Executing '$exec_str'...");
151 # Print program version {{{
152 for (@main::version_array
) {
159 # Send the help message to stdout {{{
162 if ($Opt{'verbose'}) {
168 Usage: $progname [options] [file [files [...]]]
173 Load into PostgreSQL database X. Default: "$Std{'database'}".
177 Prepend X as timezone to the date. Valid formats:
179 A '+' or '-' followed by a four-digit number (HHMM) which
180 indicates the offset relative to UTC. Examples:
184 Time zone abbreviation. Examples:
189 Comma-separated list of point types to extract from files:
193 Default: "$Std{'type'}".
195 Increase level of verbosity. Can be repeated.
197 Print version information.
199 Print debugging messages.
207 # Print a status message to stderr based on verbosity level {{{
208 my ($verbose_level, $Txt) = @_;
210 if ($Opt{'verbose'} >= $verbose_level) {
211 print(STDERR
"$progname: $Txt\n");
217 # Print a debugging message {{{
219 my @call_info = caller;
220 chomp(my $Txt = shift);
221 my $File = $call_info[1];
223 $File =~ s
#^.*/(.*?)$#$1#;
224 print(STDERR
"$File:$call_info[2] $$ $Txt\n");
231 # Plain Old Documentation (POD) {{{
245 [options] [file [files [...]]]
255 =item B<-h>, B<--help>
257 Print a brief help summary.
259 =item B<-v>, B<--verbose>
261 Increase level of verbosity. Can be repeated.
265 Print version information.
269 Print debugging messages.
279 Made by Øyvind A. Holm S<E<lt>sunny@sunbase.orgE<gt>>.
283 Copyleft © Øyvind A. Holm E<lt>sunny@sunbase.orgE<gt>
284 This is free software; see the file F<COPYING> for legalese stuff.
288 This program is free software; you can redistribute it and/or modify it
289 under the terms of the GNU General Public License as published by the
290 Free Software Foundation; either version 2 of the License, or (at your
291 option) any later version.
293 This program is distributed in the hope that it will be useful, but
294 WITHOUT ANY WARRANTY; without even the implied warranty of
295 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
296 See the GNU General Public License for more details.
298 You should have received a copy of the GNU General Public License along
299 with this program; if not, write to the Free Software Foundation, Inc.,
300 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
308 # vim: set fenc=UTF-8 ft=perl fdm=marker ts=4 sw=4 sts=4 et fo+=w :