示例#1
0
文件: exec.c 项目: kisom/site-tools
void
Xwrite(void)
{
	char *file;
	int f;
	switch(count(runq->argv->words)){
	default:
		Xerror1("> requires singleton\n");
		return;
	case 0:
		Xerror1("> requires file\n");
		return;
	case 1:
		break;
	}
	file = runq->argv->words->word;
	if((f = Creat(file))<0){
		pfmt(err, "%s: ", file);
		Xerror("can't open");
		return;
	}
	pushredir(ROPEN, f, runq->code[runq->pc].i);
	runq->pc++;
	poplist();
}
示例#2
0
文件: exec.c 项目: kisom/site-tools
void
Xdup(void)
{
	pushredir(RDUP, runq->code[runq->pc].i, runq->code[runq->pc+1].i);
	runq->pc+=2;
}
示例#3
0
文件: simple.c 项目: chrislusf/push
void
execdot(void)
{
	int iflag = 0;
	int fd;
	list *av;
	thread *p = runq;
	char *zero;
	static int first = 1;
	char file[512];
	word *path;
	if(first){
		dotcmds[0].i = 1;
		dotcmds[1].f = Xmark;
		dotcmds[2].f = Xword;
		dotcmds[3].s="0";
		dotcmds[4].f = Xlocal;
		dotcmds[5].f = Xmark;
		dotcmds[6].f = Xword;
		dotcmds[7].s="*";
		dotcmds[8].f = Xlocal;
		dotcmds[9].f = Xrdcmds;
		dotcmds[10].f = Xunlocal;
		dotcmds[11].f = Xunlocal;
		dotcmds[12].f = Xreturn;
		first = 0;
	}
	else
		eflagok = 1;
	popword();
	if(p->argv->words && strcmp(p->argv->words->word, "-i")==0){
		iflag = 1;
		popword();
	}
	/* get input file */
	if(p->argv->words==0){
		Xerror1("Usage: . [-i] file [arg ...]");
		return;
	}
	zero = strdup(p->argv->words->word);
	popword();
	fd=-1;
	for(path = searchpath(zero);path;path = path->next){
		strcpy(file, path->word);
		if(file[0])
			strcat(file, "/");
		strcat(file, zero);
		if((fd = open(file, 0))>=0) break;
		if(strcmp(file, "/dev/stdin")==0){	/* for sun & ucb */
			fd = Dup1(0);
			if(fd>=0)
				break;
		}
	}
	if(fd<0){
		pfmt(err, "%s: ", zero);
		setstatus("can't open");
		Xerror(".: can't open");
		return;
	}
	/* set up for a new command loop */
	start(dotcmds, 1, (struct var *)0);
	pushredir(RCLOSE, fd, 0);
	runq->cmdfile = zero;
	runq->cmdfd = openfd(fd);
	runq->iflag = iflag;
	runq->iflast = 0;
	/* push $* value */
	pushlist();
	runq->argv->words = p->argv->words;
	/* free caller's copy of $* */
	av = p->argv;
	p->argv = av->next;
	efree((char *)av);
	/* push $0 value */
	pushlist();
	pushword(zero);
	ndot++;
}
示例#4
0
文件: exec.c 项目: kisom/site-tools
void
Xclose(void)
{
	pushredir(RCLOSE, runq->code[runq->pc].i, 0);
	runq->pc++;
}
示例#5
0
文件: eval.c 项目: pexip/os-dash
void
evaltree(union node *n, int flags)
{
	int checkexit = 0;
	void (*evalfn)(union node *, int);
	unsigned isor;
	int status;
	if (n == NULL) {
		TRACE(("evaltree(NULL) called\n"));
		goto out;
	}
#ifndef SMALL
	displayhist = 1;	/* show history substitutions done with fc */
#endif
	TRACE(("pid %d, evaltree(%p: %d, %d) called\n",
	    getpid(), n, n->type, flags));
	switch (n->type) {
	default:
#ifdef DEBUG
		out1fmt("Node type = %d\n", n->type);
#ifndef USE_GLIBC_STDIO
		flushout(out1);
#endif
		break;
#endif
	case NNOT:
		evaltree(n->nnot.com, EV_TESTED);
		status = !exitstatus;
		goto setstatus;
	case NREDIR:
		errlinno = lineno = n->nredir.linno;
		if (funcline)
			lineno -= funcline - 1;
		expredir(n->nredir.redirect);
		pushredir(n->nredir.redirect);
		status = redirectsafe(n->nredir.redirect, REDIR_PUSH);
		if (!status) {
			evaltree(n->nredir.n, flags & EV_TESTED);
			status = exitstatus;
		}
		if (n->nredir.redirect)
			popredir(0);
		goto setstatus;
	case NCMD:
#ifdef notyet
		if (eflag && !(flags & EV_TESTED))
			checkexit = ~0;
		evalcommand(n, flags, (struct backcmd *)NULL);
		break;
#else
		evalfn = evalcommand;
checkexit:
		if (eflag && !(flags & EV_TESTED))
			checkexit = ~0;
		goto calleval;
#endif
	case NFOR:
		evalfn = evalfor;
		goto calleval;
	case NWHILE:
	case NUNTIL:
		evalfn = evalloop;
		goto calleval;
	case NSUBSHELL:
	case NBACKGND:
		evalfn = evalsubshell;
		goto checkexit;
	case NPIPE:
		evalfn = evalpipe;
		goto checkexit;
	case NCASE:
		evalfn = evalcase;
		goto calleval;
	case NAND:
	case NOR:
	case NSEMI:
#if NAND + 1 != NOR
#error NAND + 1 != NOR
#endif
#if NOR + 1 != NSEMI
#error NOR + 1 != NSEMI
#endif
		isor = n->type - NAND;
		evaltree(
			n->nbinary.ch1,
			(flags | ((isor >> 1) - 1)) & EV_TESTED
		);
		if (!exitstatus == isor)
			break;
		if (!evalskip) {
			n = n->nbinary.ch2;
evaln:
			evalfn = evaltree;
calleval:
			evalfn(n, flags);
			break;
		}
		break;
	case NIF:
		evaltree(n->nif.test, EV_TESTED);
		if (evalskip)
			break;
		if (exitstatus == 0) {
			n = n->nif.ifpart;
			goto evaln;
		} else if (n->nif.elsepart) {
			n = n->nif.elsepart;
			goto evaln;
		}
		goto success;
	case NDEFUN:
		defun(n);
success:
		status = 0;
setstatus:
		exitstatus = status;
		break;
	}
out:
	if (checkexit & exitstatus)
		goto exexit;

	if (pendingsigs)
		dotrap();

	if (flags & EV_EXIT) {
exexit:
		exraise(EXEXIT);
	}
}