added CR delimiters to if-feature

This commit is contained in:
Olof hagsand 2020-07-27 13:00:56 +02:00
parent f7b640810b
commit 918bf6223b
2 changed files with 23 additions and 12 deletions

View file

@ -2072,6 +2072,7 @@ ys_populate2(yang_stmt *ys,
* @retval 1 OK * @retval 1 OK
* @note if-feature syntax is restricted to single, and, or, syntax, such as "a or b" * @note if-feature syntax is restricted to single, and, or, syntax, such as "a or b"
* but RFC7950 allows for nested expr/term/factor syntax. * but RFC7950 allows for nested expr/term/factor syntax.
* XXX This should really be parsed in yang/lex.
*/ */
static int static int
yang_if_feature(clicon_handle h, yang_if_feature(clicon_handle h,
@ -2082,6 +2083,7 @@ yang_if_feature(clicon_handle h,
int nvec; int nvec;
char *f; char *f;
int i; int i;
int j;
char *prefix = NULL; char *prefix = NULL;
char *feature = NULL; char *feature = NULL;
yang_stmt *ymod; /* module yang node */ yang_stmt *ymod; /* module yang node */
@ -2089,19 +2091,18 @@ yang_if_feature(clicon_handle h,
int opand = -1; /* -1:not set, 0:or, 1:and */ int opand = -1; /* -1:not set, 0:or, 1:and */
int enabled = 0; int enabled = 0;
if ((vec = clicon_strsep(ys->ys_argument, " \t", &nvec)) == NULL) if ((vec = clicon_strsep(ys->ys_argument, " \t\r\n", &nvec)) == NULL)
goto done; goto done;
if (nvec%2 == 0){ /* Must be odd: eg a / "a or b" etc */
clicon_err(OE_YANG, EINVAL, "Syntax error IF_FEATURE \"%s\" (only single if-feature-expr and/or lists allowed)", ys->ys_argument);
goto done;
}
/* Two steps: first detect operators /* Two steps: first detect operators
* Step 1: support "a" or "a or b or c" or "a and b and c " * Step 1: support "a" or "a or b or c" or "a and b and c "
*/ */
j = 0;
for (i=0; i<nvec; i++){ for (i=0; i<nvec; i++){
if (i%2==0) /* only keep odd i:s 1,3,... */
continue;
f = vec[i]; f = vec[i];
if (strcmp(f, "") == 0) /* skip empty */
continue;
if ((j++)%2==0) /* only keep odd i:s 1,3,... */
continue;
/* odd i: operator "and" or "or" */ /* odd i: operator "and" or "or" */
if (strcmp(f, "or") == 0){ if (strcmp(f, "or") == 0){
switch (opand){ switch (opand){
@ -2142,6 +2143,11 @@ yang_if_feature(clicon_handle h,
goto done; goto done;
} }
} /* for step 1 */ } /* for step 1 */
if (j%2 == 0){ /* Must be odd: eg a / "a or b" etc */
clicon_err(OE_YANG, EINVAL, "Syntax error IF_FEATURE \"%s\" (only single if-feature-expr and/or lists allowed)", ys->ys_argument);
goto done;
}
if (opand == -1) /* Uninitialized means single operand */ if (opand == -1) /* Uninitialized means single operand */
opand = 1; opand = 1;
if (opand) /* if AND, start as enabled, if OR start as disabled */ if (opand) /* if AND, start as enabled, if OR start as disabled */
@ -2149,10 +2155,13 @@ yang_if_feature(clicon_handle h,
else else
enabled = 0; enabled = 0;
/* Step 2: Boolean operations on operands */ /* Step 2: Boolean operations on operands */
j = 0;
for (i=0; i<nvec; i++){ for (i=0; i<nvec; i++){
if (i%2==1) /* only keep even i:s 0,2,... */
continue;
f = vec[i]; f = vec[i];
if (strcmp(f, "") == 0) /* skip empty */
continue;
if ((j++)%2==1) /* only keep even i:s 0,2,... */
continue;
if (nodeid_split(f, &prefix, &feature) < 0) if (nodeid_split(f, &prefix, &feature) < 0)
goto done; goto done;
/* Specifically need to handle? strcmp(prefix, myprefix)) */ /* Specifically need to handle? strcmp(prefix, myprefix)) */

View file

@ -77,17 +77,19 @@ module example{
type "string"; type "string";
} }
leaf m1{ leaf m1{
if-feature "A and A1"; if-feature "A and
A1";
description "Enabled"; description "Enabled";
type "string"; type "string";
} }
leaf m2{ leaf m2{
if-feature "A or A1"; if-feature "A or
A1";
description "Enabled"; description "Enabled";
type "string"; type "string";
} }
leaf m3{ leaf m3{
if-feature "A and B"; if-feature "A and B";
description "Not enabled"; description "Not enabled";
type "string"; type "string";
} }