+ inc->column_details = g_malloc0_n(column_count, sizeof(inc->column_details[0]));
+ column_idx = channel_idx = analog_idx = 0;
+ channel_name = g_string_sized_new(64);
+ for (format_idx = 0; format_idx < format_count; format_idx++) {
+ /* Process a format field, which can span multiple columns. */
+ format = formats[format_idx];
+ (void)split_column_format(format, &c, &f, &b);
+ if (f && !c)
+ c = auto_column_count;
+ while (c-- > 0) {
+ /* Fill in a column's processing details. */
+ detail = &inc->column_details[column_idx++];
+ detail->col_nr = column_idx;
+ detail->text_format = f;
+ if (format_is_analog(detail->text_format)) {
+ detail->channel_offset = analog_idx;
+ detail->channel_count = 1;
+ detail->analog_digits = b;
+ analog_idx += detail->channel_count;
+ } else if (format_is_logic(detail->text_format)) {
+ detail->channel_offset = channel_idx;
+ detail->channel_count = b;
+ channel_idx += detail->channel_count;
+ } else if (format_is_ignore(detail->text_format)) {
+ /* EMPTY */
+ continue;
+ } else {
+ /*
+ * Neither logic nor analog data, nor ignore.
+ * Format was noted. No channel creation involved.
+ */
+ continue;
+ }
+ /*
+ * Pick most appropriate channel names. Optionally
+ * use text from a header line (when requested by the
+ * user). In the absence of header text, channels are
+ * assigned rather generic names.
+ *
+ * Manipulation of the column's caption (when a header
+ * line is seen) is acceptable, because this header
+ * line won't get processed another time.
+ */
+ column = column_texts[detail->col_nr - 1];
+ if (inc->use_header && column && *column)
+ caption = sr_scpi_unquote_string(column);
+ else
+ caption = NULL;
+ if (!caption || !*caption)
+ caption = NULL;
+ /*
+ * TODO Need we first create _all_ logic channels,
+ * before creating analog channels? Just store the
+ * parameters here (index, type, name) and have the
+ * creation sequence done outside of the format
+ * spec parse loop.
+ */
+ for (create_idx = 0; create_idx < detail->channel_count; create_idx++) {
+ if (caption && detail->channel_count == 1) {
+ g_string_assign(channel_name, caption);
+ } else if (caption) {
+ g_string_printf(channel_name, "%s[%zu]",
+ caption, create_idx);
+ } else {
+ g_string_printf(channel_name, "%zu",
+ detail->channel_offset + create_idx);
+ }
+ if (format_is_analog(detail->text_format)) {
+ channel_sdi_nr = logic_count + detail->channel_offset + create_idx;
+ channel_type = SR_CHANNEL_ANALOG;
+ detail->channel_index = g_slist_length(in->sdi->channels);
+ } else if (format_is_logic(detail->text_format)) {
+ channel_sdi_nr = detail->channel_offset + create_idx;
+ channel_type = SR_CHANNEL_LOGIC;
+ } else {
+ continue;
+ }
+ sr_channel_new(in->sdi, channel_sdi_nr,
+ channel_type, TRUE, channel_name->str);
+ }
+ }
+ }
+ inc->logic_channels = channel_idx;
+ inc->analog_channels = analog_idx;
+ g_string_free(channel_name, TRUE);
+ g_strfreev(formats);