File src/hstr_favorites.c changed (mode: 100644) (index 905ee57..83a2695) |
8 |
8 |
*/ |
*/ |
9 |
9 |
|
|
10 |
10 |
#include <stdbool.h> |
#include <stdbool.h> |
|
11 |
|
#include <stdio.h> |
11 |
12 |
#include <string.h> |
#include <string.h> |
|
13 |
|
#include <unistd.h> |
12 |
14 |
#include "include/hstr_favorites.h" |
#include "include/hstr_favorites.h" |
13 |
15 |
|
|
14 |
16 |
#define FAVORITE_SEGMENT_SIZE 10 |
#define FAVORITE_SEGMENT_SIZE 10 |
|
... |
... |
void favorites_load(FavoriteItems *favorites) |
28 |
30 |
strcpy(favorites->items[0],"a"); |
strcpy(favorites->items[0],"a"); |
29 |
31 |
favorites->items[1]=malloc(2); |
favorites->items[1]=malloc(2); |
30 |
32 |
strcpy(favorites->items[1],"b"); |
strcpy(favorites->items[1],"b"); |
|
33 |
|
|
|
34 |
|
lazy loading (boolean indicator to FavoriteItems) |
|
35 |
|
|
|
36 |
|
// TODO load from file |
|
37 |
|
|
|
38 |
|
char *home = getenv(ENV_VAR_HOME); |
|
39 |
|
char *fileName=(char*)malloc(strlen(home)+1+strlen(FILE_HH_RC)+1); |
|
40 |
|
strcpy(fileName,home); |
|
41 |
|
strcat(fileName,"/"); |
|
42 |
|
strcat(fileName,FILE_HH_RC); |
|
43 |
|
|
|
44 |
|
char *file_contents=NULL; |
|
45 |
|
if(access(fileName, F_OK) != -1) { |
|
46 |
|
long input_file_size; |
|
47 |
|
|
|
48 |
|
FILE *input_file = fopen(fileName, "rb"); |
|
49 |
|
fseek(input_file, 0, SEEK_END); |
|
50 |
|
input_file_size = ftell(input_file); |
|
51 |
|
rewind(input_file); |
|
52 |
|
file_contents = malloc((input_file_size + 1) * (sizeof(char))); |
|
53 |
|
if(fread(file_contents, sizeof(char), input_file_size, input_file)==-1) { |
|
54 |
|
exit(EXIT_FAILURE); |
|
55 |
|
} |
|
56 |
|
fclose(input_file); |
|
57 |
|
file_contents[input_file_size] = 0; |
|
58 |
|
} else { |
|
59 |
|
fprintf(stderr,"\nHistory file not found: %s\n",fileName); |
|
60 |
|
} |
|
61 |
|
|
|
62 |
|
if(file_contents) { |
|
63 |
|
split & process & initilize favorites |
|
64 |
|
} |
31 |
65 |
} |
} |
32 |
66 |
|
|
33 |
67 |
void favorites_add(FavoriteItems *favorites, char *newFavorite) |
void favorites_add(FavoriteItems *favorites, char *newFavorite) |
|
... |
... |
void favorites_remove(FavoriteItems *favorites, char *almostDead) |
69 |
103 |
|
|
70 |
104 |
void favorites_save(FavoriteItems *favorites) |
void favorites_save(FavoriteItems *favorites) |
71 |
105 |
{ |
{ |
|
106 |
|
create/update history file |
|
107 |
|
|
72 |
108 |
} |
} |
73 |
109 |
|
|
74 |
110 |
void favorites_destroy(FavoriteItems *favorites) |
void favorites_destroy(FavoriteItems *favorites) |