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.
|
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
|
* 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
|
|
|
|
/*
|
|
|
|
|
* Taught to send *real* morse by Lyndon Nerenberg (VE7TCP/VE6BBM)
|
|
|
|
|
* <lyndon@orthanc.com>
|
|
|
|
|
*/
|
|
|
|
|
|
1994-09-04 04:03:31 +00:00
|
|
|
|
#ifndef lint
|
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";
|
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
|
|
#ifndef lint
|
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
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
1994-09-04 04:03:31 +00:00
|
|
|
|
#include <ctype.h>
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#include <fcntl.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
|
|
|
|
|
|
|
|
|
#ifdef SPEAKER
|
|
|
|
|
#include <machine/speaker.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
struct morsetab {
|
|
|
|
|
char inchar;
|
|
|
|
|
char *morse;
|
|
|
|
|
};
|
|
|
|
|
|
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
|
|
|
|
{',', "--..--"},
|
|
|
|
|
{'.', ".-.-.-"},
|
|
|
|
|
{'?', "..--.."},
|
|
|
|
|
{'/', "-..-."},
|
|
|
|
|
{'-', "-....-"},
|
|
|
|
|
{'=', "-...-"}, /* BT */
|
|
|
|
|
{':', "---..."},
|
|
|
|
|
{';', "-.-.-."},
|
|
|
|
|
{'(', "-.--."}, /* KN */
|
|
|
|
|
{')', "-.--.-"},
|
|
|
|
|
{'$', "...-..-"},
|
|
|
|
|
{'+', ".-.-."}, /* AR */
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
/* prosigns without already assigned values */
|
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'#', ".-..."}, /* AS */
|
|
|
|
|
{'@', "...-.-"}, /* SK */
|
|
|
|
|
{'*', "...-."}, /* 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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
static const struct morsetab iso8859tab[] = {
|
|
|
|
|
{'<EFBFBD>', ".--.-"},
|
|
|
|
|
{'<EFBFBD>', ".--.-"},
|
|
|
|
|
{'<EFBFBD>', ".--.-"},
|
|
|
|
|
{'<EFBFBD>', ".-.-"},
|
|
|
|
|
{'<EFBFBD>', "-.-.."},
|
|
|
|
|
{'<EFBFBD>', "..-.."},
|
|
|
|
|
{'<EFBFBD>', "..-.."},
|
|
|
|
|
{'<EFBFBD>', "-..-."},
|
|
|
|
|
{'<EFBFBD>', "---."},
|
|
|
|
|
{'<EFBFBD>', "..--"},
|
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
|
|
|
|
};
|
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
static const struct morsetab koi8rtab[] = {
|
1995-08-27 14:06:15 +00:00
|
|
|
|
/*
|
|
|
|
|
* the cyrillic alphabet; you'll need a KOI8R font in order
|
|
|
|
|
* to see the actual characters
|
|
|
|
|
*/
|
1999-12-15 04:28:10 +00:00
|
|
|
|
{'<EFBFBD>', ".-"}, /* a */
|
|
|
|
|
{'<EFBFBD>', "-..."}, /* be */
|
|
|
|
|
{'<EFBFBD>', ".--"}, /* ve */
|
|
|
|
|
{'<EFBFBD>', "--."}, /* ge */
|
|
|
|
|
{'<EFBFBD>', "-.."}, /* de */
|
|
|
|
|
{'<EFBFBD>', "."}, /* ye */
|
|
|
|
|
{'<EFBFBD>', "."}, /* yo, the same as ye */
|
|
|
|
|
{'<EFBFBD>', "...-"}, /* she */
|
|
|
|
|
{'<EFBFBD>', "--.."}, /* ze */
|
|
|
|
|
{'<EFBFBD>', ".."}, /* i */
|
|
|
|
|
{'<EFBFBD>', ".---"}, /* i kratkoye */
|
|
|
|
|
{'<EFBFBD>', "-.-"}, /* ka */
|
|
|
|
|
{'<EFBFBD>', ".-.."}, /* el */
|
|
|
|
|
{'<EFBFBD>', "--"}, /* em */
|
|
|
|
|
{'<EFBFBD>', "-."}, /* en */
|
|
|
|
|
{'<EFBFBD>', "---"}, /* o */
|
|
|
|
|
{'<EFBFBD>', ".--."}, /* pe */
|
|
|
|
|
{'<EFBFBD>', ".-."}, /* er */
|
|
|
|
|
{'<EFBFBD>', "..."}, /* es */
|
|
|
|
|
{'<EFBFBD>', "-"}, /* te */
|
|
|
|
|
{'<EFBFBD>', "..-"}, /* u */
|
|
|
|
|
{'<EFBFBD>', "..-."}, /* ef */
|
|
|
|
|
{'<EFBFBD>', "...."}, /* kha */
|
|
|
|
|
{'<EFBFBD>', "-.-."}, /* ce */
|
|
|
|
|
{'<EFBFBD>', "---."}, /* che */
|
|
|
|
|
{'<EFBFBD>', "----"}, /* sha */
|
|
|
|
|
{'<EFBFBD>', "--.-"}, /* shcha */
|
|
|
|
|
{'<EFBFBD>', "-.--"}, /* yi */
|
|
|
|
|
{'<EFBFBD>', "-..-"}, /* myakhkij znak */
|
|
|
|
|
{'<EFBFBD>', "..-.."}, /* ae */
|
|
|
|
|
{'<EFBFBD>', "..--"}, /* yu */
|
|
|
|
|
{'<EFBFBD>', ".-.-"}, /* ya */
|
|
|
|
|
|
|
|
|
|
{'\0', ""}
|
1994-09-04 04:03:31 +00:00
|
|
|
|
};
|
|
|
|
|
|
1995-08-27 14:06:15 +00:00
|
|
|
|
void show(const char *), play(const char *), morse(char);
|
2000-02-27 01:21:28 +00:00
|
|
|
|
void ttyout(const char *);
|
|
|
|
|
void sighandler(int);
|
|
|
|
|
|
|
|
|
|
#define GETOPTOPTS "d:ef:sw:"
|
|
|
|
|
#define USAGE \
|
|
|
|
|
"usage: morse [-s] [-e] [-d device] [-w speed] [-f frequency] [string ...]\n"
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
2000-02-27 01:21:28 +00:00
|
|
|
|
static int pflag, sflag, eflag;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
static int wpm = 20; /* words per minute */
|
|
|
|
|
#define FREQUENCY 600
|
|
|
|
|
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)
|
|
|
|
|
static float dot_clock;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
int spkr, line;
|
|
|
|
|
struct termios otty, ntty;
|
|
|
|
|
int olflags;
|
|
|
|
|
|
|
|
|
|
#ifdef SPEAKER
|
1995-08-27 14:06:15 +00:00
|
|
|
|
tone_t sound;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
#undef GETOPTOPTS
|
|
|
|
|
#define GETOPTOPTS "d:ef:psw:"
|
|
|
|
|
#undef USAGE
|
|
|
|
|
#define USAGE \
|
|
|
|
|
"usage: morse [-s] [-p] [-e] [-d device] [-w speed] [-f frequency] [string ...]\n"
|
1995-08-27 14:06:15 +00:00
|
|
|
|
#endif
|
1994-09-04 04:03:31 +00:00
|
|
|
|
|
1999-12-15 04:28:10 +00:00
|
|
|
|
static const struct morsetab *hightab = iso8859tab;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
main(int argc, char **argv)
|
1994-09-04 04:03:31 +00:00
|
|
|
|
{
|
2000-02-27 01:21:28 +00:00
|
|
|
|
int ch, lflags;
|
1999-11-16 02:58:06 +00:00
|
|
|
|
char *p;
|
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) {
|
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;
|
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
|
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:
|
2000-02-27 01:21:28 +00:00
|
|
|
|
fputs(USAGE, stderr);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
if ((pflag || device) && sflag) {
|
|
|
|
|
fputs("morse: only one of -p, -d and -s allowed\n", stderr);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
if ((pflag || device) && ((wpm < 1) || (wpm > 60))) {
|
1995-08-27 14:06:15 +00:00
|
|
|
|
fputs("morse: insane speed\n", stderr);
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
if ((pflag || device) && (freq == 0))
|
1995-08-27 14:06:15 +00:00
|
|
|
|
freq = FREQUENCY;
|
|
|
|
|
|
|
|
|
|
#ifdef SPEAKER
|
|
|
|
|
if (pflag) {
|
|
|
|
|
if ((spkr = open(SPEAKER, O_WRONLY, 0)) == -1) {
|
|
|
|
|
perror(SPEAKER);
|
1994-09-04 04:03:31 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
} else
|
|
|
|
|
#endif
|
|
|
|
|
if (device) {
|
|
|
|
|
if ((line = open(device, O_WRONLY | O_NONBLOCK)) == -1) {
|
|
|
|
|
perror("open tty line");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
if (tcgetattr(line, &otty) == -1) {
|
|
|
|
|
perror("tcgetattr() failed");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
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 */
|
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
|
1994-09-04 04:03:31 +00:00
|
|
|
|
argc -= optind;
|
|
|
|
|
argv += optind;
|
|
|
|
|
|
1997-09-01 13:58:22 +00:00
|
|
|
|
if((p = getenv("LC_CTYPE")) ||
|
|
|
|
|
(p = getenv("LC_ALL")) ||
|
|
|
|
|
(p = getenv("LANG"))) {
|
|
|
|
|
if(strlen(p) >= sizeof(".KOI8-R") &&
|
|
|
|
|
strcasecmp(&p[strlen(p) + 1 - sizeof(".KOI8-R")], ".KOI8-R") == 0)
|
1995-08-27 14:06:15 +00:00
|
|
|
|
hightab = koi8rtab;
|
|
|
|
|
}
|
1997-09-01 13:58:22 +00:00
|
|
|
|
(void) setlocale(LC_CTYPE, "");
|
1995-08-27 14:06:15 +00:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
1995-08-27 14:06:15 +00:00
|
|
|
|
void
|
|
|
|
|
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 == ' ') {
|
|
|
|
|
if (pflag) {
|
|
|
|
|
play(" ");
|
|
|
|
|
return;
|
2000-02-27 01:21:28 +00:00
|
|
|
|
} else if (device) {
|
|
|
|
|
ttyout(" ");
|
|
|
|
|
return;
|
1995-08-27 14:06:15 +00:00
|
|
|
|
} else {
|
|
|
|
|
show("");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (m = ((unsigned char)c < 0x80? mtab: hightab);
|
|
|
|
|
m->inchar != '\0';
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
1995-08-27 14:06:15 +00:00
|
|
|
|
void
|
|
|
|
|
show(const char *s)
|
1994-09-04 04:03:31 +00:00
|
|
|
|
{
|
|
|
|
|
if (sflag)
|
|
|
|
|
printf(" %s", s);
|
1995-08-27 14:06:15 +00:00
|
|
|
|
else
|
|
|
|
|
for (; *s; ++s)
|
|
|
|
|
printf(" %s", *s == '.' ? "dit" : "dah");
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
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;
|
|
|
|
|
sound.duration = dot_clock * WORD_SPACE;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
sound.duration = 0;
|
|
|
|
|
}
|
|
|
|
|
if (sound.duration) {
|
|
|
|
|
if (ioctl(spkr, SPKRTONE, &sound) == -1) {
|
|
|
|
|
perror("ioctl play");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sound.frequency = 0;
|
|
|
|
|
sound.duration = dot_clock;
|
|
|
|
|
if (ioctl(spkr, SPKRTONE, &sound) == -1) {
|
|
|
|
|
perror("ioctl rest");
|
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sound.frequency = 0;
|
|
|
|
|
sound.duration = dot_clock * CHAR_SPACE;
|
|
|
|
|
ioctl(spkr, SPKRTONE, &sound);
|
|
|
|
|
#endif
|
1994-09-04 04:03:31 +00:00
|
|
|
|
}
|
2000-02-27 01:21:28 +00:00
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
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;
|
|
|
|
|
duration = dot_clock * WORD_SPACE;
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
duration = dot_clock * CHAR_SPACE * 10000;
|
|
|
|
|
usleep(duration);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
sighandler(int signo)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
ioctl(line, TIOCMSET, &olflags);
|
|
|
|
|
tcsetattr(line, TCSANOW, &otty);
|
|
|
|
|
|
|
|
|
|
signal(signo, SIG_DFL);
|
|
|
|
|
(void)kill(getpid(), signo);
|
|
|
|
|
}
|