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.

114 lines
3.8 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2007-2016 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2017 KiCad Developers, see AUTHORS.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 <wx/wx.h>
  25. #include <ki_exception.h>
  26. #define THROWERS_WHERE _( "from %s : %s() line:%d" )
  27. #define PARSE_PROBLEM _( "%s in input/source\n'%s'\nline %d, offset %d" )
  28. const wxString IO_ERROR::What() const
  29. {
  30. #ifdef DEBUG
  31. return wxString( "IO_ERROR: " ) + Problem() + "\n\n" + Where();
  32. #else
  33. return Problem();
  34. #endif
  35. }
  36. const wxString IO_ERROR::Where() const
  37. {
  38. return where;
  39. }
  40. const wxString IO_ERROR::Problem() const
  41. {
  42. return problem;
  43. }
  44. void IO_ERROR::init( const wxString& aProblem, const char* aThrowersFile, const char* aThrowersFunction, int aThrowersLineNumber )
  45. {
  46. problem = aProblem;
  47. // The throwers filename is a full filename, depending on Kicad source location.
  48. // a short filename will be printed (it is better for user, the full filename has no meaning).
  49. wxString srcname = aThrowersFile;
  50. where.Printf( THROWERS_WHERE, srcname.AfterLast( '/' ).GetData(),
  51. wxString( aThrowersFunction ).GetData(), aThrowersLineNumber );
  52. }
  53. void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile,
  54. const char* aThrowersFunction, int aThrowersLineNumber,
  55. const wxString& aSource,
  56. const char* aInputLine,
  57. int aLineNumber, int aByteIndex )
  58. {
  59. problem.Printf( PARSE_PROBLEM, aProblem.GetData(), aSource.GetData(), aLineNumber, aByteIndex );
  60. inputLine = aInputLine;
  61. lineNumber = aLineNumber;
  62. byteIndex = aByteIndex;
  63. // The throwers filename is a full filename, depending on Kicad source location.
  64. // a short filename will be printed (it is better for user, the full filename has no meaning).
  65. wxString srcname = aThrowersFile;
  66. where.Printf( THROWERS_WHERE, srcname.AfterLast( '/' ).GetData(),
  67. wxString( aThrowersFunction ).GetData(), aThrowersLineNumber );
  68. }
  69. FUTURE_FORMAT_ERROR::FUTURE_FORMAT_ERROR( const PARSE_ERROR& aParseError, const wxString& aRequiredVersion ) :
  70. PARSE_ERROR(), requiredVersion( aRequiredVersion )
  71. {
  72. // Avoid double-printing the error message
  73. bool wrapped_same_type = !!( dynamic_cast<const FUTURE_FORMAT_ERROR *>( &aParseError ) );
  74. if( wrapped_same_type )
  75. {
  76. problem = aParseError.Problem();
  77. }
  78. else
  79. {
  80. problem.Printf( _(
  81. "KiCad was unable to open this file, as it was created with a more "
  82. "recent version than the one you are running. To open it, you'll need "
  83. "to upgrade KiCad to a more recent version.\n\n"
  84. "Date of KiCad version required (or newer): %s\n\n"
  85. "Full error text:\n%s" ),
  86. requiredVersion, aParseError.Problem() );
  87. }
  88. lineNumber = aParseError.lineNumber;
  89. byteIndex = aParseError.byteIndex;
  90. inputLine = aParseError.inputLine;
  91. }