diff options
author | Søren Sandmann Pedersen <ssp@dhcp-100-2-40.bos.redhat.com> | 2009-04-14 07:37:41 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@dhcp-100-2-40.bos.redhat.com> | 2009-04-14 07:37:41 -0400 |
commit | dc927e676bfadb834ede60de8c10eb4a5d128962 (patch) | |
tree | db8c394462fb6607efeefe30ecdccfc035462291 | |
parent | fd224d61577076685b6e4e99858e28c7660824cf (diff) |
Use nul_canonicalize_filename
-rw-r--r-- | siv.c | 8 | ||||
-rw-r--r-- | window.c | 113 |
2 files changed, 17 insertions, 104 deletions
@@ -352,12 +352,18 @@ process_options (int argc, char **argv) /* Don't open more than 32 windows */ if (i < 32) { + char *canonicalized; + if (g_path_is_absolute (option)) name = g_strdup (option); else name = g_build_filename (g_get_current_dir(), option, NULL); + + canonicalized = nul_canonicalize_filename (name); - g_ptr_array_add (result, name); + g_ptr_array_add (result, canonicalized); + + g_free (name); } } @@ -2,6 +2,7 @@ #include <gtk/gtk.h> #include <string.h> #include <gdk/gdkx.h> +#include <libnul.h> #include "siv.h" @@ -815,6 +816,8 @@ retry: GError *err = NULL; SivWindow *target; gboolean success; + char *tmp; + if (window->original) target = window_new (window->app); @@ -826,7 +829,7 @@ retry: /* This broke in GTK+ 2.13 */ if (!g_path_is_absolute (filename)) { - char *folder, *tmp; + char *folder; folder = gtk_file_chooser_get_current_folder (chooser); tmp = g_build_filename (folder, filename, NULL); @@ -836,6 +839,10 @@ retry: filename = tmp; } + + tmp = nul_canonicalize_filename (filename); + g_free (filename); + filename = tmp; set_busy (GTK_WIDGET (chooser), TRUE); @@ -985,94 +992,6 @@ set_defaults (SivWindow *window) gtk_check_menu_item_set_active (get_widget (window, "menu_no"), TRUE); } -/* Cut and paste from GLib */ -static char * -canonicalize_filename (const char *filename) -{ - char *canon, *start, *p, *q; - char *cwd; - int i; - - if (!g_path_is_absolute (filename)) - { - cwd = g_get_current_dir (); - canon = g_build_filename (cwd, filename, NULL); - g_free (cwd); - } - else - canon = g_strdup (filename); - - start = (char *)g_path_skip_root (canon); - - /* POSIX allows double slashes at the start to - * mean something special (as does windows too). - * So, "//" != "/", but more than two slashes - * is treated as "/". - */ - i = 0; - for (p = start - 1; - (p >= canon) && - G_IS_DIR_SEPARATOR (*p); - p--) - i++; - if (i > 2) - { - i -= 1; - start -= i; - memmove (start, start+i, strlen (start+i)+1); - } - - p = start; - while (*p != 0) - { - if (p[0] == '.' && (p[1] == 0 || G_IS_DIR_SEPARATOR (p[1]))) - { - memmove (p, p+1, strlen (p+1)+1); - } - else if (p[0] == '.' && p[1] == '.' && - (p[2] == 0 || G_IS_DIR_SEPARATOR (p[2]))) - { - q = p + 2; - /* Skip previous separator */ - - p = p - 2; - if (p < start) - p = start; - while (p > start && !G_IS_DIR_SEPARATOR (*p)) - p--; - if (G_IS_DIR_SEPARATOR (*p)) - *p++ = G_DIR_SEPARATOR; - memmove (p, q, strlen (q)+1); - } - else - { - /* Skip until next separator */ - while (*p != 0 && !G_IS_DIR_SEPARATOR (*p)) - p++; - - if (*p != 0) - { - /* Canonicalize one separator */ - *p++ = G_DIR_SEPARATOR; - } - } - - /* Remove additional separators */ - q = p; - while (*q && G_IS_DIR_SEPARATOR (*q)) - q++; - - if (p != q) - memmove (p, q, strlen (q)+1); - } - - /* Remove trailing slashes */ - if (p > start && G_IS_DIR_SEPARATOR (*(p-1))) - *(p-1) = 0; - - return canon; -} - static void apply_meta_data (SivWindow *window, const char *filename) { @@ -1125,16 +1044,13 @@ gboolean window_load_file (SivWindow *window, const char *filename, GError **err) { GdkPixbuf *pixbuf; - gchar *canon; - canon = canonicalize_filename (filename); - pixbuf = gdk_pixbuf_new_from_file (filename, err); if (pixbuf) { window->original = pixbuf; - window->filename = canon; + window->filename = g_strdup (filename); apply_meta_data (window, filename); @@ -1144,8 +1060,6 @@ window_load_file (SivWindow *window, const char *filename, GError **err) } else { - g_free (canon); - return FALSE; } } @@ -1235,14 +1149,7 @@ gboolean window_matches_file (SivWindow *window, const char *filename) { - char *canon = canonicalize_filename (filename); - gboolean match; - - match = window->filename && strcmp (canon, window->filename) == 0; - - g_free (canon); - - return match; + return window->filename && strcmp (filename, window->filename) == 0; } gboolean |