]> sigrok.org Git - libsigrokdecode.git/commitdiff
srd: Cosmetics, whitespace, coding-style fixes.
authorUwe Hermann <redacted>
Wed, 8 Feb 2012 21:39:30 +0000 (22:39 +0100)
committerUwe Hermann <redacted>
Fri, 10 Feb 2012 08:30:40 +0000 (09:30 +0100)
controller.c
decoder.c
exception.c
module_sigrokdecode.c
sigrokdecode.h
type_decoder.c
type_logic.c
util.c

index d5bab5bc032562f07ae66262b680886480c295a5..15001ed25b464c3173d71a0a97e349750beca147 100644 (file)
 #include <inttypes.h>
 #include <stdlib.h>
 
-
 /* List of decoder instances. */
 static GSList *di_list = NULL;
 
 /* List of frontend callbacks to receive PD output. */
 static GSList *callbacks = NULL;
 
-/* lives in decoder.c */
+/* decoder.c */
 extern GSList *pd_list;
 
-/* lives in module_sigrokdecode.c */
+/* module_sigrokdecode.c */
 extern PyMODINIT_FUNC PyInit_sigrokdecode(void);
 
-/* lives in type_logic.c */
+/* type_logic.c */
 extern PyTypeObject srd_logic_type;
 
-
 /**
  * Initialize libsigrokdecode.
  *
@@ -89,7 +87,6 @@ int srd_init(void)
        return SRD_OK;
 }
 
-
 /**
  * Shutdown libsigrokdecode.
  *
@@ -104,7 +101,6 @@ int srd_init(void)
  */
 int srd_exit(void)
 {
-
        srd_dbg("Exiting libsigrokdecode.");
 
        srd_unload_all_decoders();
@@ -116,7 +112,6 @@ int srd_exit(void)
        return SRD_OK;
 }
 
