From: Ian Jackson Date: Sun, 21 Aug 2016 11:35:24 +0000 (+0100) Subject: normalise: support NORM-OPTIONS X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=commitdiff_plain;h=737bc761f157f1d8ac66661d0f14b29d81ce0e63 normalise: support NORM-OPTIONS Signed-off-by: Ian Jackson --- 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/^\#/;