📄 path.c
字号:
/*************************************************************************
* PathGetDriveNumberW [SHLWAPI.@]
*
* See PathGetDriveNumberA.
*/
int WINAPI PathGetDriveNumberW(LPCWSTR lpszPath)
{
TRACE ("(%s)\n",debugstr_w(lpszPath));
if (lpszPath)
{
WCHAR tl = tolowerW(lpszPath[0]);
if (tl >= 'a' && tl <= 'z' && lpszPath[1] == ':')
return tl - 'a';
}
return -1;
}
/*************************************************************************
* PathRemoveFileSpecA [SHLWAPI.@]
*
* Remove the file specification from a path.
*
* PARAMS
* lpszPath [I/O] Path to remove the file spec from
*
* RETURNS
* TRUE If the path was valid and modified
* FALSE Otherwise
*/
BOOL WINAPI PathRemoveFileSpecA(LPSTR lpszPath)
{
LPSTR lpszFileSpec = lpszPath;
BOOL bModified = FALSE;
TRACE("(%s)\n",debugstr_a(lpszPath));
if(lpszPath)
{
/* Skip directory or UNC path */
if (*lpszPath == '\\')
lpszFileSpec = ++lpszPath;
if (*lpszPath == '\\')
lpszFileSpec = ++lpszPath;
while (*lpszPath)
{
if(*lpszPath == '\\')
lpszFileSpec = lpszPath; /* Skip dir */
else if(*lpszPath == ':')
{
lpszFileSpec = ++lpszPath; /* Skip drive */
if (*lpszPath == '\\')
lpszFileSpec++;
}
if (!(lpszPath = CharNextA(lpszPath)))
break;
}
if (*lpszFileSpec)
{
*lpszFileSpec = '\0';
bModified = TRUE;
}
}
return bModified;
}
/*************************************************************************
* PathRemoveFileSpecW [SHLWAPI.@]
*
* See PathRemoveFileSpecA.
*/
BOOL WINAPI PathRemoveFileSpecW(LPWSTR lpszPath)
{
LPWSTR lpszFileSpec = lpszPath;
BOOL bModified = FALSE;
TRACE("(%s)\n",debugstr_w(lpszPath));
if(lpszPath)
{
/* Skip directory or UNC path */
if (*lpszPath == '\\')
lpszFileSpec = ++lpszPath;
if (*lpszPath == '\\')
lpszFileSpec = ++lpszPath;
while (*lpszPath)
{
if(*lpszPath == '\\')
lpszFileSpec = lpszPath; /* Skip dir */
else if(*lpszPath == ':')
{
lpszFileSpec = ++lpszPath; /* Skip drive */
if (*lpszPath == '\\')
lpszFileSpec++;
}
lpszPath++;
}
if (*lpszFileSpec)
{
*lpszFileSpec = '\0';
bModified = TRUE;
}
}
return bModified;
}
/*************************************************************************
* PathStripPathA [SHLWAPI.@]
*
* Remove the initial path from the beginning of a filename
*
* PARAMS
* lpszPath [I/O] Path to remove the initial path from
*
* RETURNS
* Nothing.
*/
void WINAPI PathStripPathA(LPSTR lpszPath)
{
TRACE("(%s)\n", debugstr_a(lpszPath));
if (lpszPath)
{
LPSTR lpszFileName = PathFindFileNameA(lpszPath);
if(lpszFileName)
RtlMoveMemory(lpszPath, lpszFileName, strlen(lpszFileName)+1);
}
}
/*************************************************************************
* PathStripPathW [SHLWAPI.@]
*
* See PathStripPathA.
*/
void WINAPI PathStripPathW(LPWSTR lpszPath)
{
LPWSTR lpszFileName;
TRACE("(%s)\n", debugstr_w(lpszPath));
lpszFileName = PathFindFileNameW(lpszPath);
if(lpszFileName)
RtlMoveMemory(lpszPath, lpszFileName, (strlenW(lpszFileName)+1)*sizeof(WCHAR));
}
/*************************************************************************
* PathStripToRootA [SHLWAPI.@]
*
* Reduce a path to its root.
*
* PARAMS
* lpszPath [I/O] the path to reduce
*
* RETURNS
* Success: TRUE if the stripped path is a root path
* Failure: FALSE if the path cannot be stripped or is NULL
*/
BOOL WINAPI PathStripToRootA(LPSTR lpszPath)
{
TRACE("(%s)\n", debugstr_a(lpszPath));
if (!lpszPath)
return FALSE;
while(!PathIsRootA(lpszPath))
if (!PathRemoveFileSpecA(lpszPath))
return FALSE;
return TRUE;
}
/*************************************************************************
* PathStripToRootW [SHLWAPI.@]
*
* See PathStripToRootA.
*/
BOOL WINAPI PathStripToRootW(LPWSTR lpszPath)
{
TRACE("(%s)\n", debugstr_w(lpszPath));
if (!lpszPath)
return FALSE;
while(!PathIsRootW(lpszPath))
if (!PathRemoveFileSpecW(lpszPath))
return FALSE;
return TRUE;
}
/*************************************************************************
* PathRemoveArgsA [SHLWAPI.@]
*
* Strip space separated arguments from a path.
*
* PARAMS
* lpszPath [I/O] Path to remove arguments from
*
* RETURNS
* Nothing.
*/
void WINAPI PathRemoveArgsA(LPSTR lpszPath)
{
TRACE("(%s)\n",debugstr_a(lpszPath));
if(lpszPath)
{
LPSTR lpszArgs = PathGetArgsA(lpszPath);
if (*lpszArgs)
lpszArgs[-1] = '\0';
else
{
LPSTR lpszLastChar = CharPrevA(lpszPath, lpszArgs);
if(*lpszLastChar == ' ')
*lpszLastChar = '\0';
}
}
}
/*************************************************************************
* PathRemoveArgsW [SHLWAPI.@]
*
* See PathRemoveArgsA.
*/
void WINAPI PathRemoveArgsW(LPWSTR lpszPath)
{
TRACE("(%s)\n",debugstr_w(lpszPath));
if(lpszPath)
{
LPWSTR lpszArgs = PathGetArgsW(lpszPath);
if (*lpszArgs || (lpszArgs > lpszPath && lpszArgs[-1] == ' '))
lpszArgs[-1] = '\0';
}
}
/*************************************************************************
* PathRemoveExtensionA [SHLWAPI.@]
*
* Remove the file extension from a path
*
* PARAMS
* lpszPath [I/O] Path to remove the extension from
*
* RETURNS
* Nothing.
*/
void WINAPI PathRemoveExtensionA(LPSTR lpszPath)
{
TRACE("(%s)\n", debugstr_a(lpszPath));
if (lpszPath)
{
lpszPath = PathFindExtensionA(lpszPath);
*lpszPath = '\0';
}
}
/*************************************************************************
* PathRemoveExtensionW [SHLWAPI.@]
*
* See PathRemoveExtensionA.
*/
void WINAPI PathRemoveExtensionW(LPWSTR lpszPath)
{
TRACE("(%s)\n", debugstr_w(lpszPath));
if (lpszPath)
{
lpszPath = PathFindExtensionW(lpszPath);
*lpszPath = '\0';
}
}
/*************************************************************************
* PathRemoveBackslashA [SHLWAPI.@]
*
* Remove a trailing backslash from a path.
*
* PARAMS
* lpszPath [I/O] Path to remove backslash from
*
* RETURNS
* Success: A pointer to the end of the path
* Failure: NULL, if lpszPath is NULL
*/
LPSTR WINAPI PathRemoveBackslashA( LPSTR lpszPath )
{
LPSTR szTemp = NULL;
TRACE("(%s)\n", debugstr_a(lpszPath));
if(lpszPath)
{
szTemp = CharPrevA(lpszPath, lpszPath + strlen(lpszPath));
if (!PathIsRootA(lpszPath) && *szTemp == '\\')
*szTemp = '\0';
}
return szTemp;
}
/*************************************************************************
* PathRemoveBackslashW [SHLWAPI.@]
*
* See PathRemoveBackslashA.
*/
LPWSTR WINAPI PathRemoveBackslashW( LPWSTR lpszPath )
{
LPWSTR szTemp = NULL;
TRACE("(%s)\n", debugstr_w(lpszPath));
if(lpszPath)
{
szTemp = lpszPath + strlenW(lpszPath);
if (szTemp > lpszPath) szTemp--;
if (!PathIsRootW(lpszPath) && *szTemp == '\\')
*szTemp = '\0';
}
return szTemp;
}
/*************************************************************************
* PathRemoveBlanksA [SHLWAPI.@]
*
* Remove Spaces from the start and end of a path.
*
* PARAMS
* lpszPath [I/O] Path to strip blanks from
*
* RETURNS
* Nothing.
*/
VOID WINAPI PathRemoveBlanksA(LPSTR lpszPath)
{
TRACE("(%s)\n", debugstr_a(lpszPath));
if(lpszPath && *lpszPath)
{
LPSTR start = lpszPath;
while (*lpszPath == ' ')
lpszPath = CharNextA(lpszPath);
while(*lpszPath)
*start++ = *lpszPath++;
if (start != lpszPath)
while (start[-1] == ' ')
start--;
*start = '\0';
}
}
/*************************************************************************
* PathRemoveBlanksW [SHLWAPI.@]
*
* See PathRemoveBlanksA.
*/
VOID WINAPI PathRemoveBlanksW(LPWSTR lpszPath)
{
TRACE("(%s)\n", debugstr_w(lpszPath));
if(lpszPath && *lpszPath)
{
LPWSTR start = lpszPath;
while (*lpszPath == ' ')
lpszPath++;
while(*lpszPath)
*start++ = *lpszPath++;
if (start != lpszPath)
while (start[-1] == ' ')
start--;
*start = '\0';
}
}
/*************************************************************************
* PathQuoteSpacesA [SHLWAPI.@]
*
* Surround a path containg spaces in quotes.
*
* PARAMS
* lpszPath [I/O] Path to quote
*
* RETURNS
* Nothing.
*
* NOTES
* The path is not changed if it is invalid or has no spaces.
*/
VOID WINAPI PathQuoteSpacesA(LPSTR lpszPath)
{
TRACE("(%s)\n", debugstr_a(lpszPath));
if(lpszPath && StrChrA(lpszPath,' '))
{
size_t iLen = strlen(lpszPath) + 1;
if (iLen + 2 < MAX_PATH)
{
memmove(lpszPath + 1, lpszPath, iLen);
lpszPath[0] = '"';
lpszPath[iLen] = '"';
lpszPath[iLen + 1] = '\0';
}
}
}
/*************************************************************************
* PathQuoteSpacesW [SHLWAPI.@]
*
* See PathQuoteSpacesA.
*/
VOID WINAPI PathQuoteSpacesW(LPWSTR lpszPath)
{
TRACE("(%s)\n", debugstr_w(lpszPath));
if(lpszPath && StrChrW(lpszPath,' '))
{
int iLen = strlenW(lpszPath) + 1;
if (iLen + 2 < MAX_PATH)
{
memmove(lpszPath + 1, lpszPath, iLen * sizeof(WCHAR));
lpszPath[0] = '"';
lpszPath[iLen] = '"';
lpszPath[iLen + 1] = '\0';
}
}
}
/*************************************************************************
* PathUnquoteSpacesA [SHLWAPI.@]
*
* Remove quotes ("") from around a path, if present.
*
* PARAMS
* lpszPath [I/O] Path to strip quotes from
*
* RETURNS
* Nothing
*
* NOTES
* If the path contains a single quote only, an empty string will result.
* Otherwise quotes are only removed if they appear at the start and end
* of the path.
*/
VOID WINAPI PathUnquoteSpacesA(LPSTR lpszPath)
{
TRACE("(%s)\n", debugstr_a(lpszPath));
if (lpszPath && *lpszPath == '"')
{
DWORD dwLen = strlen(lpszPath) - 1;
if (lpszPath[dwLen] == '"')
{
lpszPath[dwLen] = '\0';
for (; *lpszPath; lpszPath++)
*lpszPath = lpszPath[1];
}
}
}
/*************************************************************************
* PathUnquoteSpacesW [SHLWAPI.@]
*
* See PathUnquoteSpacesA.
*/
VOID WINAPI PathUnquoteSpacesW(LPWSTR lpszPath)
{
TRACE("(%s)\n", debugstr_w(lpszPath));
if (lpszPath && *lpszPath == '"')
{
DWORD dwLen = strlenW(lpszPath) - 1;
if (lpszPath[dwLen] == '"')
{
lpszPath[dwLen] = '\0';
for (; *lpszPath; lpszPath++)
*lpszPath = lpszPath[1];
}
}
}
/*************************************************************************
* PathParseIconLocationA [SHLWAPI.@]
*
* Parse the location of an icon from a path.
*
* PARAMS
* lpszPath [I/O] The path to parse the icon location from.
*
* RETURNS
* Success: The number of the icon
* Failure: 0 if the path does not contain an icon location or is NULL
*
* NOTES
* The path has surrounding quotes and spaces removed regardless
* of whether the call succeeds or not.
*/
int WINAPI PathParseIconLocationA(LPSTR lpszPath)
{
int iRet = 0;
LPSTR lpszComma;
TRACE("(%s)\n", debugstr_a(lpszPath));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -