On (01/06/08 12:38), Enno Gottox Boland wrote: > To: dynamic window manager <dwm@suckless.org> > From: Enno Gottox Boland <[EMAIL PROTECTED]> > Subject: [dwm] [patch] simplification to drawtext > Reply-To: dynamic window manager <dwm@suckless.org> > List-Id: dynamic window manager <dwm.suckless.org> > > Hi! > > Here's a small simplification to drawtext. > > regards > Gottox >
> diff -r 2488c46e002c dwm.c > --- a/dwm.c Thu May 29 18:42:53 2008 +0100 > +++ b/dwm.c Sun Jun 01 12:36:37 2008 +0200 > @@ -571,14 +571,8 @@ > for(; len && (w = textnw(buf, len)) > dc.w - h; len--); > if(!len) > return; > - if(len < olen) { > - if(len > 1) > - buf[len - 1] = '.'; > - if(len > 2) > - buf[len - 2] = '.'; > - if(len > 3) > - buf[len - 3] = '.'; > - } > + if(len < olen) > + strncpy(&buf[MAX(0, len - 3)], "...", len); Not much readable (because it firstly looks like it's error (buf maybe not ended with \0)). I am against using strncpy in case that dest string is not C string, but char[] + length. Maybe: memcpy(&buf[MAX(0, len - 3)], "...", 3); would be somewhat better ;) > XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]); > if(dc.font.set) > XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, > len); -- Premysl "Anydot" Hruby, http://www.redrum.cz/