diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index b709acf..f4a62a0 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -49,7 +49,6 @@ target_include_directories(parafeed PUBLIC $) # install target set(header_list - boolError.h clbool.h clconvert.h clError.h @@ -96,7 +95,7 @@ bison_target(ShellParser ${CMAKE_CURRENT_BINARY_DIR}/shell.tab.cc COMPILE_FLAGS "-p sh_ -o shell.tab.cc" DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/shell.tab.h) -# set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/shell.tab.c PROPERTY LANGUAGE CXX)) + set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/shell.tab.c PROPERTY LANGUAGE CXX) flex_target(ShellScanner shell.l ${CMAKE_CURRENT_BINARY_DIR}/shell.cc @@ -112,10 +111,12 @@ bison_target(CalcParser ${CMAKE_CURRENT_BINARY_DIR}/y.tab.c COMPILE_FLAGS "-p calc_" DEFINES_FILE ${CMAKE_CURRENT_BINARY_DIR}/y.tab.h) + set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/shell.tab.c PROPERTY LANGUAGE CXX) flex_target(CalcScanner calc/lex.l ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c COMPILE_FLAGS "-Pcalc_") + #set_property(SOURCE ${CMAKE_CURRENT_BINARY_DIR}/lex.yy.c PROPERTY LANGUAGE CXX) add_flex_bison_dependency(CalcScanner CalcParser) target_sources(parafeed PRIVATE ${BISON_CalcParser_OUTPUTS} ${FLEX_CalcScanner_OUTPUTS}) @@ -148,6 +149,7 @@ set(sh_sources yyerror.cc minmatch.cc isBool.cc) + foreach(source IN LISTS sh_sources) set_property(SOURCE ${source} PROPERTY LANGUAGE CXX) endforeach() diff --git a/code/ErrorObj.h b/code/ErrorObj.h index 9dc7003..76bbadb 100644 --- a/code/ErrorObj.h +++ b/code/ErrorObj.h @@ -21,10 +21,11 @@ #define ERROROBJ_H #include #include +#include using namespace std; -class ErrorObj{ +class ErrorObj: public std::exception{ public: enum {Informational=100,Recoverable,Severe,Fatal}; ErrorObj():Id(), Msg(), Src(), Message(),Level(0) diff --git a/code/SetVar.cc b/code/SetVar.cc index 2eaaf12..79302e2 100644 --- a/code/SetVar.cc +++ b/code/SetVar.cc @@ -23,7 +23,7 @@ #include #include #include -#include +#include #ifdef __cplusplus #include #include @@ -154,23 +154,31 @@ int UnsetVar(Symbol *S, int setFactoryDefaults) } else { - // Matched=(clIsTrue(newval) || clIsFalse(newval)); Matched=0; try { if (clIsTrue(newval)==1) {Matched=1;} else if (clIsFalse(newval)==1) {Matched=1;} } - catch (boolError& x) + catch (clBoolParsingError& x) { throw(x); } os << newval; } - // os << b; newval=os.str(); } + else if (ISSET(S->Attributes, CL_INTEGERTYPE)|| + ISSET(S->Attributes, CL_FLOATTYPE)) + { + double d; + if ((n=calc((char *)v,&d)) < 0) + { + std::string mesg("Error in parsing value of \""+std::string(S->Name)+"\""); + throw(clNumParsingError(mesg.c_str(),"###Error",CL_SEVERE)); + } + } else if (n > 0) { Matched=0; @@ -199,7 +207,7 @@ void SetVal(const char *v, Symbol *S, int i) { string vv; string trimmed=trim(string(v)); - // stripwhite(v); + try { VerifyVal(trimmed.c_str(),S,vv); diff --git a/code/boolError.h b/code/boolError.h deleted file mode 100644 index c914bd4..0000000 --- a/code/boolError.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2000-2012, 2013 S. Bhatnagar (bhatnagar dot sanjay at gmail dot com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ -//-*-C++-*- -// -// $Id: clError.h,v 2.1 1999/09/15 12:00:51 sanjay Exp sanjay $ -// -#if !defined(BOOLERROROBJ_H) -#define BOOLERROROBJ_H -#ifdef __cplusplus - -/*-------------------------------------------------------------------- - The C++ object thrown in case of error. It's derived from ErrorObj - class, which is the baseclass for all error objects. ---------------------------------------------------------------------*/ - -#include -class boolError: public clError -{ -public: - boolError(): clError() {}; - boolError(const char *m, const char *i, int l=0): clError(m,i,l) {}; - boolError(const boolError& that) - {this->Msg = that.Msg; this->Id = that.Id; this->Level = that.Level;} -}; -#endif /* __cplusplus */ - -#endif /* CLERROR_H */ diff --git a/code/calc/calc.y b/code/calc/calc.y index 2a52c89..8d93a51 100644 --- a/code/calc/calc.y +++ b/code/calc/calc.y @@ -22,7 +22,7 @@ #include #include #include - +#include static double fooUserFunc(char* s) { return 0.0; } @@ -67,6 +67,7 @@ expr: NUMBER { $$ = $1; } $$ = (*($1->ufunc))($1->Name); if ($1->Name) free($1->Name); $1->Name = NULL; + return -2; } else { diff --git a/code/calc/lex.l b/code/calc/lex.l index 1dbb4e3..d9a94bd 100644 --- a/code/calc/lex.l +++ b/code/calc/lex.l @@ -31,8 +31,8 @@ int Calc_index; /*----------------------------------------------------------------------*/ int calc_error(char *s) { - /* ywarn(s, (char *) 0);*/ - return 1; + ywarn(s, (char *) 0); + return 1; } /*----------------------------------------------------------------------*/ int ywarn(char *s, char *t) @@ -83,7 +83,7 @@ int Calc_index=0; #define unput(C) {Calc_line[Calc_index==0?Calc_index:--Calc_index]=C;} #define output(C) {fprintf(stderr,"%c",C);} #define ECHON /* {fprintf(stderr,"\"\\n\"\n");}*/ -#define ECHO /*{fprintf(stderr,"\"%s\"\n",yytext);}*/ +#define ECHOSS(S) /* {fprintf(stderr,"%s: \"%s\"\n",S,yytext);}*/ /*yy_scan_buffer(Calc_line,strlen(Calc_line));*/ @@ -156,12 +156,13 @@ DANG ({DDEG}?({SPACE}?{DMIN})?({SPACE}?{DSEC})?) } {HEXD} { int i; - ECHO; + ECHOSS("HEXD"); sscanf(yytext+2,"%x",&i);calc_lval.val = i; INCR_INDEX; return NUMBER; } {HANG} {/* Numer in the hour angle format */ + ECHOSS("HANG"); float a[3]; split3(yytext,yyleng,"hms",a); calc_lval.val = (a[0]*60.0+a[1])*60.0+a[2]; @@ -170,6 +171,7 @@ DANG ({DDEG}?({SPACE}?{DMIN})?({SPACE}?{DSEC})?) return NUMBER; } {DANG} {/* Number in the angular format */ + ECHOSS("DANG"); float a[3]; split3(yytext,yyleng,"d\'\"",a); calc_lval.val = (a[0]*60.0+a[1])*60.0+a[2]; @@ -178,36 +180,37 @@ DANG ({DDEG}?({SPACE}?{DMIN})?({SPACE}?{DSEC})?) return NUMBER; } {CREAL} { - ECHO; + ECHOSS("CREAL"); sscanf(yytext,"%lf",&calc_lval.val); INCR_INDEX; return NUMBER; } {FREAL} { float m,e; char c; - ECHO; + ECHOSS("FREAL"); sscanf(yytext, "%f%c%f", &m,&c,&e); calc_lval.val = m*pow(10.0,e); INCR_INDEX; return NUMBER; } atan2 { Calc_Symbol *s; /* A patch for atan2...*/ - ECHO; + ECHOSS("atan2"); INCR_INDEX; if ((s=calcget(yytext))!=0) { calc_lval.symb=s; return s->type;} } [a-zA-Z]+[a-zA-Z0-9]* { Calc_Symbol *s; - ECHO; INCR_INDEX; if ((s=calcget(yytext))!=0) { + ECHOSS("A-Z"+s->type); calc_lval.symb=s; return s->type; } else { + ECHOSS("A-Z UserFunc"); s2.ufunc = UserFunc; s2.Name = (char *)malloc(strlen(yytext)+1); strcpy(s2.Name,yytext); @@ -216,7 +219,4 @@ atan2 { Calc_Symbol *s; /* A patch for atan2...*/ } } \n {ECHON;return '\n';} -. {ECHO;return yytext[0];} - - - +. {ECHOSS(".");return yytext[0];} diff --git a/code/callbacks.cc b/code/callbacks.cc index 0888951..a9012bf 100644 --- a/code/callbacks.cc +++ b/code/callbacks.cc @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include //#include diff --git a/code/cl.h b/code/cl.h index f99aa54..3447ae4 100644 --- a/code/cl.h +++ b/code/cl.h @@ -230,7 +230,7 @@ int dowarranty(char *); // #endif //int clparseVal(Symbol *, int *, double *); #ifdef __cplusplus -void reportParseError(const Symbol& S, const int& N); +void reportParseError(clError& excp,const Symbol& S, const int& N); int PrintVals(FILE *f,Symbol *S,unsigned int newline=1); #endif int PrintKey(FILE *f, Symbol *S); diff --git a/code/clError.h b/code/clError.h index 36daa56..2a7a174 100644 --- a/code/clError.h +++ b/code/clError.h @@ -43,9 +43,32 @@ class clError: public ErrorObj this->Msg = that.Msg; this->Id = that.Id; this->Level = that.Level; - } + }; + void set(const string& m, const string& i, int l=0) + { + Msg=m; Id=i; Level=l; + }; + ~clError() {}; +}; + +class clBoolParsingError: public clError +{ +public: + clBoolParsingError(): clError() {}; + clBoolParsingError(const char *m, const char *i, int l=0): clError(m,i,l) {}; + clBoolParsingError(const clBoolParsingError& that) + {this->Msg = that.Msg; this->Id = that.Id; this->Level = that.Level;} }; +class clNumParsingError: public clError +{ +public: + clNumParsingError():clError() {}; + clNumParsingError(const char *m, const char *i, int l=0): clError(m,i,l) {}; + clNumParsingError(const string& m, const string& i, int l=0): clError(m,i,l) {}; + clNumParsingError(const clNumParsingError& that) : clError(that) {}; + ~clNumParsingError() {}; +}; /*--------------------------------------------------------------------- In the entire library, the following routine is used always when an exception is to be thrown. diff --git a/code/clparseVal.cc b/code/clparseVal.cc index b03b81c..1643684 100644 --- a/code/clparseVal.cc +++ b/code/clparseVal.cc @@ -24,6 +24,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { #endif @@ -31,11 +32,12 @@ extern "C" { Convert the n th value of symbol S into a double ------------------------------------------------------------------------*/ -void reportParseError(const Symbol& S, const int& N) + void reportParseError(clError& excp, const Symbol& S, const int& N) { ostringstream os; os << "In conversion of " << S.Name << "[" << N << "]=" << S.Val[N]; - clThrowUp(os.str().c_str(), "###Error", CL_FAIL); + excp.set(os.str().c_str(), "###Error", CL_FAIL); + throw(excp); } #ifdef __cplusplus } @@ -62,7 +64,7 @@ int clparseVal(Symbol *S, int *Which, string& val) int clparseVal(Symbol *S, int *Which, double *d) { - unsigned int N = _ABS(*Which),n; + unsigned int N = _ABS(*Which); HANDLE_EXCEPTIONS( if (S != NULL) { @@ -75,10 +77,20 @@ HANDLE_EXCEPTIONS( else if ((retVal=clIsFalse(val))==1) *d=0; //*d = clIsTrue(val); if (retVal == CL_UNKNOWNBOOL ) - reportParseError(*S, N-1); + { + clBoolParsingError clExcp; + reportParseError(clExcp, *S, N-1); + } + } + else + { + int n=calc((char *)S->Val[N-1].c_str(),d); + if (n < 0) + { + clNumParsingError clExcp; + reportParseError(clExcp,*S, N-1); + } } - else if ((n=calc((char *)S->Val[N-1].c_str(),d))) - reportParseError(*S, N-1); return 1; } else return CL_FAIL; diff --git a/code/isBool.cc b/code/isBool.cc index 026a342..2abba05 100644 --- a/code/isBool.cc +++ b/code/isBool.cc @@ -25,7 +25,7 @@ #include #include #include -#include +#include //#include #ifdef __cplusplus @@ -78,7 +78,7 @@ int clIsTrue(const string& val) int retVal=clBoolCmp(val, true); if (retVal == CL_UNKNOWNBOOL) { - boolError bl("Unrecognized value for Bool", "###Error", CL_INFORMATIONAL); + clBoolParsingError bl("Unrecognized value for Bool", "###Error", CL_INFORMATIONAL); throw(bl); } return retVal; @@ -88,7 +88,7 @@ int clIsFalse(const string& val) int retVal=clBoolCmp(val, false); if (retVal == CL_UNKNOWNBOOL) { - boolError bl("Unrecognized value for Bool", "###Error", CL_INFORMATIONAL); + clBoolParsingError bl("Unrecognized value for Bool", "###Error", CL_INFORMATIONAL); throw(bl); } return retVal; diff --git a/code/tstcpp.cc b/code/tstcpp.cc index 49a9d62..688b1d8 100644 --- a/code/tstcpp.cc +++ b/code/tstcpp.cc @@ -114,7 +114,7 @@ void UI(bool restart, int argc, char **argv) } EndCL(); } - catch (clError x) + catch (clError& x) { x << x << endl; clRetry();