/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley Software License Agreement
* specifies the terms and conditions for redistribution.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "sh.h"
#include "sh.tconst.h"
#include <fcntl.h>
#include <unistd.h>
/*
* C Shell
*/
int
{
while (s && *s)
if (*s++ == c)
return (1);
return (0);
}
int
{
extern char end[];
}
tchar *
{
tchar *n;
tchar *p;
if (s == 0)
s = S_ /* "" */;
#ifndef m32
for (p = s; *p++; )
;
while (*p++ = *s++)
;
return (n);
#else
strcpy_(p, s);
return (p);
#endif
}
static void *
{
#ifdef debug
#endif
child++;
#ifndef debug
error("Out of memory");
#ifdef lint
i = i;
#endif
#else
printf("i=%d: Out of memory\n", i);
abort();
#endif
return (0); /* fool lint */
}
tchar **
{
while (*up)
up++;
return (up);
}
void
{
if (av[1])
printf(" ");
}
}
int
{
int i = 0;
while (*av++)
i++;
return (i);
}
tchar **
{
continue;
return (oav);
}
tchar **
{
return (up);
}
void
{
}
tchar **
{
sizeof (tchar **));
while (*v)
return (onewv);
}
tchar *
{
tchar *p, *q;
#ifndef m32
for (p = cp; *p++; )
;
for (q = dp; *q++; )
;
;
for (p--, q = dp; *p++ = *q++; )
;
#else
#endif
return (ep);
}
tchar **
{
sizeof (tchar **));
}
int
{
if (!*cp)
return (0);
while (cp[1])
cp++;
return (*cp);
}
void
donefds(void)
{
(void) close(0);
(void) close(1);
(void) close(2);
/*
* To avoid NIS+ functions to get hold of 0/1/2,
* use descriptor 0, and dup it to 1 and 2.
*/
didfds = 0;
}
/*
* Move descriptor i to j.
* If j is -1 then we just want to get i to a safe place,
* i.e. to a unit > 2. This also happens in dcopy.
*/
int
dmove(int i, int j)
{
int fd;
if (i == j || i < 0)
return (i);
if (j >= 0) {
if (fd != -1)
} else
j = dcopy(i, j);
if (j != i) {
(void) close(i);
unsetfd(i);
}
return (j);
}
int
dcopy(int i, int j)
{
int fd;
if (i == j || i < 0 || j < 0 && i > 2)
return (i);
if (j >= 0) {
if (fd != -1)
return (j);
}
(void) close(j);
unsetfd(j);
return (renum(i, j));
}
int
renum(int i, int j)
{
int k = dup(i);
if (k < 0)
return (-1);
if (j == -1 && k > 2) {
setfd(k);
return (k);
}
if (k != j) {
j = renum(k, j);
(void) close(k); /* no need ofr unsetfd() */
return (j);
}
return (k);
}
#ifndef copy
void
{
if (size)
do
while (--size != 0);
}
#endif
/*
* Left shift a command argument list, discarding
* the first c arguments. Used in "shift" commands
* as well as by commands like "repeat".
*/
void
{
tchar **u = v;
while (*u && --c >= 0)
xfree((char *)*u++);
(void) blkcpy(v, u);
}
int
{
if (*cp == '-') {
cp++;
return (0);
}
cp++;
return (*cp == 0);
}
tchar **
{
sizeof (tchar **));
}
tchar *
{
while (*cp)
cp++;
return (cp);
}
tchar *
{
continue;
return (cp);
}
void
{
bferr("Undefined variable");
}
int
{
for (;;) {
if (*sub == 0)
return (1);
if (*str == 0)
return (0);
return (0);
}
}
/*
* blk*_ routines
*/
char **
{
while (*up)
up++;
return (up);
}
int
{
int i = 0;
while (*av++)
i++;
return (i);
}
char **
{
continue;
return (oav);
}
char **
{
return (up);
}
char **
{
char **wp =
sizeof (char **));
}
/*
* If stack address was passed to free(), we have no good way to see if
* they are really in the stack. Therefore, we record the bottom of heap,
* and filter out the address not within heap's top(end) and bottom
* (xalloc_bottom).
*/
extern char end[];
static char *xalloc_bottom;
void *
{
if (bp > xalloc_bottom)
xalloc_bottom = bp;
return (rptr);
}
void *
{
/* data area, but not in heap area. don't touch it */
oob:
if (size == 0)
return (NULL);
/* copy max size */
return (rptr);
}
if (rptr < xalloc_bottom) {
/* address in the heap */
inb:
if (size == 0) {
return (NULL);
}
if (bp > xalloc_bottom)
xalloc_bottom = bp;
return (rptr);
}
#if defined(__sparc)
/* in the stack frame */
goto oob;
}
#endif
/*
* can be a memory block returned indirectly from
* library functions. update bottom, and check it again.
*/
xalloc_bottom = sbrk(0);
if (rptr <= xalloc_bottom)
goto inb;
else
goto oob;
/*NOTREACHED*/
}
void
{
return;
}
if (rptr < xalloc_bottom) {
return;
}
#if defined(__sparc)
/* in the stack frame */
return;
}
#endif
xalloc_bottom = sbrk(0);
if (rptr <= xalloc_bottom) {
}
}
void *
{
char *cp;
i *= j;
return (cp);
}