|
|
|
@ -158,25 +158,20 @@ int is_file(char* path) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void save_text_helper(Buffer* buffer,char* filename) {
|
|
|
|
|
if (is_file(filename) == 1) {
|
|
|
|
|
FILE* file = fopen(filename,"w");
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < buffer->size) {
|
|
|
|
|
if ((buffer->start - buffer->text) == i) { /* If we have encountered
|
|
|
|
|
the start of the gap */
|
|
|
|
|
i += buffer->gap_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (i >= buffer->size) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
FILE* file = fopen(filename,"w");
|
|
|
|
|
int i = 0;
|
|
|
|
|
while (i < buffer->size) {
|
|
|
|
|
if ((buffer->start - buffer->text) == i) { /* If we have encountered
|
|
|
|
|
the start of the gap */
|
|
|
|
|
i += buffer->gap_size;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fputc(*(buffer->text + i),file);
|
|
|
|
|
i++;
|
|
|
|
|
if (i >= buffer->size) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
fputc(*(buffer->text + i),file);
|
|
|
|
|
i++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void init_curses() {
|
|
|
|
@ -207,14 +202,10 @@ int main(int argc, char** argv) {
|
|
|
|
|
num_of_chars++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
printf("File does not exist.\n");
|
|
|
|
|
return -10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (num_of_chars > 0) {
|
|
|
|
|
buffer_left(buffer);
|
|
|
|
|
num_of_chars--;
|
|
|
|
|
while (num_of_chars > 0) {
|
|
|
|
|
buffer_left(buffer);
|
|
|
|
|
num_of_chars--;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -301,8 +292,6 @@ int main(int argc, char** argv) {
|
|
|
|
|
buffer_insert(ch,buffer);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue_while_loop:
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
endwin();
|
|
|
|
|