]> sigrok.org Git - libsigrokdecode.git/blobdiff - decode.c
Introduce proper libtool versioning for the libs.
[libsigrokdecode.git] / decode.c
index 536be2c347315c4ac941d0490d5c307b17ab8733..da8624a4a40f125784398c64da9ca7a9f1dd45b0 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -31,7 +31,7 @@
 #endif
 
 /* The list of protocol decoders. */
-GSList *list_pds;
+GSList *list_pds = NULL;
 
 /**
  * Initialize libsigrokdecode.
@@ -47,22 +47,20 @@ int sigrokdecode_init(void)
        /* Py_Initialize() returns void and usually cannot fail. */
        Py_Initialize();
 
-       /* Add some more search directories for convenience. */
+       /* Add search directory for the protocol decoders. */
        /* FIXME: Check error code. */
        /* FIXME: What happens if this function is called multiple times? */
-       PyRun_SimpleString(
-               "import sys;"
-               "sys.path.append('libsigrokdecode/decoders');"
-               "sys.path.append('" DECODERS_DIR "');"
-               );
+       PyRun_SimpleString("import sys;"
+                          "sys.path.append(r'" DECODERS_DIR "');");
 
        if (!(dir = opendir(DECODERS_DIR)))
                return SIGROKDECODE_ERR_DECODERS_DIR;
 
        while ((dp = readdir(dir)) != NULL) {
-               if (!strstr(dp->d_name, ".py"))
+               if (!g_str_has_suffix(dp->d_name, ".py"))
                        continue;
-               if ((tmp = strdup(dp->d_name)))
+               /* For now use the filename (without .py) as decoder name. */
+               if ((tmp = g_strndup(dp->d_name, strlen(dp->d_name) - 3)))
                        list_pds = g_slist_append(list_pds, tmp);
        }
        closedir(dir);
@@ -70,6 +68,18 @@ int sigrokdecode_init(void)
        return SIGROKDECODE_OK;
 }
 
+/**
+ * Returns the list of supported/loaded protocol decoders.
+ *
+ * This is a GSList containing the names of the decoders as strings.
+ *
+ * @return List of decoders, NULL if none are supported or loaded.
+ */
+GSList *sigrokdecode_list_decoders(void)
+{
+       return list_pds;
+}
+
 /**
  * Helper function to handle Python strings.
  *