X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=appendix-a6.git;a=blobdiff_plain;f=parse;h=90f46fe82a97a04e8c81e6ed2a487dde9163064e;hp=a7c6bc0b0f01e068df15becb8a81f04d7818bceb;hb=44e12e2814ebcedfdfe83ce373f719fbd695d069;hpb=6a76222ef4bb2d1223d99389577bf18dbd17aa6c diff --git a/parse b/parse index a7c6bc0..90f46fe 100755 --- a/parse +++ b/parse @@ -11,11 +11,13 @@ binmode STDERR, 'encoding(UTF-8)' or die; our @choices; our %choices; our @invotes; +our $defcho; sub addchoice { - my $cho = shift @_; - $choices{$cho} = { @_, Index => (scalar @choices) }; - push @choices, $cho; + my $choname = shift @_; + my $cho = $choices{$choname} = { @_, Index => (scalar @choices) }; + push @choices, $choname; + return $cho; } while (<>) { @@ -23,12 +25,13 @@ while (<>) { next if m/^\s*\#/; next unless m/\S/; if (m/^([A-Z]+)\s*\=\s*(\S.*)$/) { - my ($cho, $desc) = ($1,$2); - my $smaj; + my ($choname, $desc) = ($1,$2); + my $cho = addchoice($choname, Desc => $desc); if ($desc =~ m/\[(\d+):(\d+)\]/) { - $smaj = [$1,$2]; - } - addchoice($cho, Desc => $desc, Smaj => $smaj); + $cho->{Smaj} = [$1,$2]; + } elsif ($desc =~ m/\[default\]/) { + $defcho = $cho; + } } elsif (m/^V:\s+(\S+)\s+(\S.*)/) { push @invotes, [ $1, $2 ]; } else { @@ -36,13 +39,12 @@ while (<>) { } } -if (!$choices{FD}) { - addchoice('FD', Desc => "Further Discussion"); +$defcho ||= $choices{FD}; +if (!$defcho) { + $defcho = addchoice('FD', Desc => "Further Discussion"); } - -our $chofd = $choices{FD}; - -die "FD has smaj?!" if $chofd->{Smaj}; +my $defi = $defcho->{Index}; +die "FD has smaj?!" if $defcho->{Smaj}; our @vab; # $vab[$ia][$ib] = V(A,B) @@ -62,16 +64,16 @@ foreach my $iv (@invotes) { } } foreach my $ia (0..$#vs) { - foreach my $ib (0..$#vs) { + foreach my $ib ($ia+1..$#vs) { my $va = $vs[$ia]; my $vb = $vs[$ib]; if ($va < $vb) { $vab[$ia][$ib]++; } elsif ($vb < $va) { $vab[$ib][$ia]++; } } } - } + }; die "voter $voter $@" if $@; } -print p %choices; -print p @vab; +p %choices; +p @vab;