#!/bin/awk -f #UM> rote (awk) : rote learning program BEGIN { if (ARGV[1] !~ /./) { print " ROTE 2.0 - GPL free software www.benjaminwaters.org 2004" print "__________________________________________________________________________" print " Usage: rote inputfile" print "__________________________________________________________________________" print "-> The Inputfile: rote assumes the input file to be a series of lines\n consisting of a question, then the delimiter `:', then the answer." print "-> Mode 1: typing mode, is selected by typing 1 and then return at\n the prompt. You will now be displayed questions one at a time, and you\n must type the exact answer, followed by a return." print "-> Mode 2: speaking mode, is selected by typing 2 and then return\n at the prompt. You will now be displayed questions one at a time and rote\n will wait for you to type a return before giving you an answer. When you\n have read the answer, you can mark it true by typing another return,\n false by typing any other character and then return." print "-> The Truefile: if you type a filename when prompted for a truefile, rote\n will append correctly answered lines to a file of this name." print "-> The Falsefile: if you type a filename when prompted for a falsefile,\n rote will append incorrectly answered lines to a file of this name." print "__________________________________________________________________________" exit} } BEGIN {FS=":"} # set the delimiter by replacing the : with whatever you want. BEGIN { printf "Enter 1 for typing mode, 2 for speaking mode, 0 to reverse a file (outputs to truefile): " getline mode < "-" if (mode !~ /[0-2]/) { print "Valid modes are 0, 1, or 2" exit} } BEGIN { printf "truefile: " getline truefile < "-" } BEGIN { printf "falsefile: " getline falsefile < "-" } { if (mode ~/0/) {print $2":"$1 >> truefile} else if (mode ~ /1/) { printf $1": " getline answer < "-" ++total if ($2 == answer) { if (truefile ~ /./) { print $1":"$2 >> truefile ++true } else ++true } else { if (falsefile ~ /./) { print $1":"$2 >> falsefile gsub(/./, " ", $1) print $1">", $2} else { gsub(/./, " ", $1) print $1">", $2}} } else { q = $1 a = $2 printf q": " getline < "-" printf a"\n" ++total getline answer < "-" if (answer ~ /^$/) { if (truefile ~ /./) { print q":"a >> truefile ++true } else ++true } else { if (falsefile ~ /./) { print q":"a >> falsefile }} } } END { if (true > 0) print "\n" "TRUE:", true "/" total, "(" true/total*100 "%)" }