From 737bc761f157f1d8ac66661d0f14b29d81ce0e63 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 21 Aug 2016 12:35:24 +0100 Subject: [PATCH] normalise: support NORM-OPTIONS Signed-off-by: Ian Jackson --- normalise | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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/^\#/; -- 2.30.2