Some new patches for st.
>From 17025c9ab88bb8560bac3896c2384ad060c6e8d9 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Mon, 17 Sep 2012 19:03:35 +0200
Subject: Add xcalloc wrapper

malloc and realloc are called through xmalloc and xrealloc, so calloc should
be called through xcalloc.
---
 st.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index d5ecf61..df7f8d8 100644
--- a/st.c
+++ b/st.c
@@ -324,6 +324,7 @@ static int isfullutf8(char *, int);
 
 static void *xmalloc(size_t);
 static void *xrealloc(void *, size_t);
+static void *xcalloc(size_t nmemb, size_t size);
 
 static void (*handler[LASTEvent])(XEvent *) = {
 	[KeyPress] = kpress,
@@ -373,6 +374,14 @@ xrealloc(void *p, size_t len) {
 	return p;
 }
 
+void *
+xcalloc(size_t nmemb, size_t size) {
+	void *p = calloc(nmemb, size);
+	if(!p)
+		die("Out of memory\n");
+	return p;
+}
+
 int
 utf8decode(char *s, long *u) {
 	uchar c;
@@ -1801,8 +1810,8 @@ tresize(int col, int row) {
 	/* allocate any new rows */
 	for(/* i == minrow */; i < row; i++) {
 		term.dirty[i] = 1;
-		term.line[i] = calloc(col, sizeof(Glyph));
-		term.alt [i] = calloc(col, sizeof(Glyph));
+		term.line[i] = xcalloc(col, sizeof(Glyph));
+		term.alt [i] = xcalloc(col, sizeof(Glyph));
 	}
 	if(col > term.col) {
 		bool *bp = term.tabs + term.col;
-- 
1.7.10.4

>From cd17e65b475b1eaccc73a2668f67953ac12222e4 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Mon, 17 Sep 2012 19:05:06 +0200
Subject: Add newline in error messages

---
 st.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index df7f8d8..c408ca9 100644
--- a/st.c
+++ b/st.c
@@ -363,14 +363,14 @@ void *
 xmalloc(size_t len) {
 	void *p = malloc(len);
 	if(!p)
-		die("Out of memory");
+		die("Out of memory\n");
 	return p;
 }
 
 void *
 xrealloc(void *p, size_t len) {
 	if((p = realloc(p, len)) == NULL)
-		die("Out of memory");
+		die("Out of memory\n");
 	return p;
 }
 
-- 
1.7.10.4

>From b13844523254ef2e05a8c3d81b89b8aba09e3513 Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Mon, 17 Sep 2012 20:19:48 +0200
Subject: Copy non set positions as spaces

st selection don't insert in the selection position whose value is not
set. This is correct for the positions in the end of the line, but cause
some problems in the beginning. For example echo -e 'a\tb' will print in the
screen:

a	b

but after selecting and copying in some place you get:

ab

because positions from 1 to 7 don't have any value. This patch deals all
positions without value as blank (even at the end of the line).
---
 st.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/st.c b/st.c
index c408ca9..b2e5e22 100644
--- a/st.c
+++ b/st.c
@@ -596,14 +596,17 @@ selcopy(void) {
 		/* append every set & selected glyph to the selection */
 		for(y = 0; y < term.row; y++) {
 			for(x = 0; x < term.col; x++) {
-				is_selected = selected(x, y);
-				if((term.line[y][x].state & GLYPH_SET) && is_selected) {
-					int size = utf8size(term.line[y][x].c);
-					memcpy(ptr, term.line[y][x].c, size);
-					ptr += size;
-				}
+				int size;
+				char *p;
+				Glyph *gp = &term.line[y][x];
+
+				if(!(is_selected = selected(x, y)))
+					continue;
+				p = (gp->state & GLYPH_SET) ? gp->c : " ";
+				size = utf8size(p);
+				memcpy(ptr, p, size);
+				ptr += size;
 			}
-
 			/* \n at the end of every selected line except for the last one */
 			if(is_selected && y < sel.e.y)
 				*ptr++ = '\n';
-- 
1.7.10.4

>From b6a73e21dfe968a8dbc8736799175a58cd8dfd8b Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k...@shike2.com>
Date: Mon, 17 Sep 2012 20:24:19 +0200
Subject: Clean windows display after resizing

Some times the size after a resizing is not an exact multiply of a number of
characters, so redrawn the screen using the lines and columns of the neww
size can cause that some old graphics keep in the screen. Solution is clean
all the windows with the background color.
---
 st.c |    3 +++
 1 file changed, 3 insertions(+)

diff --git a/st.c b/st.c
index b2e5e22..20e4512 100644
--- a/st.c
+++ b/st.c
@@ -1839,6 +1839,9 @@ void
 xresize(int col, int row) {
 	xw.w = MAX(1, 2*BORDER + col * xw.cw);
 	xw.h = MAX(1, 2*BORDER + row * xw.ch);
+	XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0,
+		       DisplayWidth(xw.dpy, xw.scr),
+		       DisplayHeight(xw.dpy, xw.scr));
 }
 
 void
-- 
1.7.10.4

Reply via email to