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.

91 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 <string_utils.h>
  26. typedef wxXmlAttribute XATTR;
  27. void XNODE::Format( OUTPUTFORMATTER* out, int nestLevel )
  28. {
  29. switch( GetType() )
  30. {
  31. case wxXML_ELEMENT_NODE:
  32. out->Print( nestLevel, "(%s", TO_UTF8( GetName() ) );
  33. FormatContents( out, nestLevel );
  34. if( GetNext() )
  35. out->Print( 0, ")\n" );
  36. else
  37. out->Print( 0, ")" );
  38. break;
  39. default:
  40. FormatContents( out, nestLevel );
  41. }
  42. }
  43. void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel )
  44. {
  45. // output attributes first if they exist
  46. for( XATTR* attr = (XATTR*) GetAttributes(); attr; attr = (XATTR*) attr->GetNext() )
  47. {
  48. out->Print( 0, " (%s %s)",
  49. TO_UTF8( attr->GetName() ),
  50. out->Quotew( attr->GetValue() ).c_str() );
  51. }
  52. // we only expect to have used one of two types here:
  53. switch( GetType() )
  54. {
  55. case wxXML_ELEMENT_NODE:
  56. // output children if they exist.
  57. for( XNODE* kid = (XNODE*) GetChildren(); kid; kid = (XNODE*) kid->GetNext() )
  58. {
  59. if( kid->GetType() != wxXML_TEXT_NODE )
  60. {
  61. if( kid == GetChildren() )
  62. out->Print( 0, "\n" );
  63. kid->Format( out, nestLevel+1 );
  64. }
  65. else
  66. {
  67. kid->Format( out, 0 );
  68. }
  69. }
  70. break;
  71. case wxXML_TEXT_NODE:
  72. out->Print( 0, " %s", out->Quotew( GetContent() ).c_str() );
  73. break;
  74. default:
  75. ; // not supported
  76. }
  77. }
  78. // EOF