1 /* Convert ASCII to morse code. Reads from stdin if provided with no argument
2 or "-", otherwise reads from the first command line argument. Prints "?" if
3 character is not found. */
10 const char *aa[] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
11 "k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
12 "u", "v", "w", "x", "y", "z", "1", "2", "3", "4",
13 "5", "6", "7", "8", "9", "0", " "};
15 const char *ma[] = {"•-", "-•••", "-•-•", "-••", "•", "••-•", "--•",
16 "••••", "••", "•---", "-•-", "•-••", "--", "-•",
17 "---", "•--•", "--•-", "•-•", "•••", "-", "•--",
18 "•••-", "•--", "-••-", "-•--", "--••", "•----",
19 "••---", "•••--", "••••-", "•••••", "-••••",
20 "--•••", "---••", "----•", "-----", " "};
25 if (strcmp(c, "\n") == 0) {
30 for (int i = 0; aa[i]; i++) {
31 if (strcmp(c, aa[i]) == 0) {
34 } else if (i == sizeof(aa)/sizeof(char *) - 1) {
42 main(int argc, char **argv)
47 if (argv[1] && strcmp(argv[1], "-") != 0) {
48 for (int i = 0; argv[1][i]; i++) {
53 while (read(STDIN_FILENO, &c[0], 1) > 0) {