From a8813b2eae321ef5f304c20a9067248d0c17ecd5 Mon Sep 17 00:00:00 2001 From: Tamas TEVESZ Date: Thu, 23 Sep 2010 15:34:05 +0200 Subject: [PATCH] WINGs: Add normalizePath() Removes multiple consecutive and any trailing slashes from a path-looking string Signed-off-by: Tamas TEVESZ --- WINGs/wfilepanel.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/WINGs/wfilepanel.c b/WINGs/wfilepanel.c index ef13312e..bd2a11d8 100644 --- a/WINGs/wfilepanel.c +++ b/WINGs/wfilepanel.c @@ -69,6 +69,8 @@ static void fillColumn(WMBrowserDelegate * self, WMBrowser * bPtr, int column, W static void deleteFile(); +static void normalizePath(char *s); + static void createDir(); static void goHome(); @@ -652,6 +654,36 @@ static void createDir(WMButton * bPre, WMFilePanel * panel) wfree(file); } +/* + *---------------------------------------------------------------------- + * normalizePath-- + * Remove multiple consecutive and any trailing slashes from + * a path. + *---------------------------------------------------------------------- + */ +static void normalizePath(char *s) +{ + int i, j, found; + + found = 0; + for (i = 0; s[i]; !found && i++) { + found = 0; + if (s[i] == '/' && s[i+1] == '/') { + int nslash = 1; + found = 1; + i++; + while (s[i+nslash] == '/') + nslash++; + for (j = 0; s[i+j+nslash]; j++) + s[i+j] = s[i+j+nslash]; + s[i+j] = '\0'; + } + } + if (i > 1 && s[--i] == '/') + s[i] = '\0'; +} + + static void deleteFile(WMButton * bPre, WMFilePanel * panel) { char *file; -- 2.11.4.GIT