MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
IncludeParser Class Reference

#include <parsinc.h>

Inheritance diagram for IncludeParser:
Collaboration diagram for IncludeParser:

Classes

struct  MyInput
 

Public Member Functions

 IncludeParser (MathParser &MP, InputStream &streamIn, const char *initial_file="initial file")
 
virtual ~IncludeParser (void)
 
virtual void Close (void)
 
virtual const char * GetFileName (enum Delims Del=DEFAULTDELIM)
 
virtual HighParser::ErrOut GetLineData (void) const
 
- Public Member Functions inherited from HighParser
 HighParser (MathParser &MP, InputStream &streamIn)
 
virtual ~HighParser (void)
 
virtual const KeyTablePutKeyTable (const KeyTable &KT)
 
virtual int GetLineNumber (void) const
 
virtual MathParserGetMathParser (void)
 
bool IsDescription (void) const
 
Token GotDescription (void)
 
int GetDescription (void)
 
virtual void ExpectDescription (void)
 
virtual void ExpectArg (void)
 
virtual bool IsKeyWord (const char *sKeyWord)
 
virtual int IsKeyWord (void)
 
virtual bool IsArg (void)
 
virtual bool IsStringWithDelims (enum Delims Del=DEFAULTDELIM)
 
virtual const char * IsWord (const HighParser::WordSet &ws)
 
virtual void PutBackSemicolon (void)
 
virtual bool GetBool (bool bDefval=false)
 
virtual bool GetYesNo (bool &bRet)
 
virtual bool GetYesNoOrBool (bool bDefval=false)
 
virtual integer GetInt (integer iDefval=0)
 
template<class Range >
integer GetInt (integer iDefval, Range r)
 
virtual doublereal GetReal (const doublereal &dDefval=0.0)
 
template<class Range >
doublereal GetReal (const doublereal &dDefval, Range r)
 
virtual std::string GetString (const std::string &sDefVal)
 
virtual TypedValue GetValue (const TypedValue &v)
 
template<class Range >
TypedValue GetValue (const TypedValue &v, Range r)
 
virtual mbsleep_t GetTimeout (const mbsleep_t &DefVal)
 
virtual int GetWord (void)
 
virtual const char * GetString (unsigned flags=HighParser::NONE)
 
virtual const char * GetStringWithDelims (enum Delims Del=DEFAULTDELIM, bool escape=true)
 
template<class Range >
integer GetInt (int iDefVal, Range range)
 

Protected Member Functions

flag fCheckStack (void)
 
bool Include_int (void)
 
virtual void Eof (void)
 
- Protected Member Functions inherited from HighParser
virtual HighParser::Token FirstToken (void)
 
virtual void NextToken (const char *sFuncName)
 
int iGetDescription_int (const char *const s)
 
virtual void SetDelims (enum Delims Del, char &cLdelim, char &cRdelim) const
 
int ParseWord (unsigned flags=HighParser::NONE)
 
void PutbackWord (void)
 

Protected Attributes

std::stack< MyInput * > myinput
 
char * sCurrPath
 
char * sInitialPath
 
char * sCurrFile
 
- Protected Attributes inherited from HighParser
LowParser LowP
 
InputStreampIn
 
std::ifstream * pf
 
char sStringBuf [iDefaultBufSize]
 
char sStringBufWithSpaces [iDefaultBufSize]
 
MathParserMathP
 
const KeyTableKeyT
 
LowParser::Token CurrLowToken
 
Token CurrToken
 

Friends

struct IncludeDR
 

Additional Inherited Members

- Public Types inherited from HighParser
enum  Token {
  UNKNOWN = -1, DESCRIPTION, FIRSTARG, ARG,
  LASTARG, NOARGS, WORD, NUMBER,
  STRING, ENDOFFILE, LASTITEM
}
 
enum  Delims {
  UNKNOWNDELIM = -1, PLAINBRACKETS, SQUAREBRACKETS, CURLYBRACKETS,
  SINGLEQUOTE, DOUBLEQUOTE, DEFAULTDELIM, LASTDELIM
}
 
