Ejemplo n.º 1
0
static int
preadfd(void)
{
	int nr;
	parsenextc = parsefile->buf;

#ifndef NO_HISTORY
	if (el != NULL && gotwinch) {
		gotwinch = 0;
		el_resize(el);
	}
#endif
retry:
#ifndef NO_HISTORY
	if (parsefile->fd == 0 && el) {
		static const char *rl_cp;
		static int el_len;

		if (rl_cp == NULL)
			rl_cp = el_gets(el, &el_len);
		if (rl_cp == NULL)
			nr = 0;
		else {
			nr = el_len;
			if (nr > BUFSIZ)
				nr = BUFSIZ;
			memcpy(parsenextc, rl_cp, nr);
			if (nr != el_len) {
				el_len -= nr;
				rl_cp += nr;
			} else
				rl_cp = NULL;
		}
	} else
#endif
		nr = read(parsefile->fd, parsenextc, BUFSIZ);

	if (nr <= 0) {
                if (nr < 0) {
                        if (errno == EINTR)
                                goto retry;
                        if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
                                int flags = fcntl(0, F_GETFL, 0);
                                if (flags >= 0 && flags & O_NONBLOCK) {
                                        flags &=~ O_NONBLOCK;
                                        if (fcntl(0, F_SETFL, flags) >= 0) {
						out2fmt_flush("sh: turning off NDELAY mode\n");
                                                goto retry;
                                        }
                                }
                        }
                }
                nr = -1;
	}
	return nr;
}
Ejemplo n.º 2
0
static int
preadfd(void)
{
	int nr;
	parsenextc = parsefile->buf;

#if !defined(NO_HISTORY)
	if (el != NULL && gotwinch) {
		gotwinch = 0;
		el_resize(el);
	}
#endif
retry:
#ifndef NO_HISTORY
	if (parsefile->fd == 0 && el) {
		const char *rl_cp;

		rl_cp = el_gets(el, &nr);
		if (rl_cp == NULL)
			nr = 0;
		else {
			/* XXX - BUFSIZE should redesign so not necessary */
			(void) strcpy(parsenextc, rl_cp);
		}
	} else
#endif
		nr = read(parsefile->fd, parsenextc, BUFSIZ - 1);

	if (nr <= 0) {
                if (nr < 0) {
                        if (errno == EINTR)
                                goto retry;
#ifdef EWOULDBLOCK
                        if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
                                int flags = fcntl(0, F_GETFL, 0);
                                if (flags >= 0 && flags & O_NONBLOCK) {
                                        flags &=~ O_NONBLOCK;
                                        if (fcntl(0, F_SETFL, flags) >= 0) {
						out2str("sh: turning off NDELAY mode\n");
                                                goto retry;
                                        }
                                }
                        }
#endif /* EWOULDBLOCK */
                }
                nr = -1;
	}
	return nr;
}
Ejemplo n.º 3
0
/* sig_handler():
 *	This is the handler called for all signals
 *	XXX: we cannot pass any data so we just store the old editline
 *	state in a private variable
 */
