Signed-off-by: Michael Stefaniuc mstefani@winehq.org --- programs/cmd/batch.c | 2 +- programs/cmd/builtins.c | 150 ++++++++++++++++++++--------------------------- programs/cmd/directory.c | 12 ++-- programs/cmd/wcmdmain.c | 66 ++++++++++----------- 4 files changed, 102 insertions(+), 128 deletions(-)
diff --git a/programs/cmd/batch.c b/programs/cmd/batch.c index 1a78b55557..14e2539bf7 100644 --- a/programs/cmd/batch.c +++ b/programs/cmd/batch.c @@ -599,7 +599,7 @@ void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute) if (memchrW(firstModifier, 's', modifierLen) != NULL) { if (finaloutput[0] != 0x00) strcatW(finaloutput, spaceW); /* Don't flag as doneModifier - %~s on its own is processed later */ - GetShortPathNameW(outputparam, outputparam, sizeof(outputparam)/sizeof(outputparam[0])); + GetShortPathNameW(outputparam, outputparam, ARRAY_SIZE(outputparam)); }
/* 5. Handle 'f' : Fully qualified path (File doesn't have to exist) */ diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 088632f214..1da61556d9 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -191,12 +191,12 @@ static BOOL WCMD_ask_confirm (const WCHAR *message, BOOL showSureText,
/* Load the translated valid answers */ if (showSureText) - LoadStringW(hinst, WCMD_CONFIRM, confirm, sizeof(confirm)/sizeof(WCHAR)); + LoadStringW(hinst, WCMD_CONFIRM, confirm, ARRAY_SIZE(confirm)); msgid = optionAll ? WCMD_YESNOALL : WCMD_YESNO; - LoadStringW(hinst, msgid, options, sizeof(options)/sizeof(WCHAR)); - LoadStringW(hinst, WCMD_YES, Ybuffer, sizeof(Ybuffer)/sizeof(WCHAR)); - LoadStringW(hinst, WCMD_NO, Nbuffer, sizeof(Nbuffer)/sizeof(WCHAR)); - LoadStringW(hinst, WCMD_ALL, Abuffer, sizeof(Abuffer)/sizeof(WCHAR)); + LoadStringW(hinst, msgid, options, ARRAY_SIZE(options)); + LoadStringW(hinst, WCMD_YES, Ybuffer, ARRAY_SIZE(Ybuffer)); + LoadStringW(hinst, WCMD_NO, Nbuffer, ARRAY_SIZE(Nbuffer)); + LoadStringW(hinst, WCMD_ALL, Abuffer, ARRAY_SIZE(Abuffer));
/* Loop waiting on a valid answer */ if (optionAll) @@ -207,7 +207,7 @@ static BOOL WCMD_ask_confirm (const WCHAR *message, BOOL showSureText, if (showSureText) WCMD_output_asis (confirm); WCMD_output_asis (options); - WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), answer, sizeof(answer)/sizeof(WCHAR), &count); + WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), answer, ARRAY_SIZE(answer), &count); answer[0] = toupperW(answer[0]); if (answer[0] == Ybuffer[0]) return TRUE; @@ -370,8 +370,8 @@ void WCMD_choice (const WCHAR * args) {
/* use default keys, when needed: localized versions of "Y"es and "No" */ if (!opt_c) { - LoadStringW(hinst, WCMD_YES, buffer, sizeof(buffer)/sizeof(WCHAR)); - LoadStringW(hinst, WCMD_NO, buffer + 1, sizeof(buffer)/sizeof(WCHAR) - 1); + LoadStringW(hinst, WCMD_YES, buffer, ARRAY_SIZE(buffer)); + LoadStringW(hinst, WCMD_NO, buffer + 1, ARRAY_SIZE(buffer) - 1); opt_c = buffer; buffer[2] = 0; } @@ -793,8 +793,8 @@ void WCMD_copy(WCHAR * args) { /* If COPYCMD is set, then we force the overwrite with /Y and ask for * confirmation with /-Y. If COPYCMD is neither of those, then we use the * default behavior. */ - len = GetEnvironmentVariableW(copyCmdW, copycmd, sizeof(copycmd)/sizeof(WCHAR)); - if (len && len < (sizeof(copycmd)/sizeof(WCHAR))) { + len = GetEnvironmentVariableW(copyCmdW, copycmd, ARRAY_SIZE(copycmd)); + if (len && len < ARRAY_SIZE(copycmd)) { if (!lstrcmpiW (copycmd, parmY)) prompt = FALSE; else if (!lstrcmpiW (copycmd, parmNoY)) @@ -825,7 +825,7 @@ void WCMD_copy(WCHAR * args) { WINE_TRACE("Destination supplied, processing to see if file or directory\n");
/* Convert to fully qualified path/filename */ - GetFullPathNameW(destination->name, sizeof(destname)/sizeof(WCHAR), destname, &filenamepart); + GetFullPathNameW(destination->name, ARRAY_SIZE(destname), destname, &filenamepart); WINE_TRACE("Full dest name is '%s'\n", wine_dbgstr_w(destname));
/* If parameter is a directory, ensure it ends in \ */ @@ -907,7 +907,7 @@ void WCMD_copy(WCHAR * args) {
/* Convert to fully qualified path/filename in srcpath, file filenamepart pointing to where the filename portion begins (used for wildcard expansion). */ - GetFullPathNameW(thiscopy->name, sizeof(srcpath)/sizeof(WCHAR), srcpath, &filenamepart); + GetFullPathNameW(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart); WINE_TRACE("Full src name is '%s'\n", wine_dbgstr_w(srcpath));
/* If parameter is a directory, ensure it ends in * */ @@ -917,7 +917,7 @@ void WCMD_copy(WCHAR * args) { /* We need to know where the filename part starts, so append * and recalculate the full resulting path */ strcatW(thiscopy->name, starW); - GetFullPathNameW(thiscopy->name, sizeof(srcpath)/sizeof(WCHAR), srcpath, &filenamepart); + GetFullPathNameW(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart); WINE_TRACE("Directory, so full name is now '%s'\n", wine_dbgstr_w(srcpath));
} else if ((strpbrkW(srcpath, wildcardsW) == NULL) && @@ -927,7 +927,7 @@ void WCMD_copy(WCHAR * args) { /* We need to know where the filename part starts, so append * and recalculate the full resulting path */ strcatW(thiscopy->name, slashstarW); - GetFullPathNameW(thiscopy->name, sizeof(srcpath)/sizeof(WCHAR), srcpath, &filenamepart); + GetFullPathNameW(thiscopy->name, ARRAY_SIZE(srcpath), srcpath, &filenamepart); WINE_TRACE("Directory, so full name is now '%s'\n", wine_dbgstr_w(srcpath)); }
@@ -1216,7 +1216,7 @@ static BOOL WCMD_delete_confirm_wildcard(const WCHAR *filename, BOOL *pPrompted) WCHAR fpath[MAX_PATH];
/* Convert path into actual directory spec */ - GetFullPathNameW(filename, sizeof(fpath)/sizeof(WCHAR), fpath, NULL); + GetFullPathNameW(filename, ARRAY_SIZE(fpath), fpath, NULL); WCMD_splitpath(fpath, drive, dir, fname, ext);
/* Only prompt for * and *.*, not *a, a*, *.a* etc */ @@ -1351,7 +1351,7 @@ static BOOL WCMD_delete_one (const WCHAR *thisArg) { WCHAR ext[MAX_PATH];
/* Convert path into actual directory spec */ - GetFullPathNameW(argCopy, sizeof(thisDir)/sizeof(WCHAR), thisDir, NULL); + GetFullPathNameW(argCopy, ARRAY_SIZE(thisDir), thisDir, NULL); WCMD_splitpath(thisDir, drive, dir, fname, ext);
strcpyW(thisDir, drive); @@ -1598,16 +1598,13 @@ static void WCMD_part_execute(CMD_LIST **cmdList, const WCHAR *firstcmd,
/* End of the command - does 'ELSE ' follow as the next command? */ } else { - if (isIF - && WCMD_keyword_ws_found(ifElse, sizeof(ifElse)/sizeof(ifElse[0]), - (*cmdList)->command)) { - + if (isIF && WCMD_keyword_ws_found(ifElse, ARRAY_SIZE(ifElse), (*cmdList)->command)) { /* Swap between if and else processing */ processThese = !executecmds;
/* Process the ELSE part */ if (processThese) { - const int keyw_len = sizeof(ifElse)/sizeof(ifElse[0]) + 1; + const int keyw_len = ARRAY_SIZE(ifElse) + 1; WCHAR *cmd = ((*cmdList)->command) + keyw_len;
/* Skip leading whitespace between condition and the command */ @@ -1692,39 +1689,35 @@ static BOOL WCMD_parse_forf_options(WCHAR *options, WCHAR *eol, int *skip,
/* Save End of line character (Ignore line if first token (based on delims) starts with it) */ } else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, - pos, sizeof(eolW)/sizeof(WCHAR), - eolW, sizeof(eolW)/sizeof(WCHAR)) == CSTR_EQUAL) { - *eol = *(pos + sizeof(eolW)/sizeof(WCHAR)); - pos = pos + sizeof(eolW)/sizeof(WCHAR) + 1; + pos, ARRAY_SIZE(eolW), eolW, ARRAY_SIZE(eolW)) == CSTR_EQUAL) { + *eol = *(pos + ARRAY_SIZE(eolW)); + pos = pos + ARRAY_SIZE(eolW) + 1; WINE_TRACE("Found eol as %c(%x)\n", *eol, *eol);
/* Save number of lines to skip (Can be in base 10, hex (0x...) or octal (0xx) */ } else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, - pos, sizeof(skipW)/sizeof(WCHAR), - skipW, sizeof(skipW)/sizeof(WCHAR)) == CSTR_EQUAL) { + pos, ARRAY_SIZE(skipW), skipW, ARRAY_SIZE(skipW)) == CSTR_EQUAL) { WCHAR *nextchar = NULL; - pos = pos + sizeof(skipW)/sizeof(WCHAR); + pos = pos + ARRAY_SIZE(skipW); *skip = strtoulW(pos, &nextchar, 0); WINE_TRACE("Found skip as %d lines\n", *skip); pos = nextchar;
/* Save if usebackq semantics are in effect */ - } else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, - pos, sizeof(usebackqW)/sizeof(WCHAR), - usebackqW, sizeof(usebackqW)/sizeof(WCHAR)) == CSTR_EQUAL) { + } else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, pos, + ARRAY_SIZE(usebackqW), usebackqW, ARRAY_SIZE(usebackqW)) == CSTR_EQUAL) { *usebackq = TRUE; - pos = pos + sizeof(usebackqW)/sizeof(WCHAR); + pos = pos + ARRAY_SIZE(usebackqW); WINE_TRACE("Found usebackq\n");
/* Save the supplied delims. Slightly odd as space can be a delimiter but only if you finish the optionsroot string with delims= otherwise the space is just a token delimiter! */ } else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, - pos, sizeof(delimsW)/sizeof(WCHAR), - delimsW, sizeof(delimsW)/sizeof(WCHAR)) == CSTR_EQUAL) { + pos, ARRAY_SIZE(delimsW), delimsW, ARRAY_SIZE(delimsW)) == CSTR_EQUAL) { int i=0;
- pos = pos + sizeof(delimsW)/sizeof(WCHAR); + pos = pos + ARRAY_SIZE(delimsW); while (*pos && *pos != ' ') { delims[i++] = *pos; pos++; @@ -1735,11 +1728,10 @@ static BOOL WCMD_parse_forf_options(WCHAR *options, WCHAR *eol, int *skip,
/* Save the tokens being requested */ } else if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, - pos, sizeof(tokensW)/sizeof(WCHAR), - tokensW, sizeof(tokensW)/sizeof(WCHAR)) == CSTR_EQUAL) { + pos, ARRAY_SIZE(tokensW), tokensW, ARRAY_SIZE(tokensW)) == CSTR_EQUAL) { int i=0;
- pos = pos + sizeof(tokensW)/sizeof(WCHAR); + pos = pos + ARRAY_SIZE(tokensW); while (*pos && *pos != ' ') { tokens[i++] = *pos; pos++; @@ -2086,7 +2078,7 @@ static HANDLE WCMD_forf_getinputhandle(BOOL usebackq, WCHAR *itemstr, BOOL iscmd
if (iscmd) { /* Get temp filename */ - GetTempPathW(sizeof(temp_str)/sizeof(WCHAR), temp_str); + GetTempPathW(ARRAY_SIZE(temp_str), temp_str); GetTempFileNameW(temp_str, cmdW, 0, temp_file);
/* Redirect output to the temporary file */ @@ -2170,7 +2162,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { /* When recursing directories, use current directory as the starting point unless subsequently overridden */ doRecurse = (toupperW(*thisArg) == 'R'); - if (doRecurse) GetCurrentDirectoryW(sizeof(optionsRoot)/sizeof(WCHAR), optionsRoot); + if (doRecurse) GetCurrentDirectoryW(ARRAY_SIZE(optionsRoot), optionsRoot);
doFileset = (toupperW(*thisArg) == 'F');
@@ -2227,8 +2219,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { thisArg = WCMD_parameter(p, parameterNo++, NULL, FALSE, FALSE); if (!thisArg || !(CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, - thisArg, sizeof(inW)/sizeof(inW[0]), inW, - sizeof(inW)/sizeof(inW[0])) == CSTR_EQUAL)) { + thisArg, ARRAY_SIZE(inW), inW, ARRAY_SIZE(inW)) == CSTR_EQUAL)) { WCMD_output_stderr (WCMD_LoadMessage(WCMD_SYNTAXERR)); return; } @@ -2253,9 +2244,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { /* Syntax error if missing close bracket, or nothing following it and once we have the complete set, we expect a DO */ WINE_TRACE("Looking for 'do ' in %p\n", *cmdList); - if ((*cmdList == NULL) - || !WCMD_keyword_ws_found(doW, sizeof(doW)/sizeof(doW[0]), (*cmdList)->command)) { - + if ((*cmdList == NULL) || !WCMD_keyword_ws_found(doW, ARRAY_SIZE(doW), (*cmdList)->command)) { WCMD_output_stderr (WCMD_LoadMessage(WCMD_SYNTAXERR)); return; } @@ -2418,7 +2407,7 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { } else {
/* Read line by line until end of file */ - while (WCMD_fgets(buffer, sizeof(buffer)/sizeof(WCHAR), input)) { + while (WCMD_fgets(buffer, ARRAY_SIZE(buffer), input)) { WCMD_parse_line(cmdStart, firstCmd, &cmdEnd, variable[1], buffer, &doExecuted, &forf_skip, forf_eol, forf_delims, forf_tokens); buffer[0] = 0; @@ -2549,7 +2538,7 @@ void WCMD_give_help (const WCHAR *args) } } /* Launch the command with the /? option for external commands shipped with cmd.exe */ - for (i = 0; i <= (sizeof(externals)/sizeof(externals[0])); i++) { + for (i = 0; i <= ARRAY_SIZE(externals); i++) { if (CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE | SORT_STRINGSORT, args, -1, externals[i], -1) == CSTR_EQUAL) { WCHAR cmd[128]; @@ -2622,7 +2611,7 @@ void WCMD_goto (CMD_LIST **cmdList) { if (loop==1) SetFilePointer (context -> h, 0, NULL, FILE_BEGIN); }
- while (WCMD_fgets (string, sizeof(string)/sizeof(WCHAR), context -> h)) { + while (WCMD_fgets (string, ARRAY_SIZE(string), context -> h)) { str = string;
/* Ignore leading whitespace or no-echo character */ @@ -2947,8 +2936,8 @@ void WCMD_move (void)
/* If 2nd parm is directory, then use original filename */ /* Convert partial path to full path */ - GetFullPathNameW(param1, sizeof(input)/sizeof(WCHAR), input, NULL); - GetFullPathNameW(param2, sizeof(output)/sizeof(WCHAR), output, NULL); + GetFullPathNameW(param1, ARRAY_SIZE(input), input, NULL); + GetFullPathNameW(param2, ARRAY_SIZE(output), output, NULL); WINE_TRACE("Move from '%s'('%s') to '%s'\n", wine_dbgstr_w(input), wine_dbgstr_w(param1), wine_dbgstr_w(output));
@@ -3000,9 +2989,8 @@ void WCMD_move (void) force = TRUE; else { static const WCHAR copyCmdW[] = {'C','O','P','Y','C','M','D','\0'}; - len = GetEnvironmentVariableW(copyCmdW, copycmd, sizeof(copycmd)/sizeof(WCHAR)); - force = (len && len < (sizeof(copycmd)/sizeof(WCHAR)) - && ! lstrcmpiW (copycmd, parmY)); + len = GetEnvironmentVariableW(copyCmdW, copycmd, ARRAY_SIZE(copycmd)); + force = (len && len < ARRAY_SIZE(copycmd) && !lstrcmpiW(copycmd, parmY)); }
/* Prompt if overwriting */ @@ -3169,7 +3157,7 @@ void WCMD_rename (void) }
/* Convert partial path to full path */ - GetFullPathNameW(param1, sizeof(input)/sizeof(WCHAR), input, NULL); + GetFullPathNameW(param1, ARRAY_SIZE(input), input, NULL); WINE_TRACE("Rename from '%s'('%s') to '%s'\n", wine_dbgstr_w(input), wine_dbgstr_w(param1), wine_dbgstr_w(param2)); dotDst = strchrW(param2, '.'); @@ -3427,7 +3415,7 @@ void WCMD_setshow_default (const WCHAR *args) { args++; }
- GetCurrentDirectoryW(sizeof(cwd)/sizeof(WCHAR), cwd); + GetCurrentDirectoryW(ARRAY_SIZE(cwd), cwd); if (strlenW(args) == 0) { strcatW (cwd, newlineW); WCMD_output_asis (cwd); @@ -3458,7 +3446,7 @@ void WCMD_setshow_default (const WCHAR *args) { static const WCHAR fmt[] = {'%','s','%','s','%','s','\0'};
/* Convert path into actual directory spec */ - GetFullPathNameW(string, sizeof(fpath)/sizeof(WCHAR), fpath, NULL); + GetFullPathNameW(string, ARRAY_SIZE(fpath), fpath, NULL); WCMD_splitpath(fpath, drive, dir, fname, ext);
/* Rebuild path */ @@ -3480,7 +3468,7 @@ void WCMD_setshow_default (const WCHAR *args) { } else {
/* Save away the actual new directory, to store as current location */ - GetCurrentDirectoryW (sizeof(string)/sizeof(WCHAR), string); + GetCurrentDirectoryW(ARRAY_SIZE(string), string);
/* Restore old directory if drive letter would change, and CD x:\directory /D (or pushd c:\directory) not supplied */ @@ -3521,12 +3509,11 @@ void WCMD_setshow_date (void) { static const WCHAR parmT[] = {'/','T','\0'};
if (strlenW(param1) == 0) { - if (GetDateFormatW(LOCALE_USER_DEFAULT, 0, NULL, NULL, - curdate, sizeof(curdate)/sizeof(WCHAR))) { + if (GetDateFormatW(LOCALE_USER_DEFAULT, 0, NULL, NULL, curdate, ARRAY_SIZE(curdate))) { WCMD_output (WCMD_LoadMessage(WCMD_CURRENTDATE), curdate); if (strstrW (quals, parmT) == NULL) { WCMD_output (WCMD_LoadMessage(WCMD_NEWDATE)); - WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer)/sizeof(WCHAR), &count); + WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, ARRAY_SIZE(buffer), &count); if (count > 2) { WCMD_output_stderr (WCMD_LoadMessage(WCMD_NYI)); } @@ -4166,7 +4153,7 @@ void WCMD_setshow_env (WCHAR *s) { if (strlenW(p) != 0) WCMD_output_asis(p);
/* Read the reply */ - WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string)/sizeof(WCHAR), &count); + WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), string, ARRAY_SIZE(string), &count); if (count > 1) { string[count-1] = '\0'; /* ReadFile output is not null-terminated! */ if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */ @@ -4263,7 +4250,7 @@ void WCMD_setshow_path (const WCHAR *args) { static const WCHAR pathEqW[] = {'P','A','T','H','=','\0'};
if (strlenW(param1) == 0 && strlenW(param2) == 0) { - status = GetEnvironmentVariableW(pathW, string, sizeof(string)/sizeof(WCHAR)); + status = GetEnvironmentVariableW(pathW, string, ARRAY_SIZE(string)); if (status != 0) { WCMD_output_asis ( pathEqW); WCMD_output_asis ( string); @@ -4320,12 +4307,11 @@ void WCMD_setshow_time (void) {
if (strlenW(param1) == 0) { GetLocalTime(&st); - if (GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, - curtime, sizeof(curtime)/sizeof(WCHAR))) { + if (GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &st, NULL, curtime, ARRAY_SIZE(curtime))) { WCMD_output (WCMD_LoadMessage(WCMD_CURRENTTIME), curtime); if (strstrW (quals, parmT) == NULL) { WCMD_output (WCMD_LoadMessage(WCMD_NEWTIME)); - WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer)/sizeof(WCHAR), &count); + WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, ARRAY_SIZE(buffer), &count); if (count > 2) { WCMD_output_stderr (WCMD_LoadMessage(WCMD_NYI)); } @@ -4547,7 +4533,7 @@ void WCMD_type (WCHAR *args) { static const WCHAR fmt[] = {'\n','%','1','\n','\n','\0'}; WCMD_output(fmt, thisArg); } - while (WCMD_ReadFile(h, buffer, sizeof(buffer)/sizeof(WCHAR) - 1, &count)) { + while (WCMD_ReadFile(h, buffer, ARRAY_SIZE(buffer) - 1, &count)) { if (count == 0) break; /* ReadFile reports success on EOF! */ buffer[count] = 0; WCMD_output_asis (buffer); @@ -4580,8 +4566,7 @@ void WCMD_more (WCHAR *args) { /* Prefix the NLS more with '-- ', then load the text */ errorlevel = 0; strcpyW(moreStr, moreStart); - LoadStringW(hinst, WCMD_MORESTR, &moreStr[3], - (sizeof(moreStr)/sizeof(WCHAR))-3); + LoadStringW(hinst, WCMD_MORESTR, &moreStr[3], ARRAY_SIZE(moreStr)-3);
if (param1[0] == 0x00) {
@@ -4601,7 +4586,7 @@ void WCMD_more (WCHAR *args) { wsprintfW(moreStrPage, moreFmt, moreStr);
WCMD_enter_paged_mode(moreStrPage); - while (WCMD_ReadFile(hstdin, buffer, (sizeof(buffer)/sizeof(WCHAR))-1, &count)) { + while (WCMD_ReadFile(hstdin, buffer, ARRAY_SIZE(buffer)-1, &count)) { if (count == 0) break; /* ReadFile reports success on EOF! */ buffer[count] = 0; WCMD_output_asis (buffer); @@ -4632,7 +4617,7 @@ void WCMD_more (WCHAR *args) { wsprintfW(moreStrPage, moreFmt2, moreStr, 100); WCMD_leave_paged_mode(); WCMD_output_asis(moreStrPage); - WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, sizeof(buffer)/sizeof(WCHAR), &count); + WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), buffer, ARRAY_SIZE(buffer), &count); WCMD_enter_paged_mode(moreStrPage); }
@@ -4654,7 +4639,7 @@ void WCMD_more (WCHAR *args) { fileLen = (((ULONG64)fileInfo.nFileSizeHigh) << 32) + fileInfo.nFileSizeLow;
needsPause = TRUE; - while (WCMD_ReadFile(h, buffer, (sizeof(buffer)/sizeof(WCHAR))-1, &count)) { + while (WCMD_ReadFile(h, buffer, ARRAY_SIZE(buffer)-1, &count)) { if (count == 0) break; /* ReadFile reports success on EOF! */ buffer[count] = 0; curPos += count; @@ -4728,13 +4713,12 @@ int WCMD_volume(BOOL set_label, const WCHAR *path) BOOL status;
if (strlenW(path) == 0) { - status = GetCurrentDirectoryW(sizeof(curdir)/sizeof(WCHAR), curdir); + status = GetCurrentDirectoryW(ARRAY_SIZE(curdir), curdir); if (!status) { WCMD_print_error (); return 0; } - status = GetVolumeInformationW(NULL, label, sizeof(label)/sizeof(WCHAR), - &serial, NULL, NULL, NULL, 0); + status = GetVolumeInformationW(NULL, label, ARRAY_SIZE(label), &serial, NULL, NULL, NULL, 0); } else { static const WCHAR fmt[] = {'%','s','\','\0'}; @@ -4743,9 +4727,7 @@ int WCMD_volume(BOOL set_label, const WCHAR *path) return 0; } wsprintfW (curdir, fmt, path); - status = GetVolumeInformationW(curdir, label, sizeof(label)/sizeof(WCHAR), - &serial, NULL, - NULL, NULL, 0); + status = GetVolumeInformationW(curdir, label, ARRAY_SIZE(label), &serial, NULL, NULL, NULL, 0); } if (!status) { WCMD_print_error (); @@ -4763,7 +4745,7 @@ int WCMD_volume(BOOL set_label, const WCHAR *path) HIWORD(serial), LOWORD(serial)); if (set_label) { WCMD_output (WCMD_LoadMessage(WCMD_VOLUMEPROMPT)); - WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string)/sizeof(WCHAR), &count); + WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), string, ARRAY_SIZE(string), &count); if (count > 1) { string[count-1] = '\0'; /* ReadFile output is not null-terminated! */ if (string[count-2] == '\r') string[count-2] = '\0'; /* Under Windoze we get CRLF! */ @@ -4856,7 +4838,7 @@ void WCMD_assoc (const WCHAR *args, BOOL assoc) {
if (RegOpenKeyExW(key, subkey, 0, accessOptions, &readKey) == ERROR_SUCCESS) {
- valueLen = sizeof(keyValue)/sizeof(WCHAR); + valueLen = ARRAY_SIZE(keyValue); rc = RegQueryValueExW(readKey, NULL, NULL, NULL, (LPBYTE)keyValue, &valueLen); WCMD_output_asis(keyName); WCMD_output_asis(equalW); @@ -4902,9 +4884,9 @@ void WCMD_assoc (const WCHAR *args, BOOL assoc) {
/* Load the translated 'File association not found' */ if (assoc) { - LoadStringW(hinst, WCMD_NOASSOC, msgbuffer, sizeof(msgbuffer)/sizeof(WCHAR)); + LoadStringW(hinst, WCMD_NOASSOC, msgbuffer, ARRAY_SIZE(msgbuffer)); } else { - LoadStringW(hinst, WCMD_NOFTYPE, msgbuffer, sizeof(msgbuffer)/sizeof(WCHAR)); + LoadStringW(hinst, WCMD_NOFTYPE, msgbuffer, ARRAY_SIZE(msgbuffer)); } WCMD_output_stderr(msgbuffer, keyValue); errorlevel = 2; @@ -4939,11 +4921,9 @@ void WCMD_assoc (const WCHAR *args, BOOL assoc) {
/* Load the translated 'File association not found' */ if (assoc) { - LoadStringW(hinst, WCMD_NOASSOC, msgbuffer, - sizeof(msgbuffer)/sizeof(WCHAR)); + LoadStringW(hinst, WCMD_NOASSOC, msgbuffer, ARRAY_SIZE(msgbuffer)); } else { - LoadStringW(hinst, WCMD_NOFTYPE, msgbuffer, - sizeof(msgbuffer)/sizeof(WCHAR)); + LoadStringW(hinst, WCMD_NOFTYPE, msgbuffer, ARRAY_SIZE(msgbuffer)); } WCMD_output_stderr(msgbuffer, args); errorlevel = 2; diff --git a/programs/cmd/directory.c b/programs/cmd/directory.c index 91142be670..70507892ea 100644 --- a/programs/cmd/directory.c +++ b/programs/cmd/directory.c @@ -370,7 +370,7 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le if (usernames) { strcpyW (string, inputparms->dirName); strcatW (string, fd[i].cFileName); - WCMD_getfileowner(string, username, sizeof(username)/sizeof(WCHAR)); + WCMD_getfileowner(string, username, ARRAY_SIZE(username)); }
if (dirTime == Written) { @@ -381,10 +381,8 @@ static DIRECTORY_STACK *WCMD_list_directory (DIRECTORY_STACK *inputparms, int le FileTimeToLocalFileTime (&fd[i].ftCreationTime, &ft); } FileTimeToSystemTime (&ft, &st); - GetDateFormatW(0, DATE_SHORTDATE, &st, NULL, datestring, - sizeof(datestring)/sizeof(WCHAR)); - GetTimeFormatW(0, TIME_NOSECONDS, &st, - NULL, timestring, sizeof(timestring)/sizeof(WCHAR)); + GetDateFormatW(0, DATE_SHORTDATE, &st, NULL, datestring, ARRAY_SIZE(datestring)); + GetTimeFormatW(0, TIME_NOSECONDS, &st, NULL, timestring, ARRAY_SIZE(timestring));
if (wide) {
@@ -612,7 +610,7 @@ void WCMD_directory (WCHAR *args) errorlevel = 0;
/* Prefill quals with (uppercased) DIRCMD env var */ - if (GetEnvironmentVariableW(dircmdW, string, sizeof(string)/sizeof(WCHAR))) { + if (GetEnvironmentVariableW(dircmdW, string, ARRAY_SIZE(string))) { p = string; while ( (*p = toupper(*p)) ) ++p; strcatW(string,quals); @@ -823,7 +821,7 @@ void WCMD_directory (WCHAR *args) } WINE_TRACE("Using location '%s'\n", wine_dbgstr_w(fullname));
- status = GetFullPathNameW(fullname, sizeof(path)/sizeof(WCHAR), path, NULL); + status = GetFullPathNameW(fullname, ARRAY_SIZE(path), path, NULL);
/* * If the path supplied does not include a wildcard, and the endpoint of the diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 5135be4751..b269635c75 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -272,7 +272,7 @@ static void WCMD_output_asis_handle (DWORD std_handle, const WCHAR *message) { if (++line_count >= max_height - 1) { line_count = 0; WCMD_output_asis_len(pagedMessage, strlenW(pagedMessage), handle); - WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), string, sizeof(string)/sizeof(WCHAR), &count); + WCMD_ReadFile(GetStdHandle(STD_INPUT_HANDLE), string, ARRAY_SIZE(string), &count); } } while (((message = ptr) != NULL) && (*ptr)); } else { @@ -343,9 +343,8 @@ static void WCMD_show_prompt (void) { DWORD len; static const WCHAR envPrompt[] = {'P','R','O','M','P','T','\0'};
- len = GetEnvironmentVariableW(envPrompt, prompt_string, - sizeof(prompt_string)/sizeof(WCHAR)); - if ((len == 0) || (len >= (sizeof(prompt_string)/sizeof(WCHAR)))) { + len = GetEnvironmentVariableW(envPrompt, prompt_string, ARRAY_SIZE(prompt_string)); + if ((len == 0) || (len >= ARRAY_SIZE(prompt_string))) { static const WCHAR dfltPrompt[] = {'$','P','$','G','\0'}; strcpyW (prompt_string, dfltPrompt); } @@ -394,13 +393,13 @@ static void WCMD_show_prompt (void) { *q++ = '<'; break; case 'N': - status = GetCurrentDirectoryW(sizeof(curdir)/sizeof(WCHAR), curdir); + status = GetCurrentDirectoryW(ARRAY_SIZE(curdir), curdir); if (status) { *q++ = curdir[0]; } break; case 'P': - status = GetCurrentDirectoryW(sizeof(curdir)/sizeof(WCHAR), curdir); + status = GetCurrentDirectoryW(ARRAY_SIZE(curdir), curdir); if (status) { strcatW (q, curdir); while (*q) q++; @@ -641,8 +640,7 @@ static WCHAR *WCMD_expand_envvar(WCHAR *start, WCHAR startchar) len = strlenW(thisVarContents); } else {
- len = ExpandEnvironmentStringsW(thisVar, thisVarContents, - sizeof(thisVarContents)/sizeof(WCHAR)); + len = ExpandEnvironmentStringsW(thisVar, thisVarContents, ARRAY_SIZE(thisVarContents)); }
if (len == 0) @@ -1060,8 +1058,8 @@ void WCMD_run_program (WCHAR *command, BOOL called) if (strpbrkW (firstParam, delims) == NULL) { /* No explicit path given, search path */ static const WCHAR curDir[] = {'.',';','\0'}; strcpyW(pathtosearch, curDir); - len = GetEnvironmentVariableW(envPath, &pathtosearch[2], (sizeof(pathtosearch)/sizeof(WCHAR))-2); - if ((len == 0) || (len >= (sizeof(pathtosearch)/sizeof(WCHAR)) - 2)) { + len = GetEnvironmentVariableW(envPath, &pathtosearch[2], ARRAY_SIZE(pathtosearch)-2); + if ((len == 0) || (len >= ARRAY_SIZE(pathtosearch) - 2)) { static const WCHAR curDir[] = {'.','\0'}; strcpyW (pathtosearch, curDir); } @@ -1077,7 +1075,7 @@ void WCMD_run_program (WCHAR *command, BOOL called) } else {
/* Convert eg. ..\fred to include a directory by removing file part */ - GetFullPathNameW(firstParam, sizeof(pathtosearch)/sizeof(WCHAR), pathtosearch, NULL); + GetFullPathNameW(firstParam, ARRAY_SIZE(pathtosearch), pathtosearch, NULL); lastSlash = strrchrW(pathtosearch, '\'); if (lastSlash && strchrW(lastSlash, '.') != NULL) extensionsupplied = TRUE; strcpyW(stemofsearch, lastSlash+1); @@ -1088,8 +1086,8 @@ void WCMD_run_program (WCHAR *command, BOOL called) }
/* Now extract PATHEXT */ - len = GetEnvironmentVariableW(envPathExt, pathext, sizeof(pathext)/sizeof(WCHAR)); - if ((len == 0) || (len >= (sizeof(pathext)/sizeof(WCHAR)))) { + len = GetEnvironmentVariableW(envPathExt, pathext, ARRAY_SIZE(pathext)); + if ((len == 0) || (len >= ARRAY_SIZE(pathext))) { strcpyW (pathext, dfltPathExt); }
@@ -1315,7 +1313,7 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects, piped = TRUE;
/* Generate a unique temporary filename */ - GetTempPathW(sizeof(temp_path)/sizeof(WCHAR), temp_path); + GetTempPathW(ARRAY_SIZE(temp_path), temp_path); GetTempFileNameW(temp_path, cmdW, 0, (*cmdList)->nextcommand->pipeFile); WINE_TRACE("Using temporary file of %s\n", wine_dbgstr_w((*cmdList)->nextcommand->pipeFile)); @@ -1662,7 +1660,7 @@ WCHAR *WCMD_LoadMessage(UINT id) { static WCHAR msg[2048]; static const WCHAR failedMsg[] = {'F','a','i','l','e','d','!','\0'};
- if (!LoadStringW(GetModuleHandleW(NULL), id, msg, sizeof(msg)/sizeof(WCHAR))) { + if (!LoadStringW(GetModuleHandleW(NULL), id, msg, ARRAY_SIZE(msg))) { WINE_FIXME("LoadString failed with %d\n", GetLastError()); strcpyW(msg, failedMsg); } @@ -1879,7 +1877,7 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE static const WCHAR echoDot[] = {'e','c','h','o','.'}; static const WCHAR echoCol[] = {'e','c','h','o',':'}; static const WCHAR echoSlash[] = {'e','c','h','o','/'}; - const DWORD len = sizeof(echoDot)/sizeof(echoDot[0]); + const DWORD len = ARRAY_SIZE(echoDot); DWORD curr_size = strlenW(curPos); DWORD min_len = (curr_size < len ? curr_size : len); WCMD_show_prompt(); @@ -1929,11 +1927,10 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE static const WCHAR forDO[] = {'d','o'};
/* If command starts with 'rem ' or identifies a label, ignore any &&, ( etc. */ - if (WCMD_keyword_ws_found(remCmd, sizeof(remCmd)/sizeof(remCmd[0]), curPos) || - *curPos == ':') { + if (WCMD_keyword_ws_found(remCmd, ARRAY_SIZE(remCmd), curPos) || *curPos == ':') { inOneLine = TRUE;
- } else if (WCMD_keyword_ws_found(forCmd, sizeof(forCmd)/sizeof(forCmd[0]), curPos)) { + } else if (WCMD_keyword_ws_found(forCmd, ARRAY_SIZE(forCmd), curPos)) { inFor = TRUE;
/* If command starts with 'if ' or 'else ', handle ('s mid line. We should ensure this @@ -1942,11 +1939,11 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE FIXME: Silly syntax like "if 1(==1( ( echo they equal )" will be parsed wrong */ - } else if (WCMD_keyword_ws_found(ifCmd, sizeof(ifCmd)/sizeof(ifCmd[0]), curPos)) { + } else if (WCMD_keyword_ws_found(ifCmd, ARRAY_SIZE(ifCmd), curPos)) { inIf = TRUE;
- } else if (WCMD_keyword_ws_found(ifElse, sizeof(ifElse)/sizeof(ifElse[0]), curPos)) { - const int keyw_len = sizeof(ifElse)/sizeof(ifElse[0]) + 1; + } else if (WCMD_keyword_ws_found(ifElse, ARRAY_SIZE(ifElse), curPos)) { + const int keyw_len = ARRAY_SIZE(ifElse) + 1; inElse = TRUE; lastWasElse = TRUE; onlyWhiteSpace = TRUE; @@ -1958,9 +1955,8 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE /* In a for loop, the DO command will follow a close bracket followed by whitespace, followed by DO, ie closeBracket inserts a NULL entry, curLen is then 0, and all whitespace is skipped */ - } else if (inFor && - WCMD_keyword_ws_found(forDO, sizeof(forDO)/sizeof(forDO[0]), curPos)) { - const int keyw_len = sizeof(forDO)/sizeof(forDO[0]) + 1; + } else if (inFor && WCMD_keyword_ws_found(forDO, ARRAY_SIZE(forDO), curPos)) { + const int keyw_len = ARRAY_SIZE(forDO) + 1; WINE_TRACE("Found 'DO '\n"); lastWasDo = TRUE; onlyWhiteSpace = TRUE; @@ -1977,8 +1973,8 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
WINE_TRACE("Found 'FOR ', comparing next parm: '%s'\n", wine_dbgstr_w(curPos));
- if (WCMD_keyword_ws_found(forIN, sizeof(forIN)/sizeof(forIN[0]), curPos)) { - const int keyw_len = sizeof(forIN)/sizeof(forIN[0]) + 1; + if (WCMD_keyword_ws_found(forIN, ARRAY_SIZE(forIN), curPos)) { + const int keyw_len = ARRAY_SIZE(forIN) + 1; WINE_TRACE("Found 'IN '\n"); lastWasIn = TRUE; onlyWhiteSpace = TRUE; @@ -2509,8 +2505,8 @@ int wmain (int argc, WCHAR *argvW[]) BOOL found = FALSE;
/* Now extract PATHEXT */ - len = GetEnvironmentVariableW(envPathExt, pathext, sizeof(pathext)/sizeof(WCHAR)); - if ((len == 0) || (len >= (sizeof(pathext)/sizeof(WCHAR)))) { + len = GetEnvironmentVariableW(envPathExt, pathext, ARRAY_SIZE(pathext)); + if ((len == 0) || (len >= ARRAY_SIZE(pathext))) { strcpyW (pathext, dfltPathExt); }
@@ -2518,7 +2514,7 @@ int wmain (int argc, WCHAR *argvW[]) WINE_TRACE("First parameter is '%s'\n", wine_dbgstr_w(thisArg)); if (strchrW(thisArg, '\') != NULL) {
- GetFullPathNameW(thisArg, sizeof(string)/sizeof(WCHAR), string, NULL); + GetFullPathNameW(thisArg, ARRAY_SIZE(string), string, NULL); WINE_TRACE("Full path name '%s'\n", wine_dbgstr_w(string)); p = string + strlenW(string);
@@ -2553,7 +2549,7 @@ int wmain (int argc, WCHAR *argvW[]) /* Otherwise we now need to look in the path to see if we can find it */ } else { /* Does file exist with this name? */ - if (SearchPathW(NULL, thisArg, NULL, sizeof(string)/sizeof(WCHAR), string, NULL) != 0) { + if (SearchPathW(NULL, thisArg, NULL, ARRAY_SIZE(string), string, NULL) != 0) { WINE_TRACE("Found on path as '%s'\n", wine_dbgstr_w(string)); found = TRUE; } else { @@ -2571,7 +2567,7 @@ int wmain (int argc, WCHAR *argvW[]) }
/* Does file exist with this extension? */ - if (SearchPathW(NULL, thisArg, thisExt, sizeof(string)/sizeof(WCHAR), string, NULL) != 0) { + if (SearchPathW(NULL, thisArg, thisExt, ARRAY_SIZE(string), string, NULL) != 0) { WINE_TRACE("Found on path as '%s' with extension '%s'\n", wine_dbgstr_w(string), wine_dbgstr_w(thisExt)); found = TRUE; @@ -2596,7 +2592,7 @@ int wmain (int argc, WCHAR *argvW[]) }
/* Save cwd into appropriate env var (Must be before the /c processing */ - GetCurrentDirectoryW(sizeof(string)/sizeof(WCHAR), string); + GetCurrentDirectoryW(ARRAY_SIZE(string), string); if (IsCharAlphaW(string[0]) && string[1] == ':') { static const WCHAR fmt[] = {'=','%','c',':','\0'}; wsprintfW(envvar, fmt, string[0]); @@ -2656,7 +2652,7 @@ int wmain (int argc, WCHAR *argvW[]) RegQueryValueExW(key, dfltColorW, NULL, NULL, (LPBYTE)&value, &size); } else if (type == REG_SZ) { - size = sizeof(strvalue)/sizeof(WCHAR); + size = ARRAY_SIZE(strvalue); RegQueryValueExW(key, dfltColorW, NULL, NULL, (LPBYTE)strvalue, &size); value = strtoulW(strvalue, NULL, 10); @@ -2677,7 +2673,7 @@ int wmain (int argc, WCHAR *argvW[]) RegQueryValueExW(key, dfltColorW, NULL, NULL, (LPBYTE)&value, &size); } else if (type == REG_SZ) { - size = sizeof(strvalue)/sizeof(WCHAR); + size = ARRAY_SIZE(strvalue); RegQueryValueExW(key, dfltColorW, NULL, NULL, (LPBYTE)strvalue, &size); value = strtoulW(strvalue, NULL, 10);