Annotation of coherent/g/usr/lib/ncurses/lib_newwin.c, revision 1.1

1.1     ! root        1: /*********************************************************************
        !             2: *                         COPYRIGHT NOTICE                           *
        !             3: **********************************************************************
        !             4: *        This software is copyright (C) 1982 by Pavel Curtis         *
        !             5: *                                                                    *
        !             6: *        Permission is granted to reproduce and distribute           *
        !             7: *        this file by any means so long as no fee is charged         *
        !             8: *        above a nominal handling fee and so long as this            *
        !             9: *        notice is always included in the copies.                    *
        !            10: *                                                                    *
        !            11: *        Other rights are reserved except as explicitly granted      *
        !            12: *        by written permission of the author.                        *
        !            13: *                Pavel Curtis                                        *
        !            14: *                Computer Science Dept.                              *
        !            15: *                405 Upson Hall                                      *
        !            16: *                Cornell University                                  *
        !            17: *                Ithaca, NY 14853                                    *
        !            18: *                                                                    *
        !            19: *                Ph- (607) 256-4934                                  *
        !            20: *                                                                    *
        !            21: *                Pavel.Cornell@Udel-Relay   (ARPAnet)                *
        !            22: *                decvax!cornell!pavel       (UUCPnet)                *
        !            23: *********************************************************************/
        !            24: 
        !            25: /*
        !            26: **     lib_newwin.c
        !            27: **
        !            28: **     The routines newwin(), subwin() and their dependent
        !            29: **
        !            30: ** $Log:       lib_newwin.c,v $
        !            31:  * Revision 1.12  93/04/12  14:13:55  bin
        !            32:  * Udo: third color update
        !            33:  * 
        !            34:  * Revision 2.3  92/11/08  15:33:25  munk
        !            35:  * Correct definition of calloc() and malloc()
        !            36:  * and usage of cast operator
        !            37:  *
        !            38:  * Revision 1.5  92/06/02  12:05:26  bin
        !            39:  * *** empty log message ***
        !            40:  * 
        !            41:  * Revision 1.2  92/04/13  14:38:12  bin
        !            42:  * update by vlad
        !            43:  * 
        !            44:  * Revision 2.2  91/04/20  19:31:13  munk
        !            45:  * Usage of register variables
        !            46:  *
        !            47:  * Revision 2.1  82/10/25  14:48:18  pavel
        !            48:  * Added Copyright Notice
        !            49:  * 
        !            50:  * Revision 2.0  82/10/25  13:47:18  pavel
        !            51:  * Beta-one Test Release
        !            52:  * 
        !            53: **
        !            54: */
        !            55: 
        !            56: #ifdef RCSHDR
        !            57: static char RCSid[] =
        !            58:        "$Header: /src386/usr/lib/ncurses/RCS/lib_newwin.c,v 1.12 93/04/12 14:13:55 bin Exp Locker: bin $";
        !            59: #endif
        !            60: 
        !            61: #include "term.h"
        !            62: #include "curses.h"
        !            63: #include "curses.priv.h"
        !            64: 
        !            65: char   *calloc(), *malloc();
        !            66: 
        !            67: static WINDOW  *makenew();
        !            68: 
        !            69: 
        !            70: WINDOW *
        !            71: newwin(num_lines, num_columns, begy, begx)
        !            72: int    num_lines, num_columns, begy, begx;
        !            73: {
        !            74:        void            free();
        !            75:        register WINDOW *win;
        !            76:        chtype          *ptr;
        !            77:        register int    i, j;
        !            78: 
        !            79: #ifdef TRACE
        !            80:        if (_tracing)
        !            81:            _tracef("newwin(%d,%d,%d,%d) called", num_lines, num_columns, begy, begx);
        !            82: #endif
        !            83: 
        !            84:        if (!num_lines)
        !            85:            num_lines = lines - begy;
        !            86: 
        !            87:        if (!num_columns)
        !            88:            num_columns = columns - begx;
        !            89: 
        !            90:        if ((win = makenew(num_lines, num_columns, begy, begx)) == ERR)
        !            91:            return(ERR);
        !            92: 
        !            93:        for (i = 0; i < num_lines; i++)
        !            94:        {
        !            95:            if ((win->_line[i] = (chtype *)calloc(num_columns, sizeof(chtype)))
        !            96:                                                                      == NULL)
        !            97:            {
        !            98:                for (j = 0; j < i; j++)
        !            99:                    free(win->_line[j]);
        !           100: 
        !           101:                free(win->_firstchar);
        !           102:                free(win->_lastchar);
        !           103:                free(win->_line);
        !           104:                free(win);
        !           105: 
        !           106:                return(ERR);
        !           107:            }
        !           108:            else
        !           109:                for (ptr = win->_line[i]; ptr < win->_line[i] + num_columns; )
        !           110:                    *ptr++ = ' ';
        !           111:        }
        !           112: 
        !           113: #ifdef TRACE
        !           114:        if (_tracing)
        !           115:            _tracef("\tnewwin: returned window is %o", win);
        !           116: #endif
        !           117: 
        !           118:        return(win);
        !           119: }
        !           120: 
        !           121: 
        !           122: WINDOW *
        !           123: subwin(orig, num_lines, num_columns, begy, begx)
        !           124: register WINDOW        *orig;
        !           125: int    num_lines, num_columns, begy, begx;
        !           126: {
        !           127:        register WINDOW *win;
        !           128:        int             i, j, k;
        !           129: 
        !           130: #ifdef TRACE
        !           131:        if (_tracing)
        !           132:            _tracef("subwin(%d,%d,%d,%d) called",
        !           133:                 num_lines, num_columns, begy, begx);
        !           134: #endif
        !           135:        /* no negative displacments */
        !           136:        if ((0 > (j = begy)) || (0 > (k = begx)))
        !           137:                return(ERR);
        !           138: 
        !           139:        if (!num_lines)
        !           140:            num_lines = orig->_maxy - begy;
        !           141: 
        !           142:        if (!num_columns)
        !           143:            num_columns = orig->_maxx - begx;
        !           144: 
        !           145:        /* turn relative location to absolute location */
        !           146:        begx += orig->_begx;
        !           147:        begy += orig->_begy;
        !           148: 
        !           149:        /* more sanity checks */
        !           150:        if ((0 > num_lines) || 
        !           151:            (0 > num_columns) ||
        !           152:            ((begy + num_lines) > (orig->_begy + orig->_maxy)) ||
        !           153:            ((begx + num_columns) > (orig->_begx + orig->_maxx)))
        !           154:                return(ERR);
        !           155: 
        !           156:        if ((win = makenew(num_lines, num_columns, begy, begx)) == ERR)
        !           157:            return(ERR);
        !           158: 
        !           159:        for (i = 0; i < num_lines; i++)
        !           160:            win->_line[i] = &orig->_line[j++][k];
        !           161: 
        !           162:        win->_flags = _SUBWIN;
        !           163: 
        !           164: #ifdef TRACE
        !           165:        if (_tracing)
        !           166:            _tracef("\tsubwin: returned window is %o", win);
        !           167: #endif
        !           168: 
        !           169:        return(win);
        !           170: }
        !           171: 
        !           172: 
        !           173: static WINDOW *
        !           174: makenew(num_lines, num_columns, begy, begx)
        !           175: int    num_lines, num_columns, begy, begx;
        !           176: {
        !           177:        void            free();
        !           178:        register int    i;
        !           179:        register WINDOW *win;
        !           180: 
        !           181:        if ((win = (WINDOW *) malloc(sizeof(WINDOW))) == NULL)
        !           182:                return ERR;
        !           183: 
        !           184:        if ((win->_line = (chtype **) calloc(num_lines, sizeof (chtype *)))
        !           185:                                                                       == NULL)
        !           186:        {
        !           187:                free(win);
        !           188: 
        !           189:                return(ERR);
        !           190:        }
        !           191: 
        !           192:        if ((win->_firstchar = (short *) calloc(num_lines, sizeof(short))) == NULL)
        !           193:        {
        !           194:                free(win->_line);
        !           195:                free(win);
        !           196: 
        !           197:                return(ERR);
        !           198:        }
        !           199: 
        !           200:        if ((win->_lastchar = (short *) calloc(num_lines, sizeof(short))) == NULL)
        !           201:        {
        !           202:                free(win->_firstchar);
        !           203:                free(win->_line);
        !           204:                free(win);
        !           205: 
        !           206:                return(ERR);
        !           207:        }
        !           208: 
        !           209:        if ((win->_numchngd = (short *) calloc(num_lines, sizeof(short))) == NULL)
        !           210:        {
        !           211:                free(win->_lastchar);
        !           212:                free(win->_firstchar);
        !           213:                free(win->_line);
        !           214:                free(win);
        !           215: 
        !           216:                return(ERR);
        !           217:        }
        !           218: 
        !           219:        win->_curx       = 0;
        !           220:        win->_cury       = 0;
        !           221:        win->_maxy       = num_lines - 1;
        !           222:        win->_maxx       = num_columns - 1;
        !           223:        win->_begy       = begy;
        !           224:        win->_begx       = begx;
        !           225: 
        !           226:        win->_flags      = 0;
        !           227:        win->_attrs      = A_NORMAL;
        !           228: 
        !           229:        win->_clear      = (num_lines == lines  &&  num_columns == columns);
        !           230:        win->_scroll     = FALSE;
        !           231:        win->_leave      = FALSE;
        !           232:        win->_use_keypad = FALSE;
        !           233:        win->_use_meta   = FALSE;
        !           234:        win->_nodelay    = FALSE;
        !           235: 
        !           236:        win->_regtop     = 0;
        !           237:        win->_regbottom  = num_lines - 1;
        !           238: 
        !           239:        for (i = 0; i < num_lines; i++)
        !           240:        {
        !           241:            win->_firstchar[i] = win->_lastchar[i] = _NOCHANGE;
        !           242:            win->_numchngd[i] = 0;
        !           243:        }
        !           244: 
        !           245:        if (begx + num_columns == columns)
        !           246:        {
        !           247:                win->_flags |= _ENDLINE;
        !           248: 
        !           249:                if (begx == 0  &&  num_lines == lines  &&  begy == 0)
        !           250:                        win->_flags |= _FULLWIN;
        !           251: 
        !           252:                if (begy + num_lines == lines)
        !           253:                        win->_flags |= _SCROLLWIN;
        !           254:        }
        !           255: 
        !           256:        return(win);
        !           257: }

unix.superglobalmegacorp.com

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