Quizzer
view release on metacpan or search on metacpan
exercises/compile-tcsh/tcsh-6.10.00/sh.dol.c view on Meta::CPAN
register struct varent *vp = NULL;
Char name[4 * MAXVARLEN + 1];
int c, sc;
int subscr = 0, lwb = 1, upb = 0;
bool dimen = 0, bitset = 0, length = 0;
char tnp;
Char wbuf[BUFSIZE];
static Char *dolbang = NULL;
#ifdef COMPAT
dolmod = dolmcnt = dolwcnt = 0;
#else
dolnmod = dolmcnt = dolwcnt = 0;
#endif /* COMPAT */
c = sc = DgetC(0);
if (c == '{')
c = DgetC(0); /* sc is { to take } later */
if ((c & TRIM) == '#')
dimen++, c = DgetC(0); /* $# takes dimension */
else if (c == '?')
bitset++, c = DgetC(0); /* $? tests existence */
else if (c == '%')
length++, c = DgetC(0); /* $% returns length in chars */
switch (c) {
case '!':
if (dimen || bitset || length)
stderror(ERR_SYNTAX);
if (backpid != 0) {
if (dolbang)
xfree((ptr_t) dolbang);
setDolp(dolbang = putn(backpid));
}
goto eatbrac;
case '$':
if (dimen || bitset || length)
stderror(ERR_SYNTAX);
setDolp(doldol);
goto eatbrac;
#ifdef COHERENT
/* Coherent compiler doesn't allow case-labels that are not
constant-expressions */
#ifdef SHORT_STRINGS
case 0100074:
#else /* !SHORT_STRINGS */
case 0274:
#endif
#else /* !COHERENT */
case '<'|QUOTE:
#endif
if (bitset)
stderror(ERR_NOTALLOWED, "$?<");
if (dimen)
stderror(ERR_NOTALLOWED, "$#<");
if (length)
stderror(ERR_NOTALLOWED, "$%<");
{
#ifdef BSDSIGS
sigmask_t omask = sigsetmask(sigblock(0) & ~sigmask(SIGINT));
#else /* !BSDSIGS */
(void) sigrelse(SIGINT);
#endif /* BSDSIGS */
for (np = wbuf; force_read(OLDSTD, &tnp, 1) == 1; np++) {
*np = (unsigned char) tnp;
if (np >= &wbuf[BUFSIZE - 1])
stderror(ERR_LTOOLONG);
if (tnp == '\n')
break;
}
*np = 0;
#ifdef BSDSIGS
(void) sigsetmask(omask);
#else /* !BSDSIGS */
(void) sighold(SIGINT);
#endif /* BSDSIGS */
}
#ifdef COMPAT
/*
* KLUDGE: dolmod is set here because it will cause setDolp to call
* domod and thus to copy wbuf. Otherwise setDolp would use it
* directly. If we saved it ourselves, no one would know when to free
* it. The actual function of the 'q' causes filename expansion not to
* be done on the interpolated value.
*/
/*
* If we do that, then other modifiers don't work.
* in addition, let the user specify :q if wanted
* [christos]
*/
/*old*/ dolmod = 'q';
/*new*/ dolmod[dolnmod++] = 'q';
dolmcnt = 10000;
#endif /* COMPAT */
fixDolMod();
setDolp(wbuf);
goto eatbrac;
case '*':
(void) Strcpy(name, STRargv);
vp = adrof(STRargv);
subscr = -1; /* Prevent eating [...] */
break;
case DEOF:
case '\n':
np = dimen ? STRargv : (bitset ? STRstatus : NULL);
if (np) {
bitset = 0;
(void) Strcpy(name, np);
vp = adrof(np);
subscr = -1; /* Prevent eating [...] */
unDredc(c);
break;
}
else
stderror(ERR_SYNTAX);
/*NOTREACHED*/
default:
np = name;
if (Isdigit(c)) {
if (dimen)
stderror(ERR_NOTALLOWED, "$#<num>");
subscr = 0;
do {
subscr = subscr * 10 + c - '0';
c = DgetC(0);
} while (Isdigit(c));
unDredc(c);
if (subscr < 0) {
( run in 0.844 second using v1.01-cache-2.11-cpan-364913b4093 )