-const char *
-nxm_parse_field_bits(const char *s, uint32_t *headerp, int *ofsp, int *n_bitsp)
-{
- const char *full_s = s;
- const char *name;
- uint32_t header;
- int start, end;
- int name_len;
- int width;
-
- name = s;
- name_len = strcspn(s, "[");
- if (s[name_len] != '[') {
- ovs_fatal(0, "%s: missing [ looking for field name", full_s);
- }
-
- header = parse_nxm_field_name(name, name_len);
- if (!header) {
- ovs_fatal(0, "%s: unknown field `%.*s'", full_s, name_len, s);
- }
- width = nxm_field_bits(header);
-
- s += name_len;
- if (sscanf(s, "[%d..%d]", &start, &end) == 2) {
- /* Nothing to do. */
- } else if (sscanf(s, "[%d]", &start) == 1) {
- end = start;
- } else if (!strncmp(s, "[]", 2)) {
- start = 0;
- end = width - 1;
- } else {
- ovs_fatal(0, "%s: syntax error expecting [] or [<bit>] or "
- "[<start>..<end>]", full_s);
- }
- s = strchr(s, ']') + 1;
-
- if (start > end) {
- ovs_fatal(0, "%s: starting bit %d is after ending bit %d",
- full_s, start, end);
- } else if (start >= width) {
- ovs_fatal(0, "%s: starting bit %d is not valid because field is only "
- "%d bits wide", full_s, start, width);
- } else if (end >= width){
- ovs_fatal(0, "%s: ending bit %d is not valid because field is only "
- "%d bits wide", full_s, end, width);
- }
-
- *headerp = header;
- *ofsp = start;
- *n_bitsp = end - start + 1;
-
- return s;
-}
-