summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2012-03-18 16:08:17 +0000
committerDavid Robillard <d@drobilla.net>2012-03-18 16:08:17 +0000
commitd1fa6805f10c702b2191f888d4f8806f1f9d5068 (patch)
treedc7cb79dc5ad02d1c35ccd10e8e855f644e3e251
parent81040bd8c8fb95e0d387b53b3cf25e4c0669a6f7 (diff)
downloadsord-d1fa6805f10c702b2191f888d4f8806f1f9d5068.tar.gz
sord-d1fa6805f10c702b2191f888d4f8806f1f9d5068.tar.bz2
sord-d1fa6805f10c702b2191f888d4f8806f1f9d5068.zip
Always use an absolute base URI.
git-svn-id: http://svn.drobilla.net/sord/trunk@206 3d64ff67-21c5-427c-a301-fe4f08042e5a
-rw-r--r--src/sordi.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/src/sordi.c b/src/sordi.c
index d06b126..193988e 100644
--- a/src/sordi.c
+++ b/src/sordi.c
@@ -14,10 +14,16 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#define _BSD_SOURCE // for realpath
+
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#ifdef _WIN32
+# include <windows.h>
+#endif
+
#include "serd/serd.h"
#include "sord/sord.h"
#include "sord_config.h"
@@ -70,6 +76,18 @@ set_syntax(SerdSyntax* syntax, const char* name)
return true;
}
+uint8_t*
+absolute_path(const uint8_t* path)
+{
+#ifdef _WIN32
+ char* out = (char*)malloc(MAX_PATH);
+ GetFullPathName((const char*)path, MAX_PATH, out, NULL);
+ return (uint8_t*)out;
+#else
+ return (uint8_t*)realpath((const char*)path, NULL);
+#endif
+}
+
int
main(int argc, char** argv)
{
@@ -124,32 +142,29 @@ main(int argc, char** argv)
return 1;
}
- const uint8_t* input = (const uint8_t*)argv[a++];
+ const uint8_t* input = (const uint8_t*)argv[a++];
+ uint8_t* in_path = NULL;
if (from_file) {
in_name = in_name ? in_name : input;
if (!in_fd) {
- input = serd_uri_to_path(in_name);
- if (!input || !(in_fd = fopen((const char*)input, "rb"))) {
+ in_path = absolute_path(serd_uri_to_path(in_name));
+ if (!in_path || !(in_fd = fopen((const char*)in_path, "rb"))) {
return 1;
}
}
}
- const uint8_t* base_uri_str = NULL;
+ SerdURI base_uri = SERD_URI_NULL;
+ SerdNode base_uri_node = SERD_NODE_NULL;
if (a < argc) { // Base URI given on command line
- base_uri_str = (const uint8_t*)argv[a];
+ base_uri_node = serd_node_new_uri_from_string(
+ (const uint8_t*)argv[a], NULL, &base_uri);
} else if (from_file) { // Use input file URI
- base_uri_str = input;
- } else {
- base_uri_str = (const uint8_t*)"";
+ base_uri_node = serd_node_new_file_uri(in_path, NULL, &base_uri, false);
}
- SerdURI base_uri = SERD_URI_NULL;
- SerdNode base_uri_node = serd_node_new_uri_from_string(
- base_uri_str, &base_uri, &base_uri);
-
if (!base_uri_node.buf) {
- fprintf(stderr, "Invalid base URI <%s>\n", base_uri_str);
+ fprintf(stderr, "Missing base URI\n");
return 1;
}