chiark / gitweb /
New format: README.format and normalise, wip. Before restrict CAND and VOTERNAME...
[appendix-a6.git] / normalise
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 our @options, @candiates, @voters;
6
7 our %seen_cand, %need_cand;
8
9 my $candvoter_re = '[^\000-\037!"#$%()*+,/0-\136`-\177]+';
10
11 sub normalise_opts ($) {
12     my ($os) = @_;
13     my @o;
14     foreach my $o (split /\s+/, $os) {
15         if ($o =~ m/^\w+$/) {
16             push @o, $&;
17         } elsif ($o =~ m/^\w+\=\S+$/) {
18             push @o, $&;S
19         } elseif ($o !~ m/\S/) {
20         } else {
21             badinput "bad option \`$o'";
22         }
23     }
24     return @o ? " | @o" : "";
25 }
26
27 while (<>) {
28     next unless m/\S/;
29     next if m/^\#/;
30     s/^\s+//;
31     s/\s+$//;
32     if (m/^\|\s*(\w+(?:\=\S+)?)$/) {
33         push @options, "| $1";
34     } elsif (m/^($candvoter_re?)\s*=\s*([^|]+?)\s*|(.*)?$/) {
35         my ($cand,$desc,$opts) = ($1,$2,$3);
36         $desc=$cand unless length $desc;
37         $opts = normalise_opts $opts;
38         push @candidates, "$cand = $desc".$opts;
39     } elsif (m/^($candvoter_re?)?\s*\:/) {
40