From: Hugh McMaster Subject: [3/4] regsvr32: Replace all printf calls with calls to output_write; remove Silent check. Message-Id: <9CB7F20010CADE479EB89B7DCEDFB64268076ED6E9@VMBX112.ihostexchange.net> Date: Mon, 10 Mar 2014 22:21:32 -0400 This patch replaces all printf calls with calls to output_write and, hence, FormatStringW (see patch 1). The Silent check is also removed, as it is now located in the output_write function. From 7643756c371c1f490469d5bfa5c66f459b4a1db3 Mon Sep 17 00:00:00 2001 From: Hugh McMaster Date: Mon, 10 Mar 2014 22:35:01 +1100 Subject: Convert printf to FormatString --- programs/regsvr32/Makefile.in | 2 +- programs/regsvr32/regsvr32.c | 65 ++++++++++++++++--------------------------- 2 files changed, 25 insertions(+), 42 deletions(-) diff --git a/programs/regsvr32/Makefile.in b/programs/regsvr32/Makefile.in index b2c4e1b..db567ea 100644 --- a/programs/regsvr32/Makefile.in +++ b/programs/regsvr32/Makefile.in @@ -1,6 +1,6 @@ MODULE = regsvr32.exe APPMODE = -mconsole -IMPORTS = ole32 +IMPORTS = ole32 user32 C_SRCS = \ regsvr32.c diff --git a/programs/regsvr32/regsvr32.c b/programs/regsvr32/regsvr32.c index 94db5f2..4ec7a9e 100644 --- a/programs/regsvr32/regsvr32.c +++ b/programs/regsvr32/regsvr32.c @@ -51,10 +51,9 @@ #include "config.h" #include "wine/port.h" -#include -#include #include #include +#include "regsvr32.h" #include "wine/debug.h" WINE_DEFAULT_DEBUG_CHANNEL(regsvr32); @@ -65,18 +64,6 @@ typedef HRESULT (*DLLINSTALL) (BOOL,LPCWSTR); static BOOL Silent = FALSE; -static int Usage(void) -{ - printf("regsvr32 [/u] [/s] [/n] [/i[:cmdline]] dllname ...\n"); - printf("\t[/u] unregister server\n"); - printf("\t[/s] silent (no message boxes)\n"); - printf("\t[/i] Call DllInstall passing it an optional [cmdline];\n"); - printf("\t when used with /u calls dll uninstall\n"); - printf("\t[/n] Do not call DllRegisterServer; this option " - "must be used with [/i]\n"); - return 0; -} - static void __cdecl output_write(UINT id, ...) { static WCHAR fmt[1024]; @@ -142,16 +129,13 @@ static VOID *LoadProc(const char* strDll, const char* procName, HMODULE* DllHand *DllHandle = LoadLibraryExA(strDll, 0, LOAD_WITH_ALTERED_SEARCH_PATH); if(!*DllHandle) { - if(!Silent) - printf("Failed to load DLL %s\n", strDll); - + output_write(STRING_DLL_LOAD_FAILED, strDll); ExitProcess(1); } proc = (VOID *) GetProcAddress(*DllHandle, procName); if(!proc) { - if(!Silent) - printf("%s not implemented in DLL %s\n", procName, strDll); + output_write(STRING_PROC_NOT_IMPLEMENTED, procName, strDll); FreeLibrary(*DllHandle); return NULL; } @@ -171,13 +155,10 @@ static int RegisterDll(const char* strDll) hr = pfRegister(); if(FAILED(hr)) { - if(!Silent) - printf("Failed to register DLL %s\n", strDll); - + output_write(STRING_REGISTER_FAILED, strDll); return -1; } - if(!Silent) - printf("Successfully registered DLL %s\n", strDll); + output_write(STRING_REGISTER_SUCCESSFUL, strDll); if(DllHandle) FreeLibrary(DllHandle); @@ -197,13 +178,10 @@ static int UnregisterDll(char* strDll) hr = pfUnregister(); if(FAILED(hr)) { - if(!Silent) - printf("Failed to unregister DLL %s\n", strDll); - + output_write(STRING_UNREGISTER_FAILED, strDll); return -1; } - if(!Silent) - printf("Successfully unregistered DLL %s\n", strDll); + output_write(STRING_UNREGISTER_SUCCESSFUL, strDll); if(DllHandle) FreeLibrary(DllHandle); @@ -223,14 +201,16 @@ static int InstallDll(BOOL install, char *strDll, WCHAR *command_line) hr = pfInstall(install, command_line); if(FAILED(hr)) { - if(!Silent) - printf("Failed to %s DLL %s\n", install ? "install" : "uninstall", - strDll); + if (install) + output_write(STRING_INSTALL_FAILED, strDll); + else + output_write(STRING_UNINSTALL_FAILED, strDll); return -1; } - if(!Silent) - printf("Successfully %s DLL %s\n", install ? "installed" : "uninstalled", - strDll); + if (install) + output_write(STRING_INSTALL_SUCCESSFUL, strDll); + else + output_write(STRING_UNINSTALL_SUCCESSFUL, strDll); if(DllHandle) FreeLibrary(DllHandle); @@ -250,7 +230,7 @@ int main(int argc, char* argv[]) OleInitialize(NULL); /* Strictly, the Microsoft version processes all the flags before - * the files (e.g. regsvr32 file1 /s file2 is silent even for file1. + * the files (e.g. regsvr32 file1 /s file2 is silent even for file1). * For ease, we will not replicate that and will process the arguments * in order. */ @@ -307,7 +287,11 @@ int main(int argc, char* argv[]) else if((!strcasecmp(argv[i], "/c"))||(!strcasecmp(argv[i], "-c"))) /* console output */; else if (argv[i][0] == '/' && (!argv[i][2] || argv[i][2] == ':')) - printf("Unrecognized switch %s\n", argv[i]); + { + output_write(STRING_UNRECOGNIZED_SWITCH, argv[i]); + output_write(STRING_USAGE); + return 0; + } else { char *DllName = argv[i]; @@ -338,10 +322,9 @@ int main(int argc, char* argv[]) if (!DllFound) { - if(!Silent) - return Usage(); - else - return -1; + output_write(STRING_HEADER); + output_write(STRING_USAGE); + return 1; } OleUninitialize(); -- 1.8.3.2