Skip to content

Commit

Permalink
Simplify parse_out_relatives().
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurent Monin committed Jul 23, 2008
1 parent 9810215 commit b0a7f6e
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/ui_fileops.c
Original file line number Diff line number Diff line change
Expand Up @@ -665,23 +665,32 @@ void parse_out_relatives(gchar *path)

while (path[s] != '\0')
{
if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.' && (path[s+2] == G_DIR_SEPARATOR || path[s+2] == '\0') )
if (path[s] == G_DIR_SEPARATOR && path[s+1] == '.')
{
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') )
{
s += 3;
if (t > 0) t--;
while (path[t] != G_DIR_SEPARATOR && t > 0) t--;
}
else
{
if (s != t) path[t] = path[s];
t++;
s++;
/* /. 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;
}
}

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';
Expand Down

0 comments on commit b0a7f6e

Please sign in to comment.