]> sigrok.org Git - libsigrok.git/commitdiff
Cosmetics, whitespace, simplifications.
authorUwe Hermann <redacted>
Fri, 7 Jan 2011 18:55:25 +0000 (19:55 +0100)
committerUwe Hermann <redacted>
Sat, 8 Jan 2011 00:49:47 +0000 (01:49 +0100)
Reduce code nesting a bit, constify some strings.

device.c
input/input.c
input/input_binary.c
output/output_gnuplot.c
output/output_text.c
output/output_vcd.c
sigrok.h

index 5290e0eb4ee3d9939c12921324c16bfebfe56d70..1f46573b01f5202e635ede2d14b1a9d447a48a2e 100644 (file)
--- 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;
index bace6f96aa71317e8c7a6e53cd0af32855bc39bc..356de7fe0dfec68688d62bdb2d4fc5793dd3f14f 100644 (file)
 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;
 }
index 27e8fa4d34a5b8d315575dafca51919b1436bb14..113b34f6effeaedbdc7dbe3f411246f5d6191e81 100644 (file)
 #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,
 };
-
index 69a45256c432b4eb3b0bd2891e24a8134e843bd4..5d4c564b1071e646f8f9e7c13875b6247f269ca4 100644 (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;
index 621729b7d25b123ee5f18f01ef9e57bde26c6d0e..79ec794ec0a3cf9df30cab74359c0dd549d6639f 100644 (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;
index d8ce6ef063e9ad53eb068916d8505c9d5f8d0705..eea2f0e5bcd1997ee21b28f86e8f8a8bfe0d0110 100644 (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;
index b34d2b41820a130bd0fea7b67adff4d7abee9199..dd9881a79b58d814e821461968c316cca65b29a5 100644 (file)
--- 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);