From e9779bd065fc9fbbffcd98176e45711c508b525a Mon Sep 17 00:00:00 2001 From: Hannes Laimer Date: Fri, 3 Mar 2023 08:16:13 +0100 Subject: [PATCH] kdb-cli: rewrite find --- src/tools/kdb/command.h | 16 ++++-- src/tools/kdb/cp.c | 16 +++--- src/tools/kdb/cp.h | 38 +++++++------- src/tools/kdb/factory.hpp | 2 - src/tools/kdb/find.c | 101 ++++++++++++++++++++++++++++++++++++++ src/tools/kdb/find.cpp | 76 ---------------------------- src/tools/kdb/find.h | 36 ++++++++++++++ src/tools/kdb/find.hpp | 45 ----------------- src/tools/kdb/main.c | 2 + src/tools/kdb/meta-rm.c | 5 +- src/tools/kdb/meta-set.c | 10 ++-- src/tools/kdb/meta-show.c | 3 +- src/tools/kdb/meta.c | 10 ++-- src/tools/kdb/mv.c | 16 +++--- src/tools/kdb/mv.h | 38 +++++++------- src/tools/kdb/rm.c | 2 +- src/tools/kdb/rm.h | 32 ++++++------ src/tools/kdb/set.c | 7 +-- src/tools/kdb/set.h | 38 +++++++------- 19 files changed, 260 insertions(+), 233 deletions(-) create mode 100644 src/tools/kdb/find.c delete mode 100644 src/tools/kdb/find.cpp create mode 100644 src/tools/kdb/find.h delete mode 100644 src/tools/kdb/find.hpp diff --git a/src/tools/kdb/command.h b/src/tools/kdb/command.h index 47e6a69c42f..bd5783a9e1c 100644 --- a/src/tools/kdb/command.h +++ b/src/tools/kdb/command.h @@ -56,7 +56,9 @@ } \ /* debug -> verbose, so logLevel = debug+verbose */ \ bool verbose = debug; \ - if (verbose) {}; /* disable unused variable warning */ \ + if (verbose) \ + { \ + }; /* disable unused variable warning */ \ tmp = GET_OPTION_KEY (options, "verbose"); \ if (tmp != NULL) \ { \ @@ -69,7 +71,9 @@ elektraKeyToBoolean (GET_OPTION_KEY (options, "nonewline"), &noNewLine); \ } \ int colorMode = CLI_COLOR_AUTO; \ - if (colorMode) {}; /* disable unused variable warning */ \ + if (colorMode) \ + { \ + }; /* disable unused variable warning */ \ tmp = GET_OPTION_KEY (options, "color"); \ if (tmp != NULL) \ { \ @@ -83,14 +87,18 @@ } \ } \ char * fmtBuffer = NULL; \ - if (fmtBuffer) {}; /* disable unused variable warning */ \ + if (fmtBuffer) \ + { \ + }; /* disable unused variable warning */ \ if (!isatty (STDOUT_FILENO)) \ { \ colorMode = CLI_COLOR_NEVER; \ } \ \ int logLevel = verbose + debug; \ - if (logLevel) {}; /* disable unused variable warning */ \ + if (logLevel) \ + { \ + }; /* disable unused variable warning */ \ keyDel (tmp); #define EXEC_EXT(prog, argv, status) \ diff --git a/src/tools/kdb/cp.c b/src/tools/kdb/cp.c index 3138edd5e33..c670de29263 100644 --- a/src/tools/kdb/cp.c +++ b/src/tools/kdb/cp.c @@ -60,20 +60,22 @@ int execCp (KeySet * options, Key * errorKey) Key * sourceKey = keyNew (sourceName, KEY_END); Key * destKey = keyNew (destName, KEY_END); - if (keyGetNamespace (sourceKey) == KEY_NS_NONE || keyGetNamespace (sourceKey) == KEY_NS_CASCADING) { + if (keyGetNamespace (sourceKey) == KEY_NS_NONE || keyGetNamespace (sourceKey) == KEY_NS_CASCADING) + { ret = 1; ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "source key does not specify a namespace"); - elektraFree ((void*) sourceName); - elektraFree ((void*) destName); + elektraFree ((void *) sourceName); + elektraFree ((void *) destName); keyDel (sourceKey); keyDel (destKey); return ret; } - if (keyGetNamespace (destKey) == KEY_NS_NONE || keyGetNamespace (destKey) == KEY_NS_CASCADING) { + if (keyGetNamespace (destKey) == KEY_NS_NONE || keyGetNamespace (destKey) == KEY_NS_CASCADING) + { ret = 1; ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "destination key does not specify a namespace"); - elektraFree ((void*) sourceName); - elektraFree ((void*) destName); + elektraFree ((void *) sourceName); + elektraFree ((void *) destName); keyDel (sourceKey); keyDel (destKey); return ret; @@ -116,7 +118,7 @@ int execCp (KeySet * options, Key * errorKey) strcat (newName, "/"); strcat (newName, &keyName (cur)[sourceNameLen]); } - CLI_PRINT (CLI_LOG_VERBOSE, "-> moving '%s' to '%s'\n", BOLD(keyName (cur)), BOLD(newName)); + CLI_PRINT (CLI_LOG_VERBOSE, "-> moving '%s' to '%s'\n", BOLD (keyName (cur)), BOLD (newName)); Key * tmpKey = keyDup (cur, KEY_CP_ALL); keySetName (tmpKey, newName); ksAppendKey (newConf, tmpKey); diff --git a/src/tools/kdb/cp.h b/src/tools/kdb/cp.h index 90fb23bb943..2584b1cd3ed 100644 --- a/src/tools/kdb/cp.h +++ b/src/tools/kdb/cp.h @@ -1,10 +1,10 @@ /** -* @file -* -* @brief Header for cp command -* -* @copyright BSD License (see LICENSE.md or https://www.libelektra.org) -*/ + * @file + * + * @brief Header for cp command + * + * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) + */ #ifndef ELEKTRA_KDB_CP_H #define ELEKTRA_KDB_CP_H @@ -12,22 +12,22 @@ #include /** -* Adds options specification of cp command to @spec -* -* @param spec the base spec where the commands spec should be added -*/ + * Adds options specification of cp command to @spec + * + * @param spec the base spec where the commands spec should be added + */ void addCpSpec (KeySet * spec); /** -* Executes the cp command -* -* @param options cli options and arguments as specified in addCpSpec() -* @param errorKey key where errors and warnings should be saved -* -* @retval 0 cp command ran without errors -* @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info -* -*/ + * Executes the cp command + * + * @param options cli options and arguments as specified in addCpSpec() + * @param errorKey key where errors and warnings should be saved + * + * @retval 0 cp command ran without errors + * @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info + * + */ int execCp (KeySet * options, Key * errorKey); // helper functions diff --git a/src/tools/kdb/factory.hpp b/src/tools/kdb/factory.hpp index 8d899aeacf8..a8f4069e042 100644 --- a/src/tools/kdb/factory.hpp +++ b/src/tools/kdb/factory.hpp @@ -29,7 +29,6 @@ #include #include #include -#include #include #include #include @@ -80,7 +79,6 @@ class Factory m_factory.insert (std::make_pair ("mount", std::make_shared> ())); m_factory.insert (std::make_pair ("remount", std::make_shared> ())); m_factory.insert (std::make_pair ("shell", std::make_shared> ())); - m_factory.insert (std::make_pair ("find", std::make_shared> ())); m_factory.insert (std::make_pair ("plugin-info", std::make_shared> ())); m_factory.insert (std::make_pair ("test", std::make_shared> ())); m_factory.insert (std::make_pair ("plugin-check", std::make_shared> ())); diff --git a/src/tools/kdb/find.c b/src/tools/kdb/find.c new file mode 100644 index 00000000000..de5aeb89f58 --- /dev/null +++ b/src/tools/kdb/find.c @@ -0,0 +1,101 @@ +/** + * @file + * + * @brief Implementation of kdb find command + * + * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) + */ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define COMMAND_NAME "find" + +#define GET_OPTION_KEY(options, name) GET_OPT_KEY (options, COMMAND_BASE_KEY (COMMAND_NAME) "/" name) +#define GET_OPTION(options, name) GET_OPT (options, COMMAND_BASE_KEY (COMMAND_NAME) "/" name) + +void addFindSpec (KeySet * spec) +{ + ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME), KEY_META, "description", "Find keys that match a regex pattern.", + KEY_META, "command", COMMAND_NAME, KEY_END)); + ksAppendKey (spec, keyNew (COMMAND_SPEC_KEY (COMMAND_NAME) "/pattern", KEY_META, "description", "The patter that should be matched", + KEY_META, "args", "indexed", KEY_META, "args/index", "0", KEY_END)); + + ADD_BASIC_OPTIONS (spec, COMMAND_SPEC_KEY (COMMAND_NAME)) +} + +int execFind (KeySet * options, Key * errorKey) +{ + int ret = 0; + GET_BASIC_OPTIONS + + const char * patternString = GET_OPTION (options, "pattern"); + + regex_t regex; + if (regcomp (®ex, patternString, 0)) + { + ret = 1; + ELEKTRA_SET_VALIDATION_SYNTACTIC_ERRORF (errorKey, "could not compile regex pattern: '%s'", patternString); + return ret; + } + + Key * root = keyNew ("/", KEY_END); + + KeySet * conf = ksNew (0, KS_END); + KDB * handle = kdbOpen (NULL, errorKey); + CLI_PRINT (CLI_LOG_DEBUG, "loading %s\n", "/"); + + if (kdbGet (handle, conf, root) == -1) + { + ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "could not load key database", GET_ERR (root)); + ret = 1; + goto cleanup; + } + CLI_PRINT (CLI_LOG_DEBUG, "loaded %s\n", "/"); + + Key * cur = NULL; + + int regexResult; + int count = 0; + char errorMessageBuff[100]; + + for (elektraCursor it = 0; it < ksGetSize (conf); ++it) + { + cur = ksAtCursor (conf, it); + regexResult = regexec (®ex, keyName (cur), 0, NULL, 0); + CLI_PRINT (CLI_LOG_DEBUG, "matching '%s' -> %d\n", keyName (cur), regexResult); + + if (!regexResult) + { + CLI_PRINT (CLI_LOG_NONE, "%s\n", keyName (cur)); + count++; + } + else if (regexResult != REG_NOMATCH) + { + regerror (regexResult, ®ex, errorMessageBuff, sizeof (errorMessageBuff)); + CLI_PRINT (CLI_LOG_VERBOSE, "matching '%s' with '%s' failed: %s", keyName (cur), patternString, errorMessageBuff); + } + } + + CLI_PRINT (CLI_LOG_VERBOSE, "\nfound %ld keys", count); + +cleanup: + if (!noNewLine) + { + printf ("\n"); + } + keyDel (root); + elektraFree ((void *) fmtBuffer); + ksDel (conf); + regfree (®ex); + kdbClose (handle, errorKey); + return ret; +} diff --git a/src/tools/kdb/find.cpp b/src/tools/kdb/find.cpp deleted file mode 100644 index 10194d11711..00000000000 --- a/src/tools/kdb/find.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/** - * @file - * - * @brief - * - * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) - */ - -#include - -#include -#include - -#include -#include -#include - -using namespace kdb; -using namespace std; - -FindCommand::FindCommand () -{ -} - -int FindCommand::execute (Cmdline const & cl) -{ - if (cl.arguments.size () != 1) throw invalid_argument ("Need one argument"); - - Key root ("/", KEY_END); - KDB kdb (root); - KeySet ks; - - printWarnings (cerr, root, cl.verbose, cl.debug); - - kdb.get (ks, root); - - if (cl.verbose) cout << "size of all keys: " << ks.size () << endl; - - KeySet part; - std::smatch match; - - try - { - std::regex reg (cl.arguments[0]); - - for (const auto & it : ks) - { - std::string name = it.getName (); - if (std::regex_search (name, match, reg)) - { - part.append (it); - } - } - } - catch (const regex_error & error) - { - cerr << "Regex error in “" << cl.arguments[0] << "”: " << error.what () << endl; - } - - if (cl.verbose) cout << "size of found keys: " << part.size () << endl; - cout.setf (std::ios_base::unitbuf); - if (cl.null) - { - cout.unsetf (std::ios_base::skipws); - } - - std::cout << part; - - printWarnings (cerr, root, cl.verbose, cl.debug); - - return 0; -} - -FindCommand::~FindCommand () -{ -} diff --git a/src/tools/kdb/find.h b/src/tools/kdb/find.h new file mode 100644 index 00000000000..e7de3c7787a --- /dev/null +++ b/src/tools/kdb/find.h @@ -0,0 +1,36 @@ +/** + * @file + * + * @brief Header for find command + * + * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) + */ + +#ifndef ELEKTRA_KDB_FIND_H +#define ELEKTRA_KDB_FIND_H + +#include + +/** + * Adds options specification of find command to @spec + * + * @param spec the base spec where the commands spec should be added + */ +void addFindSpec (KeySet * spec); + +/** + * Executes the find command + * + * @param options cli options and arguments as specified in addFindSpec() + * @param errorKey key where errors and warnings should be saved + * + * @retval 0 find command ran without errors + * @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info + * + */ +int execFind (KeySet * options, Key * errorKey); + +// helper functions +int getKeyNameDepth (const char * name); + +#endif // ELEKTRA_KDB_FIND_H diff --git a/src/tools/kdb/find.hpp b/src/tools/kdb/find.hpp deleted file mode 100644 index 5250bcbfb00..00000000000 --- a/src/tools/kdb/find.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/** - * @file - * - * @brief - * - * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) - */ - -#ifndef KDB_FIND_H -#define KDB_FIND_H - -#include "coloredkdbio.hpp" -#include -#include - -class FindCommand : public Command -{ -public: - FindCommand (); - ~FindCommand (); - - virtual std::string getShortOptions () override - { - return "0"; - } - - virtual std::string getSynopsis () override - { - return ""; - } - - virtual std::string getShortHelpText () override - { - return "Find keys with a given regex."; - } - - virtual std::string getLongHelpText () override - { - return ""; - } - - virtual int execute (Cmdline const & cmdline) override; -}; - -#endif diff --git a/src/tools/kdb/main.c b/src/tools/kdb/main.c index 493fc30e589..13313575cb9 100644 --- a/src/tools/kdb/main.c +++ b/src/tools/kdb/main.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -36,6 +37,7 @@ command subcommands[] = { { "cmerge", addCmergeSpec, execCmerge }, { "cp", addCpSpec, execCp }, { "dirname", addDirnameSpec, execDirname }, + { "find", addFindSpec, execFind }, { "get", addGetSpec, execGet }, { "ls", addLsSpec, execLs }, { "meta", addMetaSpec, execMeta }, diff --git a/src/tools/kdb/meta-rm.c b/src/tools/kdb/meta-rm.c index 05dcdf154ca..58fb3ac023e 100644 --- a/src/tools/kdb/meta-rm.c +++ b/src/tools/kdb/meta-rm.c @@ -66,7 +66,8 @@ int execMetaRm (KeySet * options, Key * errorKey) if (keySetMeta (key, metaName, NULL) != 0 || kdbSet (handle, conf, parentKey) == -1) { ret = 1; - ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "could not remove meta-key '%s' for '%s': %s", metaName, keyName, GET_ERR (parentKey)); + ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "could not remove meta-key '%s' for '%s': %s", metaName, keyName, + GET_ERR (parentKey)); } keyDel (key); @@ -76,7 +77,7 @@ int execMetaRm (KeySet * options, Key * errorKey) { printf ("\n"); } - elektraFree ((void*) keyName); + elektraFree ((void *) keyName); keyDel (parentKey); ksDel (conf); kdbClose (handle, errorKey); diff --git a/src/tools/kdb/meta-set.c b/src/tools/kdb/meta-set.c index 99505f648f8..a35c7292411 100644 --- a/src/tools/kdb/meta-set.c +++ b/src/tools/kdb/meta-set.c @@ -56,10 +56,11 @@ int execMetaSet (KeySet * options, Key * errorKey) Key * parentKey = keyNew (keyName, KEY_END); - if (keyGetNamespace (parentKey) == KEY_NS_NONE || keyGetNamespace (parentKey) == KEY_NS_CASCADING) { + if (keyGetNamespace (parentKey) == KEY_NS_NONE || keyGetNamespace (parentKey) == KEY_NS_CASCADING) + { ret = 1; ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "key does not specify a namespace"); - elektraFree ((void*) keyName); + elektraFree ((void *) keyName); keyDel (parentKey); return ret; } @@ -87,7 +88,8 @@ int execMetaSet (KeySet * options, Key * errorKey) if (kdbSet (handle, conf, parentKey) == -1) { ret = 1; - ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "could not set meta-value '%s' for '%s': %s", metaName, keyName, GET_ERR (parentKey)); + ELEKTRA_SET_VALIDATION_SEMANTIC_ERRORF (errorKey, "could not set meta-value '%s' for '%s': %s", metaName, keyName, + GET_ERR (parentKey)); } keyDel (key); @@ -97,7 +99,7 @@ int execMetaSet (KeySet * options, Key * errorKey) { printf ("\n"); } - elektraFree ((void*) keyName); + elektraFree ((void *) keyName); keyDel (parentKey); ksDel (conf); kdbClose (handle, errorKey); diff --git a/src/tools/kdb/meta-show.c b/src/tools/kdb/meta-show.c index dceb056ef50..f4bbdaac5d4 100644 --- a/src/tools/kdb/meta-show.c +++ b/src/tools/kdb/meta-show.c @@ -61,8 +61,7 @@ int execMetaShow (KeySet * options, Key * errorKey) for (elektraCursor it = 0; it < ksGetSize (metaKeys); ++it) { cur = ksAtCursor (metaKeys, it); - CLI_PRINT (CLI_LOG_NONE, "%s -> %s%c", keyName (cur), BOLD(keyString (cur)), nullTerm ? '\0' : '\n'); - + CLI_PRINT (CLI_LOG_NONE, "%s -> %s%c", keyName (cur), BOLD (keyString (cur)), nullTerm ? '\0' : '\n'); } diff --git a/src/tools/kdb/meta.c b/src/tools/kdb/meta.c index f31c7691d02..480003908ef 100644 --- a/src/tools/kdb/meta.c +++ b/src/tools/kdb/meta.c @@ -6,12 +6,12 @@ * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) */ -#include #include #include #include #include #include +#include #include #include @@ -23,11 +23,8 @@ #define GET_OPTION(options, name) GET_OPT (options, COMMAND_BASE_KEY (COMMAND_NAME) "/" name) command metaSubcommands[] = { - { "get", addMetaGetSpec, execMetaGet }, - { "ls", addMetaLsSpec, execMetaLs }, - { "rm", addMetaRmSpec, execMetaRm }, - { "set", addMetaSetSpec, execMetaSet }, - { "show", addMetaShowSpec, execMetaShow }, + { "get", addMetaGetSpec, execMetaGet }, { "ls", addMetaLsSpec, execMetaLs }, { "rm", addMetaRmSpec, execMetaRm }, + { "set", addMetaSetSpec, execMetaSet }, { "show", addMetaShowSpec, execMetaShow }, }; void addMetaSpec (KeySet * spec) @@ -54,5 +51,4 @@ int execMeta (KeySet * options, Key * errorKey) } // this cannot happen, since not valid sub-commands are already detected when parsing return 1; - } diff --git a/src/tools/kdb/mv.c b/src/tools/kdb/mv.c index b3ae8448e70..cb68e2e39d4 100644 --- a/src/tools/kdb/mv.c +++ b/src/tools/kdb/mv.c @@ -62,20 +62,22 @@ int execMv (KeySet * options, Key * errorKey) Key * sourceKey = keyNew (sourceName, KEY_END); Key * destKey = keyNew (destName, KEY_END); - if (keyGetNamespace (sourceKey) == KEY_NS_NONE || keyGetNamespace (sourceKey) == KEY_NS_CASCADING) { + if (keyGetNamespace (sourceKey) == KEY_NS_NONE || keyGetNamespace (sourceKey) == KEY_NS_CASCADING) + { ret = 1; ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "source key does not specify a namespace"); - elektraFree ((void*) sourceName); - elektraFree ((void*) destName); + elektraFree ((void *) sourceName); + elektraFree ((void *) destName); keyDel (sourceKey); keyDel (destKey); return ret; } - if (keyGetNamespace (destKey) == KEY_NS_NONE || keyGetNamespace (destKey) == KEY_NS_CASCADING) { + if (keyGetNamespace (destKey) == KEY_NS_NONE || keyGetNamespace (destKey) == KEY_NS_CASCADING) + { ret = 1; ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "destination key does not specify a namespace"); - elektraFree ((void*) sourceName); - elektraFree ((void*) destName); + elektraFree ((void *) sourceName); + elektraFree ((void *) destName); keyDel (sourceKey); keyDel (destKey); return ret; @@ -127,7 +129,7 @@ int execMv (KeySet * options, Key * errorKey) strcat (newName, "/"); strcat (newName, &keyName (cur)[sourceNameLen]); } - CLI_PRINT (CLI_LOG_VERBOSE, "-> moving '%s' to '%s'\n", BOLD(keyName (cur)), BOLD(newName)); + CLI_PRINT (CLI_LOG_VERBOSE, "-> moving '%s' to '%s'\n", BOLD (keyName (cur)), BOLD (newName)); Key * tmpKey = keyDup (cur, KEY_CP_ALL); keySetName (tmpKey, newName); ksAppendKey (newConf, tmpKey); diff --git a/src/tools/kdb/mv.h b/src/tools/kdb/mv.h index 3941ce5050f..c15fe9f5b4c 100644 --- a/src/tools/kdb/mv.h +++ b/src/tools/kdb/mv.h @@ -1,10 +1,10 @@ /** -* @file -* -* @brief Header for mv command -* -* @copyright BSD License (see LICENSE.md or https://www.libelektra.org) -*/ + * @file + * + * @brief Header for mv command + * + * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) + */ #ifndef ELEKTRA_KDB_MV_H #define ELEKTRA_KDB_MV_H @@ -12,22 +12,22 @@ #include /** -* Adds options specification of mv command to @spec -* -* @param spec the base spec where the commands spec should be added -*/ + * Adds options specification of mv command to @spec + * + * @param spec the base spec where the commands spec should be added + */ void addMvSpec (KeySet * spec); /** -* Executes the mv command -* -* @param options cli options and arguments as specified in addMvSpec() -* @param errorKey key where errors and warnings should be saved -* -* @retval 0 mv command ran without errors -* @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info -* -*/ + * Executes the mv command + * + * @param options cli options and arguments as specified in addMvSpec() + * @param errorKey key where errors and warnings should be saved + * + * @retval 0 mv command ran without errors + * @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info + * + */ int execMv (KeySet * options, Key * errorKey); // helper functions diff --git a/src/tools/kdb/rm.c b/src/tools/kdb/rm.c index b59b7c86a20..7336ae64915 100644 --- a/src/tools/kdb/rm.c +++ b/src/tools/kdb/rm.c @@ -87,7 +87,7 @@ int execRm (KeySet * options, Key * errorKey) if ((recursive && startsWithSrc) || equalsSrc) { count++; - CLI_PRINT (CLI_LOG_VERBOSE, "removing '%s\n", BOLD(keyName (cur))); + CLI_PRINT (CLI_LOG_VERBOSE, "removing '%s\n", BOLD (keyName (cur))); continue; } ksAppendKey (newConf, cur); diff --git a/src/tools/kdb/rm.h b/src/tools/kdb/rm.h index a3bcb258a2b..5a2a53e22d3 100644 --- a/src/tools/kdb/rm.h +++ b/src/tools/kdb/rm.h @@ -1,9 +1,9 @@ /** -* @file -* -* @brief Header for rm command -* -* @copyright BSD License (see LICENSE.md or https://www.libelektra.org) + * @file + * + * @brief Header for rm command + * + * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) */ #ifndef ELEKTRA_KDB_RM_H @@ -12,21 +12,21 @@ #include /** -* Adds options specification of rm command to @spec -* -* @param spec the base spec where the commands spec should be added + * Adds options specification of rm command to @spec + * + * @param spec the base spec where the commands spec should be added */ void addRmSpec (KeySet * spec); /** -* Executes the rm command -* -* @param options cli options and arguments as specified in addRmSpec() -* @param errorKey key where errors and warnings should be saved -* -* @retval 0 rm command ran without errors -* @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info -* + * Executes the rm command + * + * @param options cli options and arguments as specified in addRmSpec() + * @param errorKey key where errors and warnings should be saved + * + * @retval 0 rm command ran without errors + * @retval 1 errors occurred, keyGetMeta (errorKey, "error/reason") for info + * */ int execRm (KeySet * options, Key * errorKey); diff --git a/src/tools/kdb/set.c b/src/tools/kdb/set.c index 9eceaa4230f..aeb870363c9 100644 --- a/src/tools/kdb/set.c +++ b/src/tools/kdb/set.c @@ -54,10 +54,11 @@ int execSet (KeySet * options, Key * errorKey) Key * parentKey = keyNew (name, KEY_END); - if (keyGetNamespace (parentKey) == KEY_NS_NONE || keyGetNamespace (parentKey) == KEY_NS_CASCADING) { + if (keyGetNamespace (parentKey) == KEY_NS_NONE || keyGetNamespace (parentKey) == KEY_NS_CASCADING) + { ret = 1; ELEKTRA_SET_VALIDATION_SYNTACTIC_ERROR (errorKey, "key does not specify a namespace"); - elektraFree ((void*) name); + elektraFree ((void *) name); keyDel (parentKey); return ret; } @@ -94,7 +95,7 @@ int execSet (KeySet * options, Key * errorKey) { printf ("\n"); } - elektraFree ((void*) name); + elektraFree ((void *) name); keyDel (parentKey); ksDel (conf); kdbClose (handle, errorKey); diff --git a/src/tools/kdb/set.h b/src/tools/kdb/set.h index 92912c2b238..3af921614ee 100644 --- a/src/tools/kdb/set.h +++ b/src/tools/kdb/set.h @@ -1,10 +1,10 @@ /** -* @file -* -* @brief KDB set subcommand header -* -* @copyright BSD License (see LICENSE.md or https://www.libelektra.org) -*/ + * @file + * + * @brief KDB set subcommand header + * + * @copyright BSD License (see LICENSE.md or https://www.libelektra.org) + */ #ifndef ELEKTRA_KDB_SET_H #define ELEKTRA_KDB_SET_H @@ -12,22 +12,22 @@ #include /** -* Adds options specification of set command to keySet -* -* @param spec the base spec where the commands spec should be added -*/ + * Adds options specification of set command to keySet + * + * @param spec the base spec where the commands spec should be added + */ void addSetSpec (KeySet * spec); /** -* Runs the set command -* -* @param options cli options and arguments as specified in addSetSpec() -* @param errorKey key where errors and warnings should be saved -* -* @retval 0 set command ran without errors -* @retval 1 errors occurred, keySetMeta (errorKey, "error/reason") for info -* -*/ + * Runs the set command + * + * @param options cli options and arguments as specified in addSetSpec() + * @param errorKey key where errors and warnings should be saved + * + * @retval 0 set command ran without errors + * @retval 1 errors occurred, keySetMeta (errorKey, "error/reason") for info + * + */ int execSet (KeySet * options, Key * errorKey); #endif // ELEKTRA_KDB_SET_H