winex11: Consider zero-size windows mapped even when they are positioned at 0,0.
[wine/multimedia.git] / programs / dxdiag / main.c
blob3ced122d6e7c03eaf9e0845fa472aa4ad7c5cfe8
1 /*
2 * DxDiag Implementation
4 * Copyright 2009 Austin English
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define WIN32_LEAN_AND_MEAN
22 #include <windows.h>
23 #include <dxdiag.h>
25 #include "wine/debug.h"
26 #include "wine/unicode.h"
28 #include "dxdiag_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
32 HINSTANCE hInstance;
34 struct command_line_info
36 WCHAR outfile[MAX_PATH];
37 enum output_type output_type;
38 BOOL whql_check;
41 static void usage(void)
43 WCHAR title[MAX_STRING_LEN];
44 WCHAR usage[MAX_STRING_LEN];
46 LoadStringW(hInstance, STRING_DXDIAG_TOOL, title, sizeof(title)/sizeof(WCHAR));
47 LoadStringW(hInstance, STRING_USAGE, usage, sizeof(usage)/sizeof(WCHAR));
49 MessageBoxW(NULL, usage, title, MB_OK | MB_ICONWARNING);
51 ExitProcess(0);
54 static BOOL process_file_name(const WCHAR *cmdline, enum output_type output_type, WCHAR *filename, size_t filename_len)
56 const WCHAR *endptr;
57 size_t len;
59 /* Skip any intervening spaces. */
60 while (*cmdline == ' ')
61 cmdline++;
63 /* Ignore filename quoting, if any. */
64 if (*cmdline == '"' && (endptr = strrchrW(cmdline, '"')))
66 /* Reject a string with only one quote. */
67 if (cmdline == endptr)
68 return FALSE;
70 cmdline++;
72 else
73 endptr = cmdline + strlenW(cmdline);
75 len = endptr - cmdline;
76 if (len == 0 || len >= filename_len)
77 return FALSE;
79 memcpy(filename, cmdline, len * sizeof(WCHAR));
80 filename[len] = '\0';
82 /* Append an extension appropriate for the output type if the filename does not have one. */
83 if (!strrchrW(filename, '.'))
85 const WCHAR *filename_ext = get_output_extension(output_type);
87 if (len + strlenW(filename_ext) >= filename_len)
88 return FALSE;
90 strcatW(filename, filename_ext);
93 return TRUE;
97 Process options [/WHQL:ON|OFF][/X outfile|/T outfile]
98 Returns TRUE if options were present, FALSE otherwise
99 Only one of /X and /T is allowed, /WHQL must come before /X and /T,
100 and the rest of the command line after /X or /T is interpreted as a
101 filename. If a non-option portion of the command line is encountered,
102 dxdiag assumes that the string is a filename for the /T option.
104 Native does not interpret quotes, but quotes are parsed here because of how
105 Wine handles the command line.
108 static BOOL process_command_line(const WCHAR *cmdline, struct command_line_info *info)
110 static const WCHAR whql_colonW[] = {'w','h','q','l',':',0};
111 static const WCHAR offW[] = {'o','f','f',0};
112 static const WCHAR onW[] = {'o','n',0};
114 info->whql_check = FALSE;
115 info->output_type = OUTPUT_NONE;
117 while (*cmdline)
119 /* Skip whitespace before arg */
120 while (*cmdline == ' ')
121 cmdline++;
123 /* If no option is specified, treat the command line as a filename. */
124 if (*cmdline != '-' && *cmdline != '/')
126 info->output_type = OUTPUT_TEXT;
127 return process_file_name(cmdline, OUTPUT_TEXT, info->outfile,
128 sizeof(info->outfile)/sizeof(WCHAR));
131 cmdline++;
133 switch (*cmdline)
135 case 'T':
136 case 't':
137 info->output_type = OUTPUT_TEXT;
138 return process_file_name(cmdline + 1, OUTPUT_TEXT, info->outfile,
139 sizeof(info->outfile)/sizeof(WCHAR));
140 case 'X':
141 case 'x':
142 info->output_type = OUTPUT_XML;
143 return process_file_name(cmdline + 1, OUTPUT_XML, info->outfile,
144 sizeof(info->outfile)/sizeof(WCHAR));
145 case 'W':
146 case 'w':
147 if (strncmpiW(cmdline, whql_colonW, 5))
148 return FALSE;
150 cmdline += 5;
152 if (!strncmpiW(cmdline, offW, 3))
154 info->whql_check = FALSE;
155 cmdline += 2;
157 else if (!strncmpiW(cmdline, onW, 2))
159 info->whql_check = TRUE;
160 cmdline++;
162 else
163 return FALSE;
165 break;
166 default:
167 return FALSE;
170 cmdline++;
173 return TRUE;
176 int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
178 struct command_line_info info;
179 struct dxdiag_information *dxdiag_info;
181 hInstance = hInst;
183 if (!process_command_line(cmdline, &info))
184 usage();
186 WINE_TRACE("WHQL check: %s\n", info.whql_check ? "TRUE" : "FALSE");
187 WINE_TRACE("Output type: %d\n", info.output_type);
188 if (info.output_type != OUTPUT_NONE)
189 WINE_TRACE("Output filename: %s\n", debugstr_output_type(info.output_type));
191 CoInitialize(NULL);
193 dxdiag_info = collect_dxdiag_information(info.whql_check);
194 if (!dxdiag_info)
196 WINE_ERR("DxDiag information collection failed\n");
197 CoUninitialize();
198 return 1;
201 if (info.output_type != OUTPUT_NONE)
202 output_dxdiag_information(dxdiag_info, info.outfile, info.output_type);
203 else
204 WINE_FIXME("Information dialog is not implemented\n");
206 free_dxdiag_information(dxdiag_info);
208 CoUninitialize();
209 return 0;