static void
sig_handler(int signo)
{
	int i, save_errno;
	sigset_t nset, oset;

	save_errno = errno;
	(void) sigemptyset(&nset);
	(void) sigaddset(&nset, signo);
	(void) sigprocmask(SIG_BLOCK, &nset, &oset);

	sel->el_signal->sig_no = signo;

	switch (signo) {
	case SIGCONT:
		tty_rawmode(sel);
		if (ed_redisplay(sel, 0) == CC_REFRESH)
			re_refresh(sel);
		terminal__flush(sel);
		break;

	case SIGWINCH:
		el_resize(sel);
		break;

	default:
		tty_cookedmode(sel);
		break;
	}

	for (i = 0; sighdl[i] != -1; i++)
		if (signo == sighdl[i])
			break;

	(void) sigaction(signo, &sel->el_signal->sig_action[i], NULL);
	sel->el_signal->sig_action[i].sa_handler = SIG_ERR;
	sel->el_signal->sig_action[i].sa_flags = 0;
	sigemptyset(&sel->el_signal->sig_action[i].sa_mask);
	(void) sigprocmask(SIG_SETMASK, &oset, NULL);
	(void) kill(0, signo);
	errno = save_errno;
}
Ejemplo n.º 4
0
libedit_private void
read_prepare(EditLine *el)
{
	if (el->el_flags & HANDLE_SIGNALS)
		sig_set(el);
	if (el->el_flags & NO_TTY)
		return;
	if ((el->el_flags & (UNBUFFERED|EDIT_DISABLED)) == UNBUFFERED)
		tty_rawmode(el);

	/* This is relatively cheap, and things go terribly wrong if
	   we have the wrong size. */
	el_resize(el);
	re_clear_display(el);	/* reset the display stuff */
	ch_reset(el);
	re_refresh(el);		/* print the prompt */

	if (el->el_flags & UNBUFFERED)
		terminal__flush(el);
}
Ejemplo n.º 5
0
static void
signalHandler(int signum)
{
   ElTclSignalContext *ctx;

#ifdef SIGWINCH
   for(ctx = sigWinchContext; ctx != NULL; ctx=ctx->next) {
      el_resize(ctx->iinfo->el);
      elTclGetWindowSize(1, NULL, &ctx->iinfo->windowSize);
   }
#endif

   for(ctx = signalContext[signum]; ctx != NULL; ctx=ctx->next)
      if (ctx->script != ELTCL_SIGDFL && ctx->script != ELTCL_SIGIGN)
	 Tcl_AsyncMark(ctx->asyncH);

#ifdef __svr4__ /* solaris 2 */
   signal(signum, signalHandler);
#endif
}
Ejemplo n.º 6
0
static int
preadfd(void)
{
	int nr;
	parsenextc = parsefile->buf;

#if !defined(NO_HISTORY) && !defined(EDITLINE)
	if (el != NULL && gotwinch) {
		gotwinch = 0;
		el_resize(el);
	}
#endif
retry:
#ifndef NO_HISTORY
#ifdef EDITLINE
	if (parsefile->fd == 0 && editable) {
		static const char *rl_cp= NULL;
		static size_t rl_off= 0;

		if (!rl_cp)
		{
			rl_cp = readline(getprompt(NULL));
			if (rl_cp == NULL)
				nr = 0;
		}
		if (rl_cp)
		{
			nr= strlen(rl_cp+rl_off);
			if (nr >= BUFSIZ-1)
			{
				nr= BUFSIZ-1;
				(void) memcpy(parsenextc, rl_cp+rl_off, nr);
				rl_off += nr;
			}
			else
			{
				(void) memcpy(parsenextc, rl_cp+rl_off, nr);
				parsenextc[nr++]= '\n';
				free(rl_cp);
				rl_cp= NULL;
				rl_off= 0;
			}
		}
	} else
#else /* !EDITLINE */
	if (parsefile->fd == 0 && el) {
		const char *rl_cp;

		rl_cp = el_gets(el, &nr);
		if (rl_cp == NULL)
			nr = 0;
		else {
			/* XXX - BUFSIZE should redesign so not necessary */
			(void) strcpy(parsenextc, rl_cp);
		}
	} else
#endif /* !EDITLINE */
#endif
		nr = read(parsefile->fd, parsenextc, BUFSIZ - 1);

	if (nr <= 0) {
                if (nr < 0) {
                        if (errno == EINTR)
                                goto retry;
#ifdef EWOULDBLOCK
                        if (parsefile->fd == 0 && errno == EWOULDBLOCK) {
                                int flags = fcntl(0, F_GETFL, 0);
                                if (flags >= 0 && flags & O_NONBLOCK) {
                                        flags &=~ O_NONBLOCK;
                                        if (fcntl(0, F_SETFL, flags) >= 0) {
						out2str("sh: turning off NDELAY mode\n");
                                                goto retry;
                                        }
                                }
                        }
#endif /* EWOULDBLOCK */
                }
                nr = -1;
	}
	return nr;
}