i *think* this implented file loading

master
bx 2022-09-15 19:23:26 +01:00
parent 9639dfc19e
commit 4e4a9a11d6
2 changed files with 23 additions and 3 deletions

View File

@ -1,7 +1,15 @@
extern void load_file(char *);
void void
c_open(char *file, char **argv) { c_open(char *file, char **argv) {
if(argv[1] == NULL) { puts("usage: O filename"); return;} if(argv[1] == NULL) { puts("usage: O filename"); return;}
FILE *f = fopen(argv[1], "r"); load_file(argv[1]);
}
void
load_file(char *file) {
FILE *f = fopen(file, "r");
if(f == NULL) { puts("couldnt open file."); return; } if(f == NULL) { puts("couldnt open file."); return; }
b_truncate(buffer); b_truncate(buffer);
Row *row = buffer; Row *row = buffer;
@ -32,11 +40,22 @@ c_save(char *file, char **argv) {
fwrite(&row->text[i], 1, 1, f); fwrite(&row->text[i], 1, 1, f);
} }
fwrite("\n", 1, 1, f); fwrite("\n", 1, 1, f);
if (row->n == NULL) break; if(row->n == NULL) break;
row = row->n; row = row->n;
} }
fclose(f);
} }

3
main.c
View File

@ -33,7 +33,7 @@ main(int argc, char **argv) {
static char buf[COM_BUF_SIZE]; static char buf[COM_BUF_SIZE];
if (argc >= 2) { if (argc >= 2) {
// todo, open file load_file(argv[1]);
} }
while(1) { while(1) {
@ -57,3 +57,4 @@ main(int argc, char **argv) {