/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 */
/*
*/
#include <stdlib.h>
#include <regexpr.h>
#include <locale.h>
#include <string.h>
#include <unistd.h>
#include <regex.h>
#include <limits.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
/* size of subexpression array */
static int ematch(char *, char *);
static void yyerror(char *);
static void errxx();
long atol();
void exit();
static char *ltoa();
static char *lltoa();
static char **Av;
static char *buf;
static int Ac;
static int Argi;
static int noarg;
static int paren;
/*
* Array used to store subexpressions in regular expressions
* Only one subexpression allowed per regular expression currently
*/
static char *operator[] = {
"|", "&", "+", "-", "*", "/", "%", ":",
"=", "==", "<", "<=", ">", ">=", "!=",
"match",
"substr", "length", "index",
"\0" };
static int op[] = {
};
static int pri[] = {
1, 2, 3, 3, 3, 3, 3, 3, 4, 4, 5, 5, 5, 6, 7,
7, 7, 7
};
/*
* clean_buf - XCU4 mod to remove leading zeros from negative signed
* numeric output, e.g., -00001 becomes -1
*/
static void
char *buf;
{
int i = 0;
int len;
long long num;
if (buf[0] == '\0')
return;
if (len <= 0)
return;
if (buf[0] == '-') {
i++; /* Skip the leading '-' see while loop */
return; /* Yes, so return */
while (i < len) {
is_a_num = 0;
break;
}
i++;
}
if (is_a_num) {
}
}
}
/*
* End XCU4 mods.
*/
static int
yylex()
{
char *p;
int i;
return (NOARG);
if ((*p == '(' || *p == ')') && p[1] == '\0')
return ((int)*p);
for (i = 0; *operator[i]; ++i)
return (op[i]);
return (A_STRING);
}
static char
{
errno = 0;
if (errno) {
#ifdef XPG6
/* XPG6: stdout will always contain newline even on error */
#endif
"expr: Integer argument too large\n"));
exit(3);
} else {
perror("expr");
exit(3);
}
}
switch (oper) {
case EQ:
break;
case GT:
break;
case GEQ:
break;
case LT:
break;
case LEQ:
break;
case NEQ:
break;
}
}
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");
errno = 0;
if (errno) {
#ifdef XPG6
/* XPG6: stdout will always contain newline even on error */
#endif
"expr: Integer argument too large\n"));
exit(3);
} else {
perror("expr");
exit(3);
}
}
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);
}
char *
substr(char *v, char *s, char *w)
{
char *res;
while (--si)
if (*v) ++v;
res = v;
while (wi--)
if (*v) ++v;
*v = '\0';
return (res);
}
char *
index(char *s, char *t)
{
long i, j;
char *rv;
for (i = 0; s[i]; ++i)
for (j = 0; t[j]; ++j)
if (s[i] == t[j]) {
return (rv);
}
return ("0");
}
char *
length(char *s)
{
long i = 0;
char *rv;
while (*s++) ++i;
return (rv);
}
static char *
match(char *s, char *p)
{
char *rv;
if (nbra /* && val != 0 */) {
}
return (rv);
}
/*
*/
static int
ematch(char *s, char *p)
{
static char *expbuf;
char *nexpbuf;
int num;
#ifdef XPG4
char *tmptr;
#endif
if (0 /* XXX nbra > 1*/)
yyerror("Too many '\\('s");
if (regerrno) {
errxx();
} else {
if (expbuf)
}
if (nbra > 0) {
p = braslist[0];
yyerror("string too long");
}
#ifdef XPG4
/*
* Use mbstowcs to find the number of multibyte characters
* in the multibyte string beginning at s, and
* ending at loc2. Create a separate string
* of the substring, so it can be passed to mbstowcs.
*/
} else {
}
yyerror("invalid multibyte character encountered");
return (0);
}
return (nmbchars);
#else
return (loc2-s);
#endif
}
return (0);
}
static void
errxx()
{
yyerror("RE error");
}
static void
yyerror(char *s)
{
#ifdef XPG6
/* XPG6: stdout will always contain newline even on error */
#endif
exit(2);
/* NOTREACHED */
}
static char *
ltoa(long l)
{
int i;
int neg = 0;
if ((unsigned long)l == 0x80000000UL)
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 *
lltoa(long long l)
{
int i;
int neg = 0;
if (l == 0x8000000000000000ULL)
return ("-9223372036854775808");
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:
break;
case SUBSTR:
break;
case LENGTH:
break;
case INDEX:
break;
}
switch (op1) {
case MATCH:
break;
case SUBSTR:
break;
case LENGTH:
break;
case INDEX:
break;
}
if (noarg == 1) {
return (r1);
}
Argi--;
goto lop;
}
noarg = 1;
}
return (r1);
}
void *
{
void *rv;
char *s = gettext("malloc error");
exit(3);
}
return (rv);
}
int
{
/*
* XCU4 allow "--" as argument
*/
/*
* XCU4 - print usage message when invoked without args
*/
if (argc < 2) {
#ifdef XPG6
/* XPG6: stdout will always contain newline even on error */
#endif
exit(3);
}
Argi = 1;
noarg = 0;
paren = 0;
#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
#endif
(void) textdomain(TEXT_DOMAIN);
yyerror("syntax error");
}
/*
* XCU4 - strip leading zeros from numeric output
*/
}