-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfiles.c
41 lines (34 loc) · 979 Bytes
/
files.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/** @file */
#include <stdio.h>
#include <f_queue.h>
#include <functions_queue.h>
#include <stdbool.h>
void save_recording(struct f_queue *tail, char *file_name)
{
FILE *f = fopen(file_name, "w");
if (f == NULL)
return;
while (tail) {
fprintf(f, "%d %d %d\n", tail->f_type, tail->f_args[0], tail->f_args[1]); ///< The data is saved in <b><int> <int> <int></b> fashion
tail = tail->prev;
}
fclose(f);
}
bool load_recording(struct f_queue **head, struct f_queue **tail, char *file_name)
{
FILE *f = fopen(file_name, "r");
if (f == NULL) {
return false;
}
char buffer[256];
int f_type, arg1, arg2;
while (fgets(buffer, sizeof(buffer), f) != NULL) {
if (sscanf(buffer, "%d %d %d", &f_type, &arg1, &arg2) != 3) { ///< Basic file validation
fclose(f);
return false;
}
add_function(head, tail, f_type, arg1, arg2);
}
fclose(f);
return true;
}