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

Go to the source code of this file.

Macros

#define CFGFILE_VERSION   1
 
#define 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 std::mutex mutex_resolver
 

Macro Definition Documentation

◆ CFGFILE_VERSION

#define CFGFILE_VERSION   1

Definition at line 38 of file filename_resolver.cpp.

◆ ERRFLG_ALIAS

#define ERRFLG_ALIAS   (1)

Definition at line 42 of file filename_resolver.cpp.

◆ ERRFLG_ENVPATH

#define ERRFLG_ENVPATH   (4)

Definition at line 44 of file filename_resolver.cpp.

◆ ERRFLG_RELPATH

#define ERRFLG_RELPATH   (2)

Definition at line 43 of file filename_resolver.cpp.

◆ MASK_3D_RESOLVER

#define MASK_3D_RESOLVER   "3D_RESOLVER"

Definition at line 46 of file filename_resolver.cpp.

◆ RESOLVER_CONFIG

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

Definition at line 39 of file filename_resolver.cpp.

Function Documentation

◆ getHollerith()

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

Definition at line 852 of file filename_resolver.cpp.

853 {
854  aResult.clear();
855 
856  if( aIndex >= aString.size() )
857  {
858  std::ostringstream ostr;
859  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
860  wxString errmsg = "bad Hollerith string on line";
861  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
862  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
863 
864  return false;
865  }
866 
867  size_t i2 = aString.find( '"', aIndex );
868 
869  if( std::string::npos == i2 )
870  {
871  std::ostringstream ostr;
872  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
873  wxString errmsg = "missing opening quote mark in config file";
874  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
875  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
876 
877  return false;
878  }
879 
880  ++i2;
881 
882  if( i2 >= aString.size() )
883  {
884  std::ostringstream ostr;
885  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
886  wxString errmsg = "invalid entry (unexpected end of line)";
887  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
888  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
889 
890  return false;
891  }
892 
893  std::string tnum;
894 
895  while( aString[i2] >= '0' && aString[i2] <= '9' )
896  tnum.append( 1, aString[i2++] );
897 
898  if( tnum.empty() || aString[i2++] != ':' )
899  {
900  std::ostringstream ostr;
901  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
902  wxString errmsg = "bad Hollerith string on line";
903  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
904  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
905 
906  return false;
907  }
908 
909  std::istringstream istr;
910  istr.str( tnum );
911  size_t nchars;
912  istr >> nchars;
913 
914  if( (i2 + nchars) >= 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  if( nchars > 0 )
926  {
927  aResult = wxString::FromUTF8( aString.substr( i2, nchars ).c_str() );
928  i2 += nchars;
929  }
930 
931  if( i2 >= aString.size() || aString[i2] != '"' )
932  {
933  std::ostringstream ostr;
934  ostr << __FILE__ << ": " << __FUNCTION__ << ": " << __LINE__ << "\n";
935  wxString errmsg = "missing closing quote mark in config file";
936  ostr << " * " << errmsg.ToUTF8() << "\n'" << aString << "'";
937  wxLogTrace( MASK_3D_RESOLVER, "%s\n", ostr.str().c_str() );
938 
939  return false;
940  }
941 
942  aIndex = i2 + 1;
943  return true;
944 }
#define MASK_3D_RESOLVER

References MASK_3D_RESOLVER.

Referenced by FILENAME_RESOLVER::readPathList().

Variable Documentation

◆ mutex_resolver

std::mutex mutex_resolver
static