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); g_message("initializing %s plugin", plugin->name);
num_devices = plugin->init(NULL); num_devices = plugin->init(NULL);
for (i = 0; i < num_devices; i++) { 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); device_new(plugin, i, num_probes);
} }
} }
@ -66,7 +67,8 @@ GSList *device_list(void)
return devices; 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; struct device *device;
int i; int i;

View File

@ -22,14 +22,12 @@
extern struct input_format input_binary; extern struct input_format input_binary;
struct input_format *input_module_list[] = { 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, &input_binary,
NULL, NULL,
}; };
struct input_format **input_list(void) struct input_format **input_list(void)
{ {
return input_module_list; return input_module_list;
} }

View File

@ -22,22 +22,17 @@
#include <fcntl.h> #include <fcntl.h>
#include <unistd.h> #include <unistd.h>
#include <sys/time.h> #include <sys/time.h>
#include <sigrok.h> #include <sigrok.h>
#define CHUNKSIZE 4096 #define CHUNKSIZE 4096
static int format_match(const char *filename)
static int format_match(char *filename)
{ {
filename = NULL; filename = NULL;
return TRUE; return TRUE;
} }
static int in_loadfile(const char *filename)
static int in_loadfile(char *filename)
{ {
struct datafeed_header header; struct datafeed_header header;
struct datafeed_packet packet; struct datafeed_packet packet;
@ -45,10 +40,10 @@ static int in_loadfile(char *filename)
char buffer[CHUNKSIZE]; char buffer[CHUNKSIZE];
int fd, size, num_probes; int fd, size, num_probes;
if( (fd = open(filename, O_RDONLY)) == -1) if ((fd = open(filename, O_RDONLY)) == -1)
return SIGROK_ERR; return SIGROK_ERR;
/* TODO: number of probes hardcoded to 8 */ /* TODO: Number of probes is hardcoded to 8. */
num_probes = 8; num_probes = 8;
device = device_new(NULL, 0, num_probes); device = device_new(NULL, 0, num_probes);
@ -64,7 +59,7 @@ static int in_loadfile(char *filename)
packet.type = DF_LOGIC8; packet.type = DF_LOGIC8;
packet.payload = buffer; packet.payload = buffer;
while( (size = read(fd, buffer, CHUNKSIZE)) > 0) { while ((size = read(fd, buffer, CHUNKSIZE)) > 0) {
packet.length = size; packet.length = size;
session_bus(device, &packet); session_bus(device, &packet);
} }
@ -74,15 +69,12 @@ static int in_loadfile(char *filename)
packet.length = 0; packet.length = 0;
session_bus(device, &packet); session_bus(device, &packet);
return SIGROK_OK; return SIGROK_OK;
} }
struct input_format input_binary = { struct input_format input_binary = {
"binary", "binary",
"Raw binary", "Raw binary",
format_match, format_match,
in_loadfile in_loadfile,
}; };

View File

@ -67,8 +67,9 @@ static int init(struct output *o)
ctx->num_enabled_probes = 0; ctx->num_enabled_probes = 0;
for (l = o->device->probes; l; l = l->next) { for (l = o->device->probes; l; l = l->next) {
probe = l->data; probe = l->data;
if (probe->enabled) if (!probe->enabled)
ctx->probelist[ctx->num_enabled_probes++] = probe->name; continue;
ctx->probelist[ctx->num_enabled_probes++] = probe->name;
} }
ctx->probelist[ctx->num_enabled_probes] = 0; 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), ""); ctx->mark_trigger + (ctx->mark_trigger / 8), "");
memset(ctx->linebuf, 0, i * ctx->linebuf_len); memset(ctx->linebuf, 0, i * ctx->linebuf_len);
} }
static int init(struct output *o, int default_spl) 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) { for (l = o->device->probes; l; l = l->next) {
probe = l->data; probe = l->data;
if (probe->enabled) if (!probe->enabled)
ctx->probelist[ctx->num_enabled_probes++] = probe->name; continue;
ctx->probelist[ctx->num_enabled_probes++] = probe->name;
} }
ctx->probelist[ctx->num_enabled_probes] = 0; 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; unsigned int outsize, offset, p;
int max_linelen; int max_linelen;
uint64_t sample; uint64_t sample;
char *outbuf; char *outbuf, c;
ctx = o->internal; ctx = o->internal;
max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line + ctx->samples_per_line / 8; max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line
outsize = length_in / ctx->unitsize * ctx->num_enabled_probes / ctx->samples_per_line * max_linelen + 512; + 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))) if (!(outbuf = calloc(1, outsize + 1)))
return SIGROK_ERR_MALLOC; 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) { offset += ctx->unitsize) {
memcpy(&sample, data_in + offset, ctx->unitsize); memcpy(&sample, data_in + offset, ctx->unitsize);
for (p = 0; p < ctx->num_enabled_probes; p++) { for (p = 0; p < ctx->num_enabled_probes; p++) {
if (sample & ((uint64_t) 1 << p)) c = (sample & ((uint64_t) 1 << p)) ? '1' : '0';
ctx->linebuf[p * ctx->linebuf_len + ctx->linebuf[p * ctx->linebuf_len +
ctx->line_offset] = '1'; ctx->line_offset] = c;
else
ctx->linebuf[p * ctx->linebuf_len +
ctx->line_offset] = '0';
} }
ctx->line_offset++; ctx->line_offset++;
ctx->spl_cnt++; ctx->spl_cnt++;
@ -255,8 +254,10 @@ static int data_hex(struct output *o, char *data_in, uint64_t length_in,
char *outbuf; char *outbuf;
ctx = o->internal; ctx = o->internal;
max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line + ctx->samples_per_line / 2; max_linelen = MAX_PROBENAME_LEN + 3 + ctx->samples_per_line
outsize = length_in / ctx->unitsize * ctx->num_enabled_probes / ctx->samples_per_line * max_linelen + 512; + 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))) if (!(outbuf = calloc(1, outsize + 1)))
return SIGROK_ERR_MALLOC; return SIGROK_ERR_MALLOC;

View File

@ -61,12 +61,15 @@ static int init(struct output *o)
if (!(ctx = calloc(1, sizeof(struct context)))) if (!(ctx = calloc(1, sizeof(struct context))))
return SIGROK_ERR_MALLOC; return SIGROK_ERR_MALLOC;
o->internal = ctx; o->internal = ctx;
ctx->num_enabled_probes = 0; ctx->num_enabled_probes = 0;
for (l = o->device->probes; l; l = l->next) { for (l = o->device->probes; l; l = l->next) {
probe = l->data; probe = l->data;
if (probe->enabled) if (!probe->enabled)
ctx->probelist[ctx->num_enabled_probes++] = probe->name; continue;
ctx->probelist[ctx->num_enabled_probes++] = probe->name;
} }
ctx->probelist[ctx->num_enabled_probes] = 0; ctx->probelist[ctx->num_enabled_probes] = 0;

View File

@ -118,8 +118,8 @@ struct input {
struct input_format { struct input_format {
char *extension; char *extension;
char *description; char *description;
int (*format_match) (char *filename); int (*format_match) (const char *filename);
int (*in_loadfile) (char *filename); int (*in_loadfile) (const char *filename);
}; };
struct input_format **input_list(void); struct input_format **input_list(void);