]> sigrok.org Git - libsigrok.git/commitdiff
libsigrok: Coding style fixes.
authorUwe Hermann <redacted>
Thu, 15 Apr 2010 18:07:16 +0000 (20:07 +0200)
committerUwe Hermann <redacted>
Thu, 15 Apr 2010 18:07:16 +0000 (20:07 +0200)
backend.c
datastore.c
debug.c
device.c
sigrok.h

index 6a49cde7c83cf01a253fc409ebc1a0ce55506147..9ce8c5b1ac3c6c1acbbacf63e6e71142696418e3 100644 (file)
--- a/backend.c
+++ b/backend.c
  */
 
 #include <glib.h>
-#include "sigrok.h"
+#include <sigrok.h>
 
 int sigrok_init(void)
 {
-       int ret;
-
-       ret = load_hwplugins();
-
-       return ret;
+       return load_hwplugins();
 }
 
-
 void sigrok_cleanup(void)
 {
-
        device_close_all();
-
 }
-
-
index 683a8abef1f3d7a65b99af5edc2ecb2d1cb8239f..443ab1539d96c0bbf920f8da369488f9905cd684 100644 (file)
 #include <stdint.h>
 #include <string.h>
 #include <glib.h>
-#include "sigrok.h"
+#include <sigrok.h>
 
 static gpointer new_chunk(struct datastore **ds);
 
-
-
 struct datastore *datastore_new(int unitsize)
 {
        struct datastore *ds;
@@ -39,20 +37,18 @@ struct datastore *datastore_new(int unitsize)
        return ds;
 }
 
-
 void datastore_destroy(struct datastore *ds)
 {
        GSList *chunk;
 
-       for(chunk = ds->chunklist; chunk; chunk = chunk->next)
+       for (chunk = ds->chunklist; chunk; chunk = chunk->next)
                g_free(chunk->data);
        g_slist_free(ds->chunklist);
        g_free(ds);
-
 }
 
