mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 04:20:27 +01:00
WINGs: Add normalizePath()
Removes multiple consecutive and any trailing slashes from a path-looking string Signed-off-by: Tamas TEVESZ <ice@extreme.hu>
This commit is contained in:
committed by
Carlos R. Mafra
parent
0d32a6d3b7
commit
a8813b2eae
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user