changeset 269:bf6792e3e700

fixed string cutting in draw.c
author Anselm R.Garbe <arg@10ksloc.org>
date Mon, 14 Aug 2006 08:52:15 +0200
parents a47b3b0d7bf4
children dacd3f3c5823
files draw.c
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/draw.c	Mon Aug 14 08:43:19 2006 +0200
+++ b/draw.c	Mon Aug 14 08:52:15 2006 +0200
@@ -26,7 +26,7 @@
 {
 	int x, y, w, h;
 	static char buf[256];
-	unsigned int len;
+	unsigned int len, olen;
 	XGCValues gcv;
 	XPoint points[5];
 	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
@@ -51,7 +51,7 @@
 		return;
 
 	w = 0;
-	len = strlen(text);
+	olen = len = strlen(text);
 	if(len >= sizeof(buf))
 		len = sizeof(buf) - 1;
 	memcpy(buf, text, len);
@@ -64,6 +64,14 @@
 	/* shorten text if necessary */
 	while(len && (w = textnw(buf, len)) > dc.w - h)
 		buf[--len] = 0;
+	if(len < olen) {
+		if(len > 3)
+			memcpy(buf + len - 4, "...\0", 4);
+		else if(len > 2)
+			memcpy(buf + len - 3, "..\0", 3);
+		else if(len > 1)
+			memcpy(buf + len - 2, ".\0", 2);
+	}
 
 	if(w > dc.w)
 		return; /* too long */