From: Leon W. <moo...@us...> - 2005-04-14 11:19:07
|
Update of /cvsroot/anyedit/AnyEditv2 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv544 Modified Files: ConfigFile.cpp ConfigFile.h Log Message: Improved class - Removed language attributes (count,number), these aren't needed. - Add Parse checks in every function, to make sure the file is parsed before read. Index: ConfigFile.h =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/ConfigFile.h,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** ConfigFile.h 27 Jan 2005 13:29:20 -0000 1.20 --- ConfigFile.h 14 Apr 2005 11:18:56 -0000 1.21 *************** *** 68,74 **** #define TAG_LANGUAGE "Language" - // Languages attributes - #define ATT_LANGUAGES_COUNT "count" - // Language tags #define TAG_LANGUAGE_NAME "Name" --- 68,71 ---- *************** *** 77,83 **** #define TAG_LANGUAGE_EXTENSIONS "Extensions" - // Language attributes - #define ATT_LANGUAGE_NUMBER "number" - // Editor tags #define TAG_EDITOR_CARETCOLOR "CaretColor" --- 74,77 ---- *************** *** 305,309 **** /// Set the color for the Highlighted Line bool SetHighlightCurrentLineColor( COLORREF clrHighlight ); ! /// Get the RightEdge type. bool GetRightEdge(); --- 299,303 ---- /// Set the color for the Highlighted Line bool SetHighlightCurrentLineColor( COLORREF clrHighlight ); ! /// Get the RightEdge type. bool GetRightEdge(); Index: ConfigFile.cpp =================================================================== RCS file: /cvsroot/anyedit/AnyEditv2/ConfigFile.cpp,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** ConfigFile.cpp 27 Jan 2005 13:29:20 -0000 1.21 --- ConfigFile.cpp 14 Apr 2005 11:18:56 -0000 1.22 *************** *** 50,54 **** CConfigFile::~CConfigFile() { - } --- 50,53 ---- *************** *** 58,62 **** pug::xml_node xnode; ! if( !m_bParsed ) Parse(); xnode = m_xml_parser.document(); --- 57,62 ---- pug::xml_node xnode; ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return pug::xml_node(); xnode = m_xml_parser.document(); *************** *** 71,82 **** pug::xml_node CConfigFile::GetLanguageNodeByNumber( int iNumber ) { - CString szNumber; pug::xml_node xnode; xnode = GetLanguagesNode(); ! if( xnode.empty() ) return false; ! szNumber.Format( "%i", iNumber ); ! return xnode.first_element_by_attribute( TAG_LANGUAGE, ATT_LANGUAGE_NUMBER, szNumber ); } --- 71,82 ---- pug::xml_node CConfigFile::GetLanguageNodeByNumber( int iNumber ) { pug::xml_node xnode; xnode = GetLanguagesNode(); ! if( xnode.empty() ) return pug::xml_node(); ! if( xnode.children() <= iNumber ) return pug::xml_node(); ! ! return xnode.child( iNumber ); } *************** *** 241,253 **** { pug::xml_node xnode; - pug::xml_attribute xattribute; xnode = GetLanguagesNode(); if( xnode.empty() ) return -1; ! xattribute = xnode.attribute( ATT_LANGUAGES_COUNT ); ! if( xattribute.empty() ) return -1; ! ! return atoi( xattribute.value() ); } --- 241,254 ---- { pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return -1; + + // Get root node. xnode = GetLanguagesNode(); if( xnode.empty() ) return -1; ! // Return nr of children = nr of languages ! return xnode.children(); } *************** *** 258,261 **** --- 259,265 ---- pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return _T(""); + xnode = GetLanguageNodeByNumber( iNumber ); if( xnode.empty() && !xnode.children() ) return ""; *************** *** 269,272 **** --- 273,279 ---- pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return false; + xnode = GetLanguageNodeByNumber( iNumber ); if( xnode.empty() || !xnode.children() ) return false; *************** *** 280,283 **** --- 287,293 ---- pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return _T(""); + xnode = GetLanguageNodeByNumber( iNumber ); if( xnode.empty() || !xnode.children() ) return ""; *************** *** 291,294 **** --- 301,307 ---- pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return false; + xnode = GetLanguageNodeByNumber( iNumber ); if( xnode.empty() || !xnode.children() ) return false; *************** *** 302,305 **** --- 315,321 ---- pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return _T(""); + xnode = GetLanguageNodeByNumber( iNumber ); if( xnode.empty() || !xnode.children() ) return ""; *************** *** 313,316 **** --- 329,335 ---- pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return false; + xnode = GetLanguageNodeByNumber( iNumber ); if( xnode.empty() || !xnode.children() ) return false; *************** *** 325,328 **** --- 344,350 ---- pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return _T(""); + xnode = GetLanguageNodeByNumber( iNumber ); if( xnode.empty() || !xnode.children() ) return ""; *************** *** 336,339 **** --- 358,364 ---- pug::xml_node xnode; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return false; + xnode = GetLanguageNodeByNumber( iNumber ); if( xnode.empty() || !xnode.children() ) return false; *************** *** 346,380 **** bool CConfigFile::AddLanguage( CString szName, CString szSyntaxFile, CString szAutoCompFile, CString szExtensions ) { - CString szNumber; - unsigned int uiCount; pug::xml_node xnode; - pug::xml_attribute xattribute; // A language does at least need a name. if( szName.IsEmpty() ) return false; xnode = GetLanguagesNode(); if( xnode.empty() ) return false; - uiCount = xnode.children(); - szNumber.Format( "%i", uiCount + 1 ); - - xattribute = xnode.attribute( ATT_LANGUAGES_COUNT ); - if( xattribute.empty() ) return false; - - if( !xattribute.value( szNumber ) ) return false; - - // This is the point where the file is modified. - m_bModified = true; - // Add a new language tag xnode = xnode.append_child( pug::node_element ); if( xnode.empty() ) return false; ! if( !xnode.name( TAG_LANGUAGE ) ) return false; ! // Set the language number ! xattribute = xnode.append_attribute( ATT_LANGUAGE_NUMBER, (long)uiCount ); ! if( xattribute.empty() ) return false; // Add the language name --- 371,394 ---- bool CConfigFile::AddLanguage( CString szName, CString szSyntaxFile, CString szAutoCompFile, CString szExtensions ) { pug::xml_node xnode; // A language does at least need a name. if( szName.IsEmpty() ) return false; + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return false; + xnode = GetLanguagesNode(); if( xnode.empty() ) return false; // Add a new language tag xnode = xnode.append_child( pug::node_element ); if( xnode.empty() ) return false; ! // This is the point where the file is modified. ! m_bModified = true; ! // Set the tagname of the new child ! if( !xnode.name( TAG_LANGUAGE ) ) return false; // Add the language name *************** *** 408,453 **** bool CConfigFile::RemoveLanguage( int iNumber ) { - CString szNumber; - unsigned int uiCount; pug::xml_node xnode; - pug::xml_node rnode; - pug::xml_attribute xattribute; - - xnode = GetLanguagesNode(); - if( xnode.empty() && !xnode.children() ) return false; - - uiCount = xnode.children(); - szNumber.Format( "%i", uiCount - 1 ); - - xattribute = xnode.attribute( ATT_LANGUAGES_COUNT ); - if( xattribute.empty() ) return false; - - if( !xattribute.value( szNumber ) ) return false; ! // This is the point where the file is changed. ! m_bModified = true; ! ! szNumber.Format( "%i", iNumber ); ! rnode = xnode.first_element_by_attribute( TAG_LANGUAGE, ATT_LANGUAGE_NUMBER, szNumber ); ! if( rnode.empty() && !rnode.children() ) return false; ! uiCount = xnode.children(); ! if( uiCount < iNumber ) return false; // Remove the child ! xnode.remove_child( iNumber ); ! ! // Renumber the remaining Language nodes. ! while( iNumber < uiCount - 1 ) ! { ! szNumber.Format( "%i", iNumber ); ! rnode = xnode.child( iNumber ); ! xattribute = rnode.attribute( ATT_LANGUAGE_NUMBER ); ! xattribute.value( szNumber ); ! ++ iNumber; ! } ! ! return true; } --- 422,438 ---- bool CConfigFile::RemoveLanguage( int iNumber ) { pug::xml_node xnode; ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return false; ! xnode = GetLanguagesNode(); ! if( xnode.empty() ) return false; ! // Check if it is a valid number ! if( iNumber >= xnode.children() ) return false; // Remove the child ! return m_bModified = xnode.remove_child( iNumber ); } *************** *** 599,603 **** unsigned int CConfigFile::GetFileFiltersCount() { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); --- 584,589 ---- unsigned int CConfigFile::GetFileFiltersCount() { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return 0; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); *************** *** 609,617 **** CString CConfigFile::GetFileFilter( unsigned int iNumber ) { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() || iNumber >= xnode.children() ) return ""; if( !xnode.child(0).has_child_nodes() ) return ""; return xnode.child( iNumber ).child(0).value(); } --- 595,606 ---- CString CConfigFile::GetFileFilter( unsigned int iNumber ) { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return _T(""); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() || iNumber >= xnode.children() ) return ""; + if( !xnode.child(0).has_child_nodes() ) return ""; + return xnode.child( iNumber ).child(0).value(); } *************** *** 620,627 **** bool CConfigFile::RemoveAllFileFilters() { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() || !xnode.has_child_nodes() ) return false; while( xnode.has_child_nodes() ) { --- 609,618 ---- bool CConfigFile::RemoveAllFileFilters() { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return false; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() || !xnode.has_child_nodes() ) return false; + while( xnode.has_child_nodes() ) { *************** *** 629,632 **** --- 620,624 ---- m_bModified = true; } + return true; } *************** *** 635,649 **** bool CConfigFile::AddFileFilter( CString szFilter ) { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() ) return false; xnode = xnode.append_child( pug::node_element ); if( xnode.empty() ) return false; m_bModified = true; xnode.name( TAG_FILTER ); xnode = xnode.append_child( pug::node_pcdata ); if( xnode.empty() ) return false; xnode.value( szFilter ); return true; } --- 627,648 ---- bool CConfigFile::AddFileFilter( CString szFilter ) { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return false; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() ) return false; + xnode = xnode.append_child( pug::node_element ); if( xnode.empty() ) return false; + m_bModified = true; + xnode.name( TAG_FILTER ); + xnode = xnode.append_child( pug::node_pcdata ); if( xnode.empty() ) return false; + xnode.value( szFilter ); + return true; } *************** *** 652,659 **** int CConfigFile::GetFileFilterDefault() { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() || !xnode.has_attributes() ) return 0; return atoi( xnode.attribute( ATT_FILTER_DEFAULT ) ); } --- 651,660 ---- int CConfigFile::GetFileFilterDefault() { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return 0; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() || !xnode.has_attributes() ) return 0; + return atoi( xnode.attribute( ATT_FILTER_DEFAULT ) ); } *************** *** 664,672 **** CString szDefault; ! if( !m_bParsed ) Parse(); szDefault.Format( "%i", iDefault ); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() ) return false; if( !xnode.has_attributes() || !xnode.has_attribute( ATT_FILTER_DEFAULT ) ) { --- 665,675 ---- CString szDefault; ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return false; szDefault.Format( "%i", iDefault ); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_FILTERS ) ); if( xnode.empty() ) return false; + if( !xnode.has_attributes() || !xnode.has_attribute( ATT_FILTER_DEFAULT ) ) { *************** *** 675,681 **** else { - xnode.attribute( ATT_FILTER_DEFAULT ).value( szDefault ); } return m_bModified = true; } --- 678,684 ---- else { xnode.attribute( ATT_FILTER_DEFAULT ).value( szDefault ); } + return m_bModified = true; } *************** *** 684,688 **** unsigned int CConfigFile::GetFileAssociationCount() { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); --- 687,692 ---- unsigned int CConfigFile::GetFileAssociationCount() { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return 0; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); *************** *** 694,701 **** CString CConfigFile::GetFileClassDescription( unsigned int iIndex ) { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() || xnode.children() <= iIndex ) return _T(""); xnode = xnode.child( iIndex ); if( xnode.empty() || !xnode.has_child_nodes() ) return _T(""); --- 698,707 ---- CString CConfigFile::GetFileClassDescription( unsigned int iIndex ) { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return _T(""); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() || xnode.children() <= iIndex ) return _T(""); + xnode = xnode.child( iIndex ); if( xnode.empty() || !xnode.has_child_nodes() ) return _T(""); *************** *** 706,713 **** CString CConfigFile::GetFileClassExtension( unsigned int iIndex ) { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() || xnode.children() <= iIndex ) return _T(""); xnode = xnode.child( iIndex ); if( xnode.empty() || !xnode.has_attributes() ) return _T(""); --- 712,721 ---- CString CConfigFile::GetFileClassExtension( unsigned int iIndex ) { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return _T(""); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() || xnode.children() <= iIndex ) return _T(""); + xnode = xnode.child( iIndex ); if( xnode.empty() || !xnode.has_attributes() ) return _T(""); *************** *** 721,728 **** int CConfigFile::GetFileClassIcon( unsigned int iIndex ) { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() || xnode.children() <= iIndex ) return -1; xnode = xnode.child( iIndex ); if( xnode.empty() || !xnode.has_attributes() ) return -1; --- 729,738 ---- int CConfigFile::GetFileClassIcon( unsigned int iIndex ) { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return -1; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() || xnode.children() <= iIndex ) return -1; + xnode = xnode.child( iIndex ); if( xnode.empty() || !xnode.has_attributes() ) return -1; *************** *** 737,744 **** { unsigned int iCount; ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() ) return -1; for( iCount = 0; iCount < xnode.children(); ++ iCount ) { --- 747,757 ---- { unsigned int iCount; ! ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return -1; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() ) return -1; + for( iCount = 0; iCount < xnode.children(); ++ iCount ) { *************** *** 753,763 **** { char szNumber[4]; ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() || xnode.children() <= iIndex ) return false; if( !xnode.child( iIndex ).attribute( ATT_FILECLASS_EXTENSION ).value( szExtension ) ) return false; sprintf( szNumber, "%i", iIcon ); if( !xnode.child( iIndex ).attribute( ATT_FILECLASS_ICON ).value( szNumber ) ) return false; if( !xnode.child( iIndex ).child(0).value( szDescription ) ) return false; --- 766,781 ---- { char szNumber[4]; ! ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return false; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); if( xnode.empty() || !xnode.has_child_nodes() || xnode.children() <= iIndex ) return false; + if( !xnode.child( iIndex ).attribute( ATT_FILECLASS_EXTENSION ).value( szExtension ) ) return false; + sprintf( szNumber, "%i", iIcon ); if( !xnode.child( iIndex ).attribute( ATT_FILECLASS_ICON ).value( szNumber ) ) return false; + if( !xnode.child( iIndex ).child(0).value( szDescription ) ) return false; *************** *** 768,772 **** bool CConfigFile::AddFileClass( CString& szExtension, CString& szDescription, unsigned int iIcon ) { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); --- 786,791 ---- bool CConfigFile::AddFileClass( CString& szExtension, CString& szDescription, unsigned int iIcon ) { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return false; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); *************** *** 796,800 **** bool CConfigFile::RemoveFileClass( unsigned int iIndex ) { ! if( !m_bParsed ) Parse(); pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); --- 815,820 ---- bool CConfigFile::RemoveFileClass( unsigned int iIndex ) { ! // Make sure the file is parsed. ! if( !m_bParsed && !Parse() ) return false; pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_FILE_ASSOCIATIONS ) ); *************** *** 1024,1030 **** CString CConfigFile::GetInsertTextWord( unsigned int uiIndex ) { pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_INSERTTEXT ) ); if( xnode.empty() ) return _T(""); ! xnode = xnode.first_element_by_name( TAG_INSERTTEXT_INSERTWORDS ); if( xnode.empty() || !xnode.has_child_nodes() ) return _T(""); --- 1044,1053 ---- CString CConfigFile::GetInsertTextWord( unsigned int uiIndex ) { + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return _T(""); + pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_INSERTTEXT ) ); if( xnode.empty() ) return _T(""); ! xnode = xnode.first_element_by_name( TAG_INSERTTEXT_INSERTWORDS ); if( xnode.empty() || !xnode.has_child_nodes() ) return _T(""); *************** *** 1043,1049 **** bool CConfigFile::AddInsertTextWord( const CString& szWord ) { pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_INSERTTEXT ) ); if( xnode.empty() ) return false; ! xnode = xnode.first_element_by_name( TAG_INSERTTEXT_INSERTWORDS ); if( xnode.empty() ) return false; --- 1066,1075 ---- bool CConfigFile::AddInsertTextWord( const CString& szWord ) { + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return false; + pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_INSERTTEXT ) ); if( xnode.empty() ) return false; ! xnode = xnode.first_element_by_name( TAG_INSERTTEXT_INSERTWORDS ); if( xnode.empty() ) return false; *************** *** 1065,1074 **** bool CConfigFile::RemoveInsertTextWords() { pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_INSERTTEXT ) ); if( xnode.empty() ) return false; ! xnode = xnode.first_element_by_name( TAG_INSERTTEXT_INSERTWORDS ); if( xnode.empty() ) return false; ! while( xnode.has_child_nodes() ) { --- 1091,1103 ---- bool CConfigFile::RemoveInsertTextWords() { + // Make sure the file is parsed. + if( !m_bParsed && !Parse() ) return false; + pug::xml_node xnode( m_xml_parser.document().first_element_by_name( TAG_INSERTTEXT ) ); if( xnode.empty() ) return false; ! xnode = xnode.first_element_by_name( TAG_INSERTTEXT_INSERTWORDS ); if( xnode.empty() ) return false; ! while( xnode.has_child_nodes() ) { |