enum  {
  NONE = 0x00U, EATSPACES = 0x01U, ESCAPE = 0x02U, LOWER = 0x04U,
  UPPER = 0x08U
}
 
- Public Attributes inherited from HighParser
const char ESCAPE_CHAR
 

Detailed Description

Definition at line 112 of file parsinc.h.

Constructor & Destructor Documentation

IncludeParser::IncludeParser ( MathParser MP,
InputStream streamIn,
const char *  initial_file = "initial file" 
)

Definition at line 120 of file parsinc.cc.

References ASSERT, DEBUGCOUT, InitDescData(), MBDYN_EXCEPT_ARGS, NO_OP, PATH_MAX, SAFESTRDUP, sCurrFile, sCurrPath, and sInitialPath.

123 : HighParser(MP, streamIn),
124 sCurrPath(NULL),
125 sInitialPath(NULL),
126 sCurrFile(NULL)
127 {
128  ASSERT(sInitialFile != NULL);
129 #ifdef USE_INCLUDE_PARSER
130  char s[PATH_MAX];
131  if (getcwd(s, sizeof(s)) == NULL) {
132  silent_cerr("Error in getcwd()" << std::endl);
134  }
135  SAFESTRDUP(sCurrPath, s);
137  DEBUGCOUT("Current directory is \"" << sCurrPath << "\"" << std::endl);
138 
139  SAFESTRDUP(sCurrFile, sInitialFile);
140 #else /* !USE_INCLUDE_PARSER */
141  NO_OP;
142 #endif /* !USE_INCLUDE_PARSER */
143 
144  // NOTE: data will be destroyed when the underlying HighParser is destroyed (is this what we want?)
145  InitDescData();
146 }
#define PATH_MAX
Definition: parsinc.cc:49
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
static void InitDescData(void)
Definition: parsinc.cc:98
HighParser(MathParser &MP, InputStream &streamIn)
Definition: parser.cc:622
#define NO_OP
Definition: myassert.h:74
#define DEBUGCOUT(msg)
Definition: myassert.h:232
#define ASSERT(expression)
Definition: colamd.c:977
char * sInitialPath
Definition: parsinc.h:145
#define SAFESTRDUP(pnt, src)
Definition: mynewmem.h:707
char * sCurrPath
Definition: parsinc.h:144
char * sCurrFile
Definition: parsinc.h:146

Here is the call graph for this function:

IncludeParser::~IncludeParser ( void  )
virtual

Definition at line 149 of file parsinc.cc.

References Close().

150 {
152 }
virtual void Close(void)
Definition: parsinc.cc:155

Here is the call graph for this function:

Member Function Documentation

void IncludeParser::Close ( void  )
virtual

Reimplemented from HighParser.

Definition at line 155 of file parsinc.cc.

References ASSERT, DEBUGCOUT, MBDYN_EXCEPT_ARGS, myinput, HighParser::pf, IncludeParser::MyInput::pfile, HighParser::pIn, IncludeParser::MyInput::pis, SAFEDELETE, SAFEDELETEARR, sCurrFile, and sCurrPath.

Referenced by InverseSolver::Prepare(), Solver::Prepare(), and ~IncludeParser().

