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
*
* Note on xcur parameter to most xpath functions:
* The W3 standard defines the document root / element as the top-level.
@ -158,7 +158,7 @@ static const map_str2int axis_type_map[] = {
/*
* XPATH parse tree type
* XPath parse tree type
*/
/*! Map from axis-type int to string
@ -183,7 +183,7 @@ xpath_tree_int2str(int nodetype)
return (char*)clicon_int2str(xpath_tree_map, nodetype);
}
/*! Print XPATH parse tree
/*! Print XPath parse tree
*
* @note uses "" instead of '' in printing literals, rule [29] in https://www.w3.org/TR/xpath-10
*/
@ -217,8 +217,9 @@ xpath_tree_print0(cbuf *cb,
}
/*! Print a xpath_tree to CLIgen buf
*
* @param[out] cb CLIgen buffer
* @param[in] xs XPATH tree
* @param[in] xs XPath tree
*/
int
xpath_tree_print_cb(cbuf *cb,
@ -229,8 +230,11 @@ xpath_tree_print_cb(cbuf *cb,
}
/*! Print a xpath_tree
*
* @param[in] f UNIX output stream
* @param[in] xs XPATH tree
* @param[in] xs XPath tree
* @retval 0 OK
* @retval -1 Error
* @see xpath_tree2str
*/
int
@ -253,7 +257,8 @@ xpath_tree_print(FILE *f,
}
/*! Create an xpath string from an xpath tree, ie "unparsing"
* @param[in] xs XPATH tree
*
* @param[in] xs XPath tree
* @param[out] xpath XPath string as CLIgen buf
* @retval 0 OK
* @retval -1 Error
@ -389,9 +394,9 @@ xpath_tree_append(xpath_tree *xt,
* @param[in] xt2 XPath parse 2
* @param[in,out] vec XPath tree vector
* @param[in,out] len Length of XML XPath vector
* @retval -1 Error
* @retval 0 Not equal
* @retval 1 Equal
* @retval 0 Not equal
* @retval -1 Error
*/
int
xpath_tree_eq(xpath_tree *xt1, /* pattern */
@ -411,7 +416,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */
(xt2->xs_type == XP_PRIME_NR || xt2->xs_type == XP_PRIME_STR))
#endif
){
clicon_debug(CLIXON_DBG_DETAIL, "%s type %s vs %s\n", __FUNCTION__,
clixon_debug(CLIXON_DBG_DETAIL, "%s type %s vs %s\n", __FUNCTION__,
xpath_tree_int2str(xt1->xs_type),
xpath_tree_int2str(xt2->xs_type));
goto neq;
@ -423,19 +428,19 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */
goto eq;
}
if (xt1->xs_int != xt2->xs_int){
clicon_debug(CLIXON_DBG_DETAIL, "%s int\n", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s int\n", __FUNCTION__);
goto neq;
}
if (xt1->xs_double != xt2->xs_double){
clicon_debug(CLIXON_DBG_DETAIL, "%s double\n", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s double\n", __FUNCTION__);
goto neq;
}
if (clicon_strcmp(xt1->xs_s0, xt2->xs_s0)){
clicon_debug(CLIXON_DBG_DETAIL, "%s s0\n", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s s0\n", __FUNCTION__);
goto neq;
}
if (clicon_strcmp(xt1->xs_s1, xt2->xs_s1)){
clicon_debug(CLIXON_DBG_DETAIL, "%s s1\n", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s s1\n", __FUNCTION__);
goto neq;
}
xc1 = xt1->xs_c0;
@ -444,7 +449,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */
;
else{
if (xc1 == NULL || xc2 == NULL){
clicon_debug(CLIXON_DBG_DETAIL, "%s NULL\n", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s NULL\n", __FUNCTION__);
goto neq;
}
if ((ret = xpath_tree_eq(xc1, xc2, vec, len)) < 0)
@ -458,7 +463,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */
;
else{
if (xc1 == NULL || xc2 == NULL){
clicon_debug(CLIXON_DBG_DETAIL, "%s NULL\n", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s NULL\n", __FUNCTION__);
goto neq;
}
if ((ret = xpath_tree_eq(xc1, xc2, vec, len)) < 0)
@ -476,6 +481,7 @@ xpath_tree_eq(xpath_tree *xt1, /* pattern */
}
/*! Traverse through an xpath-tree using indexes
*
* @param[in] xt Start-tree
* @param[in] i List of indexes terminated by -1: 0 means c0, 1 means c1
* @retval xc End-tree
@ -506,7 +512,8 @@ xpath_tree_traverse(xpath_tree *xt,
}
/*! Free a xpath_tree
* @param[in] xs XPATH tree
*
* @param[in] xs XPath tree
* @see xpath_parse creates a xpath_tree
*/
int
@ -527,8 +534,9 @@ xpath_tree_free(xpath_tree *xs)
}
/*! Given xpath, parse it, and return structured xpath tree
* @param[in] xpath String with XPATH 1.0 syntax
* @param[out] xptree XPath-tree, parsed, structured XPATH, free:xpath_tree_free
*
* @param[in] xpath String with XPath 1.0 syntax
* @param[out] xptree XPath-tree, parsed, structured XPath, free:xpath_tree_free
* @retval 0 OK
* @retval -1 Error
* @code
@ -549,7 +557,7 @@ xpath_parse(const char *xpath,
clixon_xpath_yacc xpy = {0,};
cbuf *cb = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (xpath == NULL){
clicon_err(OE_XML, EINVAL, "XPath is NULL");
goto done;
@ -562,19 +570,19 @@ xpath_parse(const char *xpath,
if (xpath_parse_init(&xpy) < 0)
goto done;
if (clixon_xpath_parseparse(&xpy) != 0) { /* yacc returns 1 on error */
clicon_log(LOG_NOTICE, "XPATH error: on line %d", xpy.xpy_linenum);
clicon_log(LOG_NOTICE, "XPath error: on line %d", xpy.xpy_linenum);
if (clicon_errno == 0)
clicon_err(OE_XML, 0, "XPATH parser error with no error code (should not happen)");
clicon_err(OE_XML, 0, "XPath parser error with no error code (should not happen)");
xpath_scan_exit(&xpy);
goto done;
}
if (clicon_debug_get() > 2){
if (clixon_debug_get() > 2){
if ((cb = cbuf_new()) == NULL){
clicon_err(OE_XML, errno, "cbuf_new");
goto done;
}
xpath_tree_print_cb(cb, xpy.xpy_top);
clicon_debug(CLIXON_DBG_DETAIL, "xpath parse tree:\n%s", cbuf_get(cb));
clixon_debug(CLIXON_DBG_DETAIL, "xpath parse tree:\n%s", cbuf_get(cb));
}
xpath_parse_exit(&xpy);
xpath_scan_exit(&xpy);
@ -592,13 +600,14 @@ xpath_parse(const char *xpath,
}
/*! Given XML tree and xpath, parse xpath, eval it and return xpath context,
*
* This is a raw form of xpath where you can do type conversion of the return
* value, etc, not just a nodeset.
* @param[in] xcur XML-tree where to search
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath String with XPATH 1.0 syntax
* @param[in] xpath String with XPath 1.0 syntax
* @param[in] localonly Skip prefix and namespace tests (non-standard)
* @param[out] xrp Return XPATH context
* @param[out] xrp Return XPath context
* @retval 0 OK
* @retval -1 Error
* @code
@ -620,7 +629,7 @@ xpath_vec_ctx(cxobj *xcur,
xpath_tree *xptree = NULL;
xp_ctx xc = {0,};
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
if (xpath_parse(xpath, &xptree) < 0)
goto done;
xc.xc_type = XT_NODESET;
@ -645,7 +654,7 @@ xpath_vec_ctx(cxobj *xcur,
*
* @param[in] xcur XML tree where to search
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpformat Format string for XPATH syntax
* @param[in] xpformat Format string for XPath syntax
* @retval xml-tree XML tree of first match
* @retval NULL Error or not found
*
@ -706,7 +715,7 @@ xpath_first(cxobj *xcur,
*
* Reason for skipping prefix/namespace check may be with incomplete tree, for example.
* @param[in] xcur XML tree where to search
* @param[in] xpformat Format string for XPATH syntax
* @param[in] xpformat Format string for XPath syntax
* @retval xml-tree XML tree of first match
* @retval NULL Error or not found
*
@ -765,7 +774,7 @@ xpath_first_localonly(cxobj *xcur,
* If result is not nodeset, return empty nodeset
* @param[in] xcur xml-tree where to search
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpformat Format string for XPATH syntax
* @param[in] xpformat Format string for XPath syntax
* @param[out] vec vector of xml-trees. Vector must be free():d after use
* @param[out] veclen returns length of vector in return value
* @retval 0 OK
@ -832,8 +841,9 @@ xpath_vec(cxobj *xcur,
}
/* XPath that returns a vector of matches (only nodes marked with flags)
*
* @param[in] xcur xml-tree where to search
* @param[in] xpformat Format string for XPATH syntax
* @param[in] xpformat Format string for XPath syntax
* @param[in] nsc External XML namespace context, or NULL
* @param[in] flags Set of flags that return nodes must match (0 if all)
* @param[out] vec vector of xml-trees. Vector must be free():d after use
@ -911,10 +921,11 @@ xpath_vec_flag(cxobj *xcur,
}
/*! Given XML tree and xpath, returns boolean
*
* Returns true if the nodeset is non-empty
* @param[in] xcur xml-tree where to search
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpformat Format string for XPATH syntax
* @param[in] xpformat Format string for XPath syntax
* @retval 1 True
* @retval 0 False
* @retval -1 Error
@ -1111,7 +1122,7 @@ xpath2canonical(const char *xpath0,
cbuf *xcb = NULL;
int ret;
clicon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
clixon_debug(CLIXON_DBG_DETAIL, "%s", __FUNCTION__);
/* Parse input xpath into an xpath-tree */
if (xpath_parse(xpath0, &xpt) < 0)
goto done;
@ -1160,8 +1171,10 @@ xpath2canonical(const char *xpath0,
*
* @param[in] xcur xml-tree where to search
* @param[in] nsc External XML namespace context, or NULL
* @param[in] xpath XPATH syntax
* @param[in] xpath XPath syntax
* @param[oit] count Nr of elements of xpath
* @retval 0 OK
* @retval -1 Error
* @note This function is made for making optimizations in certain circumstances, such as a list
*/
int
@ -1465,7 +1478,7 @@ xpath2xml_traverse(xpath_tree *xs,
}
retval = 1;
done:
clicon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
clixon_debug(CLIXON_DBG_DETAIL, "%s retval:%d", __FUNCTION__, retval);
return retval;
fail:
retval = 0;
@ -1502,7 +1515,7 @@ xpath2xml(char *xpath,
cbuf *cberr = NULL;
xpath_tree *xpt = NULL;
clicon_debug(CLIXON_DBG_DETAIL, "%s xpath:%s", __FUNCTION__, xpath);
clixon_debug(CLIXON_DBG_DETAIL, "%s xpath:%s", __FUNCTION__, xpath);
if ((cberr = cbuf_new()) == NULL){
clicon_err(OE_UNIX, errno, "cbuf_new");
goto done;