Annotation of 43BSD/ucb/window/wwiomux.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char sccsid[] = "@(#)wwiomux.c  3.15 9/19/85";
                      3: #endif
                      4: 
                      5: /*
                      6:  * Copyright (c) 1983 Regents of the University of California,
                      7:  * All rights reserved.  Redistribution permitted subject to
                      8:  * the terms of the Berkeley Software License Agreement.
                      9:  */
                     10: 
                     11: #include "ww.h"
                     12: #include <sys/time.h>
                     13: #include <sys/types.h>
                     14: 
                     15: /*
                     16:  * Multiple window output handler.
                     17:  * The idea is to copy window outputs to the terminal, via the
                     18:  * display package.  We try to give the top most window highest
                     19:  * priority.  The only return condition is when there is keyboard
                     20:  * input, which is serviced asynchronously by wwrint().
                     21:  * When there's nothing to do, we sleep in a select().
                     22:  * This can be done better with interrupt driven io.  But that's
                     23:  * not supported on ptys, yet.
                     24:  * The history of this routine is interesting.
                     25:  */
                     26: wwiomux()
                     27: {
                     28:        register struct ww *w;
                     29:        fd_set imask;
                     30:        register n;
                     31:        register char *p;
                     32:        char c;
                     33:        static struct timeval tv = { 0, 0 };
                     34:        char noblock;
                     35: 
                     36: loop:
                     37:        if (wwinterrupt())
                     38:                return;
                     39: 
                     40:        FD_ZERO(&imask);
                     41:        noblock = 0;
                     42:        for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
                     43:                if (w->ww_pty < 0)
                     44:                        continue;
                     45:                if (w->ww_obq < w->ww_obe)
                     46:                        FD_SET(w->ww_pty, &imask);
                     47:                if (w->ww_obq > w->ww_obp && !w->ww_stopped)
                     48:                        noblock = 1;
                     49:        }
                     50: 
                     51:        if (!noblock) {
                     52:                if (wwcurwin != 0)
                     53:                        wwcurtowin(wwcurwin);
                     54:                wwupdate();
                     55:                wwflush();
                     56:                if (setjmp(wwjmpbuf))
                     57:                        return;
                     58:                wwsetjmp = 1;
                     59:                if (wwinterrupt()) {
                     60:                        wwsetjmp = 0;
                     61:                        return;
                     62:                }
                     63:        }
                     64:        wwnselect++;
                     65:        n = select(wwdtablesize, &imask, (fd_set *)0, (fd_set *)0,
                     66:                noblock ? &tv : (struct timeval *)0);
                     67:        wwsetjmp = 0;
                     68: 
                     69:        if (n < 0)
                     70:                wwnselecte++;
                     71:        else if (n == 0)
                     72:                wwnselectz++;
                     73:        else
                     74:                for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
                     75:                        if (w->ww_pty < 0 || !FD_ISSET(w->ww_pty, &imask))
                     76:                                continue;
                     77:                        wwnwread++;
                     78:                        p = w->ww_obq;
                     79:                        if (w->ww_ispty) {
                     80:                                if (p == w->ww_ob) {
                     81:                                        w->ww_obp++;
                     82:                                        w->ww_obq++;
                     83:                                } else
                     84:                                        p--;
                     85:                                c = *p;
                     86:                        }
                     87:                        n = read(w->ww_pty, p, w->ww_obe - p);
                     88:                        if (n < 0) {
                     89:                                wwnwreade++;
                     90:                                (void) close(w->ww_pty);
                     91:                                w->ww_pty = -1;
                     92:                        } else if (n == 0) {
                     93:                                wwnwreadz++;
                     94:                                (void) close(w->ww_pty);
                     95:                                w->ww_pty = -1;
                     96:                        } else if (!w->ww_ispty) {
                     97:                                wwnwreadd++;
                     98:                                wwnwreadc += n;
                     99:                                w->ww_obq += n;
                    100:                        } else if (*p == TIOCPKT_DATA) {
                    101:                                n--;
                    102:                                wwnwreadd++;
                    103:                                wwnwreadc += n;
                    104:                                w->ww_obq += n;
                    105:                        } else {
                    106:                                wwnwreadp++;
                    107:                                if (*p & TIOCPKT_STOP)
                    108:                                        w->ww_stopped = 1;
                    109:                                if (*p & TIOCPKT_START)
                    110:                                        w->ww_stopped = 0;
                    111:                                if (*p & TIOCPKT_FLUSHWRITE) {
                    112:                                        w->ww_stopped = 0;
                    113:                                        w->ww_obq = w->ww_obp = w->ww_ob;
                    114:                                }
                    115:                        }
                    116:                        if (w->ww_ispty)
                    117:                                *p = c;
                    118:                }
                    119:        for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw)
                    120:                if (w->ww_pty >= 0 && w->ww_obq > w->ww_obp && !w->ww_stopped) {
                    121:                        n = wwwrite(w, w->ww_obp, w->ww_obq - w->ww_obp);
                    122:                        if ((w->ww_obp += n) == w->ww_obq)
                    123:                                w->ww_obq = w->ww_obp = w->ww_ob;
                    124:                        if (wwinterrupt())
                    125:                                return;
                    126:                        break;
                    127:                }
                    128:        goto loop;
                    129: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.