Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
bca6e18d
Commit
bca6e18d
authored
Sep 19, 2012
by
Francois Gouget
Committed by
Alexandre Julliard
Sep 19, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kernel32: Replace the format_message() helper macro with a static function.
parent
a273cac7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
34 deletions
+39
-34
format_msg.c
dlls/kernel32/format_msg.c
+39
-34
No files found.
dlls/kernel32/format_msg.c
View file @
bca6e18d
...
...
@@ -261,30 +261,36 @@ static LPCWSTR format_insert( BOOL unicode_caller, int insert, LPCWSTR format,
return
format
;
}
struct
_format_message_data
{
LPWSTR
formatted
;
DWORD
size
;
LPWSTR
t
;
};
static
void
format_add_char
(
struct
_format_message_data
*
fmd
,
WCHAR
c
)
{
*
fmd
->
t
++
=
c
;
if
((
DWORD
)(
fmd
->
t
-
fmd
->
formatted
)
==
fmd
->
size
)
{
fmd
->
formatted
=
HeapReAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
fmd
->
formatted
,
(
fmd
->
size
*
2
)
*
sizeof
(
WCHAR
));
fmd
->
t
=
fmd
->
formatted
+
fmd
->
size
;
fmd
->
size
*=
2
;
}
}
/**********************************************************************
* format_message (internal)
*/
static
LPWSTR
format_message
(
BOOL
unicode_caller
,
DWORD
dwFlags
,
LPCWSTR
fmtstr
,
struct
format_args
*
format_args
)
{
LPWSTR
target
,
t
;
DWORD
talloced
;
struct
_format_message_data
fmd
;
LPCWSTR
f
;
DWORD
width
=
dwFlags
&
FORMAT_MESSAGE_MAX_WIDTH_MASK
;
BOOL
eos
=
FALSE
;
WCHAR
ch
;
target
=
t
=
HeapAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
100
*
sizeof
(
WCHAR
)
);
talloced
=
100
;
#define ADD_TO_T(c) do {\
*t++=c;\
if ((DWORD)(t-target) == talloced) {\
target = HeapReAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,target,talloced*2*sizeof(WCHAR));\
t = target+talloced;\
talloced*=2;\
} \
} while (0)
fmd
.
size
=
100
;
fmd
.
formatted
=
fmd
.
t
=
HeapAlloc
(
GetProcessHeap
(),
HEAP_ZERO_MEMORY
,
fmd
.
size
*
sizeof
(
WCHAR
)
);
f
=
fmtstr
;
while
(
*
f
&&
!
eos
)
{
...
...
@@ -302,7 +308,7 @@ static LPWSTR format_message( BOOL unicode_caller, DWORD dwFlags, LPCWSTR fmtstr
(
!
(
dwFlags
&
FORMAT_MESSAGE_ARGUMENT_ARRAY
)
&&
!
format_args
->
list
))
{
SetLastError
(
ERROR_INVALID_PARAMETER
);
HeapFree
(
GetProcessHeap
(),
0
,
target
);
HeapFree
(
GetProcessHeap
(),
0
,
fmd
.
formatted
);
return
NULL
;
}
insertnr
=
*
f
-
'0'
;
...
...
@@ -319,20 +325,20 @@ static LPWSTR format_message( BOOL unicode_caller, DWORD dwFlags, LPCWSTR fmtstr
break
;
}
f
=
format_insert
(
unicode_caller
,
insertnr
,
f
,
dwFlags
,
format_args
,
&
str
);
for
(
x
=
str
;
*
x
;
x
++
)
ADD_TO_T
(
*
x
);
for
(
x
=
str
;
*
x
;
x
++
)
format_add_char
(
&
fmd
,
*
x
);
HeapFree
(
GetProcessHeap
(),
0
,
str
);
break
;
case
'n'
:
ADD_TO_T
(
'\r'
);
ADD_TO_T
(
'\n'
);
format_add_char
(
&
fmd
,
'\r'
);
format_add_char
(
&
fmd
,
'\n'
);
f
++
;
break
;
case
'r'
:
ADD_TO_T
(
'\r'
);
format_add_char
(
&
fmd
,
'\r'
);
f
++
;
break
;
case
't'
:
ADD_TO_T
(
'\t'
);
format_add_char
(
&
fmd
,
'\t'
);
f
++
;
break
;
case
'0'
:
...
...
@@ -341,49 +347,48 @@ static LPWSTR format_message( BOOL unicode_caller, DWORD dwFlags, LPCWSTR fmtstr
break
;
case
'\0'
:
SetLastError
(
ERROR_INVALID_PARAMETER
);
HeapFree
(
GetProcessHeap
(),
0
,
target
);
HeapFree
(
GetProcessHeap
(),
0
,
fmd
.
formatted
);
return
NULL
;
ignore_inserts:
default:
if
(
dwFlags
&
FORMAT_MESSAGE_IGNORE_INSERTS
)
ADD_TO_T
(
'%'
);
ADD_TO_T
(
*
f
++
);
format_add_char
(
&
fmd
,
'%'
);
format_add_char
(
&
fmd
,
*
f
++
);
break
;
}
}
else
{
ch
=
*
f
;
WCHAR
ch
=
*
f
;
f
++
;
if
(
ch
==
'\r'
)
{
if
(
*
f
==
'\n'
)
f
++
;
if
(
width
)
ADD_TO_T
(
' '
);
format_add_char
(
&
fmd
,
' '
);
else
{
ADD_TO_T
(
'\r'
);
ADD_TO_T
(
'\n'
);
format_add_char
(
&
fmd
,
'\r'
);
format_add_char
(
&
fmd
,
'\n'
);
}
}
else
{
if
(
ch
==
'\n'
)
{
if
(
width
)
ADD_TO_T
(
' '
);
format_add_char
(
&
fmd
,
' '
);
else
{
ADD_TO_T
(
'\r'
);
ADD_TO_T
(
'\n'
);
format_add_char
(
&
fmd
,
'\r'
);
format_add_char
(
&
fmd
,
'\n'
);
}
}
else
ADD_TO_T
(
ch
);
format_add_char
(
&
fmd
,
ch
);
}
}
}
*
t
=
'\0'
;
*
fmd
.
t
=
'\0'
;
return
target
;
return
fmd
.
formatted
;
}
#undef ADD_TO_T
/***********************************************************************
* FormatMessageA (KERNEL32.@)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment