From d34e4a3408a176525bedfad87cfc996afbe21b66 Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Sat, 3 Aug 2013 15:12:02 -0400 Subject: [PATCH 1/2] added the -f flag for toxic --- testing/toxic/main.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 391b0b39..001d3382 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -170,12 +170,12 @@ static void do_tox() { doMessenger(); } -static void load_data() { +static void load_data(char *path) { FILE* fd; size_t len; uint8_t* buf; - if((fd = fopen("data", "r")) != NULL) { + if((fd = fopen(path, "r")) != NULL) { fseek(fd, 0, SEEK_END); len = ftell(fd); fseek(fd, 0, SEEK_SET); @@ -213,7 +213,7 @@ static void load_data() { Messenger_save(buf); - fd = fopen("data", "w"); + fd = fopen(path, "w"); if(fd == NULL) { fprintf(stderr, "fopen() failed.\n"); @@ -282,11 +282,25 @@ void prepare_window(WINDOW* w) { int main(int argc, char* argv[]) { int ch; + int i = 0; + char *filename = "data"; ToxWindow* a; + for(i = 0; i < argc; i++) { + if(argv[i][0] == '-') { + if(argv[i][1] == 'f') { + if(argv[i + 1] != NULL) + filename = argv[i + 1]; + else { + fputs("[!] you passed '-f' without giving an argument!\n", stderr); + } + } + } + } + init_term(); init_tox(); - load_data(); + load_data(filename); init_windows(); while(true) { From 9b56e21f81b0956e936a605f2b82d61eecd3d435 Mon Sep 17 00:00:00 2001 From: charmlesscoin Date: Sat, 3 Aug 2013 16:12:02 -0400 Subject: [PATCH 2/2] added a proper error message for messing up the -f flag --- testing/toxic/main.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/testing/toxic/main.c b/testing/toxic/main.c index 001d3382..3b45a89f 100644 --- a/testing/toxic/main.c +++ b/testing/toxic/main.c @@ -283,6 +283,7 @@ void prepare_window(WINDOW* w) { int main(int argc, char* argv[]) { int ch; int i = 0; + int f_flag = 0; char *filename = "data"; ToxWindow* a; @@ -292,7 +293,7 @@ int main(int argc, char* argv[]) { if(argv[i + 1] != NULL) filename = argv[i + 1]; else { - fputs("[!] you passed '-f' without giving an argument!\n", stderr); + f_flag = -1; } } } @@ -303,6 +304,14 @@ int main(int argc, char* argv[]) { load_data(filename); init_windows(); + if(f_flag == -1) { + attron(COLOR_PAIR(3) | A_BOLD); + wprintw(prompt->window, "You passed '-f' without giving an argument!\n" + "defaulting to 'data' for a keyfile...\n"); + attroff(COLOR_PAIR(3) | A_BOLD); + } + + while(true) { // Update tox. do_tox();