#define LOG_PREFIX "input/isf"
-#define CHUNK_SIZE (4 * 1024 * 1024)
+#define CHUNK_SIZE (4 * 1024 * 1024)
/* Maximum header size. */
#define MAX_HEADER_SIZE 1024
if (offset >= buf->len)
return NULL;
- /*
- * Curve metadata length is encoded as an ASCII
- * digit '0' to '9'.
- */
- metadata_length = (size_t) *data_ptr;
- if (metadata_length < '0' || metadata_length > '9')
+ /* Curve metadata length is encoded as an ASCII digit '0' to '9'. */
+ metadata_length = (size_t)*data_ptr;
+ if ((metadata_length < '0') || (metadata_length > '9'))
return NULL;
+
metadata_length -= '0';
- data_ptr += 1 + metadata_length;
- offset = (size_t) (data_ptr - buf->str);
+ data_ptr += (1 + metadata_length);
+ offset = (size_t)(data_ptr - buf->str);
if (offset >= buf->len)
return NULL;
size_t i, channel_ix;
channel_ix = 0;
- /*
- * ISF WFID looks something like WFID "Ch1, ...";
+
+ /* ISF WFID looks something like WFID "Ch1, ..."
* hence we must skip character '"'
*/
i = 1;
- while (i < buflen &&
- buf[i] != ',' &&
- buf[i] != '"' &&
- channel_ix < MAX_CHANNEL_NAME_SIZE - 1) {
+ while ((i < buflen) && (buf[i] != ',') && (buf[i] != '"') &&
+ (channel_ix < MAX_CHANNEL_NAME_SIZE - 1))
inc->channel_name[channel_ix++] = buf[i++];
- }
+
inc->channel_name[channel_ix] = 0;
}
size_t i;
i = 0;
- while (i < buflen && buf[i] != ';' && i < value_size - 1) {
+ while ((i < buflen) && (buf[i] != ';') && (i < value_size - 1)) {
value[i] = buf[i];
- ++i;
+ i++;
}
+
value[i] = 0;
- if (i >= buflen || buf[i] != ';')
+ if ((i >= buflen) || (buf[i] != ';'))
memset(value, 0, value_size);
}
find_string_value(buf, buflen, value, MAX_ENCODING_STRING_SIZE);
/* "BIN" and "BINARY" are accepted. */
- if (strcmp(value, "BINARY") != 0 && strcmp(value, "BIN") != 0) {
+ if ((strcmp(value, "BINARY") != 0) && (strcmp(value, "BIN") != 0)) {
sr_err("Only binary encoding supported.");
return SR_ERR_NA;
}
{
size_t i = 0;
- while (i < buflen && buf[i] != ';')
- ++i;
+ while ((i < buflen) && (buf[i] != ';'))
+ i++;
return i < buflen;
}
value = g_ascii_strtod(str, &endptr);
/* The conversion wasn't performed. */
- if (value == 0 && endptr == str)
+ if ((value == 0) && (endptr == str))
return FALSE;
/* Detect overflow/underflow. */
if ((value == HUGE_VAL || value == DBL_MIN) && errno == ERANGE)
if (*endptr != ';')
return FALSE;
- *result = (float) value;
+ *result = (float)value;
return TRUE;
}
value = g_ascii_strtoll(str, &endptr, 10);
/* The conversion wasn't performed. */
- if (value == 0 && endptr == str)
+ if ((value == 0) && (endptr == str))
return FALSE;
/* Detect overflow/underflow. */
if ((value == LLONG_MIN || value == LLONG_MAX) && errno == ERANGE)
if (*endptr != ';')
return FALSE;
- if (value < 0 || value > UINT_MAX)
+ if ((value < 0) || (value > UINT_MAX))
return FALSE;
- *result = (unsigned int) value;
+ *result = (unsigned int)value;
return TRUE;
}
default:
return SR_ERR_ARG;
}
-
+
return SR_OK;
}
data_section = find_data_section(buf);
if (data_section == NULL)
return SR_ERR_DATA;
- data_section_offset = (size_t) (data_section - buf->str);
+
+ data_section_offset = (size_t)(data_section - buf->str);
/* Search for all header items. */
- for (i = 0; i < HEADER_ITEMS_PARAMETERS; ++i) {
+ for (i = 0; i < HEADER_ITEMS_PARAMETERS; i++) {
pattern = find_item(buf->str, data_section_offset, header_items[i]);
if (pattern == NULL) {
/* Return an error if a mandatory item is not found. */
* Calculate the offset of the header item value in the buffer
* as well as its distance from the data section.
*/
- item_offset = (size_t) (pattern - buf->str);
+ item_offset = (size_t)(pattern - buf->str);
item_offset += strlen(header_items[i]);
if (item_offset >= data_section_offset)
return SR_ERR_DATA;
buf = g_hash_table_lookup(metadata, GINT_TO_POINTER(SR_INPUT_META_HEADER));
/* Check if the header contains NR_PT item. */
- if (buf == NULL || g_strstr_len(buf->str, buf->len, nr_pt) == NULL)
+ if ((buf == NULL) || (g_strstr_len(buf->str, buf->len, nr_pt) == NULL))
return SR_ERR;
/* The header contains NR_PT item, the confidence is high. */
if (fn != NULL) {
fn_len = strlen(fn);
if (fn_len >= strlen(default_extension) &&
- g_ascii_strcasecmp(fn + fn_len - strlen(default_extension), default_extension) == 0) {
+ g_ascii_strcasecmp(fn + fn_len - strlen(default_extension), default_extension) == 0)
*confidence += 10;
- }
}
return SR_OK;
}
if (bytnr > MAX_INT_BYTNR)
return 0;
+
memcpy(data, in->buf->str + offset, bytnr);
value = 0;
if (inc->byte_order == MSB) {
- for (i = 0; i < (int) bytnr; ++i) {
+ for (i = 0; i < (int)bytnr; i++) {
value = value << 8;
value |= data[i];
}
} else {
- for (i = (int) bytnr - 1; i >= 0; --i) {
+ for (i = (int)bytnr - 1; i >= 0; i--) {
value = value << 8;
value |= data[i];
}
}
/* Check if the loaded value is negative. */
- if ((value & (1 << (8*bytnr - 1))) != 0) {
+ if ((value & (1 << (8 * bytnr - 1))) != 0) {
/* Extend the 64-bit integer if the value is negative. */
- i = ~((1 << (8*bytnr - 1)) - 1);
+ i = ~((1 << (8 * bytnr - 1)) - 1);
value |= i;
}
- return (float) value;
+ return (float)value;
}
/*
if (inc->bytnr > MAX_INT_BYTNR)
return 0;
+
memcpy(data, in->buf->str + offset, inc->bytnr);
if (inc->byte_order == MSB) {
- for (i = 0; i < (int) inc->bytnr; ++i) {
+ for (i = 0; i < (int)inc->bytnr; i++) {
value <<= 8;
value |= data[i];
}
} else {
- for (i = (int) inc->bytnr; i >= 0; --i) {
+ for (i = (int)inc->bytnr; i >= 0; i--) {
value <<= 8;
value |= data[i];
}
}
- return (float) value;
+ return (float)value;
}
/*
if (bytnr > FLOAT_BYTNR)
return 0;
+
memcpy(data, in->buf->str + offset, bytnr);
if (inc->byte_order == MSB) {
- for (i = 0; i < (int) bytnr; ++i) {
+ for (i = 0; i < (int)bytnr; i++) {
fp.i = fp.i << 8;
fp.i |= data[i];
}
} else {
- for (i = (int) bytnr - 1; i >= 0; --i) {
+ for (i = (int)bytnr - 1; i >= 0; i--) {
fp.i = fp.i << 8;
fp.i |= data[i];
}
inc = in->priv;
offset = initial_offset;
fdata = g_malloc0(sizeof(float) * num_samples);
- for (i = 0; i < num_samples; ++i) {
+ for (i = 0; i < num_samples; i++) {
if (inc->bn_fmt == RI) {
fdata[i] = (read_int_sample(in, offset) - inc->yoff) * inc->ymult + inc->yzero;
} else if (inc->bn_fmt == RP) {
if (!inc->started) {
std_session_send_df_header(in->sdi);
/* Send samplerate. */
- (void) sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, g_variant_new_uint64((uint64_t) (1 / inc->xincr)));
+ (void) sr_session_send_meta(in->sdi, SR_CONF_SAMPLERATE, g_variant_new_uint64((uint64_t)(1 / inc->xincr)));
inc->started = TRUE;
}
}
offset = data - in->buf->str;
inc->found_data_section = TRUE;
- } else {
+ } else
offset = 0;
- }
/* Slice the buffer data into chunks, send them and clear the buffer. */
processed = 0;
chunk_samples = (in->buf->len - offset) / inc->bytnr;
max_chunk_samples = CHUNK_SIZE / inc->bytnr;
total_samples = chunk_samples;
-
+
while (processed < total_samples) {
if (chunk_samples > max_chunk_samples)
num_samples = max_chunk_samples;
num_samples = chunk_samples;
send_chunk(in, offset, num_samples);
- offset += num_samples * inc->bytnr;
+ offset += (num_samples * inc->bytnr);
chunk_samples -= num_samples;
processed += num_samples;
}