You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.7 KiB

16 years ago
16 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2010 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 1992-2010 KiCad Developers, see change_log.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #include "xnode.h"
  25. #include <richio.h>
  26. #include <string_utils.h>
  27. typedef wxXmlAttribute XATTR;
  28. void XNODE::Format( OUTPUTFORMATTER* out, int nestLevel )
  29. {
  30. switch( GetType() )
  31. {
  32. case wxXML_ELEMENT_NODE:
  33. out->Print( nestLevel, "(%s", TO_UTF8( GetName() ) );
  34. FormatContents( out, nestLevel );
  35. if( GetNext() )
  36. out->Print( 0, ")\n" );
  37. else
  38. out->Print( 0, ")" );
  39. break;
  40. default:
  41. FormatContents( out, nestLevel );
  42. }
  43. }
  44. void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel )
  45. {
  46. // output attributes first if they exist
  47. for( XATTR* attr = (XATTR*) GetAttributes(); attr; attr = (XATTR*) attr->GetNext() )
  48. {
  49. out->Print( 0, " (%s %s)",
  50. TO_UTF8( attr->GetName() ),
  51. out->Quotew( attr->GetValue() ).c_str() );
  52. }
  53. // we only expect to have used one of two types here:
  54. switch( GetType() )
  55. {
  56. case wxXML_ELEMENT_NODE:
  57. // output children if they exist.
  58. for( XNODE* kid = (XNODE*) GetChildren(); kid; kid = (XNODE*) kid->GetNext() )
  59. {
  60. if( kid->GetType() != wxXML_TEXT_NODE )
  61. {
  62. if( kid == GetChildren() )
  63. out->Print( 0, "\n" );
  64. kid->Format( out, nestLevel+1 );
  65. }
  66. else
  67. {
  68. kid->Format( out, 0 );
  69. }
  70. }
  71. break;
  72. case wxXML_TEXT_NODE:
  73. out->Print( 0, " %s", out->Quotew( GetContent() ).c_str() );
  74. break;
  75. default:
  76. ; // not supported
  77. }
  78. }
  79. // EOF