Subject: bin/22056: morse doesn't handle spaces properly
To: None <gnats-bugs@gnats.netbsd.org>
From: None <rb-netbsd@bigscarychildren.net>
List: netbsd-bugs
Date: 07/04/2003 10:51:21
>Number:         22056
>Category:       bin
>Synopsis:       morse doesn't handle spaces properly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul 04 14:52:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Rick Byers
>Release:        NetBSD 1.6.1_STABLE
>Organization:
	
>Environment:
	
	
System: NetBSD Apenheul.BigScaryChildren.net 1.6.1_STABLE NetBSD 1.6.1_STABLE (WORMHOLE) #1: Mon Jun 23 22:31:30 EDT 2003 rick@Apenheul.BigScaryChildren.net:/usr/src/sys/arch/i386/compile/WORMHOLE i386
Architecture: i386
Machine: i386
>Description:
	The 'morse' game doesn't handle spaces well.  Spaces are 
 	represented by a longer pause in morse code, which the game
	displays as "..." which is also the morse representation for the
	letter 's'.

>How-To-Repeat:

Apenheul:/usr/games> ./morse -s "a a"
 .-,
  ...
,
 .-,		

Apenheul:/usr/games> ./morse -s "a a" | ./morse -d
as a

Apenheul:/usr/games> ./morse "a a"
 dit daw,
 daw dit dit dit daw,
 dit daw,


Note that "daw dit dit dit daw" is the representation of " ...\n" - the 
game prints any character other than '.' as "daw". "-...-" is the morse 
for the equals character.

>Fix:
The problem is caused by line 244 of morse.c:
         else if (isspace(c))
                show(" ...\n");
and by line 254:
                printf(" %s", *s == '.' ? "dit" : "daw");

http://www.soton.ac.uk/~scp93ch/morse/trans.html 
http://ac6v.com/morseaids.htm#INT

I suggest changing the following patch, which also changes the output 
to a more typical (readable) format where spaces are represented by '/' in 
the dots-and-dashes output and blank lines in the dits-and-dahs output.

Index: morse.c
===================================================================
RCS file: /cvsroot/src/games/morse/morse.c,v
retrieving revision 1.10
diff -c -r1.10 morse.c
*** morse.c	2000/07/03 03:57:42	1.10
--- morse.c	2003/07/04 14:49:28
***************
*** 179,184 ****
--- 179,186 ----
  			morse(ch);
  	}
  	
+ 	if(sflag)
+ 		printf("\n");	
  	return 0;
  }
  
***************
*** 241,247 ****
  	else if (c == '.')
  		show(MORSE_PERIOD);
  	else if (isspace(c))
! 		show(" ...\n");
  }
  
  void
--- 243,249 ----
  	else if (c == '.')
  		show(MORSE_PERIOD);
  	else if (isspace(c))
! 		show("/");
  }
  
  void
***************
*** 250,256 ****
  {
  	if (sflag)
  		printf(" %s", s);
! 	else for (; *s; ++s)
! 		printf(" %s", *s == '.' ? "dit" : "daw");
! 	printf(",\n");
  }
--- 252,264 ----
  {
  	if (sflag)
  		printf(" %s", s);
! 	else {
! 		for (; *s; ++s) {
! 			if( *s == '.' )
! 				printf(" dit");
! 			else if( *s == '-' )
! 				printf(" daw");
! 		}
! 		printf("\n");
! 	}
  }


>Release-Note:
>Audit-Trail:
>Unformatted: