Change so that 0 is INVALID_

This commit is contained in:
Marty Kraimer
1997-07-11 12:20:35 +00:00
parent b9f80350e0
commit ed3cefacef
7 changed files with 278 additions and 149 deletions

View File

@@ -111,7 +111,7 @@
#define epicsExportSharedSymbols
#include "dbDefs.h"
#include "post.h"
#include "postfix.h"
static double local_random();
@@ -148,6 +148,7 @@ if ( post[i] == 71 ) i=i+8;
}
printf ("*FINISHED*\n");
*/
if(*post == BAD_EXPRESSION) return(-1);
/* set post to postfix expression in calc structure */
top = pstacktop;

View File

@@ -100,7 +100,7 @@
#define epicsExportSharedSymbols
#include "dbDefs.h"
#include "post.h"
#include "postfix.h"
/* declarations for postfix */
@@ -314,6 +314,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
double constant;
register char *pposthold, *pc;
char in_stack_pri, in_coming_pri, code;
char *ppostfixStart = ppostfix;
/* convert infix expression to upper case */
for (pc=pinfix; *pc; pc++) {
@@ -335,7 +336,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case OPERAND:
if (!operand_needed){
*perror = 5;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operand to the expression */
@@ -348,7 +349,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case FLOAT_PT_CONST:
if (!operand_needed){
*perror = 5;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add constant to the expression */
@@ -356,6 +357,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
pposthold = ppostfix;
pinfix-=no_bytes;
while (*pinfix == ' ') *ppostfix++ = *pinfix++;
while (TRUE) {
if ( ( *pinfix >= '0' && *pinfix <= '9' ) || *pinfix == '.' ) {
*ppostfix++ = *pinfix;
@@ -386,7 +388,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case BINARY_OPERATOR:
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators of higher or equal priority to */
@@ -407,7 +409,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case UNARY_OPERATOR:
if (!operand_needed){
*perror = 5;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators of higher or equal priority to */
@@ -460,7 +462,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case SEPERATOR:
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators to postfix until open paren */
@@ -468,7 +470,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
if (pstacktop == &stack[1] ||
pstacktop == &stack[0]){
*perror = 6;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
*ppostfix++ = pstacktop->code;
pstacktop--;
@@ -479,7 +481,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case CLOSE_PAREN:
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators to postfix until matching paren */
@@ -487,7 +489,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
if (pstacktop == &stack[1] ||
pstacktop == &stack[0]){
*perror = 6;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
*ppostfix++ = pstacktop->code;
pstacktop--;
@@ -498,7 +500,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case CONDITIONAL:
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators of higher priority to */
@@ -525,14 +527,14 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case EXPR_TERM:
if (operand_needed && !new_expression){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add all operators on stack to postfix */
while (pstacktop >= &stack[1]){
if (pstacktop->element[0] == '('){
*perror = 6;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
*ppostfix++ = pstacktop->code;
pstacktop--;
@@ -548,19 +550,19 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
default:
*perror = 8;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
}
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add all operators on stack to postfix */
while (pstacktop >= &stack[1]){
if (pstacktop->element[0] == '('){
*perror = 6;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
*ppostfix++ = pstacktop->code;
pstacktop--;

120
src/libCom/calc/postfix.h Normal file
View File

@@ -0,0 +1,120 @@
/* postfix.h
* Author: Bob Dalesio
* Date: 9-21-88
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Modification Log:
* -----------------
* .01 01-11-89 lrd add right and left shift
* .02 02-01-89 lrd add trig functions
* .03 02-17-92 jba add exp, CEIL, and FLOOR
* .04 03-03-92 jba added MAX, MIN, and comma
* .05 03-06-92 jba added multiple conditional expressions ?
* .06 04-02-92 jba added CONSTANT for floating pt constants in expression
* .07 05-11-94 jba added CONST_PI, CONST_D2R, and CONST_R2D
*/
#ifndef INCpostfixh
#define INCpostfixh
/* defines for element table */
#define BAD_EXPRESSION 0
#define FETCH_A 1
#define FETCH_B 2
#define FETCH_C 3
#define FETCH_D 4
#define FETCH_E 5
#define FETCH_F 6
#define FETCH_G 7
#define FETCH_H 8
#define FETCH_I 9
#define FETCH_J 10
#define FETCH_K 11
#define FETCH_L 12
#define ACOS 13
#define ASIN 14
#define ATAN 15
#define COS 16
#define COSH 17
#define SIN 18
#define STORE_A 19
#define STORE_B 20
#define STORE_C 21
#define STORE_D 22
#define STORE_E 23
#define STORE_F 24
#define STORE_G 25
#define STORE_H 26
#define STORE_I 27
#define STORE_J 28
#define STORE_K 29
#define STORE_L 30
#define RIGHT_SHIFT 31
#define LEFT_SHIFT 32
#define SINH 33
#define TAN 34
#define TANH 35
#define LOG_2 36
#define COND_ELSE 37
#define ABS_VAL 38
#define UNARY_NEG 39
#define SQU_RT 40
#define EXP 41
#define CEIL 42
#define FLOOR 43
#define LOG_10 44
#define LOG_E 45
#define RANDOM 46
#define ADD 47
#define SUB 48
#define MULT 49
#define DIV 50
#define EXPON 51
#define MODULO 52
#define BIT_OR 53
#define BIT_AND 54
#define BIT_EXCL_OR 55
#define GR_OR_EQ 56
#define GR_THAN 57
#define LESS_OR_EQ 58
#define LESS_THAN 59
#define NOT_EQ 60
#define EQUAL 61
#define REL_OR 62
#define REL_AND 63
#define REL_NOT 64
#define BIT_NOT 65
#define PAREN 66
#define MAX 67
#define MIN 68
#define COMMA 69
#define COND_IF 70
#define COND_END 71
#define CONSTANT 72
#define CONST_PI 73
#define CONST_D2R 74
#define CONST_R2D 75
#define NINT 76
#define END_STACK 127
#endif /* INCpostfixh */

View File

@@ -111,7 +111,7 @@
#define epicsExportSharedSymbols
#include "dbDefs.h"
#include "post.h"
#include "postfix.h"
static double local_random();
@@ -148,6 +148,7 @@ if ( post[i] == 71 ) i=i+8;
}
printf ("*FINISHED*\n");
*/
if(*post == BAD_EXPRESSION) return(-1);
/* set post to postfix expression in calc structure */
top = pstacktop;

View File

@@ -1,117 +0,0 @@
/* $Id$
* Author: Bob Dalesio
* Date: 9-21-88
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Modification Log:
* -----------------
* .01 01-11-89 lrd add right and left shift
* .02 02-01-89 lrd add trig functions
* .03 02-17-92 jba add exp, CEIL, and FLOOR
* .04 03-03-92 jba added MAX, MIN, and comma
* .05 03-06-92 jba added multiple conditional expressions ?
* .06 04-02-92 jba added CONSTANT for floating pt constants in expression
* .07 05-11-94 jba added CONST_PI, CONST_D2R, and CONST_R2D
*/
/* defines for element table */
#define FETCH_A 0
#define FETCH_B 1
#define FETCH_C 2
#define FETCH_D 3
#define FETCH_E 4
#define FETCH_F 5
#define FETCH_G 6
#define FETCH_H 7
#define FETCH_I 8
#define FETCH_J 9
#define FETCH_K 10
#define FETCH_L 11
#define ACOS 12
#define ASIN 13
#define ATAN 14
#define COS 15
#define COSH 16
#define SIN 17
#define STORE_A 18
#define STORE_B 19
#define STORE_C 20
#define STORE_D 21
#define STORE_E 22
#define STORE_F 23
#define STORE_G 24
#define STORE_H 25
#define STORE_I 26
#define STORE_J 27
#define STORE_K 28
#define STORE_L 29
#define RIGHT_SHIFT 30
#define LEFT_SHIFT 31
#define SINH 32
#define TAN 33
#define TANH 34
#define LOG_2 35
#define COND_ELSE 36
#define ABS_VAL 37
#define UNARY_NEG 38
#define SQU_RT 39
#define EXP 40
#define CEIL 41
#define FLOOR 42
#define LOG_10 43
#define LOG_E 44
#define RANDOM 45
#define ADD 46
#define SUB 47
#define MULT 48
#define DIV 49
#define EXPON 50
#define MODULO 51
#define BIT_OR 52
#define BIT_AND 53
#define BIT_EXCL_OR 54
#define GR_OR_EQ 55
#define GR_THAN 56
#define LESS_OR_EQ 57
#define LESS_THAN 58
#define NOT_EQ 59
#define EQUAL 60
#define REL_OR 61
#define REL_AND 62
#define REL_NOT 63
#define BIT_NOT 64
#define PAREN 65
#define MAX 66
#define MIN 67
#define COMMA 68
#define COND_IF 69
#define COND_END 70
#define CONSTANT 71
#define CONST_PI 72
#define CONST_D2R 73
#define CONST_R2D 74
#define NINT 75
#define END_STACK 127

View File

@@ -100,7 +100,7 @@
#define epicsExportSharedSymbols
#include "dbDefs.h"
#include "post.h"
#include "postfix.h"
/* declarations for postfix */
@@ -314,6 +314,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
double constant;
register char *pposthold, *pc;
char in_stack_pri, in_coming_pri, code;
char *ppostfixStart = ppostfix;
/* convert infix expression to upper case */
for (pc=pinfix; *pc; pc++) {
@@ -335,7 +336,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case OPERAND:
if (!operand_needed){
*perror = 5;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operand to the expression */
@@ -348,7 +349,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case FLOAT_PT_CONST:
if (!operand_needed){
*perror = 5;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add constant to the expression */
@@ -356,6 +357,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
pposthold = ppostfix;
pinfix-=no_bytes;
while (*pinfix == ' ') *ppostfix++ = *pinfix++;
while (TRUE) {
if ( ( *pinfix >= '0' && *pinfix <= '9' ) || *pinfix == '.' ) {
*ppostfix++ = *pinfix;
@@ -386,7 +388,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case BINARY_OPERATOR:
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators of higher or equal priority to */
@@ -407,7 +409,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case UNARY_OPERATOR:
if (!operand_needed){
*perror = 5;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators of higher or equal priority to */
@@ -460,7 +462,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case SEPERATOR:
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators to postfix until open paren */
@@ -468,7 +470,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
if (pstacktop == &stack[1] ||
pstacktop == &stack[0]){
*perror = 6;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
*ppostfix++ = pstacktop->code;
pstacktop--;
@@ -479,7 +481,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case CLOSE_PAREN:
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators to postfix until matching paren */
@@ -487,7 +489,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
if (pstacktop == &stack[1] ||
pstacktop == &stack[0]){
*perror = 6;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
*ppostfix++ = pstacktop->code;
pstacktop--;
@@ -498,7 +500,7 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case CONDITIONAL:
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add operators of higher priority to */
@@ -525,14 +527,14 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
case EXPR_TERM:
if (operand_needed && !new_expression){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add all operators on stack to postfix */
while (pstacktop >= &stack[1]){
if (pstacktop->element[0] == '('){
*perror = 6;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
*ppostfix++ = pstacktop->code;
pstacktop--;
@@ -548,19 +550,19 @@ long epicsShareAPI postfix(char *pinfix,char *ppostfix,short *perror)
default:
*perror = 8;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
}
if (operand_needed){
*perror = 4;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
/* add all operators on stack to postfix */
while (pstacktop >= &stack[1]){
if (pstacktop->element[0] == '('){
*perror = 6;
return(-1);
*ppostfixStart = BAD_EXPRESSION; return(-1);
}
*ppostfix++ = pstacktop->code;
pstacktop--;

120
src/libCom/postfix.h Normal file
View File

@@ -0,0 +1,120 @@
/* postfix.h
* Author: Bob Dalesio
* Date: 9-21-88
*
* Experimental Physics and Industrial Control System (EPICS)
*
* Copyright 1991, the Regents of the University of California,
* and the University of Chicago Board of Governors.
*
* This software was produced under U.S. Government contracts:
* (W-7405-ENG-36) at the Los Alamos National Laboratory,
* and (W-31-109-ENG-38) at Argonne National Laboratory.
*
* Initial development by:
* The Controls and Automation Group (AT-8)
* Ground Test Accelerator
* Accelerator Technology Division
* Los Alamos National Laboratory
*
* Co-developed with
* The Controls and Computing Group
* Accelerator Systems Division
* Advanced Photon Source
* Argonne National Laboratory
*
* Modification Log:
* -----------------
* .01 01-11-89 lrd add right and left shift
* .02 02-01-89 lrd add trig functions
* .03 02-17-92 jba add exp, CEIL, and FLOOR
* .04 03-03-92 jba added MAX, MIN, and comma
* .05 03-06-92 jba added multiple conditional expressions ?
* .06 04-02-92 jba added CONSTANT for floating pt constants in expression
* .07 05-11-94 jba added CONST_PI, CONST_D2R, and CONST_R2D
*/
#ifndef INCpostfixh
#define INCpostfixh
/* defines for element table */
#define BAD_EXPRESSION 0
#define FETCH_A 1
#define FETCH_B 2
#define FETCH_C 3
#define FETCH_D 4
#define FETCH_E 5
#define FETCH_F 6
#define FETCH_G 7
#define FETCH_H 8
#define FETCH_I 9
#define FETCH_J 10
#define FETCH_K 11
#define FETCH_L 12
#define ACOS 13
#define ASIN 14
#define ATAN 15
#define COS 16
#define COSH 17
#define SIN 18
#define STORE_A 19
#define STORE_B 20
#define STORE_C 21
#define STORE_D 22
#define STORE_E 23
#define STORE_F 24
#define STORE_G 25
#define STORE_H 26
#define STORE_I 27
#define STORE_J 28
#define STORE_K 29
#define STORE_L 30
#define RIGHT_SHIFT 31
#define LEFT_SHIFT 32
#define SINH 33
#define TAN 34
#define TANH 35
#define LOG_2 36
#define COND_ELSE 37
#define ABS_VAL 38
#define UNARY_NEG 39
#define SQU_RT 40
#define EXP 41
#define CEIL 42
#define FLOOR 43
#define LOG_10 44
#define LOG_E 45
#define RANDOM 46
#define ADD 47
#define SUB 48
#define MULT 49
#define DIV 50
#define EXPON 51
#define MODULO 52
#define BIT_OR 53
#define BIT_AND 54
#define BIT_EXCL_OR 55
#define GR_OR_EQ 56
#define GR_THAN 57
#define LESS_OR_EQ 58
#define LESS_THAN 59
#define NOT_EQ 60
#define EQUAL 61
#define REL_OR 62
#define REL_AND 63
#define REL_NOT 64
#define BIT_NOT 65
#define PAREN 66
#define MAX 67
#define MIN 68
#define COMMA 69
#define COND_IF 70
#define COND_END 71
#define CONSTANT 72
#define CONST_PI 73
#define CONST_D2R 74
#define CONST_R2D 75
#define NINT 76
#define END_STACK 127
#endif /* INCpostfixh */