From owner-freebsd-bugs Sat Aug 26 23:50:03 1995 Return-Path: bugs-owner Received: (from majordom@localhost) by freefall.FreeBSD.org (8.6.11/8.6.6) id XAA10550 for bugs-outgoing; Sat, 26 Aug 1995 23:50:03 -0700 Received: (from gnats@localhost) by freefall.FreeBSD.org (8.6.11/8.6.6) id XAA10543 ; Sat, 26 Aug 1995 23:50:02 -0700 Resent-Date: Sat, 26 Aug 1995 23:50:02 -0700 Resent-Message-Id: <199508270650.XAA10543@freefall.FreeBSD.org> Resent-From: gnats (GNATS Management) Resent-To: freebsd-bugs Resent-Reply-To: FreeBSD-gnats@freefall.FreeBSD.org, lyndon@orthanc.com Received: from multivac.orthanc.com (multivac.orthanc.com [204.244.20.2]) by freefall.FreeBSD.org (8.6.11/8.6.6) with ESMTP id XAA10345 for ; Sat, 26 Aug 1995 23:40:47 -0700 Received: (from lyndon@localhost) by multivac.orthanc.com (8.7.Beta.10/8.7.Beta.10) id XAA04567; Sat, 26 Aug 1995 23:37:11 -0700 (PDT) Message-Id: <199508270637.XAA04567@multivac.orthanc.com> Date: Sat, 26 Aug 1995 23:37:11 -0700 (PDT) From: lyndon@orthanc.com Reply-To: lyndon@orthanc.com To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/709: morse(6) can't send morse (+FIX) Sender: bugs-owner@freebsd.org Precedence: bulk >Number: 709 >Category: bin >Synopsis: morse(6) can't send morse code >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Class: change-request >Submitter-Id: current-users >Arrival-Date: Sat Aug 26 23:50:01 PDT 1995 >Last-Modified: >Originator: Lyndon Nerenberg >Organization: Orthanc Systems: Internet and UNIX consulting ___________________________________________________________ lyndon@orthanc.com || canada!lyndon || Fax: +1 604 561 2067 For Amateur Radio information visit http://ve7tcp.ampr.org/ >Release: FreeBSD 2.0.5-RELEASE i386 >Environment: >Description: No sane morse operator copies code by writing down dots and dashes. I have radios with speakers, not braille printers :-) >How-To-Repeat: >Fix: The appended shar archive contains a substantially re-written version of the morse command that groks the spkr(4) device. A new option (-p) causes morse to send the real thing on the speaker. Two other options control the sending speed (-w) and sidetone frequency (-f). I also extended the set of characters the program understands. Traditional behaviour is a bit different: when taking text from the command line a space character is inserted between argv arguments a space now prints as a blank line (rather than " ...") text lines no longer end with ',' The man page has been modified to document the new ooptions. Audio support is conditional on the definition of SPEAKER. This shar includes the following files (rooted at /usr/src/games): morse/Makefile makefile with -DSPEAKER=\"/dev/speaker\" morse/morse.c mostly rewritten morse.c bcd/bcd.6 new man page Feel free to roll this into 2.1 if you think it's worth it. I haven't copyrighted any of the changes and consider them to be in the public domain. --lyndon # This is a shell archive. Save it in a file, remove anything before # this line, and then unpack it by entering "sh file". Note, it may # create directories; files and directories will be owned by you and # have default permissions. # # This archive contains: # # morse # bcd # morse/Makefile # morse/morse.c # bcd/bcd.6 # echo c - morse mkdir -p morse > /dev/null 2>&1 echo c - bcd mkdir -p bcd > /dev/null 2>&1 echo x - morse/Makefile sed 's/^X//' >morse/Makefile << 'END-of-morse/Makefile' X# @(#)Makefile 8.1 (Berkeley) 5/31/93 X XPROG= morse XNOMAN= noman XHIDEGAME=hidegame XCFLAGS += -DSPEAKER=\"/dev/speaker\" X X.include X END-of-morse/Makefile echo x - morse/morse.c sed 's/^X//' >morse/morse.c << 'END-of-morse/morse.c' X/* X * Copyright (c) 1988, 1993 The Regents of the University of California. All X * rights reserved. X * X * Redistribution and use in source and binary forms, with or without X * modification, are permitted provided that the following conditions are X * met: 1. Redistributions of source code must retain the above copyright X * notice, this list of conditions and the following disclaimer. 2. X * Redistributions in binary form must reproduce the above copyright notice, X * this list of conditions and the following disclaimer in the documentation X * and/or other materials provided with the distribution. 3. All advertising X * materials mentioning features or use of this software must display the X * following acknowledgement: This product includes software developed by the X * University of California, Berkeley and its contributors. 4. Neither the X * name of the University nor the names of its contributors may be used to X * endorse or promote products derived from this software without specific X * prior written permission. X * X * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY X * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED X * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE X * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR X * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR X * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER X * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X * SUCH DAMAGE. X */ X X/* X * Taught to send *real* morse by Lyndon Nerenberg (VE7TCP/VE6BBM) X * X */ X X#ifndef lint Xstatic char copyright[] = X"@(#) Copyright (c) 1988, 1993\n\ X The Regents of the University of California. All rights reserved.\n"; X#endif /* not lint */ X X#ifndef lint Xstatic char sccsid[] = "@(#)morse.c 8.1 (Berkeley) 5/31/93"; X#endif /* not lint */ X X#include X#include X#include X X#ifdef SPEAKER X#include X#include X#endif X Xstruct morsetab { X char inchar; X char *morse; X}; X Xstatic struct morsetab mtab[] = { X X /* letters */ X X 'a', ".-", X 'b', "-...", X 'c', "-.-.", X 'd', "-..", X 'e', ".", X 'f', "..-.", X 'g', "--.", X 'h', "....", X 'i', "..", X 'j', ".---", X 'k', "-.-", X 'l', ".-..", X 'm', "--", X 'n', "-.", X 'o', "---", X 'p', ".--.", X 'q', "--.-", X 'r', ".-.", X 's', "...", X 't', "-", X 'u', "..-", X 'v', "...-", X 'w', ".--", X 'x', "-..-", X 'y', "-.--", X 'z', "--..", X X /* digits */ X X '0', "-----", X '1', ".----", X '2', "..---", X '3', "...--", X '4', "....-", X '5', ".....", X '6', "-....", X '7', "--...", X '8', "---..", X '9', "----.", X X /* punctuation */ X X ',', "--..--", X '.', ".-.-.-", X '?', "..--..", X '/', "-..-.", X '-', "-....-", X '=', "-...-", /* BT */ X ':', "---...", X ';', "-.-.-.", X '(', "-.--.", /* KN */ X ')', "-.--.-", X '$', "...-..-", X '+', ".-.-.", /* AR */ X X /* prosigns without already assigned values */ X X '#', ".-...", /* AS */ X '@', "...-.-", /* SK */ X X '\0', "" X}; X Xvoid show(char *), play(char *), morse(int); X Xstatic int pflag, sflag; Xstatic int wpm = 20; /* words per minute */ X#define FREQUENCY 600 Xstatic int freq = FREQUENCY; X X#ifdef SPEAKER X#define DASH_LEN 3 X#define CHAR_SPACE 3 X#define WORD_SPACE (7 - CHAR_SPACE - 1) Xstatic float dot_clock; Xint spkr; Xtone_t sound; X#endif X Xint Xmain(int argc, char **argv) X{ X extern char *optarg; X extern int optind; X register int ch; X register char *p; X X while ((ch = getopt(argc, argv, "spw:f:")) != EOF) X switch ((char) ch) { X case 'f': X freq = atoi(optarg); X break; X case 'p': X pflag = 1; X break; X case 's': X sflag = 1; X break; X case 'w': X wpm = atoi(optarg); X break; X case '?': X default: X fputs("usage: morse [-s] [-p] [-w speed] [-f frequency] [string ...]\n", stderr); X exit(1); X } X if (pflag && sflag) { X fputs("morse: only one of -p and -s allowed\n", stderr); X exit(1); X } X if (pflag && ((wpm < 1) || (wpm > 60))) { X fputs("morse: insane speed\n", stderr); X exit(1); X } X if (pflag && (freq == 0)) X freq = FREQUENCY; X#ifdef SPEAKER X if (pflag) { X if ((spkr = open(SPEAKER, O_RDWR, 0)) == -1) { X perror(SPEAKER); X exit(1); X } X dot_clock = wpm / 2.4; /* dots/sec */ X dot_clock = 1 / dot_clock; /* duration of a dot */ X dot_clock = dot_clock / 2; /* dot_clock runs at twice */ X /* the dot rate */ X dot_clock = dot_clock * 100; /* scale for ioctl */ X } X#endif X argc -= optind; X argv += optind; X X if (*argv) { X do { X for (p = *argv; *p; ++p) { X morse((int) *p); X } X morse((int) ' '); X } while (*++argv); X } else { X while ((ch = getchar()) != EOF) X morse(ch); X } X exit(0); X} X Xvoid Xmorse(int c) X{ X struct morsetab *m; X X if (isalpha(c)) X c = tolower(c); X if ((c == '\r') || (c == '\n')) X c = ' '; X if (c == ' ') { X if (pflag) { X play(" "); X return; X } else { X show(""); X return; X } X } X for (m = mtab; m->inchar != '\0'; m++) { X if (m->inchar == c) { X if (pflag) { X play(m->morse); X } else X show(m->morse); X } X } X} X Xvoid Xshow(char *s) X{ X if (sflag) X printf(" %s", s); X else X for (; *s; ++s) X printf(" %s", *s == '.' ? "dit" : "dah"); X printf("\n"); X} X Xvoid Xplay(char *s) X{ X#ifdef SPEAKER X char *c; X X for (c = s; *c != '\0'; c++) { X switch ((int) *c) { X case '.': X sound.frequency = freq; X sound.duration = dot_clock; X break; X case '-': X sound.frequency = freq; X sound.duration = dot_clock * DASH_LEN; X break; X case ' ': X sound.frequency = 0; X sound.duration = dot_clock * WORD_SPACE; X break; X default: X sound.duration = 0; X } X if (sound.duration) { X if (ioctl(spkr, SPKRTONE, &sound) == -1) { X perror("ioctl play"); X exit(1); X } X } X sound.frequency = 0; X sound.duration = dot_clock; X if (ioctl(spkr, SPKRTONE, &sound) == -1) { X perror("ioctl rest"); X exit(1); X } X } X sound.frequency = 0; X sound.duration = dot_clock * CHAR_SPACE; X ioctl(spkr, SPKRTONE, &sound); X#endif X} END-of-morse/morse.c echo x - bcd/bcd.6 sed 's/^X//' >bcd/bcd.6 << 'END-of-bcd/bcd.6' X.\" Copyright (c) 1988, 1991, 1993 X.\" The Regents of the University of California. All rights reserved. X.\" X.\" Redistribution and use in source and binary forms, with or without X.\" modification, are permitted provided that the following conditions X.\" are met: X.\" 1. Redistributions of source code must retain the above copyright X.\" notice, this list of conditions and the following disclaimer. X.\" 2. Redistributions in binary form must reproduce the above copyright X.\" notice, this list of conditions and the following disclaimer in the X.\" documentation and/or other materials provided with the distribution. X.\" 3. All advertising materials mentioning features or use of this software X.\" must display the following acknowledgement: X.\" This product includes software developed by the University of X.\" California, Berkeley and its contributors. X.\" 4. Neither the name of the University nor the names of its contributors X.\" may be used to endorse or promote products derived from this software X.\" without specific prior written permission. X.\" X.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND X.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE X.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE X.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF X.\" SUCH DAMAGE. X.\" X.\" @(#)bcd.6 8.1 (Berkeley) 5/31/93 X.\" X.Dd May 31, 1993 X.Dt "BCD" 6 X.Os X.Sh NAME X.Nm bcd , X.Nm ppt , X.Nm morse X.Nd "reformat input as punch cards, paper tape or morse code" X.Sh SYNOPSIS X.Nm bcd X.Op Ar string ... X.Nm ppt X.Op Ar string ... X.Nm morse X.Op Fl p X.Op Fl w Ar speed X.Op Fl f Ar frequency X.Op Fl s X.Op Ar string ... X.Sh DESCRIPTION XThe commands X.Nm bcd , X.Nm ppt Xand X.Nm morse Xread the given input and reformat it in the form of punched cards, Xpaper tape or morse code respectively. XAcceptable input are command line arguments or the standard input. X.Pp XAvailable option: X.Bl -tag -width flag X.It Fl s XThe X.Fl s Xoption for morse produces dots and dashes rather than words. X.It Fl p XSend morse the real way. This only works if your system has sound Xsupport and if the program understands your audio hardware. X.It Fl w Ar speed XSet the sending speed in words per minute. If not specified the default Xspeed of 20 WPM is used. X.It Fl f Ar frequency XSet the sidetone frequency to something other than the default 600 Hz. X.El X.Pp XThe X.Fl w Xand X.Fl f Xflags only work in conjunction with the X.Fl p Xflag. X.Pp XNot all prosigns have corresponding characters. Use `#' for AS Xand `@' for SK. X.Sh FILES X.Bl -tag -width /dev/speaker -compact X.It Pa /dev/speaker Xspeaker device file X.El X.Sh HISTORY XSound support added by Lyndon Nerenberg (VE7TCP/VE6BBM) . X.Sh BUGS XDoesn't understand European or Asian characters, or the continental Xlandline code. X.Pp XSends a bit slower than it should due to system overhead. Some people Xwould call this a feature. END-of-bcd/bcd.6 exit >Audit-Trail: >Unformatted: