From 7b067fc094b0495359557e6442636a38567e995c Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 28 Mar 2011 03:13:05 +0000 Subject: Fix Windows build git-svn-id: http://svn.drobilla.net/lad/trunk/slv2@3129 a436a847-0d15-0410-975c-d299462d15a1 --- src/plugin.c | 4 ---- src/pluginui.c | 2 +- src/slv2_internal.h | 9 ++++++++ src/util.c | 19 ++++++++++++++-- src/value.c | 14 ++++++------ src/world.c | 63 +++++++++++++++++++++++++++++++++++++++++------------ wscript | 23 ++++++++++++++----- 7 files changed, 100 insertions(+), 34 deletions(-) diff --git a/src/plugin.c b/src/plugin.c index ce5299e..a4f9338 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -30,10 +30,6 @@ #include #include -#ifdef SLV2_DYN_MANIFEST -#include -#endif - #include "slv2-config.h" #include "slv2_internal.h" diff --git a/src/pluginui.c b/src/pluginui.c index 4d61690..c81a5dd 100644 --- a/src/pluginui.c +++ b/src/pluginui.c @@ -51,7 +51,7 @@ slv2_ui_new(SLV2World world, ui->binary_uri = binary_uri; // FIXME: kludge - char* bundle = strdup(slv2_value_as_string(ui->binary_uri)); + char* bundle = slv2_strdup(slv2_value_as_string(ui->binary_uri)); char* last_slash = strrchr(bundle, '/') + 1; *last_slash = '\0'; ui->bundle_uri = slv2_value_new_uri(world, bundle); diff --git a/src/slv2_internal.h b/src/slv2_internal.h index d24d570..e2a6807 100644 --- a/src/slv2_internal.h +++ b/src/slv2_internal.h @@ -28,7 +28,15 @@ extern "C" { #include #include +#ifdef __WIN32__ +#include +#define dlopen(path, flags) LoadLibrary(path) +#define dlclose(lib) FreeLibrary(lib) +#define dlsym GetProcAddress +static inline char* dlerror(void) { return "Unknown error"; } +#else #include +#endif #include @@ -379,6 +387,7 @@ SLV2Values slv2_values_from_stream_objects(SLV2Plugin p, /* ********* Utilities ********* */ char* slv2_strjoin(const char* first, ...); +char* slv2_strdup(const char* str); char* slv2_get_lang(); uint8_t* slv2_qname_expand(SLV2Plugin p, const char* qname); diff --git a/src/util.c b/src/util.c index ba2ca5d..d7ac0b7 100644 --- a/src/util.c +++ b/src/util.c @@ -59,13 +59,28 @@ slv2_strjoin(const char* first, ...) return result; } +char* +slv2_strdup(const char* str) +{ + const size_t len = strlen(str); + char* dup = malloc(len + 1); + memcpy(dup, str, len + 1); + return dup; +} + const char* slv2_uri_to_path(const char* uri) { - if (!strncmp(uri, "file://", (size_t)7)) +#ifdef __WIN32__ + if (!strncmp(uri, "file:///", (size_t)8)) { + return (char*)(uri + 8); +#else + if (!strncmp(uri, "file://", (size_t)7)) { return (char*)(uri + 7); - else +#endif + } else { return NULL; + } } /** Return the current LANG converted to Turtle (i.e. RFC3066) style. diff --git a/src/value.c b/src/value.c index 09a0720..3dce427 100644 --- a/src/value.c +++ b/src/value.c @@ -48,7 +48,7 @@ slv2_value_set_numerics_from_string(SLV2Value val) break; case SLV2_VALUE_INT: // FIXME: locale kludge, need a locale independent strtol - locale = strdup(setlocale(LC_NUMERIC, NULL)); + locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "POSIX"); val->val.int_val = strtol(val->str_val, &endptr, 10); setlocale(LC_NUMERIC, locale); @@ -56,7 +56,7 @@ slv2_value_set_numerics_from_string(SLV2Value val) break; case SLV2_VALUE_FLOAT: // FIXME: locale kludge, need a locale independent strtod - locale = strdup(setlocale(LC_NUMERIC, NULL)); + locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "POSIX"); val->val.float_val = strtod(val->str_val, &endptr); setlocale(LC_NUMERIC, locale); @@ -91,7 +91,7 @@ slv2_value_new(SLV2World world, SLV2ValueType type, const char* str) case SLV2_VALUE_INT: case SLV2_VALUE_FLOAT: case SLV2_VALUE_BOOL: - val->str_val = strdup(str); + val->str_val = slv2_strdup(str); break; } @@ -207,7 +207,7 @@ slv2_value_duplicate(SLV2Value val) result->val.uri_val = slv2_node_copy(val->val.uri_val); result->str_val = (char*)sord_node_get_string(result->val.uri_val); } else { - result->str_val = strdup(val->str_val); + result->str_val = slv2_strdup(val->str_val); result->val = val->val; } @@ -277,12 +277,12 @@ slv2_value_get_turtle_token(SLV2Value value) case SLV2_VALUE_STRING: case SLV2_VALUE_QNAME_UNUSED: case SLV2_VALUE_BOOL: - result = strdup(value->str_val); + result = slv2_strdup(value->str_val); break; case SLV2_VALUE_INT: // INT64_MAX is 9223372036854775807 (19 digits) + 1 for sign // FIXME: locale kludge, need a locale independent snprintf - locale = strdup(setlocale(LC_NUMERIC, NULL)); + locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); len = 20; result = calloc(len, 1); setlocale(LC_NUMERIC, "POSIX"); @@ -291,7 +291,7 @@ slv2_value_get_turtle_token(SLV2Value value) break; case SLV2_VALUE_FLOAT: // FIXME: locale kludge, need a locale independent snprintf - locale = strdup(setlocale(LC_NUMERIC, NULL)); + locale = slv2_strdup(setlocale(LC_NUMERIC, NULL)); len = 20; // FIXME: proper maximum value? result = calloc(len, 1); setlocale(LC_NUMERIC, "POSIX"); diff --git a/src/world.c b/src/world.c index 6209c8c..ea2e20c 100644 --- a/src/world.c +++ b/src/world.c @@ -30,9 +30,8 @@ #include #include +#ifdef HAVE_WORDEXP #include -#ifdef SLV2_DYN_MANIFEST -#include #endif #include "slv2_internal.h" @@ -212,7 +211,8 @@ slv2_world_find_statements(SLV2World world, } static SerdNode -slv2_new_uri_relative_to_base(const uint8_t* uri_str, const uint8_t* base_uri_str) +slv2_new_uri_relative_to_base(const uint8_t* uri_str, + const uint8_t* base_uri_str) { SerdURI base_uri; if (!serd_uri_parse(base_uri_str, &base_uri)) { @@ -496,22 +496,26 @@ slv2_world_load_bundle(SLV2World world, SLV2Value bundle_uri) static char* expand(const char* path) { +#ifdef HAVE_WORDEXP char* ret = NULL; wordexp_t p; wordexp(path, &p, 0); if (p.we_wordc == 0) { - // Literal directory path (e.g. no variables or ~) - ret = strdup(path); + /* Literal directory path (e.g. no variables or ~) */ + ret = slv2_strdup(path); } else if (p.we_wordc == 1) { - // Directory path expands (e.g. contains ~ or $FOO) - ret = strdup(p.we_wordv[0]); + /* Directory path expands (e.g. contains ~ or $FOO) */ + ret = slv2_strdup(p.we_wordv[0]); } else { - // Multiple expansions in a single directory path? - fprintf(stderr, "lv2config: malformed path `%s' ignored\n", path); + /* Multiple expansions in a single directory path? */ + SLV2_ERRORF("malformed path `%s' ignored\n", path); } wordfree(&p); +#else + char* ret = slv2_strdup(path); +#endif return ret; } @@ -521,31 +525,43 @@ slv2_world_load_directory(SLV2World world, const char* dir_path) { char* path = expand(dir_path); if (!path) { + SLV2_WARNF("empty path `%s'\n", path); return; } DIR* pdir = opendir(path); if (!pdir) { + SLV2_WARNF("failed to open directory `%s' (%s)\n", + path, strerror(errno)); free(path); return; } +#ifdef __WIN32__ + static const char* const file_scheme = "file:///"; +#else + static const char* const file_scheme = "file://"; +#endif + const size_t file_scheme_len = strlen(file_scheme); + struct dirent* pfile; while ((pfile = readdir(pdir))) { if (!strcmp(pfile->d_name, ".") || !strcmp(pfile->d_name, "..")) continue; - char* uri = slv2_strjoin("file://", - path, SLV2_DIR_SEP, - pfile->d_name, SLV2_DIR_SEP, + char* uri = slv2_strjoin(file_scheme, + path, "/", + pfile->d_name, "/", NULL); - DIR* const bundle_dir = opendir(uri + 7); + DIR* const bundle_dir = opendir(uri + file_scheme_len); if (bundle_dir) { closedir(bundle_dir); SLV2Value uri_val = slv2_value_new_uri(world, uri); slv2_world_load_bundle(world, uri_val); slv2_value_free(uri_val); + } else { + SLV2_WARNF("failed to open bundle `%s'\n", uri); } free(uri); @@ -555,6 +571,25 @@ slv2_world_load_directory(SLV2World world, const char* dir_path) closedir(pdir); } +static bool +is_path_sep(char c) +{ + return c == SLV2_PATH_SEP[0]; +} + +const char* +last_path_sep(const char* path) +{ + const size_t len = strlen(path); + const char* last_sep = path + len; + for (; last_sep > path; --last_sep) { + if (is_path_sep(*last_sep)) { + break; + } + } + return is_path_sep(*last_sep) ? last_sep : NULL; +} + /** Load all bundles found in @a lv2_path. * @param lv2_path A colon-delimited list of directories. These directories * should contain LV2 bundle directories (ie the search path is a list of @@ -565,7 +600,7 @@ slv2_world_load_path(SLV2World world, const char* lv2_path) { while (lv2_path[0] != '\0') { - const char* const sep = strchr(lv2_path, SLV2_PATH_SEP[0]); + const char* const sep = last_path_sep(lv2_path); if (sep) { const size_t dir_len = sep - lv2_path; char* const dir = malloc(dir_len + 1); diff --git a/wscript b/wscript index 03440fc..a39eeb9 100644 --- a/wscript +++ b/wscript @@ -94,6 +94,11 @@ def configure(conf): autowaf.check_pkg(conf, 'suil', uselib_store='SUIL', atleast_version='0.0.0', mandatory=True) + conf.check(function_name='wordexp', + header_name='wordexp.h', + define_name='HAVE_WORDEXP', + mandatory=False) + autowaf.check_header(conf, 'lv2/lv2plug.in/ns/lv2core/lv2.h') autowaf.check_header(conf, 'lv2/lv2plug.in/ns/extensions/ui/ui.h') @@ -110,7 +115,7 @@ def configure(conf): slv2_dir_sep = '/' if sys.platform == 'win32': slv2_path_sep = ';' - slv2_dir_sep = '\\' + slv2_dir_sep = '\\\\' autowaf.define(conf, 'SLV2_PATH_SEP', slv2_path_sep) autowaf.define(conf, 'SLV2_DIR_SEP', slv2_dir_sep) @@ -128,7 +133,7 @@ def configure(conf): '~/.lv2', '/boot/common/add-ons/lv2']) elif Options.platform == 'win32': - Options.options.default_lv2_path = 'C:\\Program Files\\LV2' + Options.options.default_lv2_path = 'C:\\\\Program Files\\\\LV2' else: libdirname = os.path.basename(conf.env['LIBDIR']) Options.options.default_lv2_path = slv2_path_sep.join([ @@ -193,6 +198,12 @@ def build(bld): src/world.c '''.split() + linkflags = [ '-ldl' ] + libflags = [ '-fvisibility=hidden' ] + if sys.platform == 'win32': + linkflags = [] + libflags = [] + # Library obj = bld(features = 'c cshlib', export_includes = ['.'], @@ -202,10 +213,10 @@ def build(bld): target = 'slv2', vnum = SLV2_LIB_VERSION, install_path = '${LIBDIR}', - cflags = [ '-fvisibility=hidden', + cflags = libflags + [ '-DSLV2_SHARED', '-DSLV2_INTERNAL' ], - linkflags = [ '-ldl' ]) + linkflags = linkflags) autowaf.use_lib(bld, obj, 'SORD SERD LV2CORE GLIB SUIL') if bld.env['BUILD_TESTS']: @@ -217,7 +228,7 @@ def build(bld): target = 'slv2_static', install_path = '', cflags = [ '-fprofile-arcs', '-ftest-coverage', '-DSLV2_INTERNAL' ], - linkflags = [ '-ldl' ]) + linkflags = linkflags) autowaf.use_lib(bld, obj, 'SORD SERD LV2CORE GLIB SUIL') # Unit test program @@ -226,7 +237,7 @@ def build(bld): includes = ['.', './src'], use = 'libslv2_static', uselib = 'SORD SERD LV2CORE', - linkflags = '-lgcov -ldl', + linkflags = linkflags + ['-lgcov'], target = 'test/slv2_test', install_path = '', cflags = [ '-fprofile-arcs', '-ftest-coverage' ]) -- cgit v1.2.1