X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=normalise;h=9703a3a96cdd22247e3d0c637bafb8feebae5779;hb=440eafd9205a4cbee5ab4ee0b0cf9c4e41b25bf1;hp=df9e46763b3918bab064a9002538478dfc3f02f5;hpb=622789750886b5b2e39f2fadf7efe3c962ead67e;p=appendix-a6.git diff --git a/normalise b/normalise index df9e467..9703a3a 100755 --- 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/^\#/;