From b6a4a80652a0c8a24219a34b0c38fcfe4ac1de61 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Wed, 30 May 2012 11:53:58 -0300 Subject: [PATCH] separate dumping of hierchy rules from dumping of fields With only one function, top-level fields definitions were printed in a style as if they were rules and not fields. --- b2/chr.c | 44 ++++++++++++++++++++++++++------------------ b2/chr.h | 3 ++- b2/lang.y | 6 ++++-- 3 files changed, 32 insertions(+), 21 deletions(-) diff --git a/b2/chr.c b/b2/chr.c index 2ae316e..fdad4a0 100644 --- a/b2/chr.c +++ b/b2/chr.c @@ -97,7 +97,7 @@ void field_finalize(struct field *field) #define INDENT 8 -static void dump_fields(FILE *file, const struct field *field, int level); +static void dump_rules(FILE *file, const struct field *field, int level); static void dump_set_decl(FILE *file, const struct names *first_name) @@ -127,23 +127,16 @@ static void dump_field_decl(FILE *file, const struct field *field) static void dump_action(FILE *file, const struct action *act, int level) { - const struct field *field; - if (act->fields) { - fprintf(file, " {"); - for (field = act->fields; field; field = field->next) { - fprintf(file, " %s=", field->name); - dump_field_decl(file, field); - } - fprintf(file, " }\n"); - } else { - fprintf(file, "\n"); + fprintf(file, " "); + fields_dump(file, act->fields); } - dump_fields(file, act->rules, level+1); + fprintf(file, "\n"); + dump_rules(file, act->rules, level+1); } -static void dump_one_field(FILE *file, const struct field *field, int level) +static void dump_one_rule(FILE *file, const struct field *field, int level) { const struct selector *sel; const struct condition *cond; @@ -162,7 +155,7 @@ static void dump_one_field(FILE *file, const struct field *field, int level) dump_relop(file, cond->relop); dump(file, field->fmt, &cond->value); } - fprintf(file, ": "); + fprintf(file, ":"); dump_action(file, &sel->act, level); } if (field->any.fields || field->any.rules) { @@ -173,16 +166,31 @@ static void dump_one_field(FILE *file, const struct field *field, int level) } -static void dump_fields(FILE *file, const struct field *field, int level) +void fields_dump(FILE *file, const struct field *fields) +{ + const struct field *f; + + if (!fields) + return; + fprintf(file, "{ "); + for (f = fields; f; f = f->next) { + fprintf(file, "%s%s=", f == fields ? "" : " ", f->name); + dump_field_decl(file, f); + } + fprintf(file, " }"); +} + + +static void dump_rules(FILE *file, const struct field *field, int level) { while (field) { - dump_one_field(file, field, level); + dump_one_rule(file, field, level); field = field->next; } } -void field_dump(FILE *file, const struct field *field) +void rules_dump(FILE *file, const struct field *field) { - dump_fields(file, field, 0); + dump_rules(file, field, 0); } diff --git a/b2/chr.h b/b2/chr.h index 602b7ba..7ad95b7 100644 --- a/b2/chr.h +++ b/b2/chr.h @@ -53,6 +53,7 @@ struct field *new_field(const char *name, const struct format *fmt, struct selector *new_selector(void); struct condition *new_condition(enum relop relop, const char *word); void field_finalize(struct field *field); -void field_dump(FILE *file, const struct field *field); +void fields_dump(FILE *file, const struct field *field); +void rules_dump(FILE *file, const struct field *field); #endif /* !CHR_H */ diff --git a/b2/lang.y b/b2/lang.y index 0a0b7f7..ad8dd92 100644 --- a/b2/lang.y +++ b/b2/lang.y @@ -156,8 +156,10 @@ hierarchy: | action { $$ = $1; - field_dump(stderr, $1.fields); - field_dump(stderr, $1.rules); + fields_dump(stderr, $1.fields); + if ($1.fields) + fprintf(stderr, "\n"); + rules_dump(stderr, $1.rules); } ;