diff options
author | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-03-12 06:49:18 +0000 |
---|---|---|
committer | Paul Janzen <pjanzen@cvs.openbsd.org> | 1998-03-12 06:49:18 +0000 |
commit | ac54e66959b292a0811592a74940f1ff6c30b07e (patch) | |
tree | 877530ffd98e150df0b81ce6187ec88fe3a02acc | |
parent | 10103488ed19c2a890b41f03f0039d49fe669c99 (diff) |
More characters, better handling of white space
-rw-r--r-- | games/morse/morse.c | 79 |
1 files changed, 62 insertions, 17 deletions
diff --git a/games/morse/morse.c b/games/morse/morse.c index 26eb4c7a996..67e6b61e172 100644 --- a/games/morse/morse.c +++ b/games/morse/morse.c @@ -47,8 +47,9 @@ static char rcsid[] = "$NetBSD: morse.c,v 1.3 1995/03/23 08:35:24 cgd Exp $"; #endif #endif /* not lint */ -#include <stdio.h> #include <ctype.h> +#include <stdio.h> +#include <unistd.h> static char *digit[] = { @@ -92,29 +93,31 @@ static char "--..", }; -static int sflag; +void morse __P((int)); +void show __P((char *)); + +static int sflag = 0; +int main(argc, argv) int argc; char **argv; { - extern char *optarg; - extern int optind; - register int ch; - register char *p; + int ch; + char *p; /* revoke */ setegid(getgid()); setgid(getgid()); - while ((ch = getopt(argc, argv, "s")) != -1) + while ((ch = getopt(argc, argv, "hs")) != -1) switch((char)ch) { case 's': sflag = 1; break; - case '?': + case '?': case 'h': default: - fprintf(stderr, "usage: morse [string ...]"); + fprintf(stderr, "usage: morse [-s] [string ...]"); exit(1); } argc -= optind; @@ -124,32 +127,74 @@ main(argc, argv) do { for (p = *argv; *p; ++p) morse((int)*p); + show(""); } while (*++argv); else while ((ch = getchar()) != EOF) morse(ch); + show("...-.-"); /* SK */ + exit(0); } +void morse(c) - register int c; + int c; { if (isalpha(c)) show(alph[c - (isupper(c) ? 'A' : 'a')]); else if (isdigit(c)) show(digit[c - '0']); - else if (c == ',') - show("--..--"); - else if (c == '.') - show(".-.-.-"); else if (isspace(c)) - show(" ...\n"); + show(""); /* could show BT for a pause */ + else switch((char)c) { + case ',': + show("--..--"); + break; + case '.': + show(".-.-.-"); + break; + case '?': + show("..--.."); + break; + case '/': + show("-..-."); + break; + case '-': + show("-....-"); + break; + case ':': + show("---..."); + break; + case ';': + show("-.-.-."); + break; + case '(': case ')': + show("-.--.-."); + break; + case '`': case '"': + show(".-..-."); + break; + case '\'': + show(".----."); + break; + case '+': /* AR */ + show(".-.-."); + break; + case '=': /* BT */ + show("-...-"); + break; + case '@': /* SK */ + show("...-.-"); + break; + } } +void show(s) - register char *s; + char *s; { if (sflag) printf(" %s", s); else for (; *s; ++s) printf(" %s", *s == '.' ? "dit" : "daw"); - printf(",\n"); + printf("\n"); } |