dwm-meillo
diff draw.c @ 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 | d659a2dce2b5 |
children | ffc73b32084a |
line diff
1.1 --- a/draw.c Mon Aug 14 08:43:19 2006 +0200 1.2 +++ b/draw.c Mon Aug 14 08:52:15 2006 +0200 1.3 @@ -26,7 +26,7 @@ 1.4 { 1.5 int x, y, w, h; 1.6 static char buf[256]; 1.7 - unsigned int len; 1.8 + unsigned int len, olen; 1.9 XGCValues gcv; 1.10 XPoint points[5]; 1.11 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; 1.12 @@ -51,7 +51,7 @@ 1.13 return; 1.14 1.15 w = 0; 1.16 - len = strlen(text); 1.17 + olen = len = strlen(text); 1.18 if(len >= sizeof(buf)) 1.19 len = sizeof(buf) - 1; 1.20 memcpy(buf, text, len); 1.21 @@ -64,6 +64,14 @@ 1.22 /* shorten text if necessary */ 1.23 while(len && (w = textnw(buf, len)) > dc.w - h) 1.24 buf[--len] = 0; 1.25 + if(len < olen) { 1.26 + if(len > 3) 1.27 + memcpy(buf + len - 4, "...\0", 4); 1.28 + else if(len > 2) 1.29 + memcpy(buf + len - 3, "..\0", 3); 1.30 + else if(len > 1) 1.31 + memcpy(buf + len - 2, ".\0", 2); 1.32 + } 1.33 1.34 if(w > dc.w) 1.35 return; /* too long */