Commit e737aafa authored by Gijs Vermeulen's avatar Gijs Vermeulen Committed by Alexandre Julliard

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

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