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.

93 lines
2.8 KiB

15 years ago
15 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 <macros.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", out->Quotew( GetName() ).c_str() );
  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. // attr names should never need quoting, no spaces, we designed the file.
  50. out->Quotew( attr->GetName() ).c_str(),
  51. out->Quotew( attr->GetValue() ).c_str()
  52. );
  53. }
  54. // we only expect to have used one of two types here:
  55. switch( GetType() )
  56. {
  57. case wxXML_ELEMENT_NODE:
  58. // output children if they exist.
  59. for( XNODE* kid = (XNODE*) GetChildren(); kid; kid = (XNODE*) kid->GetNext() )
  60. {
  61. if( kid->GetType() != wxXML_TEXT_NODE )
  62. {
  63. if( kid == GetChildren() )
  64. out->Print( 0, "\n" );
  65. kid->Format( out, nestLevel+1 );
  66. }
  67. else
  68. {
  69. kid->Format( out, 0 );
  70. }
  71. }
  72. break;
  73. case wxXML_TEXT_NODE:
  74. out->Print( 0, " %s", out->Quotew( GetContent() ).c_str() );
  75. break;
  76. default:
  77. ; // not supported
  78. }
  79. }
  80. // EOF