msvcrt: Import asinh implementation from musl.
[wine.git] / programs / dxdiag / main.c
blob968d84adea12895945d8ea4beda0c314ab90b12c
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 "dxdiag_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dxdiag);
30 HINSTANCE hInstance;
32 struct command_line_info
34 WCHAR outfile[MAX_PATH];
35 enum output_type output_type;
36 BOOL whql_check;
39 static void usage(void)
41 WCHAR title[MAX_STRING_LEN];
42 WCHAR usage[MAX_STRING_LEN];
44 LoadStringW(hInstance, STRING_DXDIAG_TOOL, title, ARRAY_SIZE(title));
45 LoadStringW(hInstance, STRING_USAGE, usage, ARRAY_SIZE(usage));
47 MessageBoxW(NULL, usage, title, MB_OK | MB_ICONWARNING);
49 ExitProcess(0);
52 static BOOL process_file_name(const WCHAR *cmdline, enum output_type output_type, WCHAR *filename, size_t filename_len)
54 const WCHAR *endptr;
55 size_t len;
57 /* Skip any intervening spaces. */
58 while (*cmdline == ' ')
59 cmdline++;
61 /* Ignore filename quoting, if any. */
62 if (*cmdline == '"' && (endptr = wcsrchr(cmdline, '"')))
64 /* Reject a string with only one quote. */
65 if (cmdline == endptr)
66 return FALSE;
68 cmdline++;
70 else
71 endptr = cmdline + lstrlenW(cmdline);
73 len = endptr - cmdline;
74 if (len == 0 || len >= filename_len)
75 return FALSE;
77 memcpy(filename, cmdline, len * sizeof(WCHAR));
78 filename[len] = '\0';
80 /* Append an extension appropriate for the output type if the filename does not have one. */
81 if (!wcsrchr(filename, '.'))
83 const WCHAR *filename_ext = get_output_extension(output_type);
85 if (len + lstrlenW(filename_ext) >= filename_len)
86 return FALSE;
88 lstrcatW(filename, filename_ext);
91 return TRUE;
95 Process options [/WHQL:ON|OFF][/X outfile|/T outfile]
96 Returns TRUE if options were present, FALSE otherwise
97 Only one of /X and /T is allowed, /WHQL must come before /X and /T,
98 and the rest of the command line after /X or /T is interpreted as a
99 filename. If a non-option portion of the command line is encountered,
100 dxdiag assumes that the string is a filename for the /T option.
102 Native does not interpret quotes, but quotes are parsed here because of how
103 Wine handles the command line.
106 static BOOL process_command_line(const WCHAR *cmdline, struct command_line_info *info)
108 info->whql_check = FALSE;
109 info->output_type = OUTPUT_NONE;
111 while (*cmdline)
113 /* Skip whitespace before arg */
114 while (*cmdline == ' ')
115 cmdline++;
117 /* If no option is specified, treat the command line as a filename. */
118 if (*cmdline != '-' && *cmdline != '/')
120 info->output_type = OUTPUT_TEXT;
121 return process_file_name(cmdline, OUTPUT_TEXT, info->outfile,
122 ARRAY_SIZE(info->outfile));
125 cmdline++;
127 switch (*cmdline)
129 case 'T':
130 case 't':
131 info->output_type = OUTPUT_TEXT;
132 return process_file_name(cmdline + 1, OUTPUT_TEXT, info->outfile,
133 ARRAY_SIZE(info->outfile));
134 case 'X':
135 case 'x':
136 info->output_type = OUTPUT_XML;
137 return process_file_name(cmdline + 1, OUTPUT_XML, info->outfile,
138 ARRAY_SIZE(info->outfile));
139 case 'W':
140 case 'w':
141 if (wcsnicmp(cmdline, L"whql:", 5))
142 return FALSE;
144 cmdline += 5;
146 if (!wcsnicmp(cmdline, L"off", 3))
148 info->whql_check = FALSE;
149 cmdline += 2;
151 else if (!wcsnicmp(cmdline, L"on", 2))
153 info->whql_check = TRUE;
154 cmdline++;
156 else
157 return FALSE;
159 break;
161 case 'd':
162 case 'D':
163 if (wcsnicmp(cmdline, L"dontskip", 8))
164 return FALSE;
165 cmdline += 8;
166 break;
168 default:
169 return FALSE;
172 cmdline++;
175 return TRUE;
178 int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cmdshow)
180 struct command_line_info info;
181 struct dxdiag_information *dxdiag_info;
183 hInstance = hInst;
185 if (!process_command_line(cmdline, &info))
186 usage();
188 WINE_TRACE("WHQL check: %s\n", info.whql_check ? "TRUE" : "FALSE");
189 WINE_TRACE("Output type: %d\n", info.output_type);
190 if (info.output_type != OUTPUT_NONE)
191 WINE_TRACE("Output filename: %s\n", debugstr_output_type(info.output_type));
193 CoInitialize(NULL);
195 dxdiag_info = collect_dxdiag_information(info.whql_check);
196 if (!dxdiag_info)
198 WINE_ERR("DxDiag information collection failed\n");
199 CoUninitialize();
200 return 1;
203 if (info.output_type != OUTPUT_NONE)
204 output_dxdiag_information(dxdiag_info, info.outfile, info.output_type);
205 else
206 WINE_FIXME("Information dialog is not implemented\n");
208 free_dxdiag_information(dxdiag_info);
210 CoUninitialize();
211 return 0;