Annotation of 43BSDReno/lib/libcurses/refresh.c, revision 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: (1) source distributions retain this entire copyright
        !             7:  * notice and comment, and (2) distributions including binaries display
        !             8:  * the following acknowledgement:  ``This product includes software
        !             9:  * developed by the University of California, Berkeley and its contributors''
        !            10:  * in the documentation or other materials provided with the distribution
        !            11:  * and in all advertising materials mentioning features or use of this
        !            12:  * software. Neither the name of the University nor the names of its
        !            13:  * contributors may be used to endorse or promote products derived
        !            14:  * from this software without specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
        !            16:  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
        !            17:  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: static char sccsid[] = "@(#)refresh.c  5.4 (Berkeley) 6/1/90";
        !            22: #endif /* not lint */
        !            23: 
        !            24: /*
        !            25:  * make the current screen look like "win" over the area coverd by
        !            26:  * win.
        !            27:  */
        !            28: 
        !            29: # include      "curses.ext"
        !            30: 
        !            31: # ifdef DEBUG
        !            32: # define       STATIC
        !            33: # else
        !            34: # define       STATIC  static
        !            35: # endif
        !            36: 
        !            37: STATIC short   ly, lx;
        !            38: 
        !            39: STATIC bool    curwin;
        !            40: 
        !            41: WINDOW *_win = NULL;
        !            42: 
        !            43: wrefresh(win)
        !            44: reg WINDOW     *win;
        !            45: {
        !            46:        reg short       wy;
        !            47:        reg int         retval;
        !            48:        reg WINDOW      *orig;
        !            49: 
        !            50:        /*
        !            51:         * make sure were in visual state
        !            52:         */
        !            53:        if (_endwin) {
        !            54:                _puts(VS);
        !            55:                _puts(TI);
        !            56:                _endwin = FALSE;
        !            57:        }
        !            58: 
        !            59:        /*
        !            60:         * initialize loop parameters
        !            61:         */
        !            62: 
        !            63:        ly = curscr->_cury;
        !            64:        lx = curscr->_curx;
        !            65:        wy = 0;
        !            66:        _win = win;
        !            67:        curwin = (win == curscr);
        !            68: 
        !            69:        if (win->_clear || curscr->_clear || curwin) {
        !            70:                if ((win->_flags & _FULLWIN) || curscr->_clear) {
        !            71:                        _puts(CL);
        !            72:                        ly = 0;
        !            73:                        lx = 0;
        !            74:                        if (!curwin) {
        !            75:                                curscr->_clear = FALSE;
        !            76:                                curscr->_cury = 0;
        !            77:                                curscr->_curx = 0;
        !            78:                                werase(curscr);
        !            79:                        }
        !            80:                        touchwin(win);
        !            81:                }
        !            82:                win->_clear = FALSE;
        !            83:        }
        !            84:        if (!CA) {
        !            85:                if (win->_curx != 0)
        !            86:                        _putchar('\n');
        !            87:                if (!curwin)
        !            88:                        werase(curscr);
        !            89:        }
        !            90: # ifdef DEBUG
        !            91:        fprintf(outf, "REFRESH(%0.2o): curwin = %d\n", win, curwin);
        !            92:        fprintf(outf, "REFRESH:\n\tfirstch\tlastch\n");
        !            93: # endif
        !            94:        for (wy = 0; wy < win->_maxy; wy++) {
        !            95: # ifdef DEBUG
        !            96:                fprintf(outf, "%d\t%d\t%d\n", wy, win->_firstch[wy],
        !            97:                        win->_lastch[wy]);
        !            98: # endif
        !            99:                if (win->_firstch[wy] != _NOCHANGE)
        !           100:                        if (makech(win, wy) == ERR)
        !           101:                                return ERR;
        !           102:                        else {
        !           103:                                if (win->_firstch[wy] >= win->_ch_off)
        !           104:                                        win->_firstch[wy] = win->_maxx +
        !           105:                                                            win->_ch_off;
        !           106:                                if (win->_lastch[wy] < win->_maxx +
        !           107:                                                       win->_ch_off)
        !           108:                                        win->_lastch[wy] = win->_ch_off;
        !           109:                                if (win->_lastch[wy] < win->_firstch[wy])
        !           110:                                        win->_firstch[wy] = _NOCHANGE;
        !           111:                        }
        !           112: # ifdef DEBUG
        !           113:                fprintf(outf, "\t%d\t%d\n", win->_firstch[wy],
        !           114:                        win->_lastch[wy]);
        !           115: # endif
        !           116:        }
        !           117: 
        !           118:        if (win == curscr)
        !           119:                domvcur(ly, lx, win->_cury, win->_curx);
        !           120:        else {
        !           121:                if (win->_leave) {
        !           122:                        curscr->_cury = ly;
        !           123:                        curscr->_curx = lx;
        !           124:                        ly -= win->_begy;
        !           125:                        lx -= win->_begx;
        !           126:                        if (ly >= 0 && ly < win->_maxy && lx >= 0 &&
        !           127:                            lx < win->_maxx) {
        !           128:                                win->_cury = ly;
        !           129:                                win->_curx = lx;
        !           130:                        }
        !           131:                        else
        !           132:                                win->_cury = win->_curx = 0;
        !           133:                }
        !           134:                else {
        !           135:                        domvcur(ly, lx, win->_cury + win->_begy,
        !           136:                                win->_curx + win->_begx);
        !           137:                        curscr->_cury = win->_cury + win->_begy;
        !           138:                        curscr->_curx = win->_curx + win->_begx;
        !           139:                }
        !           140:        }
        !           141:        retval = OK;
        !           142: ret:
        !           143:        _win = NULL;
        !           144:        fflush(stdout);
        !           145:        return retval;
        !           146: }
        !           147: 
        !           148: /*
        !           149:  * make a change on the screen
        !           150:  */
        !           151: STATIC
        !           152: makech(win, wy)
        !           153: reg WINDOW     *win;
        !           154: short          wy;
        !           155: {
        !           156:        reg char        *nsp, *csp, *ce;
        !           157:        reg short       wx, lch, y;
        !           158:        reg int         nlsp, clsp;     /* last space in lines          */
        !           159: 
        !           160:        wx = win->_firstch[wy] - win->_ch_off;
        !           161:        if (wx >= win->_maxx)
        !           162:                return OK;
        !           163:        else if (wx < 0)
        !           164:                wx = 0;
        !           165:        lch = win->_lastch[wy] - win->_ch_off;
        !           166:        if (lch < 0)
        !           167:                return OK;
        !           168:        else if (lch >= win->_maxx)
        !           169:                lch = win->_maxx - 1;;
        !           170:        y = wy + win->_begy;
        !           171: 
        !           172:        if (curwin)
        !           173:                csp = " ";
        !           174:        else
        !           175:                csp = &curscr->_y[wy + win->_begy][wx + win->_begx];
        !           176: 
        !           177:        nsp = &win->_y[wy][wx];
        !           178:        if (CE && !curwin) {
        !           179:                for (ce = &win->_y[wy][win->_maxx - 1]; *ce == ' '; ce--)
        !           180:                        if (ce <= win->_y[wy])
        !           181:                                break;
        !           182:                nlsp = ce - win->_y[wy];
        !           183:        }
        !           184: 
        !           185:        if (!curwin)
        !           186:                ce = CE;
        !           187:        else
        !           188:                ce = NULL;
        !           189: 
        !           190:        while (wx <= lch) {
        !           191:                if (*nsp != *csp) {
        !           192:                        domvcur(ly, lx, y, wx + win->_begx);
        !           193: # ifdef DEBUG
        !           194:                        fprintf(outf, "MAKECH: 1: wx = %d, lx = %d\n", wx, lx);
        !           195: # endif        
        !           196:                        ly = y;
        !           197:                        lx = wx + win->_begx;
        !           198:                        while (*nsp != *csp && wx <= lch) {
        !           199:                                if (ce != NULL && wx >= nlsp && *nsp == ' ') {
        !           200:                                        /*
        !           201:                                         * check for clear to end-of-line
        !           202:                                         */
        !           203:                                        ce = &curscr->_y[ly][COLS - 1];
        !           204:                                        while (*ce == ' ')
        !           205:                                                if (ce-- <= csp)
        !           206:                                                        break;
        !           207:                                        clsp = ce - curscr->_y[ly] - win->_begx;
        !           208: # ifdef DEBUG
        !           209:                                        fprintf(outf, "MAKECH: clsp = %d, nlsp = %d\n", clsp, nlsp);
        !           210: # endif
        !           211:                                        if (clsp - nlsp >= strlen(CE)
        !           212:                                            && clsp < win->_maxx) {
        !           213: # ifdef DEBUG
        !           214:                                                fprintf(outf, "MAKECH: using CE\n");
        !           215: # endif
        !           216:                                                _puts(CE);
        !           217:                                                lx = wx + win->_begx;
        !           218:                                                while (wx++ <= clsp)
        !           219:                                                        *csp++ = ' ';
        !           220:                                                return OK;
        !           221:                                        }
        !           222:                                        ce = NULL;
        !           223:                                }
        !           224:                                /*
        !           225:                                 * enter/exit standout mode as appropriate
        !           226:                                 */
        !           227:                                if (SO && (*nsp&_STANDOUT) != (curscr->_flags&_STANDOUT)) {
        !           228:                                        if (*nsp & _STANDOUT) {
        !           229:                                                _puts(SO);
        !           230:                                                curscr->_flags |= _STANDOUT;
        !           231:                                        }
        !           232:                                        else {
        !           233:                                                _puts(SE);
        !           234:                                                curscr->_flags &= ~_STANDOUT;
        !           235:                                        }
        !           236:                                }
        !           237:                                wx++;
        !           238:                                if (wx >= win->_maxx && wy == win->_maxy - 1)
        !           239:                                        if (win->_scroll) {
        !           240:                                            if ((curscr->_flags&_STANDOUT) &&
        !           241:                                                (win->_flags & _ENDLINE))
        !           242:                                                    if (!MS) {
        !           243:                                                        _puts(SE);
        !           244:                                                        curscr->_flags &= ~_STANDOUT;
        !           245:                                                    }
        !           246:                                            if (!curwin)
        !           247:                                                _putchar((*csp = *nsp) & 0177);
        !           248:                                            else
        !           249:                                                _putchar(*nsp & 0177);
        !           250:                                            if (win->_flags&_FULLWIN && !curwin)
        !           251:                                                scroll(curscr);
        !           252:                                            ly = win->_begy+win->_cury;
        !           253:                                            lx = win->_begx+win->_curx;
        !           254:                                            return OK;
        !           255:                                        }
        !           256:                                        else if (win->_flags&_SCROLLWIN) {
        !           257:                                            lx = --wx;
        !           258:                                            return ERR;
        !           259:                                        }
        !           260:                                if (!curwin)
        !           261:                                        _putchar((*csp++ = *nsp) & 0177);
        !           262:                                else
        !           263:                                        _putchar(*nsp & 0177);
        !           264: # ifdef FULLDEBUG
        !           265:                                fprintf(outf,
        !           266:                                        "MAKECH:putchar(%c)\n", *nsp & 0177);
        !           267: # endif
        !           268:                                if (UC && (*nsp & _STANDOUT)) {
        !           269:                                        _putchar('\b');
        !           270:                                        _puts(UC);
        !           271:                                }
        !           272:                                nsp++;
        !           273:                        }
        !           274: # ifdef DEBUG
        !           275:                        fprintf(outf, "MAKECH: 2: wx = %d, lx = %d\n", wx, lx);
        !           276: # endif        
        !           277:                        if (lx == wx + win->_begx)      /* if no change */
        !           278:                                break;
        !           279:                        lx = wx + win->_begx;
        !           280:                        if (lx >= COLS && AM) {
        !           281:                                lx = 0;
        !           282:                                ly++;
        !           283:                                /*
        !           284:                                 * xn glitch: chomps a newline after auto-wrap.
        !           285:                                 * we just feed it now and forget about it.
        !           286:                                 */
        !           287:                                if (XN) {
        !           288:                                        _putchar('\n');
        !           289:                                        _putchar('\r');
        !           290:                                }
        !           291:                        }
        !           292:                }
        !           293:                else if (wx <= lch)
        !           294:                        while (*nsp == *csp && wx <= lch) {
        !           295:                                nsp++;
        !           296:                                if (!curwin)
        !           297:                                        csp++;
        !           298:                                ++wx;
        !           299:                        }
        !           300:                else
        !           301:                        break;
        !           302: # ifdef DEBUG
        !           303:                fprintf(outf, "MAKECH: 3: wx = %d, lx = %d\n", wx, lx);
        !           304: # endif        
        !           305:        }
        !           306:        return OK;
        !           307: }
        !           308: 
        !           309: /*
        !           310:  * perform a mvcur, leaving standout mode if necessary
        !           311:  */
        !           312: STATIC
        !           313: domvcur(oy, ox, ny, nx)
        !           314: int    oy, ox, ny, nx; {
        !           315: 
        !           316:        if (curscr->_flags & _STANDOUT && !MS) {
        !           317:                _puts(SE);
        !           318:                curscr->_flags &= ~_STANDOUT;
        !           319:        }
        !           320:        mvcur(oy, ox, ny, nx);
        !           321: }

unix.superglobalmegacorp.com

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