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.
10 our ($opt_h, $opt_m) = (0, 0);
18 Syntax: gpsfold [options]
23 -m Add a "# move" after the fold.
32 defined($ARGV[0]) && ($Title = join(" ", @ARGV));
33 my $colon_str = (length($Title) ?
": " : "");
36 my ($start_date, $end_date) = ("", "");
38 while ($Line = <STDIN
>) {
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/) {
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/) {
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");