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", "k", "l",
11 "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "1",
12 "2", "3", "4", "5", "6", "7", "8", "9", "0", " "};
14 const char *ma[] = {"•-", "-•••", "-•-•", "-••", "•", "••-•", "--•", "••••",
15 "••", "•---", "-•-", "•-••", "--", "-•", "---", "•--•", "--•-", "•-•", "•••",
16 "-", "•--", "•••-", "•--", "-••-", "-•--", "--••", "•----", "••---", "•••--",
17 "••••-", "•••••", "-••••", "--•••", "---••", "----•", "-----", " "};
22 if (strcmp(c, "\n") == 0) {
27 for (int i = 0; aa[i]; i++) {
28 if (strcmp(c, aa[i]) == 0) {
31 } else if (i == sizeof(aa)/sizeof(char *) - 1) {
39 main(int argc, char **argv)
44 if (argv[1] && strcmp(argv[1], "-") != 0) {
45 for (int i = 0; argv[1][i]; i++) {
50 while (read(STDIN_FILENO, &c[0], 1) > 0) {