summaryrefslogtreecommitdiff
path: root/src/cache.c
diff options
context:
space:
mode:
authorLouie S <louie@example.com>2023-05-09 18:39:36 -0700
committerLouie S <louie@example.com>2023-05-09 18:39:36 -0700
commit2a790c9b633f72a1b0a106fc72d7587aa08d4bcb (patch)
tree8e8707c8055b2b80cbb7f133139d6f00341b6a04 /src/cache.c
parent14a6e82cc82e8c1802c0d468c6b32553d56099a6 (diff)
Change how e_hover and e_offset are managed; cache e_hover and e_offset as array
Diffstat (limited to 'src/cache.c')
-rw-r--r--src/cache.c31
1 files changed, 19 insertions, 12 deletions
diff --git a/src/cache.c b/src/cache.c
index 60a0fa6..599879d 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -9,10 +9,11 @@
#include "include/cache.h"
#include "include/read_cfg.h"
-void save_to_cache(int g_hover, int e_hover, int true_hover, char *cfg_name){
+void save_to_cache(int g_count, int g_hover, int *e_hover, int *e_offset, int true_hover, char *cfg_name){
FILE *fp;
struct stat cfg_stat; //for determining last modification time of file
char *path = get_cache_path(true);
+ int i;
//ensure get_cache_path() did not return NULL
if(path == NULL) return;
@@ -30,20 +31,26 @@ void save_to_cache(int g_hover, int e_hover, int true_hover, char *cfg_name){
//write to file
fwrite(cfg_name, sizeof(char), BUF_LEN, fp);
fwrite(&cfg_stat.st_mtime, sizeof(long int), 1, fp);
+ fwrite(&g_count, sizeof(int), 1, fp);
fwrite(&g_hover, sizeof(int), 1, fp);
- fwrite(&e_hover, sizeof(int), 1, fp);
+ for(i = 0; i < g_count; ++i){
+ fwrite(&(e_hover[i]), sizeof(int), 1, fp);
+ fwrite(&(e_offset[i]), sizeof(int), 1, fp);
+ }
fwrite(&true_hover, sizeof(int), 1, fp);
fclose(fp);
return;
}
-void load_cache(int *g_hover, int *e_hover, int *true_hover, char *new_cfg_name){
+void load_cache(int g_count, int *g_hover, int **e_hover, int **e_offset, int *true_hover, char *new_cfg_name){
FILE *fp;
char *path = get_cache_path(false);
char saved_cfg_name[BUF_LEN];
long int saved_cfg_mtime;
struct stat new_cfg_stat;
+ int saved_g_count;
+ int i;
//ensure get_cache_path() did not return NULL
if(path == NULL) return;
@@ -61,15 +68,15 @@ void load_cache(int *g_hover, int *e_hover, int *true_hover, char *new_cfg_name)
stat(new_cfg_name, &new_cfg_stat);
if(!(strcmp(saved_cfg_name, new_cfg_name)) && saved_cfg_mtime >= new_cfg_stat.st_mtime){
- fread(g_hover, sizeof(int), 1, fp);
- fread(e_hover, sizeof(int), 1, fp);
- fread(true_hover, sizeof(int), 1, fp);
- }
-
- else{
- *g_hover = 0;
- *e_hover = 0;
- *true_hover = 0;
+ fread(&saved_g_count, sizeof(int), 1, fp);
+ if(saved_g_count == g_count){
+ fread(g_hover, sizeof(int), 1, fp);
+ for(i = 0; i < g_count; ++i){
+ fread(&(*e_hover)[i], sizeof(int), 1, fp);
+ fread(&(*e_offset)[i], sizeof(int), 1, fp);
+ }
+ fread(true_hover, sizeof(int), 1, fp);
+ }
}
fclose(fp);