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