changeset 50:d08bf3b6561d

Use strdup; Added function to decode morse code.
author Matti Hamalainen <ccr@tnsp.org>
date Sun, 02 Nov 2008 18:43:38 +0200
parents 0bcc38910a77
children cf7789d88350
files nnchat.c
diffstat 1 files changed, 42 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Wed Oct 29 02:51:51 2008 +0200
+++ b/nnchat.c	Sun Nov 02 18:43:38 2008 +0200
@@ -189,12 +189,12 @@
 void addRingBuf(ringbuf_t *buf, const char *str)
 {
 	if (buf->n < buf->size) {
-		buf->data[buf->n] = th_strdup(str);
+		buf->data[buf->n] = strdup(str);
 		buf->n++;
 	} else {
 		th_free(buf->data[0]);
 		memmove(&(buf->data[0]), &(buf->data[1]), buf->size - 1);
-		buf->data[buf->size - 1] = th_strdup(str);
+		buf->data[buf->size - 1] = strdup(str);
 	}
 }
 
@@ -625,6 +625,39 @@
 }
 
 
+char * tab2str(conv_ent_t *tab, size_t ntab, char *str)
+{
+	char *result, *s = str;
+	size_t resSize, resPos = 0;
+
+	if (!str) return NULL;
+	
+	resSize = (strlen(str) * 4) + SET_ALLOC_SIZE;
+	if ((result = th_malloc(resSize)) == NULL)
+		return NULL;
+	
+	while (*s) {
+		size_t i;
+		BOOL found = FALSE;
+		for (i = 0; i < ntab; i++) {
+			size_t len = strlen(tab[i].code);
+			if (!strcmp(s, tab[i].code) && s[len] == ' ') {
+				s += len;
+				PUSHCHAR(tab[i].c);
+				found = TRUE;
+				break;
+			}
+		}
+		if (!found) PUSHCHAR(*s);
+		
+		s++;
+	}
+	PUSHCHAR(0);
+
+	return result;	
+}
+
+
 char *encodeStr1(char *str)
 {
 	char *result, *s = str;
@@ -902,6 +935,10 @@
 	} else {
 		t = stripTags(s);
 		h = decodeStr2(t);
+		if (setMorseMode) {
+			th_free(t); t = h;
+			h = tab2str(morseTab, sizeof(morseTab) / sizeof(morseTab[0]), t);
+		}
 		printMsg("½5½<½15½%s½5½>½0½ %s\n", p, h);
 		th_free(h);
 		th_free(t);
@@ -1060,7 +1097,7 @@
 		return 0;
 	} else if (!strncmp(buf, "/to ", 4)) {
 		th_free(setTarget);
-		setTarget = th_strdup(buf + 4);
+		setTarget = strdup(buf + 4);
 		printMsg("Set prv target to '%s'\n", setTarget);
 		return 0;
 	} else if (setPrvMode) {
@@ -1219,6 +1256,7 @@
 		raw();
 		keypad(stdscr, TRUE);
 		noecho();
+		meta(stdscr, TRUE);
 		timeout(SET_DELAY);
 		curVis = curs_set(0);
 		if (has_colors()) {
@@ -1305,7 +1343,7 @@
 			
 			/* Handle several buffered keypresses at once */
 			do {
-			c = getch();
+			c = wgetch(stdscr);
 			switch (c) {
 			case KEY_RESIZE:
 				if (!initializeWindows()) {