chiark / gitweb /
wip
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 13 Jan 2019 23:48:11 +0000 (23:48 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 13 Jan 2019 23:48:11 +0000 (23:48 +0000)
parse-input-graph

index 8bf53fc8e495bc7a2d45c6e5226feef3fe18b6d0..b6d267c7a531a1668d00d2c8ee24371ea949f453 100755 (executable)
@@ -11,78 +11,82 @@ our %region;
 # $region{NAME}{Adj}[]{Dikes}
 
 sub read_in () {
-    my $ccolour;
-    my $cregion;
+  my $ccolour;
+  my $cregion;
 
-    while (<>) {
-       next if m{^\s*\#};
-       next unless m{\S};
-       s{\s+$}{};
-       chomp or confess;
-       if (m{^\w+}) {
-           $ccolor = $&;
-           next;
-       }
-       if {my ($name, $water) = m{^\t+(\S.*\S)(?: \[(\d+)\])$}) {
-           confess unless defined $ccolour;
-           confess if $region{$name};
-           $region{$name}{Colour} = $ccolour;
-           $region{$name}{Water} = $water;
-           $cregion = $name;
-           next;
-       }
-       if (my ($aref, $adykes) = m{^\t\t(\S.*\S)(?: (\+\+?)$}) {
-           my $adj = { Dykes => length $adykes };
-           if ($aref =~ {\.}) {
-               $aref =~ s{\-}{[^- ]*-};
-               $aref =~ s{\.}{[^- ]* ?};
-               $adj->{Regexp} = $aref;
-           } else {
-               $adj->{Name} = $aref;
-           }
-           push @{ $region{$cregion}{Adj} }, $adj;
-           next;
-       }
-       confess "$_ ?";
+  while (<>) {
+    next if m{^\s*\#};
+    next unless m{\S};
+    s{\s+$}{};
+    chomp or confess;
+    if (m{^\w+}) {
+      $ccolour = $&;
+      next;
     }
+    if (my ($name, $water) = m{^\t+(\S.*\S)(?: \[(\d+)\])$}) {
+      confess unless defined $ccolour;
+      confess if $region{$name};
+      $region{$name}{Colour} = $ccolour;
+      $region{$name}{Water} = $water;
+      $cregion = $name;
+      next;
+    }
+    if (my ($aref, $adykes) = m{^\t\t(\S.*\S)(?: (\+\+?))$}) {
+      my $adj = { Dykes => length $adykes };
+      if ($aref =~ {\.}) {
+       $aref =~ s{\-}{[^- ]*-};
+       $aref =~ s{\.}{[^- ]* ?};
+       $adj->{Regexp} = $aref;
+      } else {
+       $adj->{Name} = $aref;
+      }
+      push @{ $region{$cregion}{Adj} }, $adj;
+      next;
+    }
+    confess "$_ ?";
+  }
 }
 
 sub unique_aref ($$) {
-    my ($ra, $adja) = @_;
-    my $re = $adj->{Regexp};
-    return $adj->{Name} unless defined $re;
-    my @found;
-    foreach my $rb (sort keys %region) {
-       next unless $rb =~ m{^$re$};
-       foreach my $adjb (@{ $region{rb}{Adj} }) {
-           my $adjbn = $adjb->{Name};
-           next unless defined $adjbn;
-           next unless $adjbn eq $ra;
-       }
+  my ($ra, $adja) = @_;
+  my $re = $adj->{Regexp};
+  return $adj->{Name} unless defined $re;
+  my @found;
+  foreach my $rb (sort keys %region) {
+    next unless $rb =~ m{^$re$};
+    foreach my $adjb (@{ $region{rb}{Adj} }) {
+      my $adjbn = $adjb->{Name};
+      next unless defined $adjbn;
+      next unless $adjbn eq $ra;
     }
-    confess "$ra $re @found ?" unless @found==1;
-    print "resolve $ra -> $re  as @found\n";
-    return $found[1];
+  }
+  confess "$ra $re @found ?" unless @found==1;
+  print "resolve $ra -> $re  as @found\n";
+  return $found[1];
 }   
 
 sub resolve_arefs () {
-    foreach my $ra (sort keys $region) {
-       foreach my $adj (@{ $region{$ra}{Adj} }) {
-           next if defined $adj->{Name};
-           $adj->{ProspectiveName} = unique_aref $ra, $adj;
-       }
+  foreach my $ra (sort keys $region) {
+    foreach my $adj (@{ $region{$ra}{Adj} }) {
+      next if defined $adj->{Name};
+      $adj->{ProspectiveName} = unique_aref $ra, $adj;
     }
-    foreach my $ra (sort keys $region) {
-       foreach my $adj (@{ $region{$ra}{Adj} }) {
-           $adj->{Name} //= $adj->{ProspectiveName};
-       }
+  }
+  foreach my $ra (sort keys $region) {
+    foreach my $adj (@{ $region{$ra}{Adj} }) {
+      $adj->{Name} //= $adj->{ProspectiveName};
     }
-    foreach my $ra (sort keys $region) {
-       foreach my $adj (@{ $region{$ra}{Adj} }) {
-           confess unless $adj->{Name} eq unique_aref $ra, $adj;
-       }
+  }
+  foreach my $ra (sort keys $region) {
+    foreach my $adj (@{ $region{$ra}{Adj} }) {
+      confess unless $adj->{Name} eq unique_aref $ra, $adj;
     }
+  }
 }
 
 read_in();
 resolve_arefs();
+
+# Local variables:
+# cperl-indent-level: 2
+# End.