2013-06-02 13:55:50 -06:00
|
|
|
/* $XTermId: scrollback.c,v 1.16 2013/04/23 09:57:05 Bertram.Felgenhauer Exp $ */
|
2009-09-05 09:58:09 -06:00
|
|
|
|
2011-09-17 05:51:57 -06:00
|
|
|
/*
|
2013-06-02 13:55:50 -06:00
|
|
|
* Copyright 2009-2011,2013 by Thomas E. Dickey
|
2011-09-17 05:51:57 -06:00
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the
|
|
|
|
* sale, use or other dealings in this Software without prior written
|
|
|
|
* authorization.
|
|
|
|
*/
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
#include <xterm.h>
|
|
|
|
|
2013-06-02 13:55:50 -06:00
|
|
|
#define REAL_ROW(screen, row) ((row) + (screen)->saved_fifo)
|
2009-09-05 09:58:09 -06:00
|
|
|
#define ROW2FIFO(screen, row) \
|
2010-05-08 06:20:46 -06:00
|
|
|
(unsigned) (REAL_ROW(screen, row) % (screen)->savelines)
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a row-number, find the corresponding data for the line in the VT100
|
|
|
|
* widget's saved-line FIFO. The row-number (from getLineData) is negative.
|
|
|
|
* So we just count backwards from the last saved line.
|
|
|
|
*/
|
|
|
|
LineData *
|
|
|
|
getScrollback(TScreen * screen, int row)
|
|
|
|
{
|
2010-05-08 06:20:46 -06:00
|
|
|
LineData *result = 0;
|
|
|
|
|
|
|
|
if (screen->saved_fifo > 0 && REAL_ROW(screen, row) >= 0) {
|
|
|
|
unsigned which = ROW2FIFO(screen, row);
|
|
|
|
ScrnBuf where = scrnHeadAddr(screen, screen->saveBuf_index, which);
|
|
|
|
result = (LineData *) where;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE(("getScrollback %d -> %d -> %p\n",
|
|
|
|
row, ROW2FIFO(screen, row),
|
|
|
|
(void *) result));
|
|
|
|
return result;
|
2009-09-05 09:58:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a new row in the scrollback FIFO, returning a pointer to it.
|
|
|
|
*/
|
|
|
|
LineData *
|
|
|
|
addScrollback(TScreen * screen)
|
|
|
|
{
|
|
|
|
ScrnBuf where = 0;
|
|
|
|
unsigned which;
|
|
|
|
unsigned ncols = (unsigned) MaxCols(screen);
|
|
|
|
Char *block;
|
|
|
|
|
|
|
|
if (screen->saveBuf_index != 0) {
|
|
|
|
TRACE(("addScrollback %lu\n", screen->saved_fifo));
|
|
|
|
|
|
|
|
/* first, see which index we'll use */
|
|
|
|
which = (unsigned) (screen->saved_fifo % screen->savelines);
|
|
|
|
where = scrnHeadAddr(screen, screen->saveBuf_index, which);
|
|
|
|
|
|
|
|
/* discard any obsolete index data */
|
|
|
|
if (screen->saved_fifo > screen->savelines) {
|
|
|
|
LineData *prior = (LineData *) where;
|
|
|
|
/*
|
|
|
|
* setupLineData uses the attribs as the first address used from the
|
|
|
|
* data block.
|
|
|
|
*/
|
|
|
|
if (prior->attribs != 0) {
|
|
|
|
TRACE(("...freeing prior FIFO data in slot %d: %p->%p\n",
|
2009-10-31 08:11:57 -06:00
|
|
|
which, (void *) prior, prior->attribs));
|
2009-09-05 09:58:09 -06:00
|
|
|
free(prior->attribs);
|
|
|
|
prior->attribs = 0;
|
|
|
|
}
|
2013-06-02 13:55:50 -06:00
|
|
|
if (screen->saved_fifo > 2 * screen->savelines) {
|
|
|
|
screen->saved_fifo -= screen->savelines;
|
|
|
|
}
|
2009-09-05 09:58:09 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/* allocate the new data */
|
|
|
|
block = allocScrnData(screen, 1, ncols);
|
|
|
|
|
|
|
|
/* record the new data in the index */
|
|
|
|
setupLineData(screen, where, (Char *) block, 1, ncols);
|
|
|
|
|
|
|
|
TRACE(("...storing new FIFO data in slot %d: %p->%p\n",
|
2009-10-31 08:11:57 -06:00
|
|
|
which, (void *) where, block));
|
2009-09-05 09:58:09 -06:00
|
|
|
|
2013-06-02 13:55:50 -06:00
|
|
|
screen->saved_fifo++;
|
2009-09-05 09:58:09 -06:00
|
|
|
}
|
|
|
|
return (LineData *) where;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-02 13:55:50 -06:00
|
|
|
deleteScrollback(TScreen * screen)
|
2009-09-05 09:58:09 -06:00
|
|
|
{
|
2013-06-02 13:55:50 -06:00
|
|
|
unsigned which = ROW2FIFO(screen, -1);
|
2009-09-05 09:58:09 -06:00
|
|
|
ScrnBuf where = scrnHeadAddr(screen, screen->saveBuf_index, which);
|
|
|
|
LineData *prior = (LineData *) where;
|
|
|
|
/*
|
|
|
|
* setupLineData uses the attribs as the first address used from the
|
|
|
|
* data block.
|
|
|
|
*/
|
|
|
|
if (prior->attribs != 0) {
|
|
|
|
TRACE(("...freeing prior FIFO data in slot %d: %p->%p\n",
|
2009-10-31 08:11:57 -06:00
|
|
|
which, (void *) prior, prior->attribs));
|
2009-09-05 09:58:09 -06:00
|
|
|
free(prior->attribs);
|
|
|
|
prior->attribs = 0;
|
|
|
|
}
|
2013-06-02 13:55:50 -06:00
|
|
|
screen->saved_fifo--;
|
2009-09-05 09:58:09 -06:00
|
|
|
}
|