Skip to content

Commit

Permalink
add C enum generation
Browse files Browse the repository at this point in the history
  • Loading branch information
driftregion committed Jan 27, 2022
1 parent 68139f7 commit 35f3bef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions 2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,16 @@ static int msg2h_types(dbc_t *dbc, FILE *h, dbc2c_options_t *copts)
assert(dbc);
assert(copts);

for (size_t i = 0; i < dbc->val_count; i++) {
val_list_t *list = dbc->vals[i];
fprintf(h, "typedef enum {\n");
for (size_t j = 0; j < list->val_list_item_count; j++) {
val_list_item_t *item = list->val_list_items[j];
fprintf(h, "\t%s_%s=%d,\n", list->name, item->name, item->value);
}

This comment has been minimized.

Copy link
@howerj

howerj Jan 27, 2022

I'd add spaces around the "=", ideally all the assignments would like up, but meh.

fprintf(h, "} %s_e;\n\n", list->name);
}

for (size_t i = 0; i < dbc->message_count; i++) {
can_msg_t *msg = dbc->messages[i];
char name[MAX_NAME_LENGTH] = {0};
Expand Down
2 changes: 1 addition & 1 deletion parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static const char *dbc_grammar =
" | <comment_string> "
" ) <s>* ';' <n> ;\n "
" comments : <comment>* ; "
" dbc : <version> <symbols> <bs> <ecus> <values>* <n>* <messages> (<n>|<sigval>|<types>)* ; \n" ;
" dbc : <version> <symbols> <bs> <ecus> <values>* <n>* <messages> <comments> <sigval>* <attribute_definition>* <attribute_value>* <vals> ; \n" ;

This comment has been minimized.

Copy link
@howerj

howerj Jan 27, 2022

If this breaks something, somebody will let us know.

const char *parse_get_grammar(void)
{
Expand Down

2 comments on commit 35f3bef

@howerj
Copy link

@howerj howerj commented on 35f3bef Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to make a pull request for this, or should I copy this over? :?

@driftregion
Copy link
Owner Author

@driftregion driftregion commented on 35f3bef Jan 29, 2022 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.