From: Uwe Hermann Date: Fri, 7 Jan 2011 18:55:25 +0000 (+0100) Subject: Cosmetics, whitespace, simplifications. X-Git-Tag: libsigrok-0.1.0~475 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=757b8c628a5b64f8b6b166044b1b3ac1ccf797dc;p=libsigrok.git Cosmetics, whitespace, simplifications. Reduce code nesting a bit, constify some strings. --- diff --git a/device.c b/device.c index 5290e0eb..1f46573b 100644 --- a/device.c +++ b/device.c @@ -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; diff --git a/input/input.c b/input/input.c index bace6f96..356de7fe 100644 --- a/input/input.c +++ b/input/input.c @@ -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; } diff --git a/input/input_binary.c b/input/input_binary.c index 27e8fa4d..113b34f6 100644 --- a/input/input_binary.c +++ b/input/input_binary.c @@ -22,22 +22,17 @@ #include #include #include - #include #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, }; - diff --git a/output/output_gnuplot.c b/output/output_gnuplot.c index 69a45256..5d4c564b 100644 --- a/output/output_gnuplot.c +++ b/output/output_gnuplot.c @@ -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; diff --git a/output/output_text.c b/output/output_text.c index 621729b7..79ec794e 100644 --- a/output/output_text.c +++ b/output/output_text.c @@ -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; diff --git a/output/output_vcd.c b/output/output_vcd.c index d8ce6ef0..eea2f0e5 100644 --- a/output/output_vcd.c +++ b/output/output_vcd.c @@ -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; diff --git a/sigrok.h b/sigrok.h index b34d2b41..dd9881a7 100644 --- a/sigrok.h +++ b/sigrok.h @@ -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);