Mercurial > geeqie
diff src/main.c @ 653:e06947d07086
Expand tilde with file: and view: remote parameters.
Now these are working:
geeqie -r file:~/dir
geeqie -r view:~user/file
author | zas_ |
---|---|
date | Tue, 13 May 2008 16:09:43 +0000 |
parents | 9bcfd6d7a902 |
children | 8268cbe682f1 |
line wrap: on
line diff
--- a/src/main.c Tue May 13 14:49:38 2008 +0000 +++ b/src/main.c Tue May 13 16:09:43 2008 +0000 @@ -45,6 +45,9 @@ #include <math.h> +#ifdef G_OS_UNIX +#include <pwd.h> +#endif static RemoteConnection *remote_connection = NULL; @@ -81,6 +84,54 @@ return text; } +/* Borrowed from gtkfilesystemunix.c */ +gchar *expand_tilde(const gchar *filename) +{ +#ifndef G_OS_UNIX + return g_strdup(filename); +#else + const char *notilde; + const char *slash; + const char *home; + + if (filename[0] != '~') + return g_strdup(filename); + + notilde = filename + 1; + slash = strchr(notilde, G_DIR_SEPARATOR); + if (slash == notilde || !*notilde) + { + home = g_get_home_dir(); + if (!home) + return g_strdup(filename); + } + else + { + gchar *username; + struct passwd *passwd; + + if (slash) + username = g_strndup(notilde, slash - notilde); + else + username = g_strdup(notilde); + + passwd = getpwnam(username); + g_free(username); + + if (!passwd) + return g_strdup(filename); + + home = passwd->pw_dir; + } + + if (slash) + return g_build_filename(home, G_DIR_SEPARATOR_S, slash + 1, NULL); + else + return g_build_filename(home, G_DIR_SEPARATOR_S, NULL); +#endif +} + + /* *----------------------------------------------------------------------------- * keyboard functions