Use size_t for things that get counted: column indices, channel numbers
(line numbers already used size_t). De-anonymize an enum to avoid 'int'
where it gets referenced. Adjust printf(3) format strings. Get unsigned
values from option lookups (stick with 32bits, should be acceptable for
spreadsheet columns and channel counts).
Address other minor nits while we are here: Also terminate the last item
in an enum declaration. Add a doxygen comment for parse_line(). Rename a
parameter to achieve tabular doc text layout.
*/
/* Single column formats. */
*/
/* Single column formats. */
+enum single_col_format {
uint64_t samplerate;
/* Number of channels. */
uint64_t samplerate;
/* Number of channels. */
- unsigned int num_channels;
/* Column delimiter character(s). */
GString *delimiter;
/* Column delimiter character(s). */
GString *delimiter;
gboolean multi_column_mode;
/* Column number of the sample data in single column mode. */
gboolean multi_column_mode;
/* Column number of the sample data in single column mode. */
- unsigned int single_column;
/*
* Number of the first column to parse. Equivalent to the number of the
* first channel in multi column mode and the single column number in
* single column mode.
*/
/*
* Number of the first column to parse. Equivalent to the number of the
* first channel in multi column mode and the single column number in
* single column mode.
*/
- unsigned int first_column;
/*
* Column number of the first channel in multi column mode and position of
* the bit for the first channel in single column mode.
*/
/*
* Column number of the first channel in multi column mode and position of
* the bit for the first channel in single column mode.
*/
- unsigned int first_channel;
/* Line number to start processing. */
size_t start_line;
/* Line number to start processing. */
size_t start_line;
gboolean header;
/* Format sample data is stored in single column mode. */
gboolean header;
/* Format sample data is stored in single column mode. */
+ enum single_col_format format;
size_t sample_unit_size; /**!< Byte count for a single sample. */
uint8_t *sample_buffer; /**!< Buffer for a single sample. */
size_t sample_unit_size; /**!< Byte count for a single sample. */
uint8_t *sample_buffer; /**!< Buffer for a single sample. */
length = strlen(str);
if (!length) {
length = strlen(str);
if (!length) {
- sr_err("Column %u in line %zu is empty.", inc->single_column,
+ sr_err("Column %zu in line %zu is empty.", inc->single_column,
inc->line_number);
return SR_ERR;
}
inc->line_number);
return SR_ERR;
}
if (str[length - i - 1] == '1') {
inc->sample_buffer[j / 8] |= (1 << (j % 8));
} else if (str[length - i - 1] != '0') {
if (str[length - i - 1] == '1') {
inc->sample_buffer[j / 8] |= (1 << (j % 8));
} else if (str[length - i - 1] != '0') {
- sr_err("Invalid value '%s' in column %u in line %zu.",
+ sr_err("Invalid value '%s' in column %zu in line %zu.",
str, inc->single_column, inc->line_number);
return SR_ERR;
}
str, inc->single_column, inc->line_number);
return SR_ERR;
}
length = strlen(str);
if (!length) {
length = strlen(str);
if (!length) {
- sr_err("Column %u in line %zu is empty.", inc->single_column,
+ sr_err("Column %zu in line %zu is empty.", inc->single_column,
inc->line_number);
return SR_ERR;
}
inc->line_number);
return SR_ERR;
}
c = str[length - i - 1];
if (!g_ascii_isxdigit(c)) {
c = str[length - i - 1];
if (!g_ascii_isxdigit(c)) {
- sr_err("Invalid value '%s' in column %u in line %zu.",
+ sr_err("Invalid value '%s' in column %zu in line %zu.",
str, inc->single_column, inc->line_number);
return SR_ERR;
}
str, inc->single_column, inc->line_number);
return SR_ERR;
}
length = strlen(str);
if (!length) {
length = strlen(str);
if (!length) {
- sr_err("Column %u in line %zu is empty.", inc->single_column,
+ sr_err("Column %zu in line %zu is empty.", inc->single_column,
inc->line_number);
return SR_ERR;
}
inc->line_number);
return SR_ERR;
}
c = str[length - i - 1];
if (c < '0' || c > '7') {
c = str[length - i - 1];
if (c < '0' || c > '7') {
- sr_err("Invalid value '%s' in column %u in line %zu.",
+ sr_err("Invalid value '%s' in column %zu in line %zu.",
str, inc->single_column, inc->line_number);
return SR_ERR;
}
str, inc->single_column, inc->line_number);
return SR_ERR;
}
-static char **parse_line(char *buf, struct context *inc, int max_columns)
+/**
+ * @brief Splits a text line into a set of columns.
+ *
+ * @param[in] buf The input text line to split.
+ * @param[in] inc The input module's context.
+ * @param[in] max_cols The maximum column count, negative to get all of them.
+ *
+ * @returns An array of strings, representing the columns' text.
+ */
+static char **parse_line(char *buf, struct context *inc, ssize_t max_cols)
{
const char *str, *remainder;
GSList *list, *l;
{
const char *str, *remainder;
GSList *list, *l;
remainder = buf;
str = strstr(remainder, inc->delimiter->str);
remainder = buf;
str = strstr(remainder, inc->delimiter->str);
- while (str && max_columns) {
+ while (str && max_cols) {
if (n >= inc->first_column) {
column = g_strndup(remainder, str - remainder);
list = g_slist_prepend(list, g_strstrip(column));
if (n >= inc->first_column) {
column = g_strndup(remainder, str - remainder);
list = g_slist_prepend(list, g_strstrip(column));
- if (buf[0] && max_columns && n >= inc->first_column) {
+ if (buf[0] && max_cols && n >= inc->first_column) {
column = g_strdup(remainder);
list = g_slist_prepend(list, g_strstrip(column));
k++;
column = g_strdup(remainder);
list = g_slist_prepend(list, g_strstrip(column));
k++;
in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
in->priv = inc = g_malloc0(sizeof(struct context));
in->sdi = g_malloc0(sizeof(struct sr_dev_inst));
in->priv = inc = g_malloc0(sizeof(struct context));
- inc->single_column = g_variant_get_int32(g_hash_table_lookup(options, "single-column"));
+ inc->single_column = g_variant_get_uint32(g_hash_table_lookup(options, "single-column"));
inc->multi_column_mode = inc->single_column == 0;
inc->multi_column_mode = inc->single_column == 0;
- inc->num_channels = g_variant_get_int32(g_hash_table_lookup(options, "numchannels"));
+ inc->num_channels = g_variant_get_uint32(g_hash_table_lookup(options, "numchannels"));
inc->delimiter = g_string_new(g_variant_get_string(
g_hash_table_lookup(options, "delimiter"), NULL));
inc->delimiter = g_string_new(g_variant_get_string(
g_hash_table_lookup(options, "delimiter"), NULL));
inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate"));
inc->samplerate = g_variant_get_uint64(g_hash_table_lookup(options, "samplerate"));
- inc->first_channel = g_variant_get_int32(g_hash_table_lookup(options, "first-channel"));
+ inc->first_channel = g_variant_get_uint32(g_hash_table_lookup(options, "first-channel"));
inc->header = g_variant_get_boolean(g_hash_table_lookup(options, "header"));
inc->header = g_variant_get_boolean(g_hash_table_lookup(options, "header"));
- inc->start_line = g_variant_get_int32(g_hash_table_lookup(options, "startline"));
+ inc->start_line = g_variant_get_uint32(g_hash_table_lookup(options, "startline"));
if (inc->start_line < 1) {
sr_err("Invalid start line %zu.", inc->start_line);
return SR_ERR_ARG;
if (inc->start_line < 1) {
sr_err("Invalid start line %zu.", inc->start_line);
return SR_ERR_ARG;
{
struct context *inc;
GString *channel_name;
{
struct context *inc;
GString *channel_name;
- unsigned int num_columns, i;
size_t line_number, l;
int ret;
char **lines, *line, **columns, *column;
size_t line_number, l;
int ret;
char **lines, *line, **columns, *column;
/* Ensure that the first column is not out of bounds. */
if (!num_columns) {
/* Ensure that the first column is not out of bounds. */
if (!num_columns) {
- sr_err("Column %u in line %zu is out of bounds.",
+ sr_err("Column %zu in line %zu is out of bounds.",
inc->first_column, line_number);
ret = SR_ERR;
goto out;
inc->first_column, line_number);
ret = SR_ERR;
goto out;
*/
if (!inc->num_channels) {
inc->num_channels = num_columns;
*/
if (!inc->num_channels) {
inc->num_channels = num_columns;
- sr_dbg("Number of auto-detected channels: %u.",
+ sr_dbg("Number of auto-detected channels: %zu.",
if (inc->header && inc->multi_column_mode && column[0] != '\0')
g_string_assign(channel_name, column);
else
if (inc->header && inc->multi_column_mode && column[0] != '\0')
g_string_assign(channel_name, column);
else
- g_string_printf(channel_name, "%u", i);
+ g_string_printf(channel_name, "%zu", i);
sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name->str);
}
g_string_free(channel_name, TRUE);
sr_channel_new(in->sdi, i, SR_CHANNEL_LOGIC, TRUE, channel_name->str);
}
g_string_free(channel_name, TRUE);
struct context *inc;
gsize num_columns;
uint64_t samplerate;
struct context *inc;
gsize num_columns;
uint64_t samplerate;
- int max_columns, ret, l;
+ size_t max_columns, l;
+ int ret;
char *p, **lines, *line, **columns;
inc = in->priv;
char *p, **lines, *line, **columns;
inc = in->priv;
}
num_columns = g_strv_length(columns);
if (!num_columns) {
}
num_columns = g_strv_length(columns);
if (!num_columns) {
- sr_err("Column %u in line %zu is out of bounds.",
+ sr_err("Column %zu in line %zu is out of bounds.",
inc->first_column, inc->line_number);
g_strfreev(columns);
g_strfreev(lines);
inc->first_column, inc->line_number);
g_strfreev(columns);
g_strfreev(lines);