summaryrefslogtreecommitdiffstats
path: root/games
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2003-11-03 11:05:43 +0000
committerphk <phk@FreeBSD.org>2003-11-03 11:05:43 +0000
commita401023210452d532b84adeccad1013b81719af2 (patch)
tree6ecdd48cec628c16a34fea121a4c99f271ab647d /games
parent1333a1f77f0d29c61bfa6fb3e936ca39f586c2c7 (diff)
downloadFreeBSD-src-a401023210452d532b84adeccad1013b81719af2.zip
FreeBSD-src-a401023210452d532b84adeccad1013b81719af2.tar.gz
Add a '-l' option suitable for use with /dev/led/* lamps.
Diffstat (limited to 'games')
-rw-r--r--games/morse/morse.65
-rw-r--r--games/morse/morse.c45
2 files changed, 33 insertions, 17 deletions
diff --git a/games/morse/morse.6 b/games/morse/morse.6
index 1e3b68b..21be6c9 100644
--- a/games/morse/morse.6
+++ b/games/morse/morse.6
@@ -46,6 +46,7 @@
.Op Fl e
.Op Fl w Ar speed
.Op Fl f Ar frequency
+.Op Fl l
.Op Fl s
.Op Ar string ...
.Sh DESCRIPTION
@@ -56,6 +57,10 @@ Acceptable input are command line arguments or the standard input.
.Pp
Available options:
.Bl -tag -width flag
+.It Fl l
+The
+.Fl l
+option produces output suitable for led(4) devices.
.It Fl s
The
.Fl s
diff --git a/games/morse/morse.c b/games/morse/morse.c
index 832228d..3b7a404 100644
--- a/games/morse/morse.c
+++ b/games/morse/morse.c
@@ -202,11 +202,11 @@ void show(const char *), play(const char *), morse(char);
void ttyout(const char *);
void sighandler(int);
-#define GETOPTOPTS "d:ef:sw:"
+#define GETOPTOPTS "d:ef:lsw:"
#define USAGE \
-"usage: morse [-s] [-e] [-d device] [-w speed] [-f frequency] [string ...]\n"
+"usage: morse [-els] [-d device] [-w speed] [-f frequency] [string ...]\n"
-static int pflag, sflag, eflag;
+static int pflag, lflag, sflag, eflag;
static int wpm = 20; /* words per minute */
#define FREQUENCY 600
static int freq = FREQUENCY;
@@ -223,7 +223,7 @@ int olflags;
#ifdef SPEAKER
tone_t sound;
#undef GETOPTOPTS
-#define GETOPTOPTS "d:ef:psw:"
+#define GETOPTOPTS "d:ef:lpsw:"
#undef USAGE
#define USAGE \
"usage: morse [-s] [-p] [-e] [-d device] [-w speed] [-f frequency] [string ...]\n"
@@ -249,6 +249,9 @@ main(int argc, char **argv)
case 'f':
freq = atoi(optarg);
break;
+ case 'l':
+ lflag = 1;
+ break;
#ifdef SPEAKER
case 'p':
pflag = 1;
@@ -265,8 +268,12 @@ main(int argc, char **argv)
fputs(USAGE, stderr);
exit(1);
}
- if ((pflag || device) && sflag) {
- fputs("morse: only one of -p, -d and -s allowed\n", stderr);
+ if (sflag && lflag) {
+ fputs("morse: only one of -l and -s allowed\n", stderr);
+ exit(1);
+ }
+ if ((pflag || device) && (sflag || lflag)) {
+ fputs("morse: only one of -p, -d and -l, -s allowed\n", stderr);
exit(1);
}
if ((pflag || device) && ((wpm < 1) || (wpm > 60))) {
@@ -328,6 +335,8 @@ main(int argc, char **argv)
hightab = iso8859tab;
}
+ if (lflag)
+ printf("m");
if (*argv) {
do {
for (p = *argv; *p; ++p) {
@@ -361,16 +370,15 @@ morse(char c)
if ((c == '\r') || (c == '\n'))
c = ' ';
if (c == ' ') {
- if (pflag) {
+ if (pflag)
play(" ");
- return;
- } else if (device) {
+ else if (device)
ttyout(" ");
- return;
- } else {
+ else if (lflag)
+ printf("\n");
+ else
show("");
- return;
- }
+ return;
}
for (m = ((unsigned char)c < 0x80? mtab: hightab);
m != NULL && m->inchar != '\0';
@@ -389,12 +397,15 @@ morse(char c)
void
show(const char *s)
{
- if (sflag)
- printf(" %s", s);
- else
+ if (lflag) {
+ printf("%s ", s);
+ } else if (sflag) {
+ printf(" %s\n", s);
+ } else {
for (; *s; ++s)
printf(" %s", *s == '.' ? "dit" : "dah");
- printf("\n");
+ printf("\n");
+ }
}
void
OpenPOWER on IntegriCloud