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.c78
1 files changed, 39 insertions, 39 deletions
diff --git a/testing/toxic/prompt.c b/testing/toxic/prompt.c
index ab44e960..67f80fef 100644
--- a/testing/toxic/prompt.c
+++ b/testing/toxic/prompt.c
@@ -20,24 +20,24 @@ static char prompt_buf[MAX_STR_SIZE] = {0};
20static int prompt_buf_pos = 0; 20static int prompt_buf_pos = 0;
21 21
22/* commands */ 22/* commands */
23void cmd_accept(ToxWindow *, char **); 23void cmd_accept(ToxWindow *, Messenger *m, char **);
24void cmd_add(ToxWindow *, char **); 24void cmd_add(ToxWindow *, Messenger *m, char **);
25void cmd_clear(ToxWindow *, char **); 25void cmd_clear(ToxWindow *, Messenger *m, char **);
26void cmd_connect(ToxWindow *, char **); 26void cmd_connect(ToxWindow *, Messenger *m, char **);
27void cmd_help(ToxWindow *, char **); 27void cmd_help(ToxWindow *, Messenger *m, char **);
28void cmd_msg(ToxWindow *, char **); 28void cmd_msg(ToxWindow *, Messenger *m, char **);
29void cmd_myid(ToxWindow *, char **); 29void cmd_myid(ToxWindow *, Messenger *m, char **);
30void cmd_nick(ToxWindow *, char **); 30void cmd_nick(ToxWindow *, Messenger *m, char **);
31void cmd_quit(ToxWindow *, char **); 31void cmd_quit(ToxWindow *, Messenger *m, char **);
32void cmd_status(ToxWindow *, char **); 32void cmd_status(ToxWindow *, Messenger *m, char **);
33void cmd_statusmsg(ToxWindow *, char **); 33void cmd_statusmsg(ToxWindow *, Messenger *m, char **);
34 34
35#define NUM_COMMANDS 13 35#define NUM_COMMANDS 13
36 36
37static struct { 37static struct {
38 char *name; 38 char *name;
39 int numargs; 39 int numargs;
40 void (*func)(ToxWindow *, char **); 40 void (*func)(ToxWindow *, Messenger *m, char **);
41} commands[] = { 41} commands[] = {
42 { "accept", 1, cmd_accept }, 42 { "accept", 1, cmd_accept },
43 { "add", 1, cmd_add }, 43 { "add", 1, cmd_add },
@@ -74,7 +74,7 @@ unsigned char *hex_string_to_bin(char hex_string[])
74 return val; 74 return val;
75} 75}
76 76
77void cmd_accept(ToxWindow *self, char **args) 77void cmd_accept(ToxWindow *self, Messenger *m, char **args)
78{ 78{
79 int num = atoi(args[1]); 79 int num = atoi(args[1]);
80 if (num >= num_requests) { 80 if (num >= num_requests) {
@@ -82,7 +82,7 @@ void cmd_accept(ToxWindow *self, char **args)
82 return; 82 return;
83 } 83 }
84 84
85 num = m_addfriend_norequest(pending_requests[num]); 85 num = m_addfriend_norequest(m, pending_requests[num]);
86 if (num == -1) 86 if (num == -1)
87 wprintw(self->window, "Failed to add friend.\n"); 87 wprintw(self->window, "Failed to add friend.\n");
88 else { 88 else {
@@ -91,7 +91,7 @@ void cmd_accept(ToxWindow *self, char **args)
91 } 91 }
92} 92}
93 93
94void cmd_add(ToxWindow *self, char **args) 94void cmd_add(ToxWindow *self, Messenger *m, char **args)
95{ 95{
96 uint8_t id_bin[KEY_SIZE_BYTES]; 96 uint8_t id_bin[KEY_SIZE_BYTES];
97 char xx[3]; 97 char xx[3];
@@ -121,7 +121,7 @@ void cmd_add(ToxWindow *self, char **args)
121 } 121 }
122 id_bin[i] = x; 122 id_bin[i] = x;
123 } 123 }
124 int num = m_addfriend(id_bin, (uint8_t*) msg, strlen(msg)+1); 124 int num = m_addfriend(m, id_bin, (uint8_t*) msg, strlen(msg)+1);
125 switch (num) { 125 switch (num) {
126 case FAERR_TOOLONG: 126 case FAERR_TOOLONG:
127 wprintw(self->window, "Message is too long.\n"); 127 wprintw(self->window, "Message is too long.\n");
@@ -145,12 +145,12 @@ void cmd_add(ToxWindow *self, char **args)
145 } 145 }
146} 146}
147 147
148void cmd_clear(ToxWindow *self, char **args) 148void cmd_clear(ToxWindow *self, Messenger *m, char **args)
149{ 149{
150 wclear(self->window); 150 wclear(self->window);
151} 151}
152 152
153void cmd_connect(ToxWindow *self, char **args) 153void cmd_connect(ToxWindow *self, Messenger *m, char **args)
154{ 154{
155 IP_Port dht; 155 IP_Port dht;
156 char *ip = args[1]; 156 char *ip = args[1];
@@ -174,13 +174,13 @@ void cmd_connect(ToxWindow *self, char **args)
174 free(binary_string); 174 free(binary_string);
175} 175}
176 176
177void cmd_quit(ToxWindow *self, char **args) 177void cmd_quit(ToxWindow *self, Messenger *m, char **args)
178{ 178{
179 endwin(); 179 endwin();
180 exit(0); 180 exit(0);
181} 181}
182 182
183void cmd_help(ToxWindow *self, char **args) 183void cmd_help(ToxWindow *self, Messenger *m, char **args)
184{ 184{
185 wclear(self->window); 185 wclear(self->window);
186 wattron(self->window, COLOR_PAIR(2) | A_BOLD); 186 wattron(self->window, COLOR_PAIR(2) | A_BOLD);
@@ -197,7 +197,7 @@ void cmd_help(ToxWindow *self, char **args)
197 wprintw(self->window, " quit/exit : Exit program\n"); 197 wprintw(self->window, " quit/exit : Exit program\n");
198 wprintw(self->window, " help : Print this message again\n"); 198 wprintw(self->window, " help : Print this message again\n");
199 wprintw(self->window, " clear : Clear this window\n"); 199 wprintw(self->window, " clear : Clear this window\n");
200 200
201 wattron(self->window, A_BOLD); 201 wattron(self->window, A_BOLD);
202 wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n"); 202 wprintw(self->window, "TIP: Use the TAB key to navigate through the tabs.\n\n");
203 wattroff(self->window, A_BOLD); 203 wattroff(self->window, A_BOLD);
@@ -205,17 +205,17 @@ void cmd_help(ToxWindow *self, char **args)
205 wattroff(self->window, COLOR_PAIR(2)); 205 wattroff(self->window, COLOR_PAIR(2));
206} 206}
207 207
208void cmd_msg(ToxWindow *self, char **args) 208void cmd_msg(ToxWindow *self, Messenger *m, char **args)
209{ 209{
210 char *id = args[1]; 210 char *id = args[1];
211 char *msg = args[2]; 211 char *msg = args[2];
212 if (m_sendmessage(atoi(id), (uint8_t*) msg, strlen(msg)+1) == 0) 212 if (m_sendmessage(m, atoi(id), (uint8_t*) msg, strlen(msg)+1) == 0)
213 wprintw(self->window, "Error occurred while sending message.\n"); 213 wprintw(self->window, "Error occurred while sending message.\n");
214 else 214 else
215 wprintw(self->window, "Message successfully sent.\n"); 215 wprintw(self->window, "Message successfully sent.\n");
216} 216}
217 217
218void cmd_myid(ToxWindow *self, char **args) 218void cmd_myid(ToxWindow *self, Messenger *m, char **args)
219{ 219{
220 char id[KEY_SIZE_BYTES*2 + 1] = {0}; 220 char id[KEY_SIZE_BYTES*2 + 1] = {0};
221 size_t i; 221 size_t i;
@@ -227,14 +227,14 @@ void cmd_myid(ToxWindow *self, char **args)
227 wprintw(self->window, "Your ID: %s\n", id); 227 wprintw(self->window, "Your ID: %s\n", id);
228} 228}
229 229
230void cmd_nick(ToxWindow *self, char **args) 230void cmd_nick(ToxWindow *self, Messenger *m, char **args)
231{ 231{
232 char *nick = args[1]; 232 char *nick = args[1];
233 setname((uint8_t*) nick, strlen(nick)+1); 233 setname(m, (uint8_t*) nick, strlen(nick)+1);
234 wprintw(self->window, "Nickname set to: %s\n", nick); 234 wprintw(self->window, "Nickname set to: %s\n", nick);
235} 235}
236 236
237void cmd_status(ToxWindow *self, char **args) 237void cmd_status(ToxWindow *self, Messenger *m, char **args)
238{ 238{
239 char *status = args[1]; 239 char *status = args[1];
240 char *status_text; 240 char *status_text;
@@ -260,24 +260,24 @@ void cmd_status(ToxWindow *self, char **args)
260 260
261 char *msg = args[2]; 261 char *msg = args[2];
262 if (msg == NULL) { 262 if (msg == NULL) {
263 m_set_userstatus(status_kind); 263 m_set_userstatus(m, status_kind);
264 wprintw(self->window, "Status set to: %s\n", status_text); 264 wprintw(self->window, "Status set to: %s\n", status_text);
265 } 265 }
266 else { 266 else {
267 m_set_userstatus(status_kind); 267 m_set_userstatus(m, status_kind);
268 m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); 268 m_set_statusmessage(m, (uint8_t*) msg, strlen(msg)+1);
269 wprintw(self->window, "Status set to: %s, %s\n", status_text, msg); 269 wprintw(self->window, "Status set to: %s, %s\n", status_text, msg);
270 } 270 }
271} 271}
272 272
273void cmd_statusmsg(ToxWindow *self, char **args) 273void cmd_statusmsg(ToxWindow *self, Messenger *m, char **args)
274{ 274{
275 char *msg = args[1]; 275 char *msg = args[1];
276 m_set_statusmessage((uint8_t*) msg, strlen(msg)+1); 276 m_set_statusmessage(m, (uint8_t*) msg, strlen(msg)+1);
277 wprintw(self->window, "Status set to: %s\n", msg); 277 wprintw(self->window, "Status set to: %s\n", msg);
278} 278}
279 279
280static void execute(ToxWindow *self, char *u_cmd) 280static void execute(ToxWindow *self, Messenger *m, char *u_cmd)
281{ 281{
282 int newlines = 0; 282 int newlines = 0;
283 char cmd[MAX_STR_SIZE] = {0}; 283 char cmd[MAX_STR_SIZE] = {0};
@@ -341,13 +341,13 @@ static void execute(ToxWindow *self, char *u_cmd)
341 return; 341 return;
342 } 342 }
343 } 343 }
344 /* check for excess arguments */ 344 /* check for excess arguments */
345 if (strcmp(cmdargs[0], "add") && strlen(cmdargs[j]) != 0) { 345 if (strcmp(cmdargs[0], "add") && strlen(cmdargs[j]) != 0) {
346 wprintw(self->window, "Invalid command: too many arguments to %s.\n", commands[i].name); 346 wprintw(self->window, "Invalid command: too many arguments to %s.\n", commands[i].name);
347 return; 347 return;
348 } 348 }
349 /* pass arguments to command function */ 349 /* pass arguments to command function */
350 (commands[i].func)(self, cmdargs); 350 (commands[i].func)(self, m, cmdargs);
351 return; 351 return;
352 } 352 }
353 } 353 }
@@ -356,7 +356,7 @@ static void execute(ToxWindow *self, char *u_cmd)
356 wprintw(self->window, "Invalid command.\n"); 356 wprintw(self->window, "Invalid command.\n");
357} 357}
358 358
359static void prompt_onKey(ToxWindow *self, int key) 359static void prompt_onKey(ToxWindow *self, Messenger *m, int key)
360{ 360{
361 /* Add printable characters to line */ 361 /* Add printable characters to line */
362 if (isprint(key)) { 362 if (isprint(key)) {
@@ -380,7 +380,7 @@ static void prompt_onKey(ToxWindow *self, int key)
380 /* RETURN key: execute command */ 380 /* RETURN key: execute command */
381 else if (key == '\n') { 381 else if (key == '\n') {
382 wprintw(self->window, "\n"); 382 wprintw(self->window, "\n");
383 execute(self, prompt_buf); 383 execute(self, m, prompt_buf);
384 prompt_buf_pos = 0; 384 prompt_buf_pos = 0;
385 prompt_buf[0] = 0; 385 prompt_buf[0] = 0;
386 } 386 }
@@ -413,10 +413,10 @@ static void prompt_onDraw(ToxWindow *self)
413 wrefresh(self->window); 413 wrefresh(self->window);
414} 414}
415 415
416static void prompt_onInit(ToxWindow *self) 416static void prompt_onInit(ToxWindow *self, Messenger *m)
417{ 417{
418 scrollok(self->window, 1); 418 scrollok(self->window, 1);
419 cmd_help(self, NULL); 419 cmd_help(self, m, NULL);
420 wclrtoeol(self->window); 420 wclrtoeol(self->window);
421} 421}
422 422