Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
a7f0dc07
Commit
a7f0dc07
authored
Oct 08, 2018
by
Hans Leidekker
Committed by
Alexandre Julliard
Oct 08, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wmic: Output Unicode text with BOM when redirected.
Signed-off-by:
Hans Leidekker
<
hans@codeweavers.com
>
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
2ccb82b0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
24 deletions
+33
-24
main.c
programs/wmic/main.c
+33
-24
No files found.
programs/wmic/main.c
View file @
a7f0dc07
...
...
@@ -124,32 +124,17 @@ static WCHAR *find_prop( IWbemClassObject *class, const WCHAR *prop )
static
int
output_string
(
HANDLE
handle
,
const
WCHAR
*
msg
,
...
)
{
va_list
va_args
;
int
w
len
;
DWORD
count
,
ret
;
int
len
;
DWORD
count
;
WCHAR
buffer
[
8192
];
va_start
(
va_args
,
msg
);
vsprintfW
(
buffer
,
msg
,
va_args
);
len
=
vsnprintfW
(
buffer
,
ARRAY_SIZE
(
buffer
)
,
msg
,
va_args
);
va_end
(
va_args
);
wlen
=
strlenW
(
buffer
);
ret
=
WriteConsoleW
(
handle
,
buffer
,
wlen
,
&
count
,
NULL
);
if
(
!
ret
)
{
DWORD
len
;
char
*
msgA
;
/* On Windows WriteConsoleW() fails if the output is redirected. So fall
* back to WriteFile(), assuming the console encoding is still the right
* one in that case.
*/
len
=
WideCharToMultiByte
(
GetConsoleOutputCP
(),
0
,
buffer
,
wlen
,
NULL
,
0
,
NULL
,
NULL
);
if
(
!
(
msgA
=
HeapAlloc
(
GetProcessHeap
(),
0
,
len
*
sizeof
(
char
)
)))
return
0
;
WideCharToMultiByte
(
GetConsoleOutputCP
(),
0
,
buffer
,
wlen
,
msgA
,
len
,
NULL
,
NULL
);
WriteFile
(
handle
,
msgA
,
len
,
&
count
,
FALSE
);
HeapFree
(
GetProcessHeap
(),
0
,
msgA
);
}
if
(
!
WriteConsoleW
(
handle
,
buffer
,
len
,
&
count
,
NULL
))
WriteFile
(
handle
,
buffer
,
len
*
sizeof
(
WCHAR
),
&
count
,
FALSE
);
return
count
;
}
...
...
@@ -162,13 +147,37 @@ static int output_error( int msg )
return
output_string
(
GetStdHandle
(
STD_ERROR_HANDLE
),
fmtW
,
buffer
);
}
static
int
output_header
(
const
WCHAR
*
prop
)
{
static
const
WCHAR
bomW
[]
=
{
0xfeff
},
fmtW
[]
=
{
'%'
,
's'
,
'\r'
,
'\n'
,
0
};
int
len
;
DWORD
count
;
WCHAR
buffer
[
8192
];
len
=
snprintfW
(
buffer
,
ARRAY_SIZE
(
buffer
),
fmtW
,
prop
);
if
(
!
WriteConsoleW
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
buffer
,
len
,
&
count
,
NULL
))
/* redirected */
{
WriteFile
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
bomW
,
sizeof
(
bomW
),
&
count
,
FALSE
);
WriteFile
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
buffer
,
len
*
sizeof
(
WCHAR
),
&
count
,
FALSE
);
count
+=
sizeof
(
bomW
);
}
return
count
;
}
static
int
output_line
(
const
WCHAR
*
str
)
{
static
const
WCHAR
fmtW
[]
=
{
'%'
,
's'
,
'\r'
,
'\n'
,
0
};
return
output_string
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
fmtW
,
str
);
}
static
int
query_prop
(
const
WCHAR
*
class
,
const
WCHAR
*
propname
)
{
static
const
WCHAR
select_allW
[]
=
{
'S'
,
'E'
,
'L'
,
'E'
,
'C'
,
'T'
,
' '
,
'*'
,
' '
,
'F'
,
'R'
,
'O'
,
'M'
,
' '
,
0
};
static
const
WCHAR
cimv2W
[]
=
{
'R'
,
'O'
,
'O'
,
'T'
,
'\\'
,
'C'
,
'I'
,
'M'
,
'V'
,
'2'
,
0
};
static
const
WCHAR
wqlW
[]
=
{
'W'
,
'Q'
,
'L'
,
0
};
static
const
WCHAR
newlineW
[]
=
{
'\r'
,
'\n'
,
0
};
static
const
WCHAR
fmtW
[]
=
{
'%'
,
's'
,
'\r'
,
'\n'
,
0
};
HRESULT
hr
;
IWbemLocator
*
locator
=
NULL
;
IWbemServices
*
services
=
NULL
;
...
...
@@ -218,13 +227,13 @@ static int query_prop( const WCHAR *class, const WCHAR *propname )
output_error
(
STRING_INVALID_QUERY
);
goto
done
;
}
output_
string
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
fmtW
,
prop
);
output_
header
(
prop
);
first
=
FALSE
;
}
if
(
IWbemClassObject_Get
(
obj
,
prop
,
0
,
&
v
,
NULL
,
NULL
)
==
WBEM_S_NO_ERROR
)
{
VariantChangeType
(
&
v
,
&
v
,
0
,
VT_BSTR
);
output_
string
(
GetStdHandle
(
STD_OUTPUT_HANDLE
),
fmtW
,
V_BSTR
(
&
v
)
);
output_
line
(
V_BSTR
(
&
v
)
);
VariantClear
(
&
v
);
}
IWbemClassObject_Release
(
obj
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment