Quizzer
view release on metacpan or search on metacpan
exercises/compile-tcsh/tcsh-6.10.00/tc.os.c view on Meta::CPAN
#include "sh.h"
RCSID("$Id: tc.os.c,v 3.52 2000/11/11 23:03:39 christos Exp $")
#include "tw.h"
#include "ed.h"
#include "ed.defns.h" /* for the function names */
#include "sh.decls.h"
#ifdef _UWIN
#define TIOCGPGRP TIOCGETPGRP
#define TIOCSPGRP TIOCSETPGRP
#endif
/***
*** MACH
***/
#ifdef MACH
/* dosetpath -- setpath built-in command
*
**********************************************************************
* HISTORY
* 08-May-88 Richard Draves (rpd) at Carnegie-Mellon University
* Major changes to remove artificial limits on sizes and numbers
* of paths.
*
**********************************************************************
*/
#ifdef MACH
static Char STRCPATH[] = {'C', 'P', 'A', 'T', 'H', '\0'};
static Char STRLPATH[] = {'L', 'P', 'A', 'T', 'H', '\0'};
static Char STRMPATH[] = {'M', 'P', 'A', 'T', 'H', '\0'};
# if EPATH
static Char STREPATH[] = {'E', 'P', 'A', 'T', 'H', '\0'};
# endif
#endif /* MACH */
static Char *syspaths[] = {STRKPATH, STRCPATH, STRLPATH, STRMPATH,
#if EPATH
STREPATH,
#endif
0};
#define LOCALSYSPATH "/usr/local"
/*ARGSUSED*/
void
dosetpath(arglist, c)
Char **arglist;
struct command *c;
{
extern char *getenv();
sigmask_t omask;
Char **pathvars, **cmdargs;
char **spaths, **cpaths, **cmds;
char *tcp;
unsigned int npaths, ncmds;
int i, sysflag;
omask = sigsetmask(sigmask(SIGINT));
/*
* setpath(3) uses stdio and we want 0, 1, 2 to work...
*/
if (!didfds) {
(void) dcopy(SHIN, 0);
(void) dcopy(SHOUT, 1);
(void) dcopy(SHDIAG, 2);
didfds = 1;
}
for (i = 1; arglist[i] && (arglist[i][0] != '-'); i++);
npaths = i - 1;
cmdargs = &arglist[i];
for (; arglist[i]; i++);
ncmds = i - npaths - 1;
if (npaths) {
sysflag = 0;
pathvars = &arglist[1];
}
else {
sysflag = 1;
npaths = (sizeof syspaths / sizeof *syspaths) - 1;
pathvars = syspaths;
}
/* note that npaths != 0 */
spaths = (char **) xmalloc((size_t) npaths * sizeof *spaths);
setzero((char *) spaths, npaths * sizeof *spaths);
cpaths = (char **) xmalloc((size_t) (npaths + 1) * sizeof *cpaths);
setzero((char *) cpaths, (npaths + 1) * sizeof *cpaths);
cmds = (char **) xmalloc((size_t) (ncmds + 1) * sizeof *cmds);
setzero((char *) cmds, (ncmds + 1) * sizeof *cmds);
for (i = 0; i < npaths; i++) {
char *val = getenv(short2str(pathvars[i]));
if (val == NULL)
val = "";
spaths[i] = (char *) xmalloc((size_t) (Strlen(pathvars[i]) +
strlen(val) + 2) * sizeof **spaths);
(void) strcpy(spaths[i], short2str(pathvars[i]));
(void) strcat(spaths[i], "=");
(void) strcat(spaths[i], val);
cpaths[i] = spaths[i];
}
for (i = 0; i < ncmds; i++) {
Char *val = globone(cmdargs[i], G_ERROR);
if (val == NULL)
goto abortpath;
cmds[i] = (char *) xmalloc((size_t) Strlen(val) + 1);
(void) strcpy(cmds[i], short2str(val));
}
if (setpath(cpaths, cmds, LOCALSYSPATH, sysflag, 1) < 0) {
abortpath:
if (spaths) {
for (i = 0; i < npaths; i++)
if (spaths[i])
xfree((ptr_t) spaths[i]);
xfree((ptr_t) spaths);
}
if (cpaths)
xfree((ptr_t) cpaths);
if (cmds) {
for (i = 0; i < ncmds; i++)
if (cmds[i])
xfree((ptr_t) cmds[i]);
xfree((ptr_t) cmds);
}
(void) sigsetmask(omask);
donefds();
return;
}
for (i = 0; i < npaths; i++) {
Char *val, *name;
name = str2short(cpaths[i]);
for (val = str2short(cpaths[i]); val && *val && *val != '='; val++);
if (val && *val == '=') {
*val++ = '\0';
tsetenv(name, val);
if (Strcmp(name, STRKPATH) == 0) {
importpath(val);
if (havhash)
dohash(NULL, NULL);
}
*--val = '=';
}
}
(void) sigsetmask(omask);
donefds();
}
#endif /* MACH */
/***
*** AIX
***/
#ifdef TCF
/* ARGSUSED */
void
dogetxvers(v, c)
Char **v;
struct command *c;
{
char xvers[MAXPATHLEN];
if (getxvers(xvers, MAXPATHLEN) == -1)
stderror(ERR_SYSTEM, "getxvers", strerror(errno));
xprintf("%s\n", xvers);
flush();
}
/*ARGSUSED*/
void
dosetxvers(v, c)
Char **v;
struct command *c;
{
char *xvers;
++v;
if (!*v || *v[0] == '\0')
xvers = "";
else
xvers = short2str(*v);
if (setxvers(xvers) == -1)
stderror(ERR_SYSTEM, "setxvers", strerror(errno));
}
#include <sf.h>
#ifdef _AIXPS2
# define XC_PDP11 0x01
# define XC_23 0x02
# define XC_Z8K 0x03
# define XC_8086 0x04
# define XC_68K 0x05
# define XC_Z80 0x06
# define XC_VAX 0x07
# define XC_16032 0x08
# define XC_286 0x09
# define XC_386 0x0a
# define XC_S370 0x0b
#else
# include <sys/x.out.h>
#endif /* _AIXPS2 */
static struct xc_cpu_t {
short xc_id;
char *xc_name;
} xcpu[] =
exercises/compile-tcsh/tcsh-6.10.00/tc.os.c view on Meta::CPAN
#endif /* BSDSIGS */
++v;
if (*v[0] == '-') {
/*
* Do the -site.
*/
s = short2str(&v[0][1]);
/*
* see comment in setspath()
*/
dont_free = 1;
if ((st = sfname(s)) == NULL) {
setname(s);
stderror(ERR_NAME | ERR_STRING, CGETS(23, 7, "Site not found"));
}
dont_free = 0;
new_site = st->sf_id;
++v;
}
if (!*v || *v[0] == '\0') {
if (migratepid(0, new_site) == -1)
err1++;
}
else {
gflag = 0, tglob(v);
if (gflag) {
v = globall(v);
if (v == 0)
stderror(ERR_NAME | ERR_NOMATCH);
}
else {
v = gargv = saveblk(v);
trim(v);
}
while (v && (cp = *v)) {
if (*cp == '%') {
pp = pfind(cp);
if (kill3((pid_t) - pp->p_jobid, SIGMIGRATE, new_site) < 0) {
xprintf("%S: %s\n", cp, strerror(errno));
err1++;
}
}
else if (!(Isdigit(*cp) || *cp == '-'))
stderror(ERR_NAME | ERR_JOBARGS);
else {
pid = atoi(short2str(cp));
if (migratepid(pid, new_site) == -1)
err1++;
}
v++;
}
if (gargv)
blkfree(gargv), gargv = 0;
}
done:
#ifdef BSDSIGS
(void) sigsetmask(omask);
#else
(void) sigrelse(SIGCHLD);
if (setintr)
(void) sigrelse(SIGINT);
#endif /* BSDSIGS */
if (err1)
stderror(ERR_SILENT);
}
#endif /* TCF */
/***
*** CRAY ddmode <velo@sesun3.epfl.ch> (Martin Ouwehand EPFL-SIC/SE)
***/
#if defined(_CRAY) && !defined(_CRAYMPP)
void
dodmmode(v, c)
Char **v;
struct command *c;
{
Char *cp = v[1];
USE(c);
if ( !cp ) {
int mode;
mode = dmmode(0);
dmmode(mode);
xprintf("%d\n",mode);
}
else {
if (cp[1] != '\0')
stderror(ERR_NAME | ERR_STRING,
CGETS(23, 30, "Too many arguments"));
else
switch(*cp) {
case '0':
dmmode(0);
break;
case '1':
dmmode(1);
break;
default:
stderror(ERR_NAME | ERR_STRING,
CGETS(23, 31, "Invalid argument"));
}
}
}
#endif /* _CRAY && !_CRAYMPP */
/***
*** CONVEX Warps.
***/
#ifdef WARP
/*
* handle the funky warping of symlinks
*/
exercises/compile-tcsh/tcsh-6.10.00/tc.os.c view on Meta::CPAN
else {
we = getwarpbyname(newwarp);
if (we)
warp = we->w_value;
else
warp = -1;
}
if ((warp < 0) || (warp >= WARP_MAXLINK))
stderror(ERR_NAME | ERR_STRING, CGETS(23, 10, "Invalid warp"));
if ((setwarp(warp) < 0) || (getwarp() != warp)) {
(void) setwarp(oldwarp);
stderror(ERR_NAME | ERR_STRING, CGETS(23, 11, "Setwarp failed"));
}
}
signal(SIGSYS, old_sigsys_handler);
return;
}
#endif /* WARP */
/***
*** Masscomp or HCX
***/
/* Added, DAS DEC-90. */
#if defined(masscomp) || defined(_CX_UX)
/*ARGSUSED*/
void
douniverse(v, c)
register Char **v;
struct command *c;
{
register Char *cp = v[1];
register Char *cp2; /* dunno how many elements v comes in with */
char ubuf[100];
#ifdef BSDSIGS
register sigmask_t omask = 0;
#endif /* BSDSIGS */
if (cp == 0) {
(void) getuniverse(ubuf);
xprintf("%s\n", ubuf);
}
else {
cp2 = v[2];
if (cp2 == 0) {
if (*cp == '\0' || setuniverse(short2str(cp)) != 0)
stderror(ERR_NAME | ERR_STRING, CGETS(23, 12, "Illegal universe"));
}
else {
(void) getuniverse(ubuf);
if (*cp == '\0' || setuniverse(short2str(cp)) != 0)
stderror(ERR_NAME | ERR_STRING, CGETS(23, 12, "Illegal universe"));
if (setintr)
#ifdef BSDSIGS
omask = sigblock(sigmask(SIGINT)) & ~sigmask(SIGINT);
#else /* !BSDSIGS */
(void) sighold(SIGINT);
#endif /* BSDSIGS */
lshift(v, 2);
if (setintr)
#ifdef BSDSIGS
(void) sigsetmask(omask);
#else /* !BSDSIGS */
(void) sigrelse (SIGINT);
#endif /* BSDSIGS */
reexecute(c);
(void) setuniverse(ubuf);
}
}
}
#endif /* masscomp || _CX_UX */
#if defined(_CX_UX)
/*ARGSUSED*/
void
doatt(v, c)
register Char **v;
struct command *c;
{
register Char *cp = v[1];
char ubuf[100];
#ifdef BSDSIGS
register sigmask_t omask = 0;
#endif /* BSDSIGS */
if (cp == 0)
(void) setuniverse("att");
else {
(void) getuniverse(ubuf);
(void) setuniverse("att");
if (setintr)
#ifdef BSDSIGS
omask = sigblock(sigmask(SIGINT)) & ~sigmask(SIGINT);
#else /* !BSDSIGS */
(void) sighold(SIGINT);
#endif /* BSDSIGS */
lshift(v, 1);
if (setintr)
#ifdef BSDSIGS
(void) sigsetmask(omask);
#else /* !BSDSIGS */
(void) sigrelse (SIGINT);
#endif /* BSDSIGS */
reexecute(c);
(void) setuniverse(ubuf);
}
}
/*ARGSUSED*/
void
doucb(v, c)
register Char **v;
struct command *c;
{
register Char *cp = v[1];
char ubuf[100];
#ifdef BSDSIGS
register sigmask_t omask = 0;
#endif /* BSDSIGS */
if (cp == 0)
(void) setuniverse("ucb");
else {
(void) getuniverse(ubuf);
(void) setuniverse("ucb");
if (setintr)
#ifdef BSDSIGS
omask = sigblock(sigmask(SIGINT)) & ~sigmask(SIGINT);
#else /* !BSDSIGS */
(void) sighold(SIGINT);
#endif /* BSDSIGS */
lshift(v, 1);
if (setintr)
#ifdef BSDSIGS
(void) sigsetmask(omask);
#else /* !BSDSIGS */
(void) sigrelse (SIGINT);
#endif /* BSDSIGS */
reexecute(c);
(void) setuniverse(ubuf);
}
}
#endif /* _CX_UX */
#ifdef _SEQUENT_
/*
* Compute the difference in process stats.
*/
void
pr_stat_sub(p2, p1, pr)
struct process_stats *p2, *p1, *pr;
{
pr->ps_utime.tv_sec = p2->ps_utime.tv_sec - p1->ps_utime.tv_sec;
pr->ps_utime.tv_usec = p2->ps_utime.tv_usec - p1->ps_utime.tv_usec;
if (pr->ps_utime.tv_usec < 0) {
pr->ps_utime.tv_sec -= 1;
pr->ps_utime.tv_usec += 1000000;
}
pr->ps_stime.tv_sec = p2->ps_stime.tv_sec - p1->ps_stime.tv_sec;
pr->ps_stime.tv_usec = p2->ps_stime.tv_usec - p1->ps_stime.tv_usec;
if (pr->ps_stime.tv_usec < 0) {
pr->ps_stime.tv_sec -= 1;
pr->ps_stime.tv_usec += 1000000;
}
pr->ps_maxrss = p2->ps_maxrss - p1->ps_maxrss;
pr->ps_pagein = p2->ps_pagein - p1->ps_pagein;
pr->ps_reclaim = p2->ps_reclaim - p1->ps_reclaim;
pr->ps_zerofill = p2->ps_zerofill - p1->ps_zerofill;
pr->ps_pffincr = p2->ps_pffincr - p1->ps_pffincr;
pr->ps_pffdecr = p2->ps_pffdecr - p1->ps_pffdecr;
pr->ps_swap = p2->ps_swap - p1->ps_swap;
pr->ps_syscall = p2->ps_syscall - p1->ps_syscall;
pr->ps_volcsw = p2->ps_volcsw - p1->ps_volcsw;
pr->ps_involcsw = p2->ps_involcsw - p1->ps_involcsw;
pr->ps_signal = p2->ps_signal - p1->ps_signal;
pr->ps_lread = p2->ps_lread - p1->ps_lread;
pr->ps_lwrite = p2->ps_lwrite - p1->ps_lwrite;
pr->ps_bread = p2->ps_bread - p1->ps_bread;
pr->ps_bwrite = p2->ps_bwrite - p1->ps_bwrite;
pr->ps_phread = p2->ps_phread - p1->ps_phread;
pr->ps_phwrite = p2->ps_phwrite - p1->ps_phwrite;
}
#endif /* _SEQUENT_ */
#ifdef NEEDmemset
/* This is a replacement for a missing memset function */
ptr_t xmemset(loc, value, len)
ptr_t loc;
int len;
size_t value;
{
char *ptr = (char *) loc;
( run in 1.870 second using v1.01-cache-2.11-cpan-364913b4093 )