cmd: Use wide character string literals in directory.c.

Signed-off-by: Gijs Vermeulen <gijsvrm@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Gijs Vermeulen 2020-03-24 21:12:51 +01:00 committed by Alexandre Julliard
parent 5fd548fc9b
commit e737aafa8e
1 changed files with 19 additions and 49 deletions

View File

@ -220,8 +220,7 @@ static void WCMD_getfileowner(WCHAR *filename, WCHAR *owner, int ownerlen) {
/* Convert to a username */
if (LookupAccountSidW(NULL, pSID, name, &nameLen, domain, &domainLen, &nameuse)) {
static const WCHAR fmt[] = {'%','s','%','c','%','s','\0'};
swprintf(owner, ownerlen, fmt, domain, '\\', name);
swprintf(owner, ownerlen, L"%s%c%s", domain, '\\', name);
}
heap_free(secBuffer);
}
@ -253,10 +252,6 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
int concurrentDirs = 0;
BOOL done_header = FALSE;
static const WCHAR fmtDir[] = {'%','1','!','1','0','s','!',' ',' ','%','2','!','8','s','!',' ',' ',
'<','D','I','R','>',' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
static const WCHAR fmtFile[] = {'%','1','!','1','0','s','!',' ',' ','%','2','!','8','s','!',' ',' ',
' ',' ','%','3','!','1','0','s','!',' ',' ','\0'};
static const WCHAR fmt2[] = {'%','1','!','-','1','3','s','!','\0'};
static const WCHAR fmt3[] = {'%','1','!','-','2','3','s','!','\0'};
static const WCHAR fmt4[] = {'%','1','\0'};
@ -317,9 +312,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
if (!bare) {
if (level != 0 && (entry_count > 0)) WCMD_output_asis (newlineW);
if (!recurse || ((entry_count > 0) && done_header==FALSE)) {
static const WCHAR headerW[] = {'D','i','r','e','c','t','o','r','y',' ','o','f',
' ','%','1','\n','\n','\0'};
WCMD_output (headerW, real_path);
WCMD_output (L"Directory of %1\n\n", real_path);
done_header = TRUE;
}
}
@ -388,13 +381,11 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
tmp_width = cur_width;
if (fd[i].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
static const WCHAR fmt[] = {'[','%','1',']','\0'};
WCMD_output (fmt, fd[i].cFileName);
WCMD_output (L"[%1]", fd[i].cFileName);
dir_count++;
tmp_width = tmp_width + lstrlenW(fd[i].cFileName) + 2;
} else {
static const WCHAR fmt[] = {'%','1','\0'};
WCMD_output (fmt, fd[i].cFileName);
WCMD_output (L"%1", fd[i].cFileName);
tmp_width = tmp_width + lstrlenW(fd[i].cFileName) ;
file_count++;
file_size.u.LowPart = fd[i].nFileSizeLow;
@ -406,15 +397,14 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
if ((cur_width + widest) > max_width) {
cur_width = 0;
} else {
static const WCHAR padfmt[] = {'%','1','!','*','s','!','\0'};
WCMD_output(padfmt, cur_width - tmp_width, nullW);
WCMD_output(L"%1!*s!", cur_width - tmp_width, nullW);
}
} else if (fd[i].dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
dir_count++;
if (!bare) {
WCMD_output (fmtDir, datestring, timestring);
WCMD_output (L"%1!10s! %2!8s! <DIR> ", datestring, timestring);
if (shortname) WCMD_output (fmt2, fd[i].cAlternateFileName);
if (usernames) WCMD_output (fmt3, username);
WCMD_output(fmt4,fd[i].cFileName);
@ -433,7 +423,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
file_size.u.HighPart = fd[i].nFileSizeHigh;
byte_count.QuadPart += file_size.QuadPart;
if (!bare) {
WCMD_output (fmtFile, datestring, timestring,
WCMD_output (L"%1!10s! %2!8s! %3!10s! ", datestring, timestring,
WCMD_filesize64(file_size.QuadPart));
if (shortname) WCMD_output (fmt2, fd[i].cAlternateFileName);
if (usernames) WCMD_output (fmt3, username);
@ -449,14 +439,10 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
if (!bare) {
if (file_count == 1) {
static const WCHAR fmt[] = {' ',' ',' ',' ',' ',' ',' ','1',' ','f','i','l','e',' ',
'%','1','!','2','5','s','!',' ','b','y','t','e','s','\n','\0'};
WCMD_output (fmt, WCMD_filesize64 (byte_count.QuadPart));
WCMD_output (L" 1 file %1!25s! bytes\n", WCMD_filesize64 (byte_count.QuadPart));
}
else {
static const WCHAR fmt[] = {'%','1','!','8','d','!',' ','f','i','l','e','s',' ','%','2','!','2','4','s','!',
' ','b','y','t','e','s','\n','\0'};
WCMD_output (fmt, file_count, WCMD_filesize64 (byte_count.QuadPart));
WCMD_output (L"%1!8d! files %2!24s! bytes\n", file_count, WCMD_filesize64 (byte_count.QuadPart));
}
}
byte_total = byte_total + byte_count.QuadPart;
@ -465,13 +451,9 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
if (!bare && !recurse) {
if (dir_count == 1) {
static const WCHAR fmt[] = {'%','1','!','8','d','!',' ','d','i','r','e','c','t','o','r','y',
' ',' ',' ',' ',' ',' ',' ',' ',' ','\0'};
WCMD_output (fmt, 1);
WCMD_output (L"%1!8d! directory ", 1);
} else {
static const WCHAR fmt[] = {'%','1','!','8','d','!',' ','d','i','r','e','c','t','o','r','i',
'e','s','\0'};
WCMD_output (fmt, dir_count);
WCMD_output (L"%1!8d! directories", dir_count);
}
}
}
@ -555,7 +537,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le
static void WCMD_dir_trailer(WCHAR drive) {
ULARGE_INTEGER avail, total, freebytes;
DWORD status;
WCHAR driveName[] = {'c',':','\\','\0'};
WCHAR driveName[] = L"c:\\";
driveName[0] = drive;
status = GetDiskFreeSpaceExW(driveName, &avail, &total, &freebytes);
@ -564,18 +546,10 @@ static void WCMD_dir_trailer(WCHAR drive) {
if (errorlevel==0 && !bare) {
if (recurse) {
static const WCHAR fmt1[] = {'\n',' ',' ',' ',' ',' ','T','o','t','a','l',' ','f','i','l','e','s',
' ','l','i','s','t','e','d',':','\n','%','1','!','8','d','!',' ','f','i','l','e',
's','%','2','!','2','5','s','!',' ','b','y','t','e','s','\n','\0'};
static const WCHAR fmt2[] = {'%','1','!','8','d','!',' ','d','i','r','e','c','t','o','r','i','e','s',' ','%',
'2','!','1','8','s','!',' ','b','y','t','e','s',' ','f','r','e','e','\n','\n',
'\0'};
WCMD_output (fmt1, file_total, WCMD_filesize64 (byte_total));
WCMD_output (fmt2, dir_total, WCMD_filesize64 (freebytes.QuadPart));
WCMD_output (L"\n Total files listed:\n%1!8d! files%2!25s! bytes\n", file_total, WCMD_filesize64 (byte_total));
WCMD_output (L"%1!8d! directories %2!18s! bytes free\n\n", dir_total, WCMD_filesize64 (freebytes.QuadPart));
} else {
static const WCHAR fmt[] = {' ','%','1','!','1','8','s','!',' ','b','y','t','e','s',' ','f','r','e','e',
'\n','\n','\0'};
WCMD_output (fmt, WCMD_filesize64 (freebytes.QuadPart));
WCMD_output (L" %1!18s! bytes free\n\n", WCMD_filesize64 (freebytes.QuadPart));
}
}
}
@ -605,12 +579,11 @@ void WCMD_directory (WCHAR *args)
WCHAR dir[MAX_PATH];
WCHAR fname[MAX_PATH];
WCHAR ext[MAX_PATH];
static const WCHAR dircmdW[] = {'D','I','R','C','M','D','\0'};
errorlevel = 0;
/* Prefill quals with (uppercased) DIRCMD env var */
if (GetEnvironmentVariableW(dircmdW, string, ARRAY_SIZE(string))) {
if (GetEnvironmentVariableW(L"DIRCMD", string, ARRAY_SIZE(string))) {
p = string;
while ( (*p = toupper(*p)) ) ++p;
lstrcatW(string,quals);
@ -804,11 +777,9 @@ void WCMD_directory (WCHAR *args)
lstrcpyW(fullname, thisArg);
} else if (thisArg[1] == ':' && thisArg[2] != '\\') {
WCHAR envvar[4];
static const WCHAR envFmt[] = {'=','%','c',':','\0'};
wsprintfW(envvar, envFmt, thisArg[0]);
wsprintfW(envvar, L"=%c:", thisArg[0]);
if (!GetEnvironmentVariableW(envvar, fullname, MAX_PATH)) {
static const WCHAR noEnvFmt[] = {'%','c',':','\0'};
wsprintfW(fullname, noEnvFmt, thisArg[0]);
wsprintfW(fullname, L"%c:", thisArg[0]);
}
lstrcatW(fullname, slashW);
lstrcatW(fullname, &thisArg[2]);
@ -906,8 +877,7 @@ void WCMD_directory (WCHAR *args)
}
}
} else {
static const WCHAR newLine2[] = {'\n','\n','\0'};
if (!bare) WCMD_output_asis (newLine2);
if (!bare) WCMD_output_asis (L"\n\n");
}
/* Clear any errors from previous invocations, and process it */