moved file commmands to c_file.c

master
bx 2022-04-03 08:12:16 +01:00
parent 8f917f058c
commit 338bda9c80
3 changed files with 25 additions and 23 deletions

View File

@ -1,3 +1,24 @@
void
c_open(char *file) {
FILE *f = fopen(file + 2, "r");
if(f == NULL) { puts("couldnt open file."); return; }
b_truncate(buffer);
Row *row = buffer;
while (1) {
size_t red = 0;
for (int i = 0; i < ROW_SIZE; i++) {
red = fread(&row->text[i], 1, 1, f);
if (red != 1) return;
if (row->text[i] == '\n') {
row->text[i] = 0;
break;
}
}
row = b_insert(row);
}
fclose(f);
}
void void
c_save(char *file) { c_save(char *file) {
FILE *f = fopen(file + 2, "w"); FILE *f = fopen(file + 2, "w");
@ -15,3 +36,4 @@ c_save(char *file) {
} }
} }

View File

@ -1,21 +0,0 @@
void
c_open(char *file) {
FILE *f = fopen(file + 2, "r");
if(f == NULL) { puts("couldnt open file."); return; }
b_truncate(buffer);
Row *row = buffer;
while (1) {
size_t red = 0;
for (int i = 0; i < ROW_SIZE; i++) {
red = fread(&row->text[i], 1, 1, f);
if (red != 1) return;
if (row->text[i] == '\n') {
row->text[i] = 0;
break;
}
}
row = b_insert(row);
}
fclose(f);
}

5
efn.c
View File

@ -9,7 +9,8 @@
#include "main.c" #include "main.c"
#include "c_quit.c" #include "c_quit.c"
#include "c_open.c"
#include "c_file.c"
#include "b_truncate.c" #include "b_truncate.c"
#include "c_print.c" #include "c_print.c"
@ -17,7 +18,6 @@
#include "c_writeline.c" #include "c_writeline.c"
#include "b_getline.c" #include "b_getline.c"
#include "c_save.c"
#include "c_insertline.c" #include "c_insertline.c"
#include "c_indent.c" #include "c_indent.c"
#include "c_delete.c" #include "c_delete.c"
@ -26,3 +26,4 @@
#include "commands.c" #include "commands.c"