Cleaned up prettyprint->pretty, use yang_cvec_set access function

This commit is contained in:
Olof hagsand 2022-06-02 19:56:49 +02:00
parent b6bfcb69f7
commit 625a0ed19a
3 changed files with 43 additions and 41 deletions

View file

@ -805,6 +805,7 @@ cli_show_auto1(clicon_handle h,
* @see cli_show_auto_state For config and state * @see cli_show_auto_state For config and state
* @note SHOULD be used: ... @datamodel, cli_show_auto(<dbname>,...) to get correct #args * @note SHOULD be used: ... @datamodel, cli_show_auto(<dbname>,...) to get correct #args
* @see cli_auto_show * @see cli_auto_show
* @see cli_show_config
*/ */
int int
cli_show_auto(clicon_handle h, cli_show_auto(clicon_handle h,

View file

@ -90,9 +90,9 @@
/*! Print an XML tree structure to an output stream and encode chars "<>&" /*! Print an XML tree structure to an output stream and encode chars "<>&"
* *
* @param[in] f UNIX output stream * @param[in] f UNIX output stream
* @param[in] xn clicon xml tree * @param[in] xn Clicon xml tree
* @param[in] level how many spaces to insert before each line * @param[in] level How many spaces to insert before each line
* @param[in] prettyprint insert \n and spaces tomake the xml more readable. * @param[in] pretty Insert \n and spaces to make the xml more readable.
* @param[in] fn Callback to make print function * @param[in] fn Callback to make print function
* @see clixon_xml2cbuf * @see clixon_xml2cbuf
* One can use clixon_xml2cbuf to get common code, but using fprintf is * One can use clixon_xml2cbuf to get common code, but using fprintf is
@ -102,7 +102,7 @@ int
xml2file_recurse(FILE *f, xml2file_recurse(FILE *f,
cxobj *x, cxobj *x,
int level, int level,
int prettyprint, int pretty,
clicon_output_cb *fn) clicon_output_cb *fn)
{ {
int retval = -1; int retval = -1;
@ -138,7 +138,7 @@ xml2file_recurse(FILE *f,
(*fn)(f, "%s=\"%s\"", name, xml_value(x)); (*fn)(f, "%s=\"%s\"", name, xml_value(x));
break; break;
case CX_ELMNT: case CX_ELMNT:
(*fn)(f, "%*s<", prettyprint?(level*XML_INDENT):0, ""); (*fn)(f, "%*s<", pretty?(level*XML_INDENT):0, "");
if (namespace) if (namespace)
(*fn)(f, "%s:", namespace); (*fn)(f, "%s:", namespace);
(*fn)(f, "%s", name); (*fn)(f, "%s", name);
@ -149,7 +149,7 @@ xml2file_recurse(FILE *f,
while ((xc = xml_child_each(x, xc, -1)) != NULL) { while ((xc = xml_child_each(x, xc, -1)) != NULL) {
switch (xml_type(xc)){ switch (xml_type(xc)){
case CX_ATTR: case CX_ATTR:
if (xml2file_recurse(f, xc, level+1, prettyprint, fn) <0) if (xml2file_recurse(f, xc, level+1, pretty, fn) <0)
goto done; goto done;
break; break;
case CX_BODY: case CX_BODY:
@ -169,22 +169,22 @@ xml2file_recurse(FILE *f,
(*fn)(f, "/>"); (*fn)(f, "/>");
else{ else{
(*fn)(f, ">"); (*fn)(f, ">");
if (prettyprint && hasbody == 0) if (pretty && hasbody == 0)
(*fn)(f, "\n"); (*fn)(f, "\n");
xc = NULL; xc = NULL;
while ((xc = xml_child_each(x, xc, -1)) != NULL) { while ((xc = xml_child_each(x, xc, -1)) != NULL) {
if (xml_type(xc) != CX_ATTR) if (xml_type(xc) != CX_ATTR)
if (xml2file_recurse(f, xc, level+1, prettyprint, fn) <0) if (xml2file_recurse(f, xc, level+1, pretty, fn) <0)
goto done; goto done;
} }
if (prettyprint && hasbody==0) if (pretty && hasbody==0)
(*fn)(f, "%*s", level*XML_INDENT, ""); (*fn)(f, "%*s", level*XML_INDENT, "");
(*fn)(f, "</"); (*fn)(f, "</");
if (namespace) if (namespace)
(*fn)(f, "%s:", namespace); (*fn)(f, "%s:", namespace);
(*fn)(f, "%s>", name); (*fn)(f, "%s>", name);
} }
if (prettyprint) if (pretty)
(*fn)(f, "\n"); (*fn)(f, "\n");
break; break;
default: default:
@ -203,7 +203,7 @@ xml2file_recurse(FILE *f,
* @param[in] f Output file * @param[in] f Output file
* @param[in] xn XML tree * @param[in] xn XML tree
* @param[in] level How many spaces to insert before each line * @param[in] level How many spaces to insert before each line
* @param[in] pretty Insert \n and spaces tomake the xml more readable. * @param[in] pretty Insert \n and spaces to make the xml more readable.
* @param[in] fn File print function (if NULL, use fprintf) * @param[in] fn File print function (if NULL, use fprintf)
* @param[in] skiptop 0: Include top object 1: Skip top-object, only children, * @param[in] skiptop 0: Include top object 1: Skip top-object, only children,
* @retval 0 OK * @retval 0 OK
@ -303,16 +303,16 @@ xml_dump(FILE *f,
/*! Internal: print XML tree structure to a cligen buffer and encode chars "<>&" /*! Internal: print XML tree structure to a cligen buffer and encode chars "<>&"
* *
* @param[in,out] cb Cligen buffer to write to * @param[in,out] cb Cligen buffer to write to
* @param[in] xn Clicon xml tree * @param[in] xn Clixon xml tree
* @param[in] level Indentation level for prettyprint * @param[in] level Indentation level for prettyprint
* @param[in] prettyprint insert \n and spaces tomake the xml more readable. * @param[in] pretty Insert \n and spaces to make the xml more readable.
* @param[in] depth Limit levels of child resources: -1 is all, 0 is none, 1 is node itself * @param[in] depth Limit levels of child resources: -1 is all, 0 is none, 1 is node itself
*/ */
static int static int
clixon_xml2cbuf1(cbuf *cb, clixon_xml2cbuf1(cbuf *cb,
cxobj *x, cxobj *x,
int level, int level,
int prettyprint, int pretty,
int32_t depth) int32_t depth)
{ {
int retval = -1; int retval = -1;
@ -343,7 +343,7 @@ clixon_xml2cbuf1(cbuf *cb,
cprintf(cb, "%s=\"%s\"", name, xml_value(x)); cprintf(cb, "%s=\"%s\"", name, xml_value(x));
break; break;
case CX_ELMNT: case CX_ELMNT:
if (prettyprint) if (pretty)
cprintf(cb, "%*s<", level*XML_INDENT, ""); cprintf(cb, "%*s<", level*XML_INDENT, "");
else else
cbuf_append_str(cb, "<"); cbuf_append_str(cb, "<");
@ -359,7 +359,7 @@ clixon_xml2cbuf1(cbuf *cb,
while ((xc = xml_child_each(x, xc, -1)) != NULL) while ((xc = xml_child_each(x, xc, -1)) != NULL)
switch (xml_type(xc)){ switch (xml_type(xc)){
case CX_ATTR: case CX_ATTR:
if (clixon_xml2cbuf1(cb, xc, level+1, prettyprint, -1) < 0) if (clixon_xml2cbuf1(cb, xc, level+1, pretty, -1) < 0)
goto done; goto done;
break; break;
case CX_BODY: case CX_BODY:
@ -376,14 +376,14 @@ clixon_xml2cbuf1(cbuf *cb,
cbuf_append_str(cb, "/>"); cbuf_append_str(cb, "/>");
else{ else{
cbuf_append_str(cb, ">"); cbuf_append_str(cb, ">");
if (prettyprint && hasbody == 0) if (pretty && hasbody == 0)
cbuf_append_str(cb, "\n"); cbuf_append_str(cb, "\n");
xc = NULL; xc = NULL;
while ((xc = xml_child_each(x, xc, -1)) != NULL) while ((xc = xml_child_each(x, xc, -1)) != NULL)
if (xml_type(xc) != CX_ATTR) if (xml_type(xc) != CX_ATTR)
if (clixon_xml2cbuf1(cb, xc, level+1, prettyprint, depth-1) < 0) if (clixon_xml2cbuf1(cb, xc, level+1, pretty, depth-1) < 0)
goto done; goto done;
if (prettyprint && hasbody == 0) if (pretty && hasbody == 0)
cprintf(cb, "%*s", level*XML_INDENT, ""); cprintf(cb, "%*s", level*XML_INDENT, "");
cbuf_append_str(cb, "</"); cbuf_append_str(cb, "</");
if (namespace){ if (namespace){
@ -393,7 +393,7 @@ clixon_xml2cbuf1(cbuf *cb,
cbuf_append_str(cb, name); cbuf_append_str(cb, name);
cbuf_append_str(cb, ">"); cbuf_append_str(cb, ">");
} }
if (prettyprint) if (pretty)
cbuf_append_str(cb, "\n"); cbuf_append_str(cb, "\n");
break; break;
default: default:
@ -409,8 +409,8 @@ clixon_xml2cbuf1(cbuf *cb,
* *
* @param[in,out] cb Cligen buffer to write to * @param[in,out] cb Cligen buffer to write to
* @param[in] xn Top-level xml object * @param[in] xn Top-level xml object
* @param[in] level Indentation level for prettyprint * @param[in] level Indentation level for pretty
* @param[in] prettyprint insert \n and spaces tomake the xml more readable. * @param[in] pretty Insert \n and spaces to make the xml more readable.
* @param[in] depth Limit levels of child resources: -1: all, 0: none, 1: node itself * @param[in] depth Limit levels of child resources: -1: all, 0: none, 1: node itself
* @param[in] skiptop 0: Include top object 1: Skip top-object, only children, * @param[in] skiptop 0: Include top object 1: Skip top-object, only children,
* @retval 0 OK * @retval 0 OK

View file

@ -2131,13 +2131,14 @@ ys_populate_list(clicon_handle h,
yang_stmt *ys) yang_stmt *ys)
{ {
yang_stmt *ykey; yang_stmt *ykey;
cvec *cvv;
if ((ykey = yang_find(ys, Y_KEY, NULL)) == NULL) if ((ykey = yang_find(ys, Y_KEY, NULL)) == NULL)
return 0; return 0;
if (ys->ys_cvec)
cvec_free(ys->ys_cvec); if ((cvv = yang_arg2cvec(ykey, " ")) == NULL)
if ((ys->ys_cvec = yang_arg2cvec(ykey, " ")) == NULL)
return -1; return -1;
yang_cvec_set(ys, cvv);
return 0; return 0;
} }
@ -2544,10 +2545,11 @@ static int
ys_populate_unique(clicon_handle h, ys_populate_unique(clicon_handle h,
yang_stmt *ys) yang_stmt *ys)
{ {
if (ys->ys_cvec) cvec *cvv;
cvec_free(ys->ys_cvec);
if ((ys->ys_cvec = yang_arg2cvec(ys, " ")) == NULL) if ((cvv = yang_arg2cvec(ys, " ")) == NULL)
return -1; return -1;
yang_cvec_set(ys, cvv);
return 0; return 0;
} }
@ -3516,7 +3518,6 @@ yang_key_match(yang_stmt *yn,
retval = 1; /* match */ retval = 1; /* match */
goto done; goto done;
} }
} }
cvec_free(cvv); cvec_free(cvv);
cvv = NULL; cvv = NULL;