Annotation of 41BSD/lib/libcurses/newwin.c, revision 1.1

1.1     ! root        1: # include      "curses.ext"
        !             2: 
        !             3: short  *calloc();
        !             4: WINDOW *malloc();
        !             5: 
        !             6: static WINDOW  *makenew();
        !             7: 
        !             8: # undef                nl      /* don't need it here, and it interferes        */
        !             9: 
        !            10: WINDOW *
        !            11: newwin(num_lines, num_cols, begy, begx)
        !            12: int    num_lines, num_cols, begy, begx;
        !            13: {
        !            14:        reg WINDOW      *win;
        !            15:        reg char        *sp;
        !            16:        reg int         i, by, bx, nl, nc;
        !            17: 
        !            18:        by = begy;
        !            19:        bx = begx;
        !            20:        nl = num_lines;
        !            21:        nc = num_cols;
        !            22: 
        !            23:        if (nl == 0)
        !            24:                nl = LINES - by;
        !            25:        if (nc == 0)
        !            26:                nc = COLS - bx;
        !            27:        if ((win = makenew(nl, nc, by, bx)) == NULL)
        !            28:                return ERR;
        !            29:        for (i = 0; i < nl; i++)
        !            30:                if ((win->_y[i] = (char *) calloc(nc, sizeof (char))) == NULL) {
        !            31:                        reg int         j;
        !            32: 
        !            33:                        for (j = 0; j < i; j++)
        !            34:                                cfree(win->_y[j]);
        !            35:                        cfree(win->_firstch);
        !            36:                        cfree(win->_lastch);
        !            37:                        cfree(win->_y);
        !            38:                        cfree(win);
        !            39:                        return ERR;
        !            40:                }
        !            41:                else
        !            42:                        for (sp = win->_y[i]; sp < win->_y[i] + nc; )
        !            43:                                *sp++ = ' ';
        !            44:        return win;
        !            45: }
        !            46: 
        !            47: WINDOW *
        !            48: subwin(orig, num_lines, num_cols, begy, begx)
        !            49: reg WINDOW     *orig;
        !            50: int            num_lines, num_cols, begy, begx; {
        !            51: 
        !            52:        reg int         i;
        !            53:        reg WINDOW      *win;
        !            54:        reg int         by, bx, nl, nc;
        !            55:        reg int         j, k;
        !            56: 
        !            57:        by = begy;
        !            58:        bx = begx;
        !            59:        nl = num_lines;
        !            60:        nc = num_cols;
        !            61: 
        !            62:        /*
        !            63:         * make sure window fits inside the original one
        !            64:         */
        !            65: # ifdef        DEBUG
        !            66:        fprintf(outf, "SUBWIN(%0.2o, %d, %d, %d, %d)\n", orig, nl, nc, by, bx);
        !            67: # endif
        !            68:        if (by < orig->_begy || bx < orig->_begx
        !            69:            || by + nl > orig->_maxy || bx + nc > orig->_maxx)
        !            70:                return ERR;
        !            71:        if (nl == 0)
        !            72:                nl = orig->_maxy - orig->_begy - by;
        !            73:        if (nc == 0)
        !            74:                nc = orig->_maxx - orig->_begx - bx;
        !            75:        if ((win = makenew(nl, nc, by, bx)) == NULL)
        !            76:                return ERR;
        !            77:        j = orig->_begy + by;
        !            78:        k = orig->_begx + bx;
        !            79:        for (i = 0; i < nl; i++)
        !            80:                win->_y[i] = &orig->_y[j++][k];
        !            81:        win->_flags = _SUBWIN;
        !            82:        return win;
        !            83: }
        !            84: 
        !            85: /*
        !            86:  *     This routine sets up a window buffer and returns a pointer to it.
        !            87:  */
        !            88: static WINDOW *
        !            89: makenew(num_lines, num_cols, begy, begx)
        !            90: int    num_lines, num_cols, begy, begx; {
        !            91: 
        !            92:        reg int         i;
        !            93:        reg WINDOW      *win;
        !            94:        reg int         by, bx, nl, nc;
        !            95: 
        !            96:        by = begy;
        !            97:        bx = begx;
        !            98:        nl = num_lines;
        !            99:        nc = num_cols;
        !           100: 
        !           101: # ifdef        DEBUG
        !           102:        fprintf(outf, "MAKENEW(%d, %d, %d, %d)\n", nl, nc, by, bx);
        !           103: # endif
        !           104:        if ((win = (WINDOW *) malloc(sizeof (WINDOW))) == NULL)
        !           105:                return NULL;
        !           106: # ifdef DEBUG
        !           107:        fprintf(outf, "MAKENEW: nl = %d\n", nl);
        !           108: # endif
        !           109:        if ((win->_y = (char **) calloc(nl, sizeof (char *))) == NULL) {
        !           110:                cfree(win);
        !           111:                return (WINDOW *) NULL;
        !           112:        }
        !           113:        if ((win->_firstch = calloc(nl, sizeof (short))) == NULL) {
        !           114:                cfree(win);
        !           115:                cfree(win->_y);
        !           116:        }
        !           117:        if ((win->_lastch = calloc(nl, sizeof (short))) == NULL) {
        !           118:                cfree(win);
        !           119:                cfree(win->_y);
        !           120:                cfree(win->_firstch);
        !           121:        }
        !           122: # ifdef DEBUG
        !           123:        fprintf(outf, "MAKENEW: nc = %d\n", nc);
        !           124: # endif
        !           125:        win->_cury = win->_curx = 0;
        !           126:        win->_clear = (nl == LINES && nc == COLS);
        !           127:        win->_maxy = nl;
        !           128:        win->_maxx = nc;
        !           129:        win->_begy = by;
        !           130:        win->_begx = bx;
        !           131:        win->_scroll = win->_leave = FALSE;
        !           132:        for (i = 0; i < nl; i++)
        !           133:                win->_firstch[i] = win->_lastch[i] = _NOCHANGE;
        !           134:        win->_flags = 0;
        !           135:        if (bx + nc == COLS) {
        !           136:                win->_flags |= _ENDLINE;
        !           137:                if (bx == 0 && nl == LINES && by == 0)
        !           138:                        win->_flags |= _FULLWIN;
        !           139:                if (by + nl == LINES)
        !           140:                        win->_flags |= _SCROLLWIN;
        !           141:        }
        !           142: # ifdef DEBUG
        !           143:        fprintf(outf, "MAKENEW: win->_clear = %d\n", win->_clear);
        !           144:        fprintf(outf, "MAKENEW: win->_leave = %d\n", win->_leave);
        !           145:        fprintf(outf, "MAKENEW: win->_scroll = %d\n", win->_scroll);
        !           146:        fprintf(outf, "MAKENEW: win->_flags = %0.2o\n", win->_flags);
        !           147:        fprintf(outf, "MAKENEW: win->_maxy = %d\n", win->_maxy);
        !           148:        fprintf(outf, "MAKENEW: win->_maxx = %d\n", win->_maxx);
        !           149:        fprintf(outf, "MAKENEW: win->_begy = %d\n", win->_begy);
        !           150:        fprintf(outf, "MAKENEW: win->_begx = %d\n", win->_begx);
        !           151: # endif
        !           152:        return win;
        !           153: }

unix.superglobalmegacorp.com

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