-
 /**
  * Add an additional search directory for the protocol decoders.
  *
@@ -163,7 +158,6 @@ int set_modulepath(void)
        return ret;
 }
 
-
 /**
  * Set options in a decoder instance.
  *
@@ -175,7 +169,7 @@ int set_modulepath(void)
  * @return SRD_OK upon success, a (negative) error code otherwise.
  */
 int srd_instance_set_options(struct srd_decoder_instance *di,
-               GHashTable *options)
+                            GHashTable * options)
 {
        PyObject *py_dec_options, *py_dec_optkeys, *py_di_options, *py_optval;
        PyObject *py_optlist, *py_classval;
@@ -184,7 +178,7 @@ int srd_instance_set_options(struct srd_decoder_instance *di,
        int num_optkeys, ret, size, i;
        char *key, *value;
 
-       if(!PyObject_HasAttrString(di->decoder->py_dec, "options")) {
+       if (!PyObject_HasAttrString(di->decoder->py_dec, "options")) {
                /* Decoder has no options. */
                if (g_hash_table_size(options) == 0) {
                        /* No options provided. */
@@ -215,7 +209,8 @@ int srd_instance_set_options(struct srd_decoder_instance *di,
                if (!(py_classval = PyList_GetItem(py_optlist, 1)))
                        goto err_out;
                if (!PyUnicode_Check(py_classval) && !PyLong_Check(py_classval)) {
-                       srd_err("Options of type %s are not yet supported.", Py_TYPE(py_classval)->tp_name);
+                       srd_err("Options of type %s are not yet supported.",
+                               Py_TYPE(py_classval)->tp_name);
                        goto err_out;
                }
 
@@ -231,8 +226,9 @@ int srd_instance_set_options(struct srd_decoder_instance *di,
                                if (!(py_optval = PyLong_FromString(value, NULL, 0))) {
                                        /* ValueError Exception */
                                        PyErr_Clear();
-                                       srd_err("Option %s has invalid value %s: expected integer.",
-                                                       key, value);
+                                       srd_err("Option %s has invalid value "
+                                               "%s: expected integer.",
+                                               key, value);
                                        goto err_out;
                                }
                        }
@@ -250,7 +246,8 @@ int srd_instance_set_options(struct srd_decoder_instance *di,
                                if (val_ull == (unsigned long long)-1) {
                                        /* OverFlowError exception */
                                        PyErr_Clear();
-                                       srd_err("Invalid integer value for %s: expected integer.", key);
+                                       srd_err("Invalid integer value for %s: "
+                                               "expected integer.", key);
                                        goto err_out;
                                }
                                if (!(py_optval = PyLong_FromUnsignedLongLong(val_ull)))
@@ -282,7 +279,6 @@ err_out:
 /* Helper GComparefunc for g_slist_find_custom() in srd_instance_set_probes() */
 static gint compare_probe_id(struct srd_probe *a, char *probe_id)
 {
-
        return strcmp(a->id, probe_id);
 }
 
@@ -291,13 +287,12 @@ static gint compare_probe_id(struct srd_probe *a, char *probe_id)
  *
  * @param di Decoder instance.
  * @param probes A GHashTable of probes to set. Key is probe name, value is
- * the probe number. Samples passed to this instance will be arranged in this
- * order.
- *
+ *               the probe number. Samples passed to this instance will be
+ *               arranged in this order.
  * @return SRD_OK upon success, a (negative) error code otherwise.
  */
 int srd_instance_set_probes(struct srd_decoder_instance *di,
-               GHashTable *new_probes)
+                           GHashTable * new_probes)
 {
        GList *l;
        GSList *sl;
@@ -306,16 +301,16 @@ int srd_instance_set_probes(struct srd_decoder_instance *di,
        char *probe_id, *probenum_str;
 
        srd_dbg("set probes called for instance %s with list of %d probes",
-                       di->instance_id, g_hash_table_size(new_probes));
+               di->instance_id, g_hash_table_size(new_probes));
 
        if (g_hash_table_size(new_probes) == 0)
                /* No probes provided. */
                return SRD_OK;
 
-       if(di->dec_num_probes == 0) {
+       if (di->dec_num_probes == 0) {
                /* Decoder has no probes. */
                srd_err("Protocol decoder %s has no probes to define.",
-                               di->decoder->name);
+                       di->decoder->name);
                return SRD_ERR_ARG;
        }
 
@@ -331,7 +326,8 @@ int srd_instance_set_probes(struct srd_decoder_instance *di,
                probenum_str = g_hash_table_lookup(new_probes, probe_id);
                if (!probenum_str) {
                        /* Probe name was specified without a value. */
-                       srd_err("No probe number was specified for %s.", probe_id);
+                       srd_err("No probe number was specified for %s.",
+                               probe_id);
                        g_free(new_probemap);
                        return SRD_ERR_ARG;
                }
@@ -340,16 +336,17 @@ int srd_instance_set_probes(struct srd_decoder_instance *di,
                                (GCompareFunc)compare_probe_id))) {
                        /* Fall back on optional probes. */
                        if (!(sl = g_slist_find_custom(di->decoder->opt_probes,
-                                       probe_id, (GCompareFunc)compare_probe_id))) {
-                               srd_err("Protocol decoder %s has no probe '%s'.",
-                                               di->decoder->name, probe_id);
+                            probe_id, (GCompareFunc) compare_probe_id))) {
+                               srd_err("Protocol decoder %s has no probe "
+                                       "'%s'.", di->decoder->name, probe_id);
                                g_free(new_probemap);
                                return SRD_ERR_ARG;
                        }
                }
                p = sl->data;
                new_probemap[p->order] = new_probenum;
-               srd_dbg("setting probe mapping for %d = probe %d", p->order, new_probenum);
+               srd_dbg("setting probe mapping for %d = probe %d", p->order,
+                       new_probenum);
        }
        g_free(di->dec_probemap);
        di->dec_probemap = new_probemap;
@@ -362,16 +359,16 @@ int srd_instance_set_probes(struct srd_decoder_instance *di,
  *
  * @param id Decoder 'id' field.
  * @param options GHashtable of options which override the defaults set in
- *         the decoder class.
+ *                the decoder class.
  * @return Pointer to a newly allocated struct srd_decoder_instance, or
- *             NULL in case of failure.
+ *         NULL in case of failure.
  */
 struct srd_decoder_instance *srd_instance_new(const char *decoder_id,
-               GHashTable *options)
+                                             GHashTable *options)
 {
+       int i;
        struct srd_decoder *dec;
        struct srd_decoder_instance *di;
-       int i;
        char *instance_id;
 
        srd_dbg("Creating new %s instance.", decoder_id);
@@ -395,9 +392,10 @@ struct srd_decoder_instance *srd_instance_new(const char *decoder_id,
         * order in which the decoder class defined them.
         */
        di->dec_num_probes = g_slist_length(di->decoder->probes) +
-                       g_slist_length(di->decoder->opt_probes);
+                            g_slist_length(di->decoder->opt_probes);
        if (di->dec_num_probes) {
-               if (!(di->dec_probemap = g_try_malloc(sizeof(int) * di->dec_num_probes))) {
+               if (!(di->dec_probemap =
+                    g_try_malloc(sizeof(int) * di->dec_num_probes))) {
                        srd_err("Failed to malloc probe map.");
                        g_free(di);
                        return NULL;
@@ -409,7 +407,8 @@ struct srd_decoder_instance *srd_instance_new(const char *decoder_id,
        /* Create a new instance of this decoder class. */
        if (!(di->py_instance = PyObject_CallObject(dec->py_dec, NULL))) {
                if (PyErr_Occurred())
-                       catch_exception("failed to create %s instance: ", decoder_id);
+                       catch_exception("failed to create %s instance: ",
+                                       decoder_id);
                g_free(di->dec_probemap);
                g_free(di);
                return NULL;
@@ -428,9 +427,8 @@ struct srd_decoder_instance *srd_instance_new(const char *decoder_id,
 }
 
 int srd_instance_stack(struct srd_decoder_instance *di_from,
-               struct srd_decoder_instance *di_to)
+                      struct srd_decoder_instance *di_to)
 {
-
        if (!di_from || !di_to) {
                srd_err("Invalid from/to instance pair.");
                return SRD_ERR_ARG;
@@ -486,7 +484,7 @@ struct srd_decoder_instance *srd_instance_find_by_id(char *instance_id)
  * @return Pointer to struct srd_decoder_instance, or NULL if not found.
  */
 struct srd_decoder_instance *srd_instance_find_by_obj(GSList *stack,
-               PyObject *obj)
+                                                     PyObject *obj)
 {
        GSList *l;
        struct srd_decoder_instance *tmp, *di;
@@ -514,13 +512,15 @@ int srd_instance_start(struct srd_decoder_instance *di, PyObject *args)
 
        if (!(py_name = PyUnicode_FromString("start"))) {
                srd_err("Unable to build python object for 'start'.");
-               catch_exception("Protocol decoder instance %s: ", di->instance_id);
+               catch_exception("Protocol decoder instance %s: ",
+                               di->instance_id);
                return SRD_ERR_PYTHON;
        }
 
        if (!(py_res = PyObject_CallMethodObjArgs(di->py_instance,
-                       py_name, args, NULL))) {
-               catch_exception("Protocol decoder instance %s: ", di->instance_id);
+                                                 py_name, args, NULL))) {
+               catch_exception("Protocol decoder instance %s: ",
+                               di->instance_id);
                return SRD_ERR_PYTHON;
        }
 
@@ -551,7 +551,8 @@ int srd_instance_start(struct srd_decoder_instance *di, PyObject *args)
  * @return SRD_OK upon success, a (negative) error code otherwise.
  */
 int srd_instance_decode(uint64_t start_samplenum,
-       struct srd_decoder_instance *di, uint8_t *inbuf, uint64_t inbuflen)
+                       struct srd_decoder_instance *di, uint8_t *inbuf,
+                       uint64_t inbuflen)
 {
        PyObject *py_res;
        srd_logic *logic;
@@ -590,8 +591,10 @@ int srd_instance_decode(uint64_t start_samplenum,
        Py_IncRef(di->py_instance);
        end_samplenum = start_samplenum + inbuflen / di->data_unitsize;
        if (!(py_res = PyObject_CallMethod(di->py_instance, "decode",
-                       "KKO", logic->start_samplenum, end_samplenum, logic))) {
-               catch_exception("Protocol decoder instance %s: ", di->instance_id);
+                                          "KKO", logic->start_samplenum,
+                                          end_samplenum, logic))) {
+               catch_exception("Protocol decoder instance %s: ",
+                               di->instance_id);
                return SRD_ERR_PYTHON; /* TODO: More specific error? */
        }
        Py_DecRef(py_res);
@@ -616,7 +619,6 @@ void srd_instance_free(struct srd_decoder_instance *di)
                g_free(pdo);
        }
        g_slist_free(di->pd_output);
-
 }
 
 void srd_instance_free_all(GSList *stack)
@@ -635,7 +637,6 @@ void srd_instance_free_all(GSList *stack)
                g_slist_free(di_list);
                di_list = NULL;
        }
-
 }
 
 int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
@@ -672,18 +673,19 @@ int srd_session_start(int num_probes, int unitsize, uint64_t samplerate)
 }
 
 /* Feed logic samples to decoder session. */
-int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf, uint64_t inbuflen)
+int srd_session_feed(uint64_t start_samplenum, uint8_t * inbuf,
+                    uint64_t inbuflen)
 {
        GSList *d;
        int ret;
 
        srd_dbg("Calling decode() on all instances with starting sample "
-               "number %"PRIu64", %"PRIu64" bytes at 0x%p", start_samplenum,
-               inbuflen, inbuf);
+               "number %" PRIu64 ", %" PRIu64 " bytes at 0x%p",
+               start_samplenum, inbuflen, inbuf);
 
        for (d = di_list; d; d = d->next) {
                if ((ret = srd_instance_decode(start_samplenum, d->data, inbuf,
-                               inbuflen)) != SRD_OK)
+                                              inbuflen)) != SRD_OK)
                        return ret;
        }
 
