Explanation

The following mark scheme is meant to be interpreted via bash, as is done optionally in BitterSuite. It also contains directives that are intended to be expanded via nroff.

Example

 #!/bin/bash
$(

domath () {
   # Restrict to two trailing decimal points for the floating point value,
   # then chop off trailing zeroes, then chop off a trailing decimal point.
   # Note: because of truncation, do not accumulate domath results.
   echo "scale = 2; $1" | bc | sed -e 's/\(\.[1-9]*\)\(0*\)$/\1/g' | sed 's/\.$//g'
}

q1dr=4
q1tot=$( domath "$t1o + $q1dr" )

q2dr=5
q2tot=$( domath "$t2o + $q2dr" )

alltot=$( domath "$q1dr + $q2dr + $to" )

# The innermost echo allows preservation of space for evaluation later
# by replacing them with hex codes.
# This delayed evaluation is handled by the echo that is echoed by
# 'eval echo'
# There really must be a simpler way to do this...
tempvar=$(eval echo "echo -e \"$(echo "
.ti 5
This is a marking scheme that incorporates both nroff
directives and shell interpretation, including the pre-assignment of variables
that are used internally.  This should help ensure, for example, that course staff
doesn't make any arithmetic errors when creating assignment totals.

.ad c
=========================================

Total Mark Assigned:   _______  / $alltot

Marked By:  ________

=========================================

.ad l
.in 8
.ti -8
Q1: _____ / $q1tot

.ti -4
Design recipe: $(printf "%11s" "_____ / $q1dr")

.ti -4
Autotesting: $(printf "%13s" "$t1e / $t1o")

.ti -8
Q2: _____ / $q2tot

.ti -4
Design recipe: $(printf "%11s" "_____ / $q2dr")

.ti -4
Autotesting: $(printf "%13s" "$t2e / $t2o")
.ti 12
" | sed 's/ /\\x20/g')\"" | perl -ne 'chomp; print "$_\\n";' )

echo $tempvar
)
Topic revision: r1 - 2016-01-11 - YiLee
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback