1 /* $XTermId: scrollback.c,v 1.14 2010/04/28 21:47:09 tom Exp $ */
3 /************************************************************
5 Copyright 2009,2010 by Thomas E. Dickey
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice shall be included
18 in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
24 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 Except as contained in this notice, the name(s) of the above copyright
29 holders shall not be used in advertising or otherwise to promote the
30 sale, use or other dealings in this Software without prior written
33 ********************************************************/
37 #define REAL_ROW(screen, row) ((row) + 1 + (screen)->saved_fifo)
38 #define ROW2FIFO(screen, row) \
39 (unsigned) (REAL_ROW(screen, row) % (screen)->savelines)
42 * Given a row-number, find the corresponding data for the line in the VT100
43 * widget's saved-line FIFO. The row-number (from getLineData) is negative.
44 * So we just count backwards from the last saved line.
47 getScrollback(TScreen * screen, int row)
51 if (screen->saved_fifo > 0 && REAL_ROW(screen, row) >= 0) {
52 unsigned which = ROW2FIFO(screen, row);
53 ScrnBuf where = scrnHeadAddr(screen, screen->saveBuf_index, which);
54 result = (LineData *) where;
57 TRACE(("getScrollback %d -> %d -> %p\n",
58 row, ROW2FIFO(screen, row),
64 * Allocate a new row in the scrollback FIFO, returning a pointer to it.
67 addScrollback(TScreen * screen)
71 unsigned ncols = (unsigned) MaxCols(screen);
74 if (screen->saveBuf_index != 0) {
76 TRACE(("addScrollback %lu\n", screen->saved_fifo));
78 /* first, see which index we'll use */
79 which = (unsigned) (screen->saved_fifo % screen->savelines);
80 where = scrnHeadAddr(screen, screen->saveBuf_index, which);
82 /* discard any obsolete index data */
83 if (screen->saved_fifo > screen->savelines) {
84 LineData *prior = (LineData *) where;
86 * setupLineData uses the attribs as the first address used from the
89 if (prior->attribs != 0) {
90 TRACE(("...freeing prior FIFO data in slot %d: %p->%p\n",
91 which, (void *) prior, prior->attribs));
97 /* allocate the new data */
98 block = allocScrnData(screen, 1, ncols);
100 /* record the new data in the index */
101 setupLineData(screen, where, (Char *) block, 1, ncols);
103 TRACE(("...storing new FIFO data in slot %d: %p->%p\n",
104 which, (void *) where, block));
107 return (LineData *) where;
111 deleteScrollback(TScreen * screen, int row)
113 unsigned which = ROW2FIFO(screen, row);
114 ScrnBuf where = scrnHeadAddr(screen, screen->saveBuf_index, which);
115 LineData *prior = (LineData *) where;
117 * setupLineData uses the attribs as the first address used from the
120 if (prior->attribs != 0) {
121 TRACE(("...freeing prior FIFO data in slot %d: %p->%p\n",
122 which, (void *) prior, prior->attribs));
123 free(prior->attribs);