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.
11 our ($opt_h, $opt_m) = (0, 0);
19 Syntax: gpsfold [options]
24 -m Add a "# move" after the fold.
33 defined($ARGV[0]) && ($Title = join(" ", @ARGV));
34 my $colon_str = (length($Title) ?
": " : "");
37 my ($start_date, $end_date) = ("", "");
39 while ($Line = <STDIN
>) {
41 unless (length($start_date)) {
42 if ($Line =~ /^(?:# )?(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(Z?)\t/) {
43 $start_date = "$1$2${3}T$4$5$6$7";
44 } elsif ($Line =~ /^(?:# )?(\d\d\d\d\d\d\d\dT\d\d\d\d\d\dZ?)\t/) {
46 } elsif ($Line =~ /^(?:# )?1 (\S+) (\S+) (\S+) (\S+) (\d\d)\/(\d\d
)\
/(\d\d\d\d) (\d\d):(\d\d):(\d\d)/) {
47 $start_date = "$7$5${6}T$8$9$10";
50 if ($Line =~ /^(?:# )?(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)(Z?)\t/) {
51 $end_date = "$1$2${3}T$4$5$6$7";
52 } elsif ($Line =~ /^(?:# )?(\d\d\d\d\d\d\d\dT\d\d\d\d\d\dZ?)\t/) {
54 } elsif ($Line =~ /^(?:# )?1 (\S+) (\S+) (\S+) (\S+) (\d\d)\/(\d\d
)\
/(\d\d\d\d) (\d\d):(\d\d):(\d\d)/) {
55 $end_date = "$7$5${6}T$8$9$10";
59 push(@Data, "# $start_date-$end_date$colon_str$Title \x7D\x7D\x7D\n");
60 unshift(@Data, "# $start_date-$end_date$colon_str$Title \x7B\x7B\x7B\n");
61 $opt_m && push(@Data, "# move\n");