2018-01-06 07:48:17 +00:00
|
|
|
|
/*-
|
1994-09-04 04:03:31 +00:00
|
|
|
|
* Copyright (c) 1988, 1993
|
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2010-02-15 18:46:02 +00:00
|
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
1994-09-04 04:03:31 +00:00
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
1995-08-27 14:06:15 +00:00
|
|
|
|
/*
|
2008-06-08 19:35:47 +00:00
|
|
|
|
* Taught to send *real* morse by Lyndon Nerenberg (VE6BBM)
|
|
|
|
|
* <lyndon@orthanc.ca>
|
1995-08-27 14:06:15 +00:00
|
|
|
|
*/
|
|
|
|
|
|
1999-11-30 03:50:02 +00:00
|
|
|
|
static const char copyright[] =
|
1994-09-04 04:03:31 +00:00
|
|
|
|
"@(#) Copyright (c) 1988, 1993\n\
|
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
|
|
1999-11-30 03:50:02 +00:00
|
|
|
|
#if 0
|
1994-09-04 04:03:31 +00:00
|
|
|
|
static char sccsid[] = "@(#)morse.c 8.1 (Berkeley) 5/31/93";
|
1999-11-30 03:50:02 +00:00
|
|
|
|
#endif
|
|
|
|
|
static const char rcsid[] =
|
|
|
|
|
"$FreeBSD$";
|
1994-09-04 04:03:31 +00:00
|
|
|
|
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#include <sys/time.h>
|
2018-01-03 09:08:32 +00:00
|
|
|
|
#include <sys/ioctl.h>
|
2000-02-27 01:21:28 +00:00
|
|
|
|
|
1994-09-04 04:03:31 +00:00
|
|
|
|
#include <ctype.h>
|
2018-01-06 07:02:24 +00:00
|
|
|
|
#include <err.h>
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#include <fcntl.h>
|
2001-06-26 01:43:52 +00:00
|
|
|
|
#include <langinfo.h>
|
1995-08-27 14:06:15 +00:00
|
|
|
|
#include <locale.h>
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#include <signal.h>
|
|
|
|
|
#include <stdio.h>
|
1995-08-27 14:06:15 +00:00
|
|
|
|
#include <stdlib.h>
|
1998-05-09 08:17:46 +00:00
|
|
|
|
#include <string.h>
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#include <termios.h>
|
1999-12-15 04:28:10 +00:00
|
|
|
|
#include <unistd.h>
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
2018-01-06 07:48:17 +00:00
|
|
|
|
#ifdef __FreeBSD__
|
2010-02-04 07:08:06 +00:00
|
|
|
|
/* Always use the speaker, let the open fail if -p is selected */
|
|
|
|
|
#define SPEAKER "/dev/speaker"
|
2018-01-06 07:48:17 +00:00
|
|
|
|
#endif
|
2010-02-04 07:08:06 +00:00
|
|
|
|
|
2018-01-06 07:02:24 +00:00
|
|
|
|
#define WHITESPACE " \t\n"
|
|
|
|
|
#define DELIMITERS " \t"
|
|
|
|
|
|
1995-08-27 14:06:15 +00:00
|
|
|
|
#ifdef SPEAKER
|
2005-11-11 09:57:32 +00:00
|
|
|
|
#include <dev/speaker/speaker.h>
|
1995-08-27 14:06:15 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct morsetab {
|
2010-02-15 14:31:05 +00:00
|
|
|
|
const char inchar;
|
|
|
|
|
const char *morse;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
static const struct morsetab mtab[] = {
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
/* letters */
|
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'a', ".-"},
|
|
|
|
|
{'b', "-..."},
|
|
|
|
|
{'c', "-.-."},
|
|
|
|
|
{'d', "-.."},
|
|
|
|
|
{'e', "."},
|
|
|
|
|
{'f', "..-."},
|
|
|
|
|
{'g', "--."},
|
|
|
|
|
{'h', "...."},
|
|
|
|
|
{'i', ".."},
|
|
|
|
|
{'j', ".---"},
|
|
|
|
|
{'k', "-.-"},
|
|
|
|
|
{'l', ".-.."},
|
|
|
|
|
{'m', "--"},
|
|
|
|
|
{'n', "-."},
|
|
|
|
|
{'o', "---"},
|
|
|
|
|
{'p', ".--."},
|
|
|
|
|
{'q', "--.-"},
|
|
|
|
|
{'r', ".-."},
|
|
|
|
|
{'s', "..."},
|
|
|
|
|
{'t', "-"},
|
|
|
|
|
{'u', "..-"},
|
|
|
|
|
{'v', "...-"},
|
|
|
|
|
{'w', ".--"},
|
|
|
|
|
{'x', "-..-"},
|
|
|
|
|
{'y', "-.--"},
|
|
|
|
|
{'z', "--.."},
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
/* digits */
|
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'0', "-----"},
|
|
|
|
|
{'1', ".----"},
|
|
|
|
|
{'2', "..---"},
|
|
|
|
|
{'3', "...--"},
|
|
|
|
|
{'4', "....-"},
|
|
|
|
|
{'5', "....."},
|
|
|
|
|
{'6', "-...."},
|
|
|
|
|
{'7', "--..."},
|
|
|
|
|
{'8', "---.."},
|
|
|
|
|
{'9', "----."},
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
/* punctuation */
|
1994-09-04 04:03:31 +00:00
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{',', "--..--"},
|
|
|
|
|
{'.', ".-.-.-"},
|
2004-02-20 11:55:38 +00:00
|
|
|
|
{'"', ".-..-."},
|
|
|
|
|
{'!', "..--."},
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'?', "..--.."},
|
|
|
|
|
{'/', "-..-."},
|
|
|
|
|
{'-', "-....-"},
|
|
|
|
|
{'=', "-...-"}, /* BT */
|
|
|
|
|
{':', "---..."},
|
|
|
|
|
{';', "-.-.-."},
|
|
|
|
|
{'(', "-.--."}, /* KN */
|
|
|
|
|
{')', "-.--.-"},
|
|
|
|
|
{'$', "...-..-"},
|
|
|
|
|
{'+', ".-.-."}, /* AR */
|
2004-02-20 13:46:39 +00:00
|
|
|
|
{'@', ".--.-."}, /* AC */
|
2018-01-03 09:08:32 +00:00
|
|
|
|
{'_', "..--.-"},
|
|
|
|
|
{'\'', ".----."},
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
/* prosigns without already assigned values */
|
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'#', ".-..."}, /* AS */
|
2004-02-20 11:55:38 +00:00
|
|
|
|
{'&', "...-.-"}, /* SK */
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'*', "...-."}, /* VE */
|
|
|
|
|
{'%', "-...-.-"}, /* BK */
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'\0', ""}
|
1995-08-27 14:06:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-01-15 13:23:01 +00:00
|
|
|
|
/*
|
|
|
|
|
* Code-points for some Latin1 chars in ISO-8859-1 encoding.
|
|
|
|
|
* UTF-8 encoded chars in the comments.
|
|
|
|
|
*/
|
2004-05-11 11:11:14 +00:00
|
|
|
|
static const struct morsetab iso8859_1tab[] = {
|
2012-01-15 13:23:01 +00:00
|
|
|
|
{'\340', ".--.-"}, /* à */
|
|
|
|
|
{'\341', ".--.-"}, /* á */
|
|
|
|
|
{'\342', ".--.-"}, /* â */
|
|
|
|
|
{'\344', ".-.-"}, /* ä */
|
|
|
|
|
{'\347', "-.-.."}, /* ç */
|
|
|
|
|
{'\350', "..-.."}, /* è */
|
|
|
|
|
{'\351', "..-.."}, /* é */
|
|
|
|
|
{'\352', "-..-."}, /* ê */
|
2018-01-03 17:04:13 +00:00
|
|
|
|
{'\361', "--.--"}, /* ñ */
|
2012-01-15 13:23:01 +00:00
|
|
|
|
{'\366', "---."}, /* ö */
|
|
|
|
|
{'\374', "..--"}, /* ü */
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'\0', ""}
|
1995-08-27 14:06:15 +00:00
|
|
|
|
};
|
|
|
|
|
|
2012-01-15 13:23:01 +00:00
|
|
|
|
/*
|
|
|
|
|
* Code-points for some Greek chars in ISO-8859-7 encoding.
|
|
|
|
|
* UTF-8 encoded chars in the comments.
|
|
|
|
|
*/
|
2004-05-11 11:11:14 +00:00
|
|
|
|
static const struct morsetab iso8859_7tab[] = {
|
|
|
|
|
/*
|
|
|
|
|
* This table does not implement:
|
|
|
|
|
* - the special sequences for the seven diphthongs,
|
|
|
|
|
* - the punctuation differences.
|
|
|
|
|
* Implementing these features would introduce too many
|
|
|
|
|
* special-cases in the program's main loop.
|
2011-05-14 19:03:30 +00:00
|
|
|
|
* The diphthong sequences are:
|
2004-05-11 11:11:14 +00:00
|
|
|
|
* alpha iota .-.-
|
|
|
|
|
* alpha upsilon ..--
|
|
|
|
|
* epsilon upsilon ---.
|
|
|
|
|
* eta upsilon ...-
|
2011-05-14 19:03:30 +00:00
|
|
|
|
* omicron iota ---..
|
|
|
|
|
* omicron upsilon ..-
|
2004-05-11 11:11:14 +00:00
|
|
|
|
* upsilon iota .---
|
|
|
|
|
* The different punctuation symbols are:
|
|
|
|
|
* ; ..-.-
|
|
|
|
|
* ! --..--
|
|
|
|
|
*/
|
2012-01-15 13:23:01 +00:00
|
|
|
|
{'\341', ".-"}, /* α, alpha */
|
|
|
|
|
{'\334', ".-"}, /* ά, alpha with acute */
|
|
|
|
|
{'\342', "-..."}, /* β, beta */
|
|
|
|
|
{'\343', "--."}, /* γ, gamma */
|
|
|
|
|
{'\344', "-.."}, /* δ, delta */
|
|
|
|
|
{'\345', "."}, /* ε, epsilon */
|
|
|
|
|
{'\335', "."}, /* έ, epsilon with acute */
|
|
|
|
|
{'\346', "--.."}, /* ζ, zeta */
|
|
|
|
|
{'\347', "...."}, /* η, eta */
|
|
|
|
|
{'\336', "...."}, /* ή, eta with acute */
|
|
|
|
|
{'\350', "-.-."}, /* θ, theta */
|
|
|
|
|
{'\351', ".."}, /* ι, iota */
|
|
|
|
|
{'\337', ".."}, /* ί, iota with acute */
|
|
|
|
|
{'\372', ".."}, /* ϊ, iota with diaeresis */
|
|
|
|
|
{'\300', ".."}, /* ΐ, iota with acute and diaeresis */
|
|
|
|
|
{'\352', "-.-"}, /* κ, kappa */
|
|
|
|
|
{'\353', ".-.."}, /* λ, lambda */
|
|
|
|
|
{'\354', "--"}, /* μ, mu */
|
|
|
|
|
{'\355', "-."}, /* ν, nu */
|
|
|
|
|
{'\356', "-..-"}, /* ξ, xi */
|
|
|
|
|
{'\357', "---"}, /* ο, omicron */
|
|
|
|
|
{'\374', "---"}, /* ό, omicron with acute */
|
|
|
|
|
{'\360', ".--."}, /* π, pi */
|
|
|
|
|
{'\361', ".-."}, /* ρ, rho */
|
|
|
|
|
{'\363', "..."}, /* σ, sigma */
|
|
|
|
|
{'\362', "..."}, /* ς, final sigma */
|
|
|
|
|
{'\364', "-"}, /* τ, tau */
|
|
|
|
|
{'\365', "-.--"}, /* υ, upsilon */
|
|
|
|
|
{'\375', "-.--"}, /* ύ, upsilon with acute */
|
|
|
|
|
{'\373', "-.--"}, /* ϋ, upsilon and diaeresis */
|
|
|
|
|
{'\340', "-.--"}, /* ΰ, upsilon with acute and diaeresis */
|
|
|
|
|
{'\366', "..-."}, /* φ, phi */
|
|
|
|
|
{'\367', "----"}, /* χ, chi */
|
|
|
|
|
{'\370', "--.-"}, /* ψ, psi */
|
|
|
|
|
{'\371', ".--"}, /* ω, omega */
|
|
|
|
|
{'\376', ".--"}, /* ώ, omega with acute */
|
2004-05-11 11:11:14 +00:00
|
|
|
|
|
|
|
|
|
{'\0', ""}
|
|
|
|
|
};
|
|
|
|
|
|
2012-01-15 13:23:01 +00:00
|
|
|
|
/*
|
|
|
|
|
* Code-points for the Cyrillic alphabet in KOI8-R encoding.
|
|
|
|
|
* UTF-8 encoded chars in the comments.
|
|
|
|
|
*/
|
1999-12-15 04:28:10 +00:00
|
|
|
|
static const struct morsetab koi8rtab[] = {
|
2012-01-15 13:23:01 +00:00
|
|
|
|
{'\301', ".-"}, /* а, a */
|
|
|
|
|
{'\302', "-..."}, /* б, be */
|
|
|
|
|
{'\327', ".--"}, /* в, ve */
|
|
|
|
|
{'\307', "--."}, /* г, ge */
|
|
|
|
|
{'\304', "-.."}, /* д, de */
|
|
|
|
|
{'\305', "."}, /* е, ye */
|
|
|
|
|
{'\243', "."}, /* ё, yo, the same as ye */
|
|
|
|
|
{'\326', "...-"}, /* ж, she */
|
|
|
|
|
{'\332', "--.."}, /* з, ze */
|
|
|
|
|
{'\311', ".."}, /* и, i */
|
|
|
|
|
{'\312', ".---"}, /* й, i kratkoye */
|
|
|
|
|
{'\313', "-.-"}, /* к, ka */
|
|
|
|
|
{'\314', ".-.."}, /* л, el */
|
|
|
|
|
{'\315', "--"}, /* м, em */
|
|
|
|
|
{'\316', "-."}, /* н, en */
|
|
|
|
|
{'\317', "---"}, /* о, o */
|
|
|
|
|
{'\320', ".--."}, /* п, pe */
|
|
|
|
|
{'\322', ".-."}, /* р, er */
|
|
|
|
|
{'\323', "..."}, /* с, es */
|
|
|
|
|
{'\324', "-"}, /* т, te */
|
|
|
|
|
{'\325', "..-"}, /* у, u */
|
|
|
|
|
{'\306', "..-."}, /* ф, ef */
|
|
|
|
|
{'\310', "...."}, /* х, kha */
|
|
|
|
|
{'\303', "-.-."}, /* ц, ce */
|
|
|
|
|
{'\336', "---."}, /* ч, che */
|
|
|
|
|
{'\333', "----"}, /* ш, sha */
|
|
|
|
|
{'\335', "--.-"}, /* щ, shcha */
|
|
|
|
|
{'\331', "-.--"}, /* ы, yi */
|
|
|
|
|
{'\330', "-..-"}, /* ь, myakhkij znak */
|
|
|
|
|
{'\334', "..-.."}, /* э, ae */
|
|
|
|
|
{'\300', "..--"}, /* ю, yu */
|
|
|
|
|
{'\321', ".-.-"}, /* я, ya */
|
1999-12-15 04:28:10 +00:00
|
|
|
|
|
|
|
|
|
{'\0', ""}
|
1994-09-04 04:03:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static void show(const char *), play(const char *), morse(char);
|
2018-01-06 07:02:24 +00:00
|
|
|
|
static void decode (char *), fdecode(FILE *);
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static void ttyout(const char *);
|
|
|
|
|
static void sighandler(int);
|
2000-02-27 01:21:28 +00:00
|
|
|
|
|
2018-01-06 07:02:24 +00:00
|
|
|
|
static int pflag, lflag, rflag, sflag, eflag;
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static int wpm = 20; /* effective words per minute */
|
|
|
|
|
static int cpm; /* effective words per minute between
|
2005-06-07 19:01:41 +00:00
|
|
|
|
* characters */
|
1995-08-27 14:06:15 +00:00
|
|
|
|
#define FREQUENCY 600
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static int freq = FREQUENCY;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
static char *device; /* for tty-controlled generator */
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
#define DASH_LEN 3
|
|
|
|
|
#define CHAR_SPACE 3
|
|
|
|
|
#define WORD_SPACE (7 - CHAR_SPACE - 1)
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static float dot_clock;
|
|
|
|
|
static float cdot_clock;
|
|
|
|
|
static int spkr, line;
|
|
|
|
|
static struct termios otty, ntty;
|
|
|
|
|
static int olflags;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
|
|
|
|
|
#ifdef SPEAKER
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static tone_t sound;
|
2018-01-06 07:02:24 +00:00
|
|
|
|
#define GETOPTOPTS "c:d:ef:lprsw:"
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#define USAGE \
|
2018-01-06 07:02:24 +00:00
|
|
|
|
"usage: morse [-elprs] [-d device] [-w speed] [-c speed] [-f frequency] [string ...]\n"
|
|
|
|
|
#else
|
|
|
|
|
#define GETOPTOPTS "c:d:ef:lrsw:"
|
|
|
|
|
#define USAGE \
|
|
|
|
|
"usage: morse [-elrs] [-d device] [-w speed] [-c speed] [-f frequency] [string ...]\n"
|
|
|
|
|
|
1995-08-27 14:06:15 +00:00
|
|
|
|
#endif
|
1994-09-04 04:03:31 +00:00
|
|
|
|
|
2001-06-26 01:43:52 +00:00
|
|
|
|
static const struct morsetab *hightab;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
int
|
2018-01-06 07:48:17 +00:00
|
|
|
|
main(int argc, char *argv[])
|
1994-09-04 04:03:31 +00:00
|
|
|
|
{
|
2000-02-27 01:21:28 +00:00
|
|
|
|
int ch, lflags;
|
2001-06-26 01:43:52 +00:00
|
|
|
|
char *p, *codeset;
|
1994-09-04 04:03:31 +00:00
|
|
|
|
|
2000-02-27 01:21:28 +00:00
|
|
|
|
while ((ch = getopt(argc, argv, GETOPTOPTS)) != -1)
|
1995-08-27 14:06:15 +00:00
|
|
|
|
switch ((char) ch) {
|
2011-05-14 19:03:30 +00:00
|
|
|
|
case 'c':
|
|
|
|
|
cpm = atoi(optarg);
|
|
|
|
|
break;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
case 'd':
|
|
|
|
|
device = optarg;
|
|
|
|
|
break;
|
|
|
|
|
case 'e':
|
|
|
|
|
eflag = 1;
|
|
|
|
|
setvbuf(stdout, 0, _IONBF, 0);
|
|
|
|
|
break;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
case 'f':
|
|
|
|
|
freq = atoi(optarg);
|
|
|
|
|
break;
|
2003-11-03 11:05:43 +00:00
|
|
|
|
case 'l':
|
|
|
|
|
lflag = 1;
|
|
|
|
|
break;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#ifdef SPEAKER
|
1995-08-27 14:06:15 +00:00
|
|
|
|
case 'p':
|
|
|
|
|
pflag = 1;
|
|
|
|
|
break;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#endif
|
2018-01-06 07:02:24 +00:00
|
|
|
|
case 'r':
|
|
|
|
|
rflag = 1;
|
|
|
|
|
break;
|
1994-09-04 04:03:31 +00:00
|
|
|
|
case 's':
|
|
|
|
|
sflag = 1;
|
|
|
|
|
break;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
case 'w':
|
|
|
|
|
wpm = atoi(optarg);
|
|
|
|
|
break;
|
1994-09-04 04:03:31 +00:00
|
|
|
|
case '?':
|
|
|
|
|
default:
|
2018-01-06 07:02:24 +00:00
|
|
|
|
errx(1, USAGE);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
2018-01-06 07:02:24 +00:00
|
|
|
|
if ((sflag && lflag) || (sflag && rflag) || (lflag && rflag)) {
|
|
|
|
|
errx(1, "morse: only one of -l, -s, and -r allowed\n");
|
2003-11-03 11:05:43 +00:00
|
|
|
|
}
|
|
|
|
|
if ((pflag || device) && (sflag || lflag)) {
|
2018-01-06 07:02:24 +00:00
|
|
|
|
errx(1, "morse: only one of -p, -d and -l, -s allowed\n");
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
2018-01-06 07:02:24 +00:00
|
|
|
|
if (cpm == 0) {
|
2005-06-07 19:01:41 +00:00
|
|
|
|
cpm = wpm;
|
2018-01-06 07:02:24 +00:00
|
|
|
|
}
|
2005-06-07 19:01:41 +00:00
|
|
|
|
if ((pflag || device) && ((wpm < 1) || (wpm > 60) || (cpm < 1) || (cpm > 60))) {
|
2018-01-06 07:02:24 +00:00
|
|
|
|
errx(1, "morse: insane speed\n");
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
2018-01-06 07:02:24 +00:00
|
|
|
|
if ((pflag || device) && (freq == 0)) {
|
1995-08-27 14:06:15 +00:00
|
|
|
|
freq = FREQUENCY;
|
2018-01-06 07:02:24 +00:00
|
|
|
|
}
|
1995-08-27 14:06:15 +00:00
|
|
|
|
#ifdef SPEAKER
|
|
|
|
|
if (pflag) {
|
|
|
|
|
if ((spkr = open(SPEAKER, O_WRONLY, 0)) == -1) {
|
2018-01-06 07:02:24 +00:00
|
|
|
|
err(1, SPEAKER);
|
1994-09-04 04:03:31 +00:00
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
if (device) {
|
|
|
|
|
if ((line = open(device, O_WRONLY | O_NONBLOCK)) == -1) {
|
2018-01-06 07:02:24 +00:00
|
|
|
|
err(1, "open tty line");
|
2000-02-27 01:21:28 +00:00
|
|
|
|
}
|
|
|
|
|
if (tcgetattr(line, &otty) == -1) {
|
2018-01-06 07:02:24 +00:00
|
|
|
|
err(1, "tcgetattr() failed");
|
2000-02-27 01:21:28 +00:00
|
|
|
|
}
|
|
|
|
|
ntty = otty;
|
|
|
|
|
ntty.c_cflag |= CLOCAL;
|
|
|
|
|
tcsetattr(line, TCSANOW, &ntty);
|
|
|
|
|
lflags = fcntl(line, F_GETFL);
|
|
|
|
|
lflags &= ~O_NONBLOCK;
|
|
|
|
|
fcntl(line, F_SETFL, &lflags);
|
|
|
|
|
ioctl(line, TIOCMGET, &lflags);
|
|
|
|
|
lflags &= ~TIOCM_RTS;
|
|
|
|
|
olflags = lflags;
|
|
|
|
|
ioctl(line, TIOCMSET, &lflags);
|
|
|
|
|
(void)signal(SIGHUP, sighandler);
|
|
|
|
|
(void)signal(SIGINT, sighandler);
|
|
|
|
|
(void)signal(SIGQUIT, sighandler);
|
|
|
|
|
(void)signal(SIGTERM, sighandler);
|
|
|
|
|
}
|
|
|
|
|
if (pflag || device) {
|
1995-08-27 14:06:15 +00:00
|
|
|
|
dot_clock = wpm / 2.4; /* dots/sec */
|
|
|
|
|
dot_clock = 1 / dot_clock; /* duration of a dot */
|
|
|
|
|
dot_clock = dot_clock / 2; /* dot_clock runs at twice */
|
|
|
|
|
/* the dot rate */
|
|
|
|
|
dot_clock = dot_clock * 100; /* scale for ioctl */
|
2005-06-07 19:01:41 +00:00
|
|
|
|
|
|
|
|
|
cdot_clock = cpm / 2.4; /* dots/sec */
|
|
|
|
|
cdot_clock = 1 / cdot_clock; /* duration of a dot */
|
|
|
|
|
cdot_clock = cdot_clock / 2; /* dot_clock runs at twice */
|
|
|
|
|
/* the dot rate */
|
|
|
|
|
cdot_clock = cdot_clock * 100; /* scale for ioctl */
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
|
1994-09-04 04:03:31 +00:00
|
|
|
|
argc -= optind;
|
|
|
|
|
argv += optind;
|
|
|
|
|
|
2001-06-26 01:43:52 +00:00
|
|
|
|
if (setlocale(LC_CTYPE, "") != NULL &&
|
|
|
|
|
*(codeset = nl_langinfo(CODESET)) != '\0') {
|
|
|
|
|
if (strcmp(codeset, "KOI8-R") == 0)
|
1995-08-27 14:06:15 +00:00
|
|
|
|
hightab = koi8rtab;
|
2001-06-26 01:43:52 +00:00
|
|
|
|
else if (strcmp(codeset, "ISO8859-1") == 0 ||
|
|
|
|
|
strcmp(codeset, "ISO8859-15") == 0)
|
2004-05-11 11:11:14 +00:00
|
|
|
|
hightab = iso8859_1tab;
|
|
|
|
|
else if (strcmp(codeset, "ISO8859-7") == 0)
|
|
|
|
|
hightab = iso8859_7tab;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-01-06 07:02:24 +00:00
|
|
|
|
if (lflag) {
|
2003-11-03 11:05:43 +00:00
|
|
|
|
printf("m");
|
2018-01-06 07:02:24 +00:00
|
|
|
|
}
|
|
|
|
|
if (rflag) {
|
|
|
|
|
if (*argv) {
|
|
|
|
|
do {
|
|
|
|
|
p = strtok(*argv, DELIMITERS);
|
|
|
|
|
if (p == NULL) {
|
|
|
|
|
decode(*argv);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
while (p) {
|
|
|
|
|
decode(p);
|
|
|
|
|
p = strtok(NULL, DELIMITERS);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} while (*++argv);
|
|
|
|
|
putchar('\n');
|
|
|
|
|
} else {
|
|
|
|
|
fdecode(stdin);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (*argv) {
|
1994-09-04 04:03:31 +00:00
|
|
|
|
do {
|
1995-08-27 14:06:15 +00:00
|
|
|
|
for (p = *argv; *p; ++p) {
|
2000-02-27 01:21:28 +00:00
|
|
|
|
if (eflag)
|
|
|
|
|
putchar(*p);
|
1997-09-01 13:58:22 +00:00
|
|
|
|
morse(*p);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
if (eflag)
|
|
|
|
|
putchar(' ');
|
1997-09-01 13:58:22 +00:00
|
|
|
|
morse(' ');
|
1994-09-04 04:03:31 +00:00
|
|
|
|
} while (*++argv);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
} else {
|
2000-02-27 01:21:28 +00:00
|
|
|
|
while ((ch = getchar()) != EOF) {
|
|
|
|
|
if (eflag)
|
|
|
|
|
putchar(ch);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
morse(ch);
|
2000-02-27 01:21:28 +00:00
|
|
|
|
}
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
if (device)
|
|
|
|
|
tcsetattr(line, TCSANOW, &otty);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
exit(0);
|
1994-09-04 04:03:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static void
|
1995-08-27 14:06:15 +00:00
|
|
|
|
morse(char c)
|
1994-09-04 04:03:31 +00:00
|
|
|
|
{
|
1999-12-15 04:28:10 +00:00
|
|
|
|
const struct morsetab *m;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
1997-09-01 13:58:22 +00:00
|
|
|
|
if (isalpha((unsigned char)c))
|
|
|
|
|
c = tolower((unsigned char)c);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
if ((c == '\r') || (c == '\n'))
|
|
|
|
|
c = ' ';
|
|
|
|
|
if (c == ' ') {
|
2003-11-03 11:05:43 +00:00
|
|
|
|
if (pflag)
|
1995-08-27 14:06:15 +00:00
|
|
|
|
play(" ");
|
2003-11-03 11:05:43 +00:00
|
|
|
|
else if (device)
|
2000-02-27 01:21:28 +00:00
|
|
|
|
ttyout(" ");
|
2003-11-03 11:05:43 +00:00
|
|
|
|
else if (lflag)
|
|
|
|
|
printf("\n");
|
|
|
|
|
else
|
1995-08-27 14:06:15 +00:00
|
|
|
|
show("");
|
2003-11-03 11:05:43 +00:00
|
|
|
|
return;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
for (m = ((unsigned char)c < 0x80? mtab: hightab);
|
2001-06-26 01:43:52 +00:00
|
|
|
|
m != NULL && m->inchar != '\0';
|
1995-08-27 14:06:15 +00:00
|
|
|
|
m++) {
|
|
|
|
|
if (m->inchar == c) {
|
|
|
|
|
if (pflag) {
|
|
|
|
|
play(m->morse);
|
2000-02-27 01:21:28 +00:00
|
|
|
|
} else if (device) {
|
|
|
|
|
ttyout(m->morse);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
} else
|
|
|
|
|
show(m->morse);
|
|
|
|
|
}
|
|
|
|
|
}
|
1994-09-04 04:03:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static void
|
1995-08-27 14:06:15 +00:00
|
|
|
|
show(const char *s)
|
1994-09-04 04:03:31 +00:00
|
|
|
|
{
|
2003-11-03 11:05:43 +00:00
|
|
|
|
if (lflag) {
|
|
|
|
|
printf("%s ", s);
|
|
|
|
|
} else if (sflag) {
|
|
|
|
|
printf(" %s\n", s);
|
|
|
|
|
} else {
|
1995-08-27 14:06:15 +00:00
|
|
|
|
for (; *s; ++s)
|
2008-06-08 19:35:47 +00:00
|
|
|
|
printf(" %s", *s == '.' ? *(s + 1) == '\0' ? "dit" :
|
|
|
|
|
"di" : "dah");
|
2003-11-03 11:05:43 +00:00
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static void
|
1995-08-27 14:06:15 +00:00
|
|
|
|
play(const char *s)
|
|
|
|
|
{
|
|
|
|
|
#ifdef SPEAKER
|
|
|
|
|
const char *c;
|
|
|
|
|
|
|
|
|
|
for (c = s; *c != '\0'; c++) {
|
1997-09-01 13:58:22 +00:00
|
|
|
|
switch (*c) {
|
1995-08-27 14:06:15 +00:00
|
|
|
|
case '.':
|
|
|
|
|
sound.frequency = freq;
|
|
|
|
|
sound.duration = dot_clock;
|
|
|
|
|
break;
|
|
|
|
|
case '-':
|
|
|
|
|
sound.frequency = freq;
|
|
|
|
|
sound.duration = dot_clock * DASH_LEN;
|
|
|
|
|
break;
|
|
|
|
|
case ' ':
|
|
|
|
|
sound.frequency = 0;
|
2005-06-07 19:01:41 +00:00
|
|
|
|
sound.duration = cdot_clock * WORD_SPACE;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
sound.duration = 0;
|
|
|
|
|
}
|
|
|
|
|
if (sound.duration) {
|
|
|
|
|
if (ioctl(spkr, SPKRTONE, &sound) == -1) {
|
2018-01-06 07:02:24 +00:00
|
|
|
|
err(1, "ioctl play");
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sound.frequency = 0;
|
|
|
|
|
sound.duration = dot_clock;
|
|
|
|
|
if (ioctl(spkr, SPKRTONE, &sound) == -1) {
|
2018-01-06 07:02:24 +00:00
|
|
|
|
err(1, "ioctl rest");
|
1995-08-27 14:06:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sound.frequency = 0;
|
2005-06-07 19:01:41 +00:00
|
|
|
|
sound.duration = cdot_clock * CHAR_SPACE;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
ioctl(spkr, SPKRTONE, &sound);
|
|
|
|
|
#endif
|
1994-09-04 04:03:31 +00:00
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static void
|
2000-02-27 01:21:28 +00:00
|
|
|
|
ttyout(const char *s)
|
|
|
|
|
{
|
|
|
|
|
const char *c;
|
|
|
|
|
int duration, on, lflags;
|
|
|
|
|
|
|
|
|
|
for (c = s; *c != '\0'; c++) {
|
|
|
|
|
switch (*c) {
|
|
|
|
|
case '.':
|
|
|
|
|
on = 1;
|
|
|
|
|
duration = dot_clock;
|
|
|
|
|
break;
|
|
|
|
|
case '-':
|
|
|
|
|
on = 1;
|
|
|
|
|
duration = dot_clock * DASH_LEN;
|
|
|
|
|
break;
|
|
|
|
|
case ' ':
|
|
|
|
|
on = 0;
|
2005-06-07 19:01:41 +00:00
|
|
|
|
duration = cdot_clock * WORD_SPACE;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
on = 0;
|
|
|
|
|
duration = 0;
|
|
|
|
|
}
|
|
|
|
|
if (on) {
|
|
|
|
|
ioctl(line, TIOCMGET, &lflags);
|
|
|
|
|
lflags |= TIOCM_RTS;
|
|
|
|
|
ioctl(line, TIOCMSET, &lflags);
|
|
|
|
|
}
|
|
|
|
|
duration *= 10000;
|
|
|
|
|
if (duration)
|
|
|
|
|
usleep(duration);
|
|
|
|
|
ioctl(line, TIOCMGET, &lflags);
|
|
|
|
|
lflags &= ~TIOCM_RTS;
|
|
|
|
|
ioctl(line, TIOCMSET, &lflags);
|
|
|
|
|
duration = dot_clock * 10000;
|
|
|
|
|
usleep(duration);
|
|
|
|
|
}
|
2005-06-07 19:01:41 +00:00
|
|
|
|
duration = cdot_clock * CHAR_SPACE * 10000;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
usleep(duration);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-06 07:02:24 +00:00
|
|
|
|
void
|
|
|
|
|
fdecode(FILE *stream)
|
|
|
|
|
{
|
|
|
|
|
char *n, *p, *s;
|
|
|
|
|
char buf[BUFSIZ];
|
|
|
|
|
|
|
|
|
|
s = buf;
|
2018-01-06 09:48:04 +00:00
|
|
|
|
while (fgets(s, BUFSIZ - (s - buf), stream)) {
|
2018-01-06 07:02:24 +00:00
|
|
|
|
p = buf;
|
|
|
|
|
|
|
|
|
|
while (*p && isblank(*p)) {
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
while (*p && isspace(*p)) {
|
|
|
|
|
p++;
|
|
|
|
|
putchar (' ');
|
|
|
|
|
}
|
|
|
|
|
while (*p) {
|
|
|
|
|
n = strpbrk(p, WHITESPACE);
|
|
|
|
|
if (n == NULL) {
|
|
|
|
|
/* The token was interrupted at the end
|
|
|
|
|
* of the buffer. Shift it to the begin
|
|
|
|
|
* of the buffer.
|
|
|
|
|
*/
|
|
|
|
|
for (s = buf; *p; *s++ = *p++)
|
|
|
|
|
;
|
|
|
|
|
} else {
|
|
|
|
|
*n = '\0';
|
|
|
|
|
n++;
|
|
|
|
|
decode(p);
|
|
|
|
|
p = n;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
putchar('\n');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
decode(char *p)
|
|
|
|
|
{
|
|
|
|
|
char c;
|
|
|
|
|
const struct morsetab *m;
|
|
|
|
|
|
|
|
|
|
c = ' ';
|
|
|
|
|
for (m = mtab; m != NULL && m->inchar != '\0'; m++) {
|
|
|
|
|
if (strcmp(m->morse, p) == 0) {
|
|
|
|
|
c = m->inchar;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (c == ' ')
|
|
|
|
|
for (m = hightab; m != NULL && m->inchar != '\0'; m++) {
|
|
|
|
|
if (strcmp(m->morse, p) == 0) {
|
|
|
|
|
c = m->inchar;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
putchar(c);
|
|
|
|
|
}
|
|
|
|
|
|
2011-11-05 07:18:53 +00:00
|
|
|
|
static void
|
2000-02-27 01:21:28 +00:00
|
|
|
|
sighandler(int signo)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ioctl(line, TIOCMSET, &olflags);
|
|
|
|
|
tcsetattr(line, TCSANOW, &otty);
|
|
|
|
|
|
|
|
|
|
signal(signo, SIG_DFL);
|
|
|
|
|
(void)kill(getpid(), signo);
|
|
|
|
|
}
|