expr.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.6 */
#include <stdio.h>
/*
* FMLI begin
*/
#include <setjmp.h>
#include "wish.h"
/* #include "message.h" */
#include "eval.h"
/*
* FMLI end
*/
# define A_STRING 258
# define NOARG 259
# define OR 260
# define AND 261
# define EQ 262
# define LT 263
# define GT 264
# define GEQ 265
# define LEQ 266
# define NEQ 267
# define ADD 268
# define SUBT 269
# define MULT 270
# define DIV 271
# define REM 272
# define MCH 273
# define MATCH 274
#define ESIZE 256
long atol();
static char **Av;
static char *buf;
static int Ac;
static int Argi;
static int noarg;
static int paren;
extern int nbra;
static char *operator[] = {
"|", "&", "+", "-", "*", "/", "%", ":",
"=", "==", "<", "<=", ">", ">=", "!=",
"match", "\0" };
static int op[] = {
MATCH };
static int pri[] = {
1,2,3,3,3,3,3,3,4,4,5,5,5,6,7};
yylex() {
register char *p;
register i;
if((*p == '(' || *p == ')') && p[1] == '\0' )
return (int)*p;
for(i = 0; *operator[i]; ++i)
return op[i];
return A_STRING;
}
static char *
{
long i;
else
switch(oper) {
case EQ:
i = i==0;
break;
case GT:
i = i>0;
break;
case GEQ:
i = i>=0;
break;
case LT:
i = i<0;
break;
case LEQ:
i = i<=0;
break;
case NEQ:
i = i!=0;
break;
}
return i? "1": "0";
}
static char *
{
register char *rv;
yyerror("non-numeric argument");
switch(oper) {
case ADD:
break;
case SUBT:
break;
case MULT:
break;
case DIV:
if (i2 == 0)
yyerror("division by zero");
break;
case REM:
if (i2 == 0)
yyerror("division by zero");
break;
}
return rv;
}
static char *
{
register char *rv;
switch(oper) {
case OR:
rv = "0";
else
else
break;
case AND:
rv = "0";
rv = "0";
else
break;
}
return rv;
}
static char *
match(s, p)
char *s, *p;
{
register char *rv;
if(nbra) {
}
return rv;
}
static int
ematch(s, p)
char *s;
register char *p;
{
void errxx();
register num;
if(nbra > 1)
yyerror("Too many '\\('s");
if(nbra == 1) {
p = braslist[0];
}
return(loc2-s);
}
return(0);
}
void
errxx()
{
yyerror("RE error");
}
static int
yyerror(s)
char *s;
{
/*
* Changed the expr prefix to fmlexpr. mek
*/
doupdate();
/*NOTREACHED*/
}
static char *
ltoa(l)
long l;
{
static str[20];
register i;
register neg = 0;
if(l == 0x80000000L)
return "-2147483648";
if(l < 0)
++neg, l = -l;
do {
i = l % 10;
*sp-- = '0' + i;
l /= 10;
}
while(l);
if(neg)
*sp-- = '-';
return ++sp;
}
static char *
{
yyerror("syntax error");
}
}
else {
if (ylex == '(') {
paren++;
Argi++;
Argi--;
}
}
lop:
Argi++;
return r1;
else {
switch(op1) {
case OR:
case AND:
break;
case EQ:
case LT:
case GT:
case LEQ:
case GEQ:
case NEQ:
break;
case ADD:
case SUBT:
case MULT:
case DIV:
case REM:
break;
case MCH:
break;
}
if(noarg == 1) {
return r1;
}
Argi--;
goto lop;
}
}
if(ylex == ')') {
yyerror("syntax error");
}
if(par != 0) {
paren--;
Argi++;
}
Argi++;
return r1;
}
return r1;
}
Argi++;
switch(op1) {
case MATCH:
}
switch(op1) {
case MATCH:
break;
}
if(noarg == 1) {
return r1;
}
Argi--;
goto lop;
}
noarg = 1;
}
return r1;
}
int argc;
char **argv;
{
Argi = 1;
noarg = 0;
paren = 0;
Mstring[0][0] = '\0';
/*
* FMLI: return FAIL if setjmp returns a non-zero value
* (i.e., called by longjmp() in yyerror())
*/
return(FAIL);
yyerror("syntax error");
}
/*
* use FMLI output routines
*/
}