Improve error checking and messages from AS file parser.

This commit is contained in:
Andrew Johnson
2006-04-03 21:41:11 +00:00
parent d7016a007c
commit abfd3f0186
4 changed files with 62 additions and 63 deletions

View File

@@ -119,7 +119,6 @@ epicsShareFunc void epicsShareAPI asTrapWriteAfterWrite(void *pvt);
#define S_asLib_noMemory (M_asLib|14) /*access security: no Memory */
/*Private declarations */
#define ASMAXINP 12
epicsShareExtern int asActive;
/* definition of access rights*/
@@ -169,7 +168,7 @@ typedef struct{
ELLNODE node;
asAccessRights access;
int level;
int inpUsed; /*mask for which inputs are used*/
unsigned long inpUsed; /*bitmap of which inputs are used*/
int result; /*Result of calc converted to TRUE/FALSE*/
char *calc;
void *rpcl;
@@ -191,9 +190,9 @@ typedef struct asg{
ELLLIST inpList;
ELLLIST ruleList;
ELLLIST memberList;
double *pavalue; /*pointer to array of input values*/
int inpBad; /*mask for which inputs are bad*/
int inpChanged; /*mask showing inputs that have changed*/
double *pavalue; /*pointer to array of input values*/
unsigned long inpBad; /*bitmap of which inputs are bad*/
unsigned long inpChanged; /*bitmap of inputs that changed*/
} ASG;
typedef struct asgMember {
ELLNODE node;

View File

@@ -69,7 +69,7 @@ uag_user_list: uag_user_list ',' uag_user_list_name
uag_user_list_name: tokenSTRING
{
if (asUagAddUser(yyUag,$1))
yyerror($1);
yyerror("");
free((void *)$1);
}
;
@@ -115,17 +115,14 @@ asg_body_list: asg_body_list asg_body_item
asg_body_item: inp_config | rule_config
;
inp_config: tokenINP '(' inp_body ')'
inp_config: tokenINP '(' tokenSTRING ')'
{
if (asAsgAddInp(yyAsg,$<Str>3,$<Int>1))
if (asAsgAddInp(yyAsg,$3,$<Int>1))
yyerror("");
free((void *)$<Str>3);
free((void *)$3);
}
;
inp_body: tokenSTRING
;
rule_config: tokenRULE rule_head rule_body
| tokenRULE rule_head
@@ -142,7 +139,7 @@ rule_head_manditory: '(' tokenINTEGER ',' tokenSTRING
} else if((strcmp($4,"WRITE")==0)) {
rights=asWRITE;
} else {
yyerror("Illegal access type");
yyerror("Access rights must be NONE, READ or WRITE");
rights = asNOACCESS;
}
yyAsgRule = asAsgAddRule(yyAsg,rights,$2);
@@ -160,7 +157,7 @@ rule_log_options: ',' tokenSTRING ')'
status = asAsgAddRuleOptions(yyAsgRule,AS_TRAP_WRITE);
if(status) yyerror("");
} else if((strcmp($2,"NOTRAPWRITE")!=0)) {
yyerror("Illegal access type");
yyerror("Log options must be TRAPWRITE or NOTRAPWRITE");
}
free((void *)$2);
}
@@ -178,7 +175,7 @@ rule_list_item: tokenUAG '(' rule_uag_list ')'
| tokenCALC '(' tokenSTRING ')'
{
if (asAsgRuleCalc(yyAsgRule,$3))
yyerror("access security CALC failure");
yyerror("");
free((void *)$3);
}
;
@@ -213,8 +210,9 @@ rule_hag_list_name: tokenSTRING
static int yyerror(str)
char *str;
{
epicsPrintf("Access Security Error(%s) line %d token %s\n",
str,line_num,yytext);
if (strlen(str)) epicsPrintf("%s\n", str);
epicsPrintf("Access Security file error at line %d\n",
line_num);
yyFailed = TRUE;
return(0);
}

View File

