--- rxvt-unicode/src/screen.C 2005/12/20 21:49:55 1.177 +++ rxvt-unicode/src/screen.C 2005/12/27 01:25:42 1.198 @@ -85,9 +85,6 @@ #define ROWCOL_IN_ROW_AT_OR_BEFORE(X, Y) \ ROW_AND_COL_IN_ROW_AT_OR_BEFORE ((X).row, (X).col, (Y).row, (Y).col) -#define LINENO(n) (((n) + term_start + total_rows) % total_rows) -#define ROW(n) (save [LINENO (n)]) - /* * CLEAR_ROWS : clear rows starting from row * CLEAR_CHARS: clear chars starting from pixel position @@ -152,12 +149,10 @@ /* ------------------------------------------------------------------------- * * SCREEN INITIALISATION * * ------------------------------------------------------------------------- */ + void rxvt_term::scr_reset () { - unsigned int p, q; - int k; - #if ENABLE_OVERLAY scr_overlay_off (); #endif @@ -177,6 +172,7 @@ // we need at least two lines for wrapping to work correctly if (nrow + saveLines < 2) { + //TODO//FIXME saveLines++; prev_nrow--; nsaved++; @@ -190,7 +186,7 @@ screen.tscroll = 0; screen.bscroll = nrow - 1; - if (!save) + if (!row_buf) { /* * first time called so just malloc everything: don't rely on realloc @@ -202,16 +198,16 @@ talloc = new rxvt_salloc (ncol * sizeof (text_t)); ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); - save = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); - buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); - drawn = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); - swap_save = (line_t *)rxvt_calloc (nrow, sizeof (line_t)); - - for (p = nrow; p--; ) - { - scr_blank_screen_mem (ROW(p), DEFAULT_RSTYLE); - scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); - scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE); + row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); + temp_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); + drawn_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); + swap_buf = (line_t *)rxvt_calloc (nrow , sizeof (line_t)); + + for (int row = nrow; row--; ) + { + scr_blank_screen_mem (ROW (row), DEFAULT_RSTYLE); + scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); + scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); } memset (charsets, 'B', sizeof (charsets)); @@ -245,182 +241,171 @@ * add or delete rows as appropriate */ - rxvt_salloc *old_ta; - rxvt_salloc *old_ra; + rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t)); + rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); +#if 0 if (nrow < prev_nrow) { - /* delete rows */ - k = min (nsaved, prev_nrow - nrow); - // k = max (0, - ( (nrow - 1) - r->screen.cur.row)); // mmc's http://maruska.dyndns.org/wiki/scrolling-bug //make configurable? //D TODO - scr_scroll_text (0, (int)prev_nrow - 1, k); - - for (p = nrow; p < prev_nrow; p++) + for (int row = nrow; row < prev_nrow; row++) { - lfree (ROW(p)); - lfree (swap_save[p]); - lfree (drawn[p]); + lfree (swap_buf [row]); + lfree (drawn_buf[row]); } - - /* we have fewer rows so fix up cursor position */ - MIN_IT (screen.cur.row, (int32_t)nrow - 1); - - scr_reset_realloc (); /* realloc _last_ */ } - else if (nrow > prev_nrow) - { - /* add rows */ - scr_reset_realloc (); /* realloc _first_ */ - - int ocol = ncol; - ncol = prev_ncol; // save b/c scr_blank_screen_mem uses this - - k = min (nsaved, nrow - prev_nrow); - - for (p = prev_total_rows; p < total_rows; p++) - save[p].clear (); - - for (p = prev_total_rows; p < total_rows - k; p++) - scr_blank_screen_mem (save[p], DEFAULT_RSTYLE); - - for (p = prev_nrow; p < nrow; p++) - { - swap_save[p].clear (); scr_blank_screen_mem (swap_save[p], DEFAULT_RSTYLE); - drawn[p].clear (); scr_blank_screen_mem (drawn[p], DEFAULT_RSTYLE); - } +#endif - if (k > 0) - { - scr_scroll_text (0, (int)nrow - 1, -k); - screen.cur.row += k; - screen.s_cur.row += k; - nsaved -= k; - } + drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); + temp_buf = (line_t *)rxvt_realloc (temp_buf , nrow * sizeof (line_t)); + swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t)); -#ifdef DEBUG_STRICT - assert (screen.cur.row < nrow); -#else /* drive with your eyes closed */ - MIN_IT (screen.cur.row, nrow - 1); -#endif - ncol = ocol; // save b/c scr_blank_screen_mem uses this + for (int row = min (nrow, prev_nrow); row--; ) + { + lresize (drawn_buf[row]); + lresize (swap_buf [row]); } - /* resize columns */ - if (ncol != prev_ncol) + for (int row = prev_nrow; row < nrow; row++) { - old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t)); - old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); - - for (p = total_rows; p--; ) - lresize (save[p]); - - for (p = nrow; p--; ) - { - lresize (drawn[p]); - lresize (swap_save[p]); - } - - MIN_IT (screen.cur.col, (int16_t)ncol - 1); - - delete old_ta; - delete old_ra; + swap_buf [row].clear (); scr_blank_screen_mem (swap_buf [row], DEFAULT_RSTYLE); + drawn_buf[row].clear (); scr_blank_screen_mem (drawn_buf[row], DEFAULT_RSTYLE); } -#if 0 - // re-wrap lines, this is rather ugly, possibly because I am too dumb - // to come up with a lean and mean algorithm. - rxvt_salloc *ta = new rxvt_salloc (ncol * sizeof (text_t)); - rxvt_salloc *ra = new rxvt_salloc (ncol * sizeof (rend_t)); - - text_t **tp = (text_t **)rxvt_calloc (total_rows, sizeof (text_t *)); - rend_t **rp = (rend_t **)rxvt_calloc (total_rows, sizeof (rend_t *)); - tlen_t *tl = (tlen_t *) rxvt_calloc (total_rows, sizeof (tlen_t)); - - for (p = 0; p < prev_total_rows; p++) printf ("P %p %d\n", save[p].t, save[p].l);//D - - p = prev_total_rows; - q = total_rows; + line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); + + int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row + int pend = MOD (term_start - nsaved , prev_total_rows); + int q = total_rows; // rewrapped row - while (p > 0 && q > 0) + if (nsaved) { - --p; + // re-wrap lines, this is rather ugly, possibly because I am too dumb + // to come up with a lean and mean algorithm. - printf ("pq %d:%d\n", p, q); - if (save[p].t) + row_col_t ocur = screen.cur; + ocur.row = MOD (term_start + ocur.row, prev_total_rows); + + do { - int llen = save[p].l; + p = MOD (p - 1, prev_total_rows); +#ifdef DEBUG_STRICT + assert (old_buf [MOD (p, prev_total_rows)].t); +#endif - assert (llen >= 0); + int plines = 1; + int llen = old_buf [MOD (p, prev_total_rows)].l; - while (p && save[p - 1].l < 0) + while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) { - --p; + p = MOD (p - 1, prev_total_rows); + + plines++; llen += prev_ncol; } - int qlines = llen / ncol + 1; - int lofs = 0; + int qlines = max (0, (llen - 1) / ncol) + 1; + + // drop partial lines completely + if (q < qlines) + break; q -= qlines; - int qrow = q; + int lofs = 0; + line_t *qline; - printf ("QL %d llen %d\n", qlines, llen);//D - for (; qlines--; qrow++) + // re-assemble the full line by destination lines + for (int qrow = q; qlines--; qrow++) { - if (qrow >= 0) - { - tp [qrow] = (text_t *)ta->alloc (); - rp [qrow] = (rend_t *)ra->alloc (); - tl [qrow] = LINE_CONT1; - - int qcol = 0; + qline = row_buf + qrow; + lalloc (*qline); + qline->set_is_longer (); - for (;;) - { - int prow = lofs / prev_ncol + p; - int pcol = lofs % prev_ncol; + int qcol = 0; - int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); - - printf ("q %d lofs %d>%d len %d pq %d:%d p %d:%d q :%d\n", q, llen, lofs, len, prev_ncol, ncol, prow, pcol, qcol); + // fill a single destination line + while (lofs < llen && qcol < ncol) + { + int prow = lofs / prev_ncol; + int pcol = lofs % prev_ncol; - if (len <= 0) - { - tl [qrow] = qcol; + prow = MOD (p + prow, prev_total_rows); - TODO - scr_blank_line (tp [qrow] + qcol, rp [qrow] + qcol, - ncol - qcol, DEFAULT_RSTYLE); + // we only adjust the cursor _row_ and put it into + // the topmost line of "long line" it was in, as + // this seems to upset applications/shells/readline + // least. + if (prow == ocur.row) + screen.cur.row = q - (total_rows - nrow); - break; - } + line_t &pline = old_buf [prow]; - assert (lofs < 1000); + int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); - memcpy (tp [qrow] + qcol, save[prow].t + pcol, len * sizeof (text_t)); - memcpy (rp [qrow] + qcol, save[prow].r + pcol, len * sizeof (rend_t)); + assert (len); + assert (pline.t); - lofs += len; - qcol += len; + memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); + memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); - if (qcol == ncol) - break; - } + lofs += len; + qcol += len; } - else - lofs += ncol; } + + qline->l = llen ? MOD (llen - 1, ncol) + 1 : 0; +#ifdef DEBUG_STRICT //TODO//FIXME//TEMPORARY + if (qline->l < 0) + { + fprintf (stderr, "ERROR, PLEASE REPORT to rxvt-unicode@plan9.de: qline->l %d = llen %d < ncol %d ? %d : MOD %d\n", qline->l,llen,ncol,llen,MOD (llen - 1, ncol) + 1);//D + qline->l = 0; + } +#endif + scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); } + while (p != pend && q > 0); + + term_start = total_rows - nrow; + nsaved = term_start - q; + + // make sure all terminal lines exist + while (nsaved < 0) + scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); + } + else + { + // if no scrollback exists (yet), wing, instead of wrap + + for (int row = min (nrow, prev_nrow); row--; ) + { + line_t &pline = old_buf [MOD (term_start + row, prev_total_rows)]; + line_t &qline = row_buf [row]; - free (screen.text); screen.text = tp; - free (screen.rend); screen.rend = rp; - free (screen.tlen); screen.tlen = tl; + qline = pline; + lresize (qline); + } - for (p = 0; p < total_rows; p++) printf ("P %p %d\n", save[p].t, save[p].l);//D + for (int row = prev_nrow; row < nrow; row++) + { + row_buf [row].clear (); scr_blank_screen_mem (row_buf [row], DEFAULT_RSTYLE); + } + + term_start = 0; + } + +#ifdef DEBUG_STRICT //TODO: remove + for (int i = -nsaved; i < nrow; i++) + assert (ROW (i).t); #endif + free (old_buf); + delete old_ta; + delete old_ra; + + clamp_it (screen.cur.row, 0, nrow - 1); + clamp_it (screen.cur.col, 0, ncol - 1); + if (tabs) free (tabs); } @@ -430,21 +415,12 @@ tabs = (char *)rxvt_malloc (ncol * sizeof (char)); - for (p = 0; p < ncol; p++) - tabs[p] = (p % TABSIZE == 0) ? 1 : 0; + for (int col = ncol; col--; ) + tabs [col] = col % TABSIZE == 0; tt_winch (); } -void -rxvt_term::scr_reset_realloc () -{ - swap_save = (line_t *) rxvt_realloc (swap_save , nrow * sizeof (line_t)); - drawn = (line_t *) rxvt_realloc (drawn , nrow * sizeof (line_t)); - buf = (line_t *) rxvt_realloc (buf , nrow * sizeof (line_t)); - save = (line_t *) rxvt_realloc (save , total_rows * sizeof (line_t)); -} - /* ------------------------------------------------------------------------- */ /* * Free everything. That way malloc debugging can find leakage. @@ -455,11 +431,13 @@ delete talloc; talloc = 0; delete ralloc; ralloc = 0; - free (save); - free (swap_save); - free (drawn); - free (buf); + free (row_buf); + free (swap_buf); + free (drawn_buf); + free (temp_buf); free (tabs); + + row_buf = 0; // signal that we freed all the arrays } /* ------------------------------------------------------------------------- */ @@ -520,14 +498,11 @@ } /* boundary check in case screen size changed between SAVE and RESTORE */ - MIN_IT (s->cur.row, nrow - 1); - MIN_IT (s->cur.col, ncol - 1); + min_it (s->cur.row, nrow - 1); + min_it (s->cur.col, ncol - 1); #ifdef DEBUG_STRICT assert (s->cur.row >= 0); assert (s->cur.col >= 0); -#else /* drive with your eyes closed */ - MAX_IT (s->cur.row, 0); - MAX_IT (s->cur.col, 0); #endif } @@ -548,25 +523,24 @@ selection_check (2); /* check for boundary cross */ - SWAP_IT (scrn, current_screen, int); + int i = current_screen; current_screen = scrn; scrn = i; + + ::swap (screen.cur.row, swap.cur.row); + ::swap (screen.cur.col, swap.cur.col); - SWAP_IT (screen.cur.row, swap.cur.row, int16_t); - SWAP_IT (screen.cur.col, swap.cur.col, int16_t); - MAX_IT (screen.cur.row, 0); - MIN_IT (screen.cur.row, (int32_t)prev_nrow - 1); - MAX_IT (screen.cur.col, 0); - MIN_IT (screen.cur.col, (int32_t)prev_ncol - 1); + screen.cur.row = clamp (screen.cur.row, 0, prev_nrow - 1); + screen.cur.col = clamp (screen.cur.col, 0, prev_ncol - 1); #if NSCREENS if (options & Opt_secondaryScreen) { num_scr = 0; - for (int i = nrow; i--; ) - SWAP_IT (ROW(i), swap_save[i], line_t); + for (int i = prev_nrow; i--; ) + ::swap (ROW(i), swap_buf [i]); - SWAP_IT (screen.charset, swap.charset, int16_t); - SWAP_IT (screen.flags, swap.flags, int); + ::swap (screen.charset, swap.charset); + ::swap (screen.flags, swap.flags); screen.flags |= Screen_VisibleCursor; swap.flags |= Screen_VisibleCursor; } @@ -655,11 +629,20 @@ selection.end.row -= count; selection.mark.row -= count; - selection_check (0); + if (selection.beg.row < -nsaved + || selection.end.row < -nsaved + || selection.mark.row < -nsaved) + { + CLEAR_ALL_SELECTION (); + selection.op = SELECTION_CLEAR; + } } for (int i = count; i--; ) - scr_blank_screen_mem (ROW(row2 - i), rstyle); + { + ROW(row2 - i).l = 0; + scr_blank_screen_mem (ROW(row2 - i), rstyle); + } if ((options & Opt_scrollWithBuffer) && view_start != 0 @@ -670,20 +653,17 @@ { if (selection.op && current_screen == selection.screen) { - int i = selection.beg.row; - int j = selection.end.row; - - if ((i < row1 && j > row1) - || (i < row2 && j > row2) - || (i - count < row1 && i >= row1) - || (i - count > row2 && i <= row2) - || (j - count < row1 && j >= row1) - || (j - count > row2 && j <= row2)) + if ((selection.beg.row < row1 && selection.end.row > row1) + || (selection.beg.row < row2 && selection.end.row > row2) + || (selection.beg.row - count < row1 && selection.beg.row >= row1) + || (selection.beg.row - count > row2 && selection.beg.row <= row2) + || (selection.end.row - count < row1 && selection.end.row >= row1) + || (selection.end.row - count > row2 && selection.end.row <= row2)) { CLEAR_ALL_SELECTION (); - selection.op = SELECTION_CLEAR; /* XXX: too aggressive? */ + selection.op = SELECTION_CLEAR; } - else if (j >= row1 && j <= row2) + else if (selection.end.row >= row1 && selection.end.row <= row2) { /* move selected region too */ selection.beg.row -= count; @@ -699,16 +679,18 @@ int rows = row2 - row1 + 1; + min_it (count, rows); + for (int row = 0; row < rows; row++) { - buf [row] = ROW(row1 + (row + count + rows) % rows); + temp_buf [row] = ROW(row1 + (row + count + rows) % rows); if (!IN_RANGE_EXC (row + count, 0, rows)) - scr_blank_screen_mem (buf [row], rstyle); + scr_blank_screen_mem (temp_buf [row], rstyle); } for (int row = 0; row < rows; row++) - ROW(row1 + row) = buf [row]; + ROW(row1 + row) = temp_buf [row]; } return count; @@ -726,7 +708,7 @@ unsigned char checksel; unicode_t c; - int row, last_col; + int last_col; const unicode_t *strend = str + len; want_refresh = 1; @@ -736,9 +718,9 @@ if (nlines > 0) { nlines += screen.cur.row - screen.bscroll; - if ((nlines > 0) - && (screen.tscroll == 0) - && (screen.bscroll == (nrow - 1))) + if (nlines > 0 + && screen.tscroll == 0 + && screen.bscroll == (nrow - 1)) { /* _at least_ this many lines need to be scrolled */ scr_scroll_text (screen.tscroll, screen.bscroll, nlines); @@ -748,14 +730,10 @@ #ifdef DEBUG_STRICT assert (screen.cur.col < last_col); - assert ((screen.cur.row < nrow) - && (screen.cur.row >= - (int32_t)nsaved)); -#else /* drive with your eyes closed */ - MIN_IT (screen.cur.col, last_col - 1); - MIN_IT (screen.cur.row, (int32_t)nrow - 1); - MAX_IT (screen.cur.row, - (int32_t)nsaved); + assert (screen.cur.row < nrow + && screen.cur.row >= -nsaved); #endif - row = screen.cur.row; + int row = screen.cur.row; checksel = selection.op && current_screen == selection.screen ? 1 : 0; @@ -767,9 +745,9 @@ if (c < 0x20) if (c == C0_LF) - { + { if (!line->is_longer ()) /* XXX: think about this */ - MAX_IT (line->l, screen.cur.col); + max_it (line->l, screen.cur.col); screen.flags &= ~Screen_WrapNext; @@ -784,7 +762,7 @@ else if (c == C0_CR) { if (!line->is_longer ()) /* XXX: think about this */ - MAX_IT (line->l, screen.cur.col); + max_it (line->l, screen.cur.col); screen.flags &= ~Screen_WrapNext; screen.cur.col = 0; @@ -970,12 +948,10 @@ } if (!line->is_longer ()) /* XXX: think about this */ - MAX_IT (line->l, screen.cur.col); + max_it (line->l, screen.cur.col); #ifdef DEBUG_STRICT assert (screen.cur.row >= 0); -#else /* drive with your eyes closed */ - MAX_IT (screen.cur.row, 0); #endif } @@ -1024,9 +1000,7 @@ return; else if (count > 0) { - int row = screen.cur.row; - - line_t &l = ROW(row); + line_t &l = ROW(screen.cur.row); rend_t base_rend = l.r[i]; ht &= l.t[i] == ' '; @@ -1051,7 +1025,7 @@ base_rend = SET_FONT (base_rend, 0); if (!l.is_longer ()) /* XXX: think about this */ - MAX_IT (l.l, x); + max_it (l.l, x); i = screen.cur.col; @@ -1111,16 +1085,12 @@ void rxvt_term::scr_forwardindex () { - int row; - if (screen.cur.col < ncol - 1) scr_gotorc (0, 1, R_RELATIVE | C_RELATIVE); else { - row = screen.cur.row; - - if (ROW(row).is_longer ()) //TODO//FIXME//LEN - ROW(row).l = ncol; + if (ROW(screen.cur.row).is_longer ()) //TODO//FIXME//LEN + ROW(screen.cur.row).l = ncol; scr_gotorc (0, 0, R_RELATIVE); scr_insdel_chars (1, DELETE); @@ -1140,8 +1110,7 @@ ZERO_SCROLLBACK (); screen.cur.col = relative & C_RELATIVE ? screen.cur.col + col : col; - MAX_IT (screen.cur.col, 0); - MIN_IT (screen.cur.col, (int32_t)ncol - 1); + clamp_it (screen.cur.col, 0, ncol - 1); screen.flags &= ~Screen_WrapNext; @@ -1169,14 +1138,13 @@ if (screen.flags & Screen_Relative) { /* relative origin mode */ screen.cur.row = row + screen.tscroll; - MIN_IT (screen.cur.row, screen.bscroll); + min_it (screen.cur.row, screen.bscroll); } else screen.cur.row = row; } - MAX_IT (screen.cur.row, 0); - MIN_IT (screen.cur.row, (int32_t)nrow - 1); + clamp_it (screen.cur.row, 0, nrow - 1); } /* ------------------------------------------------------------------------- */ @@ -1201,8 +1169,7 @@ else screen.cur.row += dirn; - MAX_IT (screen.cur.row, 0); - MIN_IT (screen.cur.row, (int32_t)nrow - 1); + clamp_it (screen.cur.row, 0, nrow - 1); selection_check (0); } @@ -1216,21 +1183,21 @@ void rxvt_term::scr_erase_line (int mode) { - unsigned int row, col, num; + unsigned int col, num; want_refresh = 1; ZERO_SCROLLBACK (); selection_check (1); - row = screen.cur.row; + line_t &line = ROW(screen.cur.row); switch (mode) { case 0: /* erase to end of line */ col = screen.cur.col; num = ncol - col; - MIN_IT (ROW(row).l, (int16_t)col); + min_it (line.l, col); if (ROWCOL_IN_ROW_AT_OR_AFTER (selection.beg, screen.cur) || ROWCOL_IN_ROW_AT_OR_AFTER (selection.end, screen.cur)) CLEAR_SELECTION (); @@ -1245,7 +1212,7 @@ case 2: /* erase whole line */ col = 0; num = ncol; - ROW(row).l = 0; + line.l = 0; if (selection.beg.row <= screen.cur.row && selection.end.row >= screen.cur.row) CLEAR_SELECTION (); @@ -1254,7 +1221,7 @@ return; } - scr_blank_line (ROW(row), col, num, rstyle); + scr_blank_line (line, col, num, rstyle); } /* ------------------------------------------------------------------------- */ @@ -1307,7 +1274,7 @@ if (row >= nrow) /* Out Of Bounds */ return; - MIN_IT (num, (nrow - row)); + min_it (num, nrow - row); if (rstyle & (RS_RVid | RS_Uline)) ren = (rend_t) ~RS_None; @@ -1328,9 +1295,9 @@ for (; num--; row++) { - scr_blank_screen_mem (ROW (row), rstyle); ROW (row).l = 0; - scr_blank_line (drawn[row], 0, ncol, ren); + scr_blank_screen_mem (ROW (row), rstyle); + scr_blank_line (drawn_buf [row], 0, ncol, ren); } } @@ -1425,7 +1392,7 @@ scr_do_wrap (); selection_check (1); - MIN_IT (count, (ncol - screen.cur.col)); + min_it (count, ncol - screen.cur.col); row = screen.cur.row; @@ -1443,7 +1410,7 @@ if (!line->is_longer ()) { line->l += count; - MIN_IT (line->l, ncol); + min_it (line->l, ncol); } if (selection.op && current_screen == selection.screen @@ -1514,8 +1481,8 @@ void rxvt_term::scr_scroll_region (int top, int bot) { - MAX_IT (top, 0); - MIN_IT (bot, (int)nrow - 1); + max_it (top, 0); + min_it (bot, nrow - 1); if (top > bot) return; @@ -1623,7 +1590,7 @@ if (rvideo != mode) { rvideo = mode; - SWAP_IT (pix_colors[Color_fg], pix_colors[Color_bg], rxvt_color); + ::swap (pix_colors[Color_fg], pix_colors[Color_bg]); #if XPM_BACKGROUND if (bgPixmap.pixmap == None) #endif @@ -1729,7 +1696,7 @@ for (int i = 0; i < nrow; i++) { int col = 0; - rend_t *drp = drawn[i].r; + rend_t *drp = drawn_buf[i].r; for (; col < ncol; col++, drp++) if ((*drp & mask) == value) @@ -1757,7 +1724,7 @@ int i; row_col_t rc[RC_COUNT]; - if (!drawn) /* sanity check */ + if (!drawn_buf) /* sanity check */ return; #ifndef NO_SLOW_LINK_SUPPORT @@ -1768,13 +1735,6 @@ } #endif -#ifdef DEBUG_STRICT - x = max (x, 0); - x = min (x, (int)width); - y = max (y, 0); - y = min (y, (int)height); -#endif - /* round down */ rc[PART_BEG].col = Pixel2Col (x); rc[PART_BEG].row = Pixel2Row (y); @@ -1785,12 +1745,12 @@ /* sanity checks */ for (i = PART_BEG; i < RC_COUNT; i++) { - MIN_IT (rc[i].col, ncol - 1); - MIN_IT (rc[i].row, nrow - 1); + min_it (rc[i].col, ncol - 1); + min_it (rc[i].row, nrow - 1); } for (i = rc[PART_BEG].row; i <= rc[PART_END].row; i++) - fill_text (&drawn[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); + fill_text (&drawn_buf[i].t[rc[PART_BEG].col], 0, rc[PART_END].col - rc[PART_BEG].col + 1); if (refresh) scr_refresh (SLOW_REFRESH); @@ -1963,8 +1923,7 @@ showcursor; /* show the cursor */ int16_t col, row, /* column/row we're processing */ ocrow; /* old cursor row */ - int i, /* tmp */ - row_offset; /* basic offset in screen structure */ + int i; /* tmp */ #ifndef NO_CURSORCOLOR rend_t cc1; /* store colours at cursor position (s) */ #endif @@ -1981,8 +1940,6 @@ must_clear = 0; refresh_count = 0; - row_offset = term_start - view_start; - #if XPM_BACKGROUND must_clear |= bgPixmap.pixmap != None; #endif @@ -2061,7 +2018,7 @@ { if (ocrow < nrow && oldcursor.col < ncol) - drawn[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); + drawn_buf[ocrow].r[oldcursor.col] ^= (RS_RVid | RS_Uline); if (focus || !showcursor) oldcursor.row = -1; @@ -2109,9 +2066,9 @@ { if (row + i >= 0 && row + i < nrow && row + i != ocrow) { - line_t s = save[(row + row_offset) % total_rows]; - line_t d = drawn[row]; - line_t d2 = drawn[row + i]; + line_t s = ROW(row - view_start); + line_t d = drawn_buf[row]; + line_t d2 = drawn_buf[row + i]; for (nits = 0, col = ncol; col--; ) if (s.t[col] != d2.t[col] || s.r[col] != d2.r[col]) @@ -2139,7 +2096,7 @@ { /* also comes here at end if needed because of >= above */ if (wlen < len) - SWAP_IT (wlen, len, int); + ::swap (wlen, len); XCopyArea (display->display, vt, vt, gc, 0, Row2Pixel (len + i), @@ -2157,10 +2114,10 @@ */ for (row = 0; row < nrow; row++) { - text_t *stp = save[(row + row_offset) % total_rows].t; - rend_t *srp = save[(row + row_offset) % total_rows].r; - text_t *dtp = drawn[row].t; - rend_t *drp = drawn[row].r; + text_t *stp = ROW(row - view_start).t; + rend_t *srp = ROW(row - view_start).r; + text_t *dtp = drawn_buf[row].t; + rend_t *drp = drawn_buf[row].r; /* * E2: OK, now the real pass @@ -2235,7 +2192,7 @@ int fore = GET_FGCOLOR (rend); // desired foreground int back = GET_BGCOLOR (rend); // desired background - // only do special processing if any attributes are set, which is rare + // only do special processing if any attributes are set, which is unlikely if (rend & (RS_Bold | RS_Italic | RS_Uline | RS_RVid | RS_Blink | RS_Careful)) { #if ENABLE_STYLES @@ -2281,7 +2238,7 @@ if (invert) { - SWAP_IT (fore, back, int); + ::swap (fore, back); #ifndef NO_BOLD_UNDERLINE_REVERSE if (ISSET_PIXCOLOR (Color_RV)) @@ -2383,7 +2340,7 @@ col--; while (col + cursorwidth < ncol - && drawn[oldcursor.row].t[col + cursorwidth] == NOCHAR) + && drawn_buf[oldcursor.row].t[col + cursorwidth] == NOCHAR) cursorwidth++; #ifndef NO_CURSORCOLOR @@ -2425,12 +2382,12 @@ rxvt_term::scr_remap_chars () { for (int i = total_rows; i--; ) - scr_remap_chars (save[i]); + scr_remap_chars (row_buf [i]); for (int i = nrow; i--; ) { - scr_remap_chars (drawn[i]); - scr_remap_chars (swap_save[i]); + scr_remap_chars (drawn_buf [i]); + scr_remap_chars (swap_buf [i]); } } @@ -2507,7 +2464,7 @@ else { col = 0; - row = view_start; + row = -view_start; } for (; row < min (selection.end.row, view_end); row++, col = 0) @@ -2537,16 +2494,16 @@ for (row = saveLines - nsaved; row < saveLines + nrow - 1; row++) { - width = save[row].l >= 0 ? save[row].l + width = row_buf[row].l >= 0 ? row_buf[row].l : ncol; for (towrite = width; towrite; towrite -= wrote) { - wrote = write (fd, & (save[row].t[width - towrite]), + wrote = write (fd, & (row_buf[row].t[width - towrite]), towrite); if (wrote < 0) return; /* XXX: death, no report */ } - if (save[row].l >= 0) + if (row_buf[row].l >= 0) if (write (fd, r1, 1) <= 0) return; /* XXX: death, no report */ } @@ -3033,8 +2990,8 @@ selection.mark.row = row - view_start; selection.mark.col = col; - selection.mark.row = min (max (selection.mark.row, -nsaved), nrow - 1); - selection.mark.col = min (max (selection.mark.col, 0), ncol - 1); + selection.mark.row = clamp (selection.mark.row, -nsaved, nrow - 1); + selection.mark.col = clamp (selection.mark.col, 0, ncol - 1); while (selection.mark.col > 0 && ROW(selection.mark.row).t[selection.mark.col] == NOCHAR) @@ -3149,8 +3106,8 @@ void rxvt_term::selection_extend (int x, int y, int flag) { - int col = min (max (Pixel2Col (x), 0), nrow - 1); - int row = min (max (Pixel2Row (y), 0), ncol); + int col = clamp (Pixel2Col (x), 0, ncol); + int row = clamp (Pixel2Row (y), 0, nrow - 1); /* * If we're selecting characters (single click) then we must check first @@ -3373,7 +3330,7 @@ #if ENABLE_FRILLS if (selection.rect && selection.beg.col > selection.end.col) - SWAP_IT (selection.beg.col, selection.end.col, int); + ::swap (selection.beg.col, selection.end.col); #endif } @@ -3581,9 +3538,9 @@ rxvt_term::pixel_position (int *x, int *y) { *x = Pixel2Col (*x); - /* MAX_IT (*x, 0); MIN_IT (*x, (int)ncol - 1); */ + /* max_it (*x, 0); min_it (*x, (int)ncol - 1); */ *y = Pixel2Row (*y); - /* MAX_IT (*y, 0); MIN_IT (*y, (int)nrow - 1); */ + /* max_it (*y, 0); min_it (*y, (int)nrow - 1); */ } /* ------------------------------------------------------------------------- */ @@ -3615,14 +3572,11 @@ if (y < 0) y = nrow - h; // make space for border - w += 2; MIN_IT (w, ncol); - h += 2; MIN_IT (h, nrow); - - x -= 1; MAX_IT (x, 0); - y -= 1; MAX_IT (y, 0); + w += 2; min_it (w, ncol); + h += 2; min_it (h, nrow); - MIN_IT (x, ncol - w); - MIN_IT (y, nrow - h); + x -= 1; clamp_it (x, 0, ncol - w); + y -= 1; clamp_it (y, 0, nrow - h); ov_x = x; ov_y = y; ov_w = w; ov_h = h; @@ -3724,8 +3678,8 @@ text_t *t1 = ov_text[y]; rend_t *r1 = ov_rend[y]; - text_t *t2 = ROW(y - view_start).t + ov_x; - rend_t *r2 = ROW(y - view_start).r + ov_x; + text_t *t2 = ROW(y + ov_y - view_start).t + ov_x; + rend_t *r2 = ROW(y + ov_y - view_start).r + ov_x; for (int x = ov_w; x--; ) {