From: Andrei Ziureaev <andrei.ziureaev@xxxxxxx> Add an inline helper function to dtc.h that checks if there's a marker of a type at an offset. Also, there are two useful static functions in treesource.c. Make them public, add their prototypes to dtc.h and rename one of them. Signed-off-by: Andrei Ziureaev <andrei.ziureaev@xxxxxxx> Signed-off-by: Andrei Ziureaev <andreiziureaev@xxxxxxxxx> --- dtc.h | 11 +++++++++++ treesource.c | 8 ++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dtc.h b/dtc.h index a08f415..286d999 100644 --- a/dtc.h +++ b/dtc.h @@ -125,6 +125,17 @@ struct data { for_each_marker(m) \ if ((m)->type == (t)) +static inline bool markers_have_type_at_offset(struct marker *m, enum markertype type, int off) +{ + for_each_marker_of_type(m, type) + if (m->offset == off) + return true; + + return false; +} + +bool marker_has_data_type_information(struct marker *m); +struct marker *next_type_marker(struct marker *m); size_t type_marker_length(struct marker *m); void data_free(struct data d); diff --git a/treesource.c b/treesource.c index 061ba8c..0785d83 100644 --- a/treesource.c +++ b/treesource.c @@ -124,14 +124,14 @@ static void write_propval_int(FILE *f, const char *p, size_t len, size_t width) } } -static bool has_data_type_information(struct marker *m) +bool marker_has_data_type_information(struct marker *m) { return m->type >= TYPE_UINT8; } -static struct marker *next_type_marker(struct marker *m) +struct marker *next_type_marker(struct marker *m) { - while (m && !has_data_type_information(m)) + while (m && !marker_has_data_type_information(m)) m = m->next; return m; } @@ -230,7 +230,7 @@ static void write_propval(FILE *f, struct property *prop) size_t data_len = type_marker_length(m) ? : len - m->offset; const char *p = &prop->val.val[m->offset]; - if (has_data_type_information(m)) { + if (marker_has_data_type_information(m)) { emit_type = m->type; fprintf(f, " %s", delim_start[emit_type]); } else if (m->type == LABEL) -- 2.17.1