Reduce code nesting a bit, constify some strings.
g_message("initializing %s plugin", plugin->name);
num_devices = plugin->init(NULL);
for (i = 0; i < num_devices; i++) {
- num_probes = (int)plugin->get_device_info(i, DI_NUM_PROBES);
+ num_probes = (int)plugin->get_device_info(i,
+ DI_NUM_PROBES);
device_new(plugin, i, num_probes);
}
}
return devices;
}
-struct device *device_new(struct device_plugin *plugin, int plugin_index, int num_probes)
+struct device *device_new(struct device_plugin *plugin, int plugin_index,
+ int num_probes)
{
struct device *device;
int i;
extern struct input_format input_binary;
struct input_format *input_module_list[] = {
-
- /* this one has to be last, because it will take any input */
+ /* This one has to be last, because it will take any input. */
&input_binary,
NULL,
};
struct input_format **input_list(void)
{
-
return input_module_list;
}
#include <fcntl.h>
#include <unistd.h>
#include <sys/time.h>
-
#include <sigrok.h>
#define CHUNKSIZE 4096
-
-static int format_match(char *filename)
+static int format_match(const char *filename)
{
-
filename = NULL;
-
return TRUE;
}
-
-static int in_loadfile(char *filename)
+static int in_loadfile(const char *filename)
{
struct datafeed_header header;
struct datafeed_packet packet;
char buffer[CHUNKSIZE];
int fd, size, num_probes;
- if( (fd = open(filename, O_RDONLY)) == -1)
+ if ((fd = open(filename, O_RDONLY)) == -1)
return SIGROK_ERR;
- /* TODO: number of probes hardcoded to 8 */
+ /* TODO: Number of probes is hardcoded to 8. */
num_probes = 8;
device = device_new(NULL, 0, num_probes);
packet.type = DF_LOGIC8;
packet.payload = buffer;
- while( (size = read(fd, buffer, CHUNKSIZE)) > 0) {
+ while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
packet.length = size;
session_bus(device, &packet);
}
packet.length = 0;
session_bus(device, &packet);
-
return SIGROK_OK;
}
-
struct input_format input_binary = {
- "binary",
- "Raw binary",
- format_match,
- in_loadfile
+ "binary",
+ "Raw binary",
+ format_match,
+ in_loadfile,
};
-
ctx->num_enabled_probes = 0;
for (l = o->device->probes; l; l = l->next) {
probe = l->data;
- if (probe->enabled)
- ctx->probelist[ctx->num_enabled_probes++] = probe->name;
+ if (!probe->enabled)
+ continue;
+ ctx->probelist[ctx->num_enabled_probes++] = probe->name;
}
ctx->probelist[ctx->num_enabled_probes] = 0;
ctx->mark_trigger + (ctx->mark_trigger / 8), "");
memset(ctx->linebuf, 0, i * ctx->linebuf_len);
-
}
static int init(struct output *o, int default_spl)
for (l = o->device->probes; l; l = l->next) {
probe = l->data;
- if (probe->enabled)
- ctx->probelist[ctx->num_enabled_probes++] = probe->name;
+ if (!probe->enabled)
+ continue;
+ ctx->probelist[ctx->num_enabled_probes++] = probe->name;
}
ctx->probelist[ctx->num_enabled_probes] = 0;
unsigned int outsize, offset, p;
int max_linelen;
uint64_t sample;
- char *outbuf;
+ char *outbuf, c;
ctx = o->internal;
- max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line + ctx->samples_per_line / 8;
- outsize = length_in / ctx->unitsize * ctx->num_enabled_probes / ctx->samples_per_line * max_linelen + 512;
+ max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line
+ + ctx->samples_per_line / 8;
+ outsize = length_in / ctx->unitsize * ctx->num_enabled_probes
+ / ctx->samples_per_line * max_linelen + 512;
if (!(outbuf = calloc(1, outsize + 1)))
return SIGROK_ERR_MALLOC;
offset += ctx->unitsize) {
memcpy(&sample, data_in + offset, ctx->unitsize);
for (p = 0; p < ctx->num_enabled_probes; p++) {
- if (sample & ((uint64_t) 1 << p))
- ctx->linebuf[p * ctx->linebuf_len +
- ctx->line_offset] = '1';
- else
- ctx->linebuf[p * ctx->linebuf_len +
- ctx->line_offset] = '0';
+ c = (sample & ((uint64_t) 1 << p)) ? '1' : '0';
+ ctx->linebuf[p * ctx->linebuf_len +
+ ctx->line_offset] = c;
}
ctx->line_offset++;
ctx->spl_cnt++;
char *outbuf;
ctx = o->internal;
- max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line + ctx->samples_per_line / 2;
- outsize = length_in / ctx->unitsize * ctx->num_enabled_probes / ctx->samples_per_line * max_linelen + 512;
+ max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line
+ + ctx->samples_per_line / 2;
+ outsize = length_in / ctx->unitsize * ctx->num_enabled_probes
+ / ctx->samples_per_line * max_linelen + 512;
if (!(outbuf = calloc(1, outsize + 1)))
return SIGROK_ERR_MALLOC;
if (!(ctx = calloc(1, sizeof(struct context))))
return SIGROK_ERR_MALLOC;
+
o->internal = ctx;
ctx->num_enabled_probes = 0;
+
for (l = o->device->probes; l; l = l->next) {
probe = l->data;
- if (probe->enabled)
- ctx->probelist[ctx->num_enabled_probes++] = probe->name;
+ if (!probe->enabled)
+ continue;
+ ctx->probelist[ctx->num_enabled_probes++] = probe->name;
}
ctx->probelist[ctx->num_enabled_probes] = 0;
struct input_format {
char *extension;
char *description;
- int (*format_match) (char *filename);
- int (*in_loadfile) (char *filename);
+ int (*format_match) (const char *filename);
+ int (*in_loadfile) (const char *filename);
};
struct input_format **input_list(void);