From 71c0b94db212df7f0fece9b79a5315fc47f2d2de Mon Sep 17 00:00:00 2001 From: Huw D M Davies Date: Sun, 31 Oct 1999 01:54:17 +0000 Subject: [PATCH] Better handling of newlines in FormatMessage*. --- misc/lstr.c | 97 +++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 48 deletions(-) diff --git a/misc/lstr.c b/misc/lstr.c index 10e8bc8eec4..4f374c2aac2 100644 --- a/misc/lstr.c +++ b/misc/lstr.c @@ -502,8 +502,8 @@ DWORD WINAPI FormatMessage16( DWORD talloced; LPSTR from,f; DWORD width = dwFlags & FORMAT_MESSAGE_MAX_WIDTH_MASK; - DWORD nolinefeed = 0; - LPSTR allocstring; + BOOL eos = FALSE; + LPSTR allocstring = NULL; TRACE("(0x%lx,%lx,%d,0x%x,%p,%d,%p)\n", dwFlags,lpSource,dwMessageId,dwLanguageId,lpBuffer,nSize,args); @@ -541,7 +541,7 @@ DWORD WINAPI FormatMessage16( if (from) { f=from; - while (*f && !nolinefeed) { + while (*f && !eos) { if (*f=='%') { int insertnr; char *fmtstr,*sprintfbuf,*x,*lastf; @@ -612,31 +612,28 @@ DWORD WINAPI FormatMessage16( } HeapFree(GetProcessHeap(),0,fmtstr); break; - case 'n': - /* FIXME: perhaps add \r too? */ - ADD_TO_T('\n'); - f++; - break; - case '0': - nolinefeed=1; + case '0': /* Just stop processing format string */ + eos = TRUE; f++; break; + case 'n': /* 16 bit version just outputs 'n' */ default: ADD_TO_T(*f++); break; - } - } else { - ADD_TO_T(*f++); + } else { /* '\n' or '\r' gets mapped to "\r\n" */ + if(*f == '\n' || *f == '\r') { + ADD_TO_T('\r'); + ADD_TO_T('\n'); + if(*f++ == '\r' && *f == '\n') + f++; + } else { + ADD_TO_T(*f++); + } } } *t='\0'; } - if (!nolinefeed) { - /* add linefeed */ - if(t==target || t[-1]!='\n') - ADD_TO_T('\n'); /* FIXME: perhaps add \r too? */ - } talloced = strlen(target)+1; if (nSize && talloced