aboutsummaryrefslogtreecommitdiff
path: root/grid.c
diff options
context:
space:
mode:
Diffstat (limited to 'grid.c')
-rw-r--r--grid.c49
1 files changed, 16 insertions, 33 deletions
diff --git a/grid.c b/grid.c
index 52d6f6bc..ef7c374b 100644
--- a/grid.c
+++ b/grid.c
@@ -1,4 +1,4 @@
-/* $Id$ */
+/* $OpenBSD$ */
/*
* Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
@@ -151,8 +151,6 @@ grid_collect_history(struct grid *gd)
{
u_int yy;
- GRID_DEBUG(gd, "");
-
if (gd->hsize < gd->hlimit)
return;
@@ -173,10 +171,9 @@ grid_scroll_history(struct grid *gd)
{
u_int yy;
- GRID_DEBUG(gd, "");
-
yy = gd->hsize + gd->sy;
- gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, yy + 1,
+ sizeof *gd->linedata);
memset(&gd->linedata[yy], 0, sizeof gd->linedata[yy]);
gd->hsize++;
@@ -189,11 +186,10 @@ grid_scroll_history_region(struct grid *gd, u_int upper, u_int lower)
struct grid_line *gl_history, *gl_upper, *gl_lower;
u_int yy;
- GRID_DEBUG(gd, "upper=%u, lower=%u", upper, lower);
-
/* Create a space for a new line. */
yy = gd->hsize + gd->sy;
- gd->linedata = xrealloc(gd->linedata, yy + 1, sizeof *gd->linedata);
+ gd->linedata = xreallocarray(gd->linedata, yy + 1,
+ sizeof *gd->linedata);
/* Move the entire screen down to free a space for this line. */
gl_history = &gd->linedata[gd->hsize];
@@ -227,7 +223,7 @@ grid_expand_line(struct grid *gd, u_int py, u_int sx)
if (sx <= gl->cellsize)
return;
- gl->celldata = xrealloc(gl->celldata, sx, sizeof *gl->celldata);
+ gl->celldata = xreallocarray(gl->celldata, sx, sizeof *gl->celldata);
for (xx = gl->cellsize; xx < sx; xx++)
grid_put_cell(gd, xx, py, &grid_default_cell);
gl->cellsize = sx;
@@ -282,8 +278,6 @@ grid_clear(struct grid *gd, u_int px, u_int py, u_int nx, u_int ny)
{
u_int xx, yy;
- GRID_DEBUG(gd, "px=%u, py=%u, nx=%u, ny=%u", px, py, nx, ny);
-
if (nx == 0 || ny == 0)
return;
@@ -319,8 +313,6 @@ grid_clear_lines(struct grid *gd, u_int py, u_int ny)
struct grid_line *gl;
u_int yy;
- GRID_DEBUG(gd, "py=%u, ny=%u", py, ny);
-
if (ny == 0)
return;
@@ -342,8 +334,6 @@ grid_move_lines(struct grid *gd, u_int dy, u_int py, u_int ny)
{
u_int yy;
- GRID_DEBUG(gd, "dy=%u, py=%u, ny=%u", dy, py, ny);
-
if (ny == 0 || py == dy)
return;
@@ -381,8 +371,6 @@ grid_move_cells(struct grid *gd, u_int dx, u_int px, u_int py, u_int nx)
struct grid_line *gl;
u_int xx;
- GRID_DEBUG(gd, "dx=%u, px=%u, py=%u, nx=%u", dx, px, py, nx);
-
if (nx == 0 || px == dx)
return;
@@ -528,20 +516,18 @@ grid_string_cells_code(const struct grid_cell *lastgc,
s[n++] = attrs[i].code;
}
- /* If the foreground c changed, append its parameters. */
+ /* If the foreground colour changed, append its parameters. */
nnewc = grid_string_cells_fg(gc, newc);
noldc = grid_string_cells_fg(lastgc, oldc);
- if (nnewc != noldc ||
- memcmp(newc,oldc, nnewc * sizeof newc[0]) != 0) {
+ if (nnewc != noldc || memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0) {
for (i = 0; i < nnewc; i++)
s[n++] = newc[i];
}
- /* If the background c changed, append its parameters. */
+ /* If the background colour changed, append its parameters. */
nnewc = grid_string_cells_bg(gc, newc);
noldc = grid_string_cells_bg(lastgc, oldc);
- if (nnewc != noldc ||
- memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0) {
+ if (nnewc != noldc || memcmp(newc, oldc, nnewc * sizeof newc[0]) != 0) {
for (i = 0; i < nnewc; i++)
s[n++] = newc[i];
}
@@ -586,14 +572,12 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
const struct grid_cell *gc;
static struct grid_cell lastgc1;
struct utf8_data ud;
- const char* data;
+ const char *data;
char *buf, code[128];
size_t len, off, size, codelen;
u_int xx;
const struct grid_line *gl;
- GRID_DEBUG(gd, "px=%u, py=%u, nx=%u", px, py, nx);
-
if (lastgc != NULL && *lastgc == NULL) {
memcpy(&lastgc1, &grid_default_cell, sizeof lastgc1);
*lastgc = &lastgc1;
@@ -628,7 +612,7 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
}
while (len < off + size + codelen + 1) {
- buf = xrealloc(buf, 2, len);
+ buf = xreallocarray(buf, 2, len);
len *= 2;
}
@@ -640,7 +624,7 @@ grid_string_cells(struct grid *gd, u_int px, u_int py, u_int nx,
off += size;
}
- if (trim) {
+ if (trim) {
while (off > 0 && buf[off - 1] == ' ')
off--;
}
@@ -661,8 +645,6 @@ grid_duplicate_lines(struct grid *dst, u_int dy, struct grid *src, u_int sy,
struct grid_line *dstl, *srcl;
u_int yy;
- GRID_DEBUG(src, "dy=%u, sy=%u, ny=%u", dy, sy, ny);
-
if (dy + ny > dst->hsize + dst->sy)
ny = dst->hsize + dst->sy - dy;
if (sy + ny > src->hsize + src->sy)
@@ -705,7 +687,7 @@ grid_reflow_join(struct grid *dst, u_int *py, struct grid_line *src_gl,
nx = ox + to_copy;
/* Resize the destination line. */
- dst_gl->celldata = xrealloc(dst_gl->celldata, nx,
+ dst_gl->celldata = xreallocarray(dst_gl->celldata, nx,
sizeof *dst_gl->celldata);
dst_gl->cellsize = nx;
@@ -744,7 +726,8 @@ grid_reflow_split(struct grid *dst, u_int *py, struct grid_line *src_gl,
to_copy = src_gl->cellsize;
/* Expand destination line. */
- dst_gl->celldata = xmalloc(to_copy * sizeof *dst_gl->celldata);
+ dst_gl->celldata = xreallocarray(NULL, to_copy,
+ sizeof *dst_gl->celldata);
dst_gl->cellsize = to_copy;
dst_gl->flags |= GRID_LINE_WRAPPED;