libmpm

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

commit 35740ce0d430f6f772c4a48c15d22d851397b6c1
parent 39c2d28bdc147e5345257d0eb08ac74defddd375
Author: Ne02ptzero <louis@ne02ptzero.me>
Date:   Mon, 13 Mar 2017 21:51:18 +0100

Merge branch 'unstable' of https://github.com/Morphux/libmpm into unstable

Diffstat:
MMakefile | 2+-
Mdocs/doxyfile | 3++-
Minc/category.h | 10+++++-----
Minc/config.h | 10+++++-----
Minc/database.h | 63++++++++++++++++++++++++++++-----------------------------------
Minc/files.h | 12++++++------
Minc/flags.h | 8++++----
Minc/package.h | 16++++++++--------
Msrc/category.c | 6+++---
Msrc/config.c | 10+++++-----
Msrc/database.c | 79+++++++++++++++++++++++++++++++++++++------------------------------------------
Msrc/files.c | 4++--
Msrc/flags.c | 6+++---
Msrc/package.c | 6+++---
14 files changed, 112 insertions(+), 123 deletions(-)

diff --git a/Makefile b/Makefile @@ -79,7 +79,7 @@ init: cd lib/json-c/ && sh autogen.sh && ./configure --disable-shared && make cd lib/libconfuse/ && sh autogen.sh && ./configure && make -docs: +doc: doxygen docs/doxyfile check: all diff --git a/docs/doxyfile b/docs/doxyfile @@ -108,9 +108,10 @@ WARN_LOGFILE = #--------------------------------------------------------------------------- # Configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = src +INPUT = inc INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.c \ + *.h \ *.cc \ *.cxx \ *.cpp \ diff --git a/inc/category.h b/inc/category.h @@ -19,7 +19,7 @@ # include <morphux.h> -typedef struct category_s category_t; +typedef struct category_s category_t; # include <libmpm.h> @@ -29,24 +29,24 @@ typedef struct category_s category_t; # define CAT_COL_PARENT "parent" # define CAT_COL_PARENT_NAME "parent_name" -typedef struct category_s { +typedef struct category_s { u64_t id; char *name; char *parent_name; package_t *parent; -} category_t; +} category_t; /*! * \brief Free a category * \param[in] tmp Pointer to free * \note This function can be used as a list_free callback */ -int mpm_category_free(void *tmp); +int mpm_category_free(void *tmp); /*! * \brief Initialize a category_t * \param[in,out] ptr Structure to initialize */ -void mpm_category_init(category_t *ptr); +void mpm_category_init(category_t *ptr); #endif /* CATEGORY_H */ diff --git a/inc/config.h b/inc/config.h @@ -81,11 +81,11 @@ # define ERROR_MAX_LEN 250 -typedef struct config_s { +typedef struct config_s { cfg_t *ptr; char *fn; char *err; -} config_t; +} config_t; /*! * \brief Initialize a new config_t structure and read a config file @@ -97,18 +97,18 @@ typedef struct config_s { * * \return A freshly allocated structure */ -config_t *parse_config(const char *path, u8_t *ret); +config_t *parse_config(const char *path, u8_t *ret); /*! * \brief Free a config_t pointer * \param[in,out] ptr Pointer to free */ -void config_free(config_t **ptr); +void config_free(config_t **ptr); /*! * \brief Get the parsing error string * \param[in] ptr Config context */ -void config_get_error_string(config_t *ptr); +void config_get_error_string(config_t *ptr); #endif /* CONFIG_H */ diff --git a/inc/database.h b/inc/database.h @@ -76,9 +76,9 @@ # define SQL_TYPE_INT " integer " # define SQL_TYPE_TEXT " text " -typedef struct database_s { +typedef struct database_s { sqlite3 *sql; -} database_t; +} database_t; /*! @@ -93,7 +93,7 @@ typedef struct database_s { * database file path. * \return A fresh database_t structure */ -database_t *mpm_database_open(u8_t *ret, const char *fn); +database_t *mpm_database_open(u8_t *ret, const char *fn); /*! * \brief Close a connection to an existing database @@ -103,7 +103,7 @@ database_t *mpm_database_open(u8_t *ret, const char *fn); * On any error, this function will return the error code. * \return The error code */ -u8_t mpm_database_close(database_t *ptr); +u8_t mpm_database_close(database_t *ptr); /*! * \brief Execute a SQL query on an already opened database @@ -123,7 +123,7 @@ u8_t mpm_database_close(database_t *ptr); * This string is allocated by the sqlite library, and should be freed by the * caller. */ -u8_t mpm_database_exec(database_t *ptr, const char *query, +u8_t mpm_database_exec(database_t *ptr, const char *query, SQL_CALLBACK_PTR(cl), void *ct, char **err); /*! * \brief Get a package by his Id @@ -142,8 +142,7 @@ u8_t mpm_database_exec(database_t *ptr, const char *query, * \note This function will set pkg to NULL before filling it with the results. * You should not call this function with an existing package list. */ -u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, - mlist_t **pkg); +u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, mlist_t **pkg); /*! * \brief Get a package by his name * \param[in] ptr Opened Database connection @@ -161,13 +160,12 @@ u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, * \note This function will set pkg to NULL before filling it with the results. * You should not call this function with an existing package list. */ -u8_t mpm_get_package_by_name(database_t *ptr, const char *name, - mlist_t **pkg); +u8_t mpm_get_package_by_name(database_t *ptr, const char *name, mlist_t **pkg); /*! * \brief Fill a package_t structure with a SQL result - * \param ptr[in] Pointer to package_t. Must not be NULL. - * \param name[in] Name of the column - * \param val[in] Value of the column + * \param[in] ptr Pointer to package_t. Must not be NULL. + * \param[in] name Name of the column + * \param[in] val Value of the column * * This function will transform an SQL result, given through an sqlite callback, * and fill a package_t structure with it. @@ -175,11 +173,11 @@ u8_t mpm_get_package_by_name(database_t *ptr, const char *name, * * \note If a unknown column is passed to this function, a panic will be throwed. */ -package_t *sql_to_package(package_t *ptr, char *name, char *val); +package_t *sql_to_package(package_t *ptr, char *name, char *val); /*! * \brief Init an empty database - * \param ptr[in] Open connection to a database + * \param[in] ptr Open connection to a database * * This function will create tables in an empty database. * Careful, this function do not check if a database is empty before making @@ -189,16 +187,16 @@ package_t *sql_to_package(package_t *ptr, char *name, char *val); * * \return Status code */ -u8_t mpm_database_init(database_t *ptr); +u8_t mpm_database_init(database_t *ptr); /*! * \brief Add a package entry in the database - * \param ptr[in] Opened connection to a database - * \param pkg[in] Package to add + * \param[in] ptr Opened connection to a database + * \param[in] pkg Package to add * * This function will add a package entry to an already opened connection. */ -u8_t mpm_database_add_pkg(database_t *ptr, package_t *pkg); +u8_t mpm_database_add_pkg(database_t *ptr, package_t *pkg); /*! * \brief Get a file by his Id @@ -217,8 +215,7 @@ u8_t mpm_database_add_pkg(database_t *ptr, package_t *pkg); * You should not call this function with an existing files list. * \return Error code */ -u8_t mpm_get_file_by_id(database_t *ptr, u64_t id, - mlist_t **files); +u8_t mpm_get_file_by_id(database_t *ptr, u64_t id, mlist_t **files); /*! * \brief Get a file by his path @@ -237,8 +234,7 @@ u8_t mpm_get_file_by_id(database_t *ptr, u64_t id, * You should not call this function with an existing files list. * \return Error code */ -u8_t mpm_get_file_by_path(database_t *ptr, const char *path, - mlist_t **files); +u8_t mpm_get_file_by_path(database_t *ptr, const char *path, mlist_t **files); /*! * \brief Get a file by his parent id @@ -257,8 +253,7 @@ u8_t mpm_get_file_by_path(database_t *ptr, const char *path, * You should not call this function with an existing files list. * \return Error code */ -u8_t mpm_get_file_by_parent_id(database_t *ptr, u64_t id, - mlist_t **files); +u8_t mpm_get_file_by_parent_id(database_t *ptr, u64_t id, mlist_t **files); /*! * \brief Get a file by his parent name @@ -277,8 +272,7 @@ u8_t mpm_get_file_by_parent_id(database_t *ptr, u64_t id, * You should not call this function with an existing files list. * \return Error code */ -u8_t mpm_get_file_by_parent_name(database_t *ptr, const char *name, - mlist_t **files); +u8_t mpm_get_file_by_parent_name(database_t *ptr, const char *name, mlist_t **files); /*! * \brief Fill a file_t structure with a SQL result @@ -292,14 +286,14 @@ u8_t mpm_get_file_by_parent_name(database_t *ptr, const char *name, * * \note If a unknown column is passed to this function, a panic will be throwed. */ -file_t *sql_to_file(file_t *ptr, char *name, char *val); +file_t *sql_to_file(file_t *ptr, char *name, char *val); /*! * \brief Add a file entry to the database * \param[in] ptr Opened connection to a database * \param[in] file File to add */ -u8_t mpm_database_add_file(database_t *ptr, file_t *file); +u8_t mpm_database_add_file(database_t *ptr, file_t *file); /*! * \brief Fill a category_t structure with a SQL result @@ -313,13 +307,13 @@ u8_t mpm_database_add_file(database_t *ptr, file_t *file); * * \note If a unknown column is passed to this function, a panic will be throwed. */ -category_t *sql_to_category(category_t *ptr, char *name, char *val); +category_t *sql_to_category(category_t *ptr, char *name, char *val); /*! * \brief Get a category by his Id * \param[in] ptr Opened Database connection * \param[in] id ID to search for - * \param[out] files Pointer on a list, used to store the results + * \param[out] cat Pointer on a list, used to store the results * * This function will search in an already opened database a category with a * given id. @@ -332,13 +326,13 @@ category_t *sql_to_category(category_t *ptr, char *name, char *val); * You should not call this function with an existing files list. * \return Error code */ -u8_t mpm_get_categ_by_id(database_t *ptr, u64_t id, mlist_t **cat); +u8_t mpm_get_categ_by_id(database_t *ptr, u64_t id, mlist_t **cat); /*! * \brief Get a category by his name * \param[in] ptr Opened Database connection * \param[in] name Name to search for - * \param[out] files Pointer on a list, used to store the results + * \param[out] cat Pointer on a list, used to store the results * * This function will search in an already opened database a category with a * given name. @@ -351,14 +345,13 @@ u8_t mpm_get_categ_by_id(database_t *ptr, u64_t id, mlist_t **cat); * You should not call this function with an existing files list. * \return Error code */ -u8_t mpm_get_categ_by_name(database_t *ptr, const char *name, - mlist_t **cat); +u8_t mpm_get_categ_by_name(database_t *ptr, const char *name, mlist_t **cat); /*! * \brief Add a category in the database * \param[in] ptr Opened connection to a database * \param[in] cat Category to add */ -u8_t mpm_database_add_categ(database_t *ptr, category_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 @@ -29,34 +29,34 @@ typedef struct package_s package_t; -typedef enum file_type_e { +typedef enum file_type_e { FILE_TYPE_CONFIG = 1, FILE_TYPE_BIN, FILE_TYPE_LIB, FILE_TYPE_OTHER -} file_type_t; +} file_type_t; -typedef struct file_s { +typedef struct file_s { u64_t id; char *path; file_type_t type; package_t *parent; char *parent_name; char *hash; -} file_t; +} file_t; /*! * \brief Initialize a file_t structure * \param[in,out] ptr Structure to initialize */ -void mpm_file_init(file_t *ptr); +void mpm_file_init(file_t *ptr); /*! * \brief Free a file_t entry * \param[in] tmp Pointer to free * \note Can be called as a callback of list_free */ -int mpm_file_free(void *tmp); +int mpm_file_free(void *tmp); # include <package.h> #endif /* FILES_H */ diff --git a/inc/flags.h b/inc/flags.h @@ -18,10 +18,10 @@ # define FLAGS_H # include <morphux.h> -typedef enum flag_index_e { +typedef enum flag_index_e { MPM_VERBOSE_LEVEL = 0, MPM_LAST /* Always keep this one last */ -} flag_index_t; +} flag_index_t; /*! * \brief Set an internal flag @@ -30,7 +30,7 @@ typedef enum flag_index_e { * \note If the flag is greater than MPM_LAST value this function won't do * anything */ -void mpm_set_flag(flag_index_t flag, u8_t val); +void mpm_set_flag(flag_index_t flag, u8_t val); /*! * \brief Get an internal flag @@ -39,6 +39,6 @@ void mpm_set_flag(flag_index_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(flag_index_t flag); +u8_t mpm_get_flag(flag_index_t flag); #endif /* FLAGS_H */ diff --git a/inc/package.h b/inc/package.h @@ -20,13 +20,13 @@ # include <morphux.h> # include <files.h> -typedef enum package_state_e { +typedef enum package_state_e { PACKAGE_STATE_USER_INSTALLED, PACKAGE_STATE_DEPENDENCY, PACKAGE_STATE_ORPHAN -} package_state_t; +} package_state_t; -typedef struct category_s category_t; +typedef struct category_s category_t; # define PKG_TABLE "pkgs" # define PKG_COL_ID "id" @@ -41,7 +41,7 @@ typedef struct category_s category_t; # define PKG_COL_CONFIG "config" # define PKG_COL_DOCS "docs" -typedef struct package_s { +typedef struct package_s { u64_t id; char *name; char *version; @@ -53,19 +53,19 @@ typedef struct package_s { mlist_t *binaries; mlist_t *config; mlist_t *docs; -} package_t; +} package_t; /*! * \brief Free a package entry * \note Can be used as list_free callback */ -int mpm_package_free(void *tmp); +int mpm_package_free(void *tmp); /*! * \brief Initialize a package entry - * \param ptr[in,out] Pointer to an allocated ptr + * \param[in,out] ptr Pointer to an allocated ptr */ -void mpm_package_init(package_t *ptr); +void mpm_package_init(package_t *ptr); # include <category.h> #endif /* PACKAGE_H */ diff --git a/src/category.c b/src/category.c @@ -14,9 +14,9 @@ * limitations under the License. * \******************************************************************************/ -# include <category.h> +#include <category.h> -int mpm_category_free(void *tmp) { +int mpm_category_free(void *tmp) { category_t *ptr = tmp; if (ptr) @@ -33,7 +33,7 @@ int mpm_category_free(void *tmp) { return 1; } -void mpm_category_init(category_t *ptr) { +void mpm_category_init(category_t *ptr) { if (ptr) { ptr->name = NULL; diff --git a/src/config.c b/src/config.c @@ -16,9 +16,9 @@ #include "config.h" -static char g_error[ERROR_MAX_LEN] = ""; +static char g_error[ERROR_MAX_LEN] = ""; -static void config_error_cb(cfg_t *ptr, const char *fmt, va_list ap) { +static void config_error_cb(cfg_t *ptr, const char *fmt, va_list ap) { char err[250]; (void)ptr; @@ -27,7 +27,7 @@ static void config_error_cb(cfg_t *ptr, const char *fmt, va_list ap) strcpy(g_error, err); } -config_t *parse_config(const char *path, u8_t *ret) { +config_t *parse_config(const char *path, u8_t *ret) { config_t *config = NULL; /* Main section */ @@ -110,7 +110,7 @@ config_t *parse_config(const char *path, u8_t *ret) { return config; } -void config_free(config_t **ptr) { +void config_free(config_t **ptr) { if (ptr != NULL && *ptr != NULL) { cfg_free((*ptr)->ptr); @@ -121,7 +121,7 @@ void config_free(config_t **ptr) { } } -void config_get_error_string(config_t *ptr) { +void config_get_error_string(config_t *ptr) { if (strlen(g_error) == 0 || ptr == NULL) return ; diff --git a/src/database.c b/src/database.c @@ -17,8 +17,8 @@ #include <database.h> SQL_CALLBACK_DEF(callback_files) { - mlist_t **head = context; - file_t *ptr; + mlist_t **head = context; + file_t *ptr; ptr = malloc(sizeof(file_t)); assert(ptr != NULL); @@ -49,8 +49,8 @@ SQL_CALLBACK_DEF(callback_package) { } SQL_CALLBACK_DEF(callback_categ) { - mlist_t **head = context; - category_t *ptr; + mlist_t **head = context; + category_t *ptr; ptr = malloc(sizeof(category_t)); assert(ptr != NULL); @@ -65,7 +65,7 @@ SQL_CALLBACK_DEF(callback_categ) { } -database_t *mpm_database_open(u8_t *ret, const char *fn) { +database_t *mpm_database_open(u8_t *ret, const char *fn) { database_t *ptr; u8_t error = 0; @@ -86,7 +86,7 @@ error: return NULL; } -u8_t mpm_database_close(database_t *ptr) { +u8_t mpm_database_close(database_t *ptr) { u8_t error = 1; if (ptr != NULL) @@ -97,8 +97,8 @@ u8_t mpm_database_close(database_t *ptr) { return error; } -u8_t mpm_database_exec(database_t *ptr, const char *query, - SQL_CALLBACK_PTR(cl), void *ct, char **err) { +u8_t mpm_database_exec(database_t *ptr, const char *query, SQL_CALLBACK_PTR(cl), + void *ct, char **err) { if (ptr == NULL || query == NULL) return 1; @@ -106,8 +106,7 @@ u8_t mpm_database_exec(database_t *ptr, const char *query, } -u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, - mlist_t **pkg) { +u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, mlist_t **pkg) { char *query; u8_t ret; @@ -121,8 +120,7 @@ u8_t mpm_get_package_by_id(database_t *ptr, u64_t id, return ret; } -u8_t mpm_get_package_by_name(database_t *ptr, const char *name, - mlist_t **pkg) { +u8_t mpm_get_package_by_name(database_t *ptr, const char *name, mlist_t **pkg) { char *query; u8_t ret; @@ -136,7 +134,7 @@ u8_t mpm_get_package_by_name(database_t *ptr, const char *name, return ret; } -package_t *sql_to_package(package_t *ptr, char *name, char *val) { +package_t *sql_to_package(package_t *ptr, char *name, char *val) { if (ptr == NULL) return ptr; @@ -161,8 +159,8 @@ package_t *sql_to_package(package_t *ptr, char *name, char *val) { } -u8_t mpm_database_init(database_t *ptr) { - static const char *query_table[] = {\ +u8_t mpm_database_init(database_t *ptr) { + static const char *query_table[] = {\ /* Package table */ SQL_CREATE_TABLE PKG_TABLE "(" \ PKG_COL_ID SQL_TYPE_INT SQL_TYPE_PRIMARY_KEY "," \ @@ -215,7 +213,7 @@ error: } -u8_t mpm_database_add_pkg(database_t *ptr, package_t *pkg) { +u8_t mpm_database_add_pkg(database_t *ptr, package_t *pkg) { char *query, *err; char *deps, *files, *binaries, *config, *docs; u8_t ret; @@ -244,8 +242,7 @@ u8_t mpm_database_add_pkg(database_t *ptr, package_t *pkg) { return ret; } -u8_t mpm_get_file_by_id(database_t *ptr, u64_t id, - mlist_t **files) { +u8_t mpm_get_file_by_id(database_t *ptr, u64_t id, mlist_t **files) { char *query; u8_t ret; @@ -259,10 +256,9 @@ u8_t mpm_get_file_by_id(database_t *ptr, u64_t id, return ret; } -u8_t mpm_get_file_by_path(database_t *ptr, const char *path, - mlist_t **files) { - char *query; - u8_t ret; +u8_t mpm_get_file_by_path(database_t *ptr, const char *path, mlist_t **files) { + char *query; + u8_t ret; if (ptr == NULL || path == NULL) return 1; @@ -274,10 +270,10 @@ u8_t mpm_get_file_by_path(database_t *ptr, const char *path, return ret; } -u8_t mpm_get_file_by_parent_id(database_t *ptr, u64_t id, +u8_t mpm_get_file_by_parent_id(database_t *ptr, u64_t id, mlist_t **files) { - char *query; - u8_t ret; + char *query; + u8_t ret; if (ptr == NULL) return 1; @@ -289,10 +285,9 @@ u8_t mpm_get_file_by_parent_id(database_t *ptr, u64_t id, return ret; } -u8_t mpm_get_file_by_parent_name(database_t *ptr, const char *name, - mlist_t **files) { - char *query; - u8_t ret; +u8_t mpm_get_file_by_parent_name(database_t *ptr, const char *name, mlist_t **files) { + char *query; + u8_t ret; if (ptr == NULL || name == NULL) return 1; @@ -342,9 +337,9 @@ file_t *sql_to_file(file_t *ptr, char *name, char *val) { return ptr; } -u8_t mpm_database_add_file(database_t *ptr, file_t *file) { - char *query, *err; - u8_t ret; +u8_t mpm_database_add_file(database_t *ptr, file_t *file) { + char *query, *err; + u8_t ret; if (ptr == NULL || file == NULL) return 1; @@ -363,9 +358,9 @@ u8_t mpm_database_add_file(database_t *ptr, file_t *file) { return ret; } -u8_t mpm_database_add_categ(database_t *ptr, category_t *cat) { - char *query, *err; - u8_t ret; +u8_t mpm_database_add_categ(database_t *ptr, category_t *cat) { + char *query, *err; + u8_t ret; if (ptr == NULL || cat == NULL) return 1; @@ -384,9 +379,9 @@ u8_t mpm_database_add_categ(database_t *ptr, category_t *cat) { } -u8_t mpm_get_categ_by_id(database_t *ptr, u64_t id, mlist_t **cat) { - char *query; - u8_t ret; +u8_t mpm_get_categ_by_id(database_t *ptr, u64_t id, mlist_t **cat) { + char *query; + u8_t ret; if (ptr == NULL) return 1; @@ -399,9 +394,9 @@ 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) { - char *query; - u8_t ret; +u8_t mpm_get_categ_by_name(database_t *ptr, const char *name, mlist_t **cat) { + char *query; + u8_t ret; if (ptr == NULL) return 1; @@ -413,7 +408,7 @@ u8_t mpm_get_categ_by_name(database_t *ptr, const char *name, mlist_t **cat) } -category_t *sql_to_category(category_t *ptr, char *name, char *val) { +category_t *sql_to_category(category_t *ptr, char *name, char *val) { if (ptr == NULL) return ptr; diff --git a/src/files.c b/src/files.c @@ -16,7 +16,7 @@ #include <files.h> -void mpm_file_init(file_t *ptr) { +void mpm_file_init(file_t *ptr) { if (ptr) { ptr->path = NULL; @@ -26,7 +26,7 @@ void mpm_file_init(file_t *ptr) { } } -int mpm_file_free(void *tmp) { +int mpm_file_free(void *tmp) { file_t *ptr = tmp; if (ptr) diff --git a/src/flags.c b/src/flags.c @@ -16,14 +16,14 @@ #include <flags.h> -static u8_t mpm_flags[MPM_LAST] = {0}; +static u8_t mpm_flags[MPM_LAST] = {0}; -void mpm_set_flag(flag_index_t flag, u8_t val) { +void mpm_set_flag(flag_index_t flag, u8_t val) { if (flag < MPM_LAST) mpm_flags[flag] = val; } -u8_t mpm_get_flag(flag_index_t flag) { +u8_t mpm_get_flag(flag_index_t flag) { assert(flag < MPM_LAST); return mpm_flags[flag]; } diff --git a/src/package.c b/src/package.c @@ -14,9 +14,9 @@ * limitations under the License. * \******************************************************************************/ -# include <package.h> +#include <package.h> -int mpm_package_free(void *tmp) { +int mpm_package_free(void *tmp) { package_t *ptr = tmp; if (ptr) @@ -36,7 +36,7 @@ int mpm_package_free(void *tmp) { return 1; } -void mpm_package_init(package_t *ptr) { +void mpm_package_init(package_t *ptr) { if (ptr) { ptr->id = 0;