4 * Copyright 2008 Christian Costa
6 * This file contains the (internal) driver registration functions,
7 * driver enumeration APIs and DirectDraw creation functions.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "wine/debug.h"
32 #include "d3dxof_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(d3dxof_parsing);
40 #define TOKEN_STRING 2
41 #define TOKEN_INTEGER 3
43 #define TOKEN_INTEGER_LIST 6
44 #define TOKEN_FLOAT_LIST 7
45 #define TOKEN_OBRACE 10
46 #define TOKEN_CBRACE 11
47 #define TOKEN_OPAREN 12
48 #define TOKEN_CPAREN 13
49 #define TOKEN_OBRACKET 14
50 #define TOKEN_CBRACKET 15
51 #define TOKEN_OANGLE 16
52 #define TOKEN_CANGLE 17
54 #define TOKEN_COMMA 19
55 #define TOKEN_SEMICOLON 20
56 #define TOKEN_TEMPLATE 31
58 #define TOKEN_DWORD 41
59 #define TOKEN_FLOAT 42
60 #define TOKEN_DOUBLE 43
62 #define TOKEN_UCHAR 45
63 #define TOKEN_SWORD 46
64 #define TOKEN_SDWORD 47
66 #define TOKEN_LPSTR 49
67 #define TOKEN_UNICODE 50
68 #define TOKEN_CSTRING 51
69 #define TOKEN_ARRAY 52
71 #define CLSIDFMT "<%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X>"
73 static const char* get_primitive_string(WORD token)
107 void dump_template(xtemplate* templates_array, xtemplate* ptemplate)
112 clsid = &ptemplate->class_id;
114 DPRINTF("template %s\n", ptemplate->name);
116 DPRINTF(CLSIDFMT "\n", clsid->Data1, clsid->Data2, clsid->Data3, clsid->Data4[0],
117 clsid->Data4[1], clsid->Data4[2], clsid->Data4[3], clsid->Data4[4], clsid->Data4[5], clsid->Data4[6], clsid->Data4[7]);
118 for (j = 0; j < ptemplate->nb_members; j++)
120 if (ptemplate->members[j].nb_dims)
122 if (ptemplate->members[j].type == TOKEN_NAME)
123 DPRINTF("%s ", templates_array[ptemplate->members[j].idx_template].name);
125 DPRINTF("%s ", get_primitive_string(ptemplate->members[j].type));
126 DPRINTF("%s", ptemplate->members[j].name);
127 for (k = 0; k < ptemplate->members[j].nb_dims; k++)
129 if (ptemplate->members[j].dim_fixed[k])
130 DPRINTF("[%d]", ptemplate->members[j].dim_value[k]);
132 DPRINTF("[%s]", ptemplate->members[ptemplate->members[j].dim_value[k]].name);
138 else if (ptemplate->nb_childs)
140 DPRINTF("[%s", ptemplate->childs[0]);
141 for (j = 1; j < ptemplate->nb_childs; j++)
142 DPRINTF(",%s", ptemplate->childs[j]);
148 BOOL read_bytes(parse_buffer * buf, LPVOID data, DWORD size)
150 if (buf->rem_bytes < size)
152 memcpy(data, buf->buffer, size);
154 buf->rem_bytes -= size;
158 static void rewind_bytes(parse_buffer * buf, DWORD size)
161 buf->rem_bytes += size;
164 static void dump_TOKEN(WORD token)
166 #define DUMP_TOKEN(t) case t: TRACE(#t "\n"); break
169 DUMP_TOKEN(TOKEN_NAME);
170 DUMP_TOKEN(TOKEN_STRING);
171 DUMP_TOKEN(TOKEN_INTEGER);
172 DUMP_TOKEN(TOKEN_GUID);
173 DUMP_TOKEN(TOKEN_INTEGER_LIST);
174 DUMP_TOKEN(TOKEN_FLOAT_LIST);
175 DUMP_TOKEN(TOKEN_OBRACE);
176 DUMP_TOKEN(TOKEN_CBRACE);
177 DUMP_TOKEN(TOKEN_OPAREN);
178 DUMP_TOKEN(TOKEN_CPAREN);
179 DUMP_TOKEN(TOKEN_OBRACKET);
180 DUMP_TOKEN(TOKEN_CBRACKET);
181 DUMP_TOKEN(TOKEN_OANGLE);
182 DUMP_TOKEN(TOKEN_CANGLE);
183 DUMP_TOKEN(TOKEN_DOT);
184 DUMP_TOKEN(TOKEN_COMMA);
185 DUMP_TOKEN(TOKEN_SEMICOLON);
186 DUMP_TOKEN(TOKEN_TEMPLATE);
187 DUMP_TOKEN(TOKEN_WORD);
188 DUMP_TOKEN(TOKEN_DWORD);
189 DUMP_TOKEN(TOKEN_FLOAT);
190 DUMP_TOKEN(TOKEN_DOUBLE);
191 DUMP_TOKEN(TOKEN_CHAR);
192 DUMP_TOKEN(TOKEN_UCHAR);
193 DUMP_TOKEN(TOKEN_SWORD);
194 DUMP_TOKEN(TOKEN_SDWORD);
195 DUMP_TOKEN(TOKEN_VOID);
196 DUMP_TOKEN(TOKEN_LPSTR);
197 DUMP_TOKEN(TOKEN_UNICODE);
198 DUMP_TOKEN(TOKEN_CSTRING);
199 DUMP_TOKEN(TOKEN_ARRAY);
202 TRACE("Unknown token %d\n", token);
208 static BOOL is_space(char c)
222 static BOOL is_operator(char c)
241 static inline BOOL is_separator(char c)
243 return is_space(c) || is_operator(c);
246 static WORD get_operator_token(char c)
255 return TOKEN_OBRACKET;
257 return TOKEN_CBRACKET;
269 return TOKEN_SEMICOLON;
274 static BOOL is_keyword(parse_buffer* buf, const char* keyword)
276 char tmp[8]; /* longest keyword size (template) */
277 DWORD len = strlen(keyword);
279 if (!read_bytes(buf, tmp, len))
281 if (strncasecmp(tmp, keyword, len))
283 rewind_bytes(buf, len);
287 if (!read_bytes(buf, tmp, 1))
289 if (is_separator(tmp[0]))
291 rewind_bytes(buf, 1);
294 rewind_bytes(buf, len+1);
298 static WORD get_keyword_token(parse_buffer* buf)
300 if (is_keyword(buf, "template"))
301 return TOKEN_TEMPLATE;
302 if (is_keyword(buf, "WORD"))
304 if (is_keyword(buf, "DWORD"))
306 if (is_keyword(buf, "FLOAT"))
308 if (is_keyword(buf, "DOUBLE"))
310 if (is_keyword(buf, "CHAR"))
312 if (is_keyword(buf, "UCHAR"))
314 if (is_keyword(buf, "SWORD"))
316 if (is_keyword(buf, "SDWORD"))
318 if (is_keyword(buf, "VOID"))
320 if (is_keyword(buf, "STRING"))
322 if (is_keyword(buf, "UNICODE"))
323 return TOKEN_UNICODE;
324 if (is_keyword(buf, "CSTRING"))
325 return TOKEN_CSTRING;
326 if (is_keyword(buf, "array"))
332 static BOOL is_guid(parse_buffer* buf)
340 if (buf->rem_bytes < 38 || *buf->buffer != '<')
343 while (pos < sizeof(tmp) - 2 && *(buf->buffer+pos) != '>')
345 tmp[pos] = *(buf->buffer+pos);
350 if (pos != 38 /* <+36+> */)
352 TRACE("Wrong guid %s (%d)\n", tmp, pos);
356 buf->rem_bytes -= pos;
358 ret = sscanf(tmp, CLSIDFMT, &class_id.Data1, tab, tab+1, tab+2, tab+3, tab+4, tab+5, tab+6, tab+7, tab+8, tab+9);
361 TRACE("Wrong guid %s (%d)\n", tmp, pos);
364 TRACE("Found guid %s (%d)\n", tmp, pos);
366 class_id.Data2 = tab[0];
367 class_id.Data3 = tab[1];
368 class_id.Data4[0] = tab[2];
369 class_id.Data4[1] = tab[3];
370 class_id.Data4[2] = tab[4];
371 class_id.Data4[3] = tab[5];
372 class_id.Data4[4] = tab[6];
373 class_id.Data4[5] = tab[7];
374 class_id.Data4[6] = tab[8];
375 class_id.Data4[7] = tab[9];
377 *(GUID*)buf->value = class_id;
382 static BOOL is_name(parse_buffer* buf)
388 while (pos < buf->rem_bytes && !is_separator(c = *(buf->buffer+pos)))
390 if (!(((c >= 'a') && (c <= 'z')) || ((c >= 'A') && (c <= 'Z')) || ((c >= '0') && (c <= '9')) || (c == '_') || (c == '-')))
392 if (pos < sizeof(tmp))
396 tmp[min(pos, sizeof(tmp) - 1)] = 0;
400 TRACE("Wrong name %s\n", tmp);
405 buf->rem_bytes -= pos;
407 TRACE("Found name %s\n", tmp);
408 strcpy((char*)buf->value, tmp);
413 static BOOL is_float(parse_buffer* buf)
421 while (pos < buf->rem_bytes && !is_separator(c = *(buf->buffer+pos)))
423 if (!((!pos && (c == '-')) || ((c >= '0') && (c <= '9')) || (!dot && (c == '.'))))
427 if (pos < sizeof(tmp))
431 tmp[min(pos, sizeof(tmp) - 1)] = 0;
434 buf->rem_bytes -= pos;
436 sscanf(tmp, "%f", &decimal);
438 TRACE("Found float %s - %f\n", tmp, decimal);
440 *(float*)buf->value = decimal;
445 static BOOL is_integer(parse_buffer* buf)
452 while (pos < buf->rem_bytes && !is_separator(c = *(buf->buffer+pos)))
454 if (!((c >= '0') && (c <= '9')))
456 if (pos < sizeof(tmp))
460 tmp[min(pos, sizeof(tmp) - 1)] = 0;
463 buf->rem_bytes -= pos;
465 sscanf(tmp, "%d", &integer);
467 TRACE("Found integer %s - %d\n", tmp, integer);
469 *(DWORD*)buf->value = integer;
474 static BOOL is_string(parse_buffer* buf)
481 if (*buf->buffer != '"')
484 while (pos < buf->rem_bytes && !is_operator(c = *(buf->buffer+pos+1)))
491 if (pos < sizeof(tmp))
495 tmp[min(pos, sizeof(tmp) - 1)] = 0;
499 TRACE("Wrong string %s\n", tmp);
503 buf->buffer += pos + 2;
504 buf->rem_bytes -= pos + 2;
506 TRACE("Found string %s\n", tmp);
507 strcpy((char*)buf->value, tmp);
512 static WORD parse_TOKEN(parse_buffer * buf)
521 if (!read_bytes(buf, &c, 1))
523 /*TRACE("char = '%c'\n", is_space(c) ? ' ' : c);*/
524 if ((c == '#') || (c == '/'))
526 /* Handle comment (# or //) */
529 if (!read_bytes(buf, &c, 1))
537 if (!read_bytes(buf, &c, 1))
544 if (is_operator(c) && (c != '<'))
546 token = get_operator_token(c);
556 rewind_bytes(buf, 1);
558 if ((token = get_keyword_token(buf)))
568 token = TOKEN_INTEGER;
587 FIXME("Unrecognize element\n");
599 if (!read_bytes(buf, &token, 2))
602 /* Convert integer and float list into separate elements */
603 if (token == TOKEN_INTEGER_LIST)
605 if (!read_bytes(buf, &nb_elem, 4))
607 token = TOKEN_INTEGER;
609 TRACE("Integer list (TOKEN_INTEGER_LIST) of size %d\n", nb_elem);
611 else if (token == TOKEN_FLOAT_LIST)
613 if (!read_bytes(buf, &nb_elem, 4))
617 TRACE("Float list (TOKEN_FLOAT_LIST) of size %d\n", nb_elem);
623 token = is_float ? TOKEN_FLOAT : TOKEN_INTEGER;
628 if (!read_bytes(buf, &integer, 4))
631 *(DWORD*)buf->value = integer;
644 if (!read_bytes(buf, &count, 4))
646 if (!read_bytes(buf, strname, count))
649 /*TRACE("name = %s\n", strname);*/
651 strcpy((char*)buf->value, strname);
658 if (!read_bytes(buf, &integer, 4))
660 /*TRACE("integer = %ld\n", integer);*/
662 *(DWORD*)buf->value = integer;
670 if (!read_bytes(buf, &class_id, 16))
672 sprintf(strguid, CLSIDFMT, class_id.Data1, class_id.Data2, class_id.Data3, class_id.Data4[0],
673 class_id.Data4[1], class_id.Data4[2], class_id.Data4[3], class_id.Data4[4], class_id.Data4[5],
674 class_id.Data4[6], class_id.Data4[7]);
675 /*TRACE("guid = {%s}\n", strguid);*/
677 *(GUID*)buf->value = class_id;
685 if (!read_bytes(buf, &count, 4))
687 if (!read_bytes(buf, strname, count))
690 if (!read_bytes(buf, &tmp_token, 2))
692 if ((tmp_token != TOKEN_COMMA) && (tmp_token != TOKEN_SEMICOLON))
693 ERR("No comma or semicolon (got %d)\n", tmp_token);
694 /*TRACE("name = %s\n", strname);*/
696 strcpy((char*)buf->value, strname);
710 case TOKEN_SEMICOLON:
736 static WORD get_TOKEN(parse_buffer * buf)
738 if (buf->token_present)
740 buf->token_present = FALSE;
741 return buf->current_token;
744 buf->current_token = parse_TOKEN(buf);
746 return buf->current_token;
749 static WORD check_TOKEN(parse_buffer * buf)
751 if (buf->token_present)
752 return buf->current_token;
754 buf->current_token = parse_TOKEN(buf);
755 buf->token_present = TRUE;
757 return buf->current_token;
760 BOOL is_template_available(parse_buffer * buf)
762 return check_TOKEN(buf) == TOKEN_TEMPLATE;
765 static inline BOOL is_primitive_type(WORD token)
790 static BOOL parse_template_option_info(parse_buffer * buf)
792 xtemplate* cur_template = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates];
794 if (check_TOKEN(buf) == TOKEN_DOT)
797 if (get_TOKEN(buf) != TOKEN_DOT)
799 if (get_TOKEN(buf) != TOKEN_DOT)
801 cur_template->open = TRUE;
807 if (get_TOKEN(buf) != TOKEN_NAME)
809 strcpy(cur_template->childs[cur_template->nb_childs], (char*)buf->value);
810 if (check_TOKEN(buf) == TOKEN_GUID)
812 cur_template->nb_childs++;
813 if (check_TOKEN(buf) != TOKEN_COMMA)
817 cur_template->open = FALSE;
823 static BOOL parse_template_members_list(parse_buffer * buf)
832 cur_member = &buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[idx_member];
834 if (check_TOKEN(buf) == TOKEN_ARRAY)
840 if (check_TOKEN(buf) == TOKEN_NAME)
842 cur_member->type = get_TOKEN(buf);
843 cur_member->idx_template = 0;
844 while (cur_member->idx_template < buf->pdxf->nb_xtemplates)
846 if (!strcasecmp((char*)buf->value, buf->pdxf->xtemplates[cur_member->idx_template].name))
848 cur_member->idx_template++;
850 if (cur_member->idx_template == buf->pdxf->nb_xtemplates)
852 ERR("Reference to a nonexistent template '%s'\n", (char*)buf->value);
856 else if (is_primitive_type(check_TOKEN(buf)))
857 cur_member->type = get_TOKEN(buf);
861 if (get_TOKEN(buf) != TOKEN_NAME)
863 strcpy(cur_member->name, (char*)buf->value);
867 while (check_TOKEN(buf) == TOKEN_OBRACKET)
869 if (nb_dims >= MAX_ARRAY_DIM)
871 FIXME("Too many dimensions (%d) for multi-dimensional array\n", nb_dims + 1);
875 if (check_TOKEN(buf) == TOKEN_INTEGER)
878 cur_member->dim_fixed[nb_dims] = TRUE;
879 cur_member->dim_value[nb_dims] = *(DWORD*)buf->value;
884 if (get_TOKEN(buf) != TOKEN_NAME)
886 for (i = 0; i < idx_member; i++)
888 if (!strcmp((char*)buf->value, buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].name))
890 if (buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].nb_dims)
892 ERR("Array cannot be used to specify variable array size\n");
895 if (buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].members[i].type != TOKEN_DWORD)
897 FIXME("Only DWORD supported to specify variable array size\n");
905 ERR("Reference to unknown member %s\n", (char*)buf->value);
908 cur_member->dim_fixed[nb_dims] = FALSE;
909 cur_member->dim_value[nb_dims] = i;
911 if (get_TOKEN(buf) != TOKEN_CBRACKET)
917 cur_member->nb_dims = nb_dims;
919 if (get_TOKEN(buf) != TOKEN_SEMICOLON)
925 buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].nb_members = idx_member;
930 static BOOL parse_template_parts(parse_buffer * buf)
932 if (!parse_template_members_list(buf))
934 if (check_TOKEN(buf) == TOKEN_OBRACKET)
937 if (!parse_template_option_info(buf))
939 if (get_TOKEN(buf) != TOKEN_CBRACKET)
946 static void go_to_next_definition(parse_buffer * buf)
949 while (buf->rem_bytes)
951 read_bytes(buf, &c, 1);
952 if ((c == '#') || (c == '/'))
954 /* Handle comment (# or //) */
957 if (!read_bytes(buf, &c, 1))
965 if (!read_bytes(buf, &c, 1))
970 else if (!is_space(c))
972 rewind_bytes(buf, 1);
978 BOOL parse_template(parse_buffer * buf)
980 if (get_TOKEN(buf) != TOKEN_TEMPLATE)
982 if (get_TOKEN(buf) != TOKEN_NAME)
984 strcpy(buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].name, (char*)buf->value);
985 if (get_TOKEN(buf) != TOKEN_OBRACE)
987 if (get_TOKEN(buf) != TOKEN_GUID)
989 buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].class_id = *(GUID*)buf->value;
990 if (!parse_template_parts(buf))
992 if (get_TOKEN(buf) != TOKEN_CBRACE)
996 /* Go to the next template */
997 go_to_next_definition(buf);
1000 TRACE("%d - %s - %s\n", buf->pdxf->nb_xtemplates, buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].name, debugstr_guid(&buf->pdxf->xtemplates[buf->pdxf->nb_xtemplates].class_id));
1001 buf->pdxf->nb_xtemplates++;
1006 static BOOL check_buffer(parse_buffer * buf, ULONG size)
1008 if ((buf->cur_pos_data + size) > buf->capacity)
1011 ULONG new_capacity = buf->capacity ? 2 * buf->capacity : 100000;
1013 pdata = HeapAlloc(GetProcessHeap(), 0, new_capacity);
1016 memcpy(pdata, buf->pdata, buf->cur_pos_data);
1017 HeapFree(GetProcessHeap(), 0, buf->pdata);
1018 buf->capacity = new_capacity;
1020 buf->pxo->root->pdata = pdata;
1025 static BOOL parse_object_parts(parse_buffer * buf, BOOL allow_optional);
1026 static BOOL parse_object_members_list(parse_buffer * buf)
1030 xtemplate* pt = buf->pxt[buf->level];
1032 for (i = 0; i < pt->nb_members; i++)
1037 buf->pxo->members[i].name = pt->members[i].name;
1038 buf->pxo->members[i].start = buf->cur_pos_data;
1040 for (k = 0; k < pt->members[i].nb_dims; k++)
1042 if (pt->members[i].dim_fixed[k])
1043 nb_elems *= pt->members[i].dim_value[k];
1045 nb_elems *= *(DWORD*)(buf->pxo->root->pdata + buf->pxo->members[pt->members[i].dim_value[k]].start);
1048 TRACE("Elements to consider: %d\n", nb_elems);
1050 for (k = 0; k < nb_elems; k++)
1054 token = check_TOKEN(buf);
1055 if (token == TOKEN_COMMA)
1061 /* Allow comma omission */
1062 if (!((token == TOKEN_FLOAT) || (token == TOKEN_INTEGER)))
1067 if (pt->members[i].type == TOKEN_NAME)
1071 TRACE("Found sub-object %s\n", buf->pdxf->xtemplates[pt->members[i].idx_template].name);
1073 /* To do template lookup */
1074 for (j = 0; j < buf->pdxf->nb_xtemplates; j++)
1076 if (!strcasecmp(buf->pdxf->xtemplates[pt->members[i].idx_template].name, buf->pdxf->xtemplates[j].name))
1078 buf->pxt[buf->level] = &buf->pdxf->xtemplates[j];
1082 if (j == buf->pdxf->nb_xtemplates)
1084 ERR("Unknown template %s\n", (char*)buf->value);
1088 TRACE("Enter %s\n", buf->pdxf->xtemplates[pt->members[i].idx_template].name);
1089 if (!parse_object_parts(buf, FALSE))
1098 token = check_TOKEN(buf);
1099 if (token == TOKEN_INTEGER)
1102 TRACE("%s = %d\n", pt->members[i].name, *(DWORD*)buf->value);
1103 /* Assume larger size */
1104 if (!check_buffer(buf, 4))
1106 if (pt->members[i].type == TOKEN_WORD)
1108 *(((WORD*)(buf->cur_pos_data + buf->pdata))) = (WORD)(*(DWORD*)buf->value);
1109 buf->cur_pos_data += 2;
1111 else if (pt->members[i].type == TOKEN_DWORD)
1113 *(((DWORD*)(buf->cur_pos_data + buf->pdata))) = (DWORD)(*(DWORD*)buf->value);
1114 buf->cur_pos_data += 4;
1118 FIXME("Token %d not supported\n", pt->members[i].type);
1122 else if (token == TOKEN_FLOAT)
1125 TRACE("%s = %f\n", pt->members[i].name, *(float*)buf->value);
1126 if (!check_buffer(buf, 4))
1128 if (pt->members[i].type == TOKEN_FLOAT)
1130 *(((float*)(buf->cur_pos_data + buf->pdata))) = (float)(*(float*)buf->value);
1131 buf->cur_pos_data += 4;
1135 FIXME("Token %d not supported\n", pt->members[i].type);
1139 else if (token == TOKEN_LPSTR)
1142 TRACE("%s = %s\n", pt->members[i].name, (char*)buf->value);
1143 if (!check_buffer(buf, sizeof(LPSTR)))
1145 if (pt->members[i].type == TOKEN_LPSTR)
1147 int len = strlen((char*)buf->value) + 1;
1148 if ((buf->cur_pstrings - buf->pstrings + len) > MAX_STRINGS_BUFFER)
1150 FIXME("Buffer too small %p %p %d\n", buf->cur_pstrings, buf->pstrings, len);
1153 strcpy((char*)buf->cur_pstrings, (char*)buf->value);
1154 *(((LPCSTR*)(buf->cur_pos_data + buf->pdata))) = (char*)buf->cur_pstrings;
1155 buf->cur_pstrings += len;
1156 buf->cur_pos_data += sizeof(LPSTR);
1160 FIXME("Token %d not supported\n", pt->members[i].type);
1166 FIXME("Unexpected token %d\n", token);
1172 if (nb_elems && buf->txt && (check_TOKEN(buf) != TOKEN_CBRACE) && (check_TOKEN(buf) != TOKEN_NAME))
1174 token = get_TOKEN(buf);
1175 if ((token != TOKEN_SEMICOLON) && (token != TOKEN_COMMA))
1183 static BOOL parse_object_parts(parse_buffer * buf, BOOL allow_optional)
1185 buf->pxo->nb_childs = 0;
1187 if (!parse_object_members_list(buf))
1192 buf->pxo->size = buf->cur_pos_data - buf->pxo->pos_data;
1194 /* Skip trailing semicolon */
1195 while (check_TOKEN(buf) == TOKEN_SEMICOLON)
1200 if (check_TOKEN(buf) == TOKEN_OBRACE)
1204 if (get_TOKEN(buf) != TOKEN_NAME)
1206 if (get_TOKEN(buf) != TOKEN_CBRACE)
1208 TRACE("Found optional reference %s\n", (char*)buf->value);
1209 for (i = 0; i < (buf->nb_pxo_globals+1); i++)
1211 for (j = 0; j < (buf->pxo_globals[i])[0].nb_subobjects; j++)
1213 if (!strcmp((buf->pxo_globals[i])[j].name, (char*)buf->value))
1218 if (i == (buf->nb_pxo_globals+1))
1220 ERR("Reference to unknown object %s\n", (char*)buf->value);
1224 if (buf->pxo->root->nb_subobjects >= MAX_SUBOBJECTS)
1226 FIXME("Too many sub-objects\n");
1230 buf->pxo->childs[buf->pxo->nb_childs] = &buf->pxo_tab[buf->pxo->root->nb_subobjects++];
1231 buf->pxo->childs[buf->pxo->nb_childs]->ptarget = &(buf->pxo_globals[i])[j];
1232 buf->pxo->childs[buf->pxo->nb_childs]->binary = FALSE;
1233 buf->pxo->nb_childs++;
1235 else if (check_TOKEN(buf) == TOKEN_NAME)
1237 xobject* pxo = buf->pxo;
1239 if (buf->pxo->root->nb_subobjects >= MAX_SUBOBJECTS)
1241 FIXME("Too many sub-objects\n");
1245 buf->pxo = buf->pxo->childs[buf->pxo->nb_childs] = &buf->pxo_tab[buf->pxo->root->nb_subobjects++];
1247 TRACE("Enter optional %s\n", (char*)buf->value);
1249 if (!parse_object(buf))
1256 buf->pxo->nb_childs++;
1263 if (buf->pxo->nb_childs > MAX_CHILDS)
1265 FIXME("Too many childs %d\n", buf->pxo->nb_childs);
1272 BOOL parse_object(parse_buffer * buf)
1276 buf->pxo->pos_data = buf->cur_pos_data;
1277 buf->pxo->ptarget = NULL;
1278 buf->pxo->binary = FALSE;
1279 buf->pxo->root = buf->pxo_tab;
1281 if (get_TOKEN(buf) != TOKEN_NAME)
1284 /* To do template lookup */
1285 for (i = 0; i < buf->pdxf->nb_xtemplates; i++)
1287 if (!strcasecmp((char*)buf->value, buf->pdxf->xtemplates[i].name))
1289 buf->pxt[buf->level] = &buf->pdxf->xtemplates[i];
1290 memcpy(&buf->pxo->type, &buf->pdxf->xtemplates[i].class_id, 16);
1294 if (i == buf->pdxf->nb_xtemplates)
1296 ERR("Unknown template %s\n", (char*)buf->value);
1300 if (check_TOKEN(buf) == TOKEN_NAME)
1303 strcpy(buf->pxo->name, (char*)buf->value);
1306 buf->pxo->name[0] = 0;
1308 if (get_TOKEN(buf) != TOKEN_OBRACE)
1310 if (check_TOKEN(buf) == TOKEN_GUID)
1313 memcpy(&buf->pxo->class_id, buf->value, 16);
1316 memset(&buf->pxo->class_id, 0, 16);
1318 if (!parse_object_parts(buf, TRUE))
1320 if (get_TOKEN(buf) != TOKEN_CBRACE)
1325 /* Go to the next object */
1326 go_to_next_definition(buf);