[LTP] [PATCH] lib: tst_bool_expr: Add support for strings

Richard Palethorpe rpalethorpe@suse.de
Wed Nov 11 15:19:00 CET 2020


Hello,

Cyril Hrubis <chrubis@suse.cz> writes:

> diff --git a/lib/tst_bool_expr.c b/lib/tst_bool_expr.c
> index dd147cde3..35ffa5a80 100644
> --- a/lib/tst_bool_expr.c
> +++ b/lib/tst_bool_expr.c
> @@ -64,6 +64,7 @@ static unsigned int tokenize(const char *expr, struct tst_expr_tok *last)
>  {
>  	size_t i, j;
>  	unsigned int token_cnt = 0;
> +	int in_string = 0;
>  
>  	for (j = i = 0; expr[i]; i++) {


Why not skip the whole switch statement if in_string and just check for
the closing '"' instead?

>  		switch (expr[i]) {
> @@ -72,14 +73,21 @@ static unsigned int tokenize(const char *expr, struct tst_expr_tok *last)
>  		case '!':
>  		case '&':
>  		case '|':
> -			token_cnt += new_tok(&last, &expr[j], i - j);
> -			token_cnt += new_tok(&last, &expr[i], 1);
> -			j = i+1;
> +			if (!in_string) {
> +				token_cnt += new_tok(&last, &expr[j], i - j);
> +				token_cnt += new_tok(&last, &expr[i], 1);
> +				j = i+1;
> +			}
>  		break;
>  		case '\t':
>  		case ' ':
> -			token_cnt += new_tok(&last, &expr[j], i - j);
> -			j = i+1;
> +			if (!in_string) {
> +				token_cnt += new_tok(&last, &expr[j], i - j);
> +				j = i+1;
> +			}
> +		break;
> +		case '"':
> +			in_string = !in_string;
>  		break;
>  		default:
>  		break;
> -- 
> 2.26.2

It should probably be an error if tokenize exits with in_string=1?

-- 
Thank you,
Richard.


More information about the ltp mailing list