generated from Riley/Conan-C
Add cjson dependency and enhance todoitem management: refactor structures and functions
This commit is contained in:
parent
ec75e0723e
commit
2891fea4e9
7 changed files with 37 additions and 16 deletions
|
|
@ -21,6 +21,7 @@ class helloConan(ConanFile):
|
||||||
|
|
||||||
def requirements(self):
|
def requirements(self):
|
||||||
self.requires("cwalk/1.2.8")
|
self.requires("cwalk/1.2.8")
|
||||||
|
self.requires("cjson/1.7.18")
|
||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
deps = PkgConfigDeps(self)
|
deps = PkgConfigDeps(self)
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,11 @@ target_name = 'main'
|
||||||
|
|
||||||
# self.requires("zlib/1.2.11")
|
# self.requires("zlib/1.2.11")
|
||||||
cwalk = dependency('cwalk', version : '1.2.8', static: true, required: true)
|
cwalk = dependency('cwalk', version : '1.2.8', static: true, required: true)
|
||||||
|
# self.requires("cjson/1.7.18")
|
||||||
|
cjson = dependency('cjson', version : '1.7.18', static: true, required: true)
|
||||||
|
|
||||||
|
files = files('src/main.c', 'src/paths.c', 'src/log.c',
|
||||||
files = files('src/main.c', 'src/paths.c', 'src/log.c')
|
'src/todoitem.c', 'src/todoitem_fs.c')
|
||||||
|
|
||||||
if get_option('buildtype') == 'debug'
|
if get_option('buildtype') == 'debug'
|
||||||
if CC.has_argument('-fsanitize=address') and CC.has_link_argument('-fsanitize=address')
|
if CC.has_argument('-fsanitize=address') and CC.has_link_argument('-fsanitize=address')
|
||||||
|
|
@ -18,6 +20,6 @@ if get_option('buildtype') == 'debug'
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
|
||||||
executable(target_name, files, dependencies: [cwalk], include_directories: include_directories('src/include'))
|
executable(target_name, files, dependencies: [cwalk, cjson], include_directories: include_directories('src/include'))
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
19
src/include/todoitem.h
Normal file
19
src/include/todoitem.h
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
char *description;
|
||||||
|
int priority;
|
||||||
|
int completed;
|
||||||
|
} todoitem;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
todoitem *items;
|
||||||
|
int count;
|
||||||
|
} todolist;
|
||||||
|
|
||||||
|
todolist *tdl_init();
|
||||||
|
void tdl_free(todolist *list);
|
||||||
|
void tdl_add_item(todolist *list, char *name, char *description, int priority, int completed);
|
||||||
|
todoitem *tdi_init(char *name, char *description, int priority, int completed);
|
||||||
|
void tdl_free(todolist *list);
|
||||||
|
void tdl_remove_item(todolist *list, int index);
|
||||||
|
void tdi_free(todoitem *item);
|
||||||
|
|
@ -46,7 +46,6 @@ int setup_appdata() {
|
||||||
}
|
}
|
||||||
|
|
||||||
log_debug("Appdata folder already exists: %s", path);
|
log_debug("Appdata folder already exists: %s", path);
|
||||||
mkdir(path);
|
|
||||||
free(path);
|
free(path);
|
||||||
return 0; // no change
|
return 0; // no change
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,18 +21,6 @@ todolist *tdl_init() {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
void tdl_free(todolist *list) {
|
|
||||||
if (list != NULL) {
|
|
||||||
for (int i = 0; i < list->count; i++) {
|
|
||||||
free(list->items[i].name);
|
|
||||||
free(list->items[i].description);
|
|
||||||
}
|
|
||||||
free(list->items);
|
|
||||||
free(list);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void tdl_add_item(todolist *list, char *name, char *description, int priority, int completed) {
|
void tdl_add_item(todolist *list, char *name, char *description, int priority, int completed) {
|
||||||
list->items = realloc(list->items, sizeof(todoitem) * (list->count + 1));
|
list->items = realloc(list->items, sizeof(todoitem) * (list->count + 1));
|
||||||
list->items[list->count].name = name;
|
list->items[list->count].name = name;
|
||||||
|
|
|
||||||
12
src/todoitem_fs.c
Normal file
12
src/todoitem_fs.c
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#include <todoitem.h>
|
||||||
|
#include <paths.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
todolist *tdl_load_from_disk(FILE *fp) {
|
||||||
|
if(!fp) return NULL;
|
||||||
|
// loads dynamically as a list of json objects in the given file
|
||||||
|
// TODO: im done for the day do thsi tmr
|
||||||
|
|
||||||
|
todolist *list = tdl_init();
|
||||||
|
return list;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue