52 for (cIn = In.
get(); isspace(cIn); cIn = In.
get()) {
68 for (cIn = In.
get(); cIn !=
'\n'; cIn = In.
get()) {
94 }
else if (cIn ==
'*') {
95 for (cIn = In.
get(); !In.
eof(); cIn = In.
get()) {
106 }
else if (cIn ==
'/') {
112 silent_cerr(
"warning: '/*' inside a comment "
152 for (cIn = In.
get(); !In.
eof(); cIn = In.
get()) {
197 if (isalpha(cIn) || cIn ==
'_') {
255 : sKeyWords(0), oldKey(0), HP(hp)
273 for (
int iCnt = 0;
sKeyWords[iCnt]; iCnt++) {
274 if (strcasecmp(
sKeyWords[iCnt], sToFind) == 0) {
293 bool IsWord(
const std::string& s)
const {
303 pedantic_cout(
"registering description \"" << name <<
"\"" << std::endl);
304 return DescFuncMap.insert(DescFuncMapType::value_type(name, rf)).second;
319 silent_cerr(
"Parser error in ReadDescription(),"
320 " colon or semicolon expected after description at line "
325 bRC = func->second->Read(HP);
328 silent_cerr(
"semicolon expected at line " << HP.
GetLineData() << std::endl);
355 silent_cout(prefix <<
' ' << v);
362 silent_cout(std::endl);
376 silent_cout(
"math parser symbol table at line "
384 for (MathParser::NameSpaceMap::const_iterator i = ns.begin(); i != ns.end(); ++i) {
385 const std::string& sName = i->second->sGetName();
386 const Table *pT = i->second->GetTable();
388 silent_cout(
"namespace \"" << sName <<
"\" symbol table at line "
390 << *pT << std::endl);
401 silent_cerr(
"PrintSymbolTableDR::Read(): warning, unable to find namespace \"" << sName <<
"\" at line "
407 silent_cerr(
"PrintSymbolTableDR::Read(): warning, namespace \"" << sName <<
"\" "
408 "has no symbol table at line " << HP.
GetLineData() << std::endl);
411 silent_cout(
"namespace \"" << sName <<
"\" symbol table at line "
413 << *pT << std::endl);
430 silent_cerr(
"Parser error in SetDR::Read(), "
431 "arg expected at line "
452 silent_cerr(
"Parser error in SetEnvDR::Read(), "
453 "arg(s) expected at line "
461 overwrite = b ? 1 : 0;
466 silent_cerr(
"unable to get AVA for \"setenv\" at line "
471 char *avasep = std::strchr(const_cast<char *>(ava),
'=');
472 if (avasep == NULL) {
475 #elif defined(HAVE_PUTENV)
477 silent_cerr(
"unable to unset the environment variable "
478 "\"" << ava <<
"\" at line "
486 silent_cerr(
"illegal AVA \"" << ava
494 bool bPresent(getenv(ava) != NULL);
495 int rc = setenv(ava, avasep, overwrite);
497 silent_cerr(
"unable to set the environment variable \""
498 << ava <<
"\" to \"" << avasep
504 if (bPresent && overwrite == 0) {
505 silent_cout(
"Environment variable \"" << ava
506 <<
"\" _not_ overwritten with \"" << avasep
507 <<
"\" (current value is \"" << getenv(ava)
511 }
else if (!bPresent) {
512 silent_cout(
"Environment variable \"" << ava
513 <<
"\" set to \"" << avasep
518 silent_cout(
"Environment variable \"" << ava
519 <<
"\" overwritten to \"" << avasep
524 #else // ! HAVE_SETENV
525 silent_cerr(
"SetEnvDR::Read(): warning, setenv() not available; ignored at line "
527 #endif // !HAVE_SETENV
540 silent_cerr(
"Parser error in ExitDR::Read(),"
541 " semicolon expected at line "
578 silent_cerr(
"DestroyDescData() called once too many" << std::endl);
598 static std::stack<const HighParser *>
pHP;
606 return pHP.top()->GetLineData();
616 out <<
pHP.top()->GetLineData();
713 silent_cerr(
"Parser error in HighParser::iGetDescription_int(), "
714 "semicolon expected at line "
734 silent_cerr(
"Parser error in HighParser::GetDescription, "
735 "invalid call to GetDescription at line "
746 goto restart_parsing;
749 silent_cerr(
"Parser error in HighParser::GetDescription, "
750 <<
"keyword expected at line "
759 goto restart_parsing;
835 silent_cerr(
"Parser error in "
836 << sFuncName <<
", missing separator at line "
853 if (!isalpha(cIn) && cIn !=
'_') {
858 *sBufWithSpaces++ = cIn;
861 *sBuf++ = tolower(cIn);
863 }
else if (flags &
UPPER) {
864 *sBuf++ = toupper(cIn);
870 for (cIn =
pIn->
get(); isalnum(cIn) || cIn ==
'_' || isspace(cIn); cIn =
pIn->
get()) {
871 *sBufWithSpaces++ = cIn;
881 *sBuf++ = tolower(cIn);
883 }
else if (flags & UPPER) {
884 *sBuf++ = toupper(cIn);
893 *sBufWithSpaces =
'\0';
912 const char sFuncName[] =
"HighParser::IsKeyWord()";
942 const char sFuncName[] =
"HighParser::IsKeyWord()";
979 const char sFuncName[] =
"HighParser::IsWord()";
1085 const char sFuncName[] =
"HighParser::GetWord()";
1088 silent_cerr(
"Parser error in "
1089 << sFuncName <<
", keyword arg expected at line "
1096 silent_cerr(
"Parser error in "
1097 << sFuncName <<
", keyword expected at line "
1115 const char sFuncName[] =
"HighParser::GetString()";
1117 pedantic_cout(
"use of deprecated method \"GetString\" at line"
1121 silent_cerr(
"Parser error in "
1122 << sFuncName <<
", string arg expected at line "
1132 while (isspace(cIn =
pIn->
get())) {
1142 for (cIn =
pIn->
get(); cIn !=
',' && cIn !=
';'; cIn =
pIn->
get()) {
1212 char cLdelim, cRdelim;
1224 return (cIn == cLdelim);
1230 const char sFuncName[] =
"HighParser::GetStringWithDelims()";
1233 silent_cerr(
"Parser error in "
1234 << sFuncName <<
", string arg expected at line "
1242 char cLdelim, cRdelim;
1251 if (cIn == cLdelim) {
1252 for (cIn =
pIn->
get(); cIn != cRdelim; cIn =
pIn->
get()) {
1276 }
else if (cIn ==
'\r') {
1280 goto escaped_generic;
1284 }
else if ((cIn ==
ESCAPE_CHAR) || (cIn == cRdelim)) {
1306 for (i = 0; i < 2; i++) {
1307 int shift = 4*(1 - i), h = 0;
1314 if (hex[i] >=
'0' && hex[i] <=
'9') {
1316 }
else if (hex[i] >=
'a' && hex[i] <=
'f') {
1318 }
else if (hex[i] >=
'A' && hex[i] <=
'F') {
1321 silent_cerr(
"invalid escape sequence "
1322 "\"\\" << hex <<
"\" "
1346 }
else if (cIn ==
',' || cIn ==
';') {
1353 silent_cerr(
"Parser error in "
1354 << sFuncName << std::endl
1355 <<
"first non-blank char at line "
1356 <<
GetLineData() <<
" isn't a valid left-delimiter"
std::map< std::string, NameSpace * > NameSpaceMap
static const char ONE_LINE_REMARK
#define MBDYN_EXCEPT_ARGS
#define DEBUGCOUTFNAME(fname)
virtual integer GetInt(integer iDefval=0)
bool IsDescription(void) const
virtual const char * IsWord(const HighParser::WordSet &ws)
virtual void ExpectArg(void)
LowParser(HighParser &hp)
bool SetDescData(const std::string &name, DescRead *rf)
virtual bool GetBool(bool bDefval=false)
int mbsleep_sleep2real(const mbsleep_t *t, doublereal *d)
bool ReadDescription(HighParser &HP, const std::string &desc)
virtual HighParser::ErrOut GetLineData(void) const
#define SAFEDELETEARR(pnt)
std::ostream & operator<<(std::ostream &out, const HighParser::ErrOut &err)
HighParser(MathParser &MP, InputStream &streamIn)
static const HighParser::ErrOut unknownErr
virtual ~HighParser(void)
integer iGetInt(void) const
char sStringBufWithSpaces[iDefaultBufSize]
Token GotDescription(void)
virtual bool GetYesNoOrBool(bool bDefval=false)
virtual TypedValue GetValue(const TypedValue &v)
virtual void ExpectDescription(void)
void func(const T &u, const T &v, const T &w, doublereal e, T &f)
static DescWordSetType DescWordSet
std::map< std::string, DescRead *, ltstrcase > DescFuncMapType
virtual const KeyTable * PutKeyTable(const KeyTable &KT)
int Find(const char *sToFind) const
Token GetToken(InputStream &In)
bool Read(HighParser &HP)
LowParser::Token CurrLowToken
bool Read(HighParser &HP)
virtual bool IsKeyWord(const char *sKeyWord)
static DescFuncMapType DescFuncMap
virtual const char * GetStringWithDelims(enum Delims Del=DEFAULTDELIM, bool escape=true)
const NameSpaceMap & GetNameSpaceMap(void) const
const unsigned int iDefaultBufSize
void PackWords(InputStream &In)
const std::string & GetString(void) const
virtual MathParser & GetMathParser(void)
static int skip_remarks(HighParser &HP, InputStream &In, char &cIn)
static void InitDescData(void)
virtual mbsleep_t GetTimeout(const mbsleep_t &DefVal)
#define ASSERT(expression)
virtual HighParser::Token FirstToken(void)
std::ostream & mbdyn_print_line_data(std::ostream &out)
bool Read(HighParser &HP)
virtual bool IsWord(const std::string &s) const =0
KeyTable(HighParser &hp, const char *const sTable[])
static std::stack< cleanup * > c
virtual std::string GetString(const std::string &sDefVal)
NameSpace * GetNameSpace(const std::string &name) const
virtual bool GetYesNo(bool &bRet)
virtual int IsKeyWord(void)
doublereal dGetReal(void) const
virtual void NextToken(const char *sFuncName)
virtual bool IsStringWithDelims(enum Delims Del=DEFAULTDELIM)
virtual int GetWord(void)
int iGetDescription_int(const char *const s)
HighParser::ErrOut mbdyn_get_line_data(void)
#define SAFENEWARR(pnt, item, sz)
virtual int GetLineNumber(void) const
virtual void SetDelims(enum Delims Del, char &cLdelim, char &cRdelim) const
virtual Table * GetTable(void)=0
char sStringBuf[iDefaultBufSize]
int mbsleep_real2sleep(doublereal d, mbsleep_t *t)
static std::stack< const HighParser * > pHP
Table & GetSymbolTable(void) const
virtual void PutBackSemicolon(void)
bool Read(HighParser &HP)
static unsigned desc_done
static void DestroyDescData(void)
int ParseWord(unsigned flags=HighParser::NONE)
bool IsWord(const std::string &s) const
virtual doublereal GetReal(const doublereal &dDefval=0.0)