Skip to contentSkip to conversation

src: Always print range expressions numerically

PATCH Applied Elise Lennion 2 participants 2 messages Feb 2, 2017 – Feb 5, 2017 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH v2 2/2 src: Always print range expressions numerically

Because the rules are more legible this way. Also, the parser doesn't accept strings on ranges, so, printing ranges numerically better match the rules definition.

Fixes(Bug 1046 - mobility header with range gives illegible rule).

---

v2: Replace ternary operator with if statements.
Remove the new NUMERIC_CONSTANT, now uses a value bigger than NUMERIC_ALL to print symbolic constants as numbers, this case is only met during expr_range_print.

 src/datatype.c   | 8 +++++++-
 src/expression.c | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)
src/datatype.c +7 -1
index 1518606..d697a07 100644
@@ -175,9 +175,15 @@ void symbolic_constant_print(const struct symbol_table *tbl,
 		return expr_basetype(expr)->print(expr);
 
 	if (quotes)
-		printf("\"%s\"", s->identifier);
+		printf("\"");
+
+	if (numeric_output > NUMERIC_ALL)
+		printf("%lu", val);
 	else
 		printf("%s", s->identifier);
+
+	if (quotes)
+		printf("\"");
 }
 
 static void switch_byteorder(void *data, unsigned int len)
src/expression.c +2 -0
index 1567870..da94b79 100644
@@ -597,9 +597,11 @@ struct expr *relational_expr_alloc(const struct location *loc, enum ops op,
 
 static void range_expr_print(const struct expr *expr)
 {
+	numeric_output += NUMERIC_ALL + 1;
 	expr_print(expr->left);
 	printf("-");
 	expr_print(expr->right);
+	numeric_output -= NUMERIC_ALL + 1;
 }
 
 static void range_expr_clone(struct expr *new, const struct expr *expr)
Signature · 1 line
2.7.4
#1 lore raw
Quoted 3 lines · Elise Lennion

Because the rules are more legible this way. Also, the parser doesn't accept strings on ranges, so, printing ranges numerically better match the rules definition.

Also applied, thanks.