X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=main.c;h=3b219eca466db58fe040ab2e5b9bb42dd5701d28;hb=f4c2725eadab1725646757ffbceadfb5bec44ed2;hp=d57ec4d8b33b26a543c42d46f38e460d568ff8a3;hpb=4d4eab198ec016ec7c39cecf8b472ff3046fd965;p=taskasaur.git diff --git a/main.c b/main.c index d57ec4d..3b219ec 100644 --- a/main.c +++ b/main.c @@ -1,15 +1,24 @@ #include #include #include +#include #include +#define MAX_TODO_LENGTH 200 + void winch_handler(int sig); +char* read_todo(FILE* file); + WINDOW* create_list_win(int height, int width, int y, int x); +#include "config.h" + int main(int argc, char** argv) { + int flag; + FILE* board_file; int height, width; int x, y; int ch; @@ -17,6 +26,48 @@ main(int argc, char** argv) signal(SIGWINCH, winch_handler); + // 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; + } + + char* lineptr = read_todo(board_file); + printf("lineptr: %p\n", lineptr); + printf("first: %c\n", *lineptr); + free(lineptr); + fclose(board_file); + + break; + + case 'n': + + // 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; + } + // create a file here + printf("Successfully created %s\n", optarg); + break; + + case -1: + case '?': + printf("Help string\n"); + return 2; + } + + + + return 0; + // start ncurses initscr(); cbreak(); @@ -34,9 +85,9 @@ main(int argc, char** argv) todo_win = create_list_win(20, 20, 5, 5); move(y,x); - while ((ch = getch()) != 113) { + while ((ch = getch()) != 113) { // while not q - //ofc the first thing we need is vim keys + // ofc the first thing we need is vim keys switch (ch) { case 104: // h x -= 1; @@ -68,6 +119,24 @@ winch_handler(int sig) refresh(); } + +char* +read_todo(FILE* file) +{ // apparently getline isn't rly that portable, so consider other options + char* lineptr; + size_t len; + ssize_t nread; + + lineptr = NULL; + len = 0; + + while ((nread = getline(&lineptr, &len, file)) != -1) { + printf("Read line of size %zd\n", nread); + } + + return lineptr; +} + WINDOW* create_list_win(int height, int width, int y, int x) {