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 39 of file filename_resolver.cpp.

◆ ERRFLG_ALIAS

#define ERRFLG_ALIAS   (1)

Definition at line 43 of file filename_resolver.cpp.

◆ ERRFLG_ENVPATH

#define ERRFLG_ENVPATH   (4)

Definition at line 45 of file filename_resolver.cpp.

◆ ERRFLG_RELPATH

#define ERRFLG_RELPATH   (2)

Definition at line 44 of file filename_resolver.cpp.

◆ MASK_3D_RESOLVER

#define MASK_3D_RESOLVER   "3D_RESOLVER"

Definition at line 47 of file filename_resolver.cpp.

◆ RESOLVER_CONFIG

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

Definition at line 40 of file filename_resolver.cpp.

Function Documentation

◆ getHollerith()

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

Definition at line 859 of file filename_resolver.cpp.

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

References MASK_3D_RESOLVER.

Referenced by FILENAME_RESOLVER::readPathList().

Variable Documentation

◆ mutex_resolver

std::mutex mutex_resolver
static