d3dxof: Finish strings support.

This commit is contained in:
Christian Costa 2008-11-09 11:11:40 +01:00 committed by Alexandre Julliard
parent e4748c3ca3
commit 48c4248d3a
2 changed files with 31 additions and 10 deletions

View File

@ -668,22 +668,21 @@ static BOOL is_integer(parse_buffer* buf)
static BOOL is_string(parse_buffer* buf) static BOOL is_string(parse_buffer* buf)
{ {
char tmp[32]; char tmp[32];
DWORD pos = 1; DWORD pos = 0;
char c; char c;
BOOL ok = 0; BOOL ok = 0;
if (*buf->buffer != '"') if (*buf->buffer != '"')
return FALSE; return FALSE;
tmp[0] = '"';
while (!is_separator(c = *(buf->buffer+pos)) && (pos < 32)) while (!is_separator(c = *(buf->buffer+pos+1)) && (pos < 31))
{ {
tmp[pos++] = c;
if (c == '"') if (c == '"')
{ {
ok = 1; ok = 1;
break; break;
} }
tmp[pos++] = c;
} }
tmp[pos] = 0; tmp[pos] = 0;
@ -693,8 +692,8 @@ static BOOL is_string(parse_buffer* buf)
return FALSE; return FALSE;
} }
buf->buffer += pos; buf->buffer += pos + 2;
buf->rem_bytes -= pos; buf->rem_bytes -= pos + 2;
TRACE("Found string %s\n", tmp); TRACE("Found string %s\n", tmp);
strcpy((char*)buf->value, tmp); strcpy((char*)buf->value, tmp);
@ -1884,7 +1883,6 @@ static BOOL parse_object_members_list(parse_buffer * buf)
} }
else if (token == TOKEN_LPSTR) else if (token == TOKEN_LPSTR)
{ {
static char fake_string[] = "Fake string";
get_TOKEN(buf); get_TOKEN(buf);
TRACE("%s = %s\n", pt->members[i].name, (char*)buf->value); TRACE("%s = %s\n", pt->members[i].name, (char*)buf->value);
/* Assume larger size */ /* Assume larger size */
@ -1895,8 +1893,15 @@ static BOOL parse_object_members_list(parse_buffer * buf)
} }
if (pt->members[i].type == TOKEN_LPSTR) if (pt->members[i].type == TOKEN_LPSTR)
{ {
/* Use a fake string for now */ int len = strlen((char*)buf->value) + 1;
*(((LPCSTR*)(buf->cur_pdata))) = fake_string; if ((buf->cur_pstrings - buf->pstrings + len) > MAX_STRINGS_BUFFER)
{
WARN("Buffer too small %p %p %d\n", buf->cur_pstrings, buf->pstrings, len);
return FALSE;
}
strcpy((char*)buf->cur_pstrings, (char*)buf->value);
*(((LPCSTR*)(buf->cur_pdata))) = (char*)buf->cur_pstrings;
buf->cur_pstrings += len;
buf->cur_pdata += 4; buf->cur_pdata += 4;
} }
else else
@ -2067,6 +2072,7 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
IDirectXFileDataImpl* object; IDirectXFileDataImpl* object;
HRESULT hr; HRESULT hr;
LPBYTE pdata; LPBYTE pdata;
LPBYTE pstrings;
TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj); TRACE("(%p/%p)->(%p)\n", This, iface, ppDataObj);
@ -2082,6 +2088,7 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
This->buf.pxo_tab = &This->xobjects[This->nb_xobjects][0]; This->buf.pxo_tab = &This->xobjects[This->nb_xobjects][0];
This->buf.cur_subobject = 0; This->buf.cur_subobject = 0;
This->buf.pxo = &This->buf.pxo_tab[This->buf.cur_subobject++]; This->buf.pxo = &This->buf.pxo_tab[This->buf.cur_subobject++];
This->buf.level = 0;
pdata = HeapAlloc(GetProcessHeap(), 0, MAX_DATA_SIZE); pdata = HeapAlloc(GetProcessHeap(), 0, MAX_DATA_SIZE);
if (!pdata) if (!pdata)
@ -2090,12 +2097,21 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
return DXFILEERR_BADALLOC; return DXFILEERR_BADALLOC;
} }
This->buf.cur_pdata = pdata; This->buf.cur_pdata = pdata;
This->buf.level = 0;
pstrings = HeapAlloc(GetProcessHeap(), 0, MAX_STRINGS_BUFFER);
if (!pstrings)
{
WARN("Out of memory\n");
HeapFree(GetProcessHeap(), 0, This->buf.pxo->pdata);
return DXFILEERR_BADALLOC;
}
This->buf.cur_pstrings = This->buf.pstrings = pstrings;
if (!parse_object(&This->buf)) if (!parse_object(&This->buf))
{ {
TRACE("Object is not correct\n"); TRACE("Object is not correct\n");
HeapFree(GetProcessHeap(), 0, This->buf.pxo->pdata); HeapFree(GetProcessHeap(), 0, This->buf.pxo->pdata);
HeapFree(GetProcessHeap(), 0, This->buf.pstrings);
return DXFILEERR_PARSEERROR; return DXFILEERR_PARSEERROR;
} }
@ -2106,6 +2122,7 @@ static HRESULT WINAPI IDirectXFileEnumObjectImpl_GetNextDataObject(IDirectXFileE
return DXFILEERR_BADALLOC; return DXFILEERR_BADALLOC;
} }
object->pstrings = pstrings;
object->pobj = This->buf.pxo; object->pobj = This->buf.pxo;
object->cur_enum_object = 0; object->cur_enum_object = 0;
object->level = 0; object->level = 0;

View File

@ -40,6 +40,7 @@
#define MAX_TEMPLATES 200 #define MAX_TEMPLATES 200
#define MAX_OBJECTS 200 #define MAX_OBJECTS 200
#define MAX_SUBOBJECTS 120 #define MAX_SUBOBJECTS 120
#define MAX_STRINGS_BUFFER 200
typedef struct { typedef struct {
DWORD type; DWORD type;
@ -101,6 +102,7 @@ typedef struct {
int cur_enum_object; int cur_enum_object;
BOOL from_ref; BOOL from_ref;
ULONG level; ULONG level;
LPBYTE pstrings;
} IDirectXFileDataImpl; } IDirectXFileDataImpl;
typedef struct { typedef struct {
@ -124,6 +126,7 @@ typedef struct {
BOOL txt; BOOL txt;
ULONG cur_subobject; ULONG cur_subobject;
LPBYTE cur_pdata; LPBYTE cur_pdata;
LPBYTE cur_pstrings;
BYTE value[100]; BYTE value[100];
xobject* pxo_globals; xobject* pxo_globals;
ULONG nb_pxo_globals; ULONG nb_pxo_globals;
@ -132,6 +135,7 @@ typedef struct {
xobject* pxo; xobject* pxo;
xtemplate* pxt[MAX_SUBOBJECTS]; xtemplate* pxt[MAX_SUBOBJECTS];
ULONG level; ULONG level;
LPBYTE pstrings;
} parse_buffer; } parse_buffer;
typedef struct { typedef struct {