KiCad PCB EDA Suite
3d_filename_resolver.cpp File Reference
#include <sstream>
#include <cstring>
#include <fstream>
#include <wx/filename.h>
#include <wx/log.h>
#include <wx/msgdlg.h>
#include <pgm_base.h>
#include <trace_helpers.h>
#include "common.h"
#include "3d_filename_resolver.h"

Go to the source code of this file.

Macros

#define CFGFILE_VERSION   1
 
#define S3D_RESOLVER_CONFIG   wxT( "3Dresolver.cfg" )
 
#define ERRFLG_ALIAS   (1)
 
#define ERRFLG_RELPATH   (2)
 
#define ERRFLG_ENVPATH   (4)
 
#define MASK_3D_RESOLVER   "3D_RESOLVER"
 

Functions

static bool getHollerith (const std::string &aString, size_t &aIndex, wxString &aResult)
 

Variables

static wxCriticalSection lock3D_resolver
 

Macro Definition Documentation

#define CFGFILE_VERSION   1
#define ERRFLG_ALIAS   (1)

Definition at line 42 of file 3d_filename_resolver.cpp.

Referenced by S3D_FILENAME_RESOLVER::ResolvePath().

#define ERRFLG_ENVPATH   (4)

Definition at line 44 of file 3d_filename_resolver.cpp.

Referenced by S3D_FILENAME_RESOLVER::ResolvePath().

#define ERRFLG_RELPATH   (2)

Definition at line 43 of file 3d_filename_resolver.cpp.

Referenced by S3D_FILENAME_RESOLVER::ResolvePath().

#define S3D_RESOLVER_CONFIG   wxT( "3Dresolver.cfg" )

Function Documentation

static bool getHollerith ( const std::string &  aString,
size_t &  aIndex,
wxString &  aResult 
)
static

Definition at line 884 of file 3d_filename_resolver.cpp.

References MASK_3D_RESOLVER.

Referenced by S3D_FILENAME_RESOLVER::readPathList().

885 {
886  aResult.clear();
887 
888  if( aIndex >= aString.size() )
889  {
890  std::ostringstream ostr;
891  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
892  wxString errmsg = "bad Hollerith string on line";
893  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
894  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
895 
896  return false;
897  }
898 
899  size_t i2 = aString.find( '"', aIndex );
900 
901  if( std::string::npos == i2 )
902  {
903  std::ostringstream ostr;
904  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
905  wxString errmsg = "missing opening quote mark in config file";
906  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
907  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
908 
909  return false;
910  }
911 
912  ++i2;
913 
914  if( i2 >= aString.size() )
915  {
916  std::ostringstream ostr;
917  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
918  wxString errmsg = "invalid entry (unexpected end of line)";
919  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
920  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
921 
922  return false;
923  }
924 
925  std::string tnum;
926 
927  while( aString[i2] >= '0' && aString[i2] <= '9' )
928  tnum.append( 1, aString[i2++] );
929 
930  if( tnum.empty() || aString[i2++] != ':' )
931  {
932  std::ostringstream ostr;
933  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
934  wxString errmsg = "bad Hollerith string on line";
935  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
936  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
937 
938  return false;
939  }
940 
941  std::istringstream istr;
942  istr.str( tnum );
943  size_t nchars;
944  istr >> nchars;
945 
946  if( (i2 + nchars) >= aString.size() )
947  {
948  std::ostringstream ostr;
949  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
950  wxString errmsg = "invalid entry (unexpected end of line)";
951  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
952  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
953 
954  return false;
955  }
956 
957  if( nchars > 0 )
958  {
959  aResult = aString.substr( i2, nchars );
960  i2 += nchars;
961  }
962 
963  if( aString[i2] != '"' )
964  {
965  std::ostringstream ostr;
966  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
967  wxString errmsg = "missing closing quote mark in config file";
968  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
969  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
970 
971  return false;
972  }
973 
974  aIndex = i2 + 1;
975  return true;
976 }
#define MASK_3D_RESOLVER

Variable Documentation

wxCriticalSection lock3D_resolver
static