diff --git a/reactos/base/applications/cacls/CMakeLists.txt b/reactos/base/applications/cacls/CMakeLists.txt index aa9f30858d4..3abda6c12fe 100644 --- a/reactos/base/applications/cacls/CMakeLists.txt +++ b/reactos/base/applications/cacls/CMakeLists.txt @@ -1,6 +1,8 @@ -list(APPEND SOURCE cacls.c cacls.rc) -add_executable(cacls ${SOURCE}) +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) + +add_executable(cacls cacls.c cacls.rc) set_module_type(cacls win32cui UNICODE) +target_link_libraries(cacls conutils ${PSEH_LIB}) add_importlibs(cacls advapi32 user32 shell32 msvcrt kernel32) add_cd_file(TARGET cacls DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/applications/cacls/cacls.c b/reactos/base/applications/cacls/cacls.c index f58a9b8cfa3..a393846bf3a 100644 --- a/reactos/base/applications/cacls/cacls.c +++ b/reactos/base/applications/cacls/cacls.c @@ -34,152 +34,16 @@ static GENERIC_MAPPING FileGenericMapping = static -INT -LengthOfStrResource(IN HINSTANCE hInst, - IN UINT uID) +VOID PrintError(DWORD dwError) { - HRSRC hrSrc; - HGLOBAL hRes; - LPWSTR lpName, lpStr; + if (dwError == ERROR_SUCCESS) + return; - if (hInst == NULL) - { - hInst = GetModuleHandle(NULL); - } - - /* There are always blocks of 16 strings */ - lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1); - - /* Find the string table block */ - hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING); - if (hrSrc) - { - hRes = LoadResource(hInst, hrSrc); - if (hRes) - { - lpStr = LockResource(hRes); - if (lpStr) - { - UINT x; - - /* Find the string we're looking for */ - uID &= 0xF; /* position in the block, same as % 16 */ - for (x = 0; x < uID; x++) - { - lpStr += (*lpStr) + 1; - } - - /* Found the string */ - return (int)(*lpStr); - } - } - } - return -1; + ConMsgPrintf(StdErr, + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, dwError, LANG_USER_DEFAULT); } - -static -INT -AllocAndLoadString(OUT LPTSTR *lpTarget, - IN HINSTANCE hInst, - IN UINT uID) -{ - INT ln; - - ln = LengthOfStrResource(hInst, - uID); - if (ln++ > 0) - { - (*lpTarget) = (LPTSTR)HeapAlloc(GetProcessHeap(), - 0, - ln * sizeof(TCHAR)); - if ((*lpTarget) != NULL) - { - INT Ret; - Ret = LoadString(hInst, - uID, - *lpTarget, - ln); - if (!Ret) - { - HeapFree(GetProcessHeap(), - 0, - *lpTarget); - } - return Ret; - } - } - return 0; -} - - -static -VOID -PrintHelp(VOID) -{ - LPTSTR szHelp; - - if (AllocAndLoadString(&szHelp, - NULL, - IDS_HELP) != 0) - { - _tprintf(_T("%s"), - szHelp); - - HeapFree(GetProcessHeap(), - 0, - szHelp); - } -} - - -static -VOID -PrintErrorMessage(IN DWORD dwError) -{ - LPTSTR szError; - - if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | - FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - dwError, - MAKELANGID(LANG_NEUTRAL, - SUBLANG_DEFAULT), - (LPTSTR)&szError, - 0, - NULL) != 0) - { - _tprintf(_T("%s"), - szError); - LocalFree((HLOCAL)szError); - } -} - - -static -DWORD -LoadAndPrintString(IN HINSTANCE hInst, - IN UINT uID) -{ - TCHAR szTemp[255]; - DWORD Len; - - Len = (DWORD)LoadString(hInst, - uID, - szTemp, - sizeof(szTemp) / sizeof(szTemp[0])); - - if (Len != 0) - { - _tprintf(_T("%s"), - szTemp); - } - - return Len; -} - - static BOOL PrintFileDacl(IN LPTSTR FilePath, @@ -352,18 +216,15 @@ BuildSidString: /* print the ACE Flags */ if (Ace->Header.AceFlags & CONTAINER_INHERIT_ACE) { - IndentAccess += LoadAndPrintString(NULL, - IDS_ABBR_CI); + IndentAccess += PrintResourceString(IDS_ABBR_CI); } if (Ace->Header.AceFlags & OBJECT_INHERIT_ACE) { - IndentAccess += LoadAndPrintString(NULL, - IDS_ABBR_OI); + IndentAccess += PrintResourceString(IDS_ABBR_OI); } if (Ace->Header.AceFlags & INHERIT_ONLY_ACE) { - IndentAccess += LoadAndPrintString(NULL, - IDS_ABBR_IO); + IndentAccess += PrintResourceString(IDS_ABBR_IO); } IndentAccess += 2; @@ -375,13 +236,11 @@ BuildSidString: { if (AccessMask == FILE_ALL_ACCESS) { - LoadAndPrintString(NULL, - IDS_ABBR_NONE); + PrintResourceString(IDS_ABBR_NONE); } else { - LoadAndPrintString(NULL, - IDS_DENY); + PrintResourceString(IDS_DENY); goto PrintSpecialAccess; } } @@ -389,24 +248,20 @@ BuildSidString: { if (AccessMask == FILE_ALL_ACCESS) { - LoadAndPrintString(NULL, - IDS_ABBR_FULL); + PrintResourceString(IDS_ABBR_FULL); } else if (!(Ace->Mask & (GENERIC_READ | GENERIC_EXECUTE)) && AccessMask == (FILE_GENERIC_READ | FILE_EXECUTE)) { - LoadAndPrintString(NULL, - IDS_ABBR_READ); + PrintResourceString(IDS_ABBR_READ); } else if (AccessMask == (FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_EXECUTE | DELETE)) { - LoadAndPrintString(NULL, - IDS_ABBR_CHANGE); + PrintResourceString(IDS_ABBR_CHANGE); } else if (AccessMask == FILE_GENERIC_WRITE) { - LoadAndPrintString(NULL, - IDS_ABBR_WRITE); + PrintResourceString(IDS_ABBR_WRITE); } else { @@ -446,15 +301,13 @@ BuildSidString: {STANDARD_RIGHTS_ALL, IDS_STANDARD_RIGHTS_ALL}, }; - LoadAndPrintString(NULL, - IDS_ALLOW); + PrintResourceString(IDS_ALLOW); PrintSpecialAccess: - LoadAndPrintString(NULL, - IDS_SPECIAL_ACCESS); + PrintResourceString(IDS_SPECIAL_ACCESS); /* print the special access rights */ - x = sizeof(AccessRights) / sizeof(AccessRights[0]); + x = ARRAYSIZE(AccessRights); while (x-- != 0) { if ((Ace->Mask & AccessRights[x].Access) == AccessRights[x].Access) @@ -468,8 +321,7 @@ PrintSpecialAccess: _tprintf(_T(" ")); } - LoadAndPrintString(NULL, - AccessRights[x].uID); + PrintResourceString(AccessRights[x].uID); } } @@ -541,7 +393,7 @@ GetPathOfFile(LPTSTR FilePath, LPCTSTR pszFiles) *pch = 0; if (!GetFullPathName(FilePath, MAX_PATH, FullPath, NULL)) { - PrintErrorMessage(GetLastError()); + PrintError(GetLastError()); return FALSE; } lstrcpyn(FilePath, FullPath, MAX_PATH); @@ -549,7 +401,7 @@ GetPathOfFile(LPTSTR FilePath, LPCTSTR pszFiles) attrs = GetFileAttributes(FilePath); if (attrs == 0xFFFFFFFF || !(attrs & FILE_ATTRIBUTE_DIRECTORY)) { - PrintErrorMessage(ERROR_DIRECTORY); + PrintError(ERROR_DIRECTORY); return FALSE; } } @@ -591,7 +443,7 @@ PrintDaclsOfFiles(LPCTSTR pszFiles) LastError = GetLastError(); if (LastError == ERROR_ACCESS_DENIED) { - PrintErrorMessage(LastError); + PrintError(LastError); if (!OptionC) { FindClose(hFind); @@ -609,7 +461,7 @@ PrintDaclsOfFiles(LPCTSTR pszFiles) if (LastError != ERROR_NO_MORE_FILES) { - PrintErrorMessage(LastError); + PrintError(LastError); return FALSE; } @@ -771,7 +623,7 @@ ChangeACLsOfFiles(LPCTSTR pszFiles) LastError = GetLastError(); if (LastError == ERROR_ACCESS_DENIED) { - PrintErrorMessage(LastError); + PrintError(LastError); if (!OptionC) { FindClose(hFind); @@ -788,7 +640,7 @@ ChangeACLsOfFiles(LPCTSTR pszFiles) if (LastError != ERROR_NO_MORE_FILES) { - PrintErrorMessage(LastError); + PrintError(LastError); return FALSE; } @@ -826,7 +678,7 @@ ChangeACLsOfFilesInCurDir(LPCTSTR pszFiles) LastError = GetLastError(); if (LastError == ERROR_ACCESS_DENIED) { - PrintErrorMessage(LastError); + PrintError(LastError); if (!OptionC) { FindClose(hFind); @@ -843,7 +695,7 @@ ChangeACLsOfFilesInCurDir(LPCTSTR pszFiles) if (LastError != ERROR_NO_MORE_FILES) { - PrintErrorMessage(LastError); + PrintError(LastError); return FALSE; } @@ -872,7 +724,7 @@ ChangeACLsOfFilesInCurDir(LPCTSTR pszFiles) LastError = GetLastError(); if (LastError == ERROR_ACCESS_DENIED) { - PrintErrorMessage(LastError); + PrintError(LastError); if (!OptionC) { FindClose(hFind); @@ -889,23 +741,24 @@ ChangeACLsOfFilesInCurDir(LPCTSTR pszFiles) if (LastError != ERROR_NO_MORE_FILES) { - PrintErrorMessage(LastError); + PrintError(LastError); return FALSE; } return TRUE; } -int -__cdecl -_tmain(int argc, const TCHAR *argv[]) +int _tmain(int argc, const TCHAR *argv[]) { INT i; LPTSTR pch; BOOL InvalidParameter = FALSE; + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); + if (argc <= 1) { - PrintHelp(); + PrintResourceString(IDS_HELP); return 0; } @@ -991,8 +844,8 @@ _tmain(int argc, const TCHAR *argv[]) if (InvalidParameter) { - PrintErrorMessage(ERROR_INVALID_PARAMETER); - PrintHelp(); + PrintError(ERROR_INVALID_PARAMETER); + PrintResourceString(IDS_HELP); return 1; } diff --git a/reactos/base/applications/cacls/precomp.h b/reactos/base/applications/cacls/precomp.h index 3337cc4d5e1..c2e1af0b185 100644 --- a/reactos/base/applications/cacls/precomp.h +++ b/reactos/base/applications/cacls/precomp.h @@ -2,11 +2,14 @@ #define _CACLS_PRECOMP_H #include +#include + #include #include -#include +#include // For CharPrev #include -#include + +#include #include "resource.h" diff --git a/reactos/base/applications/cmdutils/clip/CMakeLists.txt b/reactos/base/applications/cmdutils/clip/CMakeLists.txt index 53b3991b620..f15c2e93101 100644 --- a/reactos/base/applications/cmdutils/clip/CMakeLists.txt +++ b/reactos/base/applications/cmdutils/clip/CMakeLists.txt @@ -1,5 +1,8 @@ +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) + add_executable(clip clip.c clip.rc) set_module_type(clip win32cui UNICODE) -add_importlibs(clip user32 msvcrt kernel32 advapi32) +target_link_libraries(clip conutils ${PSEH_LIB}) +add_importlibs(clip advapi32 user32 msvcrt kernel32) add_cd_file(TARGET clip DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/applications/cmdutils/clip/clip.c b/reactos/base/applications/cmdutils/clip/clip.c index ee1fcd63cde..8899c8914f4 100644 --- a/reactos/base/applications/cmdutils/clip/clip.c +++ b/reactos/base/applications/cmdutils/clip/clip.c @@ -12,31 +12,18 @@ #include #include +#include + #include "resource.h" -static void PrintError(void) +VOID PrintError(DWORD dwError) { - DWORD dwError; - LPWSTR lpMsgBuf = NULL; - - dwError = GetLastError(); - if (dwError == NO_ERROR) + if (dwError == ERROR_SUCCESS) return; - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, dwError, 0, (LPWSTR)&lpMsgBuf, 0, NULL); - wprintf(L"%s", lpMsgBuf); - LocalFree(lpMsgBuf); -} - -static void PrintResourceString(UINT uID) -{ - WCHAR buff[500]; - - if (LoadStringW(GetModuleHandle(NULL), uID, buff, ARRAYSIZE(buff))) - { - wprintf(L"%s", buff); - } + ConMsgPrintf(StdErr, + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, dwError, LANG_USER_DEFAULT); } static BOOL IsDataUnicode(HGLOBAL hGlobal) @@ -61,28 +48,27 @@ int wmain(int argc, wchar_t** argv) LPBYTE lpBuffer; SIZE_T dwSize = 0; + /* Initialize the Console Standard Streams */ hInput = GetStdHandle(STD_INPUT_HANDLE); + ConInitStdStreams(); /* Check for usage */ if (argc > 1 && wcsncmp(argv[1], L"/?", 2) == 0) { - PrintResourceString(IDS_HELP); + ConResPrintf(StdOut, IDS_HELP); return 0; } if (GetFileType(hInput) == FILE_TYPE_CHAR) { - PrintResourceString(IDS_USAGE); + ConResPrintf(StdOut, IDS_USAGE); return 0; } /* Initialize a growable buffer for holding clipboard data */ hBuffer = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, 4096); if (!hBuffer) - { - PrintError(); - return -1; - } + goto Failure; /* * Read data from the input stream by chunks of 4096 bytes @@ -92,7 +78,7 @@ int wmain(int argc, wchar_t** argv) { lpBuffer = GlobalLock(hBuffer); if (!lpBuffer) - goto cleanup; + goto Failure; bStatus = ReadFile(hInput, lpBuffer + dwSize, 4096, &dwBytesRead, NULL); dwSize += dwBytesRead; @@ -100,7 +86,7 @@ int wmain(int argc, wchar_t** argv) hTemp = GlobalReAlloc(hBuffer, GlobalSize(hBuffer) + 4096, GMEM_ZEROINIT); if (!hTemp) - goto cleanup; + goto Failure; hBuffer = hTemp; } @@ -118,7 +104,7 @@ int wmain(int argc, wchar_t** argv) /* Attempt to open the clipboard */ if (!OpenClipboard(NULL)) - goto cleanup; + goto Failure; /* Empty it, copy our data, then close it */ @@ -138,8 +124,8 @@ int wmain(int argc, wchar_t** argv) CloseClipboard(); return 0; -cleanup: - GlobalFree(hBuffer); - PrintError(); +Failure: + if (hBuffer) GlobalFree(hBuffer); + PrintError(GetLastError()); return -1; } diff --git a/reactos/base/applications/cmdutils/comp/CMakeLists.txt b/reactos/base/applications/cmdutils/comp/CMakeLists.txt index 45f078ad5f6..0e2ce7a573b 100644 --- a/reactos/base/applications/cmdutils/comp/CMakeLists.txt +++ b/reactos/base/applications/cmdutils/comp/CMakeLists.txt @@ -1,5 +1,8 @@ +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) + add_executable(comp comp.c comp.rc) set_module_type(comp win32cui UNICODE) -add_importlibs(comp user32 msvcrt kernel32) +target_link_libraries(comp conutils ${PSEH_LIB}) +add_importlibs(comp msvcrt kernel32) add_cd_file(TARGET comp DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/applications/cmdutils/comp/comp.c b/reactos/base/applications/cmdutils/comp/comp.c index 8738df2d2c2..89b0f8505f8 100644 --- a/reactos/base/applications/cmdutils/comp/comp.c +++ b/reactos/base/applications/cmdutils/comp/comp.c @@ -1,273 +1,251 @@ -/* - * ReactOS Win32 Applications - * Copyright (C) 2005 ReactOS Team - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - */ -/* - * PROJECT: ReactOS Comp utility - * COPYRIGHT: See COPYING in the top level directory - * FILE: base/applications/cmdutils/comp/comp.c - * PURPOSE: Compares the contents of two files - * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com) - */ - -#include -#include -// #include -// #include -#include - -#define WIN32_NO_STATUS -#include -#include -#include - -#include "resource.h" - -#define STRBUF 1024 - -VOID PrintResourceString(INT resID, ...) -{ - WCHAR bufSrc[RC_STRING_MAX_SIZE]; - WCHAR bufFormatted[RC_STRING_MAX_SIZE]; - CHAR bufFormattedOem[RC_STRING_MAX_SIZE]; - - va_list args; - va_start(args, resID); - - if (LoadStringW(GetModuleHandleW(NULL), resID, bufSrc, ARRAYSIZE(bufSrc))) - vswprintf(bufFormatted, bufSrc, args); - else - swprintf(bufFormatted, L"Resource loading error!"); - - CharToOemW(bufFormatted, bufFormattedOem); - fputs(bufFormattedOem, stdout); - - va_end(args); -} - -/* getline: read a line, return length */ -INT GetBuff(PBYTE buff, FILE* in) -{ - return fread(buff, sizeof(BYTE), STRBUF, in); -} - -INT FileSize(FILE* fd) -{ - INT result = -1; - if (fseek(fd, 0, SEEK_END) == 0 && (result = ftell(fd)) != -1) - { - /* Restoring file pointer */ - rewind(fd); - } - return result; -} - -/* Print program usage */ -VOID Usage(VOID) -{ - PrintResourceString(IDS_HELP); -} - - -int wmain (int argc, WCHAR* argv[]) -{ - INT i; - - /* File pointers */ - FILE *fp1 = NULL; - FILE *fp2 = NULL; - - INT BufLen1, BufLen2; - PBYTE Buff1 = NULL; - PBYTE Buff2 = NULL; - WCHAR File1[_MAX_PATH + 1], // File paths - File2[_MAX_PATH + 1]; - BOOL bAscii = FALSE, // /A switch - bLineNos = FALSE; // /L switch - UINT LineNumber; - UINT Offset; - INT FileSizeFile1; - INT FileSizeFile2; - INT NumberOfOptions = 0; - INT FilesOK = 1; - INT Status = EXIT_SUCCESS; - - /* Parse command line for options */ - for (i = 1; i < argc; i++) - { - if (argv[i][0] == L'/') - { - switch (argv[i][1]) - { - case L'A': - bAscii = TRUE; - NumberOfOptions++; - break; - - case L'L': - bLineNos = TRUE; - NumberOfOptions++; - break; - - case L'?': - Usage(); - return EXIT_SUCCESS; - - default: - PrintResourceString(IDS_INVALIDSWITCH, argv[i][1]); - Usage(); - return EXIT_FAILURE; - } - } - } - - if (argc - NumberOfOptions == 3) - { - wcsncpy(File1, argv[1 + NumberOfOptions], _MAX_PATH); - wcsncpy(File2, argv[2 + NumberOfOptions], _MAX_PATH); - } - else - { - PrintResourceString(IDS_BADSYNTAX); - return EXIT_FAILURE; - } - - Buff1 = (PBYTE)malloc(STRBUF); - if (Buff1 == NULL) - { - wprintf(L"Can't get free memory for Buff1\n"); - Status = EXIT_FAILURE; - goto Cleanup; - } - - Buff2 = (PBYTE)malloc(STRBUF); - if (Buff2 == NULL) - { - wprintf(L"Can't get free memory for Buff2\n"); - Status = EXIT_FAILURE; - goto Cleanup; - } - - if ((fp1 = _wfopen(File1, L"rb")) == NULL) - { - PrintResourceString(IDS_FILEERROR, File1); - Status = EXIT_FAILURE; - goto Cleanup; - } - if ((fp2 = _wfopen(File2, L"rb")) == NULL) - { - PrintResourceString(IDS_FILEERROR, File2); - Status = EXIT_FAILURE; - goto Cleanup; - } - - PrintResourceString(IDS_COMPARING, File1, File2); - - FileSizeFile1 = FileSize(fp1); - if (FileSizeFile1 == -1) - { - PrintResourceString(IDS_FILESIZEERROR, File1); - Status = EXIT_FAILURE; - goto Cleanup; - } - - FileSizeFile2 = FileSize(fp2); - if (FileSizeFile2 == -1) - { - PrintResourceString(IDS_FILESIZEERROR, File2); - Status = EXIT_FAILURE; - goto Cleanup; - } - - if (FileSizeFile1 != FileSizeFile2) - { - PrintResourceString(IDS_SIZEDIFFERS); - Status = EXIT_FAILURE; - goto Cleanup; - } - - LineNumber = 1; - Offset = 0; - while (1) - { - BufLen1 = GetBuff(Buff1, fp1); - BufLen2 = GetBuff(Buff2, fp2); - - if (ferror(fp1) || ferror(fp2)) - { - PrintResourceString(IDS_READERROR); - Status = EXIT_FAILURE; - goto Cleanup; - } - - if (!BufLen1 && !BufLen2) - break; - - assert(BufLen1 == BufLen2); - for (i = 0; i < BufLen1; i++) - { - if (Buff1[i] != Buff2[i]) - { - FilesOK = 0; - - /* Reporting here a mismatch */ - if (bLineNos) - { - PrintResourceString(IDS_MISMATCHLINE, LineNumber); - } - else - { - PrintResourceString(IDS_MISMATCHOFFSET, Offset); - } - - if (bAscii) - { - PrintResourceString(IDS_ASCIIDIFF, 1, Buff1[i]); - PrintResourceString(IDS_ASCIIDIFF, 2, Buff2[i]); - } - else - { - PrintResourceString(IDS_HEXADECIMALDIFF, 1, Buff1[i]); - PrintResourceString(IDS_HEXADECIMALDIFF, 2, Buff2[i]); - } - } - - Offset++; - - if (Buff1[i] == '\n') - LineNumber++; - } - } - - if (FilesOK) - PrintResourceString(IDS_MATCH); - -Cleanup: - if (fp2) - fclose(fp2); - if (fp1) - fclose(fp1); - - if (Buff2) - free(Buff2); - if (Buff1) - free(Buff1); - - return Status; -} - -/* EOF */ +/* + * ReactOS Win32 Applications + * Copyright (C) 2005 ReactOS Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/* + * PROJECT: ReactOS Comp utility + * COPYRIGHT: See COPYING in the top level directory + * FILE: base/applications/cmdutils/comp/comp.c + * PURPOSE: Compares the contents of two files + * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com) + */ + +#include +#include +// #include +// #include +#include + +#define WIN32_NO_STATUS +#include +#include + +#include + +#include "resource.h" + +#define STRBUF 1024 + +/* getline: read a line, return length */ +INT GetBuff(PBYTE buff, FILE* in) +{ + return fread(buff, sizeof(BYTE), STRBUF, in); +} + +INT FileSize(FILE* fd) +{ + INT result = -1; + if (fseek(fd, 0, SEEK_END) == 0 && (result = ftell(fd)) != -1) + { + /* Restoring file pointer */ + rewind(fd); + } + return result; +} + + +int wmain (int argc, WCHAR* argv[]) +{ + INT i; + + /* File pointers */ + FILE *fp1 = NULL; + FILE *fp2 = NULL; + + INT BufLen1, BufLen2; + PBYTE Buff1 = NULL; + PBYTE Buff2 = NULL; + WCHAR File1[_MAX_PATH + 1], // File paths + File2[_MAX_PATH + 1]; + BOOL bAscii = FALSE, // /A switch + bLineNos = FALSE; // /L switch + UINT LineNumber; + UINT Offset; + INT FileSizeFile1; + INT FileSizeFile2; + INT NumberOfOptions = 0; + INT FilesOK = 1; + INT Status = EXIT_SUCCESS; + + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); + + /* Parse command line for options */ + for (i = 1; i < argc; i++) + { + if (argv[i][0] == L'/') + { + switch (towlower(argv[i][1])) + { + case L'a': + bAscii = TRUE; + NumberOfOptions++; + break; + + case L'l': + bLineNos = TRUE; + NumberOfOptions++; + break; + + case L'?': + PrintResourceString(IDS_HELP); + return EXIT_SUCCESS; + + default: + PrintResourceString(IDS_INVALIDSWITCH, argv[i][1]); + PrintResourceString(IDS_HELP); + return EXIT_FAILURE; + } + } + } + + if (argc - NumberOfOptions == 3) + { + wcsncpy(File1, argv[1 + NumberOfOptions], _MAX_PATH); + wcsncpy(File2, argv[2 + NumberOfOptions], _MAX_PATH); + } + else + { + PrintResourceString(IDS_BADSYNTAX); + return EXIT_FAILURE; + } + + Buff1 = (PBYTE)malloc(STRBUF); + if (Buff1 == NULL) + { + ConPrintf(StdErr, L"Can't get free memory for Buff1\n"); + Status = EXIT_FAILURE; + goto Cleanup; + } + + Buff2 = (PBYTE)malloc(STRBUF); + if (Buff2 == NULL) + { + ConPrintf(StdErr, L"Can't get free memory for Buff2\n"); + Status = EXIT_FAILURE; + goto Cleanup; + } + + if ((fp1 = _wfopen(File1, L"rb")) == NULL) + { + PrintResourceString(IDS_FILEERROR, File1); + Status = EXIT_FAILURE; + goto Cleanup; + } + if ((fp2 = _wfopen(File2, L"rb")) == NULL) + { + PrintResourceString(IDS_FILEERROR, File2); + Status = EXIT_FAILURE; + goto Cleanup; + } + + PrintResourceString(IDS_COMPARING, File1, File2); + + FileSizeFile1 = FileSize(fp1); + if (FileSizeFile1 == -1) + { + PrintResourceString(IDS_FILESIZEERROR, File1); + Status = EXIT_FAILURE; + goto Cleanup; + } + + FileSizeFile2 = FileSize(fp2); + if (FileSizeFile2 == -1) + { + PrintResourceString(IDS_FILESIZEERROR, File2); + Status = EXIT_FAILURE; + goto Cleanup; + } + + if (FileSizeFile1 != FileSizeFile2) + { + PrintResourceString(IDS_SIZEDIFFERS); + Status = EXIT_FAILURE; + goto Cleanup; + } + + LineNumber = 1; + Offset = 0; + while (1) + { + BufLen1 = GetBuff(Buff1, fp1); + BufLen2 = GetBuff(Buff2, fp2); + + if (ferror(fp1) || ferror(fp2)) + { + PrintResourceString(IDS_READERROR); + Status = EXIT_FAILURE; + goto Cleanup; + } + + if (!BufLen1 && !BufLen2) + break; + + assert(BufLen1 == BufLen2); + for (i = 0; i < BufLen1; i++) + { + if (Buff1[i] != Buff2[i]) + { + FilesOK = 0; + + /* Reporting here a mismatch */ + if (bLineNos) + { + PrintResourceString(IDS_MISMATCHLINE, LineNumber); + } + else + { + PrintResourceString(IDS_MISMATCHOFFSET, Offset); + } + + if (bAscii) + { + PrintResourceString(IDS_ASCIIDIFF, 1, Buff1[i]); + PrintResourceString(IDS_ASCIIDIFF, 2, Buff2[i]); + } + else + { + PrintResourceString(IDS_HEXADECIMALDIFF, 1, Buff1[i]); + PrintResourceString(IDS_HEXADECIMALDIFF, 2, Buff2[i]); + } + } + + Offset++; + + if (Buff1[i] == '\n') + LineNumber++; + } + } + + if (FilesOK) + PrintResourceString(IDS_MATCH); + +Cleanup: + if (fp2) + fclose(fp2); + if (fp1) + fclose(fp1); + + if (Buff2) + free(Buff2); + if (Buff1) + free(Buff1); + + return Status; +} + +/* EOF */ diff --git a/reactos/base/applications/cmdutils/help/CMakeLists.txt b/reactos/base/applications/cmdutils/help/CMakeLists.txt index cce3258e592..0ffad38fc79 100644 --- a/reactos/base/applications/cmdutils/help/CMakeLists.txt +++ b/reactos/base/applications/cmdutils/help/CMakeLists.txt @@ -1,6 +1,9 @@ +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) + add_executable(cmd_help help.c help.rc) set_module_type(cmd_help win32cui UNICODE) -add_importlibs(cmd_help user32 msvcrt kernel32) +target_link_libraries(cmd_help conutils ${PSEH_LIB}) +add_importlibs(cmd_help msvcrt kernel32) set_target_properties(cmd_help PROPERTIES OUTPUT_NAME "help") add_cd_file(TARGET cmd_help DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/applications/cmdutils/help/help.c b/reactos/base/applications/cmdutils/help/help.c index 012b5a6ece1..3937fa531af 100644 --- a/reactos/base/applications/cmdutils/help/help.c +++ b/reactos/base/applications/cmdutils/help/help.c @@ -14,30 +14,14 @@ #define WIN32_NO_STATUS #include #include -#include -#include + #include +#include + #include "help.h" #include "resource.h" -VOID PrintResourceString(INT resID, ...) -{ - WCHAR bufSrc[RC_STRING_MAX_SIZE]; - WCHAR bufFormatted[RC_STRING_MAX_SIZE]; - CHAR bufFormattedOem[RC_STRING_MAX_SIZE]; - - va_list args; - va_start(args, resID); - - LoadStringW(GetModuleHandleW(NULL), resID, bufSrc, ARRAYSIZE(bufSrc)); - vswprintf(bufFormatted, bufSrc, args); - CharToOemW(bufFormatted, bufFormattedOem); - fputs(bufFormattedOem, stdout); - - va_end(args); -} - BOOL IsInternalCommand(LPCWSTR Cmd) { size_t i; @@ -73,6 +57,9 @@ int wmain(int argc, WCHAR* argv[]) { WCHAR CmdLine[CMDLINE_LENGTH]; + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); + /* * If the user hasn't asked for specific help, * then print out the list of available commands. @@ -108,7 +95,7 @@ int wmain(int argc, WCHAR* argv[]) * Run " /?" in the current command processor. */ StringCbPrintfW(CmdLine, sizeof(CmdLine), L"%ls /?", argv[1]); - + _flushall(); return _wsystem(CmdLine); } diff --git a/reactos/base/applications/logoff/CMakeLists.txt b/reactos/base/applications/logoff/CMakeLists.txt index a5c08d7c24e..798d0e1d60a 100644 --- a/reactos/base/applications/logoff/CMakeLists.txt +++ b/reactos/base/applications/logoff/CMakeLists.txt @@ -1,11 +1,8 @@ -list(APPEND SOURCE - misc.c - logoff.c - precomp.h) +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) -add_executable(logoff ${SOURCE} logoff.rc) -set_module_type(logoff win32cui) +add_executable(logoff logoff.c logoff.rc) +set_module_type(logoff win32cui UNICODE) +target_link_libraries(logoff conutils ${PSEH_LIB}) add_importlibs(logoff advapi32 user32 msvcrt kernel32) -add_pch(logoff precomp.h SOURCE) add_cd_file(TARGET logoff DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/applications/logoff/logoff.c b/reactos/base/applications/logoff/logoff.c index e1ba36b2415..88e2a813880 100644 --- a/reactos/base/applications/logoff/logoff.c +++ b/reactos/base/applications/logoff/logoff.c @@ -11,88 +11,61 @@ * with Windows' system32\logoff.exe commandline application. */ -#include "precomp.h" - #include -#include -//Commandline argument switches -LPTSTR szRemoteServerName = NULL; +#include +#include +#include + +#include + +#include "resource.h" + +// Commandline argument switches +LPWSTR szRemoteServerName = NULL; BOOL bVerbose; -//---------------------------------------------------------------------- -// -//Retrieve resource string and output the Usage to the console -// -//---------------------------------------------------------------------- -static void PrintUsage() { - LPTSTR lpUsage = NULL; - - if (AllocAndLoadString(&lpUsage, GetModuleHandle(NULL), IDS_USAGE)) { - _putts(lpUsage); - LocalFree(lpUsage); - } - -} - //---------------------------------------------------------------------- // // Writes the last error as both text and error code to the console. // //---------------------------------------------------------------------- -void DisplayLastError() +VOID DisplayError(DWORD dwError) { - int errorCode = GetLastError(); - LPTSTR lpMsgBuf; - - // Display the error message to the user - FormatMessage( - FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - errorCode, - LANG_USER_DEFAULT, - (LPTSTR) &lpMsgBuf, - 0, - NULL); - - _ftprintf(stderr, lpMsgBuf); - _ftprintf(stderr, _T("Error code: %d\n"), errorCode); - - LocalFree(lpMsgBuf); + ConMsgPrintf(StdErr, + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, dwError, LANG_USER_DEFAULT); + ConPrintf(StdErr, L"Error code: %lu\n", dwError); } //---------------------------------------------------------------------- // -//Sets flags based on commandline arguments +// Sets flags based on commandline arguments // //---------------------------------------------------------------------- -BOOL ParseCommandLine(int argc, TCHAR *argv[]) +BOOL ParseCommandLine(int argc, WCHAR *argv[]) { int i; - LPTSTR lpIllegalMsg; //FIXME: Add handling of commandline arguments to select the session number and name, and also name of remote machine //Example: logoff.exe 4 /SERVER:Master should logoff session number 4 on remote machine called Master. for (i = 1; i < argc; i++) { switch(argv[i][0]){ - case '-': - case '/': + case L'-': + case L'/': // -v (verbose) - if (argv[i][1] == 'v') { + if (argv[i][1] == L'v') { bVerbose = TRUE; break; //continue parsing the arguments } // -? (usage) - else if(argv[i][1] == '?') { + else if(argv[i][1] == L'?') { return FALSE; //display the Usage } default: //Invalid parameter detected - if (AllocAndLoadString(&lpIllegalMsg, GetModuleHandle(NULL), IDS_ILLEGAL_PARAM)) { - _putts(lpIllegalMsg); - LocalFree(lpIllegalMsg); - } + ConResPrintf(StdErr, IDS_ILLEGAL_PARAM); return FALSE; } } @@ -102,46 +75,45 @@ BOOL ParseCommandLine(int argc, TCHAR *argv[]) //---------------------------------------------------------------------- // -//Main entry for program +// Main entry for program // //---------------------------------------------------------------------- -int _tmain(int argc, TCHAR *argv[]) +int wmain(int argc, WCHAR *argv[]) { - LPTSTR lpLogoffRemote, lpLogoffLocal; + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); // // Parse command line // if (!ParseCommandLine(argc, argv)) { - PrintUsage(); + ConResPrintf(StdOut, IDS_USAGE); return 1; } // - //Should we log off session on remote server? + // Should we log off session on remote server? // if (szRemoteServerName) { if (bVerbose) { - if (AllocAndLoadString(&lpLogoffRemote, GetModuleHandle(NULL), IDS_LOGOFF_REMOTE)) - _putts(lpLogoffRemote); + ConResPrintf(StdOut, IDS_LOGOFF_REMOTE); } - //FIXME: Add Remote Procedure Call to logoff user on a remote machine - _ftprintf(stderr, "Remote Procedure Call in logoff.exe has not been implemented"); + // FIXME: Add Remote Procedure Call to logoff user on a remote machine + ConPrintf(StdErr, L"Remote Procedure Call in logoff.exe has not been implemented"); } // - //Perform logoff of current session on local machine instead + // Perform logoff of current session on local machine instead // else { if (bVerbose) { - //Get resource string, and print it. - if (AllocAndLoadString(&lpLogoffLocal, GetModuleHandle(NULL), IDS_LOGOFF_LOCAL)) - _putts(lpLogoffLocal); + // Get resource string, and print it. + ConResPrintf(StdOut, IDS_LOGOFF_LOCAL); } - //Actual logoff - if (!ExitWindows(NULL, NULL)) { - DisplayLastError(); + // Actual logoff + if (!ExitWindowsEx(EWX_LOGOFF, 0)) { + DisplayError(GetLastError()); return 1; } } diff --git a/reactos/base/applications/logoff/misc.c b/reactos/base/applications/logoff/misc.c deleted file mode 100644 index d7b042bc501..00000000000 --- a/reactos/base/applications/logoff/misc.c +++ /dev/null @@ -1,63 +0,0 @@ -#include "precomp.h" - -static INT -LengthOfStrResource(IN HINSTANCE hInst, - IN UINT uID) -{ - HRSRC hrSrc; - HGLOBAL hRes; - LPWSTR lpName, lpStr; - - if (hInst == NULL) - { - return -1; - } - - /* There are always blocks of 16 strings */ - lpName = (LPWSTR)MAKEINTRESOURCE((uID >> 4) + 1); - - /* Find the string table block */ - if ((hrSrc = FindResourceW(hInst, lpName, (LPWSTR)RT_STRING)) && - (hRes = LoadResource(hInst, hrSrc)) && - (lpStr = (WCHAR*) LockResource(hRes))) - { - UINT x; - - /* Find the string we're looking for */ - uID &= 0xF; /* position in the block, same as % 16 */ - for (x = 0; x < uID; x++) - { - lpStr += (*lpStr) + 1; - } - - /* Found the string */ - return (int)(*lpStr); - } - return -1; -} - -INT -AllocAndLoadString(OUT LPTSTR *lpTarget, - IN HINSTANCE hInst, - IN UINT uID) -{ - INT ln; - - ln = LengthOfStrResource(hInst, - uID); - if (ln++ > 0) - { - (*lpTarget) = (LPTSTR)LocalAlloc(LMEM_FIXED, - ln * sizeof(TCHAR)); - if ((*lpTarget) != NULL) - { - INT Ret; - if (!(Ret = LoadString(hInst, uID, *lpTarget, ln))) - { - LocalFree((HLOCAL)(*lpTarget)); - } - return Ret; - } - } - return 0; -} diff --git a/reactos/base/applications/logoff/precomp.h b/reactos/base/applications/logoff/precomp.h deleted file mode 100644 index 44a8fc45a96..00000000000 --- a/reactos/base/applications/logoff/precomp.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __SHUTDOWN_PRECOMP_H -#define __SHUTDOWN_PRECOMP_H - -#include - -#include -#include -#include - -#include "resource.h" - -/* misc.c */ -INT AllocAndLoadString(OUT LPTSTR *lpTarget, - IN HINSTANCE hInst, - IN UINT uID); - -#endif /* __SHUTDOWN_PRECOMP_H */ diff --git a/reactos/base/applications/shutdown/CMakeLists.txt b/reactos/base/applications/shutdown/CMakeLists.txt index 3d27bb64cdc..7f91d250ba5 100644 --- a/reactos/base/applications/shutdown/CMakeLists.txt +++ b/reactos/base/applications/shutdown/CMakeLists.txt @@ -1,4 +1,6 @@ +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) + list(APPEND SOURCE gui.c misc.c @@ -7,6 +9,7 @@ list(APPEND SOURCE add_executable(shutdown ${SOURCE} shutdown.rc) set_module_type(shutdown win32cui UNICODE) +target_link_libraries(shutdown conutils ${PSEH_LIB}) add_importlibs(shutdown advapi32 user32 powrprof msvcrt kernel32) add_pch(shutdown precomp.h SOURCE) add_cd_file(TARGET shutdown DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/applications/shutdown/misc.c b/reactos/base/applications/shutdown/misc.c index bbd8d42c3ea..49c36306395 100644 --- a/reactos/base/applications/shutdown/misc.c +++ b/reactos/base/applications/shutdown/misc.c @@ -162,29 +162,10 @@ DWORD ParseReasonCode(LPCWSTR code) /* Writes the last error as both text and error code to the console */ VOID DisplayError(DWORD dwError) { - LPWSTR lpMsgBuf = NULL; - DWORD errLength; /* Error message length */ - LPSTR resMsg; /* For error message in OEM symbols */ - - /* Grabs the length of the error message */ - errLength = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - dwError, - LANG_USER_DEFAULT, - (LPWSTR)&lpMsgBuf, - 0, - NULL) + 1; - - /* Gets the error message ready for output */ - resMsg = (LPSTR)LocalAlloc(LPTR, errLength * sizeof(WCHAR)); - CharToOemBuffW(lpMsgBuf, resMsg, errLength); - - /* Prints out the error message to the user */ - fprintf(stderr, resMsg); - fwprintf(stderr, L"Error code: %lu\n", dwError); - - LocalFree(lpMsgBuf); - LocalFree(resMsg); + ConMsgPrintf(StdErr, + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, dwError, LANG_USER_DEFAULT); + ConPrintf(StdErr, L"Error code: %lu\n", dwError); } /* EOF */ diff --git a/reactos/base/applications/shutdown/precomp.h b/reactos/base/applications/shutdown/precomp.h index 43cb0994969..f13ce2b0d4b 100644 --- a/reactos/base/applications/shutdown/precomp.h +++ b/reactos/base/applications/shutdown/precomp.h @@ -10,14 +10,16 @@ #include #include +#include + #include "resource.h" /* DEFINES *******************************************************************/ + #define MAX_MESSAGE_SIZE 512 #define MAX_MAJOR_CODE 256 #define MAX_MINOR_CODE 65536 #define MAX_TIMEOUT 315360000 -#define MAX_BUFFER_SIZE 5024 /* Reason Code List */ typedef struct _REASON diff --git a/reactos/base/applications/shutdown/shutdown.c b/reactos/base/applications/shutdown/shutdown.c index 2aa14c4486c..9e24b924c4c 100644 --- a/reactos/base/applications/shutdown/shutdown.c +++ b/reactos/base/applications/shutdown/shutdown.c @@ -11,21 +11,6 @@ #include #include -/* - * This takes strings from a resource stringtable - * and outputs it to the console. - */ -VOID PrintResourceString(INT resID, ...) -{ - WCHAR tmpBuffer[MAX_BUFFER_SIZE]; - va_list arg_ptr; - - va_start(arg_ptr, resID); - LoadStringW(GetModuleHandle(NULL), resID, tmpBuffer, MAX_BUFFER_SIZE); - vfwprintf(stdout, tmpBuffer, arg_ptr); - va_end(arg_ptr); -} - /* * Takes the commandline arguments, and creates a * struct which matches the arguments supplied. @@ -202,6 +187,9 @@ int wmain(int argc, WCHAR *argv[]) DWORD error = ERROR_SUCCESS; struct CommandLineOptions opts; + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); + if (argc == 1) /* i.e. no commandline arguments given */ { PrintResourceString(IDS_USAGE); diff --git a/reactos/base/system/chkdsk/CMakeLists.txt b/reactos/base/system/chkdsk/CMakeLists.txt index c292fbb5b81..c89a29cdcf4 100644 --- a/reactos/base/system/chkdsk/CMakeLists.txt +++ b/reactos/base/system/chkdsk/CMakeLists.txt @@ -1,7 +1,9 @@ include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/fmifs) +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) add_executable(chkdsk chkdsk.c chkdsk.rc) set_module_type(chkdsk win32cui UNICODE) +target_link_libraries(chkdsk conutils ${PSEH_LIB}) add_importlibs(chkdsk fmifs msvcrt kernel32 ntdll) add_cd_file(TARGET chkdsk DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/system/chkdsk/chkdsk.c b/reactos/base/system/chkdsk/chkdsk.c index 262e85ab21e..0c28e62082a 100644 --- a/reactos/base/system/chkdsk/chkdsk.c +++ b/reactos/base/system/chkdsk/chkdsk.c @@ -47,6 +47,8 @@ #include #include +#include + #define NTOS_MODE_USER #include @@ -60,7 +62,7 @@ // BOOL Error = FALSE; -// switches +// Switches BOOL FixErrors = FALSE; BOOL SkipClean = FALSE; BOOL ScanSectors = FALSE; @@ -85,15 +87,11 @@ PCHKDSK Chkdsk; //---------------------------------------------------------------------- static VOID PrintWin32Error(LPWSTR Message, DWORD ErrorCode) { - LPWSTR lpMsgBuf; - - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, ErrorCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPWSTR)&lpMsgBuf, 0, NULL); - - wprintf(L"%s: %s\n", Message, lpMsgBuf); - LocalFree(lpMsgBuf); + ConPrintf(StdErr, L"%s: ", Message); + ConMsgPrintf(StdErr, + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, ErrorCode, LANG_USER_DEFAULT); + ConPrintf(StdErr, L"\n"); } @@ -126,13 +124,14 @@ CtrlCIntercept(DWORD dwCtrlType) static VOID Usage(PWCHAR ProgramName) { - wprintf(L"Usage: %s [drive:] [-F] [-V] [-R] [-C]\n\n" - L"[drive:] Specifies the drive to check.\n" - L"-F Fixes errors on the disk.\n" - L"-V Displays the full path of every file on the disk.\n" - L"-R Locates bad sectors and recovers readable information.\n" - L"-C Checks the drive only if it is dirty.\n\n", - ProgramName); + ConPrintf(StdOut, + L"Usage: %s [drive:] [-F] [-V] [-R] [-C]\n\n" + L"[drive:] Specifies the drive to check.\n" + L"-F Fixes errors on the disk.\n" + L"-V Displays the full path of every file on the disk.\n" + L"-R Locates bad sectors and recovers readable information.\n" + L"-C Checks the drive only if it is dirty.\n\n", + ProgramName); } @@ -241,76 +240,76 @@ ChkdskCallback( switch (Command) { case UNKNOWN2: - wprintf(L"UNKNOWN2\r"); + ConPrintf(StdOut, L"UNKNOWN2\r"); break; case UNKNOWN3: - wprintf(L"UNKNOWN3\n"); + ConPrintf(StdOut, L"UNKNOWN3\n"); break; case UNKNOWN4: - wprintf(L"UNKNOWN4\n"); + ConPrintf(StdOut, L"UNKNOWN4\n"); break; case UNKNOWN5: - wprintf(L"UNKNOWN5\n"); + ConPrintf(StdOut, L"UNKNOWN5\n"); break; case FSNOTSUPPORTED: - wprintf(L"FSNOTSUPPORTED\n"); + ConPrintf(StdOut, L"FSNOTSUPPORTED\n"); break; case VOLUMEINUSE: - wprintf(L"VOLUMEINUSE\n"); + ConPrintf(StdOut, L"VOLUMEINUSE\n"); break; case UNKNOWN9: - wprintf(L"UNKNOWN9\n"); + ConPrintf(StdOut, L"UNKNOWN9\n"); break; case UNKNOWNA: - wprintf(L"UNKNOWNA\n"); + ConPrintf(StdOut, L"UNKNOWNA\n"); break; case UNKNOWNC: - wprintf(L"UNKNOWNC\n"); + ConPrintf(StdOut, L"UNKNOWNC\n"); break; case UNKNOWND: - wprintf(L"UNKNOWND\n"); + ConPrintf(StdOut, L"UNKNOWND\n"); break; case INSUFFICIENTRIGHTS: - wprintf(L"INSUFFICIENTRIGHTS\n"); + ConPrintf(StdOut, L"INSUFFICIENTRIGHTS\n"); break; case STRUCTUREPROGRESS: - wprintf(L"STRUCTUREPROGRESS\n"); + ConPrintf(StdOut, L"STRUCTUREPROGRESS\n"); break; case DONEWITHSTRUCTURE: - wprintf(L"DONEWITHSTRUCTURE\n"); + ConPrintf(StdOut, L"DONEWITHSTRUCTURE\n"); break; case CLUSTERSIZETOOSMALL: - wprintf(L"CLUSTERSIZETOOSMALL\n"); + ConPrintf(StdOut, L"CLUSTERSIZETOOSMALL\n"); break; case PROGRESS: percent = (PDWORD)Argument; - wprintf(L"%d percent completed.\r", *percent); + ConPrintf(StdOut, L"%d percent completed.\r", *percent); break; case OUTPUT: output = (PTEXTOUTPUT)Argument; - wprintf(L"%S", output->Output); + ConPrintf(StdOut, L"%S", output->Output); break; case DONE: status = (PBOOLEAN)Argument; if (*status == FALSE) { - wprintf(L"Chkdsk was unable to complete successfully.\n\n"); + ConPrintf(StdOut, L"Chkdsk was unable to complete successfully.\n\n"); Error = TRUE; } break; @@ -361,16 +360,20 @@ int wmain(int argc, WCHAR *argv[]) { int badArg; - HANDLE volumeHandle; - WCHAR fileSystem[1024]; - WCHAR volumeName[1024]; - DWORD serialNumber; - DWORD flags, maxComponent; + HANDLE volumeHandle; + WCHAR fileSystem[1024]; + WCHAR volumeName[1024]; + DWORD serialNumber; + DWORD flags, maxComponent; - wprintf(L"\n" - L"Chkdskx v1.0.1 by Mark Russinovich\n" - L"Systems Internals - http://www.sysinternals.com\n" - L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n"); + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); + + ConPrintf(StdOut, + L"\n" + L"Chkdskx v1.0.1 by Mark Russinovich\n" + L"Systems Internals - http://www.sysinternals.com\n" + L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n"); #ifndef FMIFS_IMPORT_DLL // @@ -378,7 +381,7 @@ wmain(int argc, WCHAR *argv[]) // if (!LoadFMIFSEntryPoints()) { - wprintf(L"Could not located FMIFS entry points.\n\n"); + ConPrintf(StdErr, L"Could not located FMIFS entry points.\n\n"); return -1; } #endif @@ -389,7 +392,7 @@ wmain(int argc, WCHAR *argv[]) badArg = ParseCommandLine(argc, argv); if (badArg) { - wprintf(L"Unknown argument: %s\n", argv[badArg]); + ConPrintf(StdOut, L"Unknown argument: %s\n", argv[badArg]); Usage(argv[0]); return -1; } @@ -445,7 +448,7 @@ wmain(int argc, WCHAR *argv[]) 0); if (volumeHandle == INVALID_HANDLE_VALUE) { - wprintf(L"Chdskx cannot run because the volume is in use by another process.\n\n"); + ConPrintf(StdErr, L"Chkdsk cannot run because the volume is in use by another process.\n\n"); return -1; } CloseHandle(volumeHandle); @@ -459,7 +462,7 @@ wmain(int argc, WCHAR *argv[]) // // Just do it // - wprintf(L"The type of file system is %s.\n", fileSystem); + ConPrintf(StdOut, L"The type of file system is %s.\n", fileSystem); Chkdsk(Drive, fileSystem, FixErrors, diff --git a/reactos/base/system/format/CMakeLists.txt b/reactos/base/system/format/CMakeLists.txt index 4afe5f00b80..eb0c275b4a2 100644 --- a/reactos/base/system/format/CMakeLists.txt +++ b/reactos/base/system/format/CMakeLists.txt @@ -1,8 +1,10 @@ include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/fmifs) +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) add_executable(format format.c format.rc) set_module_type(format win32cui UNICODE) +target_link_libraries(format conutils ${PSEH_LIB}) +add_importlibs(format fmifs msvcrt kernel32 ntdll) set_target_properties(format PROPERTIES SUFFIX ".com") -add_importlibs(format user32 fmifs msvcrt kernel32 ntdll) add_cd_file(TARGET format DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/system/format/format.c b/reactos/base/system/format/format.c index 38f5d16d942..5bd7623fe8b 100644 --- a/reactos/base/system/format/format.c +++ b/reactos/base/system/format/format.c @@ -46,8 +46,8 @@ #define WIN32_NO_STATUS #include #include -#include -#include + +#include #define NTOS_MODE_USER #include @@ -62,7 +62,7 @@ // Globals BOOL Error = FALSE; -// switches +// Switches BOOL QuickFormat = FALSE; DWORD ClusterSize = 0; BOOL CompressDrive = FALSE; @@ -107,39 +107,6 @@ SIZEDEFINITION LegalSizes[] = { }; -VOID PrintStringV(LPWSTR szStr, va_list args) -{ - WCHAR bufFormatted[RC_STRING_MAX_SIZE]; - CHAR bufFormattedOem[RC_STRING_MAX_SIZE]; - - _vsnwprintf(bufFormatted, ARRAYSIZE(bufFormatted), szStr, args); - - CharToOemW(bufFormatted, bufFormattedOem); - puts(bufFormattedOem); -} - -VOID PrintString(LPWSTR szStr, ...) -{ - va_list args; - - va_start(args, szStr); - PrintStringV(szStr, args); - va_end(args); -} - -VOID PrintResourceString(UINT uID, ...) -{ - WCHAR bufSrc[RC_STRING_MAX_SIZE]; - va_list args; - - LoadStringW(GetModuleHandleW(NULL), uID, bufSrc, ARRAYSIZE(bufSrc)); - - va_start(args, uID); - PrintStringV(bufSrc, args); - va_end(args); -} - - //---------------------------------------------------------------------- // // PrintWin32Error @@ -149,15 +116,11 @@ VOID PrintResourceString(UINT uID, ...) //---------------------------------------------------------------------- static VOID PrintWin32Error(LPWSTR Message, DWORD ErrorCode) { - LPWSTR lpMsgBuf; - - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, ErrorCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPWSTR)&lpMsgBuf, 0, NULL); - - PrintString(L"%s: %s\n", Message, lpMsgBuf); - LocalFree(lpMsgBuf); + ConPrintf(StdErr, L"%s: ", Message); + ConMsgPrintf(StdErr, + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, ErrorCode, LANG_USER_DEFAULT); + ConPrintf(StdErr, L"\n"); } @@ -266,19 +229,19 @@ FormatExCallback( { case PROGRESS: percent = (PDWORD)Argument; - PrintResourceString(STRING_COMPLETE, *percent); + ConResPrintf(StdOut, STRING_COMPLETE, *percent); break; case OUTPUT: output = (PTEXTOUTPUT)Argument; - wprintf(L"%S", output->Output); + ConPrintf(StdOut, L"%S\n", output->Output); break; case DONE: status = (PBOOLEAN)Argument; if (*status == FALSE) { - PrintResourceString(STRING_FORMAT_FAIL); + ConResPrintf(StdOut, STRING_FORMAT_FAIL); Error = TRUE; } break; @@ -297,7 +260,7 @@ FormatExCallback( case UNKNOWND: case STRUCTUREPROGRESS: case CLUSTERSIZETOOSMALL: - PrintResourceString(STRING_NO_SUPPORT); + ConResPrintf(StdOut, STRING_NO_SUPPORT); return FALSE; } return TRUE; @@ -359,12 +322,12 @@ static VOID Usage(LPWSTR ProgramName) BYTE dummy; BOOLEAN latestVersion; - LoadStringW(GetModuleHandle(NULL), STRING_HELP, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_HELP, szMsg, ARRAYSIZE(szMsg)); #ifndef FMIFS_IMPORT_DLL if (!LoadFMIFSEntryPoints()) { - PrintString(szMsg, ProgramName, L""); + ConPrintf(StdOut, szMsg, ProgramName, L""); return; } #endif @@ -379,7 +342,7 @@ static VOID Usage(LPWSTR ProgramName) wcscat(szFormats, szFormatW); } - PrintString(szMsg, ProgramName, szFormats); + ConPrintf(StdOut, szMsg, ProgramName, szFormats); } @@ -408,10 +371,14 @@ int wmain(int argc, WCHAR *argv[]) ULARGE_INTEGER freeBytesAvailableToCaller, totalNumberOfBytes, totalNumberOfFreeBytes; WCHAR szMsg[RC_STRING_MAX_SIZE]; - wprintf(L"\n" - L"Formatx v1.0 by Mark Russinovich\n" - L"Systems Internals - http://www.sysinternals.com\n" - L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n"); + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); + + ConPrintf(StdOut, + L"\n" + L"Formatx v1.0 by Mark Russinovich\n" + L"Systems Internals - http://www.sysinternals.com\n" + L"ReactOS adaptation 1999 by Emanuele Aliberti\n\n"); #ifndef FMIFS_IMPORT_DLL // @@ -419,7 +386,7 @@ int wmain(int argc, WCHAR *argv[]) // if (!LoadFMIFSEntryPoints()) { - PrintResourceString(STRING_FMIFS_FAIL); + ConResPrintf(StdErr, STRING_FMIFS_FAIL); return -1; } #endif @@ -430,7 +397,7 @@ int wmain(int argc, WCHAR *argv[]) badArg = ParseCommandLine(argc, argv); if (badArg) { - PrintResourceString(STRING_UNKNOW_ARG, argv[badArg]); + ConResPrintf(StdOut, STRING_UNKNOW_ARG, argv[badArg]); Usage(argv[0]); return -1; } @@ -440,7 +407,7 @@ int wmain(int argc, WCHAR *argv[]) // if (!Drive) { - PrintResourceString(STRING_DRIVE_PARM); + ConResPrintf(StdOut, STRING_DRIVE_PARM); Usage(argv[0]); return -1; } @@ -458,22 +425,22 @@ int wmain(int argc, WCHAR *argv[]) switch (driveType) { case DRIVE_UNKNOWN : - LoadStringW(GetModuleHandle(NULL), STRING_ERROR_DRIVE_TYPE, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_ERROR_DRIVE_TYPE, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; case DRIVE_REMOTE: case DRIVE_CDROM: - PrintResourceString(STRING_NO_SUPPORT); + ConResPrintf(StdOut, STRING_NO_SUPPORT); return -1; case DRIVE_NO_ROOT_DIR: - LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; case DRIVE_REMOVABLE: - PrintResourceString(STRING_INSERT_DISK, RootDirectory[0]); + ConResPrintf(StdOut, STRING_INSERT_DISK, RootDirectory[0]); fgetws(input, ARRAYSIZE(input), stdin); media = FMIFS_FLOPPY; break; @@ -495,7 +462,7 @@ int wmain(int argc, WCHAR *argv[]) if (towlower(path[0]) == towlower(Drive[0])) { // todo: report "Cannot format system drive" - PrintResourceString(STRING_NO_SUPPORT); + ConResPrintf(StdOut, STRING_NO_SUPPORT); return -1; } } @@ -508,7 +475,7 @@ int wmain(int argc, WCHAR *argv[]) &serialNumber, &maxComponent, &flags, fileSystem, ARRAYSIZE(fileSystem))) { - LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; } @@ -518,11 +485,11 @@ int wmain(int argc, WCHAR *argv[]) &totalNumberOfBytes, &totalNumberOfFreeBytes)) { - LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; } - PrintResourceString(STRING_FILESYSTEM, fileSystem); + ConResPrintf(StdOut, STRING_FILESYSTEM, fileSystem); // // Make sure they want to do this @@ -533,27 +500,27 @@ int wmain(int argc, WCHAR *argv[]) { while (TRUE) { - PrintResourceString(STRING_LABEL_NAME_EDIT, RootDirectory[0]); + ConResPrintf(StdOut, STRING_LABEL_NAME_EDIT, RootDirectory[0]); fgetws(input, ARRAYSIZE(input), stdin); input[wcslen(input) - 1] = 0; if (!wcsicmp(input, volumeName)) break; - PrintResourceString(STRING_ERROR_LABEL); + ConResPrintf(StdOut, STRING_ERROR_LABEL); } } - PrintResourceString(STRING_YN_FORMAT, RootDirectory[0]); + ConResPrintf(StdOut, STRING_YN_FORMAT, RootDirectory[0]); - LoadStringW(GetModuleHandle(NULL), STRING_YES_NO_FAQ, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_YES_NO_FAQ, szMsg, ARRAYSIZE(szMsg)); while (TRUE) { fgetws(input, ARRAYSIZE(input), stdin); if (_wcsnicmp(&input[0], &szMsg[0], 1) == 0) break; if (_wcsnicmp(&input[0], &szMsg[1], 1) == 0) { - wprintf(L"\n"); + ConPrintf(StdOut, L"\n"); return 0; } } @@ -564,30 +531,30 @@ int wmain(int argc, WCHAR *argv[]) // if (!QuickFormat) { - LoadStringW(GetModuleHandle(NULL), STRING_VERIFYING, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_VERIFYING, szMsg, ARRAYSIZE(szMsg)); if (totalNumberOfBytes.QuadPart > 1024*1024*10) { - PrintString(L"%s %luM\n", szMsg, (DWORD)(totalNumberOfBytes.QuadPart/(1024*1024))); + ConPrintf(StdOut, L"%s %luM\n", szMsg, (DWORD)(totalNumberOfBytes.QuadPart/(1024*1024))); } else { - PrintString(L"%s %.1fM\n", szMsg, + ConPrintf(StdOut, L"%s %.1fM\n", szMsg, ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0)); } } else { - LoadStringW(GetModuleHandle(NULL), STRING_FAST_FMT, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_FAST_FMT, szMsg, ARRAYSIZE(szMsg)); if (totalNumberOfBytes.QuadPart > 1024*1024*10) { - PrintString(L"%s %luM\n", szMsg, (DWORD)(totalNumberOfBytes.QuadPart/(1024*1024))); + ConPrintf(StdOut, L"%s %luM\n", szMsg, (DWORD)(totalNumberOfBytes.QuadPart/(1024*1024))); } else { - PrintString(L"%s %.2fM\n", szMsg, + ConPrintf(StdOut, L"%s %.2fM\n", szMsg, ((float)(LONGLONG)totalNumberOfBytes.QuadPart)/(float)(1024.0*1024.0)); } - PrintResourceString(STRING_CREATE_FSYS); + ConResPrintf(StdOut, STRING_CREATE_FSYS); } // @@ -596,7 +563,7 @@ int wmain(int argc, WCHAR *argv[]) FormatEx(RootDirectory, media, FileSystem, Label, QuickFormat, ClusterSize, FormatExCallback); if (Error) return -1; - PrintResourceString(STRING_FMT_COMPLETE); + ConResPrintf(StdOut, STRING_FMT_COMPLETE); // // Enable compression if desired @@ -604,7 +571,7 @@ int wmain(int argc, WCHAR *argv[]) if (CompressDrive) { if (!EnableVolumeCompression(RootDirectory, TRUE)) - PrintResourceString(STRING_VOL_COMPRESS); + ConResPrintf(StdOut, STRING_VOL_COMPRESS); } // @@ -612,13 +579,13 @@ int wmain(int argc, WCHAR *argv[]) // if (!GotALabel) { - PrintResourceString(STRING_ENTER_LABEL); + ConResPrintf(StdOut, STRING_ENTER_LABEL); fgetws(input, ARRAYSIZE(LabelString), stdin); input[wcslen(input) - 1] = 0; if (!SetVolumeLabelW(RootDirectory, input)) { - LoadStringW(GetModuleHandle(NULL), STRING_NO_LABEL, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_NO_LABEL, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; } @@ -629,7 +596,7 @@ int wmain(int argc, WCHAR *argv[]) &serialNumber, &maxComponent, &flags, fileSystem, ARRAYSIZE(fileSystem))) { - LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; } @@ -642,13 +609,13 @@ int wmain(int argc, WCHAR *argv[]) &totalNumberOfBytes, &totalNumberOfFreeBytes)) { - LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME_SIZE, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; } - PrintResourceString(STRING_FREE_SPACE, totalNumberOfBytes.QuadPart, - totalNumberOfFreeBytes.QuadPart); + ConResPrintf(StdOut, STRING_FREE_SPACE, totalNumberOfBytes.QuadPart, + totalNumberOfFreeBytes.QuadPart); // // Get the drive's serial number @@ -658,13 +625,13 @@ int wmain(int argc, WCHAR *argv[]) &serialNumber, &maxComponent, &flags, fileSystem, ARRAYSIZE(fileSystem))) { - LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); + K32LoadStringW(GetModuleHandle(NULL), STRING_NO_VOLUME, szMsg, ARRAYSIZE(szMsg)); PrintWin32Error(szMsg, GetLastError()); return -1; } - PrintResourceString(STRING_SERIAL_NUMBER, - (unsigned int)(serialNumber >> 16), - (unsigned int)(serialNumber & 0xFFFF)); + ConResPrintf(StdOut, STRING_SERIAL_NUMBER, + (unsigned int)(serialNumber >> 16), + (unsigned int)(serialNumber & 0xFFFF)); return 0; } diff --git a/reactos/base/system/subst/CMakeLists.txt b/reactos/base/system/subst/CMakeLists.txt index e1f04ea61c8..7531f5daa03 100644 --- a/reactos/base/system/subst/CMakeLists.txt +++ b/reactos/base/system/subst/CMakeLists.txt @@ -1,5 +1,8 @@ +include_directories(${REACTOS_SOURCE_DIR}/sdk/lib/conutils) + add_executable(subst subst.c subst.rc) set_module_type(subst win32cui UNICODE) -add_importlibs(subst msvcrt kernel32 user32 ntdll) +target_link_libraries(subst conutils ${PSEH_LIB}) +add_importlibs(subst msvcrt kernel32 ntdll) add_cd_file(TARGET subst DESTINATION reactos/system32 FOR all) diff --git a/reactos/base/system/subst/subst.c b/reactos/base/system/subst/subst.c index bbbd8d970d7..57f284f5d73 100644 --- a/reactos/base/system/subst/subst.c +++ b/reactos/base/system/subst/subst.c @@ -15,7 +15,8 @@ #define WIN32_NO_STATUS #include #include -#include + +#include #include "resource.h" @@ -23,48 +24,28 @@ VOID PrintError(IN DWORD ErrCode) { - WCHAR szFmtString[RC_STRING_MAX_SIZE] = {0}; - PWSTR buffer, msg = NULL; + DWORD dwLength = 0; + PWSTR pMsgBuf = NULL; - buffer = (PWSTR)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 2048 * sizeof(WCHAR)); - if (!buffer) +#if 0 + if (ErrCode == ERROR_SUCCESS) return; +#endif - FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, - NULL, - ErrCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (PWSTR)&msg, - 0, - NULL); - if (msg) + /* Retrieve the message string without appending extra newlines */ + dwLength = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_MAX_WIDTH_MASK, + NULL, + ErrCode, + LANG_USER_DEFAULT, + (PWSTR)&pMsgBuf, + 0, NULL); + if (pMsgBuf /* && dwLength */) { - LoadStringW(GetModuleHandleW(NULL), - IDS_FAILED_WITH_ERRORCODE, - szFmtString, - ARRAYSIZE(szFmtString)); - _snwprintf(buffer, - 2048, - szFmtString, - ErrCode, - msg); - wprintf(L"%s", buffer); - - LocalFree(msg); + ConResPrintf(StdErr, IDS_FAILED_WITH_ERRORCODE, + ErrCode, pMsgBuf); + LocalFree(pMsgBuf); } - - HeapFree(GetProcessHeap(), 0, buffer); -} - -VOID DisplaySubstUsage(VOID) -{ - WCHAR szHelp[RC_STRING_MAX_SIZE] = {0}; - - LoadStringW(GetModuleHandleW(NULL), - IDS_USAGE, - szHelp, - ARRAYSIZE(szHelp)); - wprintf(L"%s", szHelp); } ULONG QuerySubstedDrive(IN WCHAR DriveLetter, @@ -172,7 +153,7 @@ VOID DumpSubstedDrives(VOID) DriveLetter = L'A' + i; if (QuerySubstedDrive(DriveLetter, &lpTargetPath, &dwSize) == ERROR_IS_SUBSTED) { - wprintf(L"%c:\\: => %s\n", DriveLetter, lpTargetPath + 4); + ConPrintf(StdOut, L"%c:\\: => %s\n", DriveLetter, lpTargetPath + 4); } i++; @@ -184,7 +165,6 @@ VOID DumpSubstedDrives(VOID) INT DeleteSubst(IN PWSTR Drive) { DWORD dwResult; - WCHAR szFmtString[RC_STRING_MAX_SIZE] = {0}; if ((wcslen(Drive) != 2) || (Drive[1] != L':')) { @@ -212,21 +192,13 @@ Quit: // case ERROR_INVALID_DRIVE: case ERROR_INVALID_PARAMETER: { - LoadStringW(GetModuleHandleW(NULL), - IDS_INVALID_PARAMETER2, - szFmtString, - ARRAYSIZE(szFmtString)); - wprintf(szFmtString, Drive); + ConResPrintf(StdErr, IDS_INVALID_PARAMETER2, Drive); return 1; } case ERROR_ACCESS_DENIED: { - LoadStringW(GetModuleHandleW(NULL), - IDS_ACCESS_DENIED, - szFmtString, - ARRAYSIZE(szFmtString)); - wprintf(szFmtString, Drive); + ConResPrintf(StdErr, IDS_ACCESS_DENIED, Drive); return 1; } @@ -243,7 +215,6 @@ Quit: INT AddSubst(IN PWSTR Drive, IN PWSTR Path) { DWORD dwResult, dwPathAttr; - WCHAR szFmtString[RC_STRING_MAX_SIZE] = {0}; if ((wcslen(Drive) != 2) || (Drive[1] != L':')) { @@ -289,42 +260,26 @@ Quit: case ERROR_INVALID_DRIVE: case ERROR_INVALID_PARAMETER: { - LoadStringW(GetModuleHandleW(NULL), - IDS_INVALID_PARAMETER2, - szFmtString, - ARRAYSIZE(szFmtString)); - wprintf(szFmtString, Drive); + ConResPrintf(StdErr, IDS_INVALID_PARAMETER2, Drive); return 1; } case ERROR_IS_SUBSTED: { - LoadStringW(GetModuleHandleW(NULL), - IDS_DRIVE_ALREADY_SUBSTED, - szFmtString, - ARRAYSIZE(szFmtString)); - wprintf(szFmtString); + ConResPrintf(StdErr, IDS_DRIVE_ALREADY_SUBSTED); return 1; } case ERROR_FILE_NOT_FOUND: case ERROR_PATH_NOT_FOUND: { - LoadStringW(GetModuleHandleW(NULL), - IDS_PATH_NOT_FOUND, - szFmtString, - ARRAYSIZE(szFmtString)); - wprintf(szFmtString, Path); + ConResPrintf(StdErr, IDS_PATH_NOT_FOUND, Path); return 1; } case ERROR_ACCESS_DENIED: { - LoadStringW(GetModuleHandleW(NULL), - IDS_ACCESS_DENIED, - szFmtString, - ARRAYSIZE(szFmtString)); - wprintf(szFmtString, Path); + ConResPrintf(StdErr, IDS_ACCESS_DENIED, Path); return 1; } @@ -341,13 +296,15 @@ Quit: int wmain(int argc, WCHAR* argv[]) { INT i; - WCHAR szFmtString[RC_STRING_MAX_SIZE] = {0}; + + /* Initialize the Console Standard Streams */ + ConInitStdStreams(); for (i = 0; i < argc; i++) { if (!_wcsicmp(argv[i], L"/?")) { - DisplaySubstUsage(); + ConResPrintf(StdOut, IDS_USAGE); return 0; } } @@ -356,11 +313,7 @@ int wmain(int argc, WCHAR* argv[]) { if (argc >= 2) { - LoadStringW(GetModuleHandleW(NULL), - IDS_INVALID_PARAMETER, - szFmtString, - ARRAYSIZE(szFmtString)); - wprintf(szFmtString, argv[1]); + ConResPrintf(StdErr, IDS_INVALID_PARAMETER, argv[1]); return 1; } DumpSubstedDrives(); @@ -369,11 +322,7 @@ int wmain(int argc, WCHAR* argv[]) if (argc > 3) { - LoadStringW(GetModuleHandleW(NULL), - IDS_INCORRECT_PARAMETER_COUNT, - szFmtString, - ARRAYSIZE(szFmtString)); - wprintf(szFmtString, argv[3]); + ConResPrintf(StdErr, IDS_INCORRECT_PARAMETER_COUNT, argv[3]); return 1; }