static qboolean demoEffectParsePoint( BG_XMLParse_t *parse,const struct BG_XMLParseBlock_s *fromBlock, void *data) { demoEffectParent_t *parent; demoEffectPoint_t *point; parseEffectPoint_t pointLoad; static BG_XMLParseBlock_t scriptParseBlock[] = { {"time", 0, demoEffectParsePointTime}, {"origin", 0, demoEffectParsePointOrigin}, {"angles", 0, demoEffectParsePointAngles}, {"color", 0, demoEffectParsePointColor}, {"size", 0, demoEffectParsePointSize}, {0, 0, 0} }; memset( &pointLoad, 0, sizeof( pointLoad )); if (!BG_XMLParse( parse, fromBlock, scriptParseBlock, &pointLoad )) { return qfalse; } parent = (demoEffectParent_t *)data; point = demoEffectPointAdd( parent, pointLoad.time ); if (!point) return qfalse; VectorCopy( pointLoad.angles, point->angles ); VectorCopy( pointLoad.origin, point->origin ); Vector4Copy( pointLoad.color, point->color ); point->flags = pointLoad.flags; return qtrue; }
static qboolean demoEffectParse( BG_XMLParse_t *parse, const struct BG_XMLParseBlock_s *fromBlock, void *data) { static BG_XMLParseBlock_t scriptParseBlock[] = { {"parent", demoEffectParsePoint, 0}, {0, 0, 0} }; if (!BG_XMLParse( parse, fromBlock, scriptParseBlock, data )) return qfalse; return qtrue; }
qboolean chaseParse( BG_XMLParse_t *parse, const struct BG_XMLParseBlock_s *fromBlock, void *data) { static BG_XMLParseBlock_t chaseParseBlock[] = { {"point", chaseParsePoint, 0}, {"locked", 0, chaseParseLocked}, {0, 0, 0} }; chaseClear(); if (!BG_XMLParse( parse, fromBlock, chaseParseBlock, data )) return qfalse; return qtrue; }
static qboolean chaseParsePoint( BG_XMLParse_t *parse,const struct BG_XMLParseBlock_s *fromBlock, void *data) { parseChasePoint_t pointLoad; static BG_XMLParseBlock_t chaseParseBlock[] = { {"origin", 0, chaseParseOrigin}, {"angles", 0, chaseParseAngles}, {"time", 0, chaseParseTime}, {"distance", 0, chaseParseDistance}, {"target", 0, chaseParseTarget}, {0, 0, 0} }; memset( &pointLoad, 0, sizeof( pointLoad )); if (!BG_XMLParse( parse, fromBlock, chaseParseBlock, &pointLoad )) { return qfalse; } if (!pointLoad.hasOrigin || !pointLoad.hasAngles || !pointLoad.hasTime || !pointLoad.hasDistance || !pointLoad.hasTarget ) return BG_XMLError(parse, "Missing section in chase point"); chasePointAdd( pointLoad.time, pointLoad.angles, pointLoad.distance, pointLoad.target, pointLoad.origin ); return qtrue; }
static qboolean demoEffectParseParent( BG_XMLParse_t *parse, const struct BG_XMLParseBlock_s *fromBlock, void *data) { demoEffectParent_t *parent; static BG_XMLParseBlock_t scriptParseBlock[] = { {"point", demoEffectParsePoint, 0}, {"origin", 0, demoEffectParseParentOrigin}, {"angles", 0, demoEffectParseParentAngles}, {"color", 0, demoEffectParseParentColor}, {"size", 0, demoEffectParseParentSize}, {"script", 0, demoEffectParseParentScript}, {"shader", 0, demoEffectParseParentShader}, {"model", 0, demoEffectParseParentModel}, {0, 0, 0} }; parent = demoEffectParentCreate(); if (!parent) return BG_XMLError( parse, "Can't allocate parent" ); data = parent; if (!BG_XMLParse( parse, fromBlock, scriptParseBlock, data )) return qfalse; return qtrue; }
qboolean BG_XMLParse( BG_XMLParse_t *parse, const BG_XMLParseBlock_t *fromBlock, const BG_XMLParseBlock_t *parseBlock, void *data ) { char tagName[128]; char line[1024]; char c; int index; qboolean readTag, closeTag; const BG_XMLParseBlock_t *blockScan; readTag = qfalse; parse->depth++; index = 0; while ( parse->filePos < parse->fileSize ) { parse->filePos++; trap_FS_Read( &c, 1, parse->fileHandle ); if ( readTag ) { if (c == '/') { if (!index) closeTag = qtrue; else return BG_XMLError(parse, "/ in tag"); } else if (c == '>') { if (!index) return BG_XMLError(parse, "empty tag"); tagName[index] = 0; if ( closeTag ) { if (!fromBlock || Q_stricmp( tagName, fromBlock->tagName)) return BG_XMLError(parse, "Unmatched close tag %s", tagName ); return qtrue; } index = 0; readTag = qfalse; blockScan = parseBlock; while (blockScan) { if (!blockScan->tagName) { blockScan = 0; break; } if (!Q_stricmp(blockScan->tagName, tagName)) { if (blockScan->openHandler) { if (!blockScan->openHandler( parse, blockScan, data)) return qfalse; } else { if (!BG_XMLParse( parse, blockScan, 0, data)) return qfalse; } break; } blockScan++; } if (!blockScan) { BG_XMLParseBlock_t block; /* Handle unrecognized blocks with a temp handler */ block.tagName = tagName; block.openHandler = 0; block.textHandler = 0; // Com_Printf("XML unrecognized tag %s, line %d\n", tagName, parse->line ); if (!BG_XMLParse( parse, &block, 0, 0)) return qfalse; } } else if (c == ' ' || c == '\t' || c =='\r') { } else if (c =='\n' ) { parse->line++; } else { if (index >= sizeof( tagName)-1) return BG_XMLError(parse, "tag too long" ); tagName[index++] = c; } } else { if (c == '<') { line[index] = 0; if (fromBlock && fromBlock->textHandler) { if ( !index ) BG_XMLWarning( parse, "Empty line for tag %s", fromBlock->tagName ); else if (!fromBlock->textHandler( parse, line, data )) return qfalse; } readTag = qtrue; closeTag = qfalse; index = 0; } else if (c) { if (c == '\n') parse->line++; if (index >= sizeof(line)-1) return BG_XMLError(parse, "line too long" ); line[index++] = c; } } continue; } if (!fromBlock) { trap_FS_FCloseFile( parse->fileHandle ); } return qtrue; };