summaryrefslogtreecommitdiff
path: root/controller.c
diff options
context:
space:
mode:
authorUwe Hermann <uwe@hermann-uwe.de>2012-01-19 00:21:00 +0100
committerUwe Hermann <uwe@hermann-uwe.de>2012-01-19 00:21:00 +0100
commit639c56898e88aae99a7b91a5c6d2b7870956d648 (patch)
treed7445195ea98cf4961062b8611ebcfb7ee3e8790 /controller.c
parente431d9cc4afa5e695efea61fb769f20d86f0bbe0 (diff)
downloadlibsigrokdecode-639c56898e88aae99a7b91a5c6d2b7870956d648.tar.gz
libsigrokdecode-639c56898e88aae99a7b91a5c6d2b7870956d648.zip
srd: Windows/MinGW Python path format fixes.
On Windows/MinGW, Python's sys.path needs entries of the form 'C:\\foo\\bar' instead of '/foo/bar'.
Diffstat (limited to 'controller.c')
-rw-r--r--controller.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/controller.c b/controller.c
index 4fa729c..f5e272e 100644
--- a/controller.c
+++ b/controller.c
@@ -114,13 +114,36 @@ int srd_exit(void)
* Add search directories for the protocol decoders.
*
* TODO: add path from env var SIGROKDECODE_PATH, config etc
+ * TODO: Should take directoryname/path as input.
*/
int set_modulepath(void)
{
int ret;
+ gchar *path, *s;
- PyRun_SimpleString("import sys");
- ret = PyRun_SimpleString("sys.path.append(r'" DECODERS_DIR "');");
+#ifdef _WIN32
+ gchar **splitted;
+
+ /*
+ * On Windows/MinGW, Python's sys.path needs entries of the form
+ * 'C:\\foo\\bar' instead of '/foo/bar'.
+ */
+
+ splitted = g_strsplit(DECODERS_DIR, "/", 0);
+ path = g_build_pathv("\\\\", splitted);
+ g_strfreev(splitted);
+#else
+ path = g_strdup(DECODERS_DIR);
+#endif
+
+ /* TODO: Prepend instead of appending. */
+ /* TODO: Sanity check on 'path' (length, escape special chars, ...). */
+ s = g_strdup_printf("import sys; sys.path.append(r'%s')", path);
+
+ ret = PyRun_SimpleString(s);
+
+ g_free(path);
+ g_free(s);
return ret;
}