@@ -724,7 +726,6 @@ void *srd_find_callback(int output_type)
        return cb;
 }
 
-
 /* This is the backend function to python sigrokdecode.add() call. */
 int pd_add(struct srd_decoder_instance *di, int output_type, char *proto_id)
 {
@@ -745,4 +746,3 @@ int pd_add(struct srd_decoder_instance *di, int output_type, char *proto_id)
 
        return pdo->pdo_id;
 }
-
index 6f4a88dbeb740e05d99d6677c15d3c970fd7385a..e039e377655382b2d9fdb0b9fcbf3fc028be0b03 100644 (file)
--- a/decoder.c
+++ b/decoder.c
 /* The list of protocol decoders. */
 GSList *pd_list = NULL;
 
-/* lives in module_sigrokdecode.c */
+/* module_sigrokdecode.c */
 extern PyObject *mod_sigrokdecode;
 
-
 /**
  * Returns the list of supported/loaded protocol decoders.
  *
@@ -39,11 +38,9 @@ extern PyObject *mod_sigrokdecode;
  */
 GSList *srd_list_decoders(void)
 {
-
        return pd_list;
 }
 
-
 /**
  * Get the decoder with the specified ID.
  *
@@ -64,7 +61,6 @@ struct srd_decoder *srd_get_decoder_by_id(const char *id)
        return NULL;
 }
 
-
 static int get_probes(struct srd_decoder *d, char *attr, GSList **pl)
 {
        PyObject *py_probelist, *py_entry;
@@ -81,7 +77,7 @@ static int get_probes(struct srd_decoder *d, char *attr, GSList **pl)
        py_probelist = PyObject_GetAttrString(d->py_dec, attr);
        if (!PyList_Check(py_probelist)) {
                srd_err("Protocol decoder %s %s attribute is not "
-                               "a list.", d->name, attr);
+                       "a list.", d->name, attr);
                goto err_out;
        }
 
@@ -94,7 +90,7 @@ static int get_probes(struct srd_decoder *d, char *attr, GSList **pl)
                py_entry = PyList_GetItem(py_probelist, i);
                if (!PyDict_Check(py_entry)) {
                        srd_err("Protocol decoder %s %s attribute is not "
-                                       "a list with dict elements.", d->name, attr);
+                               "a list with dict elements.", d->name, attr);
                        goto err_out;
                }
 
@@ -170,7 +166,7 @@ int srd_load_decoder(const char *name, struct srd_decoder **dec)
 
        if (!PyObject_IsSubclass(d->py_dec, py_basedec)) {
                srd_err("Decoder class in protocol decoder module %s is not "
-                               "a subclass of sigrokdecode.Decoder.", name);
+                       "a subclass of sigrokdecode.Decoder.", name);
                goto err_out;
        }
        Py_CLEAR(py_basedec);
@@ -178,13 +174,13 @@ int srd_load_decoder(const char *name, struct srd_decoder **dec)
        /* Check for a proper start() method. */
        if (!PyObject_HasAttrString(d->py_dec, "start")) {
                srd_err("Protocol decoder %s has no start() method Decoder "
-                               "class.", name);
+                       "class.", name);
                goto err_out;
        }
        py_method = PyObject_GetAttrString(d->py_dec, "start");
        if (!PyFunction_Check(py_method)) {
                srd_err("Protocol decoder %s Decoder class attribute 'start' "
-                               "is not a method.", name);
+                       "is not a method.", name);
                goto err_out;
        }
        Py_CLEAR(py_method);
