chiark / gitweb /
New format: README.format and normalise, wip. Before restrict CAND and VOTERNAME...
[appendix-a6.git] / normalise
diff --git a/normalise b/normalise
new file mode 100755 (executable)
index 0000000..ca5ecf7
--- /dev/null
+++ b/normalise
@@ -0,0 +1,40 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+our @options, @candiates, @voters;
+
+our %seen_cand, %need_cand;
+
+my $candvoter_re = '[^\000-\037!"#$%()*+,/0-\136`-\177]+';
+
+sub normalise_opts ($) {
+    my ($os) = @_;
+    my @o;
+    foreach my $o (split /\s+/, $os) {
+       if ($o =~ m/^\w+$/) {
+           push @o, $&;
+       } elsif ($o =~ m/^\w+\=\S+$/) {
+           push @o, $&;S
+       } elseif ($o !~ m/\S/) {
+       } else {
+           badinput "bad option \`$o'";
+       }
+    }
+    return @o ? " | @o" : "";
+}
+
+while (<>) {
+    next unless m/\S/;
+    next if m/^\#/;
+    s/^\s+//;
+    s/\s+$//;
+    if (m/^\|\s*(\w+(?:\=\S+)?)$/) {
+       push @options, "| $1";
+    } elsif (m/^($candvoter_re?)\s*=\s*([^|]+?)\s*|(.*)?$/) {
+       my ($cand,$desc,$opts) = ($1,$2,$3);
+       $desc=$cand unless length $desc;
+       $opts = normalise_opts $opts;
+       push @candidates, "$cand = $desc".$opts;
+    } elsif (m/^($candvoter_re?)?\s*\:/) {
+