Commit 0025ef60 authored by Christian Costa's avatar Christian Costa Committed by Alexandre Julliard

d3dxof: Simplify parsing.

parent f8446f26
...@@ -543,7 +543,7 @@ static BOOL is_integer(parse_buffer* buf) ...@@ -543,7 +543,7 @@ static BOOL is_integer(parse_buffer* buf)
TRACE("Found integer %s - %d\n", tmp, integer); TRACE("Found integer %s - %d\n", tmp, integer);
*(WORD*)buf->value = integer; *(DWORD*)buf->value = integer;
return TRUE; return TRUE;
} }
...@@ -623,14 +623,51 @@ static WORD parse_TOKEN_dbg_opt(parse_buffer * buf, BOOL show_token) ...@@ -623,14 +623,51 @@ static WORD parse_TOKEN_dbg_opt(parse_buffer * buf, BOOL show_token)
{ {
if (!read_bytes(buf, &token, 2)) if (!read_bytes(buf, &token, 2))
return 0; return 0;
}
switch(token) switch(token)
{ {
case TOKEN_NAME: case TOKEN_NAME:
case TOKEN_STRING: {
DWORD count;
char strname[100];
if (!read_bytes(buf, &count, 4))
return 0;
if (!read_bytes(buf, strname, count))
return 0;
strname[count] = 0;
/*TRACE("name = %s\n", strname);*/
strcpy((char*)buf->value, strname);
}
break;
case TOKEN_INTEGER: case TOKEN_INTEGER:
{
DWORD integer;
if (!read_bytes(buf, &integer, 4))
return 0;
/*TRACE("integer = %ld\n", integer);*/
*(DWORD*)buf->value = integer;
}
break;
case TOKEN_GUID: case TOKEN_GUID:
{
char strguid[38];
GUID class_id;
if (!read_bytes(buf, &class_id, 16))
return 0;
sprintf(strguid, CLSIDFMT, class_id.Data1, class_id.Data2, class_id.Data3, class_id.Data4[0],
class_id.Data4[1], class_id.Data4[2], class_id.Data4[3], class_id.Data4[4], class_id.Data4[5],
class_id.Data4[6], class_id.Data4[7]);
/*TRACE("guid = {%s}\n", strguid);*/
*(GUID*)buf->value = class_id;
}
break;
case TOKEN_STRING:
case TOKEN_INTEGER_LIST: case TOKEN_INTEGER_LIST:
case TOKEN_FLOAT_LIST: case TOKEN_FLOAT_LIST:
case TOKEN_OBRACE: case TOKEN_OBRACE:
...@@ -662,6 +699,7 @@ static WORD parse_TOKEN_dbg_opt(parse_buffer * buf, BOOL show_token) ...@@ -662,6 +699,7 @@ static WORD parse_TOKEN_dbg_opt(parse_buffer * buf, BOOL show_token)
default: default:
return 0; return 0;
} }
}
if (show_token) if (show_token)
dump_TOKEN(token); dump_TOKEN(token);
...@@ -758,64 +796,6 @@ static inline BOOL is_primitive_type(WORD token) ...@@ -758,64 +796,6 @@ static inline BOOL is_primitive_type(WORD token)
return ret; return ret;
} }
static BOOL parse_name(parse_buffer * buf)
{
DWORD count;
char strname[100];
if (parse_TOKEN(buf) != TOKEN_NAME)
return FALSE;
if (buf->txt)
return TRUE;
if (!read_bytes(buf, &count, 4))
return FALSE;
if (!read_bytes(buf, strname, count))
return FALSE;
strname[count] = 0;
/*TRACE("name = %s\n", strname);*/
strcpy((char*)buf->value, strname);
return TRUE;
}
static BOOL parse_class_id(parse_buffer * buf)
{
char strguid[38];
GUID class_id;
if (parse_TOKEN(buf) != TOKEN_GUID)
return FALSE;
if (buf->txt)
return TRUE;
if (!read_bytes(buf, &class_id, 16))
return FALSE;
sprintf(strguid, CLSIDFMT, class_id.Data1, class_id.Data2, class_id.Data3, class_id.Data4[0],
class_id.Data4[1], class_id.Data4[2], class_id.Data4[3], class_id.Data4[4], class_id.Data4[5], class_id.Data4[6], class_id.Data4[7]);
/*TRACE("guid = {%s}\n", strguid);*/
*(GUID*)buf->value = class_id;
return TRUE;
}
static BOOL parse_integer(parse_buffer * buf)
{
DWORD integer;
if (parse_TOKEN(buf) != TOKEN_INTEGER)
return FALSE;
if (buf->txt)
return TRUE;
if (!read_bytes(buf, &integer, 4))
return FALSE;
/*TRACE("integer = %ld\n", integer);*/
*(DWORD*)buf->value = integer;
return TRUE;
}
static BOOL parse_template_option_info(parse_buffer * buf) static BOOL parse_template_option_info(parse_buffer * buf)
{ {
xtemplate* cur_template = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates]; xtemplate* cur_template = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates];
...@@ -833,12 +813,11 @@ static BOOL parse_template_option_info(parse_buffer * buf) ...@@ -833,12 +813,11 @@ static BOOL parse_template_option_info(parse_buffer * buf)
{ {
while (1) while (1)
{ {
if (!parse_name(buf)) if (parse_TOKEN(buf) != TOKEN_NAME)
return FALSE; return FALSE;
strcpy(cur_template->childs[cur_template->nb_childs], (char*)buf->value); strcpy(cur_template->childs[cur_template->nb_childs], (char*)buf->value);
if (check_TOKEN(buf) == TOKEN_GUID) if (check_TOKEN(buf) == TOKEN_GUID)
if (!parse_class_id(buf)) parse_TOKEN(buf);
return FALSE;
cur_template->nb_childs++; cur_template->nb_childs++;
if (check_TOKEN(buf) != TOKEN_COMMA) if (check_TOKEN(buf) != TOKEN_COMMA)
break; break;
...@@ -852,57 +831,24 @@ static BOOL parse_template_option_info(parse_buffer * buf) ...@@ -852,57 +831,24 @@ static BOOL parse_template_option_info(parse_buffer * buf)
static BOOL parse_template_members_list(parse_buffer * buf) static BOOL parse_template_members_list(parse_buffer * buf)
{ {
parse_buffer save1;
int idx_member = 0; int idx_member = 0;
member* cur_member; member* cur_member;
while (1) while (1)
{ {
cur_member = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[idx_member]; BOOL array = 0;
save1 = *buf;
if (check_TOKEN(buf) == TOKEN_NAME)
{
if (!parse_name(buf))
break;
while (cur_member->idx_template < buf->pdxf->nb_xtemplates)
{
if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[cur_member->idx_template].name))
break;
cur_member->idx_template++;
}
if (cur_member->idx_template == buf->pdxf->nb_xtemplates)
{
TRACE("Reference to a nonexistent template '%s'\n", (char*)buf->value);
return FALSE;
}
if (check_TOKEN(buf) == TOKEN_NAME)
if (!parse_name(buf))
break;
if (parse_TOKEN(buf) != TOKEN_SEMICOLON)
break;
cur_member->type = TOKEN_NAME;
strcpy(cur_member->name, (char*)buf->value);
idx_member++;
}
else if (check_TOKEN(buf) == TOKEN_ARRAY)
{
parse_buffer save2;
WORD token;
int nb_dims = 0; int nb_dims = 0;
cur_member = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[idx_member];
parse_TOKEN(buf); if (check_TOKEN(buf) == TOKEN_ARRAY)
token = check_TOKEN(buf);
if (is_primitive_type(token))
{ {
parse_TOKEN(buf); parse_TOKEN(buf);
cur_member->type = token; array = 1;
} }
else
if (check_TOKEN(buf) == TOKEN_NAME)
{ {
if (!parse_name(buf)) cur_member->type = parse_TOKEN(buf);
break;
cur_member->type = TOKEN_NAME;
cur_member->idx_template = 0; cur_member->idx_template = 0;
while (cur_member->idx_template < buf->pdxf->nb_xtemplates) while (cur_member->idx_template < buf->pdxf->nb_xtemplates)
{ {
...@@ -912,14 +858,21 @@ static BOOL parse_template_members_list(parse_buffer * buf) ...@@ -912,14 +858,21 @@ static BOOL parse_template_members_list(parse_buffer * buf)
} }
if (cur_member->idx_template == buf->pdxf->nb_xtemplates) if (cur_member->idx_template == buf->pdxf->nb_xtemplates)
{ {
TRACE("Reference to nonexistent template '%s'\n", (char*)buf->value); TRACE("Reference to a nonexistent template '%s'\n", (char*)buf->value);
return FALSE; return FALSE;
} }
} }
if (!parse_name(buf)) else if (is_primitive_type(check_TOKEN(buf)))
cur_member->type = parse_TOKEN(buf);
else
break; break;
if (parse_TOKEN(buf) != TOKEN_NAME)
return FALSE;
strcpy(cur_member->name, (char*)buf->value); strcpy(cur_member->name, (char*)buf->value);
save2 = *buf;
if (array)
{
while (check_TOKEN(buf) == TOKEN_OBRACKET) while (check_TOKEN(buf) == TOKEN_OBRACKET)
{ {
if (nb_dims) if (nb_dims)
...@@ -930,47 +883,32 @@ static BOOL parse_template_members_list(parse_buffer * buf) ...@@ -930,47 +883,32 @@ static BOOL parse_template_members_list(parse_buffer * buf)
parse_TOKEN(buf); parse_TOKEN(buf);
if (check_TOKEN(buf) == TOKEN_INTEGER) if (check_TOKEN(buf) == TOKEN_INTEGER)
{ {
if (!parse_integer(buf)) parse_TOKEN(buf);
break;
cur_member->dim_fixed[nb_dims] = TRUE; cur_member->dim_fixed[nb_dims] = TRUE;
cur_member->dim_value[nb_dims] = *(DWORD*)buf->value; cur_member->dim_value[nb_dims] = *(DWORD*)buf->value;
} }
else else
{ {
if (!parse_name(buf)) if (parse_TOKEN(buf) != TOKEN_NAME)
break; return FALSE;
cur_member->dim_fixed[nb_dims] = FALSE; cur_member->dim_fixed[nb_dims] = FALSE;
/* Hack: Assume array size is specified in previous member */ /* Hack: Assume array size is specified in previous member */
cur_member->dim_value[nb_dims] = idx_member - 1; cur_member->dim_value[nb_dims] = idx_member - 1;
} }
if (parse_TOKEN(buf) != TOKEN_CBRACKET) if (parse_TOKEN(buf) != TOKEN_CBRACKET)
break; return FALSE;
save2 = *buf;
nb_dims++; nb_dims++;
} }
*buf = save2; if (!nb_dims)
if (parse_TOKEN(buf) != TOKEN_SEMICOLON) return FALSE;
break;
cur_member->nb_dims = nb_dims; cur_member->nb_dims = nb_dims;
idx_member++;
} }
else if (is_primitive_type(check_TOKEN(buf)))
{
cur_member->type = check_TOKEN(buf);
parse_TOKEN(buf);
if (check_TOKEN(buf) == TOKEN_NAME)
if (!parse_name(buf))
break;
strcpy(cur_member->name, (char*)buf->value);
if (parse_TOKEN(buf) != TOKEN_SEMICOLON) if (parse_TOKEN(buf) != TOKEN_SEMICOLON)
break; return FALSE;
idx_member++; idx_member++;
} }
else
break;
}
*buf = save1;
buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].nb_members = idx_member; buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].nb_members = idx_member;
return TRUE; return TRUE;
...@@ -978,16 +916,6 @@ static BOOL parse_template_members_list(parse_buffer * buf) ...@@ -978,16 +916,6 @@ static BOOL parse_template_members_list(parse_buffer * buf)
static BOOL parse_template_parts(parse_buffer * buf) static BOOL parse_template_parts(parse_buffer * buf)
{ {
if (check_TOKEN(buf) == TOKEN_OBRACKET)
{
parse_TOKEN(buf);
if (!parse_template_option_info(buf))
return FALSE;
if (parse_TOKEN(buf) != TOKEN_CBRACKET)
return FALSE;
}
else
{
if (!parse_template_members_list(buf)) if (!parse_template_members_list(buf))
return FALSE; return FALSE;
if (check_TOKEN(buf) == TOKEN_OBRACKET) if (check_TOKEN(buf) == TOKEN_OBRACKET)
...@@ -998,7 +926,6 @@ static BOOL parse_template_parts(parse_buffer * buf) ...@@ -998,7 +926,6 @@ static BOOL parse_template_parts(parse_buffer * buf)
if (parse_TOKEN(buf) != TOKEN_CBRACKET) if (parse_TOKEN(buf) != TOKEN_CBRACKET)
return FALSE; return FALSE;
} }
}
return TRUE; return TRUE;
} }
...@@ -1007,12 +934,12 @@ static BOOL parse_template(parse_buffer * buf) ...@@ -1007,12 +934,12 @@ static BOOL parse_template(parse_buffer * buf)
{ {
if (parse_TOKEN(buf) != TOKEN_TEMPLATE) if (parse_TOKEN(buf) != TOKEN_TEMPLATE)
return FALSE; return FALSE;
if (!parse_name(buf)) if (parse_TOKEN(buf) != TOKEN_NAME)
return FALSE; return FALSE;
strcpy(buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].name, (char*)buf->value); strcpy(buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].name, (char*)buf->value);
if (parse_TOKEN(buf) != TOKEN_OBRACE) if (parse_TOKEN(buf) != TOKEN_OBRACE)
return FALSE; return FALSE;
if (!parse_class_id(buf)) if (parse_TOKEN(buf) != TOKEN_GUID)
return FALSE; return FALSE;
buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].class_id = *(GUID*)buf->value; buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].class_id = *(GUID*)buf->value;
if (!parse_template_parts(buf)) if (!parse_template_parts(buf))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment