dxdiag: add basic command line parsing
Austin English
austinenglish at gmail.com
Wed Aug 26 11:54:10 CDT 2009
On Wed, Aug 26, 2009 at 9:43 AM, Austin English<austinenglish at gmail.com> wrote:
> On Wed, Aug 26, 2009 at 3:34 AM, Henri Verbeet<hverbeet at gmail.com> wrote:
>> 2009/8/26 Austin English <austinenglish at gmail.com>:
>>> Based on Dan Kegel's patch he wrote for Louis Lenders old implementation.
>>>
>> It probably doesn't make much of a difference for command line
>> parsing, but I think you want to make dxdiag explicitly unicode from
>> the start (new programs in general, really).
>
> I was trying to get some simple skeleton stuff in from the older
> patches but I'll see what I can do for Unicode support.
>
>> It also seems to me that this patch doesn't do a whole lot in practice.
>
> Right. The UCLA code has more support for dumping the info to an xml
> file, but that would be a *lot* more code. It also lets apps use /x,
> /t, etc., though both that and no switch both return 0, so not a big
> difference in practice as you pointed out.
>
> --
> -Austin
>
How's this?
--
-Austin
-------------- next part --------------
diff --git a/programs/dxdiag/main.c b/programs/dxdiag/main.c
index d24945c..5edfc6e 100644
--- a/programs/dxdiag/main.c
+++ b/programs/dxdiag/main.c
@@ -20,8 +20,77 @@
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
+#include "wine/debug.h"
-int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR cmdline, int cmdshow)
+WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
+
+/*
+ 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.
+*/
+
+static BOOL ProcessCommandLine(LPWSTR cmdline)
+{
+ const WCHAR *s = cmdline;
+ 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) {
+ /* Skip whitespace before arg */
+ while (*s == ' ')
+ s++;
+ /* Check for option */
+ if (*s != '-' && *s != '/')
+ return FALSE;
+ s++;
+ switch (*s++) {
+ case 'T':
+ case 't': opt_t = TRUE; want_arg = TRUE; opt_given = TRUE; break;
+ case 'X':
+ case 'x': opt_x = TRUE; want_arg = TRUE; opt_given = TRUE; break;
+ case 'W':
+ case 'w':
+ opt_given = TRUE;
+ while (isalpha(*s) || *s == ':')
+ s++;
+ break;
+ default: opt_help = TRUE; opt_given = TRUE; break;
+ }
+ /* 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;
+ break;
+ }
+ }
+ 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;
+}
+
+int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpcmdline, int cmdshow)
{
+ WCHAR *cmdline = GetCommandLineW();
+ if (ProcessCommandLine(cmdline))
+ return 0;
+
return 0;
}
More information about the wine-devel
mailing list