summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xbin/scoresheet.pl4
-rwxr-xr-xmkballots.sh55
2 files changed, 44 insertions, 15 deletions
diff --git a/bin/scoresheet.pl b/bin/scoresheet.pl
index 74c7a8a..96620e8 100755
--- a/bin/scoresheet.pl
+++ b/bin/scoresheet.pl
@@ -2,7 +2,7 @@
use Config::Tiny;
-($dir, $idfile) = @ARGV;
+($dir, $paper, $idfile) = @ARGV;
# Convert LaTeX units to mm
%units = (
@@ -88,7 +88,7 @@ if (defined($idfile) && open(IDS, '<', $idfile)) {
@id_list = (''); # One copy with no ID
}
-print "\\documentclass[letterpaper]{article}\n";
+print "\\documentclass[${paper}paper]{article}\n";
print "\\usepackage[utf8]{inputenc}\n";
print "\\usepackage{array}\n";
print "\\usepackage{calc}\n";
diff --git a/mkballots.sh b/mkballots.sh
index bee2836..d7b8b8d 100755
--- a/mkballots.sh
+++ b/mkballots.sh
@@ -2,32 +2,60 @@
export PATH=$(realpath -s $(dirname "$0"))/bin:"$PATH"
if [ -z "$1" -o -z "$2" ]; then
set +x
- echo "Usage: $0 prefix numballots [batches [scoresheets]]" 1>&2
+ echo "Usage: $0 project numballots [batches [scoresheets]]" 1>&2
exit 1
fi
nbatch="${3:-1}"
perbatch="${2:-100}"
scoresheets="${4:-1}"
-prefix="$1"
-proj="${proj:-tab2016}"
-shuf='shuf --random-source=/dev/urandom'
-if [ -z "$proj" ]; then
- proj=tab2016
+proj="${1:-test}"
+declare -A sub
+. "${proj}.conf"
+paper="${paper:-letter}"
+sub[PAPER]="${paper}"
+writeins="${writeins:-2}"
+template="${template:-$proj.tex}"
+if [ ! -f "$template" ]; then
+ set +x
+ echo "$0: template file $template missing!" 1>&2
+ exit 1
fi
+shuf='shuf --random-source=/dev/urandom'
sdaps="sdaps $proj"
rm -rf "$proj"
-sed -e "s:%%CANDIDATES%%:$shuf < '$proj'.cand:e" \
- -e 'T' -e 's/^\(.*\)$/\\choiceline{\1}/mg' \
- "$proj".tex > "$proj".pp.tex
+rm -f "$proj".sub.sed
+for s in "${!sub[@]}"; do
+ echo "s/%%${s//\//\\\/}%%/${sub[$s]//\//\\\/}/g" >> "$proj".sub.sed
+done
+cat >> "$proj".sub.sed <<EOF
+t
+s:%%WRITEINS%%::
+t writeins
+s:%%CANDIDATES%%:$shuf < '$proj'.cand:e
+T
+s/^\\(.*\\)\$/\\\\choiceline{\\1}/mg
+b
+: writeins
+EOF
+# Note: n-1 p commands as sed itself will print one
+for (( x=1 ; x < writeins ; x=x+1 )); do
+ echo 'p' >> "$proj".sub.sed
+done
+sed -f "$proj".sub.sed < "$template" > "$proj".pp.tex
$sdaps setup_tex "$proj".pp.tex
-rm "$proj".pp.tex
+rm "$proj".sub.sed "$proj".pp.tex
+if [ ! -f "$proj"/questionnaire.pdf ]; then
+ set +x
+ echo "$0: project $proj failed to compile!" 1>&2
+ exit 1
+fi
# Produce a tiebreakers file for csvconv.pl so we can reproduce the output
seq 1 $(wc -l < "$proj".cand) | $shuf | tr '\n' ',' | \
sed -e 's/,$/\n/' > "$proj"/tiebreakers.csv
# Generate score sheets (one PDF with blank ID, one with individual numbers)
-scoresheet.pl "$proj" > "$proj"/scoresheet.tex
+scoresheet.pl "$proj" "$paper" > "$proj"/scoresheet.tex
genids.pl "$prefix"/MT $scoresheets 1 > "$proj"/scoresheet.ids
-scoresheet.pl "$proj" "$proj"/scoresheet.ids > "$proj"/scoresheets.tex
+scoresheet.pl "$proj" "$paper" "$proj"/scoresheet.ids > "$proj"/scoresheets.tex
cd "$proj"
pdflatex scoresheet.tex && pdflatex scoresheet.tex
pdfmerge questionnaire.pdf scoresheet.pdf chkalign.pdf
@@ -43,4 +71,5 @@ for (( batch=1 ; batch <= nbatch ; batch++ )); do
start=$((start + perbatch))
done
# Make a backup copy of the project directory
-tar cvvfJ "$proj".sdaps.tar.xz "$proj" "$proj".tex "$proj".cand
+tar cvvfJ "$proj".sdaps.tar.xz "$proj" "$template" \
+ "$proj".cand "$proj".conf mkballots.sh