chiark / gitweb /
normalise: support NORM-OPTIONS
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2016 11:35:24 +0000 (12:35 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 21 Aug 2016 11:35:24 +0000 (12:35 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
normalise

index df9e46763b3918bab064a9002538478dfc3f02f5..9703a3a96cdd22247e3d0c637bafb8feebae5779 100755 (executable)
--- a/normalise
+++ b/normalise
@@ -1,4 +1,14 @@
 #!/usr/bin/perl -w
+#
+# usage:
+#  normalise [NORM-OPTIONS...] [--] INPUT-FILES...
+#
+# NORM-OPTIONS are
+#   +OPTNAME[=OPTVAL]           Election option
+#   CAND=[DESCRIPTION]
+#   +CAND+OPTNAME[=OPTVAL]      Candidate option
+#   --                          End of options to normalise
+#   -...                        Reserved for future options to normalise
 
 use strict;
 
@@ -7,6 +17,7 @@ our %candidates; # $candidates{CAND}{Desc}, {Opts}[]
 our @ballots;
 
 my $candvoter_re = '\w+';
+my $opt_re = '\w+(?:=\S*)?';
 
 sub badinput ($) {
     die "bad input: $_[0]";
@@ -45,6 +56,25 @@ sub setcanddesc ($$) {
     }
 }
 
+while (@ARGV) {
+    $_ = shift @ARGV;
+    if (m/^--$/) {
+       last;
+    } elsif (m/^(\w+)=([^|]+)$/) {
+       setcanddesc $1, $2;
+    } elsif (m/^\+($opt_re)$/) {
+       push @options, $1;
+    } elsif (m/^\+(\w+)\+($opt_re)$/) {
+       push @{ $candidates{$1}{Opts} }, $2;
+    } elsif (m/^-/) {
+       die "unknown normalise option \`$_'\n";
+    } else {
+       # oh!
+       unshift @ARGV, $_;
+       last;
+    }
+}
+
 while (<>) {
     next unless m/\S/;
     next if m/^\#/;