Annotation of researchv10no/ncurses/screen/_shove.c, revision 1.1

1.1     ! root        1: /*     @(#)_shove.c    1.1     (1.22)  */
        !             2: #include "curses.ext"
        !             3: 
        !             4: /*
        !             5:  * Shove right in body as much as necessary.
        !             6:  * Note that we give the space the same attributes as the upcoming
        !             7:  * character, to force the cookie to be placed on the space.
        !             8:  */
        !             9: /* ARGSUSED */
        !            10: _shove(body, len, lno)
        !            11: register chtype *body;
        !            12: register int len, lno;
        !            13: {
        !            14:        register int j, k, prev = 0;
        !            15:        register int curscol = SP->virt_x, cursincr = 0, shoved = 0;
        !            16:        static chtype buf[256];
        !            17: 
        !            18: #ifdef DEBUG
        !            19:        if(outf) fprintf(outf, "_shove('");
        !            20:        _prstr(body, len);
        !            21:        if(outf) fprintf(outf, "', %d, %d), SP->virt_x %d\n", len, lno, SP->virt_x);
        !            22: #endif
        !            23:        for (j=0, k=0; j<len; ) {
        !            24:                if ((body[j]&A_ATTRIBUTES) != prev) {
        !            25:                        shoved++;
        !            26:                        if ((body[j]&A_CHARTEXT) == ' ') {
        !            27:                                /* Using an existing space */
        !            28:                                buf[j] = ' ' | body[j+1]&A_ATTRIBUTES;
        !            29:                        } else if ((body[j-1]&A_CHARTEXT) == ' ') {
        !            30:                                /* Using previous existing space */
        !            31:                                buf[j-1] = ' ' | body[j]&A_ATTRIBUTES;
        !            32:                        } else {
        !            33:                                /* A space is inserted here. */
        !            34:                                buf[k++] = ' ' | body[j]&A_ATTRIBUTES;
        !            35:                                if (j < curscol)
        !            36:                                        cursincr++;
        !            37:                        }
        !            38:                }
        !            39: #ifdef DEBUG
        !            40:                if(outf) fprintf(outf, "j %d, k %d, prev %o, new %o\n",
        !            41:                        j, k, prev, body[j] & A_ATTRIBUTES);
        !            42: #endif
        !            43:                prev = body[j] & A_ATTRIBUTES;
        !            44:                buf[k++] = body[j++];
        !            45:        }
        !            46:        if (shoved) {
        !            47:                /* k is 1 more than the last column of the line */
        !            48:                if (k > columns)
        !            49:                        k = columns;
        !            50:                if (buf[k-1]&A_ATTRIBUTES) {
        !            51:                        if (k < columns)
        !            52:                                k++;
        !            53:                        buf[k-1] = ' '; /* All attributes off */
        !            54:                }
        !            55:                for (j=0; j<k; j++)
        !            56:                        body[j] = buf[j];
        !            57:                len = k;
        !            58:        }
        !            59:        if (cursincr && lno == SP->virt_y+1)
        !            60:                SP->virt_x += cursincr;
        !            61: #ifdef DEBUG
        !            62:        if(outf) fprintf(outf, "returns '");
        !            63:        _prstr(body, len);
        !            64:        if(outf) fprintf(outf, "', len %d, SP->virt_x %d\n", len, SP->virt_x);
        !            65: #endif
        !            66:        return len;
        !            67: }
        !            68: 
        !            69: #ifdef DEBUG
        !            70: static
        !            71: _prstr(result, len)
        !            72: chtype *result;
        !            73: int len;
        !            74: {
        !            75:        register chtype *cp;
        !            76: 
        !            77:        for (cp=result; *cp && cp < result+len; cp++)
        !            78:                if (*cp >= ' ' && *cp <= '~') {
        !            79:                        if(outf) fprintf(outf, "%c", *cp);
        !            80:                } else {
        !            81:                        if(outf) fprintf(outf, "<%o,%c>",
        !            82:                                *cp&A_ATTRIBUTES, *cp&A_CHARTEXT);
        !            83:                }
        !            84: }
        !            85: #endif

unix.superglobalmegacorp.com

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