From: Daniel Liu Date: Sun, 13 Dec 2020 05:54:35 +0000 (-0500) Subject: reading from file X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=f4c2725eadab1725646757ffbceadfb5bec44ed2;p=taskasaur.git reading from file --- diff --git a/config.h b/config.h index f502aa6..709b9c3 100644 --- a/config.h +++ b/config.h @@ -1,6 +1,4 @@ static char font[] = "Source Code Pro:size=12"; -static char default_board[] = "board.md"; - diff --git a/main.c b/main.c index 6295b35..3b219ec 100644 --- a/main.c +++ b/main.c @@ -1,10 +1,15 @@ #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" @@ -22,7 +27,7 @@ main(int argc, char** argv) signal(SIGWINCH, winch_handler); // read command line args - flag = getopt(argc, argv, "o:n::"); + flag = getopt(argc, argv, "o:n:"); switch (flag) { case 'o': @@ -32,12 +37,16 @@ main(int argc, char** argv) 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': - /* ; */ - /* 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) @@ -45,16 +54,18 @@ main(int argc, char** argv) printf("%s already exists\n", optarg); return 1; } - /* printf("Successfully created %s\n", to_create); */ + // create a file here + printf("Successfully created %s\n", optarg); break; case -1: case '?': printf("Help string\n"); return 2; - } + + return 0; // start ncurses @@ -108,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) { diff --git a/test_board.md b/test_board.md new file mode 100644 index 0000000..05dddeb --- /dev/null +++ b/test_board.md @@ -0,0 +1,4 @@ +1Lmao xd 1 peraerae +2Lmao xd 2 sada +3Lmao xd 3 sa +4Lmao xd 4as aodjsalkd