C-style update: Unified comment, retvals in order, remove trailing spaces

Changed function name for `clicon_debug` functions
This commit is contained in:
Olof hagsand 2023-10-22 18:04:47 +02:00
parent 6e314dd96f
commit 62348fc9c7
204 changed files with 6047 additions and 4904 deletions

View file

@ -32,7 +32,7 @@
***** END LICENSE BLOCK *****
* Clixon XML XPATH 1.0 according to https://www.w3.org/TR/xpath-10
* Clixon XML XPath 1.0 according to https://www.w3.org/TR/xpath-10
* and rfc 7950
*
*/
@ -74,12 +74,13 @@
#include "clixon_xpath_function.h"
/*! xpath function translation table
*
* @see enum clixon_xpath_function
*/
static const map_str2int xpath_fnname_map[] = { /* alphabetic order */
{"bit-is-set", XPATHFN_BIT_IS_SET},
{"boolean", XPATHFN_BOOLEAN},
{"eiling", XPATHFN_CEILING},
{"eiling", XPATHFN_CEILING},
{"comment", XPATHFN_COMMENT},
{"concat", XPATHFN_CONCAT},
{"contains", XPATHFN_CONTAINS},
@ -144,7 +145,7 @@ xp_function_current(xp_ctx *xc0,
cxobj **vec = NULL;
int veclen = 0;
xp_ctx *xc = NULL;
if ((xc = ctx_dup(xc0)) == NULL)
goto done;
if (cxvec_append(xc->xc_initial, &vec, &veclen) < 0)
@ -177,7 +178,7 @@ xp_function_deref(xp_ctx *xc0,
yang_stmt *yt;
yang_stmt *ypath;
char *path;
/* Create new xc */
if ((xc = ctx_dup(xc0)) == NULL)
goto done;
@ -210,6 +211,7 @@ xp_function_deref(xp_ctx *xc0,
}
/*! Helper function for derived-from(-and-self) - eval one node
*
* @param[in] nsc XML Namespace context
* @param[in] self If set, implements derived_from_or_self
* @retval 1 OK and match
@ -279,7 +281,7 @@ derived_from_one(char *baseidentity,
else {
/* Allocate cbuf */
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
cprintf(cb, "%s:%s", yang_argument_get(ymod), id);
@ -303,8 +305,9 @@ derived_from_one(char *baseidentity,
}
/*! Eval xpath function derived-from(-and-self)
*
* @param[in] xc Incoming context
* @param[in] xs XPATH node tree
* @param[in] xs XPath node tree
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[in] self If set, implements derived_from_or_self
@ -332,19 +335,19 @@ xp_function_derived_from(xp_ctx *xc,
char *identity = NULL;
int i;
int ret = 0;
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
clicon_err(OE_XML, EINVAL, "derived-from expects but did not get two arguments");
goto done;
}
/* contains two arguments in xs: boolean derived-from(node-set, string) */
/* This evolves to a set of (identityref) nodes */
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
if (xr0->xc_type != XT_NODESET)
goto done;
/* This evolves to a string identity */
if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
goto done;
if (ctx2string(xr1, &identity) < 0)
goto done;
@ -385,7 +388,7 @@ xp_function_derived_from(xp_ctx *xc,
* Signature: boolean bit-is-set(node-set nodes, string bit-name)
* @param[in] xc Incoming context
* @param[in] xs XPATH node tree
* @param[in] xs XPath node tree
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[out] xrp Resulting context
@ -410,16 +413,16 @@ xp_function_bit_is_set(xp_ctx *xc,
char *s1 = NULL;
cxobj *x;
char *body;
if (xs == NULL || xs->xs_c0 == NULL || xs->xs_c1 == NULL){
clicon_err(OE_XML, EINVAL, "contains expects but did not get two arguments");
goto done;
}
/* First node-set argument */
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
/* Second string argument */
if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
goto done;
if (ctx2string(xr1, &s1) < 0)
goto done;
@ -454,7 +457,7 @@ xp_function_bit_is_set(xp_ctx *xc,
*
* Signature: number position(node-set)
* @param[in] xc Incoming context
* @param[in] xs XPATH node tree
* @param[in] xs XPath node tree
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[out] xrp Resulting context
@ -470,7 +473,7 @@ xp_function_position(xp_ctx *xc,
{
int retval = -1;
xp_ctx *xr = NULL;
if ((xr = malloc(sizeof(*xr))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
@ -499,12 +502,12 @@ xp_function_count(xp_ctx *xc,
int retval = -1;
xp_ctx *xr = NULL;
xp_ctx *xr0 = NULL;
if (xs == NULL || xs->xs_c0 == NULL){
clicon_err(OE_XML, EINVAL, "count expects but did not get one argument");
goto done;
}
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
if ((xr = malloc(sizeof(*xr))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
@ -541,12 +544,12 @@ xp_function_name(xp_ctx *xc,
char *s0 = NULL;
int i;
cxobj *x;
if (xs == NULL || xs->xs_c0 == NULL){
clicon_err(OE_XML, EINVAL, "not expects but did not get one argument");
goto done;
}
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
if ((xr = malloc(sizeof(*xr))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
@ -574,8 +577,9 @@ xp_function_name(xp_ctx *xc,
}
/*! Eval xpath function contains
*
* @param[in] xc Incoming context
* @param[in] xs XPATH node tree
* @param[in] xs XPath node tree
* @param[in] nsc XML Namespace context
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[out] xrp Resulting context
@ -602,11 +606,11 @@ xp_function_contains(xp_ctx *xc,
goto done;
}
/* contains two arguments in xs: boolean contains(string, string) */
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
if (ctx2string(xr0, &s0) < 0)
goto done;
if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
if (xp_eval(xc, xs->xs_c1, nsc, localonly, &xr1) < 0)
goto done;
if (ctx2string(xr1, &s1) < 0)
goto done;
@ -653,12 +657,12 @@ xp_function_boolean(xp_ctx *xc,
xp_ctx *xr = NULL;
xp_ctx *xr0 = NULL;
int bool;
if (xs == NULL || xs->xs_c0 == NULL){
clicon_err(OE_XML, EINVAL, "not expects but did not get one argument");
goto done;
}
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
if (xp_eval(xc, xs->xs_c0, nsc, localonly, &xr0) < 0)
goto done;
bool = ctx2boolean(xr0);
if ((xr = malloc(sizeof(*xr))) == NULL){
@ -706,7 +710,7 @@ xp_function_true(xp_ctx *xc,
{
int retval = -1;
xp_ctx *xr = NULL;
if ((xr = malloc(sizeof(*xr))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;
@ -733,7 +737,7 @@ xp_function_false(xp_ctx *xc,
{
int retval = -1;
xp_ctx *xr = NULL;
if ((xr = malloc(sizeof(*xr))) == NULL){
clicon_err(OE_UNIX, errno, "malloc");
goto done;