xml sort adjust to different yang models
global yang ordering for top-level xml symbols
This commit is contained in:
parent
606245ef02
commit
789732c613
3 changed files with 30 additions and 17 deletions
|
|
@ -221,9 +221,8 @@ xml_cmp(const void* arg1,
|
||||||
cxobj *x1b;
|
cxobj *x1b;
|
||||||
cxobj *x2b;
|
cxobj *x2b;
|
||||||
|
|
||||||
if (x1==NULL || x2==NULL){
|
if (x1==NULL || x2==NULL)
|
||||||
goto done; /* shouldnt happen */
|
goto done; /* shouldnt happen */
|
||||||
}
|
|
||||||
y1 = xml_spec(x1);
|
y1 = xml_spec(x1);
|
||||||
y2 = xml_spec(x2);
|
y2 = xml_spec(x2);
|
||||||
nr1 = xml_enumerate_get(x1);
|
nr1 = xml_enumerate_get(x1);
|
||||||
|
|
@ -289,6 +288,7 @@ xml_cmp(const void* arg1,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
done:
|
done:
|
||||||
|
clicon_debug(2, "%s %s %s %d", __FUNCTION__, xml_name(x1), xml_name(x2), equal);
|
||||||
return equal;
|
return equal;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -663,8 +663,11 @@ yang_choice(yang_stmt *y)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Find matching y in yp:s children, return 0 and index or -1 if not found.
|
/*! Find matching y in yp:s children, return 0 and index or -1 if not found.
|
||||||
* @retval 0 not found
|
* @param[in] yp Parent
|
||||||
* @retval 1 found
|
* @param[in] y Yang datanode to find
|
||||||
|
* @param[out] index Index of y in yp:s list of children
|
||||||
|
* @retval 0 not found (must be datanode)
|
||||||
|
* @retval 1 found
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
order1(yang_node *yp,
|
order1(yang_node *yp,
|
||||||
|
|
@ -686,29 +689,41 @@ order1(yang_node *yp,
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Return order of yang statement y in parents child vector
|
/*! Return order of yang statement y in parents child vector
|
||||||
* @retval i Order of child with specified argument
|
* @param[in] y Find position of this data-node
|
||||||
* @retval -1 Not found
|
* @param[out] index Index of y in yp:s list of children
|
||||||
|
* @retval >=0 Order of child with specified argument
|
||||||
|
* @retval -1 Not found
|
||||||
|
* @note special handling if y is child of (sub)module
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
yang_order(yang_stmt *y)
|
yang_order(yang_stmt *y)
|
||||||
{
|
{
|
||||||
yang_node *yp;
|
yang_node *yp;
|
||||||
yang_node *ypp;
|
yang_node *ypp;
|
||||||
yang_node *yn;
|
yang_stmt *ym;
|
||||||
int i;
|
int i;
|
||||||
int j=0;
|
int j=0;
|
||||||
|
int tot = 0;
|
||||||
|
|
||||||
yp = y->ys_parent;
|
yp = y->ys_parent;
|
||||||
|
/* XML nodes with yang specs that are children of modules are special -
|
||||||
|
* In clixon, they are seen as an "implicit" container where the XML can come from different
|
||||||
|
* modules. The order must therefore be global among yang top-symbols to be unique.
|
||||||
|
* Example: <x xmlns="foo"/><y xmlns="bar"/>
|
||||||
|
* The order of x and y cannot be compared within a single yang module since they belong to different
|
||||||
|
*/
|
||||||
if (yp->yn_keyword == Y_MODULE || yp->yn_keyword == Y_SUBMODULE){
|
if (yp->yn_keyword == Y_MODULE || yp->yn_keyword == Y_SUBMODULE){
|
||||||
ypp = yp->yn_parent;
|
ypp = yp->yn_parent; /* yang spec */
|
||||||
for (i=0; i<ypp->yn_len; i++){
|
for (i=0; i<ypp->yn_len; i++){ /* iterate through other modules */
|
||||||
yn = (yang_node*)ypp->yn_stmt[i];
|
ym = ypp->yn_stmt[i];
|
||||||
if (order1(yn, y, &j) == 1)
|
if (yp == ym)
|
||||||
return j;
|
break;
|
||||||
|
tot += ym->ys_len;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
order1(yp, y, &j);
|
if (order1(yp, y, &j) == 1)
|
||||||
return j;
|
return tot + j;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! Reset flag in complete tree, arg contains flag */
|
/*! Reset flag in complete tree, arg contains flag */
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ s="$_" ; . ./lib.sh || if [ "$s" = $0 ]; then exit 0; else return 0; fi
|
||||||
|
|
||||||
APPNAME=example
|
APPNAME=example
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
cfg=$dir/conf_yang.xml
|
cfg=$dir/conf_yang.xml
|
||||||
fyangA0=$dir/A@0814-01-28.yang
|
fyangA0=$dir/A@0814-01-28.yang
|
||||||
fyangA1=$dir/A@2019-01-01.yang
|
fyangA1=$dir/A@2019-01-01.yang
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue