Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions code/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ target_include_directories(parafeed PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
# install target
set(header_list
boolError.h
clbool.h
clconvert.h
clError.h
Expand Down Expand Up @@ -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
Expand All @@ -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})
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion code/ErrorObj.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
#define ERROROBJ_H
#include <string>
#include <iostream>
#include <exception>

using namespace std;

class ErrorObj{
class ErrorObj: public std::exception{
public:
enum {Informational=100,Recoverable,Severe,Fatal};
ErrorObj():Id(), Msg(), Src(), Message(),Level(0)
Expand Down
18 changes: 13 additions & 5 deletions code/SetVar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#include <stdlib.h>
#include <cl.h>
#include <cllib.h>
#include <boolError.h>
#include <clError.h>
#ifdef __cplusplus
#include <sstream>
#include <algorithm>
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
43 changes: 0 additions & 43 deletions code/boolError.h

This file was deleted.

3 changes: 2 additions & 1 deletion code/calc/calc.y
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <math.h>
#include <calc.h>
#include <stdlib.h>

#include <stdio.h>
static double
fooUserFunc(char* s) { return 0.0; }

Expand Down Expand Up @@ -67,6 +67,7 @@ expr: NUMBER { $$ = $1; }
$$ = (*($1->ufunc))($1->Name);
if ($1->Name) free($1->Name);
$1->Name = NULL;
return -2;
}
else
{
Expand Down
24 changes: 12 additions & 12 deletions code/calc/lex.l
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));*/

Expand Down Expand Up @@ -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];
Expand All @@ -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];
Expand All @@ -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);
Expand All @@ -216,7 +219,4 @@ atan2 { Calc_Symbol *s; /* A patch for atan2...*/
}
}
\n {ECHON;return '\n';}
. {ECHO;return yytext[0];}



. {ECHOSS(".");return yytext[0];}
2 changes: 1 addition & 1 deletion code/callbacks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <string>
#include <errno.h>
#include <limits.h>
#include <boolError.h>
#include <clError.h>
#include <sstream>
#include <regex>
//#include <strstream>
Expand Down
2 changes: 1 addition & 1 deletion code/cl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion code/clError.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 18 additions & 6 deletions code/clparseVal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@
#include <string>
#include <vector>
#include <sstream>
#include <clError.h>
#ifdef __cplusplus
extern "C" {
#endif
/*------------------------------------------------------------------------
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
}
Expand All @@ -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)
{
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions code/isBool.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <stdbool.h>
#include <algorithm>
#include <cctype>
#include <boolError.h>
#include <clError.h>

//#include <clbool.h>
#ifdef __cplusplus
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading