C-API changes: Replace yn_each with yn_iter, add keyw argument to yang_stats()

This commit is contained in:
Olof hagsand 2024-06-17 12:51:39 +02:00
parent 3e07a1d279
commit 4b9ee6740b
23 changed files with 358 additions and 248 deletions

View file

@ -483,7 +483,8 @@ yang2cli_var_sub(clixon_handle h,
int retval = -1;
char *type;
yang_stmt *yi = NULL;
int i = 0;
int i;
int inext;
int j;
const char *cvtypestr;
char *arg;
@ -503,8 +504,8 @@ yang2cli_var_sub(clixon_handle h,
if (strcmp(type, "enumeration") == 0 || strcmp(type, "bits") == 0){
cprintf(cb, " choice:");
i = 0;
yi = NULL;
while ((yi = yn_each(ytype, yi)) != NULL){
inext = 0;
while ((yi = yn_iter(ytype, &inext)) != NULL){
if (yang_keyword_get(yi) != Y_ENUM && yang_keyword_get(yi) != Y_BIT)
continue;
if (i)
@ -629,15 +630,17 @@ yang2cli_var_union(clixon_handle h,
cbuf *cb)
{
int retval = -1;
yang_stmt *ytsub = NULL;
yang_stmt *ytsub;
int i;
int inext;
i = 0;
inext = 0;
/* Loop over all sub-types in the resolved union type, note these are
* not resolved types (unless they are built-in, but the resolve call is
* made in the union_one call.
*/
while ((ytsub = yn_each(ytype, ytsub)) != NULL){
while ((ytsub = yn_iter(ytype, &inext)) != NULL){
if (yang_keyword_get(ytsub) != Y_TYPE)
continue;
if (i++)
@ -952,6 +955,7 @@ yang2cli_container(clixon_handle h,
int compress = 0;
yang_stmt *ymod = NULL;
int extvalue = 0;
int inext;
int ret;
if (ys_real_module(ys, &ymod) < 0)
@ -990,8 +994,8 @@ yang2cli_container(clixon_handle h,
cprintf(cb, "%*s%s", (level+1)*3, "", "@mountpoint;\n");
}
}
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL)
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL)
if (yang2cli_stmt(h, yc, level+1, cb) < 0)
goto done;
if (!compress)
@ -1030,6 +1034,7 @@ yang2cli_list(clixon_handle h,
int last_key = 0;
int exist = 0;
int keynr = 0;
int inext;
cprintf(cb, "%*s%s", level*3, "", yang_argument_get(ys));
if ((yd = yang_find(ys, Y_DESCRIPTION, NULL)) != NULL){
@ -1078,8 +1083,8 @@ yang2cli_list(clixon_handle h,
keynr++;
}
cprintf(cb, "{\n");
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL) {
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL) {
/* cvk is a cvec of strings containing variable names
yc is a leaf that may match one of the values of cvk.
*/
@ -1128,11 +1133,12 @@ yang2cli_choice(clixon_handle h,
int level,
cbuf *cb)
{
int retval = -1;
yang_stmt *yc;
int retval = -1;
yang_stmt *yc;
int inext;
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL) {
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL) {
switch (yang_keyword_get(yc)){
case Y_CASE:
if (yang2cli_stmt(h, yc, level+2, cb) < 0)
@ -1257,6 +1263,7 @@ yang2cli_stmt(clixon_handle h,
int treeref_state = 0;
int grouping_treeref = 0;
int extvalue = 0;
int inext;
if (ys == NULL){
clixon_err(OE_YANG, EINVAL, "No yang spec");
@ -1319,8 +1326,8 @@ yang2cli_stmt(clixon_handle h,
case Y_CASE:
case Y_SUBMODULE:
case Y_MODULE:
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL)
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL)
if (yang2cli_stmt(h, yc, level+1, cb) < 0)
goto done;
break;
@ -1443,8 +1450,10 @@ yang2cli_post(clixon_handle h,
if ((yc = yang_find_datanode(yp, co->co_command)) == NULL){
#if 1
/* XXX In case of compress, look at next level */
yang_stmt *y = NULL;
while ((y = yn_each(yp, y)) != NULL){
yang_stmt *y;
int inext = 0;
while ((y = yn_iter(yp, &inext)) != NULL){
if (yang_datanode(y)){
if ((yc = yang_find_datanode(y, co->co_command)) != NULL)
break;
@ -1530,6 +1539,7 @@ yang2cli_grouping(clixon_handle h,
cg_obj *co;
int config;
int i;
int inext;
if ((pt0 = pt_new()) == NULL){
clixon_err(OE_UNIX, errno, "pt_new");
@ -1551,8 +1561,8 @@ yang2cli_grouping(clixon_handle h,
if (autocli_treeref_state(h, &treeref_state) < 0)
goto done;
if (treeref_state || yang_config(ys)){
yc = NULL;
while ((yc = yn_each(ys, yc)) != NULL)
inext = 0;
while ((yc = yn_iter(ys, &inext)) != NULL)
if (yang2cli_stmt(h, yc, 1, cb) < 0)
goto done;
}
@ -1664,6 +1674,7 @@ yang2cli_yspec(clixon_handle h,
cg_obj *co;
int i;
int config;
int inext;
if ((pt0 = pt_new()) == NULL){
clixon_err(OE_UNIX, errno, "pt_new");
@ -1674,8 +1685,8 @@ yang2cli_yspec(clixon_handle h,
goto done;
}
/* Traverse YANG, loop through all modules and generate CLI */
ymod = NULL;
while ((ymod = yn_each(yspec, ymod)) != NULL){
inext = 0;
while ((ymod = yn_iter(yspec, &inext)) != NULL){
/* Filter module name according to cli_autocli.yang setting
* Default is pass and ordering is significant
*/

View file

@ -494,6 +494,7 @@ expand_yang_list(void *h,
yang_stmt *ymod;
int modname = 0;
cbuf *cb = NULL;
int inext;
if (argv == NULL || cvec_len(argv) < 1 || cvec_len(argv) > 2){
clixon_err(OE_PLUGIN, EINVAL, "requires arguments: <schemanode> [<modname>]");
@ -518,8 +519,8 @@ expand_yang_list(void *h,
clixon_err(OE_UNIX, errno, "cbuf_new");
goto done;
}
yn = NULL;
while ((yn = yn_each(yres, yn)) != NULL) {
inext = 0;
while ((yn = yn_iter(yres, &inext)) != NULL) {
if (yang_keyword_get(yn) != Y_LIST)
continue;
cbuf_reset(cb);
@ -559,6 +560,7 @@ show_yang(clixon_handle h,
yang_stmt *yn;
char *str = NULL;
yang_stmt *yspec;
int inext;
yspec = clicon_dbspec_yang(h);
if (cvec_len(argv) > 0){
@ -568,8 +570,8 @@ show_yang(clixon_handle h,
goto done;
}
else{
yn = NULL;
while ((yn = yn_each(yspec, yn)) != NULL) {
inext = 0;
while ((yn = yn_iter(yspec, &inext)) != NULL) {
if (yang_print_cb(stdout, yn, cligen_output) < 0)
goto done;
}
@ -1900,7 +1902,6 @@ cli_show_statistics(clixon_handle h,
uint64_t u64;
char *unit;
if (argv == NULL || (cvec_len(argv) < 1 || cvec_len(argv) > 2)){
clixon_err(OE_PLUGIN, EINVAL, "Expected arguments: [(cli|backend|all) [detail]]");
goto done;
@ -1938,7 +1939,7 @@ cli_show_statistics(clixon_handle h,
cligen_output(stdout, "%-25s %-10s\n", "YANG", "Mem");
}
nr = 0; sz = 0;
if (yang_stats(yspec, &nr, &sz) < 0)
if (yang_stats(yspec, 0, &nr, &sz) < 0)
goto done;
tnr = nr;
tsz = sz;
@ -1961,7 +1962,7 @@ cli_show_statistics(clixon_handle h,
while ((cv2 = cvec_each(cvv2, cv2)) != NULL) {
yspec1 = cv_void_get(cv2);
nr = 0; sz = 0;
if (yang_stats(yspec1, &nr, &sz) < 0)
if (yang_stats(yspec1, 0, &nr, &sz) < 0)
goto done;
/* check if not duplicate */
cv3 = cv2;