Cosmetics, whitespace, simplifications.

Reduce code nesting a bit, constify some strings.
This commit is contained in:
Uwe Hermann 2011-01-07 19:55:25 +01:00
parent 6239c175c1
commit 757b8c628a
7 changed files with 39 additions and 42 deletions

View File

@ -43,7 +43,8 @@ void device_scan(void)
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);
}
}
@ -66,7 +67,8 @@ GSList *device_list(void)
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;

View File

@ -22,14 +22,12 @@
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;
}

View File

@ -22,22 +22,17 @@
#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;
@ -45,10 +40,10 @@ static int in_loadfile(char *filename)
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);
@ -64,7 +59,7 @@ static int in_loadfile(char *filename)
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);
}
@ -74,15 +69,12 @@ static int in_loadfile(char *filename)
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,
};

View File

@ -67,8 +67,9 @@ static int init(struct output *o)
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;

View File

@ -69,7 +69,6 @@ static void flush_linebufs(struct context *ctx, char *outbuf)
ctx->mark_trigger + (ctx->mark_trigger / 8), "");
memset(ctx->linebuf, 0, i * ctx->linebuf_len);
}
static int init(struct output *o, int default_spl)
@ -89,8 +88,9 @@ 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;
@ -183,11 +183,13 @@ static int data_bits(struct output *o, char *data_in, uint64_t length_in,
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;
@ -205,12 +207,9 @@ static int data_bits(struct output *o, char *data_in, uint64_t length_in,
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++;
@ -255,8 +254,10 @@ static int data_hex(struct output *o, char *data_in, uint64_t length_in,
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;

View File

@ -61,12 +61,15 @@ static int init(struct output *o)
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;

View File

@ -118,8 +118,8 @@ struct input {
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);