Quizzer

 view release on metacpan or  search on metacpan

exercises/compile-tcsh/tcsh-6.10.00/sh.func.c  view on Meta::CPAN

     */
    zlast = TC_FOREACH;
    if (intty)
	preread();
    doagain();
}

/*ARGSUSED*/
void
dowhile(v, c)
    Char  **v;
    struct command *c;
{
    register int status;
    register bool again = whyles != 0 && 
			  SEEKEQ(&whyles->w_start, &lineloc) &&
			  whyles->w_fename == 0;

    USE(c);
    v++;
    /*
     * Implement prereading here also, taking care not to evaluate the
     * expression before the loop has been read up from a terminal.
     */
    if (intty && !again)
	status = !exp0(&v, 1);
    else
	status = !expr(&v);
    if (*v)
	stderror(ERR_NAME | ERR_EXPRESSION);
    if (!again) {
	register struct whyle *nwp =
	(struct whyle *) xcalloc(1, sizeof(*nwp));

	nwp->w_start = lineloc;
	nwp->w_end.type = TCSH_F_SEEK;
	nwp->w_end.f_seek = 0;
	nwp->w_next = whyles;
	whyles = nwp;
	zlast = TC_WHILE;
	if (intty) {
	    /*
	     * The tty preread
	     */
	    preread();
	    doagain();
	    return;
	}
    }
    if (status)
	/* We ain't gonna loop no more, no more! */
	toend();
}

static void
preread()
{
    whyles->w_end.type = TCSH_I_SEEK;
    if (setintr)
#ifdef BSDSIGS
	(void) sigsetmask(sigblock((sigmask_t) 0) & ~sigmask(SIGINT));
#else /* !BSDSIGS */
	(void) sigrelse (SIGINT);
#endif /* BSDSIGS */
    search(TC_BREAK, 0, NULL);		/* read the expression in */
    if (setintr)
#ifdef BSDSIGS
	(void) sigblock(sigmask(SIGINT));
#else /* !BSDSIGS */
	(void) sighold(SIGINT);
#endif /* BSDSIGS */
    btell(&whyles->w_end);
}

/*ARGSUSED*/
void
doend(v, c)
    Char **v;
    struct command *c;
{
    USE(v);
    USE(c);
    if (!whyles)
	stderror(ERR_NAME | ERR_NOTWHILE);
    btell(&whyles->w_end);
    doagain();
}

/*ARGSUSED*/
void
docontin(v, c)
    Char **v;
    struct command *c;
{
    USE(v);
    USE(c);
    if (!whyles)
	stderror(ERR_NAME | ERR_NOTWHILE);
    doagain();
}

static void
doagain()
{
    /* Repeating a while is simple */
    if (whyles->w_fename == 0) {
	bseek(&whyles->w_start);
	return;
    }
    /*
     * The foreach variable list actually has a spurious word ")" at the end of
     * the w_fe list.  Thus we are at the of the list if one word beyond this
     * is 0.
     */
    if (!whyles->w_fe[1]) {
	dobreak(NULL, NULL);
	return;
    }
    set(whyles->w_fename, quote(Strsave(*whyles->w_fe++)), VAR_READWRITE);
    bseek(&whyles->w_start);
}

void
dorepeat(v, kp)
    Char  **v;
    struct command *kp;
{
    register int i;

#ifdef BSDSIGS
    register sigmask_t omask = 0;

#endif /* BSDSIGS */

    i = getn(v[1]);
    if (setintr)
#ifdef BSDSIGS
	omask = sigblock(sigmask(SIGINT)) & ~sigmask(SIGINT);
#else /* !BSDSIGS */
	(void) sighold(SIGINT);
#endif /* BSDSIGS */
    lshift(v, 2);
    while (i > 0) {
	if (setintr)
#ifdef BSDSIGS
	    (void) sigsetmask(omask);
#else /* !BSDSIGS */
	    (void) sigrelse (SIGINT);
#endif /* BSDSIGS */
	reexecute(kp);
	--i;
    }
    donefds();
    if (setintr)
#ifdef BSDSIGS
	(void) sigsetmask(omask);
#else /* !BSDSIGS */
	(void) sigrelse (SIGINT);
#endif /* BSDSIGS */
}

/*ARGSUSED*/
void
doswbrk(v, c)
    Char **v;
    struct command *c;
{
    USE(v);
    USE(c);
    search(TC_BRKSW, 0, NULL);
}

