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

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

References MASK_3D_RESOLVER.

Referenced by FILENAME_RESOLVER::readPathList().

Variable Documentation

◆ mutex_resolver

std::mutex mutex_resolver
static