@@ -7,11 +7,14 @@
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
integer [0-9]
digit [0-9]
name [a-zA-Z0-9_\-:\.\[\]<>;]
notquote [^\"]
escapequote \\\"
string {notquote}|{escapequote}
whitespace [ \t\r]
punctuation [(){},]
link [A-L]
%{
static ASINPUTFUNCPTR *my_yyinput;
@@ -29,18 +32,18 @@ static int yyreset()
%%
UAG {return(tokenUAG);}
HAG {return(tokenHAG);}
ASG {return(tokenASG);}
RULE {return(tokenRULE);}
CALC {return(tokenCALC);}
INP[A-L] {/* If A-L is changed then ASMAXINP must also be changed*/
UAG { return(tokenUAG); }
HAG { return(tokenHAG); }
ASG { return(tokenASG); }
RULE { return(tokenRULE); }
CALC { return(tokenCALC); }
INP{link} {
yylval.Int = (unsigned char)yytext[3];
yylval.Int -= 'A';
return(tokenINP);
}
{integer}+ {
{digit}+ { /*integer*/
yylval.Int = atoi((char *)yytext);
return(tokenINTEGER);
}
@@ -51,30 +54,29 @@ INP[A-L] {/* If A-L is changed then ASMAXINP must also be changed*/
}
\"{string}*\" { /*quoted string*/
/* making sure that neither double quote gets passed back */
/* making sure that neither double quote gets passed back */
yylval.Str=asStrdup(yytext+1);
yylval.Str[strlen(yylval.Str)-1] = '\0';
yylval.Str[strlen(yylval.Str)-1] = '\0';
return(tokenSTRING);
}
return(tokenSTRING);
}
{punctuation} { return(yytext[0]); }
"{" { return(yytext[0]); }
"}" { return(yytext[0]); }
"(" { return(yytext[0]); }
")" { return(yytext[0]); }
"," { return(yytext[0]); }
^#.*
[ \t\r] ;
{whitespace} ;
\n { line_num ++;}
. {
char message[20];
YY_BUFFER_STATE *dummy=0;
sprintf(message,"invalid character '%c'",yytext[0]);
yyerror(message);
/*The following suppresses compiler warning messages*/
if(FALSE) yyunput('c',(unsigned char *) message);
if(FALSE) yy_switch_to_buffer(*dummy);
. {
char message[20];
YY_BUFFER_STATE *dummy=0;
sprintf(message,"invalid character '%c'",yytext[0]);
yyerror(message);
/*The following suppress compiler warning messages*/
if (0) yyunput('c',(unsigned char *) message);
if (0) yy_switch_to_buffer(*dummy);
}
%%

View File

@@ -7,8 +7,8 @@
* and higher are distributed subject to a Software License Agreement found
* in file LICENSE that is included with this distribution.
\*************************************************************************/
/* share/src/as/ascheck.c */
/* share/src/as $Id$ */
/* $Id$ */
/* Author: Marty Kraimer Date: 03-24-94 */
#include <stdlib.h>
@@ -22,8 +22,7 @@
#include "dbStaticLib.h"
int main(int argc,char **argv)
{
int i;
int strip;
int argn = 1;
char *sub = NULL;
int subLength = 0;
char **pstr;
@@ -32,27 +31,28 @@ int main(int argc,char **argv)
long status = 0;
static char *subSep = ",";
/*Look for options*/
while(argc>1 && (strncmp(argv[1],"-S",2)==0)) {
/* Look for -Smacro=value options */
while (argc>argn && (strncmp(argv[argn], "-S", 2)==0)) {
pstr = &sub;
psep = subSep;
len = &subLength;
if(strlen(argv[1])==2) {
dbCatString(pstr,len,argv[2],psep);
strip = 2;
if (strlen(argv[argn])==2) {
dbCatString(pstr, len, argv[++argn], psep);
} else {
dbCatString(pstr,len,argv[1]+2,psep);
strip = 1;
dbCatString(pstr, len, argv[argn]+2, psep);
}
argc -= strip;
for(i=1; i<argc; i++) argv[i] = argv[i + strip];
argn++;
}
if(argc!=1) {
printf("usage: ascheck -Smacsub < file\n");
status = -1;
if (argc == argn) {
status = asInitFP(stdin, sub);
if(status) errlogPrintf("ascheck: Access Security File failed.\n");
} else if (argc == argn+1) {
status = asInitFile(argv[argn], sub);
if(status) errlogPrintf("ascheck: Access Security File failed.\n");
} else {
status = asInitFP(stdin,sub);
if(status) errMessage(status,"from asInitFP");
printf("usage: ascheck [-Smac=sub ...] [<] file\n");
status = -1;
}
return(status);
errlogFlush();
return status;
}