TEXT file format: Keep backward-compatible non-top-level prefix with compile-time option TEXT_SYNTAX_NOPREFIX

See https://github.com/clicon/clixon/issues/345
This commit is contained in:
Olof hagsand 2022-07-26 18:10:27 +02:00
parent 57bc36d5ed
commit bed6d3c739
3 changed files with 16 additions and 5 deletions

View file

@ -79,6 +79,7 @@ Users may have to change how they access the system
* Leaf-list support: `a [ x y z ]`
* List key support: `a x y { ... }`
* See compile-time option `TEXT_LIST_KEYS`
* Keep backward-compatible non-top-level prefix with compile-time option `TEXT_SYNTAX_NOPREFIX`
### C/CLI-API changes on existing features

View file

@ -164,3 +164,8 @@
*/
#define PROTO_RESTART_RECONNECT
/*! Disable top-level prefix for text syntax printing and parsing introduced in 5.8
* Note this is for showing/saving/printing, it is NOT for parsing/loading.
* This means that text output can not be parsed and loaded.
*/
#undef TEXT_SYNTAX_NOPREFIX

View file

@ -123,15 +123,16 @@ xml2txt1(cxobj *xn,
int retval = -1;
int exist = 0;
yang_stmt *yn;
yang_stmt *yp = NULL;
yang_stmt *ymod;
yang_stmt *ypmod;
char *prefix = NULL;
char *value;
cg_var *cvi;
cvec *cvk = NULL; /* vector of index keys */
cbuf *cb = NULL;
#ifndef TEXT_SYNTAX_NOPREFIX
yang_stmt *yp = NULL;
yang_stmt *ymod;
yang_stmt *ypmod;
char *prefix = NULL;
#endif
if (xn == NULL || fn == NULL){
clicon_err(OE_XML, EINVAL, "xn or fn is NULL");
goto done;
@ -143,6 +144,7 @@ xml2txt1(cxobj *xn,
if (exist)
goto ok;
}
#ifndef TEXT_SYNTAX_NOPREFIX
/* Find out prefix if needed: topmost or new module a la API-PATH */
if (ys_real_module(yn, &ymod) < 0)
goto done;
@ -155,6 +157,7 @@ xml2txt1(cxobj *xn,
}
else
prefix = yang_argument_get(ymod);
#endif
if (yang_keyword_get(yn) == Y_LIST){
if ((cvk = yang_cvec_get(yn)) == NULL){
clicon_err(OE_YANG, 0, "No keys");
@ -209,8 +212,10 @@ xml2txt1(cxobj *xn,
}
if (*leafl == 0){
(*fn)(f, "%*s", 4*level, "");
#ifndef TEXT_SYNTAX_NOPREFIX
if (prefix)
(*fn)(f, "%s:", prefix);
#endif
(*fn)(f, "%s", xml_name(xn));
}
cvi = NULL; /* Lists only */