156 {
157  MyInput* pmi = NULL;
158  if (!myinput.empty()) {
159  pmi = myinput.top();
160  ASSERT(pmi != NULL);
161  /* Nota: deve esserci solo l'ultimo file */
162  ASSERT(pf != NULL);
163  ASSERT(pIn != NULL);
164 
165 #ifdef USE_INCLUDE_PARSER
166  ASSERT(sCurrPath != NULL);
167  ASSERT(sCurrFile != NULL);
168 #endif /* USE_INCLUDE_PARSER */
169 
170  if (pf != NULL) {
171  SAFEDELETE(pf);
172  }
173  if (pIn != NULL) {
174  SAFEDELETE(pIn);
175  }
176 
177 #ifdef USE_INCLUDE_PARSER
178  DEBUGCOUT("Leaving directory <" << sCurrPath
179  << ">, file <" << sCurrFile << '>' << std::endl);
180  if (sCurrPath != NULL) {
182  sCurrPath = NULL;
183  }
184  if (sCurrFile != NULL) {
186  sCurrFile = NULL;
187  }
188 #endif /* USE_INCLUDE_PARSER */
189 
190  pf = pmi->pfile;
191  pIn = pmi->pis;
192 
193 #ifdef USE_INCLUDE_PARSER
194  sCurrPath = pmi->sPath;
195  sCurrFile = pmi->sFile;
196  DEBUGCOUT("Entering directory \"" << sCurrPath
197  << "\", file \"" << sCurrFile << "\"" << std::endl);
198  if (chdir(sCurrPath)) {
199  silent_cerr("Error in chdir, path=\""
200  << sCurrPath << "\"" << std::endl);
202  }
203 #endif /* USE_INCLUDE_PARSER */
204 
205  /* pmi must be non NULL */
206  SAFEDELETE(pmi);
207 
208  myinput.pop();
209  }
210 
211  /* sCurrPath can be NULL if Close() has been already called */
212 #ifdef USE_INCLUDE_PARSER
213  if (sCurrPath != NULL) {
215  sCurrPath = NULL;
216  }
217  if (sCurrFile != NULL) {
219  sCurrFile = NULL;
220  }
221 #endif /* USE_INCLUDE_PARSER */
222 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
std::ifstream * pf
Definition: parser.h:420
std::stack< MyInput * > myinput
Definition: parsinc.h:143
#define DEBUGCOUT(msg)
Definition: myassert.h:232
#define ASSERT(expression)
Definition: colamd.c:977
InputStream * pIn
Definition: parser.h:419
char * sCurrPath
Definition: parsinc.h:144
char * sCurrFile
Definition: parsinc.h:146
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710
void IncludeParser::Eof ( void  )
protectedvirtual

Reimplemented from HighParser.

Definition at line 425 of file parsinc.cc.

References fCheckStack(), and MBDYN_EXCEPT_ARGS.

426 {
427  if (!fCheckStack()) {
429  }
430 }
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
flag fCheckStack(void)
Definition: parsinc.cc:225

Here is the call graph for this function:

flag IncludeParser::fCheckStack ( void  )
protected

Definition at line 225 of file parsinc.cc.

References ASSERT, DEBUGCOUT, MBDYN_EXCEPT_ARGS, myinput, HighParser::pf, IncludeParser::MyInput::pfile, HighParser::pIn, IncludeParser::MyInput::pis, SAFEDELETE, SAFEDELETEARR, sCurrFile, and sCurrPath.

Referenced by Eof().

226 {
227  MyInput* pmi = NULL;
228  if (!myinput.empty()) {
229  pmi = myinput.top();
230 
231  ASSERT(pmi != NULL);
232  /*
233  * Nota: se la stack e' piena, allora sia pf che pIn
234  * devono essere diversi da NULL; viceversa, se la stack
235  * e' vuota, pf deve essere NULL.
236  */
237  ASSERT(pf != NULL);
238  ASSERT(pIn != NULL);
239 #ifdef USE_INCLUDE_PARSER
240  ASSERT(sCurrPath != NULL);
241  ASSERT(sCurrFile != NULL);
242 #endif /* USE_INCLUDE_PARSER */
243 
244  SAFEDELETE(pf);
245  SAFEDELETE(pIn);
246 #ifdef USE_INCLUDE_PARSER
247  DEBUGCOUT("Leaving directory <" << sCurrPath
248  << ">, file <" << sCurrFile << '>' << std::endl);
250  sCurrPath = NULL;
252  sCurrFile = NULL;
253 #endif /* USE_INCLUDE_PARSER */
254 
255  pf = pmi->pfile;
256  pIn = pmi->pis;
257 #ifdef USE_INCLUDE_PARSER
258  sCurrPath = pmi->sPath;
259  sCurrFile = pmi->sFile;
260  DEBUGCOUT("Entering directory \"" << sCurrPath
261  << "\", file \"" << sCurrFile << "\"" << std::endl);
262  if (chdir(sCurrPath)) {
263  silent_cerr("Error in chdir, path=\""
264  << sCurrPath << "\"" << std::endl);
266  }
267 #endif /* USE_INCLUDE_PARSER */
268 
269  SAFEDELETE(pmi);
270 
271  myinput.pop();
272 
273  return flag(1);
274 
275  } else {
276  return flag(0);
277  }
278 }
long int flag
Definition: mbdyn.h:43
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
std::ifstream * pf
Definition: parser.h:420
std::stack< MyInput * > myinput
Definition: parsinc.h:143
#define DEBUGCOUT(msg)
Definition: myassert.h:232
#define ASSERT(expression)
Definition: colamd.c:977
InputStream * pIn
Definition: parser.h:419
char * sCurrPath
Definition: parsinc.h:144
char * sCurrFile
Definition: parsinc.h:146
#define SAFEDELETE(pnt)
Definition: mynewmem.h:710
const char * IncludeParser::GetFileName ( enum Delims  Del = DEFAULTDELIM)
virtual

Definition at line 673 of file parsinc.cc.

References HighParser::GetStringWithDelims(), iDefaultBufSize, resolve_filename(), SAFEDELETEARR, and HighParser::sStringBuf.

Referenced by AeroDynModule::AeroDynModule(), MBDynParser::C81Data_int(), LoadableElem::GetCalls(), SocketStreamOutputElemCreator::getSocketStreamOutParam(), Include_int(), module_init(), MBDynParser::ModuleLoad_int(), ChDirDR::Read(), VariableStepDR::Read(), FixedStepDR::Read(), JoystickDR::Read(), AnnElasticCLR< T, Tder >::Read(), AnnViscoElasticCLR< T, Tder >::Read(), GRAALLDamperCLR::Read(), ReadAerodynamicModal(), DataManager::ReadControl(), ReadElectric(), ReadExtFileHandler(), ReadExtFileHandlerEDGE(), ReadExtSocketHandler(), ReadGenericAerodynamicForce(), ReadModal(), ReadRTAISolver(), ReadSparseMappingMatrix(), ReadStreamDriveEcho(), ReadStreamOutEcho(), ReadStructExtForce(), and ReadStructMappingExtForce().

674 {
675  const char *s = GetStringWithDelims(Del);
676  if (s == 0) {
677  return 0;
678  }
679 
680  const char *stmp = resolve_filename(s);
681  if (stmp == NULL) {
682  return 0;
683 
684  } else {
685  if (strlen(stmp) >= iDefaultBufSize) {
686  SAFEDELETEARR(stmp);
687  return 0;
688  }
689  strcpy(sStringBuf, stmp);
690  SAFEDELETEARR(stmp);
691  }
692 
693  return sStringBuf;
694 }
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
virtual const char * GetStringWithDelims(enum Delims Del=DEFAULTDELIM, bool escape=true)
Definition: parser.cc:1228
const unsigned int iDefaultBufSize
Definition: parser.h:133
static char * resolve_filename(const char *filename_in)
Definition: parsinc.cc:579
char sStringBuf[iDefaultBufSize]
Definition: parser.h:423

Here is the call graph for this function:

HighParser::ErrOut IncludeParser::GetLineData ( void  ) const
virtual

Reimplemented from HighParser.

Definition at line 697 of file parsinc.cc.

References HighParser::GetLineNumber(), HighParser::ErrOut::iLineNumber, sCurrFile, sCurrPath, HighParser::ErrOut::sFileName, sInitialPath, and HighParser::ErrOut::sPathName.

Referenced by AeroDynModule::AeroDynModule(), asynchronous_machine::asynchronous_machine(), MBDynParser::C81Data_int(), MBDynParser::ConstitutiveLaw_int(), SocketStreamOutputElemCreator::createSocketStreamOutElem(), DataManager::DataManager(), MBDynParser::DriveCaller_int(), MBDynParser::GetC81Data(), LoadableElem::GetCalls(), MBDynParser::GetConstLaw1D(), MBDynParser::GetConstLaw3D(), MBDynParser::GetConstLaw6D(), GetDofOrder(), MBDynParser::GetDriveCaller(), MBDynParser::GetHydraulicFluid(), MBDynParser::GetMatAbs(), MBDynParser::GetMatR2vec(), MBDynParser::GetMatRel(), MBDynParser::GetOmeAbs(), MBDynParser::GetOmeRel(), MBDynParser::GetPosAbs(), MBDynParser::GetPosRel(), MBDynParser::GetRef(), MBDynParser::GetRotAbs(), MBDynParser::GetRotRel(), SocketStreamOutputElemCreator::getSocketStreamOutParam(), MBDynParser::GetTplDriveCaller(), MBDynParser::GetUnitVecAbs(), MBDynParser::GetUnitVecRel(), MBDynParser::GetVecAbs(), MBDynParser::GetVecRel(), MBDynParser::GetVelAbs(), MBDynParser::GetVelRel(), MBDynParser::HydraulicFluid_int(), HydrodynamicPlainBearing::HydrodynamicPlainBearing(), Include_int(), InlineFriction::InlineFriction(), LoadIncForce::LoadIncForce(), LoadIncNorm::LoadIncNorm(), module_init(), MBDynParser::ModuleLoad_int(), ModuleNonsmoothNode::ModuleNonsmoothNode(), DriveCallerRead::NeedDM(), ParseFriction(), ParseScalarFunction(), ParseShapeCoefficient(), ParseUserDefinedElem(), FlightGearStreamOutputReader::Read(), FlightGearFileDriveReader::Read(), ZeroTDCR< T >::Read(), FlightGearFileDriveCallerTypeReader::Read(), VariableStepDR::Read(), FixedStepDR::Read(), ScalarFuncGR::Read(), MultiStepDriveDCR::Read(), DummyCLR< T, Tder >::Read(), SwitchDriveDCR::Read(), NodeDistDCR::Read(), GiNaCDCR::Read(), HydraulicDamperCLR::Read(), StreamDR::Read(), PowerLawGR::Read(), MinMaxDriveDCR::Read(), Eu2PhiDCR::Read(), LogarithmicGR::Read(), HuntCrossleyCLR::Read(), TDCLWR< T, Tder >::Read(), CLArray1DR::Read(), MotionContentTypeReader::Read(), ValuesContentTypeReader::Read(), CLArray3DR::Read(), ContContactCLR::Read(), CLArray6DR::Read(), MusclePennestriCLR::Read(), FactorTSR::Read(), LinearElasticCLR< T, Tder >::Read(), NLSFViscoElasticCLR< T, Tder, Typ >::Read(), LoadableElemRead::Read(), NLPViscoElasticCLR< T, Tder, Typ >::Read(), LogSFR::Read(), AnnElasticCLR< T, Tder >::Read(), AnnViscoElasticCLR< T, Tder >::Read(), InverseSquareElasticCLR::Read(), ExpSFR::Read(), LogElasticCLR< T, Tder >::Read(), DoubleLinearElasticCLR< T, Tder >::Read(), IsotropicHardeningCLR< T, Tder >::Read(), ContContact3DCLR::Read(), ContactElasticCLR< T, Tder >::Read(), SymbolicCLR< T, Tder >::Read(), ChebychevSFR::Read(), LinearViscousCLR< T, Tder >::Read(), LinearViscoElasticCLR< T, Tder >::Read(), DoubleLinearViscoElasticCLR< T, Tder >::Read(), TurbulentViscoElasticCLR< T, Tder >::Read(), LinearBiStopCLR< T, Tder >::Read(), ScalarFunctionIsotropicCLR< T, Tder >::Read(), ScalarFunctionOrthotropicCLR< T, Tder >::Read(), DoubleStepDCR::Read(), RampDCR::Read(), DoubleRampDCR::Read(), FourierSeriesDCR::Read(), PiecewiseLinearDCR::Read(), DofDCR::Read(), SimulationEntityDCR::Read(), ElementDCR::Read(), NodeDCR::Read(), FileDCR::Read(), PeriodicDCR::Read(), PostponedDCR::Read(), ReadAeroData(), ReadAerodynamicBeam(), ReadAerodynamicBeam2(), ReadAerodynamicBody(), ReadAerodynamicCustomOutput(), ReadAerodynamicModal(), ReadAirProperties(), ReadAuthMethod(), ReadBeam(), ReadBeam2(), ReadBeamCustomOutput(), ReadBody(), ReadBufferStreamDrive(), ReadBufferStreamElem(), ReadBulk(), ReadC81MultipleAeroData(), ReadCL1D(), ReadCL3D(), ReadCL6D(), DataManager::ReadControl(), InverseSolver::ReadData(), Solver::ReadData(), ReadDC1D(), ReadDC3D(), ReadDC3x3D(), ReadDC6D(), ReadDC6x6D(), ReadDriveCallerData(), ReadDriveData(), DataManager::ReadDrivers(), ReadElectric(), DataManager::ReadElem(), DataManager::ReadElems(), ReadExtFileHandler(), ReadExtFileHandlerEDGE(), ReadExtFileParams(), ReadExtForce(), ReadExtSocketHandler(), ReadFF(), FlightGearStreamOutputReader::ReadFlightGearScalarValues(), ReadForce(), ReadGenel(), ReadGenericAerodynamicForce(), ReadGravity(), ReadGustData(), ReadHBeam(), ReadHydraulicElem(), ReadHydraulicFluid(), ReadInducedVelocity(), ReadJoint(), ReadJointRegularization(), ReadMembraneConstLaw(), ReadModal(), ReadModalExtForce(), ReadModalForce(), ReadModalMappingExtForce(), DataManager::ReadNode(), DataManager::ReadNodes(), DataManager::ReadOneElem(), ReadOptionalOrientationDescription(), ReadOrientationDescription(), DriveCallerRead::ReadOutput(), ReadOutputElem(), ReadResSet(), ReadResSets(), ReadRotor(), ReadRotorData(), ReadRTAISolver(), ReadRTMBDynInDrive(), ReadRTParams(), ReadRTSolver(), DataManager::ReadScalarAlgebraicNode(), ReadScalarDof(), ReadScalarValue(), ReadScalarValues(), ReadShape(), ReadShellConstLaw(), ReadSparseMappingMatrix(), ReadStreamContent(), ReadStreamContentModifier(), ReadStreamDriveEcho(), ReadStreamDriveModifier(), ReadStreamOutEcho(), ReadStructExtForce(), ReadStructMappingExtForce(), ReadStructNode(), ReadStructuralForce(), ReadThermal(), ReadUniform(), ReadUnsteadyFlag(), ReadVariableBody(), MBDynParser::Reference_int(), RunMBDyn(), MBDynParser::ScalarFunction_int(), ShockAbsorberConstitutiveLaw< doublereal, doublereal >::ShockAbsorberConstitutiveLaw(), MBDynParser::TplDriveCaller_int(), and Wheel2::Wheel2().

698 {
699  ErrOut LineData;
700  LineData.sFileName = sCurrFile;
701  LineData.sPathName = (strcmp(sCurrPath, sInitialPath) == 0) ? 0 : sCurrPath;
702  LineData.iLineNumber = GetLineNumber();
703  return LineData;
704 }
char * sInitialPath
Definition: parsinc.h:145
char * sCurrPath
Definition: parsinc.h:144
virtual int GetLineNumber(void) const
Definition: parser.cc:674
char * sCurrFile
Definition: parsinc.h:146

Here is the call graph for this function:

bool IncludeParser::Include_int ( void  )
protected

Definition at line 281 of file parsinc.cc.

References buf, c, HighParser::CurrToken, DEBUGCERR, DEBUGCOUT, HighParser::DESCRIPTION, DIR_SEP, GetFileName(), GetLineData(), HighParser::IsArg(), MBDYN_EXCEPT_ARGS, myinput, PATH_MAX, HighParser::pf, HighParser::pIn, SAFEDELETEARR, SAFENEWWITHCONSTRUCTOR, SAFESTRDUP, sCurrFile, and sCurrPath.

Referenced by IncludeDR::Read().

282 {
283  // if (FirstToken() == UNKNOWN) {
284  if (!IsArg()) {
285  silent_cerr("Parser error in IncludeParser::Include_int(),"
286  " colon expected at line " << GetLineData()
287  << std::endl);
289  }
290 
291  const char* sfname = GetFileName();
292 
293  if (sfname != 0) {
294  struct stat s;
295 
296  if (stat(sfname, &s)) {
297  int save_errno = errno;
298 
299  silent_cerr("Cannot stat file <" << sfname << "> "
300  "at line " << GetLineData() << ": "
301  << save_errno
302  << " (" << strerror(save_errno) << ")"
303  << std::endl);
304  throw ErrFile(MBDYN_EXCEPT_ARGS);
305  }
306 
307  if (!S_ISREG(s.st_mode)) {
308  silent_cerr("File <" << sfname << "> "
309  "at line " << GetLineData() << ": "
310  "not a regular file?" << std::endl);
311  throw ErrFile(MBDYN_EXCEPT_ARGS);
312  }
313 
314  if (!(s.st_mode & S_IRUSR)) {
315  silent_cerr("File <" << sfname << "> "
316  "at line " << GetLineData() << ": "
317  "no read permissions?" << std::endl);
318  throw ErrFile(MBDYN_EXCEPT_ARGS);
319  }
320  }
321 
322  std::ifstream *pf_old = pf;
323  InputStream *pIn_old = pIn;
324  char *sOldPath = sCurrPath;
325  char *sOldFile = sCurrFile;
326 
327  pf = NULL;
328  pIn = NULL;
329 
330 #ifdef _WIN32
331  // open the file in non translated mode in order not to break seek operations
332  SAFENEWWITHCONSTRUCTOR(pf, std::ifstream, std::ifstream(sfname, std::ios::binary));
333 #else
334  SAFENEWWITHCONSTRUCTOR(pf, std::ifstream, std::ifstream(sfname));
335 #endif
336  if (!(*pf)) {
337 #ifdef DEBUG
338  char *buf = getcwd(NULL, 0);
339  if (buf != NULL) {
340  DEBUGCERR("Current directory \"" << buf << "\""
341  << std::endl);
342  free(buf);
343  }
344 #endif /* DEBUG */
345 
346  /* restore */
347  pf = pf_old;
348  pIn = pIn_old;
349  sCurrPath = sOldPath;
350  sCurrFile = sOldFile;
351 
352  silent_cerr("Invalid file <" << sfname << "> "
353  "at line " << GetLineData() << std::endl);
354  throw ErrFile(MBDYN_EXCEPT_ARGS);
355  }
356 
358 
359  /* Cambio di directory */
360 #ifdef USE_INCLUDE_PARSER
361  sCurrPath = NULL;
362  sCurrFile = NULL;
363  char* stmp = NULL;
364  SAFESTRDUP(stmp, sfname);
365  char* s = (char*)stmp + strlen(sfname);
366  while (--s >= stmp) {
367  if (s[0] == DIR_SEP) {
368  char c = s[1];
369  s[1] = '\0';
370  if (chdir(stmp)) {
371  silent_cerr("Error in chdir, path="
372  << stmp << std::endl);
374  }
375  char p[PATH_MAX];
376  if (getcwd(p, sizeof(p)) == NULL) {
377  silent_cerr("Error in getcwd()" << std::endl);
378  SAFEDELETEARR(stmp);
380  }
381  SAFESTRDUP(sCurrPath, p);
382  DEBUGCOUT("Current directory is \"" << sCurrPath
383  << "\"" << std::endl);
384 
385  s[1] = c;
386  break;
387  }
388  }
389  s++;
390  SAFESTRDUP(sCurrFile, s);
391  DEBUGCOUT("Opening file <" << sCurrFile << '>' << std::endl);
392 
393  SAFEDELETEARR(stmp);
394 
395  if (sCurrPath == NULL) {
396  char s[PATH_MAX];
397  if (getcwd(s, sizeof(s)) == NULL) {
398  silent_cerr("Error in getcwd()" << std::endl);
400  }
401  SAFESTRDUP(sCurrPath, s);
402  DEBUGCOUT("Current directory is \"" << sCurrPath
403  << "\"" << std::endl);
404  }
405 #endif /* USE_INCLUDE_PARSER */
406 
407  MyInput* pmi = NULL;
408 #ifdef USE_INCLUDE_PARSER
410  MyInput,
411  MyInput(pf_old, pIn_old, sOldPath, sOldFile));
412 #else /* !USE_INCLUDE_PARSER */
413  SAFENEWWITHCONSTRUCTOR(pmi, MyInput, MyInput(pf_old, pIn_old));
414 #endif /* !USE_INCLUDE_PARSER */
415 
416  myinput.push(pmi);
417 
418  /* FIXME: mettere un test se c'e' il punto e virgola? */
420 
421  return true;
422 }
#define PATH_MAX
Definition: parsinc.cc:49
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define SAFEDELETEARR(pnt)
Definition: mynewmem.h:713
virtual const char * GetFileName(enum Delims Del=DEFAULTDELIM)
Definition: parsinc.cc:673
std::ifstream * pf
Definition: parser.h:420
Token CurrToken
Definition: parser.h:435
#define DEBUGCERR(msg)
Definition: myassert.h:235
std::stack< MyInput * > myinput
Definition: parsinc.h:143
#define DEBUGCOUT(msg)
Definition: myassert.h:232
const char DIR_SEP
Definition: filename.h:88
#define SAFENEWWITHCONSTRUCTOR(pnt, item, constructor)
Definition: mynewmem.h:698
static std::stack< cleanup * > c
Definition: cleanup.cc:59
virtual bool IsArg(void)
Definition: parser.cc:807
InputStream * pIn
Definition: parser.h:419
#define SAFESTRDUP(pnt, src)
Definition: mynewmem.h:707
char * sCurrPath
Definition: parsinc.h:144
static doublereal buf[BUFSIZE]
Definition: discctrl.cc:333
virtual HighParser::ErrOut GetLineData(void) const
Definition: parsinc.cc:697
char * sCurrFile
Definition: parsinc.h:146

Here is the call graph for this function:

Friends And Related Function Documentation

friend struct IncludeDR
friend

Definition at line 113 of file parsinc.h.

Member Data Documentation

std::stack<MyInput *> IncludeParser::myinput
protected

Definition at line 143 of file parsinc.h.

Referenced by Close(), fCheckStack(), and Include_int().

char* IncludeParser::sCurrFile
protected

Definition at line 146 of file parsinc.h.

Referenced by Close(), fCheckStack(), GetLineData(), Include_int(), and IncludeParser().

char* IncludeParser::sCurrPath
protected

Definition at line 144 of file parsinc.h.

Referenced by Close(), fCheckStack(), GetLineData(), Include_int(), and IncludeParser().

char* IncludeParser::sInitialPath
protected

Definition at line 145 of file parsinc.h.

Referenced by GetLineData(), and IncludeParser().


The documentation for this class was generated from the following files: