1 /**************************************************************************
3 * Copyright 2008-2010 Vmware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
34 #ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
39 #elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
46 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
48 #ifndef WIN32_LEAN_AND_MEAN
49 #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
62 #ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
64 _EngDebugPrint(const char *format, ...)
68 EngDebugPrint("", (PCHAR)format, ap);
75 os_log_message(const char *message)
77 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
78 _EngDebugPrint("%s", message);
79 #elif defined(PIPE_SUBSYSTEM_WINDOWS_USER)
80 OutputDebugStringA(message);
81 if(GetConsoleWindow() && !IsDebuggerPresent()) {
83 fputs(message, stderr);
86 #elif defined(PIPE_SUBSYSTEM_WINDOWS_CE)
89 /* Format is ascii - needs to be converted to wchar_t for printing */
90 wide_str_len = MultiByteToWideChar(CP_ACP, 0, message, -1, NULL, 0);
91 wide_format = (wchar_t *) malloc((wide_str_len+1) * sizeof(wchar_t));
93 MultiByteToWideChar(CP_ACP, 0, message, -1,
94 wide_format, wide_str_len);
95 NKDbgPrintfW(wide_format, wide_format);
98 #elif defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
100 #else /* !PIPE_SUBSYSTEM_WINDOWS */
102 fputs(message, stderr);
107 #ifdef PIPE_SUBSYSTEM_WINDOWS_DISPLAY
109 find(const char *start, const char *end, char c)
112 for(p = start; !end || p != end; ++p) {
122 compare(const char *start, const char *end, const char *s)
125 for(p = start, q = s; p != end && *q != '\0'; ++p, ++q) {
129 return p == end && *q == '\0';
133 copy(char *dst, const char *start, const char *end, size_t n)
137 for(p = start, q = dst, n = n - 1; p != end && n; ++p, ++q, --n)
145 os_get_option(const char *name)
147 #if defined(PIPE_SUBSYSTEM_WINDOWS_DISPLAY)
148 /* EngMapFile creates the file if it does not exists, so it must either be
149 * disabled on release versions (or put in a less conspicuous place). */
151 const char *result = NULL;
153 const void *pMap = NULL;
154 const char *sol, *eol, *sep;
155 static char output[1024];
157 pMap = EngMapFile(L"\\??\\c:\\gallium.cfg", 0, &iFile);
159 sol = (const char *)pMap;
161 /* TODO: handle LF line endings */
162 eol = find(sol, NULL, '\r');
163 if(!eol || eol == sol)
165 sep = find(sol, eol, '=');
168 if(compare(sol, sep, name)) {
169 copy(output, sep + 1, eol, sizeof(output));
181 #elif defined(PIPE_SUBSYSTEM_WINDOWS_CE) || defined(PIPE_SUBSYSTEM_WINDOWS_MINIPORT)
182 /* TODO: implement */