| 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 | |
| 41 | void |
| 42 | winVMsg(int, MessageType, int verb, const char *, va_list) |
| 43 | _X_ATTRIBUTE_PRINTF(4, 0); |
| 44 | |
| 45 | void |
| 46 | winVMsg(int scrnIndex, MessageType type, int verb, const char *format, |
| 47 | va_list ap) |
| 48 | { |
| 49 | LogVMessageVerb(type, verb, format, ap); |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | winDrvMsg(int scrnIndex, MessageType type, const char *format, ...) |
| 54 | { |
| 55 | va_list ap; |
| 56 | |
| 57 | va_start(ap, format); |
| 58 | LogVMessageVerb(type, 0, format, ap); |
| 59 | va_end(ap); |
| 60 | } |
| 61 | |
| 62 | void |
| 63 | winMsg(MessageType type, const char *format, ...) |
| 64 | { |
| 65 | va_list ap; |
| 66 | |
| 67 | va_start(ap, format); |
| 68 | LogVMessageVerb(type, 1, format, ap); |
| 69 | va_end(ap); |
| 70 | } |
| 71 | |
| 72 | void |
| 73 | winDrvMsgVerb(int scrnIndex, MessageType type, int verb, const char *format, |
| 74 | ...) |
| 75 | { |
| 76 | va_list ap; |
| 77 | |
| 78 | va_start(ap, format); |
| 79 | LogVMessageVerb(type, verb, format, ap); |
| 80 | va_end(ap); |
| 81 | } |
| 82 | |
| 83 | void |
| 84 | winMsgVerb(MessageType type, int verb, const char *format, ...) |
| 85 | { |
| 86 | va_list ap; |
| 87 | |
| 88 | va_start(ap, format); |
| 89 | LogVMessageVerb(type, verb, format, ap); |
| 90 | va_end(ap); |
| 91 | } |
| 92 | |
| 93 | void |
| 94 | winErrorFVerb(int verb, const char *format, ...) |
| 95 | { |
| 96 | va_list ap; |
| 97 | |
| 98 | va_start(ap, format); |
| 99 | LogVMessageVerb(X_NONE, verb, format, ap); |
| 100 | va_end(ap); |
| 101 | } |
| 102 | |
| 103 | void |
| 104 | winDebug(const char *format, ...) |
| 105 | { |
| 106 | va_list ap; |
| 107 | |
| 108 | va_start(ap, format); |
| 109 | LogVMessageVerb(X_NONE, 3, format, ap); |
| 110 | va_end(ap); |
| 111 | } |
| 112 | |
| 113 | void |
| 114 | winTrace(const char *format, ...) |
| 115 | { |
| 116 | va_list ap; |
| 117 | |
| 118 | va_start(ap, format); |
| 119 | LogVMessageVerb(X_NONE, 10, format, ap); |
| 120 | va_end(ap); |
| 121 | } |
| 122 | |
| 123 | void |
| 124 | winW32Error(int verb, const char *msg) |
| 125 | { |
| 126 | winW32ErrorEx(verb, msg, GetLastError()); |
| 127 | } |
| 128 | |
| 129 | void |
| 130 | winW32ErrorEx(int verb, const char *msg, DWORD errorcode) |
| 131 | { |
| 132 | LPVOID buffer; |
| 133 | |
| 134 | if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | |
| 135 | FORMAT_MESSAGE_FROM_SYSTEM | |
| 136 | FORMAT_MESSAGE_IGNORE_INSERTS, |
| 137 | NULL, |
| 138 | errorcode, |
| 139 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 140 | (LPTSTR) &buffer, 0, NULL)) { |
| 141 | winErrorFVerb(verb, "Unknown error in FormatMessage!\n"); |
| 142 | } |
| 143 | else { |
| 144 | winErrorFVerb(verb, "%s %s", msg, (char *) buffer); |
| 145 | LocalFree(buffer); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | #if CYGDEBUG |
| 150 | void |
| 151 | winDebugWin32Message(const char *function, HWND hwnd, UINT message, |
| 152 | WPARAM wParam, LPARAM lParam) |
| 153 | { |
| 154 | static int force = 0; |
| 155 | |
| 156 | if (message >= WM_USER) { |
| 157 | if (force || getenv("WIN_DEBUG_MESSAGES") || |
| 158 | getenv("WIN_DEBUG_WM_USER")) { |
| 159 | winDebug("%s - Message WM_USER + %d\n", function, |
| 160 | message - WM_USER); |
| 161 | winDebug("\thwnd 0x%x wParam 0x%x lParam 0x%x\n", hwnd, wParam, |
| 162 | lParam); |
| 163 | } |
| 164 | } |
| 165 | else if (message < MESSAGE_NAMES_LEN && MESSAGE_NAMES[message]) { |
| 166 | const char *msgname = MESSAGE_NAMES[message]; |
| 167 | char buffer[64]; |
| 168 | |
| 169 | snprintf(buffer, sizeof(buffer), "WIN_DEBUG_%s", msgname); |
| 170 | buffer[63] = 0; |
| 171 | if (force || getenv("WIN_DEBUG_MESSAGES") || getenv(buffer)) { |
| 172 | winDebug("%s - Message %s\n", function, MESSAGE_NAMES[message]); |
| 173 | winDebug("\thwnd 0x%x wParam 0x%x lParam 0x%x\n", hwnd, wParam, |
| 174 | lParam); |
| 175 | } |
| 176 | } |
| 177 | } |
| 178 | #else |
| 179 | void |
| 180 | winDebugWin32Message(const char *function, HWND hwnd, UINT message, |
| 181 | WPARAM wParam, LPARAM lParam) |
| 182 | { |
| 183 | } |
| 184 | #endif |