31 #include <system_threads.h>
35 #include <libFreeWRL.h>
37 #include "../vrml_parser/Structs.h"
38 #include "../main/headers.h"
39 #include "CParseGeneral.h"
40 #include "../scenegraph/Vector.h"
41 #include "../vrml_parser/CFieldDecls.h"
42 #include "CParseParser.h"
43 #include "CParseLexer.h"
54 void *CParse_constructor(){
55 void *v = MALLOCV(
sizeof(
struct pCParse));
56 memset(v,0,
sizeof(
struct pCParse));
59 void CParse_init(
struct tCParse *t){
61 t->globalParser = NULL;
63 t->prv = CParse_constructor();
69 void CParse_clear(
struct tCParse *t){
74 FREE_IF_NZ(globalParser->lexer);
75 FREE_IF_NZ(t->globalParser);
82 BOOL cParse(
void *ectx,
void* ptr,
unsigned ofs,
const char* data) {
88 startt = Time1970sec();
90 if (!tg->CParse.globalParser) {
93 parser=newParser(ectx, ptr, ofs, FALSE);
94 tg->CParse.globalParser = (
void *)parser;
97 parser=reuseParser(ectx, ptr,ofs);
100 resetParseSuccessfullyFlag();
102 parser_fromString(parser, (
char *) data);
103 ASSERT(parser->lexer);
105 if(!parser_vrmlScene(parser)) {
106 #define CHARS_TO_RETURN_ERROR_END 200
107 char finalChars[CHARS_TO_RETURN_ERROR_END];
109 if (strlen(parser->lexer->nextIn) >= (CHARS_TO_RETURN_ERROR_END-10)) {
110 strncpy(finalChars,parser->lexer->nextIn, CHARS_TO_RETURN_ERROR_END-10);
111 finalChars[CHARS_TO_RETURN_ERROR_END-10] =
'.';
112 finalChars[CHARS_TO_RETURN_ERROR_END-9] =
'.';
113 finalChars[CHARS_TO_RETURN_ERROR_END-8] =
'.';
114 finalChars[CHARS_TO_RETURN_ERROR_END-7] =
'.';
116 strcpy (finalChars,parser->lexer->nextIn);
119 ConsoleMessage (
"Parsing complete, but have unrecognized data at end of input:\"%s\"",finalChars);
126 lexer_forceStringCleanup(parser->lexer);
129 endt = Time1970sec();
130 printf (
"time taken %lf\n",endt-startt);
133 return parsedSuccessfully();
140 struct X3D_Node* parser_getNodeFromName(
const char* name)
146 if (globalParser == NULL)
return NULL;
148 ind=lexer_nodeName2id(globalParser->lexer, name);
149 if(ind==ID_UNDEFINED)
152 ASSERT(!stack_empty(globalParser->DEFedNodes));
153 ASSERT(ind<vectorSize(stack_top(
struct Vector*, globalParser->DEFedNodes)));
155 stack_top(
struct Vector*, globalParser->DEFedNodes), ind);
160 char* parser_getPROTONameFromNode(
struct X3D_Node *node)
163 if(node->_nodeType == NODE_Proto){
164 cpd = getVRMLbrotoDefinition(X3D_PROTO(node));
165 if (cpd != NULL)
return cpd->protoName;
172 char *broto_getNameFromNode(
struct X3D_Node* node);
174 char* parser_getNameFromNode(
struct X3D_Node *node)
176 return broto_getNameFromNode(node);
181 void fw_assert (
char *file,
int line) {
183 printf (
"FreeWRL Internal Error at line %d in %s\n",line,file);
184 ConsoleMessage (
"FreeWRL Internal Error at line %d in %s",line,file);
186 for (looper=1; looper<60; looper++) {
190 printf (
"FreeWRL exiting...\n");