From 91618bae83e86dceab53e5a9a51368437b5bc3ea Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 24 Jan 2005 15:31:48 +0000 Subject: [PATCH] Cleanup before trying to merge signal code. --- Makefile | 8 +- README | 16 ++- morse.c | 70 +++++++----- morse.xml | 330 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 385 insertions(+), 39 deletions(-) create mode 100644 morse.xml diff --git a/Makefile b/Makefile index 8eb9ec6..6a17305 100644 --- a/Makefile +++ b/Makefile @@ -34,8 +34,6 @@ DEVICE = OSS # For alternate random number generator, add either -DUSELRAND for lrand48(), # or -DUSERAND for (ugh) rand(). Default is -DUSERANDOM for random(). # -# Define SIGRET to be your signal handler return type if not "void". -# # Define BSDSIGS or POSIXSIGS, depending on what kind of signals you # have. "Old-style" signals are not currently supported. Default is BSDSIGS. # @@ -134,6 +132,9 @@ clean: rm -f *.o morse QSO morseSun morseHP morseX11 morseIndigo morseLinux morseAdLib morseOSS cd qso; make clean +pristine: clean + rm -f morse.1 QSO.1 + morse.o: beep.h Makefile beepSun.o: beep.h beepHP.o: beep.h alarm.h @@ -143,3 +144,6 @@ beepLinux.o: beep.h alarm.h beepAdLib.o: beep.h alarm.h beepOSS.o: beep.h alarm.o: alarm.h + +morse.1: morse.xml + xmlto man morse.xml diff --git a/README b/README index fc3f1e2..70b499c 100644 --- a/README +++ b/README @@ -10,7 +10,8 @@ Currently supported devices: Linux: The IBM PC console speaker. AdLib: AdLib/SoundBlaster FM chip. (See comments in beepAdLib.c about caveats and limitations.) - OSS: Open Sound System /dev/dsp device. + OSS: Open Sound System /dev/dsp device. Also works with the newer + ALSA Linux sound system. Adding a new device is as simple as creating a new implementation of the beep.h interface. See beep*.[ch] for examples and documentation. @@ -34,7 +35,7 @@ A modified version of the program "QSO" by Paul J. Drongowski is also included. L .-.. Y -.-- + .-.-. M -- Z --.. = -...- -The following characters are included if one defines ALLPUNCTUATION : +The following characters are included if one uses the -B option: ) -.--.- " .-..-. _ ..--.- ' .----. : ---... ; -.-.-. $ ...-..- ! -.-.-- @@ -52,14 +53,14 @@ R all received OK "%" end of contact (sent before call) ("...-.-", known also as ) The following Procedural Signals (Prosigns) are included if one -defines ALLPROSIGNS : +uses the -S option: "^" new line (".-.-", the same as :a, ae) "#" invite receiving station to transmit ("-...-.-") "&" attention ("-.-.-") "@" understood ("...-.") -The following characters are included if one defines ALLINTERNATIONAL : +The following characters are included if one uses the -A option: :a .-.- (also for ae, the same as ) `a .--.- (also oa, danish a with ring over it) @@ -95,6 +96,9 @@ Written by: jdellinger@trc.amoco.com joe@soest.hawaii.edu -This version dated: - Wed Jan 17 09:43:16 CET 2001 +Since January 2005, maintained by: + Eric S. Raymond + * Turned the old compile-time options for expanding the test set into + runtime options -A, -B, -S, -X, -x. + * Updated all code to use ANSI prototypes. diff --git a/morse.c b/morse.c index 1a66396..7962b41 100644 --- a/morse.c +++ b/morse.c @@ -52,6 +52,15 @@ * One should rewrite the openterminal function to provide the * enter_standout_mode "smso/so" and exit_standout_mode "rmso/se" * terminfo/termcap terminal string capabilities. + * + * Eric S. Raymond January 2005. + * Dusted it off, cleaned it up to modern C standards. + * Changed ALLINTERNATIONAL to runtime -A option. + * Changed ALLPROSIGNS to runtime -S option. + * Changed ALLPUNCTUATION to runtime -B option. + * Changed ERROR_FREQUENCY to runtime -x option. + * Changed ERROR_VOLUME to runtime -X option. + * Wrote the manual page. */ /* @@ -1862,9 +1871,8 @@ openterminal (void) termopen = 1; } -int -readterminal (string) - char **string; +static int +readterminal (char **string) { /* This must be declared static! */ static char line[TESTBUFSZ]; @@ -1890,7 +1898,7 @@ int n; } static void -closeterminal () +closeterminal (void) { #ifdef USG ioctl (termfd, TCSETAW, &oldtermgtty); @@ -1901,14 +1909,14 @@ closeterminal () } static void -die () +die (void) { cleanup (); exit (1); } static void -cleanup () +cleanup (void) { if (termopen) closeterminal (); @@ -1916,7 +1924,7 @@ cleanup () } static void -suspend () +suspend (int sig) { signal (SIGTSTP, suspend); cleanup (); @@ -1935,7 +1943,6 @@ randomletter (void) int ii; int sum, sum2; long ranspot; -extern time_t time (); static int lasttime = -1; static long norepeat; @@ -1991,13 +1998,31 @@ static long norepeat; return ii; } -void -report () +static int +rancomp (const void *elem1, const void *elem2) { -int ii, jj, count; -float sum; -int randomstr[TWOFIFTYSIX]; -extern int rancomp (); + register int *e1 = (int *)elem1; + register int *e2 = (int *)elem2; + float a, b; + + + a = (randomfactor[(*e1)] + (randomripe[(*e1)] / (float) RIPECOUNT)); + b = (randomfactor[(*e2)] + (randomripe[(*e2)] / (float) RIPECOUNT)); + + if (a == b) + return 0; + else if (a > b) + return -1; + else + return 1; +} + +static void +report (void) +{ + int ii, jj, count; + float sum; + int randomstr[TWOFIFTYSIX]; printf ("\nCurrent words per minute: %.1f\n", words_per_minute); @@ -2060,20 +2085,3 @@ extern int rancomp (); fflush (stdout); } - -int -rancomp (elem1, elem2) - int *elem1, *elem2; -{ -float a, b; - - a = (randomfactor[(*elem1)] + (randomripe[(*elem1)] / (float) RIPECOUNT)); - b = (randomfactor[(*elem2)] + (randomripe[(*elem2)] / (float) RIPECOUNT)); - - if (a == b) - return 0; - else if (a > b) - return -1; - else - return 1; -} diff --git a/morse.xml b/morse.xml new file mode 100644 index 0000000..6046534 --- /dev/null +++ b/morse.xml @@ -0,0 +1,330 @@ + + + + +morse +1 +January 2005 + + +morse +QSO +Morse-code trainer and QSO generator for aspiring radio hams + + + + + morse + -i + -I + -r + -n num + -R num + -N num + -C charset + -w num + -f num + -v num + -g num + -f num + -e + -c + -b + -a + -l + -m + -t + -T + -s + -q + -p num + -E num + -M num + -d + -A + -B + -S + -x num + -X num + word + + + + +DESCRIPTION + +The morse program is a Morse-code trainer +intended to help aspiring radio hams pass the 5-word-per-minute +Element 1 test. It can take test text from a text file on standard +input, or test words from its command-line arguments, or generate +random text (-r) or play back what you type (-i). + +A helper program, QSO, generates plausible +QSOs that can be fed to the standard input of morse. + +The following options control the behavior of +morse: + + + +-i + + Play what you type. + + + +-I + + Like -i but don't turn off keyboard echoing. + + + +-r + + Generate random text. Starts out slanted towards easy + letters, then slants towards ones you get wrong. + + + +-n NUM + + Make words (groups) NUM characters long. + Valid values are between 1 and 20. + + + +-R NUM + + Set the total time (in minutes) to generate text. + + + +-N NUM (default 0 means unlimited) + + Set the total number of words (groups) to generate. + + + +-C 'STRING' (default all available characters) + + Select characters to send from this STRING only. + + + +-w + + words_per_minute + + + +-f + + frequency_in_hertz + + + +-v + + volume (zero to one, rather nonlinear) + + + +-g + + alternate_frequency (toggles via control-G in input FILE + at a word break) + + + +-F + + Farnsworth_character_words_per_minute + + + +-e + + leave off the <SK> sound at the end + + + +-c + + complain about illegal characters instead of just ignoring + them + + + +-b + + print each word before doing it + + + +-a + + print each word after doing it + + + +-l + + print each letter just before doing it + + + +-m + + print morse dots and dashes as they sound + (this printing-intensive option slows the wpm down!) + + + +-t + + Type along with the morse, but don't see what + you're typing (unless you make a mistake). + You are allowed to get ahead as much as you want. + If you get too far behind it will stop and resync with you. + You can force it to resync at the next word end by hitting + control-H. + Hit ESC to see how you are doing, control-D to end. + (The rightmost space in the printout marks where the average is. + Farther left spaces separate off blocks of letters that are + about twice as probable as the average to occur, three times, etc.) + + + +-T + + Like -t but see your characters (after they are played). + + + +-s + + Stop after each character and make sure you get it + right. (implies -t) + + + +-q + + Quietly resyncs with your input (after you make a + mistake). + + + +-p NUM + + Make you get it right NUM times, for penance. (implies -s). + + + +-E NUM + + If your count of wrong answers minus right answers for a + given character exceeds this, the program will start prompting + you. If above the maximum error prompt it will never + prompt (implies -t). + + + +-M NUM + + If you get more than this number of characters behind, pause until you + do your next letter. 1 behind is normal, 0 behind means never pause. + This option mplies -t. + + + +-d + + Dynamically speed up or slow down depending on how you are doing. + (if also-s, then -d only speeds up!) + + + +-A + + Add ISO 8859-1 (Latin-1) signs to test set. + + + +-B + + Add uncommon punctuation to test set. + + + +-S + + Add uncommon prosigns to test set. + + + +-X + + Set error volume. Error volume 0 means use console + speaker. + + + +-x + + Set frequency of error tone. + + + + +For the raw beginner trying to learn morse code, we recommend +the following sequence: + + + +Start learning the alphabet: + +morse -r -s -T -d -w 5 -F 15 -p 5 -E -10 + + + +Then drill drill drill: + +morse -r -s -T -d -w 5 -F 15 -p 5 -E 0 + + + +Real-time drill, with hints if you really need it: + +morse -r -T -d -w 5 -F 15 -M 2 -E 4 + + + +Simulated test: + +QSO | morse -e -T -d -w 5 -F 15 + + + +The dreaded random-letter test: + +morse -r -T -d -w 5 -F 15 + + + +Finally try for greater and greater speed: + +morse -r -T -d -w 13 -F 24 + + + + + +AUTHORS +Joe Dellinger joe@montebello.soest.hawaii.edu. +Updated 2005 by Eric S. Raymond esr@thyrsus.com. +Other contributions by Jacek M. Holeczek and Marc Unangst. + + -- 2.43.0