// ParseFunction //------------------------------------------------------------------------------ /*virtual*/ bool Function::ParseFunction( NodeGraph & nodeGraph, const BFFIterator & functionNameStart, const BFFIterator * functionBodyStartToken, const BFFIterator * functionBodyStopToken, const BFFIterator * functionHeaderStartToken, const BFFIterator * functionHeaderStopToken ) const { m_AliasForFunction.Clear(); if ( AcceptsHeader() && functionHeaderStartToken && functionHeaderStopToken && ( functionHeaderStartToken->GetDistTo( *functionHeaderStopToken ) > 1 ) ) { // find opening quote BFFIterator start( *functionHeaderStartToken ); ASSERT( *start == BFFParser::BFF_FUNCTION_ARGS_OPEN ); start++; start.SkipWhiteSpace(); const char c = *start; if ( ( c != '"' ) && ( c != '\'' ) ) { Error::Error_1001_MissingStringStartToken( start, this ); return false; } BFFIterator stop( start ); stop.SkipString( c ); ASSERT( stop.GetCurrent() <= functionHeaderStopToken->GetCurrent() ); // should not be in this function if strings are not validly terminated if ( start.GetDistTo( stop ) <= 1 ) { Error::Error_1003_EmptyStringNotAllowedInHeader( start, this ); return false; } // store alias name for use in Commit start++; // skip past opening quote if ( BFFParser::PerformVariableSubstitutions( start, stop, m_AliasForFunction ) == false ) { return false; // substitution will have emitted an error } } // parse the function body BFFParser subParser( nodeGraph ); BFFIterator subIter( *functionBodyStartToken ); subIter++; // skip past opening body token subIter.SetMax( functionBodyStopToken->GetCurrent() ); // cap parsing to body end if ( subParser.Parse( subIter ) == false ) { return false; } // complete the function return Commit( nodeGraph, functionNameStart ); }
void SkinParser::handleBeginElement( const string &rName, AttrList_t &attr ) { #define RequireAttr( attr, name, a ) \ if( MissingAttr( attr, name, a ) ) return; if( rName == "Include" ) { RequireAttr( attr, rName, "file" ); OSFactory *pFactory = OSFactory::instance( getIntf() ); string fullPath = m_path + pFactory->getDirSeparator() + attr["file"]; msg_Dbg( getIntf(), "opening included XML file: %s", fullPath.c_str() ); SkinParser subParser( getIntf(), fullPath.c_str(), m_path, m_pData ); subParser.parse(); } else if( rName == "IniFile" ) { RequireAttr( attr, rName, "id" ); RequireAttr( attr, rName, "file" ); const BuilderData::IniFile iniFile( uniqueId( attr["id"] ), attr["file"] ); m_pData->m_listIniFile.push_back( iniFile ); } else if( rName == "Anchor" ) { RequireAttr( attr, rName, "priority" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "points", "(0,0)" ); DefaultAttr( attr, "range", "10" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); const BuilderData::Anchor anchor( x + m_xOffset, y + m_yOffset, attr["lefttop"], atoi( attr["range"] ), atoi( attr["priority"] ), attr["points"], m_curLayoutId ); m_pData->m_listAnchor.push_back( anchor ); } else if( rName == "Bitmap" ) { RequireAttr( attr, rName, "id" ); RequireAttr( attr, rName, "file" ); RequireAttr( attr, rName, "alphacolor" ); DefaultAttr( attr, "nbframes", "1" ); DefaultAttr( attr, "fps", "4" ); DefaultAttr( attr, "loop", "0" ); m_curBitmapId = uniqueId( attr["id"] ); const BuilderData::Bitmap bitmap( m_curBitmapId, attr["file"], convertColor( attr["alphacolor"] ), atoi( attr["nbframes"] ), atoi( attr["fps"] ), atoi( attr["loop"] ) ); m_pData->m_listBitmap.push_back( bitmap ); } else if( rName == "SubBitmap" ) { RequireAttr( attr, rName, "id" ); RequireAttr( attr, rName, "x" ); RequireAttr( attr, rName, "y" ); RequireAttr( attr, rName, "width" ); RequireAttr( attr, rName, "height" ); DefaultAttr( attr, "nbframes", "1" ); DefaultAttr( attr, "fps", "4" ); DefaultAttr( attr, "loop", "0" ); const BuilderData::SubBitmap bitmap( uniqueId( attr["id"] ), m_curBitmapId, atoi( attr["x"] ), atoi( attr["y"] ), atoi( attr["width"] ), atoi( attr["height"] ), atoi( attr["nbframes"] ), atoi( attr["fps"] ), atoi( attr["loop"] ) ); m_pData->m_listSubBitmap.push_back( bitmap ); } else if( rName == "BitmapFont" ) { RequireAttr( attr, rName, "id" ); RequireAttr( attr, rName, "file" ); DefaultAttr( attr, "type", "digits" ); const BuilderData::BitmapFont font( uniqueId( attr["id"] ), attr["file"], attr["type"] ); m_pData->m_listBitmapFont.push_back( font ); } else if( rName == "PopupMenu" ) { RequireAttr( attr, rName, "id" ); m_popupPosList.push_back(0); m_curPopupId = uniqueId( attr["id"] ); const BuilderData::PopupMenu popup( m_curPopupId ); m_pData->m_listPopupMenu.push_back( popup ); } else if( rName == "MenuItem" ) { RequireAttr( attr, rName, "label" ); DefaultAttr( attr, "action", "none" ); const BuilderData::MenuItem item( attr["label"], attr["action"], m_popupPosList.back(), m_curPopupId ); m_pData->m_listMenuItem.push_back( item ); m_popupPosList.back()++; } else if( rName == "MenuSeparator" ) { const BuilderData::MenuSeparator sep( m_popupPosList.back(), m_curPopupId ); m_pData->m_listMenuSeparator.push_back( sep ); m_popupPosList.back()++; } else if( rName == "Button" ) { RequireAttr( attr, rName, "up" ); DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "down", "none" ); DefaultAttr( attr, "over", "none" ); DefaultAttr( attr, "action", "none" ); DefaultAttr( attr, "tooltiptext", "" ); DefaultAttr( attr, "help", "" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); const BuilderData::Button button( uniqueId( attr["id"] ), x + m_xOffset, y + m_yOffset, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), attr["visible"], attr["up"], attr["down"], attr["over"], attr["action"], attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listButton.push_back( button ); } else if( rName == "Checkbox" ) { RequireAttr( attr, rName, "up1" ); RequireAttr( attr, rName, "up2" ); RequireAttr( attr, rName, "state" ); DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "down1", "none" ); DefaultAttr( attr, "over1", "none" ); DefaultAttr( attr, "down2", "none" ); DefaultAttr( attr, "over2", "none" ); DefaultAttr( attr, "action1", "none" ); DefaultAttr( attr, "action2", "none" ); DefaultAttr( attr, "tooltiptext1", "" ); DefaultAttr( attr, "tooltiptext2", "" ); DefaultAttr( attr, "help", "" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); const BuilderData::Checkbox checkbox( uniqueId( attr["id"] ), x + m_xOffset, y + m_yOffset, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), attr["visible"], attr["up1"], attr["down1"], attr["over1"], attr["up2"], attr["down2"], attr["over2"], attr["state"], attr["action1"], attr["action2"], attr["tooltiptext1"], attr["tooltiptext2"], attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listCheckbox.push_back( checkbox ); } else if( rName == "Font" ) { RequireAttr( attr, rName, "id" ); RequireAttr( attr, rName, "file" ); DefaultAttr( attr, "size", "12" ); const BuilderData::Font fontData( uniqueId( attr["id"] ), attr["file"], atoi( attr["size"] ) ); m_pData->m_listFont.push_back( fontData ); } else if( rName == "Group" ) { DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); m_xOffset += atoi( attr["x"] ); m_yOffset += atoi( attr["y"] ); m_xOffsetList.push_back( atoi( attr["x"] ) ); m_yOffsetList.push_back( atoi( attr["y"] ) ); } else if( rName == "Image" ) { RequireAttr( attr, rName, "image" ); DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "width", "-1" ); DefaultAttr( attr, "height", "-1" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "action", "none" ); DefaultAttr( attr, "action2", "none" ); DefaultAttr( attr, "resize", "mosaic" ); DefaultAttr( attr, "help", "" ); DefaultAttr( attr, "art", "false" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); int width = getDimension( attr["width"], refWidth ); int height = getDimension( attr["height"], refHeight ); const BuilderData::Image imageData( uniqueId( attr["id"] ), x + m_xOffset, y + m_yOffset, width, height, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), attr["visible"], attr["image"], attr["action"], attr["action2"], attr["resize"], attr["help"], convertBoolean( attr["art"] ), m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listImage.push_back( imageData ); } else if( rName == "Layout" ) { RequireAttr( attr, rName, "width" ); RequireAttr( attr, rName, "height" ); DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "minwidth", "-1" ); DefaultAttr( attr, "maxwidth", "-1" ); DefaultAttr( attr, "minheight", "-1" ); DefaultAttr( attr, "maxheight", "-1" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, true ); int width = getDimension( attr["width"], refWidth ); int height = getDimension( attr["height"], refHeight ); m_curLayoutId = uniqueId( attr["id"] ); const BuilderData::Layout layout( m_curLayoutId, width, height, getDimension( attr["minwidth"], refWidth ), getDimension( attr["maxwidth"], refWidth ), getDimension( attr["minheight"], refHeight ), getDimension( attr["maxheight"], refHeight ), m_curWindowId ); updateWindowPos( width, height ); m_pData->m_listLayout.push_back( layout ); m_curLayer = 0; } else if( rName == "Panel" ) { DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); RequireAttr( attr, rName, "width" ); RequireAttr( attr, rName, "height" ); DefaultAttr( attr, "position", "-1" ); DefaultAttr( attr, "xoffset", "0" ); DefaultAttr( attr, "yoffset", "0" ); DefaultAttr( attr, "xmargin", "0" ); DefaultAttr( attr, "ymargin", "0" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); int width = getDimension( attr["width"], refWidth ); int height = getDimension( attr["height"], refHeight ); convertPosition( attr["position"], attr["xoffset"], attr["yoffset"], attr["xmargin"], attr["ymargin"], width, height, refWidth, refHeight, &x, &y ); string panelId = uniqueId( "none" ); const BuilderData::Panel panel( panelId, x + m_xOffset, y + m_yOffset, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), width, height, m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listPanel.push_back( panel ); // Add the panel to the stack m_panelStack.push_back( panelId ); } else if( rName == "Playlist" ) { RequireAttr( attr, rName, "id" ); RequireAttr( attr, rName, "font" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "flat", "true" ); // Only difference here DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "width", "0" ); DefaultAttr( attr, "height", "0" ); DefaultAttr( attr, "position", "-1" ); DefaultAttr( attr, "xoffset", "0" ); DefaultAttr( attr, "yoffset", "0" ); DefaultAttr( attr, "xmargin", "0" ); DefaultAttr( attr, "ymargin", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "bgimage", "none" ); DefaultAttr( attr, "itemimage", "none" ); DefaultAttr( attr, "openimage", "none" ); DefaultAttr( attr, "closedimage", "none" ); DefaultAttr( attr, "fgcolor", "#000000" ); DefaultAttr( attr, "playcolor", "#FF0000" ); DefaultAttr( attr, "bgcolor1", "#FFFFFF" ); DefaultAttr( attr, "bgcolor2", "#FFFFFF" ); DefaultAttr( attr, "selcolor", "#0000FF" ); DefaultAttr( attr, "help", "" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); int width = getDimension( attr["width"], refWidth ); int height = getDimension( attr["height"], refHeight ); convertPosition( attr["position"], attr["xoffset"], attr["yoffset"], attr["xmargin"], attr["ymargin"], width, height, refWidth, refHeight, &x, &y ); m_curTreeId = uniqueId( attr["id"] ); const BuilderData::Tree treeData( m_curTreeId, x + m_xOffset, y + m_yOffset, attr["visible"], attr["flat"], width, height, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), attr["font"], "playtree", attr["bgimage"], attr["itemimage"], attr["openimage"], attr["closedimage"], attr["fgcolor"], attr["playcolor"], attr["bgcolor1"], attr["bgcolor2"], attr["selcolor"], attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listTree.push_back( treeData ); } else if( rName == "Playtree" ) { RequireAttr( attr, rName, "id" ); RequireAttr( attr, rName, "font" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "flat", "false" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "width", "0" ); DefaultAttr( attr, "height", "0" ); DefaultAttr( attr, "position", "-1" ); DefaultAttr( attr, "xoffset", "0" ); DefaultAttr( attr, "yoffset", "0" ); DefaultAttr( attr, "xmargin", "0" ); DefaultAttr( attr, "ymargin", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "bgimage", "none" ); DefaultAttr( attr, "itemimage", "none" ); DefaultAttr( attr, "openimage", "none" ); DefaultAttr( attr, "closedimage", "none" ); DefaultAttr( attr, "fgcolor", "#000000" ); DefaultAttr( attr, "playcolor", "#FF0000" ); DefaultAttr( attr, "bgcolor1", "#FFFFFF" ); DefaultAttr( attr, "bgcolor2", "#FFFFFF" ); DefaultAttr( attr, "selcolor", "#0000FF" ); DefaultAttr( attr, "help", "" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); int width = getDimension( attr["width"], refWidth ); int height = getDimension( attr["height"], refHeight ); convertPosition( attr["position"], attr["xoffset"], attr["yoffset"], attr["xmargin"], attr["ymargin"], width, height, refWidth, refHeight, &x, &y ); m_curTreeId = uniqueId( attr["id"] ); const BuilderData::Tree treeData( m_curTreeId, x + m_xOffset, y + m_yOffset, attr["visible"], attr["flat"], width, height, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), attr["font"], "playtree", attr["bgimage"], attr["itemimage"], attr["openimage"], attr["closedimage"], attr["fgcolor"], attr["playcolor"], attr["bgcolor1"], attr["bgcolor2"], attr["selcolor"], attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listTree.push_back( treeData ); } else if( rName == "RadialSlider" ) { RequireAttr( attr, rName, "sequence" ); RequireAttr( attr, rName, "nbimages" ); DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "minangle", "0" ); DefaultAttr( attr, "maxangle", "360" ); DefaultAttr( attr, "value", "none" ); DefaultAttr( attr, "tooltiptext", "" ); DefaultAttr( attr, "help", "" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); const BuilderData::RadialSlider radial( uniqueId( attr["id"] ), attr["visible"], x + m_xOffset, y + m_yOffset, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), attr["sequence"], atoi( attr["nbimages"] ), atof( attr["minangle"] ) * M_PI /180, atof( attr["maxangle"] ) * M_PI / 180, attr["value"], attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listRadialSlider.push_back( radial ); } else if( rName == "Slider" ) { RequireAttr( attr, rName, "up" ); RequireAttr( attr, rName, "points" ); DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "width", "-1" ); DefaultAttr( attr, "height", "-1" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "down", "none" ); DefaultAttr( attr, "over", "none" ); DefaultAttr( attr, "thickness", "10" ); DefaultAttr( attr, "value", "none" ); DefaultAttr( attr, "tooltiptext", "" ); DefaultAttr( attr, "help", "" ); string newValue = attr["value"]; if( m_curTreeId != "" ) { // Slider associated to a tree newValue = "playtree.slider"; } int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); int width = getDimension( attr["width"], refWidth ); int height = getDimension( attr["height"], refHeight ); const BuilderData::Slider slider( uniqueId( attr["id"] ), attr["visible"], x + m_xOffset, y + m_yOffset, width, height, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), attr["up"], attr["down"], attr["over"], attr["points"], atoi( attr["thickness"] ), newValue, "none", 0, 0, 0, 0, attr["tooltiptext"], attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listSlider.push_back( slider ); } else if( rName == "SliderBackground" ) { RequireAttr( attr, rName, "image" ); DefaultAttr( attr, "nbhoriz", "1" ); DefaultAttr( attr, "nbvert", "1" ); DefaultAttr( attr, "padhoriz", "0" ); DefaultAttr( attr, "padvert", "0" ); // Retrieve the current slider data BuilderData::Slider &slider = m_pData->m_listSlider.back(); slider.m_imageId = attr["image"]; slider.m_nbHoriz = atoi( attr["nbhoriz"] ); slider.m_nbVert = atoi( attr["nbvert"] ); slider.m_padHoriz = atoi( attr["padhoriz"] ); slider.m_padVert = atoi( attr["padvert"] ); } else if( rName == "Text" ) { RequireAttr( attr, rName, "font" ); DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "text", "" ); DefaultAttr( attr, "color", "#000000" ); DefaultAttr( attr, "scrolling", "auto" ); DefaultAttr( attr, "alignment", "left" ); DefaultAttr( attr, "focus", "true" ); DefaultAttr( attr, "width", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "help", "" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); int width = getDimension( attr["width"], refWidth ); const BuilderData::Text textData( uniqueId( attr["id"] ), x + m_xOffset, y + m_yOffset, attr["visible"], attr["font"], attr["text"], width, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), convertColor( attr["color"] ), attr["scrolling"], attr["alignment"], attr["focus"], attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listText.push_back( textData ); } else if( rName == "Theme" ) { RequireAttr( attr, rName, "version" ); DefaultAttr( attr, "tooltipfont", "defaultfont" ); DefaultAttr( attr, "magnet", "15" ); DefaultAttr( attr, "alpha", "255" ); DefaultAttr( attr, "movealpha", "255" ); // Check the version if( strcmp( attr["version"], SKINS_DTD_VERSION ) ) { msg_Err( getIntf(), "bad theme version : %s (you need version %s)", attr["version"], SKINS_DTD_VERSION ); m_errors = true; return; } const BuilderData::Theme theme( attr["tooltipfont"], atoi( attr["magnet"] ), convertInRange( attr["alpha"], 1, 255, "alpha" ), convertInRange( attr["movealpha"], 1, 255, "movealpha" ) ); m_pData->m_listTheme.push_back( theme ); } else if( rName == "ThemeInfo" ) { DefaultAttr( attr, "name", "" ); DefaultAttr( attr, "author", "" ); DefaultAttr( attr, "email", "" ); DefaultAttr( attr, "website", "" ); msg_Info( getIntf(), "skin: %s author: %s", attr["name"], attr["author"] ); } else if( rName == "Video" ) { DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "width", "0" ); DefaultAttr( attr, "height", "0" ); DefaultAttr( attr, "position", "-1" ); DefaultAttr( attr, "xoffset", "0" ); DefaultAttr( attr, "yoffset", "0" ); DefaultAttr( attr, "xmargin", "0" ); DefaultAttr( attr, "ymargin", "0" ); DefaultAttr( attr, "lefttop", "lefttop" ); DefaultAttr( attr, "rightbottom", "lefttop" ); DefaultAttr( attr, "xkeepratio", "false" ); DefaultAttr( attr, "ykeepratio", "false" ); DefaultAttr( attr, "autoresize", "true" ); DefaultAttr( attr, "help", "" ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, false ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); int width = getDimension( attr["width"], refWidth ); int height = getDimension( attr["height"], refHeight ); convertPosition( attr["position"], attr["xoffset"], attr["yoffset"], attr["xmargin"], attr["ymargin"], width, height, refWidth, refHeight, &x, &y ); const BuilderData::Video videoData( uniqueId( attr["id"] ), x + m_xOffset, y + m_yOffset, width, height, attr["lefttop"], attr["rightbottom"], convertBoolean( attr["xkeepratio"] ), convertBoolean( attr["ykeepratio"] ), attr["visible"], convertBoolean( attr["autoresize"] ), attr["help"], m_curLayer, m_curWindowId, m_curLayoutId, m_panelStack.back() ); m_curLayer++; m_pData->m_listVideo.push_back( videoData ); } else if( rName == "Window" ) { DefaultAttr( attr, "id", "none" ); DefaultAttr( attr, "visible", "true" ); DefaultAttr( attr, "x", "0" ); DefaultAttr( attr, "y", "0" ); DefaultAttr( attr, "position", "-1" ); DefaultAttr( attr, "xoffset", "0" ); DefaultAttr( attr, "yoffset", "0" ); DefaultAttr( attr, "xmargin", "0" ); DefaultAttr( attr, "ymargin", "0" ); DefaultAttr( attr, "dragdrop", "true" ); DefaultAttr( attr, "playondrop", "true" ); m_curWindowId = uniqueId( attr["id"] ); int refWidth, refHeight; getRefDimensions( refWidth, refHeight, true ); int x = getDimension( attr["x"], refWidth ); int y = getDimension( attr["y"], refHeight ); const BuilderData::Window window( m_curWindowId, x + m_xOffset, y + m_yOffset, attr["position"], attr["xoffset"], attr["yoffset"], attr["xmargin"], attr["ymargin"], convertBoolean( attr["visible"] ), convertBoolean( attr["dragdrop"] ), convertBoolean( attr["playondrop"] ) ); m_pData->m_listWindow.push_back( window ); } #undef RequireAttr }
//------------------------------------------------------------------------------ /*virtual*/ bool FunctionForEach::ParseFunction( NodeGraph & nodeGraph, const BFFIterator & functionNameStart, const BFFIterator * functionBodyStartToken, const BFFIterator * functionBodyStopToken, const BFFIterator * functionHeaderStartToken, const BFFIterator * functionHeaderStopToken ) const { // build array for each pair to loop through Array< AString > localNames( 4, true ); Array< const BFFVariable * > arrayVars( 4, true ); int loopLen = -1; // parse it all out BFFIterator pos( *functionHeaderStartToken ); pos++; // skip opening token while ( pos < *functionHeaderStopToken ) { pos.SkipWhiteSpace(); if ( *pos != BFFParser::BFF_DECLARE_VAR_INTERNAL ) { Error::Error_1200_ExpectedVar( pos, this ); return false; } const BFFIterator arrayVarNameBegin = pos; AStackString< BFFParser::MAX_VARIABLE_NAME_LENGTH > localName; bool localParentScope = false; // always false thanks to the previous test if ( BFFParser::ParseVariableName( pos, localName, localParentScope ) == false ) { return false; } ASSERT( false == localParentScope ); localNames.Append( localName ); pos.SkipWhiteSpace(); // check for "in" token bool foundIn = false; if ( *pos == 'i' ) { pos++; if ( *pos == 'n' ) { foundIn = true; } } if ( foundIn == false ) { Error::Error_1201_MissingIn( pos, this ); return false; } pos++; pos.SkipWhiteSpace(); if ( *pos != BFFParser::BFF_DECLARE_VAR_INTERNAL && *pos != BFFParser::BFF_DECLARE_VAR_PARENT /* tolerant with parent vars */ ) { Error::Error_1202_ExpectedVarFollowingIn( pos, this ); return false; } const BFFIterator arrayNameStart( pos ); AStackString< BFFParser::MAX_VARIABLE_NAME_LENGTH > arrayVarName; bool arrayParentScope = false; if ( BFFParser::ParseVariableName( pos, arrayVarName, arrayParentScope ) == false ) { return false; } const BFFVariable * var = nullptr; BFFStackFrame * const arrayFrame = ( arrayParentScope ) ? BFFStackFrame::GetParentDeclaration( arrayVarName, BFFStackFrame::GetCurrent()->GetParent(), var ) : nullptr; if ( false == arrayParentScope ) { var = BFFStackFrame::GetVar( arrayVarName, nullptr ); } if ( ( arrayParentScope && ( nullptr == arrayFrame ) ) || ( var == nullptr ) ) { Error::Error_1009_UnknownVariable( arrayNameStart, this, arrayVarName ); return false; } // it can be of any supported type if ( ( var->IsArrayOfStrings() == false ) && ( var->IsArrayOfStructs() == false ) ) { Error::Error_1050_PropertyMustBeOfType( arrayVarNameBegin, this, arrayVarName.Get(), var->GetType(), BFFVariable::VAR_ARRAY_OF_STRINGS, BFFVariable::VAR_ARRAY_OF_STRUCTS ); return false; } // is this the first variable? int thisArrayLen( -1 ); if ( var->GetType() == BFFVariable::VAR_ARRAY_OF_STRINGS ) { thisArrayLen = (int)var->GetArrayOfStrings().GetSize(); } else if ( var->GetType() == BFFVariable::VAR_ARRAY_OF_STRUCTS ) { thisArrayLen = (int)var->GetArrayOfStructs().GetSize(); } else { ASSERT( false ); } if ( loopLen == -1 ) { // it will set the length of looping loopLen = thisArrayLen; } else { // variables after the first must match length of the first if ( loopLen != thisArrayLen ) { Error::Error_1204_LoopVariableLengthsDiffer( arrayVarNameBegin, this, arrayVarName.Get(), (uint32_t)thisArrayLen, (uint32_t)loopLen ); return false; } } arrayVars.Append( var ); // skip optional separator pos.SkipWhiteSpace(); if ( *pos == ',' ) { pos++; } } ASSERT( localNames.GetSize() == arrayVars.GetSize() ); // gracefully allow empty loops if ( loopLen < 1 ) { return true; } // freeze the variable to avoid modifications while looping for ( uint32_t j=0; j<arrayVars.GetSize(); ++j ) { arrayVars[ j ]->Freeze(); FLOG_INFO( "Freezing loop array '%s' of type <%s>", arrayVars[j]->GetName().Get(), BFFVariable::GetTypeName( arrayVars[j]->GetType() ) ); } bool succeed = true; for ( uint32_t i=0; i<(uint32_t)loopLen; ++i ) { // create local loop variables BFFStackFrame loopStackFrame; for ( uint32_t j=0; j<localNames.GetSize(); ++j ) { if ( arrayVars[ j ]->GetType() == BFFVariable::VAR_ARRAY_OF_STRINGS ) { BFFStackFrame::SetVarString( localNames[ j ], arrayVars[ j ]->GetArrayOfStrings()[ i ], &loopStackFrame ); } else if ( arrayVars[ j ]->GetType() == BFFVariable::VAR_ARRAY_OF_STRUCTS ) { BFFStackFrame::SetVarStruct( localNames[ j ], arrayVars[ j ]->GetArrayOfStructs()[ i ]->GetStructMembers(), &loopStackFrame ); } else { ASSERT( false ); } } // parse the function body BFFParser subParser( nodeGraph ); BFFIterator subIter( *functionBodyStartToken ); subIter++; // skip opening token subIter.SetMax( functionBodyStopToken->GetCurrent() ); // limit to closing token if ( subParser.Parse( subIter ) == false ) { succeed = false; break; } // complete the function if ( Commit( nodeGraph, functionNameStart ) == false ) { succeed = false; break; } } // unfreeze all array variables for ( uint32_t j=0; j<arrayVars.GetSize(); ++j ) { arrayVars[ j ]->Unfreeze(); FLOG_INFO( "Unfreezing loop array '%s' of type <%s>", arrayVars[j]->GetName().Get(), BFFVariable::GetTypeName( arrayVars[j]->GetType() ) ); } return succeed; }
void DatabaseParser::processDirective (QString directive, shared_ptr <FlashcardsDatabase> database) { const QString includeDirectivePrefix = "#include ", pushDirectivePrefix = "#push ", popDirectivePrefix = "#pop", imageDirectivePrefix = "#image ", pushReplacementPrefix = "#push_replacement", popReplacementPrefix = "#pop_replacement"; if (directive.startsWith (includeDirectivePrefix)) { QString includePath = directive.right (directive.length() - includeDirectivePrefix.length()); shared_ptr <DatabaseParser> subParser (new DatabaseParser); subParser->blockParsers = blockParsers; QPair <QString, QString> contentsNamePair = FileReaderSingletone::instance().readContents (includePath, DATABASE_INCLUDE_DIRECTORIES_CONTEXT); subParser->parseDatabase (contentsNamePair.second, contentsNamePair.first, database, nullptr); } else if (directive.startsWith (pushDirectivePrefix)) { directive = directive.right (directive.length() - pushDirectivePrefix.length()); QString name = "", value = ""; int valueColonIndex = directive.indexOf (':'); if (valueColonIndex != -1) { if (directive.length() <= valueColonIndex + 1 || directive[valueColonIndex + 1] != ' ') blockParseError (0, "Space expected after a colon in a variable push directive."); name = directive.left (valueColonIndex).trimmed(); value = directive.right (directive.length() - valueColonIndex - 2); } else { name = directive.trimmed(); } if (name.isEmpty()) blockParseError (0, "Variable name is empty."); for (QChar c: name) if (!c.isLetterOrNumber() && c != '_') blockParseError (0, QString ("Invalid character '") + c + "' in variable name '" + name + "'."); //qstderr << "Push variable '" << name << "' with value '" << value << "'" << endl; currentDatabase->variableStack->pushVariable (name, currentDatabase->variableStack->getVariableExpansion (value)); } else if (directive.startsWith (popDirectivePrefix) && !directive.startsWith (popReplacementPrefix)) { directive = directive.right (directive.length() - popDirectivePrefix.length()).trimmed(); if (!currentDatabase->variableStack->popVariable (directive)) blockParseError (0, directive.isEmpty() ? "Failed to pop variable: the stack is empty." : "Failed to pop variable '" + directive + "': not found on stack."); } else if (directive.startsWith (imageDirectivePrefix)) { directive = directive.right (directive.length() - imageDirectivePrefix.length()).trimmed(); directive = FileReaderSingletone::instance().getAbsolutePath (directive, DATABASE_INCLUDE_DIRECTORIES_CONTEXT); currentDatabase->variableStack->pushVariable ("image", directive); } else if (directive.startsWith (pushReplacementPrefix)) { directive = directive.right (directive.length() - pushReplacementPrefix.length()); QChar delimiter = directive.isEmpty() ? QChar ('.') : directive[0]; if (directive.isEmpty()) blockParseError (0, "Directive '" + pushReplacementPrefix + "' expects a delimiter character."); else directive = directive.right(directive.size() - 1); QStringList parts = directive.split (delimiter, QString::KeepEmptyParts); if (parts.size() != 3) blockParseError (0, QString ("Delimiter '") + delimiter + "' breaks '" + directive + "' into " + QString::number (parts.size()) + " parts, 3 expected."); if (!parts[2].isEmpty()) blockParseError (0, "Non-empty last part of a '" + pushReplacementPrefix + "' directive: '" + parts[2] + "'."); currentDatabase->replacements.push_back (QPair <QString, QString> (parts[0], currentDatabase->variableStack->getVariableExpansion (parts[1]))); } else if (directive.startsWith (popReplacementPrefix)) { if (directive != popReplacementPrefix) blockParseError (0, "Directive '" + popReplacementPrefix + "' has no parameters."); if (currentDatabase->replacements.empty()) blockParseError (0, "Replacements stack is empty."); currentDatabase->replacements.pop_back(); } else { blockParseError (0, "Unknown directive: '" + directive + "'."); } }