Exemplo n.º 1
0
void settime(u8 a, u8 b, u8 c, u8 d, u8 e, u8 f) {
    sc = a;
    mn = b;
    hr = c;
    dy = d;
    mo = e;
    yr = 2000 + f;
    fixtime();
}
Exemplo n.º 2
0
/*
 * Do read, restart on interrupt unless SH_SIGSET or SH_SIGTRAP is set
 * Use sfpkrd() to poll() or select() to wait for input if possible
 * Unfortunately, systems that get interrupted from slow reads update
 * this access time for for the terminal (in violation of POSIX).
 * The fixtime() macro, resets the time to the time at entry in
 * this case.  This is not necessary for systems that can handle
 * sfpkrd() correctly (i,e., those that support poll() or select()
 */
int ed_read(void *context, int fd, char *buff, int size, int reedit)
{
	register Edit_t *ep = (Edit_t*)context;
	register int rv= -1;
	register int delim = ((ep->e_raw&RAWMODE)?nttyparm.c_cc[VEOL]:'\n');
	Shell_t *shp = ep->sh;
	int mode = -1;
	int (*waitevent)(int,long,int) = shp->gd->waitevent;
	if(ep->e_raw==ALTMODE)
		mode = 1;
	if(size < 0)
	{
		mode = 1;
		size = -size;
	}
	sh_onstate(SH_TTYWAIT);
	errno = EINTR;
	shp->gd->waitevent = 0;
	while(rv<0 && errno==EINTR)
	{
		if(shp->trapnote&(SH_SIGSET|SH_SIGTRAP))
			goto done;
		if(ep->sh->winch && sh_isstate(SH_INTERACTIVE) && (sh_isoption(SH_VI) || sh_isoption(SH_EMACS)))
		{
			Edpos_t	lastpos;
			int	n, rows, newsize;
			/* move cursor to start of first line */
			ed_putchar(ep,'\r');
			ed_flush(ep);
			astwinsize(2,&rows,&newsize);
			n = (ep->e_plen+ep->e_cur)/++ep->e_winsz;
			while(n--)
				ed_putstring(ep,CURSOR_UP);
			if(ep->e_multiline && newsize>ep->e_winsz && (lastpos.line=(ep->e_plen+ep->e_peol)/ep->e_winsz))
			{
				/* clear the current command line */
				n = lastpos.line;
				while(lastpos.line--)
				{
					ed_nputchar(ep,ep->e_winsz,' ');
					ed_putchar(ep,'\n');
				}
				ed_nputchar(ep,ep->e_winsz,' ');
				while(n--)
					ed_putstring(ep,CURSOR_UP);
			}
	                ep->sh->winch = 0;
			ed_flush(ep);
			sh_delay(.05);
			astwinsize(2,&rows,&newsize);
			ep->e_winsz = newsize-1;
			if(ep->e_winsz < MINWINDOW)
				ep->e_winsz = MINWINDOW;
			if(!ep->e_multiline && ep->e_wsize < MAXLINE)
				ep->e_wsize = ep->e_winsz-2;
			ep->e_nocrnl=1;
			if(*ep->e_vi_insert)
			{
				buff[0] = ESC;
				buff[1] = cntl('L');
				buff[2] = 'a';
				return(3);
			}
			if(sh_isoption(SH_EMACS) || sh_isoption(SH_VI))
				buff[0] = cntl('L');
			return(1);
		}
		else
			ep->sh->winch = 0;
		/* an interrupt that should be ignored */
		errno = 0;
		if(!waitevent || (rv=(*waitevent)(fd,-1L,0))>=0)
			rv = sfpkrd(fd,buff,size,delim,-1L,mode);
	}
	if(rv < 0)
	{
#ifdef _hdr_utime
#		define fixtime()	if(isdevtty)utime(ep->e_tty,&utimes)
		int	isdevtty=0;
		struct stat statb;
		struct utimbuf utimes;
	 	if(errno==0 && !ep->e_tty)
		{
			if((ep->e_tty=ttyname(fd)) && stat(ep->e_tty,&statb)>=0)
			{
				ep->e_tty_ino = statb.st_ino;
				ep->e_tty_dev = statb.st_dev;
			}
		}
		if(ep->e_tty_ino && fstat(fd,&statb)>=0 && statb.st_ino==ep->e_tty_ino && statb.st_dev==ep->e_tty_dev)
		{
			utimes.actime = statb.st_atime;
			utimes.modtime = statb.st_mtime;
			isdevtty=1;
		}
#else
#		define fixtime()
#endif /* _hdr_utime */
		while(1)
		{
			rv = read(fd,buff,size);
			if(rv>=0 || errno!=EINTR)
				break;
			if(shp->trapnote&(SH_SIGSET|SH_SIGTRAP))
				goto done;
			/* an interrupt that should be ignored */
			fixtime();
		}
	}
	else if(rv>=0 && mode>0)
		rv = read(fd,buff,rv>0?rv:1);
done:
	shp->gd->waitevent = waitevent;
	sh_offstate(SH_TTYWAIT);
	return(rv);
}