/*
5 * Authors: see git history
7 * Copyright (C) 2018 Authors
8 * Released under GNU GPL v2+, read the file
'COPYING' for more information.
24 if ( !base.empty() && !path.empty() ) {
25 size_t base_len = base.length();
27 && (base[base_len - 1] == G_DIR_SEPARATOR))
32 if ( (path.substr(0, base_len) == base.substr(0, base_len))
33 && (path[base_len] == G_DIR_SEPARATOR))
35 size_t retPos = base_len + 1;
36 while ( (retPos < path.length()) && (path[retPos] == G_DIR_SEPARATOR) ) {
39 if ( (retPos + 1) < path.length() ) {
40 result = path.substr(retPos);
53 if (path ==
nullptr) {
58 while (*p !=
'\0') p++;
60 while ((p >= path) && (*p != G_DIR_SEPARATOR) && (*p !=
'.')) p--;
61 if (* p !=
'.')
return nullptr;
69static char const dots[] = {
'.',
'.', G_DIR_SEPARATOR,
'\0'};
80 if (*path == G_DIR_SEPARATOR)
82 if (strlen (path) >=
size)
87 else if (*base != G_DIR_SEPARATOR || !
size)
94 if (!strcmp (path,
".") || !strcmp (path,
current))
96 if (strlen (base) >=
size)
100 rp =
result + strlen (base) - 1;
101 if (*rp == G_DIR_SEPARATOR)
106 if (*++path == G_DIR_SEPARATOR)
109 *rp++ = G_DIR_SEPARATOR;
116 bp = base + strlen (base);
117 if (*(bp - 1) == G_DIR_SEPARATOR)
120 for (pp = path; *pp && *pp ==
'.';)
122 if (!strncmp (pp,
parent, 3))
125 while (bp > base && *--bp != G_DIR_SEPARATOR)
128 else if (!strncmp (pp,
current, 2))
132 else if (!strncmp (pp,
"..\0", 3))
135 while (bp > base && *--bp != G_DIR_SEPARATOR)
143 if (length >=
static_cast<int>(
size))
145 strncpy (
result, base, length);
147 if (*pp || (pp > path && *(pp - 1) == G_DIR_SEPARATOR) || length == 0)
148 *rp++ = G_DIR_SEPARATOR;
149 if (rp + strlen (pp) > endp)
161 const char *pp, *bp, *branch;
166 if (*path != G_DIR_SEPARATOR)
168 if (strlen (path) >=
size)
173 else if (*base != G_DIR_SEPARATOR || !
size)
182 for (pp = path, bp = base; *pp && *bp && *pp == *bp; pp++, bp++)
183 if (*pp == G_DIR_SEPARATOR)
185 if (((*pp == 0) || ((*pp == G_DIR_SEPARATOR) && (*(pp + 1) == 0))) &&
186 ((*bp == 0) || ((*bp == G_DIR_SEPARATOR) && (*(bp + 1) == 0))))
190 if (*pp == G_DIR_SEPARATOR || *(pp - 1) == G_DIR_SEPARATOR)
191 *rp++ = G_DIR_SEPARATOR;
197 if (((*pp == 0) && (*bp == G_DIR_SEPARATOR)) || ((*pp == G_DIR_SEPARATOR) && (*bp == 0)))
201 for (bp = base + (branch - path); *bp; bp++)
202 if (*bp == G_DIR_SEPARATOR && *(bp + 1) != 0)
208 *rp++ = G_DIR_SEPARATOR;
216 if (rp + strlen (branch + 1) > endp)
218 strcpy (rp, branch + 1);
235 gchar *full_path = (gchar *) g_malloc (1001);
236 gchar *cwd = g_get_current_dir();
239 gsize bytesWritten = 0;
240 GError* error =
nullptr;
241 gchar* cwd_utf8 = g_filename_to_utf8 ( cwd,
248 gchar *ret = g_strdup (full_path);
char const * sp_extension_from_path(char const *const path)
static char const *const current
char * inkscape_rel2abs(const char *path, const char *base, char *result, const size_t size)
Convert a relative path name into absolute.
static char const *const parent
char * inkscape_abs2rel(const char *path, const char *base, char *result, const size_t size)
std::string sp_relative_path_from_path(std::string const &path, std::string const &base)
Returns a form of path relative to base if that is easy to construct (eg if path appears to be in the...
char * prepend_current_dir_if_relative(gchar const *uri)
TODO: insert short description here.