summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Maatman <blackwolf12333@gmail.com>2013-07-30 17:32:17 +0200
committerPeter Maatman <blackwolf12333@gmail.com>2013-07-30 17:43:17 +0200
commitdc57b779d2e3d1df836698cd119a3890ffecf86d (patch)
tree224fc5380d4f20e961101f857205d2cf20d9c15b
parent2c756f1c53e0c4faad8716425eafdf1b6e58f5c0 (diff)
added utility function format_message
-rw-r--r--testing/nTox.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/testing/nTox.c b/testing/nTox.c
index c960f761..3d410f19 100644
--- a/testing/nTox.c
+++ b/testing/nTox.c
@@ -50,6 +50,26 @@ void new_lines(char *line)
50 do_refresh(); 50 do_refresh();
51} 51}
52 52
53char *format_message(char *message, int friendnum)
54{
55 char name[MAX_NAME_LENGTH];
56 if(friendnum != -1) {
57 getfriendname(friendnum, (uint8_t*)name);
58 } else {
59 getname((uint8_t*)name);
60 }
61 char *msg = malloc(100+strlen(message)+strlen(name)+1);
62 time_t rawtime;
63 struct tm * timeinfo;
64 time ( &rawtime );
65 timeinfo = localtime ( &rawtime );
66 char* time = asctime(timeinfo);
67 size_t len = strlen(time);
68 time[len-1]='\0';
69 sprintf(msg, "[%d] %s <%s> %s", friendnum, time, name, message); // timestamp
70 return msg;
71}
72
53void line_eval(char lines[HISTORY][STRING_LENGTH], char *line) 73void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
54{ 74{
55 if (line[0] == '/') { 75 if (line[0] == '/') {
@@ -89,18 +109,7 @@ void line_eval(char lines[HISTORY][STRING_LENGTH], char *line)
89 if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) { 109 if(m_sendmessage(num, (uint8_t*) message, sizeof(message)) != 1) {
90 new_lines("[i] could not send message"); 110 new_lines("[i] could not send message");
91 } else { 111 } else {
92 char name[MAX_NAME_LENGTH]; 112 new_lines(format_message(message, -1));
93 getname((uint8_t*)name);
94 char msg[100+strlen(message)+strlen(name)+1];
95 time_t rawtime;
96 struct tm * timeinfo;
97 time ( &rawtime );
98 timeinfo = localtime ( &rawtime );
99 char* time = asctime(timeinfo);
100 size_t len = strlen(time);
101 time[len-1]='\0';
102 sprintf(msg, "[%d] %s <%s> %s", num, time, name, message); // timestamp
103 new_lines(msg);
104 } 113 }
105 } 114 }
106 else if (line[1] == 'n') { 115 else if (line[1] == 'n') {
@@ -237,7 +246,7 @@ void print_message(int friendnumber, uint8_t * string, uint16_t length)
237 size_t len = strlen(temp); 246 size_t len = strlen(temp);
238 temp[len-1]='\0'; 247 temp[len-1]='\0';
239 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp 248 sprintf(msg, "[%d] %s <%s> %s", friendnumber, temp, name, string); // timestamp
240 new_lines(msg); 249 new_lines(format_message((char*)string, friendnumber));
241} 250}
242 251
243void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) { 252void print_nickchange(int friendnumber, uint8_t *string, uint16_t length) {