Annotation of researchv10no/ncurses/screen/showstring.c, revision 1.1.1.1

1.1       root        1: /*     @(#) showstring.c: 1.1 10/15/83 (1.20   3/6/83) */
                      2: 
                      3: #include "curses.ext"
                      4: 
                      5: /*
                      6:  * Dump the string running from first to last out to the terminal.
                      7:  * Take into account attributes, and attempt to take advantage of
                      8:  * large pieces of white space and text that's already there.
                      9:  * oldline is the old text of the line.
                     10:  *
                     11:  * Variable naming convention: *x means "extension", e.g. a rubber band
                     12:  * that briefly looks ahead; *c means a character version of an otherwise
                     13:  * chtype pointer; old means what was on the screen before this call;
                     14:  * left means the char 1 space to the left.
                     15:  */
                     16: _showstring(sline, scol, first, last, oldlp)
                     17: int sline, scol;
                     18: chtype *first, *last; 
                     19: struct line *oldlp;
                     20: {
                     21:        register int hl = 0;    /* nontrivial line, highlighted or with holes */
                     22:        int prevhl=SP->virt_gr, thishl; /* highlight state tty is in     */
                     23:        register chtype *p, *px;        /* current char being considered */
                     24:        register chtype *oldp, *oldpx;  /* stuff under p and px          */
                     25:        register char *pc, *pcx;        /* like p, px but in char buffer */
                     26:        chtype *tailoldp;               /* last valid oldp               */
                     27:        int oldlen;                     /* length of old line            */
                     28:        int lcol, lrow;                 /* position on screen            */
                     29:        int oldc;                       /* char at oldp                  */
                     30:        int leftoldc, leftnewc;         /* old & new chars to left of p  */
                     31:        int diff_cookies;               /* magic cookies changed         */
                     32:        int diff_attrs;                 /* highlights changed            */
                     33:        chtype *oldline;
                     34: #ifdef NONSTANDARD
                     35:        static
                     36: #endif NONSTANDARD
                     37:           char firstc[256], *lastc;    /* char copy of input first, last */
                     38: 
                     39: #ifdef DEBUG
                     40:        if(outf) fprintf(outf, "_showstring((%d,%d) %d:'", sline, scol, last-first+1);
                     41:        if(outf)
                     42:                for (p=first; p<=last; p++) {
                     43:                        thishl = *p & A_ATTRIBUTES;
                     44:                        if (thishl)
                     45:                                putc('\'', outf);
                     46:                        putc(*p & A_CHARTEXT, outf);
                     47:                }
                     48:        if(outf) fprintf(outf, "').\n");
                     49: #endif
                     50:        if (last-first > columns) {
                     51:                _pos(lines-1, 0);
                     52: #ifndef                NONSTANDARD
                     53:                fprintf(stderr, "Bad call to _showstring, first %x, last %x,\
                     54:  diff %d\pcx\n", first, last, last-first);
                     55: #endif
                     56:                abort();
                     57:        }
                     58:        if (oldlp) {
                     59:                oldline = oldlp->body;
                     60:                oldp = oldline+scol;
                     61:        }
                     62:        else
                     63:                oldp = 0;
                     64:        for (p=first,lastc=firstc; p<=last; ) {
                     65:                if (*p & A_ATTRIBUTES)
                     66:                        hl++;   /* attributes on the line */
                     67:                if (oldp && (*oldp++ & A_ATTRIBUTES))
                     68:                        hl++;   /* attributes on old line */
                     69:                if (*p==' ' && (px=p+1,*px++==' ') && *px++==' ' && *px==' ')
                     70:                        hl++;   /* a run of at least 4 blanks */
                     71:                *lastc++ = *p & A_CHARTEXT;
                     72:                p++;    /* On a separate line due to C optimizer bug */
                     73: #ifdef FULLDEBUG
                     74:        if(outf) fprintf(outf, "p %x '%c' %o, lastc %x %o, oldp %x %o, hl %d\n", p, p[-1], p[-1], lastc, lastc[-1], oldp, oldp ? oldp[-1] : 0, hl);
                     75: #endif
                     76:        }
                     77:        lastc--;
                     78: 
                     79:        lcol = scol; lrow = sline;
                     80:        if (oldlp) {
                     81:                oldline = oldlp->body;
                     82:                oldlen = oldlp->length;
                     83:                /* Check for runs of stuff that's already there. */
                     84:                for (p=first,oldp=oldline+lcol; p<=last; p++,oldp++) {
                     85:                        if (*p==*oldp && (px=p+1,oldpx=oldp+1,*px++==*oldpx++)
                     86:                                          && *px++==*oldpx++ && *px==*oldpx)
                     87:                                hl++;   /* a run of at least 4 matches */
                     88: #ifdef FULLDEBUG
                     89:        if(outf) fprintf(outf, "p %x '%c%c%c%c', oldp %x '%c%c%c%c', hl %d\n",
                     90:        p, p[0], p[1], p[2], p[3],
                     91:        oldp, oldp[0], oldp[1], oldp[2], oldp[3],
                     92:        hl);
                     93: #endif
                     94:                }
                     95:        } else {
                     96:                oldline = NULL;
                     97:                oldlen = 0;
                     98:        }
                     99: 
                    100:        if (!hl) {
                    101:                /* Simple, common case.  Do it fast. */
                    102:                _pos(lrow, lcol);
                    103:                _hlmode(0);
                    104:                _writechars(firstc, lastc);
                    105:                return;
                    106:        }
                    107: 
                    108: #ifdef DEBUG
                    109:        if(outf) fprintf(outf, "oldlp %x, oldline %x, oldlen %d 0x%x\n", oldlp, oldline, oldlen, oldlen);
                    110:        if(outf) fprintf(outf, "old body('");
                    111:        if (oldlp)
                    112:                for (p=oldline; p<=oldline+oldlen; p++)
                    113:                        if(outf) fprintf(outf, "%c", *p);
                    114:        if(outf) fprintf(outf, "').\n");
                    115: #endif
                    116:        oldc = first[-1];
                    117:        tailoldp = oldline + oldlen;
                    118:        for (p=first, oldp=oldline+lcol, pc=firstc; pc<=lastc; p++,oldp++,pc++) {
                    119:                thishl = *p & A_ATTRIBUTES;
                    120: #ifdef DEBUG
                    121:                if(outf) fprintf(outf, "prevhl %o, thishl %o\n", prevhl, thishl);
                    122: #endif
                    123:                leftoldc = oldc & A_ATTRIBUTES;
                    124:                leftnewc = p[-1] & A_ATTRIBUTES;
                    125:                diff_cookies = magic_cookie_glitch>=0 && (leftoldc != leftnewc);
                    126:                diff_attrs = ceol_standout_glitch>=0 && (((*p)&A_ATTRIBUTES) != leftnewc);
                    127:                if (oldp >= tailoldp)
                    128:                        oldc = ' ';
                    129:                else
                    130:                        oldc = *oldp;
                    131: #ifdef DEBUG
                    132:                if(outf) fprintf(outf, "p %x *p %o, pc %x *pc %o, oldp %x, *oldp %o, lcol %d, lrow %d, oldc %o\n", p, *p, pc, *pc, oldp, *oldp, lcol, lrow, oldc);
                    133: #endif
                    134:                if (*p != oldc || SP->virt_irm == 1 || diff_cookies || diff_attrs ||
                    135:                                insert_null_glitch && oldp >= oldline+oldlen) {
                    136:                        register int n;
                    137: 
                    138:                        _pos(lrow, lcol);
                    139: 
                    140:                        /*
                    141:                         * HP 2645/2626: output new for each char.
                    142:                         * This forces it to be right no matter what
                    143:                         * was there before.
                    144:                         */
                    145:                        if (ceol_standout_glitch && thishl == 0 && oldc&A_ATTRIBUTES) {
                    146: #ifdef FULLDEBUG
                    147:                                if(outf) fprintf(outf,
                    148:                                        "ceol %d, thishl %d, prevhl %d\n",
                    149:                                        ceol_standout_glitch, thishl, prevhl);
                    150: #endif
                    151:                                _forcehl();
                    152:                        }
                    153: 
                    154:                        /* Force highlighting to be right */
                    155:                        _hlmode(thishl);
                    156:                        if (thishl != prevhl) {
                    157:                                if (magic_cookie_glitch >= 0) {
                    158:                                        _sethl();
                    159:                                        p += magic_cookie_glitch;
                    160:                                        oldp += magic_cookie_glitch;
                    161:                                        pc += magic_cookie_glitch;
                    162:                                        lcol += magic_cookie_glitch;
                    163:                                }
                    164:                        }
                    165: 
                    166:                        /*
                    167:                         * Gather chunks of chars together, to be more
                    168:                         * efficient, and to allow repeats to be detected.
                    169:                         * Not done for blanks on cookie terminals because
                    170:                         * the last one might be a cookie.
                    171:                         */
                    172:                        if (magic_cookie_glitch<0 || *pc != ' ') {
                    173:                                for (px=p+1,oldpx=oldp+1;
                    174:                                        px<=last && *p==*px;
                    175:                                        px++,oldpx++) {
                    176:                                        if(!(repeat_char && oldpx<tailoldp && *p==*oldpx))
                    177:                                                break;
                    178:                                }
                    179:                                px--; oldpx--;
                    180:                                n = px - p;
                    181:                                pcx = pc + n;
                    182:                        } else {
                    183:                                n = 0;
                    184:                                pcx = pc;
                    185:                        }
                    186:                        _writechars(pc, pcx);
                    187:                        lcol += n; pc += n; p += n; oldp += n;
                    188:                        prevhl = thishl;
                    189:                }
                    190:                lcol++;
                    191:        }
                    192:        if (magic_cookie_glitch >= 0 && prevhl) {
                    193:                /* Have to turn off highlighting at end of line */
                    194:                _hlmode(0);
                    195:                _sethl();
                    196:        }
                    197: }

unix.superglobalmegacorp.com

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