/*
* 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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* UNIX shell
*/
#include "defs.h"
#include "sym.h"
#include <wait.h>
static int getch();
static void comsubst(int);
static void flush(int);
static void
/* trimflag - flag to check if argument will be trimmed */
{
unsigned int c;
unsigned int d;
unsigned char *pc;
if (quote) {
if(c == '\\') { /* don't interpret next character */
pushstak(c);
d = readwc();
if(!escchar(d)) { /* both \ and following
character are quoted if next
character is not $, `, ", or \*/
pushstak('\\');
pushstak('\\');
/* push entire multibyte char */
while(*pc) {
}
} else {
/* d might be NULL */
/* Evenif d is NULL, we have to save it */
if (*pc) {
while (*pc) {
}
} else {
}
}
} else { /* push escapes onto stack to quote characters */
pushstak('\\');
while(*pc) {
}
}
} else if(c == '\\') {
c = readwc(); /* get character to be escaped */
pushstak('\\');
/* c might be NULL */
/* Evenif c is NULL, we have to save it */
if (*pc) {
while (*pc) {
}
} else {
}
} else {
while (*pc) {
}
}
zerostak();
if (c != endch)
}
static void
{
/*
* skip chars up to }
*/
unsigned int c;
{
switch (c)
{
case SQUOTE:
break;
case DQUOTE:
break;
case DOLLAR:
skipto('}');
}
}
if (c != endch)
}
static
unsigned char endch;
int trimflag; /* flag to check if an argument is going to be trimmed, here document
output is never trimmed
*/
{
unsigned int d;
quotes */
d = readwc();
if (!subchar(d))
return(d);
if (d == DOLLAR)
{
unsigned int c;
{
int dolg = 0;
unsigned char *argp, *v;
c = readwc();
if (letter(c))
{
while (alphanum(c))
{
pushstak(c);
c = readwc();
}
zerostak();
v = n->namval;
}
else if (digchar(c))
{
*id = c;
idb[1] = 0;
if (astchar(c))
{
quoted--;
atflag = 1;
}
dolg = 1;
c = '1';
}
c -= '0';
}
else if (c == '$')
v = pidadr;
else if (c == '!')
v = pcsadr;
else if (c == '#')
{
v = numbuf;
}
else if (c == '?')
{
v = numbuf;
}
else if (c == '-')
v = flagadr;
else if (bra)
else
goto retry;
c = readwc();
{
nulflg = 1;
c = readwc();
}
else
nulflg = 0;
argp = 0;
if (bra)
{
if (c != '}')
{
else
skipto('}');
}
}
else
{
c = 0;
}
if (v && (!nulflg || *v))
{
if (c != '+')
{
for (;;)
{
if (*v == 0 && quote) {
pushstak('\\');
pushstak('\0');
} else {
while (c = *v) {
int length;
length = 1;
pushstak('\\');
}
while(length-- > 0) {
pushstak(*v++);
}
}
}
break;
else /* $* and $@ expansion */
{
/* push quoted space so that " $* " will not be broken into separate arguments */
pushstak('\\');
}
pushstak(' ');
}
}
}
}
else if (argp)
{
if (c == '?') {
if(trimflag)
badparam);
}
else if (c == '=')
{
if (n)
{
unsigned char *newargp;
/*
* copy word onto stack, trim it, and then
* do assignment
*/
usestak();
while(c = *argp) {
int len;
len = 1;
if(c == '\\' && trimflag) {
argp++;
if (*argp == 0) {
argp++;
continue;
}
len = 1;
}
while(len-- > 0) {
}
}
}
else
}
}
goto retry;
}
else
}
else if (d == endch)
return(d);
else if (d == SQUOTE)
{
goto retry;
}
{
if(!quote) {
atflag = 0;
quoted++;
}
goto retry;
}
return(d);
}
unsigned char *
unsigned char *as;
{
/*
* Strip "" and do $ substitution
* Leaves result on top of stack
*/
usestak();
quote = 0;
quoted = 0;
copyto(0, 1);
pop();
pushstak('\\');
pushstak('\0');
/*
* above is the fix for *'.c' bug
*/
}
return(fixstak());
}
/* Save file descriptor for command substitution */
static void
/* trimflag - used to determine if argument will later be trimmed */
{
/*
* command substn
*/
unsigned int d;
unsigned char *oldstaktop;
unsigned char *pc;
usestak();
if(d == '\\') {
d = readwc();
/* trim quotes for `, \, or " if command substitution is within
double quotes */
pushstak('\\');
}
}
/* d might be NULL */
if (*pc) {
while (*pc) {
}
} else {
}
}
{
unsigned char *argc;
}
{
struct trenod *t;
/*
* this is done like this so that the pipe
* is open only when needed
*/
savpipe = -1;
}
while (d = readwc()) {
unsigned char *rest;
/* quote output from command subst. if within double
quotes or backslash part of output */
pushstak('\\');
while(d = *rest++) {
/* Pick up all of multibyte character */
pushstak(d);
}
}
else {
while (*pc) {
}
}
}
{
int stat;
int rc;
int ret = 0;
/* break out if waitpid(2) has failed */
if (ret == -1)
break;
}
else
exitset();
}
while (oldstaktop != staktop)
{ /* strip off trailing newlines from command substitution only */
{
++staktop;
break;
} else if(quote)
staktop--; /* skip past backslashes if quoting */
}
pop();
}
void
{
unsigned int c;
unsigned char *pc;
/*
* DQUOTE used to stop it from quoting
*/
and interpret them */
{
if(c == '\\') {
c = readwc(); /* check if character in here document is
escaped */
if(!escchar(c) || c == '"') {
pushstak('\\');
}
}
/* c might be NULL */
if (*pc) {
while (*pc) {
}
} else {
}
if (--count == 0)
{
}
}
pop();
}
static void
{
}