|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1988 Regents of the University of California. ! 3: * All rights reserved. ! 4: * ! 5: * Redistribution and use in source and binary forms are permitted ! 6: * provided that: (1) source distributions retain this entire copyright ! 7: * notice and comment, and (2) distributions including binaries display ! 8: * the following acknowledgement: ``This product includes software ! 9: * developed by the University of California, Berkeley and its contributors'' ! 10: * in the documentation or other materials provided with the distribution ! 11: * and in all advertising materials mentioning features or use of this ! 12: * software. Neither the name of the University nor the names of its ! 13: * contributors may be used to endorse or promote products derived ! 14: * from this software without specific prior written permission. ! 15: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR ! 16: * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED ! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. ! 18: */ ! 19: ! 20: #ifndef lint ! 21: char copyright[] = ! 22: "@(#) Copyright (c) 1988 Regents of the University of California.\n\ ! 23: All rights reserved.\n"; ! 24: #endif /* not lint */ ! 25: ! 26: #ifndef lint ! 27: static char sccsid[] = "@(#)morse.c 5.2 (Berkeley) 6/1/90"; ! 28: #endif /* not lint */ ! 29: ! 30: #include <stdio.h> ! 31: #include <ctype.h> ! 32: ! 33: static char ! 34: *digit[] = { ! 35: "-----", ! 36: ".----", ! 37: "..---", ! 38: "...--", ! 39: "....-", ! 40: ".....", ! 41: "-....", ! 42: "--...", ! 43: "---..", ! 44: "----.", ! 45: }, ! 46: *alph[] = { ! 47: ".-", ! 48: "-...", ! 49: "-.-.", ! 50: "-..", ! 51: ".", ! 52: "..-.", ! 53: "--.", ! 54: "....", ! 55: "..", ! 56: ".---", ! 57: "-.-", ! 58: ".-..", ! 59: "--", ! 60: "-.", ! 61: "---", ! 62: ".--.", ! 63: "--.-", ! 64: ".-.", ! 65: "...", ! 66: "-", ! 67: "..-", ! 68: "...-", ! 69: ".--", ! 70: "-..-", ! 71: "-.--", ! 72: "--..", ! 73: }; ! 74: ! 75: static int sflag; ! 76: ! 77: main(argc, argv) ! 78: int argc; ! 79: char **argv; ! 80: { ! 81: extern char *optarg; ! 82: extern int optind; ! 83: register int ch; ! 84: register char *p; ! 85: ! 86: while ((ch = getopt(argc, argv, "s")) != EOF) ! 87: switch((char)ch) { ! 88: case 's': ! 89: sflag = 1; ! 90: break; ! 91: case '?': ! 92: default: ! 93: fprintf(stderr, "usage: morse [string ...]"); ! 94: exit(1); ! 95: } ! 96: argc -= optind; ! 97: argv += optind; ! 98: ! 99: if (*argv) ! 100: do { ! 101: for (p = *argv; *p; ++p) ! 102: morse((int)*p); ! 103: } while (*++argv); ! 104: else while ((ch = getchar()) != EOF) ! 105: morse(ch); ! 106: } ! 107: ! 108: static ! 109: morse(c) ! 110: register int c; ! 111: { ! 112: if (isalpha(c)) ! 113: show(alph[c - (isupper(c) ? 'A' : 'a')]); ! 114: else if (isdigit(c)) ! 115: show(digit[c - '0']); ! 116: else if (c == ',') ! 117: show("--..--"); ! 118: else if (c == '.') ! 119: show(".-.-.-"); ! 120: else if (isspace(c)) ! 121: show(" ...\n"); ! 122: } ! 123: ! 124: static ! 125: show(s) ! 126: register char *s; ! 127: { ! 128: if (sflag) ! 129: printf(" %s", s); ! 130: else for (; *s; ++s) ! 131: printf(" %s", *s == '.' ? "dit" : "daw"); ! 132: printf(",\n"); ! 133: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.