attrib: Use wide-char string literals.

Signed-off-by: Michael Stefaniuc <mstefani@winehq.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Michael Stefaniuc 2020-10-05 23:22:46 +02:00 committed by Alexandre Julliard
parent cc8adf7db1
commit 283dfa0f27
1 changed files with 10 additions and 22 deletions

View File

@ -24,8 +24,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(attrib); WINE_DEFAULT_DEBUG_CHANNEL(attrib);
static const WCHAR starW[] = {'*','\0'};
/* ========================================================================= /* =========================================================================
* Load a string from the resource file, handling any error * Load a string from the resource file, handling any error
* Returns string retrieved from resource file * Returns string retrieved from resource file
@ -33,11 +31,10 @@ static const WCHAR starW[] = {'*','\0'};
static WCHAR *ATTRIB_LoadMessage(UINT id) static WCHAR *ATTRIB_LoadMessage(UINT id)
{ {
static WCHAR msg[MAXSTRING]; static WCHAR msg[MAXSTRING];
const WCHAR failedMsg[] = {'F', 'a', 'i', 'l', 'e', 'd', '!', 0};
if (!LoadStringW(GetModuleHandleW(NULL), id, msg, ARRAY_SIZE(msg))) { if (!LoadStringW(GetModuleHandleW(NULL), id, msg, ARRAY_SIZE(msg))) {
WINE_FIXME("LoadString failed with %d\n", GetLastError()); WINE_FIXME("LoadString failed with %d\n", GetLastError());
lstrcpyW(msg, failedMsg); lstrcpyW(msg, L"Failed!");
} }
return msg; return msg;
} }
@ -144,8 +141,7 @@ static BOOL ATTRIB_processdirectory(const WCHAR *rootdir, const WCHAR *filespec,
WCHAR buffer[MAX_PATH]; WCHAR buffer[MAX_PATH];
HANDLE hff; HANDLE hff;
WIN32_FIND_DATAW fd; WIN32_FIND_DATAW fd;
WCHAR flags[] = {' ',' ',' ',' ',' ',' ',' ',' ','\0'}; WCHAR flags[] = L" ";
static const WCHAR slashW[] = {'\\','\0'};
WINE_TRACE("Processing dir '%s', spec '%s', %d,%x,%x\n", WINE_TRACE("Processing dir '%s', spec '%s', %d,%x,%x\n",
wine_dbgstr_w(rootdir), wine_dbgstr_w(filespec), wine_dbgstr_w(rootdir), wine_dbgstr_w(filespec),
@ -155,25 +151,22 @@ static BOOL ATTRIB_processdirectory(const WCHAR *rootdir, const WCHAR *filespec,
/* Build spec to search for */ /* Build spec to search for */
lstrcpyW(buffer, rootdir); lstrcpyW(buffer, rootdir);
lstrcatW(buffer, starW); lstrcatW(buffer, L"*");
/* Search for directories in the location and recurse if necessary */ /* Search for directories in the location and recurse if necessary */
WINE_TRACE("Searching for directories with '%s'\n", wine_dbgstr_w(buffer)); WINE_TRACE("Searching for directories with '%s'\n", wine_dbgstr_w(buffer));
hff = FindFirstFileW(buffer, &fd); hff = FindFirstFileW(buffer, &fd);
if (hff != INVALID_HANDLE_VALUE) { if (hff != INVALID_HANDLE_VALUE) {
do { do {
const WCHAR dot[] = {'.', 0};
const WCHAR dotdot[] = {'.', '.', 0};
/* Only interested in directories, and not . nor .. */ /* Only interested in directories, and not . nor .. */
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) || if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
!lstrcmpW(fd.cFileName, dot) || !lstrcmpW(fd.cFileName, dotdot)) !lstrcmpW(fd.cFileName, L".") || !lstrcmpW(fd.cFileName, L".."))
continue; continue;
/* Build new root dir to go searching in */ /* Build new root dir to go searching in */
lstrcpyW(buffer, rootdir); lstrcpyW(buffer, rootdir);
lstrcatW(buffer, fd.cFileName); lstrcatW(buffer, fd.cFileName);
lstrcatW(buffer, slashW); lstrcatW(buffer, L"\\");
ATTRIB_processdirectory(buffer, filespec, recurse, includedirs, ATTRIB_processdirectory(buffer, filespec, recurse, includedirs,
attrib_set, attrib_clear); attrib_set, attrib_clear);
@ -191,12 +184,10 @@ static BOOL ATTRIB_processdirectory(const WCHAR *rootdir, const WCHAR *filespec,
hff = FindFirstFileW(buffer, &fd); hff = FindFirstFileW(buffer, &fd);
if (hff != INVALID_HANDLE_VALUE) { if (hff != INVALID_HANDLE_VALUE) {
do { do {
const WCHAR dot[] = {'.', 0};
const WCHAR dotdot[] = {'.', '.', 0};
DWORD count; DWORD count;
WINE_TRACE("Found '%s'\n", wine_dbgstr_w(fd.cFileName)); WINE_TRACE("Found '%s'\n", wine_dbgstr_w(fd.cFileName));
if (!lstrcmpW(fd.cFileName, dot) || !lstrcmpW(fd.cFileName, dotdot)) if (!lstrcmpW(fd.cFileName, L".") || !lstrcmpW(fd.cFileName, L".."))
continue; continue;
if (!includedirs && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) if (!includedirs && (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
@ -212,7 +203,6 @@ static BOOL ATTRIB_processdirectory(const WCHAR *rootdir, const WCHAR *filespec,
SetFileAttributesW(buffer, fd.dwFileAttributes); SetFileAttributesW(buffer, fd.dwFileAttributes);
found = TRUE; found = TRUE;
} else { } else {
static const WCHAR fmt[] = {'%','1',' ',' ',' ',' ',' ','%','2','\n','\0'};
if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) { if (fd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {
flags[4] = 'H'; flags[4] = 'H';
} }
@ -233,7 +223,7 @@ static BOOL ATTRIB_processdirectory(const WCHAR *rootdir, const WCHAR *filespec,
} }
lstrcpyW(buffer, rootdir); lstrcpyW(buffer, rootdir);
lstrcatW(buffer, fd.cFileName); lstrcatW(buffer, fd.cFileName);
ATTRIB_wprintf(fmt, flags, buffer); ATTRIB_wprintf(L"%1 %2\n", flags, buffer);
for (count = 0; count < (ARRAY_SIZE(flags) - 1); count++) flags[count] = ' '; for (count = 0; count < (ARRAY_SIZE(flags) - 1); count++) flags[count] = ' ';
found = TRUE; found = TRUE;
} }
@ -253,18 +243,16 @@ int __cdecl wmain(int argc, WCHAR *argv[])
DWORD attrib_clear = 0; DWORD attrib_clear = 0;
BOOL attrib_recurse = FALSE; BOOL attrib_recurse = FALSE;
BOOL attrib_includedirs = FALSE; BOOL attrib_includedirs = FALSE;
static const WCHAR help_option[] = {'/','?','\0'};
static const WCHAR wildcardsW[] = {'*','?','\0'};
int i = 1; int i = 1;
BOOL found = FALSE; BOOL found = FALSE;
if ((argc >= 2) && !lstrcmpW(argv[1], help_option)) { if ((argc >= 2) && !lstrcmpW(argv[1], L"/?")) {
ATTRIB_wprintf(ATTRIB_LoadMessage(STRING_HELP)); ATTRIB_wprintf(ATTRIB_LoadMessage(STRING_HELP));
return 0; return 0;
} }
/* By default all files from current directory are taken into account */ /* By default all files from current directory are taken into account */
lstrcpyW(name, starW); lstrcpyW(name, L"*");
while (i < argc) { while (i < argc) {
WCHAR *param = argv[i++]; WCHAR *param = argv[i++];
@ -311,7 +299,7 @@ int __cdecl wmain(int argc, WCHAR *argv[])
/* If a directory is explicitly supplied on the command line, and no /* If a directory is explicitly supplied on the command line, and no
wildcards are in the name, then allow it to be changed/displayed */ wildcards are in the name, then allow it to be changed/displayed */
if (wcspbrk(originalname, wildcardsW) == NULL) attrib_includedirs = TRUE; if (wcspbrk(originalname, L"*?") == NULL) attrib_includedirs = TRUE;
/* Do all the processing based on the filename arg */ /* Do all the processing based on the filename arg */
found = ATTRIB_processdirectory(curdir, name, attrib_recurse, found = ATTRIB_processdirectory(curdir, name, attrib_recurse,