d3dxof: Factor out parse template loops into a function.

oldstable
Dylan Smith 2011-06-08 15:39:05 -04:00 committed by Alexandre Julliard
parent 18740e8623
commit 80705f5a91
3 changed files with 32 additions and 48 deletions

View File

@ -225,20 +225,9 @@ static HRESULT WINAPI IDirectXFileImpl_CreateEnumObject(IDirectXFile* iface, LPV
if (FAILED(hr))
goto error;
while (object->buf.rem_bytes && is_template_available(&object->buf))
{
if (!parse_template(&object->buf))
{
WARN("Template is not correct\n");
hr = DXFILEERR_BADVALUE;
goto error;
}
else
{
TRACE("Template successfully parsed:\n");
if (TRACE_ON(d3dxof))
dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
}
if (!parse_templates(&object->buf)) {
hr = DXFILEERR_BADVALUE;
goto error;
}
if (TRACE_ON(d3dxof))
@ -299,20 +288,9 @@ static HRESULT WINAPI IDirectXFileImpl_RegisterTemplates(IDirectXFile* iface, LP
if (FAILED(hr))
goto cleanup;
while (buf.rem_bytes && is_template_available(&buf))
{
if (!parse_template(&buf))
{
WARN("Template is not correct\n");
hr = DXFILEERR_BADVALUE;
goto cleanup;
}
else
{
TRACE("Template successfully parsed:\n");
if (TRACE_ON(d3dxof))
dump_template(This->xtemplates, &This->xtemplates[This->nb_xtemplates - 1]);
}
if (!parse_templates(&buf)) {
hr = DXFILEERR_BADVALUE;
goto cleanup;
}
if (TRACE_ON(d3dxof))
@ -970,20 +948,9 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
}
/* Check if there are templates defined before the object */
while (This->buf.rem_bytes && is_template_available(&This->buf))
{
if (!parse_template(&This->buf))
{
WARN("Template is not correct\n");
hr = DXFILEERR_BADVALUE;
goto error;
}
else
{
TRACE("Template successfully parsed:\n");
if (TRACE_ON(d3dxof))
dump_template(This->pDirectXFile->xtemplates, &This->pDirectXFile->xtemplates[This->pDirectXFile->nb_xtemplates - 1]);
}
if (!parse_templates(&This->buf)) {
hr = DXFILEERR_BADVALUE;
goto error;
}
if (!This->buf.rem_bytes)

View File

@ -164,10 +164,8 @@ HRESULT IDirectXFileImpl_Create(IUnknown *pUnkOuter, LPVOID *ppObj) DECLSPEC_HID
BOOL read_bytes(parse_buffer * buf, LPVOID data, DWORD size) DECLSPEC_HIDDEN;
HRESULT parse_header(parse_buffer *buf, BYTE **decomp_buffer_ptr) DECLSPEC_HIDDEN;
BOOL parse_template(parse_buffer * buf) DECLSPEC_HIDDEN;
void dump_template(xtemplate* templates_array, xtemplate* ptemplate) DECLSPEC_HIDDEN;
BOOL is_template_available(parse_buffer * buf) DECLSPEC_HIDDEN;
BOOL parse_object(parse_buffer * buf) DECLSPEC_HIDDEN;
BOOL parse_templates(parse_buffer * buf) DECLSPEC_HIDDEN;
int mszip_decompress(int inlen, int outlen, char* inbuffer, char* outbuffer) DECLSPEC_HIDDEN;

View File

@ -125,7 +125,7 @@ static const char* get_primitive_string(WORD token)
return NULL;
}
void dump_template(xtemplate* templates_array, xtemplate* ptemplate)
static void dump_template(xtemplate* templates_array, xtemplate* ptemplate)
{
int j, k;
GUID* clsid;
@ -858,7 +858,7 @@ static WORD check_TOKEN(parse_buffer * buf)
return buf->current_token;
}
BOOL is_template_available(parse_buffer * buf)
static BOOL is_template_available(parse_buffer * buf)
{
return check_TOKEN(buf) == TOKEN_TEMPLATE;
}
@ -1076,7 +1076,7 @@ static void go_to_next_definition(parse_buffer * buf)
}
}
BOOL parse_template(parse_buffer * buf)
static BOOL parse_template(parse_buffer * buf)
{
if (get_TOKEN(buf) != TOKEN_TEMPLATE)
return FALSE;
@ -1104,6 +1104,25 @@ BOOL parse_template(parse_buffer * buf)
return TRUE;
}
BOOL parse_templates(parse_buffer * buf)
{
while (buf->rem_bytes && is_template_available(buf))
{
if (!parse_template(buf))
{
WARN("Template is not correct\n");
return FALSE;
}
else
{
TRACE("Template successfully parsed:\n");
if (TRACE_ON(d3dxof_parsing))
dump_template(buf->pdxf->xtemplates, &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates - 1]);
}
}
return TRUE;
}
static BOOL check_buffer(parse_buffer * buf, ULONG size)
{
if ((buf->cur_pos_data + size) > buf->capacity)