diff --git a/editor.c b/editor.c index c46072f..d64bf0f 100644 --- a/editor.c +++ b/editor.c @@ -99,19 +99,28 @@ int main(int argc, char** argv) { Buffer* buffer = new_buffer(10); if (argc == 2) { + int num_of_chars = 0; 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); + num_of_chars++; } } else { printf("File does not exist.\n"); return -10; } + + while (num_of_chars > 1) { + buffer_left(buffer); + num_of_chars--; + } } + + init_curses(); int ch; @@ -120,8 +129,8 @@ int main(int argc, char** argv) { clear(); int i=0; - if (buffer->start != buffer->text) { /* We don't want to print the string, if the - gap starts at the first index of the string */ + if ((buffer->start != buffer->text) || (buffer->gap_size != buffer->size)) { /* We don't want to print the string, if the + gap starts at the first index of the string, and continues till the end */ while (i < buffer->size) { addch(*(buffer->text + i)); @@ -131,6 +140,7 @@ int main(int argc, char** argv) { getyx(stdscr,y,x); i += buffer->gap_size; } + } move(y,x);