FormatMessage patch
Duane Clark
dclark at akamail.com
Sun May 6 19:20:42 CDT 2001
Howdy,
This patch adds a test of the flag FORMAT_MESSAGE_IGNORE_INSERTS to the
routines FormatMessageA and FormatMessageW, and when the flag is high,
simply copies the string from "from" to "target". It appears to me from
the behavior of the routines without this patch, that they would behave
incorrectly if the flag were low. This patch does not address that
possible problem.
Changelog:
Add tests for the flag FORMAT_MESSAGE_IGNORE_INSERTS, and act
accordingly.
-------------- next part --------------
Index: dlls/kernel/format_msg.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/format_msg.c,v
retrieving revision 1.14
diff -u -r1.14 format_msg.c
--- dlls/kernel/format_msg.c 2001/01/25 22:22:21 1.14
+++ dlls/kernel/format_msg.c 2001/05/06 23:59:15
@@ -210,116 +210,123 @@
if (from) {
f=from;
- while (*f && !eos) {
- if (*f=='%') {
- int insertnr;
- char *fmtstr,*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':
+ if (dwFlags & FORMAT_MESSAGE_IGNORE_INSERTS) {
+ while (*f && !eos)
+ ADD_TO_T(*f++);
+ }
+ else {
+ while (*f && !eos) {
+ if (*f=='%') {
+ int insertnr;
+ char *fmtstr,*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)+2);
+ sprintf(fmtstr,"%%%s",f);
+ f+=strlen(f); /*at \0*/
+ }
+ } else {
+ if(!args)
+ break;
+ else
+ fmtstr=HEAP_strdupA(GetProcessHeap(),0,"%s");
+ }
+ if (args) {
+ int sz;
+ LPSTR b;
+
+ if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY)
+ argliststart=args+insertnr-1;
+ else
+ argliststart=(*(DWORD**)args)+insertnr-1;
+
+ /* FIXME: precision and width components are not handled correctly */
+ if (strcmp(fmtstr, "%ls") == 0) {
+ sz = WideCharToMultiByte( CP_ACP, 0, *(WCHAR**)argliststart, -1, NULL, 0, NULL, NULL);
+ b = HeapAlloc(GetProcessHeap(), 0, sz);
+ WideCharToMultiByte( CP_ACP, 0, *(WCHAR**)argliststart, -1, b, sz, NULL, NULL);
+ } else {
+ b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
+ /* CMF - This makes a BIG assumption about va_list */
+ TRACE("A BIG assumption\n");
+ while (vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) {
+ b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz += 100);
+ }
+ }
+ for (x=b; *x; x++) ADD_TO_T(*x);
+
+ HeapFree(GetProcessHeap(),0,b);
+ } else {
+ /* NULL args - copy formatstr
+ * (probably wrong)
+ */
+ while ((lastf<f)&&(*lastf)) {
+ ADD_TO_T(*lastf++);
+ }
+ }
+ HeapFree(GetProcessHeap(),0,fmtstr);
+ break;
+ case 'n':
+ ADD_TO_T('\r');
+ ADD_TO_T('\n');
f++;
- insertnr=insertnr*10+*f-'0';
+ break;
+ case '0':
+ eos = TRUE;
f++;
break;
default:
- f++;
+ ADD_TO_T(*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)+2);
- sprintf(fmtstr,"%%%s",f);
- f+=strlen(f); /*at \0*/
- }
- } else
- if(!args)
- break;
- else
- fmtstr=HEAP_strdupA(GetProcessHeap(),0,"%s");
- if (args) {
- int sz;
- LPSTR b;
-
- if (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY)
- argliststart=args+insertnr-1;
- else
- argliststart=(*(DWORD**)args)+insertnr-1;
-
- /* FIXME: precision and width components are not handled correctly */
- if (strcmp(fmtstr, "%ls") == 0) {
- sz = WideCharToMultiByte( CP_ACP, 0, *(WCHAR**)argliststart, -1, NULL, 0, NULL, NULL);
- b = HeapAlloc(GetProcessHeap(), 0, sz);
- WideCharToMultiByte( CP_ACP, 0, *(WCHAR**)argliststart, -1, b, sz, NULL, NULL);
- } else {
- b = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sz = 100);
- /* CMF - This makes a BIG assumption about va_list */
- while (vsnprintf(b, sz, fmtstr, (va_list) argliststart) < 0) {
- b = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, b, sz += 100);
- }
- }
- for (x=b; *x; x++) ADD_TO_T(*x);
-
- HeapFree(GetProcessHeap(),0,b);
+ } else {
+ ch = *f;
+ f++;
+ if (ch == '\r') {
+ if (*f == '\n')
+ f++;
+ ADD_TO_T(' ');
} else {
- /* NULL args - copy formatstr
- * (probably wrong)
- */
- while ((lastf<f)&&(*lastf)) {
- ADD_TO_T(*lastf++);
+ if (ch == '\n')
+ {
+ ADD_TO_T('\r');
+ ADD_TO_T('\n');
}
+ else
+ ADD_TO_T(ch);
}
- HeapFree(GetProcessHeap(),0,fmtstr);
- break;
- case 'n':
- ADD_TO_T('\r');
- ADD_TO_T('\n');
- f++;
- break;
- case '0':
- eos = TRUE;
- f++;
- break;
- default:
- ADD_TO_T(*f++);
- break;
}
- } else {
- ch = *f;
- f++;
- if (ch == '\r')
- {
- if (*f == '\n')
- f++;
- ADD_TO_T(' ');
- }
- else
- if (ch == '\n')
- {
- ADD_TO_T('\r');
- ADD_TO_T('\n');
- }
- else
- ADD_TO_T(ch);
}
}
*t='\0';
@@ -428,111 +435,117 @@
if (from) {
f=from;
- while (*f && !eos) {
- if (*f=='%') {
- int insertnr;
- char *fmtstr,*sprintfbuf,*x;
- DWORD *argliststart;
-
- fmtstr = NULL;
- 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':
+ if (dwFlags & FORMAT_MESSAGE_IGNORE_INSERTS) {
+ while (*f && !eos)
+ ADD_TO_T(*f++);
+ }
+ else {
+ while (*f && !eos) {
+ if (*f=='%') {
+ int insertnr;
+ char *fmtstr,*sprintfbuf,*x;
+ DWORD *argliststart;
+
+ fmtstr = NULL;
+ 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 (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY)
+ argliststart=args+insertnr-1;
+ else
+ argliststart=(*(DWORD**)args)+insertnr-1;
+
+ if (fmtstr[strlen(fmtstr)-1]=='s' && argliststart[0]) {
+ DWORD xarr[3];
+
+ xarr[0]=(DWORD)HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)(*(argliststart+0)));
+ /* possible invalid pointers */
+ xarr[1]=*(argliststart+1);
+ xarr[2]=*(argliststart+2);
+ sprintfbuf=HeapAlloc(GetProcessHeap(),0,strlenW((LPWSTR)argliststart[0])*2+1);
+
+ /* CMF - This makes a BIG assumption about va_list */
+ vsprintf(sprintfbuf, fmtstr, (va_list) xarr);
+ } else {
+ sprintfbuf=HeapAlloc(GetProcessHeap(),0,100);
+
+ /* CMF - This makes a BIG assumption about va_list */
+ vsprintf(sprintfbuf, fmtstr, (va_list) argliststart);
+ }
+ x=sprintfbuf;
+ while (*x) {
+ ADD_TO_T(*x++);
+ }
+ HeapFree(GetProcessHeap(),0,sprintfbuf);
+ HeapFree(GetProcessHeap(),0,fmtstr);
+ break;
+ case 'n':
+ ADD_TO_T('\r');
+ ADD_TO_T('\n');
f++;
- insertnr=insertnr*10+*f-'0';
+ break;
+ case '0':
+ eos = TRUE;
f++;
break;
default:
- f++;
+ ADD_TO_T(*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 (dwFlags & FORMAT_MESSAGE_ARGUMENT_ARRAY)
- argliststart=args+insertnr-1;
- else
- argliststart=(*(DWORD**)args)+insertnr-1;
-
- if (fmtstr[strlen(fmtstr)-1]=='s' && argliststart[0]) {
- DWORD xarr[3];
-
- xarr[0]=(DWORD)HEAP_strdupWtoA(GetProcessHeap(),0,(LPWSTR)(*(argliststart+0)));
- /* possible invalid pointers */
- xarr[1]=*(argliststart+1);
- xarr[2]=*(argliststart+2);
- sprintfbuf=HeapAlloc(GetProcessHeap(),0,strlenW((LPWSTR)argliststart[0])*2+1);
-
- /* CMF - This makes a BIG assumption about va_list */
- vsprintf(sprintfbuf, fmtstr, (va_list) xarr);
- } else {
- sprintfbuf=HeapAlloc(GetProcessHeap(),0,100);
-
- /* CMF - This makes a BIG assumption about va_list */
- vsprintf(sprintfbuf, fmtstr, (va_list) argliststart);
- }
- x=sprintfbuf;
- while (*x) {
- ADD_TO_T(*x++);
- }
- HeapFree(GetProcessHeap(),0,sprintfbuf);
- HeapFree(GetProcessHeap(),0,fmtstr);
- break;
- case 'n':
- ADD_TO_T('\r');
- ADD_TO_T('\n');
- f++;
- break;
- case '0':
- eos = TRUE;
+ } else {
+ ch = *f;
f++;
- break;
- default:
- ADD_TO_T(*f++);
- break;
+ if (ch == '\r') {
+ if (*f == '\n')
+ f++;
+ ADD_TO_T(' ');
+ } else {
+ if (ch == '\n')
+ {
+ ADD_TO_T('\r');
+ ADD_TO_T('\n');
+ }
+ else
+ ADD_TO_T(ch);
+ }
}
- } else {
- ch = *f;
- f++;
- if (ch == '\r')
- {
- if (*f == '\n')
- f++;
- ADD_TO_T(' ');
- }
- else
- if (ch == '\n')
- {
- ADD_TO_T('\r');
- ADD_TO_T('\n');
- }
- else
- ADD_TO_T(ch);
}
}
*t='\0';
More information about the wine-patches
mailing list