Annotation of 43BSDReno/usr.bin/window/wwopen.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1983 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * This code is derived from software contributed to Berkeley by
                      6:  * Edward Wang at The University of California, Berkeley.
                      7:  *
                      8:  * Redistribution and use in source and binary forms are permitted provided
                      9:  * that: (1) source distributions retain this entire copyright notice and
                     10:  * comment, and (2) distributions including binaries display the following
                     11:  * acknowledgement:  ``This product includes software developed by the
                     12:  * University of California, Berkeley and its contributors'' in the
                     13:  * documentation or other materials provided with the distribution and in
                     14:  * all advertising materials mentioning features or use of this software.
                     15:  * Neither the name of the University nor the names of its contributors may
                     16:  * be used to endorse or promote products derived from this software without
                     17:  * specific prior written permission.
                     18:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     19:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     20:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     21:  */
                     22: 
                     23: #ifndef lint
                     24: static char sccsid[] = "@(#)wwopen.c   3.29 (Berkeley) 6/6/90";
                     25: #endif /* not lint */
                     26: 
                     27: #include "ww.h"
                     28: #include <sys/types.h>
                     29: #include <sys/socket.h>
                     30: 
                     31: struct ww *
                     32: wwopen(flags, nrow, ncol, row, col, nline)
                     33: {
                     34:        register struct ww *w;
                     35:        register i, j;
                     36:        char m;
                     37:        short nvis;
                     38: 
                     39:        w = (struct ww *)calloc(sizeof (struct ww), 1);
                     40:        if (w == 0) {
                     41:                wwerrno = WWE_NOMEM;
                     42:                goto bad;
                     43:        }
                     44:        w->ww_pty = -1;
                     45:        w->ww_socket = -1;
                     46: 
                     47:        for (i = 0; i < NWW && wwindex[i] != 0; i++)
                     48:                ;
                     49:        if (i >= NWW) {
                     50:                wwerrno = WWE_TOOMANY;
                     51:                goto bad;
                     52:        }
                     53:        w->ww_index = i;
                     54: 
                     55:        if (nline < nrow)
                     56:                nline = nrow;
                     57: 
                     58:        w->ww_w.t = row;
                     59:        w->ww_w.b = row + nrow;
                     60:        w->ww_w.l = col;
                     61:        w->ww_w.r = col + ncol;
                     62:        w->ww_w.nr = nrow;
                     63:        w->ww_w.nc = ncol;
                     64: 
                     65:        w->ww_b.t = row;
                     66:        w->ww_b.b = row + nline;
                     67:        w->ww_b.l = col;
                     68:        w->ww_b.r = col + ncol;
                     69:        w->ww_b.nr = nline;
                     70:        w->ww_b.nc = ncol;
                     71: 
                     72:        w->ww_i.t = MAX(w->ww_w.t, 0);
                     73:        w->ww_i.b = MIN(w->ww_w.b, wwnrow);
                     74:        w->ww_i.l = MAX(w->ww_w.l, 0);
                     75:        w->ww_i.r = MIN(w->ww_w.r, wwncol);
                     76:        w->ww_i.nr = w->ww_i.b - w->ww_i.t;
                     77:        w->ww_i.nc = w->ww_i.r - w->ww_i.l;
                     78: 
                     79:        w->ww_cur.r = w->ww_w.t;
                     80:        w->ww_cur.c = w->ww_w.l;
                     81: 
                     82:        if (flags & WWO_PTY) {
                     83:                if (wwgetpty(w) < 0)
                     84:                        goto bad;
                     85:                w->ww_ispty = 1;
                     86:        } else if (flags & WWO_SOCKET) {
                     87:                int d[2];
                     88:                if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, d) < 0) {
                     89:                        wwerrno = WWE_SYS;
                     90:                        goto bad;
                     91:                }
                     92:                w->ww_pty = d[0];
                     93:                w->ww_socket = d[1];
                     94:        }
                     95:        if (flags & (WWO_PTY|WWO_SOCKET)) {
                     96:                if ((w->ww_ob = malloc(512)) == 0) {
                     97:                        wwerrno = WWE_NOMEM;
                     98:                        goto bad;
                     99:                }
                    100:                w->ww_obe = w->ww_ob + 512;
                    101:                w->ww_obp = w->ww_obq = w->ww_ob;
                    102:        }
                    103: 
                    104:        w->ww_win = wwalloc(w->ww_w.t, w->ww_w.l,
                    105:                w->ww_w.nr, w->ww_w.nc, sizeof (char));
                    106:        if (w->ww_win == 0)
                    107:                goto bad;
                    108:        m = 0;
                    109:        if (flags & WWO_GLASS)
                    110:                m |= WWM_GLS;
                    111:        if (flags & WWO_REVERSE)
                    112:                if (wwavailmodes & WWM_REV)
                    113:                        m |= WWM_REV;
                    114:                else
                    115:                        flags &= ~WWO_REVERSE;
                    116:        for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    117:                for (j = w->ww_w.l; j < w->ww_w.r; j++)
                    118:                        w->ww_win[i][j] = m;
                    119: 
                    120:        if (flags & WWO_FRAME) {
                    121:                w->ww_fmap = wwalloc(w->ww_w.t, w->ww_w.l,
                    122:                        w->ww_w.nr, w->ww_w.nc, sizeof (char));
                    123:                if (w->ww_fmap == 0)
                    124:                        goto bad;
                    125:                for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    126:                        for (j = w->ww_w.l; j < w->ww_w.r; j++)
                    127:                                w->ww_fmap[i][j] = 0;
                    128:        }
                    129: 
                    130:        w->ww_buf = (union ww_char **)
                    131:                wwalloc(w->ww_b.t, w->ww_b.l,
                    132:                        w->ww_b.nr, w->ww_b.nc, sizeof (union ww_char));
                    133:        if (w->ww_buf == 0)
                    134:                goto bad;
                    135:        for (i = w->ww_b.t; i < w->ww_b.b; i++)
                    136:                for (j = w->ww_b.l; j < w->ww_b.r; j++)
                    137:                        w->ww_buf[i][j].c_w = ' ';
                    138: 
                    139:        w->ww_nvis = (short *)malloc((unsigned) w->ww_w.nr * sizeof (short));
                    140:        if (w->ww_nvis == 0) {
                    141:                wwerrno = WWE_NOMEM;
                    142:                goto bad;
                    143:        }
                    144:        w->ww_nvis -= w->ww_w.t;
                    145:        nvis = m ? 0 : w->ww_w.nc;
                    146:        for (i = w->ww_w.t; i < w->ww_w.b; i++)
                    147:                w->ww_nvis[i] = nvis;
                    148: 
                    149:        w->ww_state = WWS_INITIAL;
                    150:        w->ww_oflags = flags;
                    151:        return wwindex[w->ww_index] = w;
                    152: bad:
                    153:        if (w != 0) {
                    154:                if (w->ww_win != 0)
                    155:                        wwfree(w->ww_win, w->ww_w.t);
                    156:                if (w->ww_fmap != 0)
                    157:                        wwfree(w->ww_fmap, w->ww_w.t);
                    158:                if (w->ww_buf != 0)
                    159:                        wwfree((char **)w->ww_buf, w->ww_b.t);
                    160:                if (w->ww_nvis != 0)
                    161:                        free((char *)(w->ww_nvis + w->ww_w.t));
                    162:                if (w->ww_ob != 0)
                    163:                        free(w->ww_ob);
                    164:                if (w->ww_pty >= 0)
                    165:                        (void) close(w->ww_pty);
                    166:                if (w->ww_socket >= 0)
                    167:                        (void) close(w->ww_socket);
                    168:                free((char *)w);
                    169:        }
                    170:        return 0;
                    171: }

unix.superglobalmegacorp.com

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