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.5 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2012 KiCad Developers, see CHANGELOG.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. // This is a propertytree test utility.
  25. // It can convert XML to sexpressions or beautify s-expressions in non-specctra mode.
  26. #include <assert.h>
  27. #include <ptree.h>
  28. #include <richio.h>
  29. #include <dsnlexer.h>
  30. #include <macros.h>
  31. #include <boost/property_tree/xml_parser.hpp>
  32. void usage()
  33. {
  34. fprintf( stderr, "Usage: parser_gen <grammar_s-expression_file>\n" );
  35. exit( 1 );
  36. }
  37. int main( int argc, char** argv )
  38. {
  39. if( argc != 2 )
  40. {
  41. usage();
  42. }
  43. FILE* fp = fopen( argv[1], "r" );
  44. if( !fp )
  45. {
  46. fprintf( stderr, "Unable to open \"%s\"\n", argv[1] );
  47. usage();
  48. }
  49. static const KEYWORD empty_keywords[1] = {};
  50. DSNLEXER lexer( empty_keywords, 0, fp, FROM_UTF8( argv[1] ) );
  51. try
  52. {
  53. PTREE doc;
  54. #if 0
  55. using namespace boost::property_tree;
  56. read_xml( argv[1], doc, xml_parser::trim_whitespace | xml_parser::no_comments );
  57. #else
  58. Scan( &doc, &lexer );
  59. #endif
  60. #if 1
  61. STRING_FORMATTER sf;
  62. Format( &sf, 0, 0, doc );
  63. printf( "%s", sf.GetString().c_str() );
  64. #else
  65. // writing the unchanged ptree in file2.xml
  66. boost::property_tree::xml_writer_settings<char> settings( ' ', 2 );
  67. write_xml( "/tmp/output.xml", doc, std::locale(), settings );
  68. #endif
  69. }
  70. catch( const IO_ERROR& ioe )
  71. {
  72. fprintf( stderr, "%s\n", TO_UTF8( ioe.What() ) );
  73. }
  74. }