From 25c1f6a2c173797b2ec7616f8d875da2aa03097e Mon Sep 17 00:00:00 2001 From: Rockingcool Date: Wed, 19 Apr 2023 08:07:17 -0500 Subject: [PATCH] Started working on file opening support --- editor.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/editor.c b/editor.c index ca5b654..2b52a87 100644 --- a/editor.c +++ b/editor.c @@ -4,6 +4,7 @@ #include #include #include +#include typedef struct Buffer_struct Buffer; struct Buffer_struct { @@ -93,10 +94,25 @@ void sigint_handler(int dummy) { exit(130); } -int main() { +int main(int argc, char** argv) { signal(SIGINT,sigint_handler); - Buffer* buffer = new_buffer(10); + + if (argc == 2) { + if (access(argv[1],F_OK) == 0) { /* If the file exists */ + + FILE* file = fopen(argv[1],"r"); + char c; + while (c = fgetc(file) != EOF) { + buffer_insert(c,buffer); + } + + } else { + printf("File does not exist.\n"); + return -10; + } + } + init_curses(); int ch;