Code

Connector tool: make connectors avoid the convex hull of shapes.
[inkscape.git] / src / prefix.cpp
index 4999e152432025a7ff978e8b9ecffcf322cea07d..f1fa3c2cdfae7e9eaff1da5c14b134de645d1103 100644 (file)
     #include <glib.h> //for GThreads
 #endif /* BR_THREADS */
 
-#include <stdlib.h>
-#include <stdio.h>
+#include <cstdlib>
+#include <cstdio>
+#include <cstring>
 #include <limits.h>
-#include <string.h>
 #include "prefix.h"
 
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -355,7 +356,8 @@ br_strndup (char *str, size_t size)
 char *
 br_extract_dir (const char *path)
 {
-       char *end, *result;
+       const char *end;
+       char *result;
 
        br_return_val_if_fail (path != (char*)NULL, (char*)NULL);
 
@@ -390,7 +392,8 @@ br_extract_dir (const char *path)
 char *
 br_extract_prefix (const char *path)
 {
-       char *end, *tmp, *result;
+       const char *end;
+       char *tmp, *result;
 
        br_return_val_if_fail (path != (char*)NULL, (char*)NULL);
 
@@ -424,4 +427,78 @@ br_extract_prefix (const char *path)
 }
 #endif /* __cplusplus */
 
+
+
+#ifdef __WIN32__
+
+/**
+ * Provide a similar mechanism for Win32.  Enable a macro,
+ * WIN32_DATADIR, that can look up subpaths for inkscape resources 
+ */ 
+#include <windows.h>
+#include <glibmm/ustring.h>
+
+/**
+ * Return the directory of the .exe that is currently running
+ */
+static Glib::ustring win32_getExePath()
+{
+    char exeName[MAX_PATH+1];
+    GetModuleFileName(NULL, exeName, MAX_PATH);
+    char *slashPos = strrchr(exeName, '\\');
+    if (slashPos)
+        *slashPos = '\0';
+    Glib::ustring s = exeName;
+    return s;
+}
+
+
+/**
+ * Return the relocatable version of the datadir,
+ * probably c:\inkscape 
+ */
+static Glib::ustring win32_getDataDir()
+{
+    Glib::ustring dir = win32_getExePath();
+    if (INKSCAPE_DATADIR  && *INKSCAPE_DATADIR &&
+           strcmp(INKSCAPE_DATADIR, ".") != 0)
+        {
+        dir += "\\";
+        dir += INKSCAPE_DATADIR;
+        }
+    return dir;
+}
+
+static Glib::ustring win32_getResourcePath(const Glib::ustring &childPath)
+{
+    Glib::ustring dir = win32_getDataDir();
+    if (childPath.size() > 0)
+        {
+        dir += "\\";
+        dir += childPath;
+        }
+    return dir;
+}
+
+
+/**
+ * This is the visible utility function
+ */ 
+char *win32_relative_path(const char *childPath)
+{
+    static char *returnPath = NULL;
+    if (!childPath)
+        childPath = "";
+    Glib::ustring resourcePath = win32_getResourcePath(childPath);
+    if (returnPath)
+        free(returnPath);
+    returnPath = strdup(resourcePath.c_str());
+    return returnPath;
+}
+#endif /* __WIN32__ */
+
+
+
+
 #endif /* _PREFIX_C */