1/*
2 *Copyright (C) 1994-2000 The XFree86 Project, Inc. All Rights Reserved.
3 *
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
11 *
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
14 *
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL THE XFREE86 PROJECT BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 *Except as contained in this notice, the name of the XFree86 Project
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from the XFree86 Project.
27 *
28 * Authors: Alexander Gottwald
29 */
30
31#ifdef HAVE_XWIN_CONFIG_H
32#include <xwin-config.h>
33#endif
34#include "win.h"
35#include "winmsg.h"
36#if CYGDEBUG
37#include "winmessages.h"
38#endif
39#include <stdarg.h>
40
41void winVMsg (int, MessageType, int verb, const char *, va_list);
42
43void
44winVMsg (int scrnIndex, MessageType type, int verb, const char *format,
45	 va_list ap)
46{
47  LogVMessageVerb(type, verb, format, ap);
48}
49
50
51void
52winDrvMsg (int scrnIndex, MessageType type, const char *format, ...)
53{
54  va_list ap;
55  va_start (ap, format);
56  LogVMessageVerb(type, 0, format, ap);
57  va_end (ap);
58}
59
60
61void
62winMsg (MessageType type, const char *format, ...)
63{
64  va_list ap;
65  va_start (ap, format);
66  LogVMessageVerb(type, 1, format, ap);
67  va_end (ap);
68}
69
70
71void
72winDrvMsgVerb (int scrnIndex, MessageType type, int verb, const char *format,
73	       ...)
74{
75  va_list ap;
76  va_start (ap, format);
77  LogVMessageVerb(type, verb, format, ap);
78  va_end (ap);
79}
80
81
82void
83winMsgVerb (MessageType type, int verb, const char *format, ...)
84{
85  va_list ap;
86  va_start (ap, format);
87  LogVMessageVerb(type, verb, format, ap);
88  va_end (ap);
89}
90
91
92void
93winErrorFVerb (int verb, const char *format, ...)
94{
95  va_list ap;
96  va_start (ap, format);
97  LogVMessageVerb(X_NONE, verb, format, ap);
98  va_end (ap);
99}
100
101void
102winDebug (const char *format, ...)
103{
104  va_list ap;
105  va_start (ap, format);
106  LogVMessageVerb(X_NONE, 3, format, ap);
107  va_end (ap);
108}
109
110void
111winTrace (const char *format, ...)
112{
113  va_list ap;
114  va_start (ap, format);
115  LogVMessageVerb(X_NONE, 10, format, ap);
116  va_end (ap);
117}
118
119void
120winW32Error(int verb, const char *msg)
121{
122    winW32ErrorEx(verb, msg, GetLastError());
123}
124
125void
126winW32ErrorEx(int verb, const char *msg, DWORD errorcode)
127{
128    LPVOID buffer;
129    if (!FormatMessage(
130                FORMAT_MESSAGE_ALLOCATE_BUFFER |
131                FORMAT_MESSAGE_FROM_SYSTEM |
132                FORMAT_MESSAGE_IGNORE_INSERTS,
133                NULL,
134                errorcode,
135                MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
136                (LPTSTR) &buffer,
137                0,
138                NULL ))
139    {
140        winErrorFVerb(verb, "Unknown error in FormatMessage!\n");
141    }
142    else
143    {
144        winErrorFVerb(verb, "%s %s", msg, (char *)buffer);
145        LocalFree(buffer);
146    }
147}
148
149#if CYGDEBUG
150void winDebugWin32Message(const char* function, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
151{
152  static int force = 0;
153
154  if (message >= WM_USER)
155    {
156      if (force || getenv("WIN_DEBUG_MESSAGES") || getenv("WIN_DEBUG_WM_USER"))
157      {
158        winDebug("%s - Message WM_USER + %d\n", function, message - WM_USER);
159        winDebug("\thwnd 0x%x wParam 0x%x lParam 0x%x\n", hwnd, wParam, lParam);
160      }
161    }
162  else if (message < MESSAGE_NAMES_LEN && MESSAGE_NAMES[message])
163    {
164      const char *msgname = MESSAGE_NAMES[message];
165      char buffer[64];
166      snprintf(buffer, sizeof(buffer), "WIN_DEBUG_%s", msgname);
167      buffer[63] = 0;
168      if (force || getenv("WIN_DEBUG_MESSAGES") || getenv(buffer))
169      {
170        winDebug("%s - Message %s\n", function, MESSAGE_NAMES[message]);
171        winDebug("\thwnd 0x%x wParam 0x%x lParam 0x%x\n", hwnd, wParam, lParam);
172      }
173    }
174}
175#else
176void winDebugWin32Message(const char* function, HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
177{
178}
179#endif
180