Quizzer
view release on metacpan or search on metacpan
exercises/compile-tcsh/tcsh-6.10.00/sh.func.c view on Meta::CPAN
}
/* check whether an environment variable should invoke 'set_locale()' */
static bool
islocale_var(var)
Char *var;
{
static Char *locale_vars[] = {
STRLANG, STRLC_CTYPE, STRLC_NUMERIC, STRLC_TIME,
STRLC_COLLATE, STRLC_MESSAGES, STRLC_MONETARY, 0
};
register Char **v;
for (v = locale_vars; *v; ++v)
if (eq(var, *v))
return 1;
return 0;
}
/*ARGSUSED*/
void
doprintenv(v, c)
register Char **v;
struct command *c;
{
Char *e;
extern bool output_raw;
extern bool xlate_cr;
USE(c);
if (setintr)
#ifdef BSDSIGS
(void) sigsetmask(sigblock((sigmask_t) 0) & ~sigmask(SIGINT));
#else /* !BSDSIGS */
(void) sigrelse (SIGINT);
#endif /* BSDSIGS */
v++;
if (*v == 0) {
register Char **ep;
xlate_cr = 1;
for (ep = STR_environ; *ep; ep++)
xprintf("%S\n", *ep);
xlate_cr = 0;
}
else if ((e = tgetenv(*v)) != NULL) {
output_raw = 1;
xprintf("%S\n", e);
output_raw = 0;
}
else
set(STRstatus, Strsave(STR1), VAR_READWRITE);
}
/* from "Karl Berry." <karl%mote.umb.edu@relay.cs.net> -- for NeXT things
(and anything else with a modern compiler) */
/*ARGSUSED*/
void
dosetenv(v, c)
register Char **v;
struct command *c;
{
Char *vp, *lp;
USE(c);
if (*++v == 0) {
doprintenv(--v, 0);
return;
}
vp = *v++;
if ((lp = *v++) == 0)
lp = STRNULL;
tsetenv(vp, lp = globone(lp, G_APPEND));
if (eq(vp, STRKPATH)) {
importpath(lp);
dohash(NULL, NULL);
xfree((ptr_t) lp);
return;
}
#ifdef apollo
if (eq(vp, STRSYSTYPE)) {
dohash(NULL, NULL);
xfree((ptr_t) lp);
return;
}
#endif /* apollo */
/* dspkanji/dspmbyte autosetting */
/* PATCH IDEA FROM Issei.Suzuki VERY THANKS */
#if defined(DSPMBYTE)
if(eq(vp, STRLANG) && !adrof(CHECK_MBYTEVAR)) {
autoset_dspmbyte(lp);
}
#endif
if (islocale_var(vp)) {
#ifdef NLS
int k;
# ifdef SETLOCALEBUG
dont_free = 1;
# endif /* SETLOCALEBUG */
(void) setlocale(LC_ALL, "");
# ifdef LC_COLLATE
(void) setlocale(LC_COLLATE, "");
# endif
# ifdef NLS_CATALOGS
# ifdef LC_MESSAGES
(void) setlocale(LC_MESSAGES, "");
# endif /* LC_MESSAGES */
(void) catclose(catd);
nlsinit();
# endif /* NLS_CATALOGS */
# ifdef LC_CTYPE
(void) setlocale(LC_CTYPE, ""); /* for iscntrl */
# endif /* LC_CTYPE */
# ifdef SETLOCALEBUG
dont_free = 0;
# endif /* SETLOCALEBUG */
# ifdef STRCOLLBUG
fix_strcoll_bug();
# endif /* STRCOLLBUG */
tw_cmd_free(); /* since the collation sequence has changed */
for (k = 0200; k <= 0377 && !Isprint(k); k++)
continue;
AsciiOnly = k > 0377;
#else /* !NLS */
AsciiOnly = 0;
#endif /* NLS */
NLSMapsAreInited = 0;
ed_Init();
if (MapsAreInited && !NLSMapsAreInited)
exercises/compile-tcsh/tcsh-6.10.00/sh.func.c view on Meta::CPAN
*/
lp = dcanon(lp, lp);
set(STRhome, quote(lp), VAR_READWRITE); /* cp memory used here */
/* fix directory stack for new tilde home */
dtilde();
return;
}
if (eq(vp, STRKSHLVL)) {
/* lp memory used here */
set(STRshlvl, quote(lp), VAR_READWRITE);
return;
}
if (eq(vp, STRKUSER)) {
set(STRuser, quote(lp), VAR_READWRITE); /* lp memory used here */
return;
}
if (eq(vp, STRKGROUP)) {
set(STRgroup, quote(lp), VAR_READWRITE); /* lp memory used here */
return;
}
#ifdef COLOR_LS_F
if (eq(vp, STRLS_COLORS)) {
parseLS_COLORS(lp);
return;
}
#endif /* COLOR_LS_F */
#ifdef SIG_WINDOW
/*
* Load/Update $LINES $COLUMNS
*/
if ((eq(lp, STRNULL) && (eq(vp, STRLINES) || eq(vp, STRCOLUMNS))) ||
eq(vp, STRTERMCAP)) {
xfree((ptr_t) lp);
check_window_size(1);
return;
}
/*
* Change the size to the one directed by $LINES and $COLUMNS
*/
if (eq(vp, STRLINES) || eq(vp, STRCOLUMNS)) {
#if 0
GotTermCaps = 0;
#endif
xfree((ptr_t) lp);
ed_Init();
return;
}
#endif /* SIG_WINDOW */
xfree((ptr_t) lp);
}
/*ARGSUSED*/
void
dounsetenv(v, c)
register Char **v;
struct command *c;
{
Char **ep, *p, *n;
int i, maxi;
static Char *name = NULL;
USE(c);
if (name)
xfree((ptr_t) name);
/*
* Find the longest environment variable
*/
for (maxi = 0, ep = STR_environ; *ep; ep++) {
for (i = 0, p = *ep; *p && *p != '='; p++, i++)
continue;
if (i > maxi)
maxi = i;
}
name = (Char *) xmalloc((size_t) ((maxi + 1) * sizeof(Char)));
while (++v && *v)
for (maxi = 1; maxi;)
for (maxi = 0, ep = STR_environ; *ep; ep++) {
for (n = name, p = *ep; *p && *p != '='; *n++ = *p++)
continue;
*n = '\0';
if (!Gmatch(name, *v))
continue;
maxi = 1;
/* Unset the name. This wasn't being done until
* later but most of the stuff following won't
* work (particularly the setlocale() and getenv()
* stuff) as intended until the name is actually
* removed. (sg)
*/
Unsetenv(name);
if (eq(name, STRNOREBIND)) {
NoNLSRebind = 0;
MapsAreInited = 0;
NLSMapsAreInited = 0;
ed_InitMaps();
}
#ifdef apollo
else if (eq(name, STRSYSTYPE))
dohash(NULL, NULL);
#endif /* apollo */
else if (islocale_var(name)) {
#ifdef NLS
int k;
# ifdef SETLOCALEBUG
dont_free = 1;
# endif /* SETLOCALEBUG */
(void) setlocale(LC_ALL, "");
# ifdef LC_COLLATE
(void) setlocale(LC_COLLATE, "");
# endif
# ifdef NLS_CATALOGS
# ifdef LC_MESSAGES
(void) setlocale(LC_MESSAGES, "");
# endif /* LC_MESSAGES */
(void) catclose(catd);
nlsinit();
# endif /* NLS_CATALOGS */
# ifdef LC_CTYPE
(void) setlocale(LC_CTYPE, ""); /* for iscntrl */
# endif /* LC_CTYPE */
# ifdef SETLOCALEBUG
dont_free = 0;
# endif /* SETLOCALEBUG */
# ifdef STRCOLLBUG
fix_strcoll_bug();
# endif /* STRCOLLBUG */
tw_cmd_free();/* since the collation sequence has changed */
for (k = 0200; k <= 0377 && !Isprint(k); k++)
continue;
AsciiOnly = k > 0377;
#else /* !NLS */
AsciiOnly = getenv("LANG") == NULL &&
getenv("LC_CTYPE") == NULL;
#endif /* NLS */
NLSMapsAreInited = 0;
ed_Init();
if (MapsAreInited && !NLSMapsAreInited)
ed_InitNLSMaps();
}
#ifdef WINNT_NATIVE
else if (eq(name,(STRtcshlang))) {
nls_dll_unload();
nlsinit();
}
#endif /* WINNT_NATIVE */
#ifdef COLOR_LS_F
else if (eq(name, STRLS_COLORS))
parseLS_COLORS(n);
#endif /* COLOR_LS_F */
/*
* start again cause the environment changes
*/
break;
}
xfree((ptr_t) name); name = NULL;
}
void
tsetenv(name, val)
Char *name, *val;
{
#ifdef SETENV_IN_LIB
/*
* XXX: This does not work right, since tcsh cannot track changes to
* the environment this way. (the builtin setenv without arguments does
* not print the right stuff neither does unsetenv). This was for Mach,
* it is not needed anymore.
*/
#undef setenv
char nameBuf[BUFSIZE];
char *cname = short2str(name);
if (cname == NULL)
return;
(void) strcpy(nameBuf, cname);
setenv(nameBuf, short2str(val), 1);
#else /* !SETENV_IN_LIB */
register Char **ep = STR_environ;
register Char *cp, *dp;
Char *blk[2];
Char **oep = ep;
#ifdef WINNT_NATIVE
nt_set_env(name,val);
#endif /* WINNT_NATIVE */
for (; *ep; ep++) {
#ifdef WINNT_NATIVE
for (cp = name, dp = *ep; *cp && Tolower(*cp & TRIM) == Tolower(*dp);
cp++, dp++)
#else
for (cp = name, dp = *ep; *cp && (*cp & TRIM) == *dp; cp++, dp++)
#endif /* WINNT_NATIVE */
continue;
if (*cp != 0 || *dp != '=')
continue;
cp = Strspl(STRequal, val);
xfree((ptr_t) * ep);
*ep = strip(Strspl(name, cp));
xfree((ptr_t) cp);
blkfree((Char **) environ);
environ = short2blk(STR_environ);
return;
}
cp = Strspl(name, STRequal);
blk[0] = strip(Strspl(cp, val));
xfree((ptr_t) cp);
blk[1] = 0;
STR_environ = blkspl(STR_environ, blk);
blkfree((Char **) environ);
environ = short2blk(STR_environ);
xfree((ptr_t) oep);
#endif /* SETENV_IN_LIB */
}
void
Unsetenv(name)
Char *name;
{
register Char **ep = STR_environ;
register Char *cp, *dp;
Char **oep = ep;
#ifdef WINNT_NATIVE
nt_set_env(name,NULL);
#endif /*WINNT_NATIVE */
for (; *ep; ep++) {
for (cp = name, dp = *ep; *cp && *cp == *dp; cp++, dp++)
continue;
if (*cp != 0 || *dp != '=')
continue;
cp = *ep;
*ep = 0;
STR_environ = blkspl(STR_environ, ep + 1);
blkfree((Char **) environ);
environ = short2blk(STR_environ);
*ep = cp;
xfree((ptr_t) cp);
xfree((ptr_t) oep);
return;
}
}
/*ARGSUSED*/
void
doumask(v, c)
register Char **v;
struct command *c;
{
register Char *cp = v[1];
register int i;
USE(c);
if (cp == 0) {
i = (int)umask(0);
(void) umask(i);
xprintf("%o\n", i);
return;
}
i = 0;
while (Isdigit(*cp) && *cp != '8' && *cp != '9')
i = i * 8 + *cp++ - '0';
if (*cp || i < 0 || i > 0777)
stderror(ERR_NAME | ERR_MASK);
(void) umask(i);
}
#ifndef HAVENOLIMIT
# ifndef BSDLIMIT
typedef long RLIM_TYPE;
# ifndef RLIM_INFINITY
# if !defined(_MINIX) && !defined(__clipper__) && !defined(_CRAY)
extern RLIM_TYPE ulimit();
# endif /* ! _MINIX && !__clipper__ */
# define RLIM_INFINITY 0x003fffff
# define RLIMIT_FSIZE 1
# endif /* RLIM_INFINITY */
( run in 2.084 seconds using v1.01-cache-2.11-cpan-56fb94df46f )