-
-void datastore_put(struct datastore *ds, void *data, unsigned int length, int in_unitsize, int *probelist)
+void datastore_put(struct datastore *ds, void *data, unsigned int length,
+                  int in_unitsize, int *probelist)
 {
        unsigned int stored;
        int capacity, size, num_chunks, chunk_bytes_free, chunk_offset;
@@ -62,36 +58,37 @@ void datastore_put(struct datastore *ds, void *data, unsigned int length, int in
        in_unitsize = in_unitsize;
        probelist = probelist;
 
-       if(ds->chunklist == NULL)
+       if (ds->chunklist == NULL)
                chunk = new_chunk(&ds);
        else
                chunk = g_slist_last(ds->chunklist)->data;
+
        num_chunks = g_slist_length(ds->chunklist);
        capacity = (num_chunks * DATASTORE_CHUNKSIZE);
        chunk_bytes_free = capacity - (ds->ds_unitsize * ds->num_units);
-       chunk_offset = capacity - (DATASTORE_CHUNKSIZE * (num_chunks - 1)) - chunk_bytes_free;
+       chunk_offset = capacity - (DATASTORE_CHUNKSIZE * (num_chunks - 1))
+                      - chunk_bytes_free;
        stored = 0;
-       while(stored < length) {
-               if(chunk_bytes_free == 0) {
+       while (stored < length) {
+               if (chunk_bytes_free == 0) {
                        chunk = new_chunk(&ds);
                        chunk_bytes_free = DATASTORE_CHUNKSIZE;
                        chunk_offset = 0;
                }
 
-               if(length - stored > (unsigned int)chunk_bytes_free)
+               if (length - stored > (unsigned int)chunk_bytes_free)
                        size = chunk_bytes_free;
                else
-                       /* last part, won't fill up this chunk */
+                       /* Last part, won't fill up this chunk. */
                        size = length - stored;
+
                memcpy(chunk + chunk_offset, data + stored, size);
                chunk_bytes_free -= size;
                stored += size;
        }
        ds->num_units += stored / ds->ds_unitsize;
-
 }
 
-
 static gpointer new_chunk(struct datastore **ds)
 {
        gpointer chunk;
@@ -101,5 +98,3 @@ static gpointer new_chunk(struct datastore **ds)
 
        return chunk;
 }
-
-
diff --git a/debug.c b/debug.c
index 128eb03d6dfdc69b319583286a5231fe791c62f9..4f3215b5459d7c4f50d430edde7a526ed846079a 100644 (file)
--- a/debug.c
+++ b/debug.c
  */
 
 #include <stdio.h>
-#include "sigrok.h"
+#include <sigrok.h>
 
 void hexdump(unsigned char *address, int length)
 {
        int i;
 
-       for(i = 0; i < length; i++)
-       {
-               if((i & 0x0f) == 0)
-               {
-                       if(i)
+       for (i = 0; i < length; i++) {
+               if ((i & 0x0f) == 0) {
+                       if (i)
                                printf("\n");
                        printf("%.4x   ", i);
                }
                printf("%.2x ", address[i]);
        }
        printf("\n");
-
 }
index cef3aac3dd787db6bfc4c482dfb17347f951cd13..0b59621ef08dc8876c24e3997c16d0c232023c0a 100644 (file)
--- a/device.c
+++ b/device.c
 
 #include <stdio.h>
 #include <glib.h>
-#include "sigrok.h"
+#include <sigrok.h>
 
 extern struct sigrok_global *global;
 
 GSList *devices = NULL;
 
-
 void device_scan(void)
 {
        GSList *plugins, *l;
@@ -34,45 +33,36 @@ void device_scan(void)
 
        plugins = list_hwplugins();
 
-       /* initialize all plugins first. Since the init() call may involve
+       /*
+        * Initialize all plugins first. Since the init() call may involve
         * a firmware upload and associated delay, we may as well get all
         * of these out of the way first.
         */
-       for(l = plugins; l; l = l->next)
-       {
+       for (l = plugins; l; l = l->next) {
                plugin = l->data;
                g_message("initializing %s plugin", plugin->name);
                num_devices = plugin->init(NULL);
-               for(i = 0; i < num_devices; i++)
-               {
+               for (i = 0; i < num_devices; i++)
                        device_new(plugin, i);
-               }
        }
-
 }
 
-
 void device_close_all(void)
 {
        struct device *device;
 
-       while(devices)
-       {
+       while (devices) {
                device = devices->data;
                device->plugin->close(device->plugin_index);
                device_destroy(device);
        }
-
 }
 
-
 GSList *device_list(void)
 {
-
        return devices;
 }
 
-
 struct device *device_new(struct device_plugin *plugin, int plugin_index)
 {
        struct device *device;
@@ -84,71 +74,66 @@ struct device *device_new(struct device_plugin *plugin, int plugin_index)
        device->plugin_index = plugin_index;
        devices = g_slist_append(devices, device);
 
-       num_probes = (int) device->plugin->get_device_info(device->plugin_index, DI_NUM_PROBES);
-       for(i = 0; i < num_probes; i++)
-       {
-               snprintf(probename, 16, "%d", i+1);
+       num_probes = (int)device->plugin->get_device_info(device->plugin_index,
+                                                         DI_NUM_PROBES);
+       for (i = 0; i < num_probes; i++) {
+               snprintf(probename, 16, "%d", i + 1);
                device_probe_add(device, probename);
        }
 
        return device;
 }
 
-
 void device_clear(struct device *device)
 {
-       unsigned int probenum;
+       unsigned int pnum;
 
-       /* TODO: plugin-specific clear call? */
+       /* TODO: Plugin-specific clear call? */
 
-       if(device->probes)
-               for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
-                       device_probe_clear(device, probenum);
+       if (!device->probes)
+               return;
 
+       for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++)
+               device_probe_clear(device, pnum);
 }
 
-
 void device_destroy(struct device *device)
 {
-       unsigned int probenum;
+       unsigned int pnum;
 
-       /* TODO: plugin-specific destroy call, need to decrease refcount in plugin */
+       /*
+        * TODO: Plugin-specific destroy call, need to decrease refcount
+        * in plugin.
+        */
 
        devices = g_slist_remove(devices, device);
-       if(device->probes)
-       {
-               for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
-                       device_probe_clear(device, probenum);
+       if (device->probes) {
+               for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++)
+                       device_probe_clear(device, pnum);
                g_slist_free(device->probes);
        }
        g_free(device);
-
 }
 
-
 void device_probe_clear(struct device *device, int probenum)
 {
        struct probe *p;
 
        p = probe_find(device, probenum);
-       if(!p)
+       if (!p)
                return;
 
-       if(p->name)
-       {
+       if (p->name) {
                g_free(p->name);
                p->name = NULL;
        }
 
-       if(p->trigger)
-       {
+       if (p->trigger) {
                g_free(p->trigger);
                p->trigger = NULL;
        }
-
 }
 
-
 void device_probe_add(struct device *device, char *name)
 {
        struct probe *p;
@@ -159,21 +144,17 @@ void device_probe_add(struct device *device, char *name)
        p->name = g_strdup(name);
        p->trigger = NULL;
        device->probes = g_slist_append(device->probes, p);
-
 }
 
-
 struct probe *probe_find(struct device *device, int probenum)
 {
        GSList *l;
        struct probe *p, *found_probe;
 
        found_probe = NULL;
-       for(l = device->probes; l; l = l->next)
-       {
+       for (l = device->probes; l; l = l->next) {
                p = l->data;
-               if(p->index == probenum)
-               {
+               if (p->index == probenum) {
                        found_probe = p;
                        break;
                }
@@ -182,54 +163,46 @@ struct probe *probe_find(struct device *device, int probenum)
        return found_probe;
 }
 
-
 void device_probe_name(struct device *device, int probenum, char *name)
 {
        struct probe *p;
 
        p = probe_find(device, probenum);
-       if(!p)
+       if (!p)
                return;
 
-       if(p->name)
+       if (p->name)
                g_free(p->name);
        p->name = g_strdup(name);
-
 }
 
-
 void device_trigger_clear(struct device *device)
 {
        struct probe *p;
-       unsigned int probenum;
-
-       if(device->probes)
-               for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
-               {
-                       p = probe_find(device, probenum);
-                       if(p && p->trigger)
-                       {
-                               g_free(p->trigger);
-                               p->trigger = NULL;
-                       }
-               }
+       unsigned int pnum;
 
-}
+       if (!device->probes)
+               return;
 
+       for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) {
+               p = probe_find(device, pnum);
+               if (p && p->trigger) {
+                       g_free(p->trigger);
+                       p->trigger = NULL;
+               }
+       }
+}
 
 void device_trigger_set(struct device *device, int probenum, char *trigger)
 {
        struct probe *p;
 
        p = probe_find(device, probenum);
-       if(!p)
+       if (!p)
                return;
 
-       if(p->trigger)
+       if (p->trigger)
                g_free(p->trigger);
 
        p->trigger = g_strdup(trigger);
-
 }
-
-
index 8b2e1265be311520e6d54734d1e9be927f1319e4..170966282e8ea01238fce1fc6f318dec5c3756ff 100644 (file)
--- a/sigrok.h
+++ b/sigrok.h
@@ -76,7 +76,7 @@ struct protocol {
 };
 
 /*
- * datafeed
+ * Datafeed
  */
 
 /* datafeed_packet.type values */
@@ -107,7 +107,7 @@ struct datafeed_header {
 };
 
 /*
- * output
+ * Output
  */
 struct output {
        struct output_format *format;
@@ -217,13 +217,13 @@ void device_trigger_set(struct device *device, int probenum, char *trigger);
 
 /* Hardware plugin capabilities */
 enum {
-       HWCAP_DUMMY,            // used to terminate lists
+       HWCAP_DUMMY,            /* Used to terminate lists */
        HWCAP_LOGIC_ANALYZER,
-       HWCAP_SAMPLERATE,       // change samplerate
-       HWCAP_PROBECONFIG,      // configure probe mask
-       HWCAP_CAPTURE_RATIO,    // set pre-trigger / post-trigger ratio
-       HWCAP_LIMIT_MSEC,       // set a time limit for sample acquisition
-       HWCAP_LIMIT_SAMPLES,    // set a limit on number of samples
+       HWCAP_SAMPLERATE,       /* Change samplerate */
+       HWCAP_PROBECONFIG,      /* Configure probe mask */
+       HWCAP_CAPTURE_RATIO,    /* Set pre-trigger / post-trigger ratio */
+       HWCAP_LIMIT_MSEC,       /* Set a time limit for sample acquisition */
+       HWCAP_LIMIT_SAMPLES,    /* Set a limit on number of samples */
 };
 
 struct hwcap_option {
@@ -293,8 +293,9 @@ enum {
        DI_CUR_SAMPLERATE,
 };
 
-/* a device supports either a range of samplerates with steps of a given
- * granularity, or is limited to a set of defined samplerates. use either
+/*
+ * A device supports either a range of samplerates with steps of a given
+ * granularity, or is limited to a set of defined samplerates. Use either
  * step or list, but not both.
  */
 struct samplerates {
@@ -305,13 +306,13 @@ struct samplerates {
 };
 
 struct device_plugin {
-       /* plugin-specific */
+       /* Plugin-specific */
        char *name;
        int api_version;
        int (*init) (char *deviceinfo);
        void (*cleanup) (void);
 
-       /* device-specific */
+       /* Device-specific */
        int (*open) (int device_index);
        void (*close) (int device_index);
        void *(*get_device_info) (int device_index, int device_info_id);
@@ -337,7 +338,8 @@ GSList *list_hwplugins(void);
 /* Generic device instances */
 struct sigrok_device_instance *sigrok_device_instance_new(int index,
        int status, char *vendor, char *model, char *version);
-struct sigrok_device_instance *get_sigrok_device_instance(GSList *device_instances, int device_index);
+struct sigrok_device_instance *get_sigrok_device_instance(
+                       GSList *device_instances, int device_index);
 void sigrok_device_instance_free(struct sigrok_device_instance *sdi);
 
 /* USB-specific instances */
@@ -352,7 +354,8 @@ void serial_device_instance_free(struct serial_device_instance *serial);
 int find_hwcap(int *capabilities, int hwcap);
 struct hwcap_option *find_hwcap_option(int hwcap);
 void source_remove(int fd);
-void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb, void *user_data);
+void source_add(int fd, int events, int timeout, receive_data_callback rcv_cb,
+               void *user_data);
 
 /*--- session.c -------------------------------------------------------------*/
 
@@ -367,7 +370,7 @@ struct session {
        GSList *devices;
        /* List of struct analyzer* */
        GSList *analyzers;
-       /* datafeed callbacks */
+       /* Datafeed callbacks */
        GSList *datafeed_callbacks;
        GTimeVal starttime;
 };
@@ -406,6 +409,7 @@ int serial_open(const char *pathname, int flags);
 int serial_close(int fd);
 void *serial_backup_params(int fd);
 void serial_restore_params(int fd, void *backup);
-int serial_set_params(int fd, int speed, int bits, int parity, int stopbits, int flowcontrol);
+int serial_set_params(int fd, int speed, int bits, int parity, int stopbits,
+                     int flowcontrol);
 
 #endif