@@ -192,13 +188,13 @@ int srd_load_decoder(const char *name, struct srd_decoder **dec)
        /* Check for a proper decode() method. */
        if (!PyObject_HasAttrString(d->py_dec, "decode")) {
                srd_err("Protocol decoder %s has no decode() method Decoder "
-                               "class.", name);
+                       "class.", name);
                goto err_out;
        }
        py_method = PyObject_GetAttrString(d->py_dec, "decode");
        if (!PyFunction_Check(py_method)) {
                srd_err("Protocol decoder %s Decoder class attribute 'decode' "
-                               "is not a method.", name);
+                       "is not a method.", name);
                goto err_out;
        }
        Py_CLEAR(py_method);
@@ -208,7 +204,7 @@ int srd_load_decoder(const char *name, struct srd_decoder **dec)
                py_attr = PyObject_GetAttrString(d->py_dec, "options");
                if (!PyDict_Check(py_attr)) {
                        srd_err("Protocol decoder %s options attribute is not "
-                                       "a dictionary.", d->name);
+                               "a dictionary.", d->name);
                        Py_DecRef(py_attr);
                        goto err_out;
                }
@@ -248,15 +244,17 @@ int srd_load_decoder(const char *name, struct srd_decoder **dec)
        if (PyObject_HasAttrString(d->py_dec, "annotations")) {
                py_annlist = PyObject_GetAttrString(d->py_dec, "annotations");
                if (!PyList_Check(py_annlist)) {
-                       srd_err("Protocol decoder module %s annotations should be a list.", name);
+                       srd_err("Protocol decoder module %s annotations "
+                               "should be a list.", name);
                        goto err_out;
                }
                alen = PyList_Size(py_annlist);
                for (i = 0; i < alen; i++) {
                        py_ann = PyList_GetItem(py_annlist, i);
                        if (!PyList_Check(py_ann) || PyList_Size(py_ann) != 2) {
-                               srd_err("Protocol decoder module %s annotation %d should "
-                                               "be a list with two elements.", name, i+1);
+                               srd_err("Protocol decoder module %s "
+                                       "annotation %d should be a list with "
+                                       "two elements.", name, i + 1);
                                goto err_out;
                        }
 
@@ -303,7 +301,6 @@ char *srd_decoder_doc(struct srd_decoder *dec)
        return doc;
 }
 
-
 static void free_probes(GSList *probelist)
 {
        GSList *l;
@@ -407,6 +404,3 @@ int srd_unload_all_decoders(void)
 
        return SRD_OK;
 }
-
-
-
index aa7ab616d58df4a949e8cf0c814ca06118c9a73a..a67600fa4f50a87eaba3667bcdb7e4b004040627 100644 (file)
@@ -24,7 +24,6 @@
 #include <glib.h>
 #include <frameobject.h> /* Python header not pulled in by default. */
 
-
 void catch_exception(const char *format, ...)
 {
        PyObject *etype, *evalue, *etb, *py_str;
@@ -70,8 +69,9 @@ void catch_exception(const char *format, ...)
                tracestr = NULL;
                py_tb = (PyTracebackObject *) etb;
                py_str = PyUnicode_FromFormat("%U:%d in %U",
-                               py_tb->tb_frame->f_code->co_filename, py_tb->tb_frame->f_lineno,
-                               py_tb->tb_frame->f_code->co_name);
+                                       py_tb->tb_frame->f_code->co_filename,
+                                       py_tb->tb_frame->f_lineno,
+                                       py_tb->tb_frame->f_code->co_name);
                py_str_as_str(py_str, &tracestr);
                Py_DecRef(py_str);
                g_string_printf(msg, "%s in %s: %s", ename, tracestr, str);
@@ -87,8 +87,4 @@ void catch_exception(const char *format, ...)
 
        /* Just in case. */
        PyErr_Clear();
-
-       return;
 }
