Annotation of 43BSDTahoe/usr.lib/libcurses/newwin.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Copyright (c) 1981 Regents of the University of California.
                      3:  * All rights reserved.
                      4:  *
                      5:  * Redistribution and use in source and binary forms are permitted
                      6:  * provided that the above copyright notice and this paragraph are
                      7:  * duplicated in all such forms and that any documentation,
                      8:  * advertising materials, and other materials related to such
                      9:  * distribution and use acknowledge that the software was developed
                     10:  * by the University of California, Berkeley.  The name of the
                     11:  * University may not be used to endorse or promote products derived
                     12:  * from this software without specific prior written permission.
                     13:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
                     14:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
                     15:  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     16:  */
                     17: 
                     18: #ifndef lint
                     19: static char sccsid[] = "@(#)newwin.c   5.3 (Berkeley) 6/30/88";
                     20: #endif /* not lint */
                     21: 
                     22: /*
                     23:  * allocate space for and set up defaults for a new window
                     24:  *
                     25:  */
                     26: 
                     27: # include      "curses.ext"
                     28: 
                     29: char   *malloc();
                     30: 
                     31: # define       SMALLOC (short *) malloc
                     32: 
                     33: static WINDOW  *makenew();
                     34: 
                     35: # undef                nl      /* don't need it here, and it interferes        */
                     36: 
                     37: WINDOW *
                     38: newwin(num_lines, num_cols, begy, begx)
                     39: int    num_lines, num_cols, begy, begx;
                     40: {
                     41:        reg WINDOW      *win;
                     42:        reg char        *sp;
                     43:        reg int         i, by, bx, nl, nc;
                     44:        reg int         j;
                     45: 
                     46:        by = begy;
                     47:        bx = begx;
                     48:        nl = num_lines;
                     49:        nc = num_cols;
                     50: 
                     51:        if (nl == 0)
                     52:                nl = LINES - by;
                     53:        if (nc == 0)
                     54:                nc = COLS - bx;
                     55:        if ((win = makenew(nl, nc, by, bx)) == NULL)
                     56:                return ERR;
                     57:        if ((win->_firstch = SMALLOC(nl * sizeof win->_firstch[0])) == NULL) {
                     58:                free(win->_y);
                     59:                free(win);
                     60:                return NULL;
                     61:        }
                     62:        if ((win->_lastch = SMALLOC(nl * sizeof win->_lastch[0])) == NULL) {
                     63:                free(win->_y);
                     64:                free(win->_firstch);
                     65:                free(win);
                     66:                return NULL;
                     67:        }
                     68:        win->_nextp = win;
                     69:        for (i = 0; i < nl; i++) {
                     70:                win->_firstch[i] = _NOCHANGE;
                     71:                win->_lastch[i] = _NOCHANGE;
                     72:        }
                     73:        for (i = 0; i < nl; i++)
                     74:                if ((win->_y[i] = malloc(nc * sizeof win->_y[0])) == NULL) {
                     75:                        for (j = 0; j < i; j++)
                     76:                                free(win->_y[j]);
                     77:                        free(win->_firstch);
                     78:                        free(win->_lastch);
                     79:                        free(win->_y);
                     80:                        free(win);
                     81:                        return ERR;
                     82:                }
                     83:                else
                     84:                        for (sp = win->_y[i]; sp < win->_y[i] + nc; )
                     85:                                *sp++ = ' ';
                     86:        win->_ch_off = 0;
                     87: # ifdef DEBUG
                     88:        fprintf(outf, "NEWWIN: win->_ch_off = %d\n", win->_ch_off);
                     89: # endif
                     90:        return win;
                     91: }
                     92: 
                     93: WINDOW *
                     94: subwin(orig, num_lines, num_cols, begy, begx)
                     95: reg WINDOW     *orig;
                     96: int            num_lines, num_cols, begy, begx;
                     97: {
                     98:        reg int         i;
                     99:        reg WINDOW      *win;
                    100:        reg int         by, bx, nl, nc;
                    101: 
                    102:        by = begy;
                    103:        bx = begx;
                    104:        nl = num_lines;
                    105:        nc = num_cols;
                    106: 
                    107:        /*
                    108:         * make sure window fits inside the original one
                    109:         */
                    110: # ifdef        DEBUG
                    111:        fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
                    112: # endif
                    113:        if (by < orig->_begy || bx < orig->_begx
                    114:            || by + nl > orig->_maxy + orig->_begy
                    115:            || bx + nc > orig->_maxx + orig->_begx)
                    116:                return ERR;
                    117:        if (nl == 0)
                    118:                nl = orig->_maxy + orig->_begy - by;
                    119:        if (nc == 0)
                    120:                nc = orig->_maxx + orig->_begx - bx;
                    121:        if ((win = makenew(nl, nc, by, bx)) == NULL)
                    122:                return ERR;
                    123:        win->_nextp = orig->_nextp;
                    124:        orig->_nextp = win;
                    125:        win->_orig = orig;
                    126:        _set_subwin_(orig, win);
                    127:        return win;
                    128: }
                    129: 
                    130: /*
                    131:  * this code is shared with mvwin()
                    132:  */
                    133: _set_subwin_(orig, win)
                    134: register WINDOW        *orig, *win;
                    135: {
                    136:        register int    i, j, k;
                    137: 
                    138:        j = win->_begy - orig->_begy;
                    139:        k = win->_begx - orig->_begx;
                    140:        win->_ch_off = k;
                    141: # ifdef DEBUG
                    142:        fprintf(outf, "_SET_SUBWIN_: win->_ch_off = %d\n", win->_ch_off);
                    143: # endif
                    144:        win->_firstch = &orig->_firstch[j];
                    145:        win->_lastch = &orig->_lastch[j];
                    146:        for (i = 0; i < win->_maxy; i++, j++)
                    147:                win->_y[i] = &orig->_y[j][k];
                    148: 
                    149: }
                    150: 
                    151: /*
                    152:  *     This routine sets up a window buffer and returns a pointer to it.
                    153:  */
                    154: static WINDOW *
                    155: makenew(num_lines, num_cols, begy, begx)
                    156: int    num_lines, num_cols, begy, begx; {
                    157: 
                    158:        reg int         i;
                    159:        reg WINDOW      *win;
                    160:        reg int         by, bx, nl, nc;
                    161: 
                    162:        by = begy;
                    163:        bx = begx;
                    164:        nl = num_lines;
                    165:        nc = num_cols;
                    166: 
                    167: # ifdef        DEBUG
                    168:        fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
                    169: # endif
                    170:        if ((win = (WINDOW *) malloc(sizeof *win)) == NULL)
                    171:                return NULL;
                    172: # ifdef DEBUG
                    173:        fprintf(outf, "MAKENEW: nl = %d\n", nl);
                    174: # endif
                    175:        if ((win->_y = (char **) malloc(nl * sizeof win->_y[0])) == NULL) {
                    176:                free(win);
                    177:                return NULL;
                    178:        }
                    179: # ifdef DEBUG
                    180:        fprintf(outf, "MAKENEW: nc = %d\n", nc);
                    181: # endif
                    182:        win->_cury = win->_curx = 0;
                    183:        win->_clear = FALSE;
                    184:        win->_maxy = nl;
                    185:        win->_maxx = nc;
                    186:        win->_begy = by;
                    187:        win->_begx = bx;
                    188:        win->_flags = 0;
                    189:        win->_scroll = win->_leave = FALSE;
                    190:        _swflags_(win);
                    191: # ifdef DEBUG
                    192:        fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
                    193:        fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave);
                    194:        fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll);
                    195:        fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags);
                    196:        fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy);
                    197:        fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx);
                    198:        fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy);
                    199:        fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx);
                    200: # endif
                    201:        return win;
                    202: }
                    203: 
                    204: _swflags_(win)
                    205: register WINDOW        *win;
                    206: {
                    207:        win->_flags &= ~(_ENDLINE|_FULLLINE|_FULLWIN|_SCROLLWIN);
                    208:        if (win->_begx + win->_maxx == COLS) {
                    209:                win->_flags |= _ENDLINE;
                    210:                if (win->_begx == 0) {
                    211:                        if (AL && DL)
                    212:                                win->_flags |= _FULLLINE;
                    213:                        if (win->_maxy == LINES && win->_begy == 0)
                    214:                                win->_flags |= _FULLWIN;
                    215:                }
                    216:                if (win->_begy + win->_maxy == LINES)
                    217:                        win->_flags |= _SCROLLWIN;
                    218:        }
                    219: }

unix.superglobalmegacorp.com

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