From p@i609a.hadiko.de  Tue Feb 19 02:46:16 2002
Return-Path: <p@i609a.hadiko.de>
Received: from mailgate.rz.uni-karlsruhe.de (mailgate.rz.uni-karlsruhe.de [129.13.64.97])
	by hub.freebsd.org (Postfix) with ESMTP id B896C37B404
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 19 Feb 2002 02:46:15 -0800 (PST)
Received: from nce2.hadiko.de (hadince2.hadiko.uni-karlsruhe.de [172.20.32.2])
	by mailgate.rz.uni-karlsruhe.de with esmtp (Exim 3.33 #1)
	id 16d7mo-0006RH-00; Tue, 19 Feb 2002 11:46:14 +0100
Received: from i609a.hadiko.de (hadii609a.hadiko.uni-karlsruhe.de [172.20.49.159])
	by nce2.hadiko.de (8.11.3/8.11.3) with ESMTP id g1JAkDx29324
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 19 Feb 2002 11:46:13 +0100 (MET)
Received: (from p@localhost)
	by i609a.hadiko.de (8.11.6/8.11.4) id g1JAk9R05228;
	Tue, 19 Feb 2002 11:46:10 +0100 (CET)
	(envelope-from p)
Message-Id: <200202191046.g1JAk9R05228@i609a.hadiko.de>
Date: Tue, 19 Feb 2002 11:46:10 +0100 (CET)
From: Philipp Mergenthaler <philipp.mergenthaler@stud.uni-karlsruhe.de>
Reply-To: Philipp Mergenthaler <philipp.mergenthaler@stud.uni-karlsruhe.de>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] games/morse: add ability to decode morse code
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         35109
>Category:       bin
>Synopsis:       [patch] morse(6) add ability to decode morse code
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    edwin
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Feb 19 02:50:01 PST 2002
>Closed-Date:    
>Last-Modified:  Mon Aug 04 12:10:25 UTC 2008
>Originator:     Philipp Mergenthaler
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
University of Karlsruhe
>Environment:
System: FreeBSD i609a.hadiko.de 5.0-CURRENT FreeBSD 5.0-CURRENT #474: Mon Feb 18 21:56:26 CET 2002 p@i609a.hadiko.de:/usr/src/sys/i386/compile/I609 i386


>Description:
The first patch adds the option "-D" to morse(6) to decode morse code
(consisting of dots and dashes) that is given as command line arguments
or on the standard input.  This is inspired by and partially taken from
NetBSD's morse(6).
It's somewhat enhanced though - you can give several letters per command
line argument and it deals correctly with long lines when reading from
standard input.

The second patch adds codes for three characters: underline, apostrophe
and  (n with tilde).


>How-To-Repeat:
>Fix:

Index: morse.6
===================================================================
RCS file: /ncvs/src/games/morse/morse.6,v
retrieving revision 1.10
diff -u -r1.10 morse.6
--- morse.6	7 Aug 2001 15:48:28 -0000	1.10
+++ morse.6	19 Feb 2002 04:14:32 -0000
@@ -74,13 +74,18 @@
 .Fl p ,
 but use the RTS line of
 .Ar device
-(which must by a tty device)
+(which must be a tty device)
 in order to emit the morse code.
 .It Fl e
 echo each character before it is sent, used together with either
 .Fl p
 or
 .Fl d .
+.It Fl D
+Decode morse output consisting of dots and dashes (as generated by using
+the
+.Fl s
+option).
 .El
 .Pp
 The
Index: morse.c
===================================================================
RCS file: /ncvs/src/games/morse/morse.c,v
retrieving revision 1.14
diff -u -r1.14 morse.c
--- morse.c	26 Jun 2001 01:43:52 -0000	1.14
+++ morse.c	19 Feb 2002 09:50:38 -0000
@@ -198,15 +198,17 @@
 	{'\0', ""}
 };
 
-void            show(const char *), play(const char *), morse(char);
+void            show(const char *), play(const char *), morse(char),
+		    decode (char *), fdecode(FILE *);
 void		ttyout(const char *);
 void		sighandler(int);
 
