libmpm

morphux C package management library
Log | Files | Refs | Submodules | README | LICENSE | git clone https://git.ne02ptzero.me/git/libmpm

commit ad71bd88b9bcf7da1f57814ea03d616cf6125e58
parent 75d2aea9765c748f8392734361132ed096ad1735
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon,  6 Mar 2017 19:44:16 +0100

Fix(Compilation Error)

Diffstat:
Minc/category.h | 2+-
Minc/database.h | 5-----
Msrc/database.c | 103++++++++++++++++++++++++++++++++++++++-----------------------------------------
3 files changed, 50 insertions(+), 60 deletions(-)

diff --git a/inc/category.h b/inc/category.h @@ -19,7 +19,7 @@ # include <morphux.h> -typedef struct s_category category_t; +typedef struct category_s category_t; # include <libmpm.h> diff --git a/inc/database.h b/inc/database.h @@ -81,11 +81,6 @@ typedef struct database_s { } database_t; -/* SQL callbacks */ -SQL_CALLBACK_DEF(callback_package); -SQL_CALLBACK_DEF(callback_files); -SQL_CALLBACK_DEF(callback_categ); - /*! * \brief Open a connection to a database * \param ret Return code, if any error diff --git a/src/database.c b/src/database.c @@ -16,6 +16,55 @@ #include <database.h> +SQL_CALLBACK_DEF(callback_files) { + mlist_t **head = context; + file_t *ptr; + + ptr = malloc(sizeof(file_t)); + assert(ptr != NULL); + mpm_file_init(ptr); + + for (u8_t i = 0; i < col_num; i++) + sql_to_file(ptr, col_name[i], col_txt[i]); + + list_add(*(head), ptr, sizeof(file_t)); + free(ptr); + return 0; +} + +SQL_CALLBACK_DEF(callback_package) { + mlist_t **head = context; + package_t *ptr; + + ptr = malloc(sizeof(package_t)); + assert(ptr != NULL); + mpm_package_init(ptr); + + for (u8_t i = 0; i < col_num; i++) + sql_to_package(ptr, col_name[i], col_txt[i]); + + list_add(*(head), ptr, sizeof(package_t)); + free(ptr); + return 0; +} + +SQL_CALLBACK_DEF(callback_categ) { + mlist_t **head = context; + category_t *ptr; + + ptr = malloc(sizeof(category_t)); + assert(ptr != NULL); + mpm_category_init(ptr); + + for (u8_t i = 0; i < col_num; i++) + ptr = sql_to_category(ptr, col_name[i], col_txt[i]); + + list_add(*(head), ptr, sizeof(category_t)); + free(ptr); + return 0; +} + + database_t *mpm_database_open(u8_t *ret, const char *fn) { database_t *ptr; u8_t error = 0; @@ -56,24 +105,6 @@ u8_t mpm_database_exec(database_t *ptr, const char *query, return sqlite3_exec(ptr->sql, query, cl, ct, err); } -/** - * int name(void *context, int col_num, char **col_txt, char **col_name) - */ -SQL_CALLBACK_DEF(callback_package) { - mlist_t **head = context; - package_t *ptr; - - ptr = malloc(sizeof(package_t)); - assert(ptr != NULL); - mpm_package_init(ptr); - - for (u8_t i = 0; i < col_num; i++) - sql_to_package(ptr, col_name[i], col_txt[i]); - - list_add(*(head), ptr, sizeof(package_t)); - free(ptr); - return 0; -} u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, mlist_t **pkg) { @@ -274,24 +305,6 @@ u8_t mpm_get_file_by_parent_name(database_t *ptr, const char *name, } -/** - * int name(void *context, int col_num, char **col_txt, char **col_name) - */ -SQL_CALLBACK_DEF(callback_files) { - mlist_t **head = context; - file_t *ptr; - - ptr = malloc(sizeof(file_t)); - assert(ptr != NULL); - mpm_file_init(ptr); - - for (u8_t i = 0; i < col_num; i++) - sql_to_file(ptr, col_name[i], col_txt[i]); - - list_add(*(head), ptr, sizeof(file_t)); - free(ptr); - return 0; -} file_t *sql_to_file(file_t *ptr, char *name, char *val) { @@ -399,24 +412,6 @@ u8_t mpm_get_categ_by_name(database_t *ptr, const char *name, mlist_t **cat) return ret; } -/** - * int name(void *context, int col_num, char **col_txt, char **col_name) - */ -SQL_CALLBACK_DEF(callback_categ) { - mlist_t **head = context; - category_t *ptr; - - ptr = malloc(sizeof(category_t)); - assert(ptr != NULL); - mpm_category_init(ptr); - - for (u8_t i = 0; i < col_num; i++) - ptr = sql_to_category(ptr, col_name[i], col_txt[i]); - - list_add(*(head), ptr, sizeof(category_t)); - free(ptr); - return 0; -} category_t *sql_to_category(category_t *ptr, char *name, char *val) { if (ptr == NULL)