moved file commmands to c_file.c
parent
8f917f058c
commit
338bda9c80
|
@ -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
|
||||
c_save(char *file) {
|
||||
FILE *f = fopen(file + 2, "w");
|
||||
|
@ -15,3 +36,4 @@ c_save(char *file) {
|
|||
}
|
||||
}
|
||||
|
||||
|
21
c_open.c
21
c_open.c
|
@ -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
5
efn.c
|
@ -9,7 +9,8 @@
|
|||
#include "main.c"
|
||||
|
||||
#include "c_quit.c"
|
||||
#include "c_open.c"
|
||||
|
||||
#include "c_file.c"
|
||||
|
||||
#include "b_truncate.c"
|
||||
#include "c_print.c"
|
||||
|
@ -17,7 +18,6 @@
|
|||
#include "c_writeline.c"
|
||||
#include "b_getline.c"
|
||||
|
||||
#include "c_save.c"
|
||||
#include "c_insertline.c"
|
||||
#include "c_indent.c"
|
||||
#include "c_delete.c"
|
||||
|
@ -26,3 +26,4 @@
|
|||
#include "commands.c"
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue