2018-03-29 14:22:05 -06:00
|
|
|
/* $XTermId: linedata.c,v 1.90 2017/12/25 17:12:00 tom Exp $ */
|
2009-09-05 09:58:09 -06:00
|
|
|
|
2011-09-17 05:51:57 -06:00
|
|
|
/*
|
2018-03-29 14:22:05 -06:00
|
|
|
* Copyright 2009-2014,2017 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>
|
2018-03-29 14:22:05 -06:00
|
|
|
#include <data.h>
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a row-number, find the corresponding data for the line in the VT100
|
|
|
|
* widget. Row numbers can be positive or negative.
|
|
|
|
*
|
|
|
|
* If the data comes from the scrollback, defer that to getScrollback().
|
|
|
|
*/
|
|
|
|
LineData *
|
2014-12-18 13:16:55 -07:00
|
|
|
getLineData(TScreen *screen, int row)
|
2009-09-05 09:58:09 -06:00
|
|
|
{
|
|
|
|
LineData *result = 0;
|
|
|
|
ScrnBuf buffer;
|
2010-05-08 06:20:46 -06:00
|
|
|
int max_row = screen->max_row;
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
if (row >= 0) {
|
|
|
|
buffer = screen->visbuf;
|
|
|
|
} else {
|
|
|
|
#if OPT_FIFO_LINES
|
|
|
|
buffer = 0;
|
|
|
|
result = getScrollback(screen, row);
|
|
|
|
#else
|
|
|
|
buffer = screen->saveBuf_index;
|
|
|
|
row += screen->savelines;
|
2010-05-08 06:20:46 -06:00
|
|
|
max_row += screen->savelines;
|
2009-09-05 09:58:09 -06:00
|
|
|
#endif
|
|
|
|
}
|
2010-05-08 06:20:46 -06:00
|
|
|
if (row >= 0 && row <= max_row) {
|
2009-09-05 09:58:09 -06:00
|
|
|
result = (LineData *) scrnHeadAddr(screen, buffer, (unsigned) row);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copy line's data, e.g., from one screen buffer to another, given the preset
|
|
|
|
* pointers for the destination.
|
|
|
|
*
|
|
|
|
* TODO: optionally prune unused combining character data from the result.
|
|
|
|
*/
|
|
|
|
void
|
2014-12-18 13:16:55 -07:00
|
|
|
copyLineData(LineData *dst, CLineData *src)
|
2009-09-05 09:58:09 -06:00
|
|
|
{
|
|
|
|
dst->bufHead = src->bufHead;
|
|
|
|
|
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
dst->combSize = src->combSize;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Usually we're copying the same-sized line; a memcpy is faster than
|
|
|
|
* several loops.
|
|
|
|
*/
|
|
|
|
if (dst->lineSize == src->lineSize) {
|
|
|
|
size_t size = (sizeof(dst->attribs[0])
|
|
|
|
#if OPT_ISO_COLORS
|
|
|
|
+ sizeof(dst->color[0])
|
|
|
|
#endif
|
|
|
|
+ sizeof(dst->charData[0])
|
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
+ sizeof(dst->combData[0][0]) * dst->combSize
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
memcpy(dst->attribs, src->attribs, size * dst->lineSize);
|
|
|
|
} else {
|
|
|
|
Dimension col;
|
|
|
|
Dimension limit = ((dst->lineSize < src->lineSize)
|
|
|
|
? dst->lineSize
|
|
|
|
: src->lineSize);
|
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
Char comb;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (col = 0; col < limit; ++col) {
|
|
|
|
dst->attribs[col] = src->attribs[col];
|
|
|
|
#if OPT_ISO_COLORS
|
|
|
|
dst->color[col] = src->color[col];
|
|
|
|
#endif
|
|
|
|
dst->charData[col] = src->charData[col];
|
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
for (comb = 0; comb < dst->combSize; ++comb) {
|
|
|
|
dst->combData[comb][col] = src->combData[comb][col];
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
for (col = limit; col < dst->lineSize; ++col) {
|
|
|
|
dst->attribs[col] = 0;
|
|
|
|
#if OPT_ISO_COLORS
|
2018-03-29 14:22:05 -06:00
|
|
|
dst->color[col] = initCColor;
|
2009-09-05 09:58:09 -06:00
|
|
|
#endif
|
|
|
|
dst->charData[col] = 0;
|
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
for (comb = 0; comb < dst->combSize; ++comb) {
|
|
|
|
dst->combData[comb][col] = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
#define initLineExtra(screen) \
|
2018-03-29 14:22:05 -06:00
|
|
|
screen->lineExtra = ((size_t) (screen->max_combining) * sizeof(IChar *)); \
|
|
|
|
screen->cellExtra = ((size_t) (screen->max_combining) * sizeof(IChar))
|
2009-09-05 09:58:09 -06:00
|
|
|
#else
|
|
|
|
#define initLineExtra(screen) \
|
2018-03-29 14:22:05 -06:00
|
|
|
screen->lineExtra = 0; \
|
|
|
|
screen->cellExtra = 0
|
2009-09-05 09:58:09 -06:00
|
|
|
#endif
|
|
|
|
|
2018-03-29 14:22:05 -06:00
|
|
|
/*
|
|
|
|
* CellData size depends on the "combiningChars" resource.
|
|
|
|
*/
|
|
|
|
#define CellDataSize(screen) (SizeOfCellData + screen->cellExtra)
|
|
|
|
|
|
|
|
#define CellDataAddr(screen, data, cell) \
|
|
|
|
( (CellData *)(void *) ((char *)data + (cell * CellDataSize(screen))) )
|
|
|
|
#define ConstCellDataAddr(screen, data, cell) \
|
|
|
|
( (const CellData *)(const void *) ( \
|
|
|
|
(const char *)data + (cell * CellDataSize(screen))) )
|
|
|
|
|
2009-09-05 09:58:09 -06:00
|
|
|
void
|
|
|
|
initLineData(XtermWidget xw)
|
|
|
|
{
|
2010-03-25 16:03:51 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
initLineExtra(screen);
|
|
|
|
|
2018-03-29 14:22:05 -06:00
|
|
|
TRACE(("initLineData %lu (%d combining chars)\n",
|
|
|
|
(unsigned long) screen->lineExtra, screen->max_combining));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per-line size/offsets.
|
|
|
|
*/
|
|
|
|
TRACE(("** sizeof(LineData) %lu\n", (unsigned long) sizeof(LineData)));
|
|
|
|
TRACE((" offset(lineSize) %lu\n", (unsigned long) offsetof(LineData, lineSize)));
|
|
|
|
TRACE((" offset(bufHead) %lu\n", (unsigned long) offsetof(LineData, bufHead)));
|
|
|
|
#if OPT_WIDE_CHARS
|
|
|
|
TRACE((" offset(combSize) %lu\n", (unsigned long) offsetof(LineData, combSize)));
|
|
|
|
#endif
|
|
|
|
TRACE((" offset(*attribs) %lu\n", (unsigned long) offsetof(LineData, attribs)));
|
2009-09-05 09:58:09 -06:00
|
|
|
#if OPT_ISO_COLORS
|
2018-03-29 14:22:05 -06:00
|
|
|
TRACE((" offset(*color) %lu\n", (unsigned long) offsetof(LineData, color)));
|
2009-09-05 09:58:09 -06:00
|
|
|
#endif
|
2018-03-29 14:22:05 -06:00
|
|
|
TRACE((" offset(*charData) %lu\n", (unsigned long) offsetof(LineData, charData)));
|
|
|
|
TRACE((" offset(*combData) %lu\n", (unsigned long) offsetof(LineData, combData)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Per-cell size/offsets.
|
|
|
|
*/
|
|
|
|
TRACE(("** sizeof(CellData) %lu\n", (unsigned long) CellDataSize(screen)));
|
|
|
|
TRACE((" offset(attribs) %lu\n", (unsigned long) offsetof(CellData, attribs)));
|
2009-09-05 09:58:09 -06:00
|
|
|
#if OPT_WIDE_CHARS
|
2018-03-29 14:22:05 -06:00
|
|
|
TRACE((" offset(combSize) %lu\n", (unsigned long) offsetof(CellData, combSize)));
|
2009-09-05 09:58:09 -06:00
|
|
|
#endif
|
|
|
|
#if OPT_ISO_COLORS
|
2018-03-29 14:22:05 -06:00
|
|
|
TRACE((" offset(color) %lu\n", (unsigned long) offsetof(CellData, color)));
|
2009-09-05 09:58:09 -06:00
|
|
|
#endif
|
2018-03-29 14:22:05 -06:00
|
|
|
TRACE((" offset(charData) %lu\n", (unsigned long) offsetof(CellData, charData)));
|
|
|
|
TRACE((" offset(combData) %lu\n", (unsigned long) offsetof(CellData, combData)));
|
2009-09-05 09:58:09 -06:00
|
|
|
|
2018-03-29 14:22:05 -06:00
|
|
|
/*
|
|
|
|
* Data-type sizes.
|
|
|
|
*/
|
|
|
|
#if OPT_ISO_COLORS
|
|
|
|
TRACE(("** sizeof(CellColor) %lu\n", (unsigned long) sizeof(CellColor)));
|
|
|
|
#endif
|
|
|
|
TRACE(("** sizeof(IAttr) %lu\n", (unsigned long) sizeof(IAttr)));
|
|
|
|
TRACE(("** sizeof(IChar) %lu\n", (unsigned long) sizeof(IChar)));
|
|
|
|
TRACE(("** sizeof(RowData) %lu\n", (unsigned long) sizeof(RowData)));
|
|
|
|
}
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
CellData *
|
|
|
|
newCellData(XtermWidget xw, Cardinal count)
|
|
|
|
{
|
|
|
|
CellData *result;
|
2010-03-25 16:03:51 -06:00
|
|
|
TScreen *screen = TScreenOf(xw);
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
initLineExtra(screen);
|
|
|
|
result = (CellData *) calloc((size_t) count, (size_t) CellDataSize(screen));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-18 13:16:55 -07:00
|
|
|
saveCellData(TScreen *screen,
|
|
|
|
CellData *data,
|
2009-09-05 09:58:09 -06:00
|
|
|
Cardinal cell,
|
2014-12-18 13:16:55 -07:00
|
|
|
CLineData *ld,
|
2009-09-05 09:58:09 -06:00
|
|
|
int column)
|
|
|
|
{
|
|
|
|
CellData *item = CellDataAddr(screen, data, cell);
|
|
|
|
|
|
|
|
if (column < MaxCols(screen)) {
|
|
|
|
item->attribs = ld->attribs[column];
|
|
|
|
#if OPT_ISO_COLORS
|
|
|
|
item->color = ld->color[column];
|
|
|
|
#endif
|
|
|
|
item->charData = ld->charData[column];
|
|
|
|
if_OPT_WIDE_CHARS(screen, {
|
|
|
|
size_t off;
|
|
|
|
item->combSize = ld->combSize;
|
|
|
|
for_each_combData(off, ld) {
|
|
|
|
item->combData[off] = ld->combData[off][column];
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-12-18 13:16:55 -07:00
|
|
|
restoreCellData(TScreen *screen,
|
|
|
|
const CellData *data,
|
2009-09-05 09:58:09 -06:00
|
|
|
Cardinal cell,
|
2014-12-18 13:16:55 -07:00
|
|
|
LineData *ld,
|
2009-09-05 09:58:09 -06:00
|
|
|
int column)
|
|
|
|
{
|
2014-12-18 13:16:55 -07:00
|
|
|
const CellData *item = ConstCellDataAddr(screen, data, cell);
|
2009-09-05 09:58:09 -06:00
|
|
|
|
|
|
|
if (column < MaxCols(screen)) {
|
|
|
|
ld->attribs[column] = item->attribs;
|
|
|
|
#if OPT_ISO_COLORS
|
|
|
|
ld->color[column] = item->color;
|
|
|
|
#endif
|
|
|
|
ld->charData[column] = item->charData;
|
|
|
|
if_OPT_WIDE_CHARS(screen, {
|
|
|
|
size_t off;
|
|
|
|
ld->combSize = item->combSize;
|
|
|
|
for_each_combData(off, ld) {
|
|
|
|
ld->combData[off][column] = item->combData[off];
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|