comparison nnchat.c @ 59:d57a8acf92bf

Remove morse code mode.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 11 Nov 2008 21:30:05 +0200
parents 5455d078bedd
children b802a799c31a
comparison
equal deleted inserted replaced
58:5455d078bedd 59:d57a8acf92bf
56 BOOL optDaemon = FALSE; 56 BOOL optDaemon = FALSE;
57 FILE *optLogFile = NULL; 57 FILE *optLogFile = NULL;
58 WINDOW *mainWin = NULL, 58 WINDOW *mainWin = NULL,
59 *statusWin = NULL, 59 *statusWin = NULL,
60 *editWin = NULL; 60 *editWin = NULL;
61 BOOL setPrvMode = FALSE, 61 BOOL setPrvMode = FALSE;
62 setMorseMode = FALSE;
63
64 62
65 /* Arguments 63 /* Arguments
66 */ 64 */
67 optarg_t optList[] = { 65 optarg_t optList[] = {
68 { 0, '?', "help", "Show this help", OPT_NONE }, 66 { 0, '?', "help", "Show this help", OPT_NONE },
554 return FALSE; 552 return FALSE;
555 553
556 strcpy(*buf + *pos, str); 554 strcpy(*buf + *pos, str);
557 (*pos) += tmpLen; 555 (*pos) += tmpLen;
558 return TRUE; 556 return TRUE;
559 }
560
561
562 typedef struct {
563 char c;
564 char *code;
565 } conv_ent_t;
566
567 conv_ent_t morseTab[] = {
568 { ' ', " / " },
569 { 'A', ".-" },
570 { 'B', "-..." },
571 { 'C', "-.-." },
572 { 'D', "-.." },
573 { 'E', "." },
574 { 'F', "..-." },
575 { 'G', "--." },
576 { 'H', "...." },
577 { 'I', ".." },
578 { 'J', ".---" },
579 { 'K', "-.-" },
580 { 'L', ".-.." },
581 { 'M', "--" },
582 { 'N', "-." },
583 { 'O', "---" },
584 { 'P', ".--." },
585 { 'Q', "--.-" },
586 { 'R', ".-." },
587 { 'S', "..." },
588 { 'T', "-" },
589 { 'U', "..-" },
590 { 'V', "...-" },
591 { 'W', ".--" },
592 { 'X', "-..-" },
593 { 'Y', "-.--" },
594 { 'Z', "--.." },
595 { '0', "-----" },
596 { '1', ".----" },
597 { '2', "..---" },
598 { '3', "...--" },
599 { '4', "....-" },
600 { '5', "....." },
601 { '6', "-...." },
602 { '7', "--..." },
603 { '8', "---.." },
604 { '9', "----." },
605 { '.', ".-.-.-" },
606 { ',', "--..--" },
607 { '?', "..--.." },
608 };
609
610
611 char * conv2tab(conv_ent_t *tab, size_t ntab, char *str)
612 {
613 char *result, *s = str;
614 size_t resSize, resPos = 0;
615
616 if (!str) return NULL;
617
618 resSize = (strlen(str) * 4) + SET_ALLOC_SIZE;
619 if ((result = th_malloc(resSize)) == NULL)
620 return NULL;
621
622 while (*s) {
623 size_t i;
624 char c = toupper(*s);
625 BOOL found = FALSE;
626 for (i = 0; i < ntab; i++)
627 if (tab[i].c == c) {
628 PUSHSTR(tab[i].code);
629 PUSHCHAR(' ');
630 found = TRUE;
631 break;
632 }
633 if (!found) PUSHCHAR(*s);
634
635 s++;
636 }
637 PUSHCHAR(0);
638
639 return result;
640 }
641
642
643 char * tab2str(conv_ent_t *tab, size_t ntab, char *str)
644 {
645 char *result, *s = str;
646 size_t resSize, resPos = 0;
647
648 if (!str) return NULL;
649
650 resSize = (strlen(str) * 4) + SET_ALLOC_SIZE;
651 if ((result = th_malloc(resSize)) == NULL)
652 return NULL;
653
654 while (*s) {
655 size_t i;
656 BOOL found = FALSE;
657 for (i = 0; i < ntab; i++) {
658 size_t len = strlen(tab[i].code);
659 if (!strcmp(s, tab[i].code) && s[len] == ' ') {
660 s += len;
661 PUSHCHAR(tab[i].c);
662 found = TRUE;
663 break;
664 }
665 }
666 if (!found) PUSHCHAR(*s);
667
668 s++;
669 }
670 PUSHCHAR(0);
671
672 return result;
673 } 557 }
674 558
675 559
676 char *encodeStr1(char *str) 560 char *encodeStr1(char *str)
677 { 561 {
934 th_free(h); 818 th_free(h);
935 th_free(t); 819 th_free(t);
936 } else { 820 } else {
937 t = stripTags(s); 821 t = stripTags(s);
938 h = decodeStr2(t); 822 h = decodeStr2(t);
939 if (setMorseMode) {
940 th_free(t); t = h;
941 h = tab2str(morseTab, sizeof(morseTab) / sizeof(morseTab[0]), t);
942 }
943 printMsg("½5½<½%d½%s½5½>½0½ %s\n", strcmp(p, optUserName) ? 15 : 14, p, h); 823 printMsg("½5½<½%d½%s½5½>½0½ %s\n", strcmp(p, optUserName) ? 15 : 14, p, h);
944 th_free(h); 824 th_free(h);
945 th_free(t); 825 th_free(t);
946 } 826 }
947 827
1108 } else { 988 } else {
1109 printMsg("No target set, exiting prv mode.\n"); 989 printMsg("No target set, exiting prv mode.\n");
1110 setPrvMode = FALSE; 990 setPrvMode = FALSE;
1111 return 1; 991 return 1;
1112 } 992 }
1113 } else if (buf[0] != '/') { 993 }
1114 if (setMorseMode) {
1115 tmpStr = conv2tab(morseTab, sizeof(morseTab) / sizeof(morseTab[0]), buf);
1116 strncpy(tmpBuf, tmpStr, sizeof(tmpBuf));
1117 tmpBuf[sizeof(tmpBuf)-1] = 0;
1118 th_free(tmpStr);
1119 buf = tmpBuf;
1120 }
1121 }
1122
1123 994
1124 995
1125 /* Send double-encoded */ 996 /* Send double-encoded */
1126 tmpStr = encodeStr2(buf); 997 tmpStr = encodeStr2(buf);
1127 if (!tmpStr) return -2; 998 if (!tmpStr) return -2;
1454 case 0x10a: /* F2 = Clear editbuffer */ 1325 case 0x10a: /* F2 = Clear editbuffer */
1455 clearBuf(editBuf); 1326 clearBuf(editBuf);
1456 update = TRUE; 1327 update = TRUE;
1457 break; 1328 break;
1458 1329
1459 case 0x10b: /* F3 = Toggle special mode */
1460 setMorseMode = !setMorseMode;
1461 printMsg("Morse code mode = %d\n", setMorseMode);
1462 update = TRUE;
1463 break;
1464
1465 case KEY_HOME: setBufPos(editBuf, 0); update = TRUE; break; 1330 case KEY_HOME: setBufPos(editBuf, 0); update = TRUE; break;
1466 case KEY_END: setBufPos(editBuf, editBuf->len); update = TRUE; break; 1331 case KEY_END: setBufPos(editBuf, editBuf->len); update = TRUE; break;
1467 case KEY_LEFT: setBufPos(editBuf, editBuf->pos - 1); update = TRUE; break; 1332 case KEY_LEFT: setBufPos(editBuf, editBuf->pos - 1); update = TRUE; break;
1468 case KEY_RIGHT: setBufPos(editBuf, editBuf->pos + 1); update = TRUE; break; 1333 case KEY_RIGHT: setBufPos(editBuf, editBuf->pos + 1); update = TRUE; break;
1469 1334