summaryrefslogtreecommitdiff
path: root/testing/toxic/prompt.c
diff options
context:
space:
mode:
Diffstat (limited to 'testing/toxic/prompt.c')
-rw-r--r--testing/toxic/prompt.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index 1db60883..463b9352 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -89,7 +89,9 @@ static void execute(ToxWindow* self, char* cmd) {
89 } 89 }
90 90
91 dht.ip.i = resolved_address; 91 dht.ip.i = resolved_address;
92 DHT_bootstrap(dht, hex_string_to_bin(key)); 92 unsigned char *binary_string = hex_string_to_bin(key);
93 DHT_bootstrap(dht, binary_string);
94 free(binary_string);
93 } 95 }
94 else if(!strncmp(cmd, "add ", strlen("add "))) { 96 else if(!strncmp(cmd, "add ", strlen("add "))) {
95 uint8_t id_bin[32]; 97 uint8_t id_bin[32];
@@ -148,7 +150,7 @@ static void execute(ToxWindow* self, char* cmd) {
148 wprintw(self->window, "Friend request already sent.\n"); 150 wprintw(self->window, "Friend request already sent.\n");
149 break; 151 break;
150 case -5: 152 case -5:
151 wprintw(self->window, "[i] Undefined error when adding friend.\n"); 153 wprintw(self->window, "Undefined error when adding friend.\n");
152 break; 154 break;
153 default: 155 default:
154 wprintw(self->window, "Friend added as %d.\n", num); 156 wprintw(self->window, "Friend added as %d.\n", num);
@@ -178,12 +180,13 @@ static void execute(ToxWindow* self, char* cmd) {
178 180
179 nick = strchr(cmd, ' '); 181 nick = strchr(cmd, ' ');
180 if(nick == NULL) { 182 if(nick == NULL) {
183 wprintw(self->window, "Invalid syntax.\n");
181 return; 184 return;
182 } 185 }
183 nick++; 186 nick++;
184 187
185 setname((uint8_t*) nick, strlen(nick)+1); 188 setname((uint8_t*) nick, strlen(nick)+1);
186 wprintw(self->window, "Nickname set to: %s.\n", nick); 189 wprintw(self->window, "Nickname set to: %s\n", nick);
187 } 190 }
188 else if(!strcmp(cmd, "myid")) { 191 else if(!strcmp(cmd, "myid")) {
189 char id[32*2 + 1] = {0}; 192 char id[32*2 + 1] = {0};
@@ -195,7 +198,7 @@ static void execute(ToxWindow* self, char* cmd) {
195 strcat(id, xx); 198 strcat(id, xx);
196 } 199 }
197 200
198 wprintw(self->window, "%s\n", id); 201 wprintw(self->window, "Your ID: %s\n", id);
199 } 202 }
200 else if(!strncmp(cmd, "accept ", strlen("accept "))) { 203 else if(!strncmp(cmd, "accept ", strlen("accept "))) {
201 char* id; 204 char* id;
@@ -251,20 +254,18 @@ static void execute(ToxWindow* self, char* cmd) {
251 wprintw(self->window, "Message successfully sent.\n"); 254 wprintw(self->window, "Message successfully sent.\n");
252 } 255 }
253 } 256 }
257
254 else { 258 else {
255 wprintw(self->window, "Invalid syntax.\n"); 259 wprintw(self->window, "Invalid command.\n");
256 } 260 }
257} 261}
258 262
259static void prompt_onKey(ToxWindow* self, int key) { 263static void prompt_onKey(ToxWindow* self, int key) {
260
261 // PRINTABLE characters: Add to line. 264 // PRINTABLE characters: Add to line.
262 if(isprint(key)) { 265 if(isprint(key)) {
263
264 if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) { 266 if(prompt_buf_pos == (sizeof(prompt_buf) - 1)) {
265 return; 267 return;
266 } 268 }
267
268 prompt_buf[prompt_buf_pos++] = key; 269 prompt_buf[prompt_buf_pos++] = key;
269 prompt_buf[prompt_buf_pos] = 0; 270 prompt_buf[prompt_buf_pos] = 0;
270 } 271 }
@@ -273,14 +274,12 @@ static void prompt_onKey(ToxWindow* self, int key) {
273 else if(key == '\n') { 274 else if(key == '\n') {
274 wprintw(self->window, "\n"); 275 wprintw(self->window, "\n");
275 execute(self, prompt_buf); 276 execute(self, prompt_buf);
276
277 prompt_buf_pos = 0; 277 prompt_buf_pos = 0;
278 prompt_buf[0] = 0; 278 prompt_buf[0] = 0;
279 } 279 }
280 280
281 // BACKSPACE key: Remove one character from line. 281 // BACKSPACE key: Remove one character from line.
282 else if(key == 0x107 || key == 0x8 || key == 0x7f) { 282 else if(key == 0x107 || key == 0x8 || key == 0x7f) {
283
284 if(prompt_buf_pos != 0) { 283 if(prompt_buf_pos != 0) {
285 prompt_buf[--prompt_buf_pos] = 0; 284 prompt_buf[--prompt_buf_pos] = 0;
286 } 285 }