Exemplo n.º 1
0
static void
run_in_child(void *data)
{
    int r;
    cut_fn *fns = data, bringup = fns[0], test = fns[1], takedown = fns[2];

    r = dup2(fileno(stdout), fileno(stderr));
    if (r < 0) die(3, "dup2");
    bringup();
    cur_takedown = takedown;
    test();
    takedown();
    fflush(stdout);
    fflush(stderr);
}
Exemplo n.º 2
0
void typeline(bc *bc, char *preload,int echocr)
{
int i=0,j;
int code;
int backcount=0;
char linesave[LINESIZE],ch;
int linesin;
char ref;
int xdelta;
char *p1,*p2;
char token[128];
char *fake;
int scrollback;
int startx, starty;
char spaces[256], *zerospaces;
char *tail;
int oldlen;

	memset(spaces, ' ', sizeof(spaces));
	zerospaces = spaces + sizeof(spaces)-1;
	*zerospaces = 0;
top:
	tail="";
	startx = bc->txpos;
	starty = bc->typos;
	xdelta=0;
	linesin=bc->hcount>HISTSIZE ? HISTSIZE : bc->hcount;
	strcpy(bc->debline, preload);
	i=strlen(bc->debline);
	tprintf(bc, preload);
	ref=0;
	fake=0;
	scrollback=0;
	while(!(bc->flags & (BF_CCHIT | BF_QUIT)))
	{
		if(!fake)
		{
			SDL_Delay(10);
			scaninput(bc);
			code=takedown(bc);
//if(code=='q' + MYALTED) exit(0); // alt-q
		} else
		{
			code=*fake++;
			if(!code) {fake=0;continue;}
		}
		if(code==-1) continue;
		if(code==MYPAGEUP || code==(MYPAGEUP|MYSHIFTED))
		{
			if(code==MYPAGEUP) ++scrollback;
			else scrollback+=bc->tysize;
			scrollback=showhistory(bc, scrollback);
			continue;
		} else if(code==MYPAGEDOWN || code==(MYPAGEDOWN|MYSHIFTED))
		{
			if(code==MYPAGEDOWN) --scrollback;
			else scrollback-=bc->tysize;
			if(scrollback<0) scrollback=0;
			scrollback=showhistory(bc, scrollback);
			if(scrollback)
				continue;
			else
				++ref;
		}
		if(code==9 || code==4)
		{
			j=0;
			while(i+xdelta-j>0)
			{
				ch=bc->debline[i+xdelta-j-1];
				if(!isalpha(ch) && !isdigit(ch) && ch!='_' && ch!='.') break;
				++j;
			}
			p1=token;
			while(j)
				*p1++=bc->debline[i+xdelta-j--];
			*p1=0;
			if(*token)
			{
				if(code==9)
					fake=complete(token);
				else
				{
					cr(bc);
					listall(token);
					ref=1;
				}
			}
		} else if(code==0x7f)
		{
			if(!xdelta) continue;
			p1=bc->debline+i+xdelta;
			p2=p1+1;
			while((*p1++=*p2++));
			--i;
			++xdelta;
			++ref;
		} else if(code==MYLEFT)
		{
			if(i+xdelta>0) {--xdelta;++ref;}
		} else if(code==MYRIGHT)
		{
			if(xdelta<0) {++xdelta;++ref;}
		} else if(code==MYUP)
		{
			if(backcount<linesin)
			{
				if(!backcount)
					memcpy(linesave,bc->debline,LINESIZE);
				++backcount;
				oldlen = strlen(bc->debline);
				memcpy(bc->debline,
					bc->debhist+LINESIZE*((bc->hcount-backcount) &
						(HISTSIZE-1)), LINESIZE);
				oldlen -= strlen(bc->debline);
				if(oldlen>0) tail=zerospaces-oldlen;
				xdelta=0;
			}
			++ref;
		} else if(code==MYDOWN)
		{
			if(backcount)
			{
				--backcount;
				oldlen = strlen(bc->debline);
				if(!backcount) memcpy(bc->debline,linesave,LINESIZE);
				else
					memcpy(bc->debline,bc->debhist+LINESIZE*((bc->hcount-backcount) & (HISTSIZE-1)),LINESIZE);
				oldlen -= strlen(bc->debline);
				if(oldlen>0) tail=zerospaces-oldlen;
				xdelta=0;
			}
			++ref;
		} else if(code>=0 && code<128)
		{
			if(code==8)
			{
				if(i+xdelta)
				{
					--i;
					p1=bc->debline+i+xdelta;
					p2=p1+1;
					while((*p1++=*p2++));
					++ref;
				} else continue;
			} else if(code==CR)
			{
				if(echocr) cr(bc);
				break;
			}
			else if(code>=0x20 && i<bc->txsize-1 && i<sizeof(bc->debline)-1)
			{
				p2=bc->debline+i;
				p1=p2+1;
				j=1-xdelta;
				while(j--) *p1--=*p2--;
				*p1=code;
				++ref;
			} else continue;
		}
		if(ref)
		{
			if(scrollback)
				scrollback=showhistory(bc, 0);
			i=strlen(bc->debline);
			tprintf(bc, "\033%dx\033%dy%s %s\033%dx\033%dy",
				startx, starty, bc->debline, tail, i+xdelta+startx, starty);
			tail="";
			ref=0;
		}

	}
	if(bc->flags & BF_CCHIT)
	{
		flushinput(bc);
		if(!(bc->flags & BF_RUNNING))
		{
			bc->flags &= ~BF_CCHIT;
			preload="";
			tprintf(bc, "\n");
			goto top;
		}
	}
	if(i)
	{
		memcpy(bc->debhist+LINESIZE*(bc->hcount & (HISTSIZE-1)),bc->debline,LINESIZE);
		++bc->hcount;
	}
}
Exemplo n.º 3
0
void flushinput(bc *bc)
{
	while(takedown(bc)>=0);
}