-#define GETOPTOPTS "d:ef:sw:"
+#define GETOPTOPTS "d:ef:sw:D"
 #define USAGE \
-"usage: morse [-s] [-e] [-d device] [-w speed] [-f frequency] [string ...]\n"
+"usage: morse [-s] [-e] [-D] [-d device] [-w speed] [-f frequency] [string ...]\n"
+#define WHITESPACE " \t\n"
 
-static int      pflag, sflag, eflag;
+static int      pflag, sflag, eflag, dflag;
 static int      wpm = 20;	/* words per minute */
 #define FREQUENCY 600
 static int      freq = FREQUENCY;
@@ -223,10 +225,10 @@
 #ifdef SPEAKER
 tone_t          sound;
 #undef GETOPTOPTS
-#define GETOPTOPTS "d:ef:psw:"
+#define GETOPTOPTS "d:ef:psw:D"
 #undef USAGE
 #define USAGE \
-"usage: morse [-s] [-p] [-e] [-d device] [-w speed] [-f frequency] [string ...]\n"
+"usage: morse [-s] [-p] [-e] [-D] [-d device] [-w speed] [-f frequency] [string ...]\n"
 #endif
 
 static const struct morsetab *hightab;
@@ -242,6 +244,9 @@
 		case 'd':
 			device = optarg;
 			break;
+		case 'D':
+			dflag = 1;
+			break;
 		case 'e':
 			eflag = 1;
 			setvbuf(stdout, 0, _IONBF, 0);
@@ -328,22 +333,42 @@
 			hightab = iso8859tab;
 	}
 
-	if (*argv) {
-		do {
-			for (p = *argv; *p; ++p) {
+	if (dflag) {
+		if (*argv) {
+			do {
+				p=strtok(*argv, " \t");
+				if (p == NULL)
+					decode(*argv);
+				else {
+					while (p) {
+						decode(p);
+						p=strtok(NULL, " \t");
+					}
+				}
+			} while (*++argv);
+			putchar('\n');
+		} else 
+			fdecode(stdin);
+
+
+	} else {
+		if (*argv) {
+			do {
+				for (p = *argv; *p; ++p) {
+					if (eflag)
+						putchar(*p);
+					morse(*p);
+				}
 				if (eflag)
-					putchar(*p);
-				morse(*p);
+					putchar(' ');
+				morse(' ');
+			} while (*++argv);
+		} else {
+			while ((ch = getchar()) != EOF) {
+				if (eflag)
+					putchar(ch);
+				morse(ch);
 			}
-			if (eflag)
-				putchar(' ');
-			morse(' ');
-		} while (*++argv);
-	} else {
-		while ((ch = getchar()) != EOF) {
-			if (eflag)
-				putchar(ch);
-			morse(ch);
 		}
 	}
 	if (device)
@@ -490,4 +515,69 @@
 
 	signal(signo, SIG_DFL);
 	(void)kill(getpid(), signo);
+}
+
+void
+fdecode(FILE *stream)
+{
+	char *n, *p, *s;
+	char buf[BUFSIZ];
+
+	s=buf;
+	while (fgets(s, BUFSIZ - (s - buf), stdin)) {
+		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);
 }








--- morse.c	Tue Feb 19 11:19:09 2002
+++ morse.c.new	Tue Feb 19 11:21:42 2002
@@ -130,6 +130,8 @@
 	{')', "-.--.-"},
 	{'$', "...-..-"},
 	{'+', ".-.-."},		/* AR */
+	{'_', "..--.-"},
+	{'\'', ".---."},
 
 	/* prosigns without already assigned values */
 
@@ -151,6 +153,7 @@
 	{'', "..-.."},
 	{'', "..-.."},
 	{'', "-..-."},
+	{'', "--.--"},
 	{'', "---."},
 	{'', "..--"},
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->edwin 
Responsible-Changed-By: edwin 
Responsible-Changed-When: Mon Aug 4 12:10:05 UTC 2008 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=35109 
>Unformatted:
