void elemenlist(SYMPTR lhsp, int first_alternate) { SYMPTR newsym,temprhs[128]; int numrhs = 0; switch (lookahead) { case CHR_LIT: case ID: case SEMI: case BAR: case LPAREN: case RPAREN: case LBRACE: while (lookahead == CHR_LIT || lookahead == ID || lookahead == LPAREN || lookahead == LBRACE) { if (lookahead == CHR_LIT || lookahead == ID ) { temprhs[numrhs++] = Lookup(lexeme); match(lookahead); } else if (lookahead == LBRACE) { numrhs += ParseAction(lhsp, &temprhs[numrhs], numrhs + 1); } else if (lookahead == LPAREN) { newsym = ParseGroup(lhsp, numrhs + 1); temprhs[numrhs++] = newsym; } } RegisterRule(lhsp, numrhs, temprhs, first_alternate); break; default: SyntaxError("bad rhs symbol "); } } /* end of elemenlist*/
void RayScene::ParseJoint(FILE* fp,int& cmndCtr,RayGroup* current){ char paramName[BUF_SIZE]; char keyword[BUF_SIZE]; ParametrizedRayGroup *newNode; RayGroup *currNode; int i,idx=-1; currNode=current; if(!fscanf(fp," %s ",paramName)){ParseLineError(cmndCtr,"failed to read parameter name\n");} for(i=0;i<keyFileNum;i++){ idx=keyFiles[i].index(paramName); if(idx>=0){break;} } newNode=keyData[i].getParametrizedRayGroup(idx); if(!newNode){ParseLineError(cmndCtr,"failed to link joint node to parameter\n");} strcpy(newNode->pName,paramName); currNode->addShape(newNode); currNode=newNode; while(fscanf(fp," #%s",keyword) == 1){ cmndCtr++; if(strcmp(keyword,"group_begin") == 0){ParseGroup(fp,cmndCtr,currNode);} else if(strcmp(keyword,"joint_begin") == 0){ParseJoint(fp,cmndCtr,currNode);} else if(!strcmp(keyword,"joint_end")){return;} else if(!strcmp(keyword,"group_end")){ParseLineError(cmndCtr,"group_end within a joint\n");} else if(ParseShape(fp,keyword,cmndCtr,currNode)){;} else {fprintf(stderr,"Ignoring Command %d: No valid #directive...%s \n",cmndCtr,keyword);} } ParseLineError(cmndCtr,"no group_end\n"); }
void Scene::ParseJoint(FILE* fp,int& cmndCtr,Group* current,const char* fileName){ char keyword[BUF_SIZE]; char parameterName[BUF_SIZE]; ParametrizedGroup *newNode; Group *currNode; int i; Parameter** tempArray; currNode=current; newNode=new ParametrizedGroup(fp,parameterName); if(newNode==NULL){ ParseLineError(cmndCtr,fileName, "failed to allocate memory for ParametrizedGroup\n"); } for(i=0;i<parameterNum;i++){ if(strcmp(parameterName,parameters[i]->name)==0){break;} } if(i==parameterNum){ parameterNum++; tempArray=new Parameter*[parameterNum]; assert(tempArray); for(i=0;i<parameterNum-1;i++){tempArray[i]=parameters[i];} tempArray[parameterNum-1]=new Parameter(); strcpy(tempArray[i]->name,parameterName); tempArray[i]->value=newNode->localTransform.defaultParameterValue(); if(parameterNum>1){delete[] parameters;} parameters=tempArray; newNode->parameter=parameters[parameterNum-1]; } else{newNode->parameter=parameters[i];} currNode->addShape(newNode); currNode=newNode; while(fscanf(fp," #%s",keyword) == 1){ cmndCtr++; if(strcmp(keyword,"group_begin") == 0){ ParseGroup(fp,cmndCtr,currNode,fileName); } else if(strcmp(keyword,"joint_begin") == 0){ ParseJoint(fp,cmndCtr,currNode,fileName); } /* We check if we have come to the end of a scene-graph group and we * do the appropriate pointer manipulation, making sure that we are not * leaving a group we had not begun */ else if(strcmp(keyword,"joint_end") == 0){return;} else if(strcmp(keyword,"group_end")==0){ ParseLineError(cmndCtr,fileName,"group_end within a joint\n"); } else if(ParseShape(fp,keyword,cmndCtr,currNode,fileName)){;} else { fprintf(stderr, "Ignoring Command %d: No valid #directive...%s \n",cmndCtr, keyword); } } ParseLineError(cmndCtr,fileName,"no group_end\n"); }
/* ** Searches for News line until buffer fills up or a CRLF or LF is found */ PRIVATE int HTNewsList_put_block (HTStream * me, const char * b, int l) { while (l-- > 0) { if (me->state == EOL_FCR) { if (*b == LF && me->buflen) { if (!me->junk) { *(me->buffer+me->buflen) = '\0'; me->group ? ParseGroup(me->request, me->dir, me->buffer) : ParseList(me->dir, me->buffer); } else me->junk = NO; /* back to normal */ } me->buflen = 0; me->state = EOL_BEGIN; } else if (*b == CR) { me->state = EOL_FCR; } else if (*b == LF && me->buflen) { if (!me->junk) { *(me->buffer+me->buflen) = '\0'; me->group ? ParseGroup(me->request, me->dir, me->buffer) : ParseList(me->dir, me->buffer); } else me->junk = NO; /* back to normal */ me->buflen = 0; me->state = EOL_BEGIN; } else { *(me->buffer+me->buflen++) = *b; if (me->buflen >= MAX_NEWS_LINE) { HTTRACE(PROT_TRACE, "News Dir.... Line too long - chopped\n"); *(me->buffer+me->buflen) = '\0'; me->group ? ParseGroup(me->request, me->dir, me->buffer) : ParseList(me->dir, me->buffer); me->buflen = 0; me->junk = YES; } } b++; } return HT_OK; }
//-------------------------------------------------------------- //-------------------------------------------------------------- void TaggedFilePathResolver::SetFromJson(const Json::Value& in_json) { std::vector<std::string> supportedLanguages; const Json::Value& languages = in_json["Languages"]; if(languages.isNull() == false) { for(u32 i=0; i<languages.size(); ++i) { supportedLanguages.push_back(languages[i].asString()); } } std::vector<RangeRule> supportedResolutions; const Json::Value& resolutions = in_json["Resolutions"]; if(resolutions.isNull() == false) { for(auto it = resolutions.begin(); it != resolutions.end(); ++it) { Vector2 res = ParseVector2((*it).asString()); RangeRule rule(it.memberName(), res.x * res.y); supportedResolutions.push_back(rule); } } std::vector<RangeRule> supportedAspectRatios; const Json::Value& aspects = in_json["AspectRatios"]; if(aspects.isNull() == false) { for(auto it = aspects.begin(); it != aspects.end(); ++it) { RangeRule rule(it.memberName(), (f32)(*it).asDouble()); supportedAspectRatios.push_back(rule); } } SetTags(supportedLanguages, supportedResolutions, supportedAspectRatios); TagGroup priorityIndices[(u32)TagGroup::k_total]; const Json::Value& priorities = in_json["Priorities"]; if(priorities.isNull() == false) { CS_ASSERT(priorities.size() == (u32)TagGroup::k_total, "TaggedFilePathResolver: Need to specify all groups when setting priorities"); for(u32 i=0; i<priorities.size(); ++i) { priorityIndices[i] = ParseGroup(priorities[i].asString()); } } SetPriority(priorityIndices[0], priorityIndices[1], priorityIndices[2], priorityIndices[3]); }
//------------------------------------------------------ // ParseLength // Takes a length group and chomps out any pairs contained // in it. // // input: // the parse group to process // // return: // success of parse operation. //------------------------------------------------------ bool CPrimitiveTemplate::ParseLength( const CGPGroup& grp ) { static StringViewIMap< ParseMethod > parseMethods{ { CSTRING_VIEW( "start" ), &CPrimitiveTemplate::ParseLengthStart }, { CSTRING_VIEW( "end" ), &CPrimitiveTemplate::ParseLengthEnd }, { CSTRING_VIEW( "parm" ), &CPrimitiveTemplate::ParseLengthParm }, { CSTRING_VIEW( "parms" ), &CPrimitiveTemplate::ParseLengthParm }, { CSTRING_VIEW( "flag" ), &CPrimitiveTemplate::ParseLengthFlags }, { CSTRING_VIEW( "flags" ), &CPrimitiveTemplate::ParseLengthFlags }, }; return ParseGroup( grp, parseMethods, "Length" ); }
/************************************************************************************************ * Parse * parses text data for CParseGroup's until end-of-file is reached * * inputs: * pointer to character data to be parsed, boolean indicating if we should wipe our * stored data before parsing more, boolean indicating if we should make this data * writeable * * return: * nothing ************************************************************************************************/ bool CGenericParser::Parse(char **dataPtr, bool cleanFirst/*true*/, bool writeable /*false*/) { // a quick test to find hand-edit errors that always seem to manifest as perplexing bugs before we find them... { string strBraceTest(*dataPtr); int iOpeningBraces = 0; int iClosingBraces = 0; char *p; while ((p=strchr(strBraceTest.c_str(),'{'))!=NULL) { *p = '#'; // anything that's not a '{' iOpeningBraces++; } while ((p=strchr(strBraceTest.c_str(),'}'))!=NULL) { *p = '#'; // anything that's not a '}' iClosingBraces++; } if (iOpeningBraces != iClosingBraces) { // maybe print something here, but in any case... // return false; } } if (cleanFirst) { // if this is a new stream of data, init some stuff mGroups.Clean(); } mWriteable = writeable; mGroups.SetWriteable(mWriteable); while (ParseGroup(dataPtr)) { ; } return true; }
void RayScene::ParseGroup(FILE* fp,int& cmndCtr,RayGroup* current){ char keyword[BUF_SIZE]; RayGroup *currNode,*newNode; currNode=current; newNode=new StaticRayGroup(); if(!newNode || !((StaticRayGroup*)newNode)->read(fp)){ParseLineError(cmndCtr,"failed to allocate memory for StaticGroup\n");} currNode->addShape(newNode); currNode=newNode; while(fscanf(fp," #%s",keyword) == 1){ cmndCtr++; if(!strcmp(keyword,"group_begin")){ParseGroup(fp,cmndCtr,currNode);} else if(!strcmp(keyword,"joint_begin")){ParseJoint(fp,cmndCtr,currNode);} /* We check if we have come to the end of a scene-graph group and we * do the appropriate pointer manipulation, making sure that we are not * leaving a group we had not begun */ else if(!strcmp(keyword,"group_end")){return;} else if(!strcmp(keyword,"joint_end")){ParseLineError(cmndCtr,"joint_end within a group\n");} else if(ParseShape(fp,keyword,cmndCtr,currNode)){;} else {fprintf(stderr,"Ignoring Command %d: No valid #directive...%s \n",cmndCtr,keyword);} } ParseLineError(cmndCtr,"no group_end\n"); }
ModelData* ModelLoader::LoadModelFile(std::string filePath) { ifstream file; file.open(filePath + ".obj"); if (!file) return 0; string str; while (!file.eof()) { file >> str; if (str == "#" || str == "s") ParseComment(file); else if (str == "v") ParsePosition(file); //position else if (str == "vn") ParseNormal(file); //normal else if (str == "vt") ParseTexCoord(file); //texturkoordinat else if (str == "f") ParseFace(file); //face else if (str == "usemtl") ParseMaterial(file); //material else if (str == "g") ParseGroup(file); //group else if (str == "mtllib") //materialfile { ParseMaterialFile(file, filePath); } str = ""; } //ParseFace2(file); ModelData* model = new ModelData(); for (auto it = m_groups.begin(); it != m_groups.end(); ++it) model->Groups.push_back(it->second); return model; }
bool XSDParser::ParseContent(DTDElement& node, bool extended /*=false*/) { DTDElement::EType curr_type; int emb=0; bool eatEOT= false; bool hasContents= false; TToken tok; for ( tok=GetNextToken(); ; tok=GetNextToken()) { emb= node.GetContent().size(); if (tok != T_EOF && tok != K_ENDOFTAG && tok != K_ANNOTATION) { hasContents= true; } switch (tok) { case T_EOF: return hasContents; case K_ENDOFTAG: if (eatEOT) { eatEOT= false; break; } FixEmbeddedNames(node); return hasContents; case K_COMPLEXTYPE: ParseComplexType(node); break; case K_SIMPLECONTENT: ParseSimpleContent(node); break; case K_EXTENSION: ParseExtension(node); break; case K_RESTRICTION: ParseRestriction(node); break; case K_ATTRIBUTE: ParseAttribute(node); break; case K_ATTRIBUTEGROUP: ParseAttributeGroup(node); break; case K_ANY: node.SetTypeIfUnknown(DTDElement::eSequence); { string name = CreateTmpEmbeddedName(node.GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(name); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eAny); elem.SetQualified(node.IsQualified()); ParseAny(elem); AddElementContent(node,name); } break; case K_SEQUENCE: emb= node.GetContent().size(); if (emb != 0 && extended) { node.SetTypeIfUnknown(DTDElement::eSequence); if (node.GetType() != DTDElement::eSequence) { ParseError("sequence"); } tok = GetRawAttributeSet(); eatEOT = true; break; } curr_type = node.GetType(); if (curr_type == DTDElement::eUnknown || curr_type == DTDElement::eUnknownGroup || (m_ResolveTypes && curr_type == DTDElement::eEmpty)) { node.SetType(DTDElement::eSequence); ParseContainer(node); if (node.GetContent().empty()) { node.ResetType(curr_type); } } else { string name = CreateTmpEmbeddedName(node.GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(name); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eSequence); elem.SetQualified(node.IsQualified()); ParseContainer(elem); AddElementContent(node,name); } break; case K_CHOICE: curr_type = node.GetType(); if (curr_type == DTDElement::eUnknown || curr_type == DTDElement::eUnknownGroup || (m_ResolveTypes && curr_type == DTDElement::eEmpty)) { node.SetType(DTDElement::eChoice); ParseContainer(node); if (node.GetContent().empty()) { node.ResetType(curr_type); } } else { string name = CreateTmpEmbeddedName(node.GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(name); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eChoice); elem.SetQualified(node.IsQualified()); ParseContainer(elem); AddElementContent(node,name); } break; case K_SET: curr_type = node.GetType(); if (curr_type == DTDElement::eUnknown || curr_type == DTDElement::eUnknownGroup || (m_ResolveTypes && curr_type == DTDElement::eEmpty)) { node.SetType(DTDElement::eSet); ParseContainer(node); if (node.GetContent().empty()) { node.ResetType(curr_type); } } else { string name = CreateTmpEmbeddedName(node.GetName(), emb); DTDElement& elem = m_MapElement[name]; elem.SetName(name); elem.SetSourceLine(Lexer().CurrentLine()); elem.SetEmbedded(); elem.SetType(DTDElement::eSet); elem.SetQualified(node.IsQualified()); ParseContainer(elem); AddElementContent(node,name); } break; case K_ELEMENT: { string name = ParseElementContent(&node,emb); AddElementContent(node,name); } break; case K_GROUP: { string name = ParseGroup(&node,emb); AddElementContent(node,name); } break; case K_ANNOTATION: SetCommentsIfEmpty(&(node.Comments())); ParseAnnotation(); break; case K_UNION: ParseUnion(node); break; case K_LIST: ParseList(node); break; default: for ( tok = GetNextToken(); tok == K_ATTPAIR || tok == K_XMLNS; tok = GetNextToken()) ; if (tok == K_CLOSING) { ParseContent(node); } break; } } FixEmbeddedNames(node); return hasContents; }
int RayScene::read(FILE* fp,int transformType){ char keyword[BUF_SIZE]; char keyFileName[BUF_SIZE]; int cmndCtr=0; int backFlag=0, ambFlag=0; int indL=-1, indM=-1, indT=-1,indRF=-1,indV=-1,indK=-1; int temp; int inShapes=0; RayGroup* root; group=new StaticRayGroup(); group->set(Matrix4D::IdentityMatrix()); root=group; lightNum=-1; textureNum=-1; materialNum=-1; rayFileNum=-1; vertexNum=-1; keyFileNum=-1; keyFiles=NULL; keyData=NULL; lights=NULL; textures=NULL; materials=NULL; rayFiles=NULL; vertices=NULL; camera=NULL; while(fscanf(fp," #%s",keyword) == 1){ cmndCtr++; //We try to read out the camera information. We make sure that we have //not begun describing the scene graph yet, and we ignore the camera if //it is the second one specified. if(!strcmp(keyword,"camera")){ if (inShapes!=0){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(camera){ fprintf(stderr,"Parsing Line %d: Ignoring extra camera\n",cmndCtr); } else { camera=new RayCamera; if(!camera){ ParseLineError(cmndCtr,"failed to allocate camera memory\n"); } if(!camera->read(fp)){ ParseLineError(cmndCtr,"failed to parse camera settings\n"); } } } //Next we try to read out the environment information. Again, we make //sure that we have not begun describing the scene graph yet and we //ignore all but the first background color and ambient color //specifications. else if(!strcmp(keyword,"background")){ if(inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(backFlag==1){ fprintf(stderr,"Parsing Line %d: Ignoring extra background\n",cmndCtr); } else { backFlag=1; if(fscanf(fp," %lg %lg %lg", &(background[0]),&(background[1]),&(background[2])) != 3){ ParseLineError(cmndCtr,"failed to parse background settings\n"); } } } else if(!strcmp(keyword,"ambient")){ if(inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(ambFlag==1){ fprintf(stderr,"Parsing Line %d: Ignoring extra ambient\n",cmndCtr); } else { ambFlag=1; if(fscanf(fp," %lg %lg %lg", &(ambient[0]),&(ambient[1]),&(ambient[2])) != 3){ ParseLineError(cmndCtr,"failed to parse ambient settings\n"); } } } else if(!strcmp(keyword,"ambient")){ if(inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(ambFlag==1){ fprintf(stderr,"Parsing Line %d: Ignoring extra ambient\n",cmndCtr); } else { ambFlag=1; if(fscanf(fp," %lg %lg %lg", &(ambient[0]),&(ambient[1]),&(ambient[2])) != 3){ ParseLineError(cmndCtr,"failed to parse ambient settings\n"); } } } //Next we try read out the number of lights. We make sure that we have //not begun describing the scene graph, and we make sure that the number //of lights is only specified once. Once we have a "good" light number //we allocate memory for the lights else if(!strcmp(keyword,"light_num")){ if (inShapes!=0){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(lightNum>-1){ ParseLineError(cmndCtr,"attempted to define light_num more than once\n"); } else{ if (fscanf(fp," %d", &(lightNum)) != 1){ ParseLineError(cmndCtr,"failed to parse num_lights setting\n"); } else{ if(lightNum < 0){ ParseLineError(cmndCtr,"you can't have negative number of lights\n"); } else if(!lightNum){lights=NULL;} else { lights=new RayLight*[lightNum]; if(!lights){ ParseLineError(cmndCtr,"failed to allocate memory Lights\n"); } } } } } //Next we try read out the number of textures. We make sure that we have //not begun describing the scene graph, and we make sure that the number //of textures is only specified once. Once we have a "good" texture number //we allocate memory for the textures. else if(!strcmp(keyword,"texture_num")){ if(inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(textureNum>-1){ ParseLineError(cmndCtr,"attempted to define texture_num more than once\n"); } else{ if(fscanf(fp," %d",&(textureNum)) != 1){ ParseLineError(cmndCtr,"failed to parse num_textures setting\n"); } else{ if(textureNum < 0){ ParseLineError(cmndCtr,"you can't have negative number of textures\n"); } else if(!textureNum){textures=NULL;} else{ textures=new RayTexture[textureNum]; if(!textures){ ParseLineError(cmndCtr,"failed to allocate memory for textures\n"); } } } } } //Next we try read out the number of materials. We make sure that we have //not begun describing the scene graph, and we make sure that the number //of materials is only specified once. Once we have a "good" material //number we allocate memory for the materials. else if(!strcmp(keyword,"material_num")){ if (inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(materialNum>-1){ ParseLineError(cmndCtr,"attempted to define material_num more than once\n"); } else{ if(fscanf(fp," %d",&(materialNum)) != 1){ ParseLineError(cmndCtr,"failed to parse num_materials setting\n"); } else { if(materialNum < 0){ ParseLineError(cmndCtr,"you can't have negative number of materials\n"); } else{ if(materialNum>0){ materials=new RayMaterial[materialNum]; if(!materials){ ParseLineError(cmndCtr,"failed to allocate memory for materials\n"); } } else{materials=NULL;} } } } } //Next we try read out the number of vertices. We make sure that we have //not begun describing the scene graph, and we make sure that the number //of vertices is only specified once. Once we have a "good" vertex //number we allocate memory for the vertices. else if(!strcmp(keyword,"vertex_num")){ if (inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(vertexNum>-1){ ParseLineError(cmndCtr,"attempted to define material_num more than once\n"); } else{ if(fscanf(fp," %d",&(vertexNum)) != 1){ ParseLineError(cmndCtr,"failed to parse num_materials setting\n"); } else { if(vertexNum < 0){ ParseLineError(cmndCtr,"you can't have negative number of materials\n"); } else{ if(vertexNum>0){ vertices=new RayVertex[vertexNum]; if(!vertices){ ParseLineError(cmndCtr,"failed to allocate memory for vertices\n"); } } else{vertices=NULL;} } } } } //Next we try read out the number of ray files. We make sure that we have //not begun describing the scene graph, and we make sure that the number //of ray files is only specified once. Once we have a "good" ray file //number we allocate memory for the ray files. else if(!strcmp(keyword,"ray_file_num")){ if (inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");} if(rayFileNum>-1){ParseLineError(cmndCtr,"attempted to define ray_file_num more than once\n");} else{ if(fscanf(fp," %d",&(rayFileNum)) != 1){ParseLineError(cmndCtr,"failed to parse ray_file_num setting\n");} else { if(rayFileNum<=0){rayFiles=NULL;} else{ rayFiles=new RayFile[rayFileNum]; if(!rayFiles){ParseLineError(cmndCtr,"failed to allocate memory for ray_files\n");} } } } } //Next we try read out the number of key-files. We make sure that we have //not begun describing the scene graph, and we make sure that the number //of key-files is only specified once. Once we have a "good" ray file //number we allocate memory for the ray files. else if(!strcmp(keyword,"key_file_num")){ if (inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");} if(keyFileNum>-1){ParseLineError(cmndCtr,"attempted to define key_file_num more than once\n");} else{ if(fscanf(fp," %d",&(keyFileNum)) != 1){ParseLineError(cmndCtr,"failed to parse key_file_num setting\n");} else { if(keyFileNum<=0){ keyFiles=NULL; keyData=NULL; } else{ keyFiles=new RayKeyFile[keyFileNum]; keyData=new RayKeyData[keyFileNum]; if(!keyFiles || !keyData){ParseLineError(cmndCtr,"failed to allocate memory for key_files\n");} } } } } //Next we try read out the next textures. We make sure that we have //not begun describing the scene graph. We make sure that we are not //adding more textures then we promised and we make sure that all the //file I/O works as it should. else if(!strcmp(keyword,"texture")){ if(inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(textureNum == -1){ ParseLineError(cmndCtr,"attempted to define texture before texture_num\n"); } indT++; if(indT == textureNum){ ParseLineError(cmndCtr,"attempted to define more textures than declared\n"); } if(!textures[indT].read(fp)){ ParseLineError(cmndCtr,"failed to generate texture\n"); } textures[indT].index=indT; } //Next we try read out the next material. We make sure that we have //not begun describing the scene graph. We make sure that we are not //adding more materials then we promised. else if(!strcmp(keyword,"material")){ if(inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(materialNum==-1){ ParseLineError(cmndCtr,"attempted to define materials before material_num\n"); } indM++; if(indM == materialNum){ ParseLineError(cmndCtr,"attempted to define more materials than declared\n"); } else{ if(!materials[indM].read(fp,temp)){ ParseLineError(cmndCtr,"failed to parse material\n"); } else{ if(temp==-1){materials[indM].tex=NULL;} else{ if(temp >= textureNum){ ParseLineError(cmndCtr, "material specifies a texture out of texture_num bounds (make sure texture_num comes before material_num) \n"); } materials[indM].tex=&(textures[temp]); } materials[indM].index=indM; } } } //Next we try read out the next vertex. We make sure that we have //not begun describing the scene graph. We make sure that we are not //adding more vertices then we promised. else if(!strcmp(keyword,"vertex")){ if(inShapes){ ParseLineError(cmndCtr,"not a valid directive within a group\n"); } if(vertexNum==-1){ ParseLineError(cmndCtr,"attempted to define vertices before vertex_num\n"); } indV++; if(indV == vertexNum){ ParseLineError(cmndCtr,"attempted to define more vertices than declared\n"); } else{ if(!vertices[indV].read(fp)){ ParseLineError(cmndCtr,"failed to parse vertices\n"); } else{vertices[indV].index=indV;} } } //Next we try to read out the next rayFile else if(!strcmp(keyword,"ray_file")){ if(inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");} if(rayFileNum==-1){ParseLineError(cmndCtr,"attempted to define ray_files before ray_file_num\n");} indRF++; if(indRF == rayFileNum){ParseLineError(cmndCtr,"attempted to define more ray_files than declared\n");} else{ if(!rayFiles[indRF].read(fp,transformType)){ParseLineError(cmndCtr,"failed to parse ray_file\n");} rayFiles[indRF].index=indRF; } } //Next we try read out the next light. We make sure that we have //not begun describing the scene graph. We make sure that we are not //adding more materials then we promised. else if(!strcmp(keyword,"light_point") || !strcmp(keyword,"light_dir") || !strcmp(keyword,"light_spot")){ if(inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");} if(lightNum==-1){ParseLineError(cmndCtr,"attempted to define lights before light_num\n");} indL++; if(indL == lightNum){ParseLineError(cmndCtr,"attempted to define more lights than light_num\n");} else{ if(!strcmp(keyword,"light_point")){lights[indL]=new RayPointLight;} else if(!strcmp(keyword,"light_dir")){lights[indL]=new RayDirectionalLight;} else if(!strcmp(keyword,"light_spot")){lights[indL]=new RaySpotLight;} if(!lights[indL]){ParseLineError(cmndCtr,"failed to allocate memory for light\n");} if(!lights[indL]->read(fp)){ParseLineError(cmndCtr,"failed to parse light\n");} } } //Next we try to read out the .key file. We make sure that we have not //begun describing the scene graph. else if(!strcmp(keyword,"key_file")){ if(inShapes){ParseLineError(cmndCtr,"not a valid directive within a group\n");} if(keyFileNum==-1){ParseLineError(cmndCtr,"attempted to define key_files before key_file_num\n");} indK++; if(indK == keyFileNum){ParseLineError(cmndCtr,"attempted to define more key_files than key_file_num\n");} fscanf(fp," %s",keyFileName); if(!keyFiles[indK].read(keyFileName)){ParseLineError(cmndCtr,"failed to read in key_file\n");} if(!keyData[indK].set(keyFiles[indK],transformType)){ParseLineError(cmndCtr,"failed to set key file data\n");} keyData[indK].setCurrentValue(0); } //Next we try read out the scene graph information, obtaining the //transform and either creating a new scene graph or adding a node //to the existing one. else if(!strcmp(keyword,"group_begin")){ inShapes=1; ParseGroup(fp,cmndCtr,root); } else if(!strcmp(keyword,"joint_begin")){ inShapes=1; ParseJoint(fp,cmndCtr,root); } //We check if we have come to the end of a scene-graph group. If we have //this is bad because we have not yet opened one else if(!strcmp(keyword,"group_end")){ ParseLineError(cmndCtr,"closed more groups then began\n"); } else if(!strcmp(keyword,"joint_end")){ ParseLineError(cmndCtr,"closed more joints then began\n"); } else if(ParseShape(fp,keyword,cmndCtr,root)){inShapes=1;} else{ fprintf(stderr, "Ignoring Command %d: No valid #directive...%s \n",cmndCtr, keyword); } } if(indL<(lightNum-1)){ParseError("Couldn't find enough lights for light_num");} if(indM<(materialNum-1)){ParseError("Couldn't find enough materials for material_num");} if(indT<(textureNum-1)){ParseError("Couldn't find enough textures for texture_num");} if(indRF<(rayFileNum-1)){ParseError("Couldn't find enough ray_files for ray_file_num");} if(lightNum==-1){lightNum=0;} if(materialNum==-1){materialNum=0;} if(textureNum==-1){textureNum=0;} if(rayFileNum==-1){rayFileNum=0;} if(vertexNum==-1){vertexNum=0;} return 1; }
/** Parse a token list. */ void Parse(const TokenNode *start, int depth) { TokenNode *tp; if(!start) { return; } if(JLIKELY(start->type == TOK_JWM)) { for(tp = start->subnodeHead; tp; tp = tp->next) { if(shouldReload) { switch(tp->type) { case TOK_ROOTMENU: ParseRootMenu(tp); break; case TOK_INCLUDE: ParseInclude(tp, depth); break; default: break; } } else { switch(tp->type) { case TOK_DESKTOPS: ParseDesktops(tp); break; case TOK_DOUBLECLICKSPEED: settings.doubleClickSpeed = ParseUnsigned(tp, tp->value); break; case TOK_DOUBLECLICKDELTA: settings.doubleClickDelta = ParseUnsigned(tp, tp->value); break; case TOK_FOCUSMODEL: ParseFocusModel(tp); break; case TOK_GROUP: ParseGroup(tp); break; case TOK_ICONPATH: AddIconPath(tp->value); break; case TOK_INCLUDE: ParseInclude(tp, depth); break; case TOK_KEY: ParseKey(tp); break; case TOK_MENUSTYLE: ParseMenuStyle(tp); break; case TOK_MOVEMODE: ParseMoveMode(tp); break; case TOK_PAGERSTYLE: ParsePagerStyle(tp); break; case TOK_POPUPSTYLE: ParsePopupStyle(tp); break; case TOK_RESIZEMODE: ParseResizeMode(tp); break; case TOK_RESTARTCOMMAND: AddRestartCommand(tp->value); break; case TOK_ROOTMENU: ParseRootMenu(tp); break; case TOK_SHUTDOWNCOMMAND: AddShutdownCommand(tp->value); break; case TOK_SNAPMODE: ParseSnapMode(tp); break; case TOK_STARTUPCOMMAND: AddStartupCommand(tp->value); break; case TOK_TASKLISTSTYLE: ParseTaskListStyle(tp); break; case TOK_TRAY: ParseTray(tp); break; case TOK_TRAYSTYLE: ParseTrayStyle(tp); break; case TOK_TRAYBUTTONSTYLE: ParseTrayButtonStyle(tp); break; case TOK_CLOCKSTYLE: ParseClockStyle(tp); break; case TOK_WINDOWSTYLE: ParseWindowStyle(tp); break; case TOK_BUTTONCLOSE: SetBorderIcon(BI_CLOSE, tp->value); break; case TOK_BUTTONMAX: SetBorderIcon(BI_MAX, tp->value); break; case TOK_BUTTONMAXACTIVE: SetBorderIcon(BI_MAX_ACTIVE, tp->value); break; case TOK_BUTTONMIN: SetBorderIcon(BI_MIN, tp->value); break; default: InvalidTag(tp, TOK_JWM); break; } } } } else { ParseError(start, "invalid start tag: %s", GetTokenName(start)); } }
/************************************************************************************************ * ParseGroup * recursively parses a text string using a nested-block format. basically parses a pair of * tokens at once, if possible. * * inputs: * pointer to character data to be parsed * * return: * true if a group is parsed, false if end-of-file ************************************************************************************************/ bool CGenericParser::ParseGroup(char **dataPtr) { string tok1; string tok2; while (1) { tok1 = GetToken(dataPtr); if (tok1.empty()) { // reached end of data return false; } if ('}' == tok1[0]) { // ending a ParseGroup mCurGroup = mCurGroup->GetParent(); return true; } tok2 = GetToken(dataPtr); if (tok2.empty()) { // empty group or a key-value pair with no value, just a key } else if ('{' == tok2[0]) { // we're starting a new CParseGroup and its name is currently in tok1 CParseGroup *newGroup = new CParseGroup(tok1, mCurGroup, mWriteable); if (NULL == mCurGroup) { // this is a top level group so add it to the parser's list mGroups.AddSubGroup(newGroup); mCurGroup = newGroup; } else { // this is somebody's subgroup mCurGroup->AddSubGroup(newGroup); // time for some ol' fashioned, down-home recursion. yeehaw! mCurGroup = newGroup; ParseGroup(dataPtr); } } else if ('}' == tok2[0]) { // error. try to recover. ReturnToBraceDepthZero(dataPtr); } else { if (mCurGroup == 0) { // assume we're adding a key/value pair at the file level mGroups.AddPair(tok1, tok2); } else { // we're considering tok1 as a key and tok2 as a value mCurGroup->AddPair(tok1, tok2); } } } }