| 1 | /* $Id: message.cpp,v 1.10 2000-02-16 14:25:42 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Win32 message API functions for OS/2 | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (ported WINE code) | 
|---|
| 7 | * | 
|---|
| 8 | * Original WINE code (loader\resource.c) | 
|---|
| 9 | * WINE level: 991031 | 
|---|
| 10 | * | 
|---|
| 11 | * Resources | 
|---|
| 12 | * | 
|---|
| 13 | * Copyright 1993 Robert J. Amstadt | 
|---|
| 14 | * Copyright 1995 Alexandre Julliard | 
|---|
| 15 | * | 
|---|
| 16 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 17 | * | 
|---|
| 18 | */ | 
|---|
| 19 | #include <os2win.h> | 
|---|
| 20 | #include <stdlib.h> | 
|---|
| 21 | #include <stdio.h> | 
|---|
| 22 | #include <string.h> | 
|---|
| 23 | #include <stdarg.h> | 
|---|
| 24 | #include "unicode.h" | 
|---|
| 25 | #include "heap.h" | 
|---|
| 26 | #include "heapstring.h" | 
|---|
| 27 |  | 
|---|
| 28 | #define DBG_LOCALLOG    DBG_message | 
|---|
| 29 | #include "dbglocal.h" | 
|---|
| 30 |  | 
|---|
| 31 | typedef VOID (* WIN32API WVSPRINTFAPROC)(LPSTR,LPCSTR,va_list); | 
|---|
| 32 | WVSPRINTFAPROC wvsprintfAProc = NULL; | 
|---|
| 33 |  | 
|---|
| 34 | BOOL LoadwvsprintfA(VOID) | 
|---|
| 35 | { | 
|---|
| 36 | //CB: load wvsprintfA dynamic to avoid problems with crosslinked DLL's | 
|---|
| 37 | if (!wvsprintfAProc) | 
|---|
| 38 | { | 
|---|
| 39 | HMODULE hUser32 = LoadLibraryA("USER32.DLL"); | 
|---|
| 40 |  | 
|---|
| 41 | wvsprintfAProc = (WVSPRINTFAPROC)GetProcAddress(hUser32,"wvsprintfA"); | 
|---|
| 42 | FreeLibrary(hUser32); | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | return wvsprintfAProc != NULL; | 
|---|
| 46 | } | 
|---|
| 47 |  | 
|---|
| 48 | //****************************************************************************** | 
|---|
| 49 | //****************************************************************************** | 
|---|
| 50 | int LoadMessageA(HINSTANCE instance, UINT id, WORD lang, | 
|---|
| 51 | LPSTR buffer, int buflen ) | 
|---|
| 52 | { | 
|---|
| 53 | HGLOBAL     hmem; | 
|---|
| 54 | HRSRC       hrsrc; | 
|---|
| 55 | BYTE        *p; | 
|---|
| 56 | int         nrofentries,i,slen; | 
|---|
| 57 | struct      _subentry { | 
|---|
| 58 | DWORD   firstentry; | 
|---|
| 59 | DWORD   lastentry; | 
|---|
| 60 | DWORD   offset; | 
|---|
| 61 | } *se; | 
|---|
| 62 | struct      _stringentry { | 
|---|
| 63 | WORD    len; | 
|---|
| 64 | WORD    unknown; | 
|---|
| 65 | CHAR    str[1]; | 
|---|
| 66 | } *stre; | 
|---|
| 67 |  | 
|---|
| 68 | /*FIXME: I am not sure about the '1' ... But I've only seen those entries*/ | 
|---|
| 69 | hrsrc = FindResourceW(instance,(LPWSTR)1,RT_MESSAGELISTW); | 
|---|
| 70 | if (!hrsrc) return 0; | 
|---|
| 71 | hmem = LoadResource(instance, hrsrc); | 
|---|
| 72 | if (!hmem) return 0; | 
|---|
| 73 |  | 
|---|
| 74 | p = (BYTE *)LockResource(hmem); | 
|---|
| 75 | nrofentries = *(DWORD*)p; | 
|---|
| 76 | stre = NULL; | 
|---|
| 77 | se = (struct _subentry*)(p+4); | 
|---|
| 78 | for (i=nrofentries;i--;) { | 
|---|
| 79 | if ((id>=se->firstentry) && (id<=se->lastentry)) { | 
|---|
| 80 | stre = (struct _stringentry*)(p+se->offset); | 
|---|
| 81 | id  -= se->firstentry; | 
|---|
| 82 | break; | 
|---|
| 83 | } | 
|---|
| 84 | se++; | 
|---|
| 85 | } | 
|---|
| 86 | if (!stre) | 
|---|
| 87 | return 0; | 
|---|
| 88 | for (i=id;i--;) { | 
|---|
| 89 | if (!(slen=stre->len)) | 
|---|
| 90 | return 0; | 
|---|
| 91 | stre = (struct _stringentry*)(((char*)stre)+slen); | 
|---|
| 92 | } | 
|---|
| 93 | slen=stre->len; | 
|---|
| 94 |  | 
|---|
| 95 | i = min(buflen - 1, slen); | 
|---|
| 96 | if (buffer == NULL) | 
|---|
| 97 | return slen; /* different to LoadString */ | 
|---|
| 98 | if (i>0) { | 
|---|
| 99 | strncpy(buffer,stre->str,i); | 
|---|
| 100 | buffer[i]=0; | 
|---|
| 101 | } else { | 
|---|
| 102 | if (buflen>1) { | 
|---|
| 103 | buffer[0]=0; | 
|---|
| 104 | return 0; | 
|---|
| 105 | } | 
|---|
| 106 | } | 
|---|
| 107 | return i; | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | /********************************************************************** | 
|---|
| 111 | *      LoadMessage32W  (internal) | 
|---|
| 112 | */ | 
|---|
| 113 | int LoadMessageW(HINSTANCE instance, UINT id, WORD lang, | 
|---|
| 114 | LPWSTR buffer, int buflen ) | 
|---|
| 115 | { | 
|---|
| 116 | INT retval; | 
|---|
| 117 | LPSTR buffer2 = NULL; | 
|---|
| 118 | if (buffer) buffer2 = (char *)HeapAlloc(GetProcessHeap(), 0, buflen ); | 
|---|
| 119 | retval = LoadMessageA(instance,id,lang,buffer2,buflen); | 
|---|
| 120 | if (buffer) | 
|---|
| 121 | { | 
|---|
| 122 | AsciiToUnicode(buffer2, buffer); | 
|---|
| 123 | HeapFree(GetProcessHeap(), 0, buffer2); | 
|---|
| 124 | } | 
|---|
| 125 | return retval; | 
|---|
| 126 | } | 
|---|
| 127 |  | 
|---|
| 128 |  | 
|---|
| 129 | /*********************************************************************** | 
|---|
| 130 | *           FormatMessage32A   (KERNEL32.138) | 
|---|
| 131 | * FIXME: missing wrap,FROM_SYSTEM message-loading, | 
|---|
| 132 | */ | 
|---|
| 133 | DWORD WIN32API FormatMessageA(DWORD   dwFlags, | 
|---|
| 134 | LPCVOID lpSource, | 
|---|
| 135 | DWORD   dwMessageId, | 
|---|
| 136 | DWORD   dwLanguageId, | 
|---|
| 137 | LPSTR   lpBuffer, | 
|---|
| 138 | DWORD   nSize, | 
|---|
| 139 | LPDWORD args /* va_list *args */) | 
|---|
| 140 | { | 
|---|
| 141 | /* This implementation is completely dependant on the format of the va_list on x86 CPUs */ | 
|---|
| 142 | LPSTR target, | 
|---|
| 143 | t; | 
|---|
| 144 | DWORD talloced; | 
|---|
| 145 | LPSTR from, | 
|---|
| 146 | f; | 
|---|
| 147 | DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK; | 
|---|
| 148 | BOOL  eos = FALSE; | 
|---|
| 149 |  | 
|---|
| 150 | dprintf(("KERNEL32: FormatMessageA(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n", | 
|---|
| 151 | dwFlags, | 
|---|
| 152 | lpSource, | 
|---|
| 153 | dwMessageId, | 
|---|
| 154 | dwLanguageId, | 
|---|
| 155 | lpBuffer, | 
|---|
| 156 | nSize, | 
|---|
| 157 | args)); | 
|---|
| 158 |  | 
|---|
| 159 | if (width) | 
|---|
| 160 | dprintf(("KERNEL32: FormatMessageA - line wrapping not supported.\n")); | 
|---|
| 161 |  | 
|---|
| 162 | from = NULL; | 
|---|
| 163 | if (dwFlags & FORMAT_MESSAGE_FROM_STRING) | 
|---|
| 164 | from = HEAP_strdupA( GetProcessHeap(), 0, (LPSTR)lpSource); | 
|---|
| 165 |  | 
|---|
| 166 | if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) | 
|---|
| 167 | { | 
|---|
| 168 | from = (char*)HeapAlloc( GetProcessHeap(),0,200 ); | 
|---|
| 169 | sprintf(from,"Systemmessage, messageid = 0x%08lx\n",dwMessageId); | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) | 
|---|
| 173 | { | 
|---|
| 174 | INT   bufsize; | 
|---|
| 175 |  | 
|---|
| 176 | dwMessageId &= 0xFFFF; | 
|---|
| 177 | bufsize=LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,NULL,100); | 
|---|
| 178 | if (bufsize) | 
|---|
| 179 | { | 
|---|
| 180 | from = (char*)HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); | 
|---|
| 181 | LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,from,bufsize+1); | 
|---|
| 182 | } | 
|---|
| 183 | } | 
|---|
| 184 |  | 
|---|
| 185 | target   = (char*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100); | 
|---|
| 186 | t  = target; | 
|---|
| 187 | talloced= 100; | 
|---|
| 188 |  | 
|---|
| 189 | #define ADD_TO_T(c) \ | 
|---|
| 190 | *t++=c;\ | 
|---|
| 191 | if (t-target == talloced) {\ | 
|---|
| 192 | target   = (char*)HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\ | 
|---|
| 193 | t  = target+talloced;\ | 
|---|
| 194 | talloced*=2;\ | 
|---|
| 195 | } | 
|---|
| 196 |  | 
|---|
| 197 | if (from) | 
|---|
| 198 | { | 
|---|
| 199 | f=from; | 
|---|
| 200 |  | 
|---|
| 201 | while (*f && !eos) | 
|---|
| 202 | { | 
|---|
| 203 | if (*f=='%') | 
|---|
| 204 | { | 
|---|
| 205 | int   insertnr; | 
|---|
| 206 | char  *fmtstr, | 
|---|
| 207 | *sprintfbuf, | 
|---|
| 208 | *x, | 
|---|
| 209 | *lastf; | 
|---|
| 210 | DWORD *argliststart; | 
|---|
| 211 |  | 
|---|
| 212 | fmtstr = NULL; | 
|---|
| 213 | lastf  = f; | 
|---|
| 214 | f++; | 
|---|
| 215 |  | 
|---|
| 216 | if (!*f) | 
|---|
| 217 | { | 
|---|
| 218 | ADD_TO_T('%'); | 
|---|
| 219 | continue; | 
|---|
| 220 | } | 
|---|
| 221 |  | 
|---|
| 222 | switch (*f) | 
|---|
| 223 | { | 
|---|
| 224 | case '1': case '2': case '3': case '4': case '5': | 
|---|
| 225 | case '6': case '7': case '8': case '9': | 
|---|
| 226 | insertnr=*f-'0'; | 
|---|
| 227 | switch (f[1]) | 
|---|
| 228 | { | 
|---|
| 229 | case '0':case '1':case '2':case '3': | 
|---|
| 230 | case '4':case '5':case '6':case '7': | 
|---|
| 231 | case '8':case '9': | 
|---|
| 232 | f++; | 
|---|
| 233 | insertnr=insertnr*10+*f-'0'; | 
|---|
| 234 | f++; | 
|---|
| 235 | break; | 
|---|
| 236 |  | 
|---|
| 237 | default: | 
|---|
| 238 | f++; | 
|---|
| 239 | break; | 
|---|
| 240 | } | 
|---|
| 241 |  | 
|---|
| 242 | if (*f=='!') | 
|---|
| 243 | { | 
|---|
| 244 | f++; | 
|---|
| 245 | if (NULL!=(x=strchr(f,'!'))) | 
|---|
| 246 | { | 
|---|
| 247 | *x='\0'; | 
|---|
| 248 | fmtstr = (char*)HeapAlloc(GetProcessHeap(),0,strlen(f)+2); | 
|---|
| 249 | sprintf(fmtstr,"%%%s",f); | 
|---|
| 250 | f=x+1; | 
|---|
| 251 | } | 
|---|
| 252 | else | 
|---|
| 253 | { | 
|---|
| 254 | fmtstr = (char*)HeapAlloc(GetProcessHeap(),0,strlen(f)); | 
|---|
| 255 | sprintf(fmtstr,"%%%s",f); | 
|---|
| 256 | f+=strlen(f); /*at \0*/ | 
|---|
| 257 | } | 
|---|
| 258 | } | 
|---|
| 259 | else | 
|---|
| 260 | if(!args) | 
|---|
| 261 | break; | 
|---|
| 262 | else | 
|---|
| 263 | fmtstr=HEAP_strdupA(GetProcessHeap(),0,"%s"); | 
|---|
| 264 |  | 
|---|
| 265 | if (args) | 
|---|
| 266 | { | 
|---|
| 267 | if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) | 
|---|
| 268 | argliststart=args+insertnr-1; | 
|---|
| 269 | else | 
|---|
| 270 | argliststart=(*(DWORD**)args)+insertnr-1; | 
|---|
| 271 |  | 
|---|
| 272 | if (fmtstr[strlen(fmtstr)-1]=='s' && argliststart[0]) | 
|---|
| 273 | sprintfbuf = (char*)HeapAlloc(GetProcessHeap(),0,strlen((LPSTR)argliststart[0])+1); | 
|---|
| 274 | else | 
|---|
| 275 | sprintfbuf = (char*)HeapAlloc(GetProcessHeap(),0,100); | 
|---|
| 276 |  | 
|---|
| 277 | /* CMF - This makes a BIG assumption about va_list */ | 
|---|
| 278 | if (LoadwvsprintfA()) wvsprintfAProc(sprintfbuf,fmtstr,(va_list)argliststart); | 
|---|
| 279 | x=sprintfbuf; | 
|---|
| 280 | while (*x) | 
|---|
| 281 | { | 
|---|
| 282 | ADD_TO_T(*x++); | 
|---|
| 283 | } | 
|---|
| 284 |  | 
|---|
| 285 | HeapFree(GetProcessHeap(),0,sprintfbuf); | 
|---|
| 286 | } | 
|---|
| 287 | else | 
|---|
| 288 | { | 
|---|
| 289 | /* NULL args - copy formatstr | 
|---|
| 290 | * (probably wrong) | 
|---|
| 291 | */ | 
|---|
| 292 | while ((lastf<f)&&(*lastf)) | 
|---|
| 293 | { | 
|---|
| 294 | ADD_TO_T(*lastf++); | 
|---|
| 295 | } | 
|---|
| 296 | } | 
|---|
| 297 |  | 
|---|
| 298 | HeapFree(GetProcessHeap(),0,fmtstr); | 
|---|
| 299 | break; | 
|---|
| 300 |  | 
|---|
| 301 | case 'n': | 
|---|
| 302 | ADD_TO_T('\r'); | 
|---|
| 303 | ADD_TO_T('\n'); | 
|---|
| 304 | f++; | 
|---|
| 305 | break; | 
|---|
| 306 |  | 
|---|
| 307 | case '0': | 
|---|
| 308 | eos = TRUE; | 
|---|
| 309 | f++; | 
|---|
| 310 | break; | 
|---|
| 311 |  | 
|---|
| 312 | default:ADD_TO_T(*f++) | 
|---|
| 313 | break; | 
|---|
| 314 | } | 
|---|
| 315 | } else | 
|---|
| 316 | { /* '\n' or '\r' gets mapped to "\r\n" */ | 
|---|
| 317 | if(*f == '\n' || *f == '\r') | 
|---|
| 318 | { | 
|---|
| 319 | ADD_TO_T('\r'); | 
|---|
| 320 | ADD_TO_T('\n'); | 
|---|
| 321 | if(*f++ == '\r' && *f == '\n') | 
|---|
| 322 | f++; | 
|---|
| 323 | } else | 
|---|
| 324 | { | 
|---|
| 325 | ADD_TO_T(*f++); | 
|---|
| 326 | } | 
|---|
| 327 | } | 
|---|
| 328 | } | 
|---|
| 329 | *t='\0'; | 
|---|
| 330 | } | 
|---|
| 331 |  | 
|---|
| 332 | talloced = strlen(target)+1; | 
|---|
| 333 | if (nSize && talloced<nSize) | 
|---|
| 334 | { | 
|---|
| 335 | target = (char*)HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize); | 
|---|
| 336 | } | 
|---|
| 337 |  | 
|---|
| 338 | //TRACE("-- %s\n",debugstr_a(target)); | 
|---|
| 339 |  | 
|---|
| 340 | if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) | 
|---|
| 341 | { | 
|---|
| 342 | /* nSize is the MINIMUM size */ | 
|---|
| 343 | *((LPVOID*)lpBuffer) = (LPVOID)LocalAlloc(GMEM_ZEROINIT,talloced); | 
|---|
| 344 | memcpy(*(LPSTR*)lpBuffer,target,talloced); | 
|---|
| 345 | } | 
|---|
| 346 | else | 
|---|
| 347 | strncpy(lpBuffer,target,nSize); | 
|---|
| 348 |  | 
|---|
| 349 | HeapFree(GetProcessHeap(),0,target); | 
|---|
| 350 | if (from) | 
|---|
| 351 | HeapFree(GetProcessHeap(),0,from); | 
|---|
| 352 |  | 
|---|
| 353 | return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ? | 
|---|
| 354 | strlen(*(LPSTR*)lpBuffer): | 
|---|
| 355 | strlen(lpBuffer); | 
|---|
| 356 | } | 
|---|
| 357 | #undef ADD_TO_T | 
|---|
| 358 |  | 
|---|
| 359 |  | 
|---|
| 360 | /*********************************************************************** | 
|---|
| 361 | *           FormatMessage32W   (KERNEL32.138) | 
|---|
| 362 | */ | 
|---|
| 363 | DWORD WINAPI FormatMessageW(DWORD   dwFlags, | 
|---|
| 364 | LPCVOID lpSource, | 
|---|
| 365 | DWORD   dwMessageId, | 
|---|
| 366 | DWORD   dwLanguageId, | 
|---|
| 367 | LPWSTR  lpBuffer, | 
|---|
| 368 | DWORD   nSize, | 
|---|
| 369 | LPDWORD args /* va_list *args */ ) | 
|---|
| 370 | { | 
|---|
| 371 | /* This implementation is completely dependant on the format of the va_list on x86 CPUs */ | 
|---|
| 372 | LPSTR target,t; | 
|---|
| 373 | DWORD talloced; | 
|---|
| 374 | LPSTR from,f; | 
|---|
| 375 | DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK; | 
|---|
| 376 | BOOL  eos = FALSE; | 
|---|
| 377 |  | 
|---|
| 378 | dprintf(("KERNEL32: FormatMessageW(%08xh,%08xh,%08xh,%08xh,%08xh,%08xh,%08xh)\n", | 
|---|
| 379 | dwFlags, | 
|---|
| 380 | lpSource, | 
|---|
| 381 | dwMessageId, | 
|---|
| 382 | dwLanguageId, | 
|---|
| 383 | lpBuffer, | 
|---|
| 384 | nSize, | 
|---|
| 385 | args)); | 
|---|
| 386 |  | 
|---|
| 387 | if (width) | 
|---|
| 388 | dprintf(("KERNEL32: FormatMessageW - line wrapping not supported.\n")); | 
|---|
| 389 |  | 
|---|
| 390 | from = NULL; | 
|---|
| 391 | if (dwFlags & FORMAT_MESSAGE_FROM_STRING) | 
|---|
| 392 | from = HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)lpSource); | 
|---|
| 393 |  | 
|---|
| 394 | if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) | 
|---|
| 395 | { | 
|---|
| 396 | /* gather information from system message tables ... */ | 
|---|
| 397 | from = (char*)HeapAlloc( GetProcessHeap(),0,200 ); | 
|---|
| 398 | sprintf(from,"Systemmessage, messageid = 0x%08lx\n",dwMessageId); | 
|---|
| 399 | } | 
|---|
| 400 |  | 
|---|
| 401 | if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) | 
|---|
| 402 | { | 
|---|
| 403 | INT   bufsize; | 
|---|
| 404 |  | 
|---|
| 405 | dwMessageId &= 0xFFFF; | 
|---|
| 406 | bufsize=LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,NULL,100); | 
|---|
| 407 | if (bufsize) | 
|---|
| 408 | { | 
|---|
| 409 | from = (char*)HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); | 
|---|
| 410 | LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,from,bufsize+1); | 
|---|
| 411 | } | 
|---|
| 412 | } | 
|---|
| 413 |  | 
|---|
| 414 | target   = (char*)HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100 ); | 
|---|
| 415 | t  = target; | 
|---|
| 416 | talloced= 100; | 
|---|
| 417 |  | 
|---|
| 418 | #define ADD_TO_T(c) \ | 
|---|
| 419 | *t++=c;\ | 
|---|
| 420 | if (t-target == talloced) {\ | 
|---|
| 421 | target   = (char*)HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\ | 
|---|
| 422 | t  = target+talloced;\ | 
|---|
| 423 | talloced*=2;\ | 
|---|
| 424 | } | 
|---|
| 425 |  | 
|---|
| 426 | if (from) { | 
|---|
| 427 | f=from; | 
|---|
| 428 | while (*f && !eos) { | 
|---|
| 429 | if (*f=='%') { | 
|---|
| 430 | int   insertnr; | 
|---|
| 431 | char  *fmtstr,*sprintfbuf,*x; | 
|---|
| 432 | DWORD *argliststart; | 
|---|
| 433 |  | 
|---|
| 434 | fmtstr = NULL; | 
|---|
| 435 | f++; | 
|---|
| 436 | if (!*f) { | 
|---|
| 437 | ADD_TO_T('%'); | 
|---|
| 438 | continue; | 
|---|
| 439 | } | 
|---|
| 440 | switch (*f) { | 
|---|
| 441 | case '1':case '2':case '3':case '4':case '5': | 
|---|
| 442 | case '6':case '7':case '8':case '9': | 
|---|
| 443 | insertnr=*f-'0'; | 
|---|
| 444 | switch (f[1]) { | 
|---|
| 445 | case '0':case '1':case '2':case '3': | 
|---|
| 446 | case '4':case '5':case '6':case '7': | 
|---|
| 447 | case '8':case '9': | 
|---|
| 448 | f++; | 
|---|
| 449 | insertnr=insertnr*10+*f-'0'; | 
|---|
| 450 | f++; | 
|---|
| 451 | break; | 
|---|
| 452 | default: | 
|---|
| 453 | f++; | 
|---|
| 454 | break; | 
|---|
| 455 | } | 
|---|
| 456 | if (*f=='!') { | 
|---|
| 457 | f++; | 
|---|
| 458 | if (NULL!=(x=strchr(f,'!'))) | 
|---|
| 459 | { | 
|---|
| 460 | *x='\0'; | 
|---|
| 461 | fmtstr=(char*)HeapAlloc( GetProcessHeap(), 0, strlen(f)+2); | 
|---|
| 462 | sprintf(fmtstr,"%%%s",f); | 
|---|
| 463 | f=x+1; | 
|---|
| 464 | } else { | 
|---|
| 465 | fmtstr=(char*)HeapAlloc(GetProcessHeap(),0,strlen(f)); | 
|---|
| 466 | sprintf(fmtstr,"%%%s",f); | 
|---|
| 467 | f+=strlen(f); /*at \0*/ | 
|---|
| 468 | } | 
|---|
| 469 | } else | 
|---|
| 470 | if(!args) | 
|---|
| 471 | break; | 
|---|
| 472 | else | 
|---|
| 473 | fmtstr=HEAP_strdupA( GetProcessHeap(),0,"%s"); | 
|---|
| 474 | if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY) | 
|---|
| 475 | argliststart=args+insertnr-1; | 
|---|
| 476 | else | 
|---|
| 477 | argliststart=(*(DWORD**)args)+insertnr-1; | 
|---|
| 478 |  | 
|---|
| 479 | if (fmtstr[strlen(fmtstr)-1]=='s' && argliststart[0]) { | 
|---|
| 480 | DWORD                  xarr[3]; | 
|---|
| 481 |  | 
|---|
| 482 | xarr[0]=(DWORD)HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)(*(argliststart+0))); | 
|---|
| 483 | /* possible invalid pointers */ | 
|---|
| 484 | xarr[1]=*(argliststart+1); | 
|---|
| 485 | xarr[2]=*(argliststart+2); | 
|---|
| 486 | sprintfbuf=(char*)HeapAlloc(GetProcessHeap(),0,lstrlenW((LPWSTR)argliststart[0])*2+1); | 
|---|
| 487 |  | 
|---|
| 488 | /* CMF - This makes a BIG assumption about va_list */ | 
|---|
| 489 | vsprintf(sprintfbuf, fmtstr, (va_list) xarr); | 
|---|
| 490 | } else { | 
|---|
| 491 | sprintfbuf=(char*)HeapAlloc(GetProcessHeap(),0,100); | 
|---|
| 492 |  | 
|---|
| 493 | /* CMF - This makes a BIG assumption about va_list */ | 
|---|
| 494 | if (LoadwvsprintfA()) wvsprintfAProc(sprintfbuf,fmtstr,(va_list)argliststart); | 
|---|
| 495 | } | 
|---|
| 496 | x=sprintfbuf; | 
|---|
| 497 | while (*x) { | 
|---|
| 498 | ADD_TO_T(*x++); | 
|---|
| 499 | } | 
|---|
| 500 | HeapFree(GetProcessHeap(),0,sprintfbuf); | 
|---|
| 501 | HeapFree(GetProcessHeap(),0,fmtstr); | 
|---|
| 502 | break; | 
|---|
| 503 | case 'n': | 
|---|
| 504 | ADD_TO_T('\r'); | 
|---|
| 505 | ADD_TO_T('\n'); | 
|---|
| 506 | f++; | 
|---|
| 507 | break; | 
|---|
| 508 | case '0': | 
|---|
| 509 | eos = TRUE; | 
|---|
| 510 | f++; | 
|---|
| 511 | break; | 
|---|
| 512 | default:ADD_TO_T(*f++) | 
|---|
| 513 | break; | 
|---|
| 514 |  | 
|---|
| 515 | } | 
|---|
| 516 | } else | 
|---|
| 517 | { /* '\n' or '\r' gets mapped to "\r\n" */ | 
|---|
| 518 | if(*f == '\n' || *f == '\r') | 
|---|
| 519 | { | 
|---|
| 520 | ADD_TO_T('\r'); | 
|---|
| 521 | ADD_TO_T('\n'); | 
|---|
| 522 | if(*f++ == '\r' && *f == '\n') | 
|---|
| 523 | f++; | 
|---|
| 524 | } else | 
|---|
| 525 | { | 
|---|
| 526 | ADD_TO_T(*f++); | 
|---|
| 527 | } | 
|---|
| 528 | } | 
|---|
| 529 | } | 
|---|
| 530 | *t='\0'; | 
|---|
| 531 | } | 
|---|
| 532 | talloced = strlen(target)+1; | 
|---|
| 533 | if (nSize && talloced<nSize) | 
|---|
| 534 | target = (char*)HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,nSize); | 
|---|
| 535 | if (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) { | 
|---|
| 536 | /* nSize is the MINIMUM size */ | 
|---|
| 537 | *((LPVOID*)lpBuffer) = (LPVOID)LocalAlloc(GMEM_ZEROINIT,talloced*2+2); | 
|---|
| 538 | lstrcpynAtoW(*(LPWSTR*)lpBuffer,target,talloced); | 
|---|
| 539 | } else | 
|---|
| 540 | lstrcpynAtoW(lpBuffer,target,nSize); | 
|---|
| 541 | HeapFree(GetProcessHeap(),0,target); | 
|---|
| 542 | if (from) HeapFree(GetProcessHeap(),0,from); | 
|---|
| 543 | return (dwFlags & FORMAT_MESSAGE_ALLOCATE_BUFFER) ? | 
|---|
| 544 | lstrlenW(*(LPWSTR*)lpBuffer): | 
|---|
| 545 | lstrlenW(lpBuffer); | 
|---|
| 546 | } | 
|---|
| 547 | #undef ADD_TO_T | 
|---|
| 548 |  | 
|---|
| 549 |  | 
|---|