From: Hans Leidekker hans@codeweavers.com
--- programs/wmic/main.c | 6 +++--- programs/wmic/wmic.h | 2 +- programs/wmic/wmic.rc | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/programs/wmic/main.c b/programs/wmic/main.c index a46e73c4c76..363b9af581f 100644 --- a/programs/wmic/main.c +++ b/programs/wmic/main.c @@ -341,7 +341,7 @@ static int process_args( int argc, WCHAR *argv[] ) int i;
for (i = 0; i < argc && argv[i][0] == '/'; i++) - WINE_FIXME( "command line switch %s not supported\n", debugstr_w(argv[i]) ); + WINE_FIXME( "switch %s not supported\n", debugstr_w(argv[i]) );
if (i >= argc) goto not_supported; @@ -351,7 +351,7 @@ static int process_args( int argc, WCHAR *argv[] ) return 0; }
- if (!wcsicmp( argv[i], L"class") || !wcsicmp( argv[i], L"context" )) + if (!wcsicmp( argv[i], L"class" ) || !wcsicmp( argv[i], L"context" )) { WINE_FIXME( "command %s not supported\n", debugstr_w(argv[i]) ); goto not_supported; @@ -388,7 +388,7 @@ static int process_args( int argc, WCHAR *argv[] ) }
not_supported: - output_error( STRING_CMDLINE_NOT_SUPPORTED ); + output_error( STRING_COMMAND_NOT_SUPPORTED ); return 1; }
diff --git a/programs/wmic/wmic.h b/programs/wmic/wmic.h index fef2113feb0..b5779bd6eb9 100644 --- a/programs/wmic/wmic.h +++ b/programs/wmic/wmic.h @@ -18,7 +18,7 @@
#include <windef.h>
-#define STRING_CMDLINE_NOT_SUPPORTED 101 +#define STRING_COMMAND_NOT_SUPPORTED 101 #define STRING_ALIAS_NOT_FOUND 102 #define STRING_INVALID_QUERY 103 #define STRING_INVALID_PATH 104 diff --git a/programs/wmic/wmic.rc b/programs/wmic/wmic.rc index 797fe7dbe08..80d76ac1447 100644 --- a/programs/wmic/wmic.rc +++ b/programs/wmic/wmic.rc @@ -24,7 +24,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_DEFAULT
STRINGTABLE { - STRING_CMDLINE_NOT_SUPPORTED, "Error: Command line not supported\n" + STRING_COMMAND_NOT_SUPPORTED, "Error: Command not supported\n" STRING_ALIAS_NOT_FOUND, "Error: Alias not found\n" STRING_INVALID_QUERY, "Error: Invalid query\n" STRING_INVALID_PATH, "Error: Invalid syntax for PATH\n"
From: Hans Leidekker hans@codeweavers.com
--- programs/wmic/main.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/programs/wmic/main.c b/programs/wmic/main.c index 363b9af581f..c1a20384eb3 100644 --- a/programs/wmic/main.c +++ b/programs/wmic/main.c @@ -405,22 +405,25 @@ int __cdecl wmain(int argc, WCHAR *argv[])
while (fgetws(cmd, sizeof(cmd), stdin) != NULL) { - cmd[wcslen(cmd)-1] = 0; /* remove trailing '\n' */ + const WCHAR *stripped;
- WINE_TRACE("command: %s\n", debugstr_w(cmd)); - if (!wcsicmp( strip_spaces(cmd), L"exit" ) || !wcsicmp( strip_spaces(cmd), L"quit" )) + cmd[wcslen(cmd) - 1] = 0; /* remove trailing '\n' */ + stripped = strip_spaces( cmd ); + + WINE_TRACE("command: %s\n", debugstr_w(stripped)); + if (!wcsicmp( stripped, L"exit" ) || !wcsicmp( stripped, L"quit" )) return 0;
- if (!cmd[0]) + if (!stripped[0]) output_error( STRING_USAGE ); else { - int _argc; - WCHAR **_argv; + int new_argc; + WCHAR **new_argv;
- _argv = CommandLineToArgvW( strip_spaces(cmd), &_argc ); - ret = process_args( _argc, _argv ); - LocalFree(_argv); + new_argv = CommandLineToArgvW( stripped, &new_argc ); + ret = process_args( new_argc, new_argv ); + LocalFree( new_argv );
output_newline(); } @@ -429,5 +432,5 @@ int __cdecl wmain(int argc, WCHAR *argv[]) return ret; }
- return process_args( argc - 1, &argv[1] ); + return process_args( argc - 1, argv + 1 ); }
From: Hans Leidekker hans@codeweavers.com
--- programs/wmic/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/programs/wmic/main.c b/programs/wmic/main.c index c1a20384eb3..56c57ea45e9 100644 --- a/programs/wmic/main.c +++ b/programs/wmic/main.c @@ -421,7 +421,7 @@ int __cdecl wmain(int argc, WCHAR *argv[]) int new_argc; WCHAR **new_argv;
- new_argv = CommandLineToArgvW( stripped, &new_argc ); + if (!(new_argv = CommandLineToArgvW( stripped, &new_argc ))) return 1; ret = process_args( new_argc, new_argv ); LocalFree( new_argv );
From: Hans Leidekker hans@codeweavers.com
--- programs/wmic/main.c | 103 +++++++++++++++++++++++-------------------- 1 file changed, 55 insertions(+), 48 deletions(-)
diff --git a/programs/wmic/main.c b/programs/wmic/main.c index 56c57ea45e9..f996d8018f4 100644 --- a/programs/wmic/main.c +++ b/programs/wmic/main.c @@ -107,62 +107,67 @@ static int output_newline( void ) return output_string( L"\n" ); }
-static WCHAR * strip_spaces(WCHAR *start) +static WCHAR *strip_spaces( WCHAR *start ) { - WCHAR *str = start, *end; - - while (*str == ' ') - str++; - - end = start + lstrlenW(start) - 1; - while (end >= start && *end == ' ') - { - *end = '\0'; - end--; - } - + WCHAR *str = start, *end = start + wcslen( start ) - 1; + while (*str == ' ') str++; + while (end >= start && *end == ' ') *end-- = 0; return str; }
-static HRESULT process_property_list( IWbemClassObject *obj, const WCHAR *proplist, WCHAR **ret ) +static HRESULT append_property( IWbemClassObject *obj, const WCHAR *prop, WCHAR *proplist ) { - WCHAR *p, *ctx, *ptr, *stripped; - HRESULT hr = S_OK; + HRESULT hr;
- if (!(p = wcsdup( proplist ))) return E_OUTOFMEMORY; + if (FAILED(hr = IWbemClassObject_Get( obj, prop, 0, NULL, NULL, NULL ))) return hr; + if (*proplist) wcscat( proplist, L"," ); + wcscat( proplist, prop ); + return S_OK; +}
- if (!(stripped = malloc( (wcslen( proplist ) + 1) * sizeof(**ret) ))) - { - free( p ); - return E_OUTOFMEMORY; - } +static HRESULT process_property_list( IWbemClassObject *obj, int argc, WCHAR *argv[], WCHAR **ret ) +{ + WCHAR *str = NULL, *ctx, *ptr, *stripped; + UINT i, len = 0; + HRESULT hr; + + for (i = 0; i < argc; i++) len += wcslen( argv[i] ); + if (!(stripped = malloc( (len + 1) * sizeof(*stripped) ))) return E_OUTOFMEMORY; *stripped = 0;
- /* Validate that every requested property is supported. */ - ptr = wcstok_s( p, L",", &ctx ); - while (ptr) + for (i = 0; i < argc; i++) { - ptr = strip_spaces( ptr ); + if (!(str = wcsdup( argv[i] ))) + { + free( stripped ); + return E_OUTOFMEMORY; + }
- if (FAILED(IWbemClassObject_Get( obj, ptr, 0, NULL, NULL, NULL ))) + /* Validate that every requested property is supported. */ + ptr = wcstok_s( str, L",", &ctx ); + if (!ptr) + { + ptr = strip_spaces( str ); + if (FAILED(hr = append_property( obj, ptr, stripped ))) goto error; + } + else { - hr = E_FAIL; - break; + while (ptr) + { + ptr = strip_spaces( ptr ); + if (FAILED(hr = append_property( obj, ptr, stripped ))) goto error; + ptr = wcstok_s( NULL, L",", &ctx ); + } } - if (*stripped) wcscat( stripped, L"," ); - wcscat( stripped, ptr ); - ptr = wcstok_s( NULL, L",", &ctx ); + free( str ); } - free( p );
- if (SUCCEEDED(hr)) - *ret = stripped; - else - { - free( stripped ); - *ret = NULL; - } + *ret = stripped; + return S_OK;
+error: + free( str ); + free( stripped ); return hr; }
@@ -218,7 +223,7 @@ done: WINE_FIXME( "Could not convert variant, vt %u.\n", vt ); }
-static int query_prop( const WCHAR *class, const WCHAR *propnames ) +static int query_prop( const WCHAR *class, int argc, WCHAR *argv[] ) { HRESULT hr; IWbemLocator *locator = NULL; @@ -231,8 +236,11 @@ static int query_prop( const WCHAR *class, const WCHAR *propnames ) IWbemClassObject *obj; ULONG count, width = 0; VARIANT v; + int i;
- WINE_TRACE("%s, %s\n", debugstr_w(class), debugstr_w(propnames)); + WINE_TRACE( "%s", debugstr_w(class) ); + for (i = 0; i < argc; i++) WINE_TRACE( " %s", debugstr_w(argv[i]) ); + WINE_TRACE( "\n" );
CoInitialize( NULL ); CoInitializeSecurity( NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, @@ -256,7 +264,7 @@ static int query_prop( const WCHAR *class, const WCHAR *propnames ) }
/* Check that this class supports all requested properties. */ - hr = process_property_list( obj, propnames, &proplist ); + hr = process_property_list( obj, argc, argv, &proplist ); IWbemClassObject_Release( obj ); if (FAILED(hr)) { @@ -337,7 +345,7 @@ done:
static int process_args( int argc, WCHAR *argv[] ) { - const WCHAR *class, *value; + const WCHAR *class; int i;
for (i = 0; i < argc && argv[i][0] == '/'; i++) @@ -383,8 +391,7 @@ static int process_args( int argc, WCHAR *argv[] ) { if (++i >= argc) goto not_supported; - value = argv[i]; - return query_prop( class, value ); + return query_prop( class, argc - i, argv + i ); }
not_supported: @@ -403,14 +410,14 @@ int __cdecl wmain(int argc, WCHAR *argv[]) { fputws( L"wmic:root\cli>", stdout );
- while (fgetws(cmd, sizeof(cmd), stdin) != NULL) + while (fgetws( cmd, sizeof(cmd), stdin ) != NULL) { const WCHAR *stripped;
cmd[wcslen(cmd) - 1] = 0; /* remove trailing '\n' */ stripped = strip_spaces( cmd );
- WINE_TRACE("command: %s\n", debugstr_w(stripped)); + WINE_TRACE( "command: %s\n", debugstr_w(stripped) ); if (!wcsicmp( stripped, L"exit" ) || !wcsicmp( stripped, L"quit" )) return 0;