From fa195fe7525788b8cb06175e6f1ff6501c25f8ca Mon Sep 17 00:00:00 2001 From: sthen Date: Tue, 19 Jan 2016 23:21:26 +0000 Subject: Teach morse(6) the prosign as '@', as added on May 24, 2004 (the 160th anniversary of the first public Morse telegraph transmission). Support decoding (only; not encoding) of other prosigns, including as we were previously using for '@'. From pjanzen. --- games/morse/morse.6 | 5 +++-- games/morse/morse.c | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'games/morse') diff --git a/games/morse/morse.6 b/games/morse/morse.6 index 63cd4a9f3ce..0a6f42c42b3 100644 --- a/games/morse/morse.6 +++ b/games/morse/morse.6 @@ -1,4 +1,4 @@ -.\" $OpenBSD: morse.6,v 1.2 2016/01/18 11:24:44 sthen Exp $ +.\" $OpenBSD: morse.6,v 1.3 2016/01/19 23:21:26 sthen Exp $ .\" .\" Copyright (c) 1988, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,7 +29,7 @@ .\" .\" @(#)bcd.6 8.1 (Berkeley) 5/31/93 .\" -.Dd $Mdocdate: January 18 2016 $ +.Dd $Mdocdate: January 19 2016 $ .Dt MORSE 6 .Os .Sh NAME @@ -58,6 +58,7 @@ back into text. A lowercase .Sq x is printed for undecipherable input; otherwise, text is returned uppercase. +Many procedural signs can be decoded (though not encoded). If the morse to be translated is given on the command line, it should be preceded by .Sq -- diff --git a/games/morse/morse.c b/games/morse/morse.c index be4d06d6646..ae246ad67e0 100644 --- a/games/morse/morse.c +++ b/games/morse/morse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: morse.c,v 1.20 2016/01/18 11:27:19 sthen Exp $ */ +/* $OpenBSD: morse.c,v 1.21 2016/01/19 23:21:26 sthen Exp $ */ /* * Copyright (c) 1988, 1993 @@ -82,6 +82,7 @@ struct punc { char c; char *morse; } other[] = { + { 'e', "..-.." }, /* accented e - only decodes */ { ',', "--..--" }, { '.', ".-.-.-" }, { '?', "..--.." }, @@ -89,17 +90,34 @@ struct punc { { '-', "-....-" }, { ':', "---..." }, { ';', "-.-.-." }, - { '(', "-.--." }, + { '(', "-.--." }, /* KN */ { ')', "-.--.-" }, { '"', ".-..-." }, { '`', ".-..-." }, { '\'', ".----." }, - { '+', ".-.-." }, /* AR */ - { '=', "-...-" }, /* BT */ - { '@', "...-.-" }, /* SK */ + { '+', ".-.-." }, /* AR \n\n\n */ + { '=', "-...-" }, /* BT \n\n */ + { '@', ".--.-." }, + { '\n', ".-.-" }, /* AA (will only decode) */ { '\0', NULL } }; +struct prosign { + char *c; + char *morse; +} ps[] = { + { "", ".-..." }, /* wait */ + { "", "-.-..-.." }, + { "", "-.-.-" }, /* start */ + { "", "......" }, /* error */ + { "", "......." }, + { "", "........" }, + { "", "...-.-" }, + { "", "...-." }, /* understood */ + { "", "...---..." }, + { NULL, NULL } +}; + void morse(int); void decode(char *); void show(char *); @@ -233,6 +251,15 @@ decode(char *s) } i++; } + i = 0; + while (ps[i].c) { + /* put whitespace around prosigns */ + if (strcmp(ps[i].morse, s) == 0) { + printf(" %s ", ps[i].c); + return; + } + i++; + } putchar('x'); /* line noise */ } -- cgit v1.2.3-59-g8ed1b