dxdiag: Introduce the file output infrastructure.

This commit is contained in:
Andrew Nguyen 2011-06-14 08:01:37 -05:00 committed by Alexandre Julliard
parent 024ab0c537
commit 9678907d34
4 changed files with 137 additions and 5 deletions

View File

@ -3,6 +3,7 @@ MODULE = dxdiag.exe
APPMODE = -mwindows -municode
C_SRCS = \
main.c
main.c \
output.c
@MAKE_PROG_RULES@

View File

@ -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);

View File

@ -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;
}

55
programs/dxdiag/output.c Normal file
View File

@ -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 <assert.h>
#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;
}