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 "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 41 of file 3d_filename_resolver.cpp.

Referenced by S3D_FILENAME_RESOLVER::ResolvePath().

#define ERRFLG_ENVPATH   (4)

Definition at line 43 of file 3d_filename_resolver.cpp.

Referenced by S3D_FILENAME_RESOLVER::ResolvePath().

#define ERRFLG_RELPATH   (2)

Definition at line 42 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 882 of file 3d_filename_resolver.cpp.

References MASK_3D_RESOLVER.

Referenced by S3D_FILENAME_RESOLVER::readPathList().

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

Variable Documentation

wxCriticalSection lock3D_resolver
static