diff --git a/lib/mapping.c b/lib/mapping.c index 16424db7c..0d7160fa7 100644 --- a/lib/mapping.c +++ b/lib/mapping.c @@ -131,34 +131,55 @@ int mapping_parse_str(struct mapping_entry *me, const char *str, struct list *no } else if (!strcmp(type, "data")) { char *first_str, *last_str; + int first = -1, last = -1; me->type = MAPPING_TYPE_DATA; first_str = strtok(NULL, "-]"); if (first_str) { - int first, last; + info("Mapping: %s", first_str); - last_str = strtok(NULL, "]"); - if (!last_str) - last_str = first_str; /* single element: data[5] => data[5-5] */ + if (me->node) + first = list_lookup_index(&me->node->in.signals, first_str); - first = signal_get_offset(first_str, me->node); - last = signal_get_offset(last_str, me->node); - if (first < 0 || last < 0 || last < first) - goto invalid_format; - - me->data.offset = first; - me->length = last - first + 1; + if (first < 0) { + char *endptr; + first = strtoul(first_str, &endptr, 10); + if (endptr != first_str + strlen(first_str)) + goto invalid_format; + } } else { me->data.offset = 0; me->length = 0; + goto end; } + + last_str = strtok(NULL, "]"); + if (last_str) { + if (me->node) + last = list_lookup_index(&me->node->in.signals, last_str); + + if (last < 0) { + char *endptr; + last = strtoul(last_str, &endptr, 10); + if (endptr != last_str + strlen(last_str)) + goto invalid_format; + } + } + else + last = first; /* single element: data[5] => data[5-5] */ + + if (last < first) + goto invalid_format; + + me->data.offset = first; + me->length = last - first + 1; } else goto invalid_format; - /* Check that there is no garbage at the end */ +end: /* Check that there is no garbage at the end */ end = strtok(NULL, ""); if (end) goto invalid_format; diff --git a/lib/signal.c b/lib/signal.c index 5bc57cb99..15c045fdf 100644 --- a/lib/signal.c +++ b/lib/signal.c @@ -79,17 +79,17 @@ int signal_parse_list(struct list *list, json_t *cfg) return 0; } -int signal_get_offset(const char *str, struct node *n) +int signal_get_offsets(const char *str, struct list *sigs) { int idx; char *endptr; struct signal *s; /* Lets try to find a signal with a matching name */ - if (n) { - s = list_lookup(&n->signals, str); + if (1) { + s = list_lookup(sigs, str); if (s) - return list_index(&n->signals, s); + return list_index(sigs, s); } /* Lets try to interpret the signal name as an index */