# HG changeset patch # User zas_ # Date 1216808497 0 # Node ID 3a939c88305c0dfbb4dad22e8eb226a787346bed # Parent 19b7349bb8c8a5a5d696a79186c488f446c43da6 Simplify parse_out_relatives(). diff -r 19b7349bb8c8 -r 3a939c88305c src/ui_fileops.c --- a/src/ui_fileops.c Wed Jul 23 09:10:41 2008 +0000 +++ b/src/ui_fileops.c Wed Jul 23 10:21:37 2008 +0000 @@ -665,23 +665,32 @@ while (path[s] != '\0') { - if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.' && (path[s+2] == G_DIR_SEPARATOR || path[s+2] == '\0') ) - { - s += 2; - } - else if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.' && path[s+2] == '.' && (path[s+3] == G_DIR_SEPARATOR || path[s+3] == '\0') ) + if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.') { - s += 3; - if (t > 0) t--; - while (path[t] != G_DIR_SEPARATOR && t > 0) t--; + /* /. occurence, let's see more */ + gint p = s + 2; + + if (path[p] == G_DIR_SEPARATOR || path[p] == '\0') + { + /* /./ or /., just skip this part */ + s = p; + continue; + } + else if (path[p] == '.' && (path[p+1] == G_DIR_SEPARATOR || path[p+1] == '\0')) + { + /* /../ or /.., remove previous part, ie. /a/b/../ becomes /a/ */ + s = p + 1; + if (t > 0) t--; + while (path[t] != G_DIR_SEPARATOR && t > 0) t--; + continue; + } } - else - { - if (s != t) path[t] = path[s]; - t++; - s++; - } + + if (s != t) path[t] = path[s]; + t++; + s++; } + if (t == 0 && path[t] == G_DIR_SEPARATOR) t++; if (t > 1 && path[t-1] == G_DIR_SEPARATOR) t--; path[t] = '\0';