libmpm

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

commit 93df8b45f9f0e6b9c0aa92fd66e68206799d49e5
parent d57bbd7a7a7c2b502b0d768ee51a7fc70f294c24
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Fri, 10 Feb 2017 11:41:55 +0100

Fix(Includes): Tabs2Spaces

Diffstat:
Minc/category.h | 28++++++++++++++--------------
Minc/database.h | 131++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Minc/files.h | 42+++++++++++++++++++++---------------------
Minc/flags.h | 8++++----
Minc/package.h | 64++++++++++++++++++++++++++++++++--------------------------------
Msrc/files.c | 38+++++++++++++++++++-------------------
Msrc/flags.c | 14+++++++-------
Msrc/package.c | 58+++++++++++++++++++++++++++++-----------------------------
8 files changed, 202 insertions(+), 181 deletions(-)

diff --git a/inc/category.h b/inc/category.h @@ -19,25 +19,25 @@ # include <morphux.h> -typedef struct s_category category_t; +typedef struct s_category category_t; # include <libmpm.h> -# define CAT_TABLE "categ" -# define CAT_COL_ID "id" -# define CAT_COL_NAME "name" -# define CAT_COL_PARENT "parent" -# define CAT_COL_PARENT_NAME "parent_name" +# define CAT_TABLE "categ" +# define CAT_COL_ID "id" +# define CAT_COL_NAME "name" +# define CAT_COL_PARENT "parent" +# define CAT_COL_PARENT_NAME "parent_name" -typedef struct s_category { - u64_t id; - char *name; - char *parent_name; - package_t *parent; -} category_t; +typedef struct s_category { + u64_t id; + char *name; + char *parent_name; + package_t *parent; +} category_t; -int mpm_category_free(void *tmp); -void mpm_category_init(category_t *ptr); +int mpm_category_free(void *tmp); +void mpm_category_init(category_t *ptr); #endif /* CATEGORY_H */ diff --git a/inc/database.h b/inc/database.h @@ -22,43 +22,63 @@ # include <package.h> # define DB_FN "test.db" -# define SQL_CALLBACK_PTR(name) int (*name)(void *, int, char**, char**) -# define SQL_CALLBACK_DEF(name) int name(void *context, int col_num, \ - char **col_txt, char **col_name) +# define SQL_CALLBACK_PTR(name) int (*name)(void *, int, char**, char**) +# define SQL_CALLBACK_DEF(name) int name(void *context, int col_num, \ + char **col_txt, char **col_name) -/* Package Search queries */ -# define QUERY_GET_PACKAGE_BY_ID(id) "SELECT * FROM " PKG_TABLE \ - " WHERE " PKG_COL_ID "= %lld", id -# define QUERY_GET_PACKAGE_BY_NAME(name) "SELECT * FROM " PKG_TABLE \ - " WHERE " PKG_COL_NAME " = \"%s\"", name +/* Package search queries */ +# define QUERY_GET_PACKAGE_BY_ID(id) "SELECT * FROM " \ + PKG_TABLE \ + " WHERE " PKG_COL_ID \ + " = %lld", id + +# define QUERY_GET_PACKAGE_BY_NAME(name) "SELECT * FROM " \ + PKG_TABLE \ + " WHERE " PKG_COL_NAME \ + " = \"%s\"", name /* File search queries */ -# define QUERY_GET_FILES_BY_ID(id) "SELECT * FROM " FILE_TABLE \ - " WHERE " FILE_COL_ID " = %lld", id -# define QUERY_GET_FILES_BY_PATH(path) "SELECT * FROM " FILE_TABLE \ - " WHERE " FILE_COL_PATH " = \"%s\"", path -# define QUERY_GET_FILES_BY_PARENT_ID(id) "SELECT * FROM " FILE_TABLE \ - " WHERE " FILE_COL_PARENT " = %lld", id -# define QUERY_GET_FILES_BY_PARENT_NAME(name) "SELECT * FROM " FILE_TABLE \ - " WHERE " FILE_COL_PARENT_NAME " = \"%s\"", \ - name +# define QUERY_GET_FILES_BY_ID(id) "SELECT * FROM " \ + FILE_TABLE \ + " WHERE " FILE_COL_ID \ + " = %lld", id + +# define QUERY_GET_FILES_BY_PATH(path) "SELECT * FROM " \ + FILE_TABLE \ + " WHERE " FILE_COL_PATH \ + " = \"%s\"", path + +# define QUERY_GET_FILES_BY_PARENT_ID(id) "SELECT * FROM " \ + FILE_TABLE \ + " WHERE " FILE_COL_PARENT \ + " = %lld", id + +# define QUERY_GET_FILES_BY_PARENT_NAME(name) "SELECT * FROM " \ + FILE_TABLE \ + " WHERE " FILE_COL_PARENT_NAME \ + " = \"%s\"", name /* Category search queries */ -# define QUERY_GET_CATEG_BY_ID(id) "SELECT * FROM " CAT_TABLE \ - " WHERE " CAT_COL_ID " = %lld", id -# define QUERY_GET_CATEG_BY_NAME(name) "SELECT * FROM " CAT_TABLE \ - " WHERE " CAT_COL_NAME " = \"%s\"", name +# define QUERY_GET_CATEG_BY_ID(id) "SELECT * FROM " \ + CAT_TABLE \ + " WHERE " CAT_COL_ID \ + " = %lld", id + +# define QUERY_GET_CATEG_BY_NAME(name) "SELECT * FROM " \ + CAT_TABLE \ + " WHERE " CAT_COL_NAME \ + " = \"%s\"", name -# define SQL_CREATE_TABLE "CREATE table " -# define SQL_INSERT_TABLE "INSERT INTO " -# define SQL_TYPE_PRIMARY_KEY " primary key " -# define SQL_TYPE_NOT_NULL " not null " -# define SQL_TYPE_INT " integer " -# define SQL_TYPE_TEXT " text " +# define SQL_CREATE_TABLE "CREATE table " +# define SQL_INSERT_TABLE "INSERT INTO " +# define SQL_TYPE_PRIMARY_KEY " primary key " +# define SQL_TYPE_NOT_NULL " not null " +# define SQL_TYPE_INT " integer " +# define SQL_TYPE_TEXT " text " -typedef struct s_database { - sqlite3 *sql; -} database_t; +typedef struct s_database { + sqlite3 *sql; +} database_t; /* SQL callbacks */ @@ -66,30 +86,31 @@ SQL_CALLBACK_DEF(callback_package); SQL_CALLBACK_DEF(callback_files); SQL_CALLBACK_DEF(callback_categ); -database_t *mpm_database_open(u8_t *ret, const char *fn); -u8_t mpm_database_close(database_t *ptr); -u8_t mpm_database_exec(database_t *ptr, const char *query, - SQL_CALLBACK_PTR(cl), void *ct, char **err); -u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, - mlist_t **pkg); -u8_t mpm_get_package_by_name(database_t *ptr, const char *name, - mlist_t **pkg); -package_t *sql_to_package(package_t *ptr, char *name, char *val); -u8_t mpm_database_init(database_t *ptr); -u8_t mpm_database_add_pkg(database_t *ptr, package_t *pkg); -u8_t mpm_get_file_by_id(database_t *ptr, u64_t id, - mlist_t **files); -u8_t mpm_get_file_by_path(database_t *ptr, const char *path, - mlist_t **files); -u8_t mpm_get_file_by_parent_id(database_t *ptr, u64_t id, - mlist_t **files); -u8_t mpm_get_file_by_parent_name(database_t *ptr, const char *name, - mlist_t **files); -file_t *sql_to_file(file_t *ptr, char *name, char *val); -u8_t mpm_database_add_file(database_t *ptr, file_t *file); -category_t *sql_to_category(category_t *ptr, char *name, char *val); -u8_t mpm_get_categ_by_id(database_t *ptr, u64_t id, mlist_t **cat); -u8_t mpm_get_categ_by_name(database_t *ptr, const char *name, mlist_t **cat); -u8_t mpm_database_add_categ(database_t *ptr, category_t *cat); +database_t *mpm_database_open(u8_t *ret, const char *fn); +u8_t mpm_database_close(database_t *ptr); +u8_t mpm_database_exec(database_t *ptr, const char *query, + SQL_CALLBACK_PTR(cl), void *ct, char **err); +u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, + mlist_t **pkg); +u8_t mpm_get_package_by_name(database_t *ptr, const char *name, + mlist_t **pkg); +package_t *sql_to_package(package_t *ptr, char *name, char *val); +u8_t mpm_database_init(database_t *ptr); +u8_t mpm_database_add_pkg(database_t *ptr, package_t *pkg); +u8_t mpm_get_file_by_id(database_t *ptr, u64_t id, + mlist_t **files); +u8_t mpm_get_file_by_path(database_t *ptr, const char *path, + mlist_t **files); +u8_t mpm_get_file_by_parent_id(database_t *ptr, u64_t id, + mlist_t **files); +u8_t mpm_get_file_by_parent_name(database_t *ptr, const char *name, + mlist_t **files); +file_t *sql_to_file(file_t *ptr, char *name, char *val); +u8_t mpm_database_add_file(database_t *ptr, file_t *file); +category_t *sql_to_category(category_t *ptr, char *name, char *val); +u8_t mpm_get_categ_by_id(database_t *ptr, u64_t id, mlist_t **cat); +u8_t mpm_get_categ_by_name(database_t *ptr, const char *name, + mlist_t **cat); +u8_t mpm_database_add_categ(database_t *ptr, category_t *cat); #endif /* DATABASE_H */ diff --git a/inc/files.h b/inc/files.h @@ -19,35 +19,35 @@ # include <morphux.h> -# define FILE_TABLE "files" -# define FILE_COL_ID "id" -# define FILE_COL_PATH "path" -# define FILE_COL_TYPE "type" -# define FILE_COL_PARENT "parent" -# define FILE_COL_PARENT_NAME "parent_name" -# define FILE_COL_HASH "hash" +# define FILE_TABLE "files" +# define FILE_COL_ID "id" +# define FILE_COL_PATH "path" +# define FILE_COL_TYPE "type" +# define FILE_COL_PARENT "parent" +# define FILE_COL_PARENT_NAME "parent_name" +# define FILE_COL_HASH "hash" typedef struct s_package package_t; enum { - FILE_TYPE_CONFIG, - FILE_TYPE_BIN, - FILE_TYPE_LIB, - FILE_TYPE_OTHER + FILE_TYPE_CONFIG, + FILE_TYPE_BIN, + FILE_TYPE_LIB, + FILE_TYPE_OTHER }; -typedef struct s_file { - u64_t id; - char *path; - u8_t type; - package_t *parent; - char *parent_name; - char *hash; -} file_t; +typedef struct s_file { + u64_t id; + char *path; + u8_t type; + package_t *parent; + char *parent_name; + char *hash; +} file_t; -void mpm_file_init(file_t *ptr); -int mpm_file_free(void *tmp); +void mpm_file_init(file_t *ptr); +int mpm_file_free(void *tmp); # include <package.h> #endif /* FILES_H */ diff --git a/inc/flags.h b/inc/flags.h @@ -19,11 +19,11 @@ # include <morphux.h> enum { - MPM_VERBOSE_LEVEL = 0, - MPM_LAST /* Always keep this one last */ + MPM_VERBOSE_LEVEL = 0, + MPM_LAST /* Always keep this one last */ }; -void mpm_set_flag(u8_t flag, u8_t val); -u8_t mpm_get_flag(u8_t flag); +void mpm_set_flag(u8_t flag, u8_t val); +u8_t mpm_get_flag(u8_t flag); #endif /* FLAGS_H */ diff --git a/inc/package.h b/inc/package.h @@ -21,42 +21,42 @@ # include <files.h> enum { - PACKAGE_STATE_USER_INSTALLED, - PACKAGE_STATE_DEPENDENCY, - PACKAGE_STATE_ORPHAN + PACKAGE_STATE_USER_INSTALLED, + PACKAGE_STATE_DEPENDENCY, + PACKAGE_STATE_ORPHAN }; -typedef struct s_category category_t; - -# define PKG_TABLE "pkgs" -# define PKG_COL_ID "id" -# define PKG_COL_NAME "name" -# define PKG_COL_VERSION "version" -# define PKG_COL_CATEG "categ" -# define PKG_COL_DESC "desc" -# define PKG_COL_STATE "state" -# define PKG_COL_DEPS "deps" -# define PKG_COL_FILES "files" -# define PKG_COL_BINARIES "binaries" -# define PKG_COL_CONFIG "config" -# define PKG_COL_DOCS "docs" +typedef struct s_category category_t; + +# define PKG_TABLE "pkgs" +# define PKG_COL_ID "id" +# define PKG_COL_NAME "name" +# define PKG_COL_VERSION "version" +# define PKG_COL_CATEG "categ" +# define PKG_COL_DESC "desc" +# define PKG_COL_STATE "state" +# define PKG_COL_DEPS "deps" +# define PKG_COL_FILES "files" +# define PKG_COL_BINARIES "binaries" +# define PKG_COL_CONFIG "config" +# define PKG_COL_DOCS "docs" typedef struct s_package { - u64_t id; - char *name; - char *version; - category_t *categ; - char *desc; - u8_t state; - mlist_t *deps; - mlist_t *files; - mlist_t *binaries; - mlist_t *config; - mlist_t *docs; -} package_t; - -int mpm_package_free(void *tmp); -void mpm_package_init(package_t *ptr); + u64_t id; + char *name; + char *version; + category_t *categ; + char *desc; + u8_t state; + mlist_t *deps; + mlist_t *files; + mlist_t *binaries; + mlist_t *config; + mlist_t *docs; +} package_t; + +int mpm_package_free(void *tmp); +void mpm_package_init(package_t *ptr); # include <category.h> #endif /* PACKAGE_H */ diff --git a/src/files.c b/src/files.c @@ -20,30 +20,30 @@ * \brief Initialize a file_t structure * \param ptr Structure to initialize */ -void mpm_file_init(file_t *ptr) { - if (ptr) { - ptr->path = NULL; - ptr->parent = NULL; - ptr->hash = NULL; - ptr->parent_name = NULL; - } +void mpm_file_init(file_t *ptr) { + if (ptr) { + ptr->path = NULL; + ptr->parent = NULL; + ptr->hash = NULL; + ptr->parent_name = NULL; + } } /*! * \brief Free a file_t entry * \note Can be called as a callback of list_free */ -int mpm_file_free(void *tmp) { - file_t *ptr = tmp; +int mpm_file_free(void *tmp) { + file_t *ptr = tmp; - if (ptr) { - free(ptr->path); - free(ptr->hash); - free(ptr->parent_name); - if (ptr->parent != NULL) { - mpm_package_free(ptr->parent); - free(ptr->parent); - } - } - return 1; + if (ptr) { + free(ptr->path); + free(ptr->hash); + free(ptr->parent_name); + if (ptr->parent != NULL) { + mpm_package_free(ptr->parent); + free(ptr->parent); + } + } + return 1; } diff --git a/src/flags.c b/src/flags.c @@ -16,7 +16,7 @@ #include <flags.h> -static u8_t mpm_flags[MPM_LAST] = {0}; +static u8_t mpm_flags[MPM_LAST] = {0}; /*! * \brief Set an internal flag @@ -25,9 +25,9 @@ static u8_t mpm_flags[MPM_LAST] = {0}; * \note If the flag is greater than MPM_LAST value this function won't do * anything */ -void mpm_set_flag(u8_t flag, u8_t val) { - if (flag < MPM_LAST) - mpm_flags[flag] = val; +void mpm_set_flag(u8_t flag, u8_t val) { + if (flag < MPM_LAST) + mpm_flags[flag] = val; } /*! @@ -37,7 +37,7 @@ void mpm_set_flag(u8_t flag, u8_t val) { * \note If the value asked by the caller is higher than MPM_LAST, this function * will raiser an assertion. */ -u8_t mpm_get_flag(u8_t flag) { - assert(flag < MPM_LAST); - return mpm_flags[flag]; +u8_t mpm_get_flag(u8_t flag) { + assert(flag < MPM_LAST); + return mpm_flags[flag]; } diff --git a/src/package.c b/src/package.c @@ -20,40 +20,40 @@ * \brief Free a package entry * \note Can be used as list_free callback */ -int mpm_package_free(void *tmp) { - package_t *ptr = tmp; +int mpm_package_free(void *tmp) { + package_t *ptr = tmp; - if (ptr) { - free(ptr->name); - free(ptr->version); - free(ptr->desc); - if (ptr->categ != NULL) { - ptr->categ->parent = NULL; - mpm_category_free(ptr->categ); - free(ptr->categ); - } - /*list_free(ptr->deps, &package_free);*/ - /* TODO: Files free */ - } - return 1; + if (ptr) { + free(ptr->name); + free(ptr->version); + free(ptr->desc); + if (ptr->categ != NULL) { + ptr->categ->parent = NULL; + mpm_category_free(ptr->categ); + free(ptr->categ); + } + /*list_free(ptr->deps, &package_free);*/ + /* TODO: Files free */ + } + return 1; } /*! * \brief Initialize a package entry * \param ptr Pointer to an allocated ptr */ -void mpm_package_init(package_t *ptr) { - if (ptr) { - ptr->id = 0; - ptr->state = PACKAGE_STATE_ORPHAN; - ptr->name = NULL; - ptr->version = NULL; - ptr->categ = NULL; - ptr->desc = NULL; - ptr->deps = NULL; - ptr->files = NULL; - ptr->binaries = NULL; - ptr->config = NULL; - ptr->docs = NULL; - } +void mpm_package_init(package_t *ptr) { + if (ptr) { + ptr->id = 0; + ptr->state = PACKAGE_STATE_ORPHAN; + ptr->name = NULL; + ptr->version = NULL; + ptr->categ = NULL; + ptr->desc = NULL; + ptr->deps = NULL; + ptr->files = NULL; + ptr->binaries = NULL; + ptr->config = NULL; + ptr->docs = NULL; + } }