From: Daniel Liu Date: Sat, 12 Dec 2020 06:28:14 +0000 (-0500) Subject: command line args X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=6afa85b8f5d9a77abaab11d47d7b8ab93f40d95d;p=taskasaur.git command line args --- diff --git a/config.h b/config.h index b3ec85d..f502aa6 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,6 @@ static char font[] = "Source Code Pro:size=12"; -static char default_board_file[] = "board.md"; +static char default_board[] = "board.md"; diff --git a/main.c b/main.c index 83b5aa0..6295b35 100644 --- a/main.c +++ b/main.c @@ -12,6 +12,7 @@ WINDOW* create_list_win(int height, int width, int y, int x); int main(int argc, char** argv) { + int flag; FILE* board_file; int height, width; int x, y; @@ -20,13 +21,41 @@ main(int argc, char** argv) signal(SIGWINCH, winch_handler); - // read from task file - board_file = fopen(default_board_file, "r"); - if (!board_file) { - printf("File does not exist\n"); - return 1; - } - fclose(board_file); + // read command line args + flag = getopt(argc, argv, "o:n::"); + switch (flag) { + case 'o': + + // read from task file (might need to check for read and write permissions) + board_file = fopen(optarg, "r"); + if (!board_file) { + printf("%s does not exist\n", optarg); + return 1; + } + break; + + case 'n': + /* ; */ + /* char to_create[]; */ + /* to_create = (optarg == 0) ? default_board : optarg; */ + + // make sure file does not exist + // however, it maybe be possible that an different error has occured (besides the file not existing) + if (access(optarg, F_OK) == 0) { + printf("%s already exists\n", optarg); + return 1; + } + /* printf("Successfully created %s\n", to_create); */ + break; + + case -1: + case '?': + printf("Help string\n"); + return 2; + + } + + return 0; // start ncurses initscr();