name.c revision 965005c81e0f731867d47892b9fb677030b102df
/*
* 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 2003 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 <stropts.h>
extern unsigned char *simple();
extern int mailchk;
static void setname(unsigned char *, int);
static void set_builtins_path();
static int patheq();
static void dolocale();
{
&acctnod,
(unsigned char *)ps2name
};
{
(unsigned char *)cdpname
};
{
&mailpnod,
(unsigned char *)pathname
};
{
&homenod,
&mailnod,
(unsigned char *)ifsname
};
{
&pathnod,
&ps2nod,
(unsigned char *)ps1name
};
{
&cdpnod,
(unsigned char *)homename
};
{
(unsigned char *)mailname
};
{
&ifsnod,
&ps1nod,
(unsigned char *)mchkname
};
{
(unsigned char *)acctname
};
{
(unsigned char *)mailpname
};
/* ======== variable and string handling ======== */
int
{
int low;
int high;
int mid;
int cond;
if (w == 0 || *w == 0)
return(0);
low = 0;
high = n - 1;
{
else if (cond > 0)
else
}
return(0);
}
void
{
while (arg)
{
{
prs(s);
if (arg)
blank();
else
newline();
}
}
}
static void
{
struct namnod *n;
{
argscan++;
if (*argscan == '=')
{
*argscan = 0; /* make name a cohesive string */
*argscan++ = '=';
{
if (n == &pathnod)
}
else
return;
}
}
}
void
replace(unsigned char **a, unsigned char *v)
{
free(*a);
*a = make(v);
}
void
{
if (n->namval == 0)
assign(n, v);
}
void
{
#ifndef RES
{
}
#endif
{
func_unhash(n->namid);
freefunc(n);
n->namenv = 0;
}
if (n == &mchknod)
{
}
if (n == &pathnod)
{
zaphash();
set_dotpath();
return;
}
{
}
}
static void
{
unsigned char *path;
ucb_builtins = 0;
{
{
ucb_builtins++;
break;
}
break;
break;
break;
}
}
static int
{
unsigned char c;
for (;;)
{
c = *component++;
if (c == COLON)
c = '\0'; /* end of component of path */
if (c != *dir++)
return (0);
if (c == '\0')
return(1);
}
}
int
{
unsigned char c[MULTI_BYTE_MAX+1];
int rc = 0;
unsigned char *oldstak;
int d;
push(f);
/*
* If stdin is a pipe then this lseek(2) will fail with ESPIPE, so
* the read buffer size is set to 1 because we will not be able
* lseek(2) back towards the beginning of the file, so we have
* to read a byte at a time instead
*
*/
f->fsiz = 1;
/*
* If stdin is a socket then this isastream(3C) will return 1, so
* the read buffer size is set to 1 because we will not be able
* lseek(2) back towards the beginning of the file, so we have
* to read a byte at a time instead
*
*/
if (isastream(0) == 1)
f->fsiz = 1;
/*
* strip leading IFS characters
*/
for (;;)
{
d = nextwc();
if(eolchar(d))
break;
pc = c;
break;
}
for (;;)
{
{
zerostak();
if (*names)
else
n = 0;
if (eolchar(d))
{
break;
}
else /* strip imbedded IFS characters */
while(1) {
d = nextwc();
if(eolchar(d))
break;
pc = c;
break;
}
}
else
{
if(d == '\\') {
d = readwc();
while(d = *rest++) {
pushstak(d);
}
}
else
{
pc = c;
while(d = *pc++) {
pushstak(d);
}
}
d = nextwc();
if (eolchar(d))
else
{
pc = c;
}
}
}
while (n)
{
if (*names)
else
n = 0;
}
if (eof)
rc = 1;
if (isastream(0) != 1)
/*
* If we are reading on a stream do not attempt to
* lseek(2) back towards the start because this is
* logically meaningless, but there is nothing in
* the standards to pervent the stream implementation
* from attempting it and breaking our code here
*
*/
pop();
return(rc);
}
void
assnum(unsigned char **p, long i)
{
int j = ltos(i);
}
unsigned char *
make(v)
unsigned char *v;
{
unsigned char *p;
if (v)
{
return(p);
}
else
return(0);
}
struct namnod *
{
int LR;
while (nscan)
{
return(nscan);
else if (LR < 0)
else
}
/*
* add name node
*/
}
unsigned char *nam;
{
return(FALSE);
else
{
while (*++cp)
{
return(FALSE);
}
}
return(TRUE);
}
static void (*namfn)();
void
{
}
static void
{
if (np)
{
}
}
void
{
unsigned char *s;
sigchk();
{
prs_buff("(){\n");
prs_buff("\n}\n");
}
else if (s = n->namval)
{
prc_buff('=');
prs_buff(s);
}
}
static unsigned char *
{
unsigned char *p;
p = movstrstak("=", p);
p = movstrstak(n->namval, p);
}
static int namec;
void
{
{
{
}
else
{
}
}
if (n->namval)
namec++;
}
void
{
{
}
}
void
{
{
}
}
void
setup_env(void)
{
unsigned char **e = environ;
while (*e)
}
static unsigned char **argnam;
static void
{
if (n->namval)
namec++;
}
static void
{
unsigned char *p;
unsigned char *namval;
else {
/* Discard Local variable in child process */
n->namflg = 0;
n->namenv = 0;
if (n->namval) {
/* Release for re-use */
}
}
}
if (namval)
{
p = movstrstak("=", p);
p = movstrstak(namval, p);
}
}
unsigned char **
{
unsigned char **er;
namec = 0;
*argnam++ = 0;
return(er);
}
void
setvars()
{
}
struct namnod *
unsigned char *nam;
{
int LR;
return(0);
while (nscan)
{
return(nscan);
else if (LR < 0)
else
}
return(0);
}
void
unset_name(unsigned char *name)
{
struct namnod *n;
unsigned char call_dolocale = 0;
{
if (n == &pathnod ||
n == &ifsnod ||
n == &ps1nod ||
n == &ps2nod ||
n == &mchknod)
{
}
#ifndef RES
#endif
{
freefunc(n);
}
else
{
}
if (call_dolocale)
{
if (n == &mailpnod)
setmail(0);
}
}
}
/*
* The environment variables which affect locale.
* Note: if all names in this list do not begin with 'L',
* you MUST modify dolocale(). Also, be sure that the
* fake_env has the same number of elements as localevar.
*/
static char *localevar[] = {
"LC_ALL",
"LC_CTYPE",
"LC_MESSAGES",
"LANG",
0
};
static char *fake_env[] = {
0,
0,
0,
0,
0
};
/*
* If name is one of several special variables which affect the locale,
* do a setlocale().
*/
static void
char *nm;
{
char **real_env;
struct namnod *n;
int i;
/*
* Take advantage of fact that names of these vars all start
* with 'L' to avoid unnecessary work.
* Do locale processing only if /usr is mounted.
*/
return;
/*
* setlocale() has all the smarts built into it, but
* it works by examining the environment. Unfortunately,
* when you set an environment variable, the shell does
* not modify its own environment; it just remembers that the
* variable needs to be exported to any children. We hack around
* this by consing up a fake environment for the use of setlocale()
* and substituting it for the real env before calling setlocale().
*/
/*
* Build the fake environment.
* Look up the value of each of the special environment
* variables, and put their value into the fake environment,
* if they are exported.
*/
char *p, *q;
if (!n->namval)
continue;
/* copy name */
while (*q)
*p++ = *q++;
*p++ = '=';
/* copy value */
q = (char*)(n->namval);
while (*q)
*p++ = *q++;
*p++ = '\0';
}
}
/*
* Switch fake env for real and call setlocale().
*/
prs("couldn't set locale correctly\n");
/*
* Switch back and tear down the fake env.
*/
for (i = 0; i < fe; i++) {
fake_env[i] = (char *)0;
}
}