From 244b61d5f12466c603e6f929ba2a73152ab829ae Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sat, 8 Aug 2009 20:06:49 +0200 Subject: Skip content tied to skipped keys and delays. --- localmarkdown2sms | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'localmarkdown2sms') diff --git a/localmarkdown2sms b/localmarkdown2sms index 100ef52..704304e 100755 --- a/localmarkdown2sms +++ b/localmarkdown2sms @@ -37,7 +37,7 @@ my (%delay, %reply); my ($path) = shift @ARGV; foreach my $file (read_dir( $path )) { - my ($key, $i); + my ($key, $i, $skipkey, $skipcontent); # suppress repeated warnings for same issue my ($warn_nonkey_delay, $warn_nonkey_content); next unless ($file =~ /\.mdwn$/); @@ -56,6 +56,8 @@ foreach my $file (read_dir( $path )) { if ($level == 1 and $content =~ /(\w+)/) { $key = lc($1); $i = 0; + $skipkey = undef; + $skipcontent = undef; if (lc($content) ne $key) { print STDERR "key \"$key\" extracted from fuzzy string \"$content\" in file \"$file\"\n"; } @@ -66,9 +68,12 @@ foreach my $file (read_dir( $path )) { } else { print STDERR "skipping non-unique key \"$key\" in file \"$file\"\n"; $key = undef; + $skipkey = 1; + $skipcontent = 1; } # delay } elsif ($level == 2 and $content =~ /((\d+[sm](\s+|\Z))+)/) { + $skipcontent = undef; if (defined( $key)) { my $delay = parse_duration($1); if (defined($reply{$key}[$i])) { @@ -79,15 +84,19 @@ foreach my $file (read_dir( $path )) { if ($content ne $1) { print STDERR "delay (${delay}s) resolved from fuzzy string \"$content\" in file \"$file\"\n"; } + } elsif ($skipkey) { + # skipping - already warned about it... } else { print STDERR "ignoring non-key'ed delay line \"$1\" in file \"$file\"\n" unless ($warn_nonkey_delay); $warn_nonkey_delay = 1; + $skipcontent = 1; } } else { print STDERR "ignoring non-parsable headline \"$line\" in file \"$file\"\n"; + $skipcontent = 1; } # reply - } elsif ( defined( $key )) { + } elsif ( defined( $key ) and not ($skipcontent)) { $content = $reply{$key}[$i] if (defined($reply{$key}[$i])); $content .= $line . "\n"; $content =~ s/^\h*$//g; # clean virtually empty lines @@ -96,6 +105,8 @@ foreach my $file (read_dir( $path )) { $content =~ s/(\S)\n([^\n])/$1 $2/g; # convert newline to space $content =~ s/\h*$//g; # strip all trailing spaces $reply{$key}[$i] = $content; + } elsif ($skipkey or $skipcontent) { + # skipping - already warned about it... } else { print STDERR "skipping non-key'ed content \"$line\" in file \"$file\"\n" unless ($warn_nonkey_content); $warn_nonkey_content = 1; -- cgit v1.2.3