+ format_count = g_strv_length(formats);
+ if (!format_count) {
+ sr_err("Cannot parse columns format %s (field count).", column_format);
+ g_strfreev(formats);
+ return SR_ERR_ARG;
+ }
+ column_count = bit_count = 0;
+ auto_column_count = 0;
+ for (format_idx = 0; format_idx < format_count; format_idx++) {
+ format = formats[format_idx];
+ ret = split_column_format(format, &c, &f, &b);
+ sr_dbg("fmt %s -> %zu cols, %s fmt, %zu bits, rc %d", format, c, col_format_text[f], b, ret);
+ if (ret != SR_OK) {
+ sr_err("Cannot parse columns format %s (field split, %s).", column_format, format);
+ g_strfreev(formats);
+ return SR_ERR_ARG;
+ }
+ if (f && !c) {
+ /* User requested "auto-count", must be last format. */
+ if (formats[format_idx + 1]) {
+ sr_err("Auto column count must be last format field.");
+ g_strfreev(formats);
+ return SR_ERR_ARG;
+ }
+ auto_column_count = inc->column_seen_count - column_count;
+ c = auto_column_count;
+ }
+ column_count += c;
+ bit_count += c * b;
+ }
+ sr_dbg("Column format %s -> %zu columns, %zu logic channels.",
+ column_format, column_count, bit_count);
+
+ /* Allocate and fill in "column processing" details. */
+ inc->column_want_count = column_count;
+ inc->column_details = g_malloc0_n(column_count, sizeof(inc->column_details[0]));
+ column_idx = channel_idx = 0;
+ for (format_idx = 0; format_idx < format_count; format_idx++) {
+ format = formats[format_idx];
+ (void)split_column_format(format, &c, &f, &b);
+ if (f && !c)
+ c = auto_column_count;
+ while (c-- > 0) {
+ detail = &inc->column_details[column_idx++];
+ detail->col_nr = column_idx;
+ detail->text_format = f;
+ if (detail->text_format) {
+ detail->channel_offset = channel_idx;
+ detail->channel_count = b;
+ channel_idx += b;
+ }
+ sr_dbg("detail -> col %zu, fmt %s, ch off/cnt %zu/%zu",
+ detail->col_nr, col_format_text[detail->text_format],
+ detail->channel_offset, detail->channel_count);
+ }
+ }
+ inc->logic_channels = channel_idx;
+ g_strfreev(formats);