-
-
index 30ea6471615b900a443bf0223adb18c584aca878..0992ea20fdee0a25d3442b7a48dfc0709a21e1bd 100644 (file)
 #include "sigrokdecode-internal.h"
 #include "config.h"
 
-
-/* lives in type_decoder.c */
+/* type_decoder.c */
 extern PyTypeObject srd_Decoder_type;
 
-/* lives in type_logic.c */
+/* type_logic.c */
 extern PyTypeObject srd_logic_type;
 
-
-/* When initialized, a reference to this module inside the python interpreter
+/*
+ * When initialized, a reference to this module inside the python interpreter
  * lives here.
  */
 PyObject *mod_sigrokdecode = NULL;
@@ -41,7 +40,6 @@ static struct PyModuleDef sigrokdecode_module = {
        .m_size = -1,
 };
 
-
 PyMODINIT_FUNC PyInit_sigrokdecode(void)
 {
        PyObject *mod;
@@ -57,22 +55,25 @@ PyMODINIT_FUNC PyInit_sigrokdecode(void)
 
        mod = PyModule_Create(&sigrokdecode_module);
        Py_INCREF(&srd_Decoder_type);
-       if (PyModule_AddObject(mod, "Decoder", (PyObject *)&srd_Decoder_type) == -1)
+       if (PyModule_AddObject(mod, "Decoder",
+           (PyObject *)&srd_Decoder_type) == -1)
                return NULL;
        Py_INCREF(&srd_logic_type);
-       if (PyModule_AddObject(mod, "srd_logic", (PyObject *)&srd_logic_type) == -1)
+       if (PyModule_AddObject(mod, "srd_logic",
+           (PyObject *)&srd_logic_type) == -1)
                return NULL;
 
        /* expose output types as symbols in the sigrokdecode module */
-       if(PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1)
+       if (PyModule_AddIntConstant(mod, "OUTPUT_ANN", SRD_OUTPUT_ANN) == -1)
                return NULL;
-       if(PyModule_AddIntConstant(mod, "OUTPUT_PROTO", SRD_OUTPUT_PROTO) == -1)
+       if (PyModule_AddIntConstant(mod, "OUTPUT_PROTO",
+           SRD_OUTPUT_PROTO) == -1)
                return NULL;
-       if(PyModule_AddIntConstant(mod, "OUTPUT_BINARY", SRD_OUTPUT_BINARY) == -1)
+       if (PyModule_AddIntConstant(mod, "OUTPUT_BINARY",
+           SRD_OUTPUT_BINARY) == -1)
                return NULL;
 
        mod_sigrokdecode = mod;
 
        return mod;
 }
-
index a7ea910bb5aa7c28ae972bbdc8d137496d4ada25..51efcc6ebf2b9a6b8b1148c7dd1635876974c30e 100644 (file)
@@ -63,15 +63,16 @@ extern "C" {
 #define SRD_LOG_DBG    4 /**< Output debug messages. */
 #define SRD_LOG_SPEW   5 /**< Output very noisy debug messages. */
 
+/*
+ * When adding an output type, don't forget to...
+ *   - expose it to PDs in controller.c:PyInit_sigrokdecode()
+ *   - add a check in module_sigrokdecode.c:Decoder_put()
+ *   - add a debug string in type_decoder.c:OUTPUT_TYPES
+ */
 enum {
        SRD_OUTPUT_ANN,
        SRD_OUTPUT_PROTO,
        SRD_OUTPUT_BINARY,
-       /* When adding an output type, don't forget to...
-        *        - expose it to PDs in controller.c:PyInit_sigrokdecode()
-        *        - add a check in module_sigrokdecode.c:Decoder_put()
-        *    - add a debug string in type_decoder.c:OUTPUT_TYPES
-        */
 };
 
 #define SRD_MAX_NUM_PROBES   64
@@ -105,7 +106,8 @@ struct srd_decoder {
        /** Optional probes */
        GSList *opt_probes;
 
-       /* List of NULL-terminated char[], containing descriptions of the
+       /*
+        * List of NULL-terminated char[], containing descriptions of the
         * supported annotation output.
         */
        GSList *annotations;
@@ -157,7 +159,6 @@ struct srd_pd_callback {
        void (*callback)(struct srd_proto_data *);
 };
 
-
 /* custom python types */
 typedef struct {
        PyObject_HEAD
@@ -173,29 +174,31 @@ typedef struct {
        PyObject *sample;
 } srd_logic;
 
-
 /*--- controller.c ----------------------------------------------------------*/
+
 int srd_init(void);
 int srd_exit(void);
 int set_modulepath(void);
 int srd_instance_set_options(struct srd_decoder_instance *di,
-               GHashTable *options);
+                            GHashTable *options);
 int srd_instance_set_probes(struct srd_decoder_instance *di,
-               GHashTable *probes);
+                           GHashTable *probes);
 struct srd_decoder_instance *srd_instance_new(const char *id,
-               GHashTable *options);
+                                             GHashTable *options);
 int srd_instance_stack(struct srd_decoder_instance *di_from,
-               struct srd_decoder_instance *di_to);
+                      struct srd_decoder_instance *di_to);
 struct srd_decoder_instance *srd_instance_find_by_id(char *instance_id);
 struct srd_decoder_instance *srd_instance_find_by_obj(GSList *stack,
-               PyObject *obj);
+                                                     PyObject *obj);
 int srd_instance_start(struct srd_decoder_instance *di, PyObject *args);
 int srd_instance_decode(uint64_t start_samplenum,
-               struct srd_decoder_instance *dec, uint8_t *inbuf, uint64_t inbuflen);
+                       struct srd_decoder_instance *dec,
+                       uint8_t *inbuf, uint64_t inbuflen);
 void srd_instance_free(struct srd_decoder_instance *di);
 void srd_instance_free_all(GSList *stack);
 int srd_session_start(int num_probes, int unitsize, uint64_t samplerate);
