2022-04-03 07:12:16 +00:00
|
|
|
void
|
2022-04-03 08:05:25 +00:00
|
|
|
c_open(char *file, char **argv) {
|
2022-04-03 08:35:05 +00:00
|
|
|
if(argv[1] == NULL) { puts("usage: O filename"); return;}
|
|
|
|
FILE *f = fopen(argv[1], "r");
|
2022-04-03 07:12:16 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2022-04-02 14:58:16 +00:00
|
|
|
void
|
2022-04-03 08:05:25 +00:00
|
|
|
c_save(char *file, char **argv) {
|
2022-04-02 14:58:16 +00:00
|
|
|
FILE *f = fopen(file + 2, "w");
|
|
|
|
if(f == NULL) { puts("couldnt open file."); return; }
|
|
|
|
Row *row = buffer;
|
|
|
|
while (1) {
|
|
|
|
for(int i = 0; i < ROW_SIZE; i++) {
|
|
|
|
if (row->text[i] == '\0' || row->text[i] == '\n')
|
|
|
|
break;
|
|
|
|
fwrite(&row->text[i], 1, 1, f);
|
|
|
|
}
|
|
|
|
fwrite("\n", 1, 1, f);
|
|
|
|
if (row->n == NULL) break;
|
|
|
|
row = row->n;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-03 07:12:16 +00:00
|
|
|
|
2022-04-03 08:05:25 +00:00
|
|
|
|
2022-04-03 08:35:05 +00:00
|
|
|
|