From 9678907d34ceec9c0eab2b9a4b798b7b5e8b5883 Mon Sep 17 00:00:00 2001 From: Andrew Nguyen Date: Tue, 14 Jun 2011 08:01:37 -0500 Subject: [PATCH] dxdiag: Introduce the file output infrastructure. --- programs/dxdiag/Makefile.in | 3 +- programs/dxdiag/dxdiag_private.h | 45 ++++++++++++++++++++++++++ programs/dxdiag/main.c | 39 +++++++++++++++++++--- programs/dxdiag/output.c | 55 ++++++++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 5 deletions(-) create mode 100644 programs/dxdiag/dxdiag_private.h create mode 100644 programs/dxdiag/output.c diff --git a/programs/dxdiag/Makefile.in b/programs/dxdiag/Makefile.in index 941d2c7e8b4..608790af72f 100644 --- a/programs/dxdiag/Makefile.in +++ b/programs/dxdiag/Makefile.in @@ -3,6 +3,7 @@ MODULE = dxdiag.exe APPMODE = -mwindows -municode C_SRCS = \ - main.c + main.c \ + output.c @MAKE_PROG_RULES@ diff --git a/programs/dxdiag/dxdiag_private.h b/programs/dxdiag/dxdiag_private.h new file mode 100644 index 00000000000..48b4c4d30d6 --- /dev/null +++ b/programs/dxdiag/dxdiag_private.h @@ -0,0 +1,45 @@ +/* + * Private definitions for the DirectX Diagnostic Tool + * + * Copyright 2011 Andrew Nguyen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* Output backend definitions. */ +enum output_type +{ + OUTPUT_NONE, + OUTPUT_TEXT, + OUTPUT_XML, +}; + +static inline const char *debugstr_output_type(enum output_type type) +{ + switch (type) + { + case OUTPUT_NONE: + return "(none)"; + case OUTPUT_TEXT: + return "Plain-text output"; + case OUTPUT_XML: + return "XML output"; + default: + return "(unknown)"; + } +} + +const WCHAR *get_output_extension(enum output_type type); +BOOL output_dxdiag_information(const WCHAR *filename, enum output_type type); diff --git a/programs/dxdiag/main.c b/programs/dxdiag/main.c index 3b89b192c49..6e4042c4e77 100644 --- a/programs/dxdiag/main.c +++ b/programs/dxdiag/main.c @@ -23,11 +23,14 @@ #include "wine/debug.h" #include "wine/unicode.h" +#include "dxdiag_private.h" + WINE_DEFAULT_DEBUG_CHANNEL(dxdiag); struct command_line_info { WCHAR outfile[MAX_PATH]; + enum output_type output_type; BOOL whql_check; }; @@ -37,7 +40,7 @@ static void usage(void) ExitProcess(0); } -static BOOL process_file_name(const WCHAR *cmdline, WCHAR *filename, size_t filename_len) +static BOOL process_file_name(const WCHAR *cmdline, enum output_type output_type, WCHAR *filename, size_t filename_len) { const WCHAR *endptr; size_t len; @@ -65,6 +68,17 @@ static BOOL process_file_name(const WCHAR *cmdline, WCHAR *filename, size_t file memcpy(filename, cmdline, len * sizeof(WCHAR)); filename[len] = '\0'; + /* Append an extension appropriate for the output type if the filename does not have one. */ + if (!(endptr = strrchrW(filename, '.'))) + { + const WCHAR *filename_ext = get_output_extension(output_type); + + if (len + strlenW(filename_ext) >= filename_len) + return FALSE; + + strcatW(filename, filename_ext); + } + return TRUE; } @@ -87,6 +101,7 @@ static BOOL process_command_line(const WCHAR *cmdline, struct command_line_info static const WCHAR onW[] = {'o','n',0}; info->whql_check = FALSE; + info->output_type = OUTPUT_NONE; while (*cmdline) { @@ -96,7 +111,11 @@ static BOOL process_command_line(const WCHAR *cmdline, struct command_line_info /* 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)); + { + info->output_type = OUTPUT_TEXT; + return process_file_name(cmdline, OUTPUT_TEXT, info->outfile, + sizeof(info->outfile)/sizeof(WCHAR)); + } cmdline++; @@ -104,10 +123,14 @@ static BOOL process_command_line(const WCHAR *cmdline, struct command_line_info { case 'T': case 't': - return process_file_name(cmdline + 1, info->outfile, sizeof(info->outfile)/sizeof(WCHAR)); + info->output_type = OUTPUT_TEXT; + return process_file_name(cmdline + 1, OUTPUT_TEXT, info->outfile, + sizeof(info->outfile)/sizeof(WCHAR)); case 'X': case 'x': - return process_file_name(cmdline + 1, info->outfile, sizeof(info->outfile)/sizeof(WCHAR)); + info->output_type = OUTPUT_XML; + return process_file_name(cmdline + 1, OUTPUT_XML, info->outfile, + sizeof(info->outfile)/sizeof(WCHAR)); case 'W': case 'w': if (strncmpiW(cmdline, whql_colonW, 5)) @@ -147,6 +170,14 @@ int WINAPI wWinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPWSTR cmdline, int cm usage(); WINE_TRACE("WHQL check: %s\n", info.whql_check ? "TRUE" : "FALSE"); + WINE_TRACE("Output type: %d\n", info.output_type); + if (info.output_type != OUTPUT_NONE) + WINE_TRACE("Output filename: %s\n", debugstr_output_type(info.output_type)); + + if (info.output_type != OUTPUT_NONE) + output_dxdiag_information(info.outfile, info.output_type); + else + WINE_FIXME("Information dialog is not implemented\n"); return 0; } diff --git a/programs/dxdiag/output.c b/programs/dxdiag/output.c new file mode 100644 index 00000000000..c7b30602cc0 --- /dev/null +++ b/programs/dxdiag/output.c @@ -0,0 +1,55 @@ +/* + * DxDiag file information output + * + * Copyright 2011 Andrew Nguyen + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + +#include "wine/debug.h" + +#include "dxdiag_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(dxdiag); + +static struct output_backend +{ + const WCHAR filename_ext[5]; +} output_backends[] = +{ + /* OUTPUT_TEXT */ + { + {'.','t','x','t',0}, + }, + /* OUTPUT_XML */ + { + {'.','x','m','l',0}, + }, +}; + +const WCHAR *get_output_extension(enum output_type type) +{ + assert(type > OUTPUT_NONE && type <= sizeof(output_backends)/sizeof(output_backends[0])); + + return output_backends[type - 1].filename_ext; +} + +BOOL output_dxdiag_information(const WCHAR *filename, enum output_type type) +{ + WINE_FIXME("File information output is not implemented\n"); + return FALSE; +}