File:  [Research Unix] / researchv10no / games / morse.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 17:21:35 2018 UTC (8 years, 1 month ago) by root
Branches: belllabs, MAIN
CVS tags: researchv10, HEAD
researchv10 Norman

#include <stdio.h>
#include <ctype.h>

char	*dit	= "dit";
char	*daw	= "daw";

char	*digit[] = {
	"-----",
	".----",
	"..---",
	"...--",
	"....-",
	".....",
	"-....",
	"--...",
	"---..",
	"----.",
	0
};

char *alph[] = {
	".-",
	"-...",
	"-.-.",
	"-..",
	".",
	"..-.",
	"--.",
	"....",
	"..",
	".---",
	"-.-",
	".-..",
	"--",
	"-.",
	"---",
	".--.",
	"--.-",
	".-.",
	"...",
	"-",
	"..-",
	"...-",
	".--",
	"-..-",
	"-.--",
	"--..",
	0};

main() {

	register c;

	while ((c = getchar()) != EOF) {
		if (isupper(c))
			c = tolower(c);
		if (isalpha(c))
			print(alph[c-'a']);
		else if (isdigit(c))
			print(digit[c-'0']);
		else if (c == ',')
			print("--..--");
		else if (c == '.')
			print(".-.-.-");
		else if (isspace(c))
			printf(" ...\n");
	}
}

print(s) char *s; {
	char *p;
	for (p = s; *p; p++)
		if (*p == '.')
			printf(" %s", dit);
		else if (*p == '-')
			printf(" %s", daw);
	printf(",\n");
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.