int
srchx(cp)
    Char *cp;
{
    struct srch *sp, *sp1, *sp2;
    int i;

    /*
     * Ignore keywords inside heredocs
     */
    if (inheredoc)
	return -1;

    /*
     * Binary search Sp1 is the beginning of the current search range. Sp2 is
     * one past the end.
     */
    for (sp1 = srchn, sp2 = srchn + nsrchn; sp1 < sp2;) {
	sp = sp1 + ((sp2 - sp1) >> 1);
	if ((i = *cp - *sp->s_name) == 0 &&
	    (i = Strcmp(cp, str2short(sp->s_name))) == 0)
	    return sp->s_value;
	if (i < 0)
	    sp2 = sp;
	else
	    sp1 = sp + 1;
    }
    return (-1);
}

static char *
isrchx(n)
    register int n;
{
    register struct srch *sp, *sp2;

    for (sp = srchn, sp2 = srchn + nsrchn; sp < sp2; sp++)
	if (sp->s_value == n)
	    return (sp->s_name);
    return ("");
}


static Char Stype;

exercises/compile-tcsh/tcsh-6.10.00/sh.func.c  view on Meta::CPAN

	    blkfree(wp->w_fe0);
	if (wp->w_fename)
	    xfree((ptr_t) wp->w_fename);
	xfree((ptr_t) wp);
    }
}

/*ARGSUSED*/
void
doecho(v, c)
    Char  **v;
    struct command *c;
{
    USE(c);
    xecho(' ', v);
}

/*ARGSUSED*/
void
doglob(v, c)
    Char  **v;
    struct command *c;
{
    USE(c);
    xecho(0, v);
    flush();
}

static void
xecho(sep, v)
    int    sep;
    register Char **v;
{
    register Char *cp;
    int     nonl = 0;
#ifdef ECHO_STYLE
    int	    echo_style = ECHO_STYLE;
#else /* !ECHO_STYLE */
# if SYSVREL > 0
    int	    echo_style = SYSV_ECHO;
# else /* SYSVREL == 0 */
    int	    echo_style = BSD_ECHO;
# endif /* SYSVREL */
#endif /* ECHO_STYLE */
    struct varent *vp;

    if ((vp = adrof(STRecho_style)) != NULL && vp->vec != NULL &&
	vp->vec[0] != NULL) {
	if (Strcmp(vp->vec[0], STRbsd) == 0)
	    echo_style = BSD_ECHO;
	else if (Strcmp(vp->vec[0], STRsysv) == 0)
	    echo_style = SYSV_ECHO;
	else if (Strcmp(vp->vec[0], STRboth) == 0)
	    echo_style = BOTH_ECHO;
	else if (Strcmp(vp->vec[0], STRnone) == 0)
	    echo_style = NONE_ECHO;
    }

    if (setintr)
#ifdef BSDSIGS
	(void) sigsetmask(sigblock((sigmask_t) 0) & ~sigmask(SIGINT));
#else /* !BSDSIGS */
	(void) sigrelse (SIGINT);
#endif /* BSDSIGS */
    v++;
    if (*v == 0)
	return;
    gflag = 0, tglob(v);
    if (gflag) {
	v = globall(v);
	if (v == 0)
	    stderror(ERR_NAME | ERR_NOMATCH);
    }
    else {
	v = gargv = saveblk(v);
	trim(v);
    }

    if ((echo_style & BSD_ECHO) != 0 && sep == ' ' && *v && eq(*v, STRmn))
	nonl++, v++;

    while ((cp = *v++) != 0) {
	register int c;

	while ((c = *cp++) != 0) {
	    if ((echo_style & SYSV_ECHO) != 0 && c == '\\') {
		switch (c = *cp++) {
		case 'a':
		    c = '\a';
		    break;
		case 'b':
		    c = '\b';
		    break;
		case 'c':
		    nonl = 1;
		    goto done;
		case 'e':
#if 0			/* Windows does not understand \e */
		    c = '\e';
#else
		    c = '\033';
#endif
		    break;
		case 'f':
		    c = '\f';
		    break;
		case 'n':
		    c = '\n';
		    break;
		case 'r':
		    c = '\r';
		    break;
		case 't':
		    c = '\t';
		    break;
		case 'v':
		    c = '\v';
		    break;
		case '\\':
		    c = '\\';
		    break;

exercises/compile-tcsh/tcsh-6.10.00/sh.func.c  view on Meta::CPAN

		case '\0':
		    c = '\\';
		    cp--;
		    break;
		default:
		    xputchar('\\' | QUOTE);
		    break;
		}
	    }
	    xputchar(c | QUOTE);

	}
	if (*v)
	    xputchar(sep | QUOTE);
    }
done:
    if (sep && nonl == 0)
	xputchar('\n');
    else
	flush();
    if (setintr)
#ifdef BSDSIGS
	(void) sigblock(sigmask(SIGINT));
#else /* !BSDSIGS */
	(void) sighold(SIGINT);
#endif /* BSDSIGS */
    if (gargv)
	blkfree(gargv), gargv = 0;
}

/* 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 */



( run in 2.731 seconds using v1.01-cache-2.11-cpan-aadc1410aed )