* /trunk/src/gpstools/poisync
[gpstools.git] / gpsfold
blob82613fe5527c21f4f509cc9430370401df6f5816
1 #!/usr/bin/perl -w
3 # $Id$
4 # Inserts fold marks in GPS data files before and after stdin.
5 # Select text in visual line mode and filter the block through this script.
7 use strict;
9 use Getopt::Std;
10 our ($opt_h, $opt_m) = (0, 0);
11 getopts('hm');
13 $| = 1;
15 if ($opt_h) {
16 print(<<END);
18 Syntax: gpsfold [options]
20 Options:
22 -h Help me, please
23 -m Add a "# move" after the fold.
25 END
26 exit(0);
29 my $Title = "";
30 my @Data = ();
32 defined($ARGV[0]) && ($Title = join(" ", @ARGV));
33 my $colon_str = (length($Title) ? ": " : "");
35 my $Line = "";
36 my ($start_date, $end_date) = ("", "");
38 while ($Line = <STDIN>) {
39 push(@Data, $Line);
40 unless (length($start_date)) {
41 if ($Line =~ /^(?:# )?(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(Z?)\t/) {
42 $start_date = "$1$2${3}T$4$5$6$7";
43 } elsif ($Line =~ /^(?:# )?(\d\d\d\d\d\d\d\dT\d\d\d\d\d\dZ?)\t/) {
44 $start_date = $1;
45 } elsif ($Line =~ /^(?:# )?1 (\S+) (\S+) (\S+) (\S+) (\d\d)\/(\d\d)\/(\d\d\d\d) (\d\d):(\d\d):(\d\d)/) {
46 $start_date = "$7$5${6}T$8$9$10";
49 if ($Line =~ /^(?:# )?(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(Z?)\t/) {
50 $end_date = "$1$2${3}T$4$5$6$7";
51 } elsif ($Line =~ /^(?:# )?(\d\d\d\d\d\d\d\dT\d\d\d\d\d\dZ?)\t/) {
52 $end_date = $1;
53 } elsif ($Line =~ /^(?:# )?1 (\S+) (\S+) (\S+) (\S+) (\d\d)\/(\d\d)\/(\d\d\d\d) (\d\d):(\d\d):(\d\d)/) {
54 $end_date = "$7$5${6}T$8$9$10";
58 push(@Data, "# $start_date-$end_date$colon_str$Title \x7D\x7D\x7D\n");
59 unshift(@Data, "# $start_date-$end_date$colon_str$Title \x7B\x7B\x7B\n");
60 $opt_m && push(@Data, "# move\n");
62 for (@Data) {
63 print $_;
66 # End of file $Id$