⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 overview.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 2 页
字号:
		 *		 * kbd equivalent of mouse:		 * win_setkbd(winfd, &s);		 */	} else		/* Grab io because about to release it */		(void)win_grabio(winfd);	/* Release io has hidden semantic of reloading colormap */	(void)win_releaseio(winfd);	/* Go iconic */	(void)window_set(frame, FRAME_CLOSED, TRUE, 0);#ifdef	get_cursor	/* Give frame old cursor back */	(void)window_set(frame, WIN_CURSOR, oldcurs_ptr, 0);#else	{	extern struct  cursor tool_cursor;	/* Give frame a std cursor */	(void)win_setcursor(winfd, (Cursor)(LINT_CAST(&tool_cursor)));	}#endif	taken_over_screen = 0;}/* ARGSUSED */static int overview_handle_output(ptytty, addr, len)	Ptytty	*ptytty;	register char *addr;	register int len;{	register i;	for (i = 0; i <= len; i++)		putc(*(addr+i), stdout);	return (len);}static	Notify_value	ptytty_pty_input_pending();static	Notify_value	ptytty_pty_output_pending();static	Notify_value	ptytty_prioritizer();#define	iwbp	ptytty->inbuf.cb_wbp#define	irbp	ptytty->inbuf.cb_rbp#define	iebp	ptytty->inbuf.cb_ebp#define	ibuf	ptytty->inbuf.cb_buf#define	owbp	ptytty->outbuf.cb_wbp#define	orbp	ptytty->outbuf.cb_rbp#define	oebp	ptytty->outbuf.cb_ebp#define	obuf	ptytty->outbuf.cb_bufstaticPtytty *ptytty_create(output)    int    (*output) ();{    Ptytty *ptytty = (Ptytty *) (LINT_CAST(calloc(1, sizeof(Ptytty))));    if (ptytty_init(ptytty) < 0)	exit(1);    ptytty->inbuf.cb_rbp = ptytty->inbuf.cb_buf;    ptytty->inbuf.cb_wbp = ptytty->inbuf.cb_buf;    ptytty->inbuf.cb_ebp = &ptytty->inbuf.cb_buf[sizeof (ptytty->inbuf.cb_buf)];    ptytty->outbuf.cb_rbp = ptytty->outbuf.cb_buf;    ptytty->outbuf.cb_wbp = ptytty->outbuf.cb_buf;    ptytty->outbuf.cb_ebp =	&ptytty->outbuf.cb_buf[sizeof (ptytty->outbuf.cb_buf)];    (void) notify_set_input_func((Notify_client)(LINT_CAST(ptytty)),     	ptytty_pty_input_pending, ptytty->pty);    ptytty->waiting_for_pty_input = 1;    ptytty->cached_pri = notify_set_prioritizer_func(    	(Notify_client)(LINT_CAST(ptytty)),ptytty_prioritizer);    ptytty->output = output;    return (ptytty);}/* ARGSUSED */staticintptytty_fork(ptytty, prog, argv)    Ptytty               *ptytty;    char                 *prog;    char                **argv;{    int                   pidchild;    struct sigvec vec, ovec;        (void)unsetenv("TERMCAP");    pidchild = fork();    if (pidchild < 0)	return (-1);    if (pidchild) {	int                   on = 1;	int                   fdflags;	if ((fdflags = fcntl(ptytty->pty, F_GETFL, 0)) == -1) {		perror("fcntl");		return (-1);	}	fdflags |= FNDELAY;	if (fcntl(ptytty->pty, F_SETFL, fdflags) == -1) {		perror("fcntl");		return (-1);	}	(void)ioctl(ptytty->pty, TIOCPKT, &on);	/* (void)signal(SIGTSTP, SIG_IGN); */	vec.sv_handler = SIG_IGN;	vec.sv_mask = vec.sv_onstack = 0;	sigvec(SIGTSTP, &vec, 0);	return (pidchild);    }    /* (void)signal(SIGWINCH, SIG_DFL); /* we don't care about SIGWINCH's */    vec.sv_handler = SIG_DFL;    vec.sv_mask = vec.sv_onstack = 0;    sigvec(SIGWINCH, &vec, 0);    /*     * Change process group of child process (me at this point in code) so its     * signal stuff doesn't affect the terminal emulator.      */    pidchild = getpid();    vec.sv_handler = SIG_IGN;    sigvec(SIGTTOU, &vec, &ovec);    {	/* int (*presigval) () = signal(SIGTTOU, SIG_IGN); */	if ((ioctl(ptytty->tty, TIOCSPGRP, &pidchild)) == -1) {	    perror("TIOCSPGRP");	}	(void)setpgrp(pidchild, pidchild);	/* (void)signal(SIGTTOU, presigval); */	sigvec(SIGTTOU, &ovec, 0);    }    /*     * Set up file descriptors      */    (void)close(ptytty->pty);    (void)dup2(ptytty->tty, 0);    (void)dup2(ptytty->tty, 1);    (void)dup2(ptytty->tty, 2);    (void)close(ptytty->tty);    execvp(prog, argv);    perror(*argv);    exit(1);    /* NOTREACHED */}staticintptytty_init(ptytty)    Ptytty  *ptytty;{    int                   tt, tmpfd, ptynum = 0;    int                   pty = 0, tty = 0;    char                  linebuf[20], *line = &linebuf[0];    char		  *ptyp = "pqrstuvwxyzPQRST";    struct stat           stb;    /*     * find unopened pty      */needpty:    while (*ptyp) {	(void)strcpy(line, "/dev/ptyXX");	line[strlen("/dev/pty")] = *ptyp;	line[strlen("/dev/ptyp")] = '0';	if (stat(line, &stb) < 0)	    break;	while (ptynum < 16) {	    line[strlen("/dev/ptyp")] = "0123456789abcdef"[ptynum];	    pty = open(line, 2);	    if (pty > 0)		goto gotpty;	    ptynum++;	}	ptyp++;    }    (void)fprintf(stderr, "All pty's in use\n");    return (-1);    /* NOTREACHED */gotpty:    line[strlen("/dev/")] = 't';    tt = open("/dev/tty", 2);    if (tt > 0) {	(void)ioctl(tt, TIOCNOTTY, 0);	(void)close(tt);    }    tty = open(line, 2);    if (tty < 0) {	ptynum++;	(void)close(pty);	goto needpty;    }    (void)ttysw_restoreparms(tty); /* Not ttysw specific */    /*     * Copy stdin.  Set stdin to tty so ttyslot in updateutmp will think this     * is the control terminal.  Restore state. Note: ttyslot should have     * companion ttyslotf(fd).      */    tmpfd = dup(0);    (void)close(0);    (void)dup(tty);    ptytty->ttyslot = updateutmp((char *)0, 0, tty);    (void)close(0);    (void)dup(tmpfd);    (void)close(tmpfd);    if (ptytty->ttyslot == 0) {	(void)close(tty);	(void)close(pty);	return (-1);    }    ptytty->tty = tty;    ptytty->pty = pty;    return (0);}/* Write user input to pty */static Notify_valueptytty_pty_output_pending(ptytty, pty)    Ptytty               *ptytty;    int                   pty;{    register int        cc;    if (iwbp > irbp) {	cc = write(pty, irbp, iwbp - irbp);	if (cc > 0) {	    irbp += cc;	    if (irbp == iwbp)		irbp = iwbp = ibuf;	} else if (cc < 0) {	    perror("pty write failure");	}    }    return (NOTIFY_DONE);}/* Read pty's input (which is output from program) */static Notify_valueptytty_pty_input_pending(ptytty, pty)    Ptytty               *ptytty;    int                   pty;{    register int        cc;    extern int errno;    /* use readv so can read packet header into separate char? */    cc = read(pty, owbp, oebp - owbp);    /* System V compatibility requires recognition of 4.2 and Sys5 returns:     * 4.2: cc == -1 and EWOULDBLOCK; Sys5: cc == 0 and EWOULDBLOCK     */    if (cc <= 0 && errno == EWOULDBLOCK)		cc = 0;    else if (cc <= 0)		cc = -1;    else if (*owbp == 0)		cc--;    else		cc = 0;    if (cc > 0) {		bcopy(owbp + 1, owbp, cc);		owbp += cc;    }    return (NOTIFY_DONE);}static Notify_valueptytty_prioritizer(ptytty, nfd, ibits_ptr, obits_ptr, ebits_ptr,		  nsig, sigbits_ptr, auto_sigbits_ptr, event_count_ptr, events)    register Ptytty      *ptytty;    fd_set                *ibits_ptr, *obits_ptr, *ebits_ptr;    int			  nsig, *sigbits_ptr, *event_count_ptr;    register int         *auto_sigbits_ptr, nfd;    Notify_event         *events;{    register int          bit;    register int          pty = ptytty->pty;    /* if (*obits_ptr & (bit = FD_BIT(pty))) { */    if (FD_SET(pty, obits_ptr)) {	(void) notify_output((Notify_client)(LINT_CAST(ptytty)), pty);	FD_CLR(pty, obits_ptr);    }    /* if (*ibits_ptr & (bit = FD_BIT(pty))) { */    if (FD_SET(pty, ibits_ptr)) {	(void) notify_input((Notify_client)(LINT_CAST(ptytty)), pty);	FD_CLR(pty, ibits_ptr);    }    (void) ptytty->cached_pri(ptytty, nfd, ibits_ptr, obits_ptr, ebits_ptr,		nsig, sigbits_ptr, auto_sigbits_ptr, event_count_ptr, events);    ptytty_reset_conditions(ptytty);    return (NOTIFY_DONE);}/* * Conditionally set conditions */staticptytty_reset_conditions(ptytty)    register Ptytty      *ptytty;{    register int          pty = ptytty->pty;    /* Send program output to terminal emulator */    ptytty_consume_output(ptytty);    /* Toggle between window input and pty output being done */    if (iwbp > irbp) {	if (!ptytty->waiting_for_pty_output) {	    /* Wait for output to complete on pty */	    (void) notify_set_output_func((Notify_client)(LINT_CAST(ptytty)),					  ptytty_pty_output_pending, pty);	    ptytty->waiting_for_pty_output = 1;	}    } else {	if (ptytty->waiting_for_pty_output) {	    /* Don't wait for output to complete on pty any more */	    (void) notify_set_output_func((Notify_client)(LINT_CAST(ptytty)), 	    	NOTIFY_FUNC_NULL, pty);	    ptytty->waiting_for_pty_output = 0;	}    }    /* Set pty input pending */    if (owbp == orbp) {	if (!ptytty->waiting_for_pty_input) {	    (void) notify_set_input_func((Notify_client)(LINT_CAST(ptytty)), 	    	ptytty_pty_input_pending, pty);	    ptytty->waiting_for_pty_input = 1;	}    } else {	if (ptytty->waiting_for_pty_input) {	    (void) notify_set_input_func((Notify_client)(LINT_CAST(ptytty)), NOTIFY_FUNC_NULL, pty);	    ptytty->waiting_for_pty_input = 0;	}    }}/* * Send program output. */staticptytty_consume_output(ptytty)    register Ptytty *ptytty;{    int                 cc;    if (owbp > orbp) {	cc = ptytty->output(ptytty, orbp, owbp - orbp);	orbp += cc;	if (orbp == owbp)	    orbp = owbp = obuf;    }}/* * Add the string to the input queue.  */ptytty_input(ptytty, addr, len)    Ptytty             *ptytty;    char               *addr;    int                 len;{    if (iwbp + len >= iebp)	    return (0);		   /* won't fit */    bcopy(addr, iwbp, len);    iwbp += len;    (void)ptytty_pty_output_pending(ptytty, ptytty->pty);    ptytty_reset_conditions(ptytty);    return (len);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -