… | |
… | |
239 | { |
239 | { |
240 | /* |
240 | /* |
241 | * add or delete rows as appropriate |
241 | * add or delete rows as appropriate |
242 | */ |
242 | */ |
243 | |
243 | |
244 | printf ("resize %d:%d => %d:%d\n", prev_nrow, prev_ncol, nrow, ncol);//D |
|
|
245 | |
|
|
246 | rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t)); |
244 | rxvt_salloc *old_ta = talloc; talloc = new rxvt_salloc (ncol * sizeof (text_t)); |
247 | rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); |
245 | rxvt_salloc *old_ra = ralloc; ralloc = new rxvt_salloc (ncol * sizeof (rend_t)); |
248 | |
246 | |
249 | #if 0 |
247 | #if 0 |
250 | if (nrow < prev_nrow) |
248 | if (nrow < prev_nrow) |
… | |
… | |
255 | lfree (drawn_buf[row]); |
253 | lfree (drawn_buf[row]); |
256 | } |
254 | } |
257 | } |
255 | } |
258 | #endif |
256 | #endif |
259 | |
257 | |
260 | drawn_buf = (line_t *) rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); |
258 | drawn_buf = (line_t *)rxvt_realloc (drawn_buf, nrow * sizeof (line_t)); |
261 | temp_buf = (line_t *) rxvt_realloc (temp_buf , nrow * sizeof (line_t)); |
259 | temp_buf = (line_t *)rxvt_realloc (temp_buf , nrow * sizeof (line_t)); |
262 | swap_buf = (line_t *) rxvt_realloc (swap_buf , nrow * sizeof (line_t)); |
260 | swap_buf = (line_t *)rxvt_realloc (swap_buf , nrow * sizeof (line_t)); |
263 | |
261 | |
264 | for (int row = min (nrow, prev_nrow); row--; ) |
262 | for (int row = min (nrow, prev_nrow); row--; ) |
265 | { |
263 | { |
266 | lresize (drawn_buf[row]); |
264 | lresize (drawn_buf[row]); |
267 | lresize (swap_buf [row]); |
265 | lresize (swap_buf [row]); |
… | |
… | |
276 | line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); |
274 | line_t *old_buf = row_buf; row_buf = (line_t *)rxvt_calloc (total_rows, sizeof (line_t)); |
277 | |
275 | |
278 | // re-wrap lines, this is rather ugly, possibly because I am too dumb |
276 | // re-wrap lines, this is rather ugly, possibly because I am too dumb |
279 | // to come up with a lean and mean algorithm. |
277 | // to come up with a lean and mean algorithm. |
280 | |
278 | |
281 | int p = MOD (term_start + nrow , prev_total_rows); // previous row |
279 | int p = MOD (term_start + prev_nrow, prev_total_rows); // previous row |
282 | int pend = MOD (term_start - nsaved, prev_total_rows); |
280 | int pend = MOD (term_start - nsaved , prev_total_rows); |
283 | int q = total_rows; // rewrapped row |
281 | int q = total_rows; // rewrapped row |
284 | |
282 | |
285 | while (p != pend && q > 0) |
283 | while (p != pend && q > 0) |
286 | { |
284 | { |
287 | p = MOD (p - 1, prev_total_rows); |
285 | p = MOD (p - 1, prev_total_rows); |
288 | |
286 | #ifdef DEBUG_STRICT |
289 | assert (old_buf [MOD (p, prev_total_rows)].t); |
287 | assert (old_buf [MOD (p, prev_total_rows)].t); |
290 | assert (!old_buf [MOD (p, prev_total_rows)].is_longer ()); |
288 | #endif |
291 | |
289 | |
292 | int llen = old_buf [MOD (p, prev_total_rows)].l; |
290 | int llen = old_buf [MOD (p, prev_total_rows)].l; |
293 | |
291 | |
294 | while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) |
292 | while (p != pend && old_buf [MOD (p - 1, prev_total_rows)].is_longer ()) |
295 | { |
293 | { |
296 | p = MOD (p - 1, prev_total_rows); |
294 | p = MOD (p - 1, prev_total_rows); |
297 | |
295 | |
298 | llen += prev_ncol; |
296 | llen += prev_ncol; |
299 | } |
297 | } |
300 | |
298 | |
301 | int qlines = llen / ncol + 1; |
299 | int qlines = max (0, (llen - 1) / ncol) + 1; |
|
|
300 | |
|
|
301 | // drop partial lines completely |
|
|
302 | if (q < qlines) |
|
|
303 | break; |
|
|
304 | |
|
|
305 | q -= qlines; |
|
|
306 | |
302 | int lofs = 0; |
307 | int lofs = 0; |
|
|
308 | line_t *qline; |
303 | |
309 | |
304 | q -= qlines; |
310 | // re-assemble the full line by destination lines |
305 | |
|
|
306 | int qrow = q; |
|
|
307 | |
|
|
308 | for (; qlines--; qrow++) |
311 | for (int qrow = q; qlines--; qrow++) |
309 | { |
312 | { |
310 | if (qrow >= 0) |
313 | qline = row_buf + qrow; |
|
|
314 | lalloc (*qline); |
|
|
315 | qline->set_is_longer (); |
|
|
316 | |
|
|
317 | int qcol = 0; |
|
|
318 | |
|
|
319 | // fill a single destination line |
|
|
320 | while (lofs < llen && qcol < ncol) |
311 | { |
321 | { |
312 | line_t &qline = row_buf [qrow]; |
|
|
313 | |
|
|
314 | lalloc (qline); |
|
|
315 | qline.set_is_longer (); |
|
|
316 | |
|
|
317 | int qcol = 0; |
|
|
318 | |
|
|
319 | for (;;) |
|
|
320 | { |
|
|
321 | int prow = lofs / prev_ncol + p; |
322 | int prow = lofs / prev_ncol; |
322 | int pcol = lofs % prev_ncol; |
323 | int pcol = lofs % prev_ncol; |
323 | |
324 | |
324 | line_t &pline = old_buf [p]; |
325 | line_t &pline = old_buf [MOD (p + prow, prev_total_rows)]; |
325 | |
326 | |
326 | int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); |
327 | int len = min (min (prev_ncol - pcol, ncol - qcol), llen - lofs); |
327 | |
328 | |
328 | 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); |
|
|
329 | |
|
|
330 | if (len <= 0) |
|
|
331 | { |
|
|
332 | qline.l = qcol; |
|
|
333 | scr_blank_line (qline, qcol, ncol - qcol, DEFAULT_RSTYLE); |
|
|
334 | break; |
|
|
335 | } |
|
|
336 | |
|
|
337 | assert (lofs < 1000); |
329 | assert (len); |
|
|
330 | assert (pline.t); |
338 | |
331 | |
339 | memcpy (qline.t + qcol, pline.t + pcol, len * sizeof (text_t)); |
332 | memcpy (qline->t + qcol, pline.t + pcol, len * sizeof (text_t)); |
340 | memcpy (qline.r + qcol, pline.r + pcol, len * sizeof (rend_t)); |
333 | memcpy (qline->r + qcol, pline.r + pcol, len * sizeof (rend_t)); |
341 | |
334 | |
342 | lofs += len; |
335 | lofs += len; |
343 | qcol += len; |
336 | qcol += len; |
344 | |
|
|
345 | if (qcol == ncol) |
|
|
346 | break; |
|
|
347 | } |
|
|
348 | } |
337 | } |
349 | else |
|
|
350 | lofs += ncol; |
|
|
351 | } |
338 | } |
|
|
339 | |
|
|
340 | qline->l = llen < ncol ? llen : MOD (llen - 1, ncol) + 1; |
|
|
341 | scr_blank_line (*qline, qline->l, ncol - qline->l, DEFAULT_RSTYLE); |
352 | } |
342 | } |
|
|
343 | |
|
|
344 | term_start = total_rows - nrow; |
|
|
345 | view_start = 0; |
|
|
346 | nsaved = term_start - q; |
|
|
347 | |
|
|
348 | // make sure all terminal lines exist |
|
|
349 | while (nsaved < 0) |
|
|
350 | scr_blank_screen_mem (ROW (-++nsaved), DEFAULT_RSTYLE); |
|
|
351 | |
|
|
352 | for (int i = -nsaved; i < nrow; i++) |
|
|
353 | assert (ROW (i).t);//D |
353 | |
354 | |
354 | free (old_buf); |
355 | free (old_buf); |
355 | delete old_ta; |
356 | delete old_ta; |
356 | delete old_ra; |
357 | delete old_ra; |
357 | |
358 | |
… | |
… | |
386 | free (row_buf); |
387 | free (row_buf); |
387 | free (swap_buf); |
388 | free (swap_buf); |
388 | free (drawn_buf); |
389 | free (drawn_buf); |
389 | free (temp_buf); |
390 | free (temp_buf); |
390 | free (tabs); |
391 | free (tabs); |
|
|
392 | |
|
|
393 | row_buf = 0; // signal that we freed all the arrays |
391 | } |
394 | } |
392 | |
395 | |
393 | /* ------------------------------------------------------------------------- */ |
396 | /* ------------------------------------------------------------------------- */ |
394 | /* |
397 | /* |
395 | * Hard reset |
398 | * Hard reset |
… | |
… | |
451 | min_it (s->cur.row, nrow - 1); |
454 | min_it (s->cur.row, nrow - 1); |
452 | min_it (s->cur.col, ncol - 1); |
455 | min_it (s->cur.col, ncol - 1); |
453 | #ifdef DEBUG_STRICT |
456 | #ifdef DEBUG_STRICT |
454 | assert (s->cur.row >= 0); |
457 | assert (s->cur.row >= 0); |
455 | assert (s->cur.col >= 0); |
458 | assert (s->cur.col >= 0); |
456 | #else /* drive with your eyes closed */ |
|
|
457 | max_it (s->cur.row, 0); |
|
|
458 | max_it (s->cur.col, 0); |
|
|
459 | #endif |
459 | #endif |
460 | } |
460 | } |
461 | |
461 | |
462 | /* ------------------------------------------------------------------------- */ |
462 | /* ------------------------------------------------------------------------- */ |
463 | /* |
463 | /* |
… | |
… | |
677 | |
677 | |
678 | #ifdef DEBUG_STRICT |
678 | #ifdef DEBUG_STRICT |
679 | assert (screen.cur.col < last_col); |
679 | assert (screen.cur.col < last_col); |
680 | assert (screen.cur.row < nrow |
680 | assert (screen.cur.row < nrow |
681 | && screen.cur.row >= -nsaved); |
681 | && screen.cur.row >= -nsaved); |
682 | #else /* drive with your eyes closed */ |
|
|
683 | min_it (screen.cur.col, last_col - 1); |
|
|
684 | clamp_it (screen.cur.row, -nsaved, nrow - 1); |
|
|
685 | #endif |
682 | #endif |
686 | row = screen.cur.row; |
683 | row = screen.cur.row; |
687 | |
684 | |
688 | checksel = selection.op && current_screen == selection.screen ? 1 : 0; |
685 | checksel = selection.op && current_screen == selection.screen ? 1 : 0; |
689 | |
686 | |
… | |
… | |
900 | if (!line->is_longer ()) /* XXX: think about this */ |
897 | if (!line->is_longer ()) /* XXX: think about this */ |
901 | max_it (line->l, screen.cur.col); |
898 | max_it (line->l, screen.cur.col); |
902 | |
899 | |
903 | #ifdef DEBUG_STRICT |
900 | #ifdef DEBUG_STRICT |
904 | assert (screen.cur.row >= 0); |
901 | assert (screen.cur.row >= 0); |
905 | #else /* drive with your eyes closed */ |
|
|
906 | max_it (screen.cur.row, 0); |
|
|
907 | #endif |
902 | #endif |
908 | } |
903 | } |
909 | |
904 | |
910 | /* ------------------------------------------------------------------------- */ |
905 | /* ------------------------------------------------------------------------- */ |
911 | /* |
906 | /* |
… | |
… | |
1691 | y = 0; |
1686 | y = 0; |
1692 | eheight = height; |
1687 | eheight = height; |
1693 | } |
1688 | } |
1694 | #endif |
1689 | #endif |
1695 | |
1690 | |
1696 | #ifdef DEBUG_STRICT |
|
|
1697 | #if 0 |
|
|
1698 | // that's not debugging //TODO //FIXME |
|
|
1699 | clamp_it (x, 0, width); |
|
|
1700 | clamp_it (y, 0, height); |
|
|
1701 | #endif |
|
|
1702 | #endif |
|
|
1703 | |
|
|
1704 | /* round down */ |
1691 | /* round down */ |
1705 | rc[PART_BEG].col = Pixel2Col (x); |
1692 | rc[PART_BEG].col = Pixel2Col (x); |
1706 | rc[PART_BEG].row = Pixel2Row (y); |
1693 | rc[PART_BEG].row = Pixel2Row (y); |
1707 | /* round up */ |
1694 | /* round up */ |
1708 | rc[PART_END].col = Pixel2Width (x + ewidth + fwidth - 1); |
1695 | rc[PART_END].col = Pixel2Width (x + ewidth + fwidth - 1); |