diff options
author | Uwe Hermann <uwe@hermann-uwe.de> | 2012-01-19 00:21:00 +0100 |
---|---|---|
committer | Uwe Hermann <uwe@hermann-uwe.de> | 2012-01-19 00:21:00 +0100 |
commit | 639c56898e88aae99a7b91a5c6d2b7870956d648 (patch) | |
tree | d7445195ea98cf4961062b8611ebcfb7ee3e8790 | |
parent | e431d9cc4afa5e695efea61fb769f20d86f0bbe0 (diff) | |
download | libsigrokdecode-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'.
-rw-r--r-- | controller.c | 27 |
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; } |