-int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf, uint64_t inbuflen);
+int srd_session_feed(uint64_t start_samplenum, uint8_t *inbuf,
+                    uint64_t inbuflen);
 int pd_add(struct srd_decoder_instance *di, int output_type, char *output_id);
 struct srd_decoder_instance *get_di_by_decobject(void *decobject);
 typedef void (*srd_pd_output_callback_t)(struct srd_proto_data *pdata);
@@ -203,6 +206,7 @@ int srd_register_callback(int output_type, srd_pd_output_callback_t cb);
 void *srd_find_callback(int output_type);
 
 /*--- decoder.c -------------------------------------------------------------*/
+
 GSList *srd_list_decoders(void);
 struct srd_decoder *srd_get_decoder_by_id(const char *id);
 int srd_load_decoder(const char *name, struct srd_decoder **dec);
@@ -212,17 +216,21 @@ int srd_unload_all_decoders(void);
 char *srd_decoder_doc(struct srd_decoder *dec);
 
 /*--- exception.c -----------------------------------------------------------*/
+
 void catch_exception(const char *format, ...);
 
 /*--- util.c ----------------------------------------------------------------*/
+
 int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr);
 int py_dictitem_as_str(PyObject *py_obj, const char *key, char **outstr);
 int py_str_as_str(PyObject *py_str, char **outstr);
 int py_strlist_to_char(PyObject *py_strlist, char ***outstr);
 
 /*--- log.c -----------------------------------------------------------------*/
+
 typedef int (*srd_log_handler_t)(void *data, int loglevel, const char *format,
                                 va_list args);
+
 int srd_log_loglevel_set(int loglevel);
 int srd_log_loglevel_get(void);
 int srd_log_handler_set(srd_log_handler_t handler, void *data);
index 8395edd4d21671be3127ad2c5232c4a440b543f6..39ea3b79684f5b47bbb53f4044a7544b198c212b 100644 (file)
@@ -22,7 +22,6 @@
 #include "config.h"
 #include <inttypes.h>
 
-
 /* This is only used for nicer srd_dbg() output. */
 char *OUTPUT_TYPES[] = {
        "OUTPUT_ANN",
@@ -30,9 +29,8 @@ char *OUTPUT_TYPES[] = {
        "OUTPUT_BINARY",
 };
 
-
 static int convert_pyobj(struct srd_decoder_instance *di, PyObject *obj,
-               int *ann_format, char ***ann)
+                        int *ann_format, char ***ann)
 {
        PyObject *py_tmp;
        struct srd_pd_output *pdo;
@@ -41,30 +39,33 @@ static int convert_pyobj(struct srd_decoder_instance *di, PyObject *obj,
        /* Should be a list of [annotation format, [string, ...]] */
        if (!PyList_Check(obj) && !PyTuple_Check(obj)) {
                srd_err("Protocol decoder %s submitted %s instead of list.",
-                               di->decoder->name, obj->ob_type->tp_name);
+                       di->decoder->name, obj->ob_type->tp_name);
                return SRD_ERR_PYTHON;
        }
 
        /* Should have 2 elements... */
        if (PyList_Size(obj) != 2) {
-               srd_err("Protocol decoder %s submitted annotation list with %d elements "
-                               "instead of 2", di->decoder->name, PyList_Size(obj));
+               srd_err("Protocol decoder %s submitted annotation list with "
+                       "%d elements instead of 2", di->decoder->name,
+                       PyList_Size(obj));
                return SRD_ERR_PYTHON;
        }
 
-       /* First element should be an integer matching a previously
-        * registered annotation format. */
+       /*
+        * The first element should be an integer matching a previously
+        * registered annotation format.
+        */
        py_tmp = PyList_GetItem(obj, 0);
        if (!PyLong_Check(py_tmp)) {
-               srd_err("Protocol decoder %s submitted annotation list, but first "
-                               "element was not an integer.", di->decoder->name);
+               srd_err("Protocol decoder %s submitted annotation list, but "
+                       "first element was not an integer.", di->decoder->name);
                return SRD_ERR_PYTHON;
        }
 
        ann_id = PyLong_AsLong(py_tmp);
        if (!(pdo = g_slist_nth_data(di->decoder->annotations, ann_id))) {
                srd_err("Protocol decoder %s submitted data to unregistered "
-                               "annotation format %d.", di->decoder->name, ann_id);
+                       "annotation format %d.", di->decoder->name, ann_id);
                return SRD_ERR_PYTHON;
        }
        *ann_format = ann_id;
