Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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-winehq
Commits
1cd007fa
Commit
1cd007fa
authored
Jun 13, 2011
by
Andrew Nguyen
Committed by
Alexandre Julliard
Jun 13, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dxdiag: Improve the command-line parsing.
parent
d8cac6ff
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
46 deletions
+103
-46
main.c
programs/dxdiag/main.c
+103
-46
No files found.
programs/dxdiag/main.c
View file @
1cd007fa
...
...
@@ -25,71 +25,128 @@
WINE_DEFAULT_DEBUG_CHANNEL
(
dxdiag
);
struct
command_line_info
{
WCHAR
outfile
[
MAX_PATH
];
BOOL
whql_check
;
};
static
void
usage
(
void
)
{
WINE_FIXME
(
"Usage message box is not implemented
\n
"
);
ExitProcess
(
0
);
}
static
BOOL
process_file_name
(
const
WCHAR
*
cmdline
,
WCHAR
*
filename
,
size_t
filename_len
)
{
const
WCHAR
*
endptr
;
size_t
len
;
/* Skip any intervening spaces. */
while
(
*
cmdline
==
' '
)
cmdline
++
;
/* Ignore filename quoting, if any. */
if
(
*
cmdline
==
'"'
&&
(
endptr
=
strrchrW
(
cmdline
,
'"'
)))
{
/* Reject a string with only one quote. */
if
(
cmdline
==
endptr
)
return
FALSE
;
cmdline
++
;
}
else
endptr
=
cmdline
+
strlenW
(
cmdline
);
len
=
endptr
-
cmdline
;
if
(
len
==
0
||
len
>=
filename_len
)
return
FALSE
;
memcpy
(
filename
,
cmdline
,
len
*
sizeof
(
WCHAR
));
filename
[
len
]
=
'\0'
;
return
TRUE
;
}
/*
Process options [/WHQL:ON|OFF][/X outfile
][
/T outfile]
Process options [/WHQL:ON|OFF][/X outfile
|
/T outfile]
Returns TRUE if options were present, FALSE otherwise
FIXME: Native behavior seems to be:
Only one of /X and /T is allowed, /WHQL must come before /X and /T,
quotes are optional around the filename, even if it contains spaces.
and the rest of the command line after /X or /T is interpreted as a
filename. If a non-option portion of the command line is encountered,
dxdiag assumes that the string is a filename for the /T option.
Native does not interpret quotes, but quotes are parsed here because of how
Wine handles the command line.
*/
static
BOOL
ProcessCommandLine
(
const
WCHAR
*
s
)
static
BOOL
process_command_line
(
const
WCHAR
*
cmdline
,
struct
command_line_info
*
info
)
{
WCHAR
outfile
[
MAX_PATH
+
1
];
int
opt_t
=
FALSE
;
int
opt_x
=
FALSE
;
int
opt_help
=
FALSE
;
int
opt_given
=
FALSE
;
int
want_arg
=
FALSE
;
outfile
[
0
]
=
0
;
while
(
*
s
)
{
static
const
WCHAR
whql_colonW
[]
=
{
'w'
,
'h'
,
'q'
,
'l'
,
':'
,
0
};
static
const
WCHAR
offW
[]
=
{
'o'
,
'f'
,
'f'
,
0
};
static
const
WCHAR
onW
[]
=
{
'o'
,
'n'
,
0
};
info
->
whql_check
=
FALSE
;
while
(
*
cmdline
)
{
/* Skip whitespace before arg */
while
(
*
s
==
' '
)
s
++
;
/* Check for option */
if
(
*
s
!=
'-'
&&
*
s
!=
'/'
)
return
FALSE
;
s
++
;
switch
(
*
s
++
)
{
while
(
*
cmdline
==
' '
)
cmdline
++
;
/* If no option is specified, treat the command line as a filename. */
if
(
*
cmdline
!=
'-'
&&
*
cmdline
!=
'/'
)
return
process_file_name
(
cmdline
,
info
->
outfile
,
sizeof
(
info
->
outfile
)
/
sizeof
(
WCHAR
));
cmdline
++
;
switch
(
*
cmdline
)
{
case
'T'
:
case
't'
:
opt_t
=
TRUE
;
want_arg
=
TRUE
;
opt_given
=
TRUE
;
break
;
case
't'
:
return
process_file_name
(
cmdline
+
1
,
info
->
outfile
,
sizeof
(
info
->
outfile
)
/
sizeof
(
WCHAR
));
case
'X'
:
case
'x'
:
opt_x
=
TRUE
;
want_arg
=
TRUE
;
opt_given
=
TRUE
;
break
;
case
'x'
:
return
process_file_name
(
cmdline
+
1
,
info
->
outfile
,
sizeof
(
info
->
outfile
)
/
sizeof
(
WCHAR
));
case
'W'
:
case
'w'
:
opt_given
=
TRUE
;
while
(
isalphaW
(
*
s
)
||
*
s
==
':'
)
s
++
;
break
;
default:
opt_help
=
TRUE
;
opt_given
=
TRUE
;
break
;
if
(
strncmpiW
(
cmdline
,
whql_colonW
,
5
))
return
FALSE
;
cmdline
+=
5
;
if
(
!
strncmpiW
(
cmdline
,
offW
,
3
))
{
info
->
whql_check
=
FALSE
;
cmdline
+=
2
;
}
/* Skip any spaces before next option or filename */
while
(
*
s
==
' '
)
s
++
;
if
(
want_arg
)
{
int
i
;
if
(
*
s
==
'"'
)
s
++
;
for
(
i
=
0
;
i
<
MAX_PATH
&&
*
s
&&
*
s
!=
'"'
;
i
++
,
s
++
)
outfile
[
i
]
=
*
s
;
outfile
[
i
]
=
0
;
else
if
(
!
strncmpiW
(
cmdline
,
onW
,
2
))
{
info
->
whql_check
=
TRUE
;
cmdline
++
;
}
else
return
FALSE
;
break
;
default:
return
FALSE
;
}
cmdline
++
;
}
if
(
opt_help
)
WINE_FIXME
(
"help unimplemented
\n
"
);
if
(
opt_t
)
WINE_FIXME
(
"/t unimplemented
\n
"
);
if
(
opt_x
)
WINE_FIXME
(
"/x unimplemented
\n
"
);
return
opt_given
;
return
TRUE
;
}
int
WINAPI
wWinMain
(
HINSTANCE
hInst
,
HINSTANCE
hPrevInst
,
LPWSTR
cmdline
,
int
cmdshow
)
{
if
(
ProcessCommandLine
(
cmdline
))
return
0
;
struct
command_line_info
info
;
if
(
!
process_command_line
(
cmdline
,
&
info
))
usage
();
WINE_TRACE
(
"WHQL check: %s
\n
"
,
info
.
whql_check
?
"TRUE"
:
"FALSE"
);
return
0
;
}
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