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

References MASK_3D_RESOLVER.

Referenced by S3D_FILENAME_RESOLVER::readPathList().

909 {
910  aResult.clear();
911 
912  if( aIndex >= aString.size() )
913  {
914  std::ostringstream ostr;
915  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
916  wxString errmsg = "bad Hollerith string on 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  size_t i2 = aString.find( '"', aIndex );
924 
925  if( std::string::npos == i2 )
926  {
927  std::ostringstream ostr;
928  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
929  wxString errmsg = "missing opening quote mark in config file";
930  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
931  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
932 
933  return false;
934  }
935 
936  ++i2;
937 
938  if( i2 >= aString.size() )
939  {
940  std::ostringstream ostr;
941  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
942  wxString errmsg = "invalid entry (unexpected end of line)";
943  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
944  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
945 
946  return false;
947  }
948 
949  std::string tnum;
950 
951  while( aString[i2] >= '0' && aString[i2] <= '9' )
952  tnum.append( 1, aString[i2++] );
953 
954  if( tnum.empty() || aString[i2++] != ':' )
955  {
956  std::ostringstream ostr;
957  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
958  wxString errmsg = "bad Hollerith string on line";
959  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
960  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
961 
962  return false;
963  }
964 
965  std::istringstream istr;
966  istr.str( tnum );
967  size_t nchars;
968  istr >> nchars;
969 
970  if( (i2 + nchars) >= aString.size() )
971  {
972  std::ostringstream ostr;
973  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
974  wxString errmsg = "invalid entry (unexpected end of line)";
975  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
976  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
977 
978  return false;
979  }
980 
981  if( nchars > 0 )
982  {
983  aResult = aString.substr( i2, nchars );
984  i2 += nchars;
985  }
986 
987  if( aString[i2] != '"' )
988  {
989  std::ostringstream ostr;
990  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
991  wxString errmsg = "missing closing quote mark in config file";
992  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
993  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
994 
995  return false;
996  }
997 
998  aIndex = i2 + 1;
999  return true;
1000 }
#define MASK_3D_RESOLVER

Variable Documentation

wxCriticalSection lock3D_resolver
static