@@ -73,12 +74,12 @@ static int convert_pyobj(struct srd_decoder_instance *di, PyObject *obj,
        py_tmp = PyList_GetItem(obj, 1);
        if (!PyList_Check(py_tmp)) {
                srd_err("Protocol decoder %s submitted annotation list, but "
-                               "second element was not a list.", di->decoder->name);
+                       "second element was not a list.", di->decoder->name);
                return SRD_ERR_PYTHON;
        }
        if (py_strlist_to_char(py_tmp, ann) != SRD_OK) {
                srd_err("Protocol decoder %s submitted annotation list, but "
-                               "second element was malformed.", di->decoder->name);
+                       "second element was malformed.", di->decoder->name);
                return SRD_ERR_PYTHON;
        }
 
@@ -102,15 +103,19 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
                return NULL;
        }
 
-       if (!PyArg_ParseTuple(args, "KKiO", &start_sample, &end_sample, &output_id, &data))
-               /* This throws an exception, but by returning NULL here we let python
-                * raise it. This results in a much better trace in controller.c
-                * on the decode() method call. */
+       if (!PyArg_ParseTuple(args, "KKiO", &start_sample, &end_sample,
+           &output_id, &data)) {
+               /*
+                * This throws an exception, but by returning NULL here we let
+                * Python raise it. This results in a much better trace in
+                * controller.c on the decode() method call.
+                */
                return NULL;
+       }
 
        if (!(l = g_slist_nth(di->pd_output, output_id))) {
                srd_err("Protocol decoder %s submitted invalid output ID %d.",
-                               di->decoder->name, output_id);
+                       di->decoder->name, output_id);
                return NULL;
        }
        pdo = l->data;
@@ -131,7 +136,7 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
                if ((cb = srd_find_callback(pdo->output_type))) {
                        /* Annotations need converting from PyObject. */
                        if (convert_pyobj(di, data, &pdata->ann_format,
-                                       (char ***)&pdata->data) != SRD_OK) {
+                                         (char ***)&pdata->data) != SRD_OK) {
                                /* An error was already logged. */
                                break;
                        }
@@ -144,10 +149,13 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
                        /* TODO: is this needed? */
                        Py_XINCREF(next_di->py_instance);
                        srd_spew("Sending %d-%d to instance %s",
-                                start_sample, end_sample, next_di->instance_id);
-                       if (!(py_res = PyObject_CallMethod(next_di->py_instance, "decode",
-                                       "KKO", start_sample, end_sample, data))) {
-                               catch_exception("calling %s decode(): ", next_di->instance_id);
+                                start_sample, end_sample,
+                                next_di->instance_id);
+                       if (!(py_res = PyObject_CallMethod(
+                           next_di->py_instance, "decode", "KKO", start_sample,
+                           end_sample, data))) {
+                               catch_exception("calling %s decode(): ",
+                                               next_di->instance_id);
                        }
                        Py_XDECREF(py_res);
                }
@@ -157,7 +165,7 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
                break;
        default:
                srd_err("Protocol decoder %s submitted invalid output type %d.",
-                               di->decoder->name, pdo->output_type);
+                       di->decoder->name, pdo->output_type);
                break;
        }
 
