Skip to content

Commit

Permalink
Add utils_path_skip_root(), a relative path safe variant of g_path_sk…
Browse files Browse the repository at this point in the history
…ip_root (forgotten patch by Colomban Wendling, #2518658).

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@3663 ea778897-0a13-0410-b9d1-a72fbfd435f5
  • Loading branch information
eht16 committed Mar 27, 2009
1 parent 1d7a122 commit a6cecbd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 11 deletions.
9 changes: 8 additions & 1 deletion ChangeLog
@@ -1,6 +1,13 @@
2009-03-27 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

* src/keyfile.c, src/utils.c, src/utils.h:
Add utils_path_skip_root(), a relative path safe variant of
g_path_skip_root (forgotten patch by Colomban Wendling, #2518658).


2009-03-26 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>

* src\main.c, src\plugins.c, src\win32.c, src\win32.h:
* src/main.c, src/plugins.c, src/win32.c, src/win32.h:
Use g_win32_get_package_installation_directory_of_module() on Windows
with newer GLib versions instead of deprecated API.
* src/keybindings.c:
Expand Down
12 changes: 2 additions & 10 deletions src/keyfile.c
Expand Up @@ -231,7 +231,6 @@ static gchar *get_session_file_string(GeanyDocument *doc)
{
gchar *fname;
gchar *locale_filename;
gchar *rootless_filename;
GeanyFiletype *ft = doc->file_type;

if (ft == NULL) /* can happen when saving a new file when quitting */
Expand All @@ -243,10 +242,7 @@ static gchar *get_session_file_string(GeanyDocument *doc)
* writing with usual colons which must never appear in a filename and replace them
* back when we read the file again from the file.
* (g_path_skip_root() to skip C:\... on Windows) */
rootless_filename = (gchar *) g_path_skip_root(locale_filename);
if (locale_filename == NULL)
rootless_filename = locale_filename;
g_strdelimit(rootless_filename, ";", ':');
g_strdelimit((gchar*) utils_path_skip_root(locale_filename), ";", ':');

fname = g_strdup_printf("%d;%s;%d;%d;%d;%d;%d;%s;%d",
sci_get_current_position(doc->editor->sci),
Expand Down Expand Up @@ -894,7 +890,6 @@ static gboolean open_session_file(gchar **tmp, guint len)
guint pos;
const gchar *ft_name;
gchar *locale_filename;
gchar *rootless_filename;
gint enc_idx, indent_type;
gboolean ro, auto_indent, line_wrapping;
/** TODO when we have a global pref for line breaking, use its value */
Expand All @@ -911,10 +906,7 @@ static gboolean open_session_file(gchar **tmp, guint len)
/* try to get the locale equivalent for the filename */
locale_filename = utils_get_locale_from_utf8(tmp[7]);
/* replace ':' back with ';' (see get_session_file_string for details) */
rootless_filename = (gchar *) g_path_skip_root(locale_filename);
if (locale_filename == NULL)
rootless_filename = locale_filename;
g_strdelimit(rootless_filename, ":", ';');
g_strdelimit((gchar*) utils_path_skip_root(locale_filename), ":", ';');

if (len > 8)
line_breaking = atoi(tmp[8]);
Expand Down
13 changes: 13 additions & 0 deletions src/utils.c
Expand Up @@ -319,6 +319,19 @@ gboolean utils_is_absolute_path(const gchar *path)
}


/* Skips root if path is absolute, do nothing otherwise.
* This is a relative-safe version of g_path_skip_root().
*/
const gchar *utils_path_skip_root(const gchar *path)
{
const gchar *path_relative;

path_relative = g_path_skip_root(path);

return (path_relative != NULL) ? path_relative : path;
}


gdouble utils_scale_round(gdouble val, gdouble factor)
{
/*val = floor(val * factor + 0.5);*/
Expand Down
2 changes: 2 additions & 0 deletions src/utils.h
Expand Up @@ -76,6 +76,8 @@ gboolean utils_atob(const gchar *str);

gboolean utils_is_absolute_path(const gchar *path);

const gchar *utils_path_skip_root(const gchar *path);

gdouble utils_scale_round(gdouble val, gdouble factor);

gboolean utils_str_equal(const gchar *a, const gchar *b);
Expand Down

0 comments on commit a6cecbd

Please sign in to comment.