From 103f3b05487b0c99d30729502fe1b217d0096316 Mon Sep 17 00:00:00 2001 From: Huw D M Davies Date: Sun, 19 Sep 1999 12:13:46 +0000 Subject: [PATCH] Fix FormatMessage16 at least enough to get win95 16bit printdlg working. --- misc/lstr.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 159 insertions(+), 1 deletion(-) diff --git a/misc/lstr.c b/misc/lstr.c index 7fb9f56e188..8df86fb3b70 100644 --- a/misc/lstr.c +++ b/misc/lstr.c @@ -496,8 +496,166 @@ DWORD WINAPI FormatMessage16( WORD nSize, LPDWORD args /* va_list *args */ ) { - return FormatMessageA(dwFlags, lpSource, (DWORD)dwMessageId, (DWORD)dwLanguageId, lpBuffer, (DWORD)nSize, args); +#ifdef __i386__ +/* This implementation is completely dependant on the format of the va_list on x86 CPUs */ + LPSTR target,t; + DWORD talloced; + LPSTR from,f; + DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK; + DWORD nolinefeed = 0; + + TRACE("(0x%lx,%p,%d,0x%x,%p,%d,%p)\n", + dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args); + if (width) + FIXME("line wrapping not supported.\n"); + from = NULL; + if (dwFlags & FORMAT_MESSAGE_FROM_STRING) + from = HEAP_strdupA( GetProcessHeap(), 0, (LPSTR)lpSource); + if (dwFlags & FORMAT_MESSAGE_FROM_SYSTEM) { + from = HeapAlloc( GetProcessHeap(),0,200 ); + sprintf(from,"Systemmessage, messageid = 0x%08x\n",dwMessageId); + } + if (dwFlags & FORMAT_MESSAGE_FROM_HMODULE) { + INT bufsize; + + dwMessageId &= 0xFFFF; + bufsize=LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,NULL,100); + if (bufsize) { + from = HeapAlloc( GetProcessHeap(), 0, bufsize + 1 ); + LoadMessageA((HMODULE)lpSource,dwMessageId,dwLanguageId,from,bufsize+1); + } + } + target = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, 100); + t = target; + talloced= 100; + +#define ADD_TO_T(c) \ + *t++=c;\ + if (t-target == talloced) {\ + target = (char*)HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2);\ + t = target+talloced;\ + talloced*=2;\ + } + + if (from) { + f=from; + while (*f && !nolinefeed) { + if (*f=='%') { + int insertnr; + char *fmtstr,*sprintfbuf,*x,*lastf; + DWORD *argliststart; + + fmtstr = NULL; + lastf = f; + f++; + if (!*f) { + ADD_TO_T('%'); + continue; + } + switch (*f) { + case '1':case '2':case '3':case '4':case '5': + case '6':case '7':case '8':case '9': + insertnr=*f-'0'; + switch (f[1]) { + case '0':case '1':case '2':case '3': + case '4':case '5':case '6':case '7': + case '8':case '9': + f++; + insertnr=insertnr*10+*f-'0'; + f++; + break; + default: + f++; + break; + } + if (*f=='!') { + f++; + if (NULL!=(x=strchr(f,'!'))) { + *x='\0'; + fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)+2); + sprintf(fmtstr,"%%%s",f); + f=x+1; + } else { + fmtstr=HeapAlloc(GetProcessHeap(),0,strlen(f)); + sprintf(fmtstr,"%%%s",f); + f+=strlen(f); /*at \0*/ + } + } else + if(!args) + break; + else + fmtstr=HEAP_strdupA(GetProcessHeap(),0,"%s"); + if (args) { + argliststart=args+insertnr-1; + if (fmtstr[strlen(fmtstr)-1]=='s') + sprintfbuf=HeapAlloc(GetProcessHeap(),0, + strlen(PTR_SEG_TO_LIN(argliststart[0]))+1); + else + sprintfbuf=HeapAlloc(GetProcessHeap(),0,100); + + /* CMF - This makes a BIG assumption about va_list */ + wvsprintf16(sprintfbuf, fmtstr, (va_list) argliststart); + x=sprintfbuf; + while (*x) { + ADD_TO_T(*x++); + } + HeapFree(GetProcessHeap(),0,sprintfbuf); + } else { + /* NULL args - copy formatstr + * (probably wrong) + */ + while ((lastf