@@ -166,7 +174,6 @@ static PyObject *Decoder_put(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
-
 static PyObject *Decoder_add(PyObject *self, PyObject *args)
 {
        PyObject *ret;
@@ -200,7 +207,6 @@ static PyMethodDef Decoder_methods[] = {
        {NULL, NULL, 0, NULL}
 };
 
-
 PyTypeObject srd_Decoder_type = {
        PyVarObject_HEAD_INIT(NULL, 0)
        .tp_name = "sigrokdecode.Decoder",
@@ -209,4 +215,3 @@ PyTypeObject srd_Decoder_type = {
        .tp_doc = "Sigrok Decoder base class",
        .tp_methods = Decoder_methods,
 };
-
index 7cea75bb4133c443274b133afed7c0eb25092144..ebe81e33a6545abf210240735902feddf3a7235c 100644 (file)
 #include <inttypes.h>
 #include <string.h>
 
-
 PyObject *srd_logic_iter(PyObject *self)
 {
-
        return self;
 }
 
 PyObject *srd_logic_iternext(PyObject *self)
 {
+       int i;
        PyObject *py_samplenum, *py_samples;
        srd_logic *logic;
        uint64_t sample;
-       int i;
        unsigned char probe_samples[SRD_MAX_NUM_PROBES];
 
-       logic = (srd_logic *) self;
+       logic = (srd_logic *)self;
        if (logic->itercnt >= logic->inbuflen / logic->di->data_unitsize) {
                /* End iteration loop. */
                return NULL;
        }
 
-       /* Convert the bit-packed sample to an array of bytes, with only 0x01
+       /*
+        * Convert the bit-packed sample to an array of bytes, with only 0x01
         * and 0x00 values, so the PD doesn't need to do any bitshifting.
         */
-       memcpy(&sample, logic->inbuf + logic->itercnt * logic->di->data_unitsize,
-                       logic->di->data_unitsize);
+       memcpy(&sample,
+              logic->inbuf + logic->itercnt * logic->di->data_unitsize,
+              logic->di->data_unitsize);
        for (i = 0; i < logic->di->dec_num_probes; i++)
-               probe_samples[i] = sample & (1 << logic->di->dec_probemap[i]) ? 1 : 0;
+               probe_samples[i] =
+                   sample & (1 << logic->di->dec_probemap[i]) ? 1 : 0;
 
        /* Prepare the next samplenum/sample list in this iteration. */
-       py_samplenum = PyLong_FromUnsignedLongLong(logic->start_samplenum + logic->itercnt);
+       py_samplenum =
+           PyLong_FromUnsignedLongLong(logic->start_samplenum +
+                                       logic->itercnt);
        PyList_SetItem(logic->sample, 0, py_samplenum);
        py_samples = PyBytes_FromStringAndSize((const char *)probe_samples,
-                       logic->di->dec_num_probes);
+                                              logic->di->dec_num_probes);
        PyList_SetItem(logic->sample, 1, py_samples);
        Py_INCREF(logic->sample);
        logic->itercnt++;
@@ -72,4 +75,3 @@ PyTypeObject srd_logic_type = {
        .tp_iter = srd_logic_iter,
        .tp_iternext = srd_logic_iternext,
 };
-
diff --git a/util.c b/util.c
index 680d3b1ce55c51166490589fbc53e0857163d3f2..18b316e66cfe80b6811bdc8290958ce7c27c8d45 100644 (file)
--- a/util.c
+++ b/util.c
@@ -22,7 +22,6 @@
 #include "sigrokdecode-internal.h"
 #include "config.h"
 
-
 /**
  * Get the value of a python object's attribute, returned as a newly
  * allocated char *.
@@ -63,7 +62,6 @@ int py_attr_as_str(PyObject *py_obj, const char *attr, char **outstr)
        return ret;
 }
 
-
 /**
  * Get the value of a python dictionary item, returned as a newly
  * allocated char *.
@@ -81,7 +79,8 @@ int py_dictitem_as_str(PyObject *py_obj, const char *key, char **outstr)
        int ret;
 
        if (!PyDict_Check(py_obj)) {
-               srd_dbg("Object is a %s, not a dictionary.", Py_TYPE(py_obj)->tp_name);
+               srd_dbg("Object is a %s, not a dictionary.",
+                       Py_TYPE(py_obj)->tp_name);
                return SRD_ERR_PYTHON;
        }
 
@@ -91,8 +90,8 @@ int py_dictitem_as_str(PyObject *py_obj, const char *key, char **outstr)
        }
 
        if (!PyUnicode_Check(py_value)) {
-               srd_dbg("Dictionary value for %s should be a string, but is a %s.",
-                       key, Py_TYPE(py_value)->tp_name);
+               srd_dbg("Dictionary value for %s should be a string, but is "
+                       "a %s.", key, Py_TYPE(py_value)->tp_name);
                return SRD_ERR_PYTHON;
        }
 
@@ -101,7 +100,6 @@ int py_dictitem_as_str(PyObject *py_obj, const char *key, char **outstr)
        return SRD_OK;
 }
 
-
 /**
  * Get the value of a python unicode string object, returned as a newly
  * allocated char *.
@@ -123,7 +121,8 @@ int py_str_as_str(PyObject *py_str, char **outstr)
        ret = SRD_OK;
 
        if (!PyUnicode_Check(py_str)) {
-               srd_dbg("Object is a %s, not a string object.", Py_TYPE(py_str)->tp_name);
+               srd_dbg("Object is a %s, not a string object.",
+                       Py_TYPE(py_str)->tp_name);
                ret = SRD_ERR_PYTHON;
                goto err_out;
        }
@@ -154,7 +153,6 @@ err_out:
        return ret;
 }
 
-
 /**
  * Convert a python list of unicode strings to a NULL-terminated UTF8-encoded
  * char * array. The caller must free each string when finished.
@@ -176,7 +174,7 @@ int py_strlist_to_char(PyObject *py_strlist, char ***outstr)
                return SRD_ERR_MALLOC;
        for (i = 0; i < list_len; i++) {
                if (!(py_str = PyUnicode_AsEncodedString(
-                               PyList_GetItem(py_strlist, i), "utf-8", NULL)))
+                   PyList_GetItem(py_strlist, i), "utf-8", NULL)))
                        return SRD_ERR_PYTHON;
                if (!(str = PyBytes_AS_STRING(py_str)))
                        return SRD_ERR_PYTHON;
@@ -187,4 +185,3 @@ int py_strlist_to_char(PyObject *py_strlist, char ***outstr)
 
        return SRD_OK;
 }
-