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
c_open(char *file, char **argv) {
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; }
b_truncate(buffer);
Row *row = buffer;
@ -35,8 +43,19 @@ c_save(char *file, char **argv) {
if(row->n == NULL) break;
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];
if (argc >= 2) {
// todo, open file
load_file(argv[1]);
}
while(1) {
@ -57,3 +57,4 @@ main(int argc, char **argv) {