dwm-meillo

changeset 581:601842ee4484

applied Jukka's sizeof K&R compliance patch, applied Manuels' last-line printage proposal for stdin reading.
author arg@mig29
date Sun, 26 Nov 2006 14:26:53 +0100
parents e9001b0f53bc
children 70472540c443
files client.c draw.c event.c main.c tag.c
diffstat 5 files changed, 16 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/client.c	Sun Nov 26 13:31:36 2006 +0100
     1.2 +++ b/client.c	Sun Nov 26 14:26:53 2006 +0100
     1.3 @@ -361,12 +361,12 @@
     1.4  	if(!name.nitems)
     1.5  		return;
     1.6  	if(name.encoding == XA_STRING)
     1.7 -		strncpy(c->name, (char *)name.value, sizeof(c->name));
     1.8 +		strncpy(c->name, (char *)name.value, sizeof c->name);
     1.9  	else {
    1.10  		if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
    1.11  				&& n > 0 && *list)
    1.12  		{
    1.13 -			strncpy(c->name, *list, sizeof(c->name));
    1.14 +			strncpy(c->name, *list, sizeof c->name);
    1.15  			XFreeStringList(list);
    1.16  		}
    1.17  	}
     2.1 --- a/draw.c	Sun Nov 26 13:31:36 2006 +0100
     2.2 +++ b/draw.c	Sun Nov 26 14:26:53 2006 +0100
     2.3 @@ -43,8 +43,8 @@
     2.4  		return;
     2.5  	w = 0;
     2.6  	olen = len = strlen(text);
     2.7 -	if(len >= sizeof(buf))
     2.8 -		len = sizeof(buf) - 1;
     2.9 +	if(len >= sizeof buf)
    2.10 +		len = sizeof buf - 1;
    2.11  	memcpy(buf, text, len);
    2.12  	buf[len] = 0;
    2.13  	h = dc.font.ascent + dc.font.descent;
     3.1 --- a/event.c	Sun Nov 26 13:31:36 2006 +0100
     3.2 +++ b/event.c	Sun Nov 26 14:26:53 2006 +0100
     3.3 @@ -244,7 +244,7 @@
     3.4  
     3.5  static void
     3.6  keypress(XEvent *e) {
     3.7 -	static unsigned int len = sizeof(key) / sizeof(key[0]);
     3.8 +	static unsigned int len = sizeof key / sizeof key[0];
     3.9  	unsigned int i;
    3.10  	KeySym keysym;
    3.11  	XKeyEvent *ev = &e->xkey;
    3.12 @@ -355,7 +355,7 @@
    3.13  
    3.14  void
    3.15  grabkeys(void) {
    3.16 -	static unsigned int len = sizeof(key) / sizeof(key[0]);
    3.17 +	static unsigned int len = sizeof key / sizeof key[0];
    3.18  	unsigned int i;
    3.19  	KeyCode code;
    3.20  
     4.1 --- a/main.c	Sun Nov 26 13:31:36 2006 +0100
     4.2 +++ b/main.c	Sun Nov 26 14:26:53 2006 +0100
     4.3 @@ -227,6 +227,7 @@
     4.4  
     4.5  int
     4.6  main(int argc, char *argv[]) {
     4.7 +	char *p;
     4.8  	int r, xfd;
     4.9  	fd_set rd;
    4.10  
    4.11 @@ -270,22 +271,23 @@
    4.12  		if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
    4.13  			if(errno == EINTR)
    4.14  				continue;
    4.15 -			else
    4.16 -				eprint("select failed\n");
    4.17 +			eprint("select failed\n");
    4.18  		}
    4.19  		if(FD_ISSET(STDIN_FILENO, &rd)) {
    4.20 -			switch(r = read(STDIN_FILENO, stext, sizeof(stext) - 1)) {
    4.21 +			switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) {
    4.22  			case -1:
    4.23 -				strncpy(stext, strerror(errno), sizeof(stext));
    4.24 -				stext[sizeof(stext) - 1] = '\0';
    4.25 +				strncpy(stext, strerror(errno), sizeof stext - 1);
    4.26  				readin = False;
    4.27  				break;
    4.28  			case 0:
    4.29 -				strncpy(stext, "EOF", sizeof(stext));
    4.30 +				strncpy(stext, "EOF", sizeof stext);
    4.31  				readin = False;
    4.32  				break;
    4.33  			default:
    4.34  				stext[r - (stext[r - 1] == '\n' ? 1 : 0)] = '\0';
    4.35 +				for(p = stext + strlen(stext) - 1; p > stext && *p != '\n'; --p);
    4.36 +				if(p > stext)
    4.37 +					strncpy(stext, p + 1, sizeof stext);
    4.38  			}
    4.39  			drawstatus();
    4.40  		}
     5.1 --- a/tag.c	Sun Nov 26 13:31:36 2006 +0100
     5.2 +++ b/tag.c	Sun Nov 26 14:26:53 2006 +0100
     5.3 @@ -50,7 +50,7 @@
     5.4  
     5.5  	if(rreg)
     5.6  		return;
     5.7 -	len = sizeof(rule) / sizeof(rule[0]);
     5.8 +	len = sizeof rule / sizeof rule[0];
     5.9  	rreg = emallocz(len * sizeof(RReg));
    5.10  	for(i = 0; i < len; i++) {
    5.11  		if(rule[i].clpattern) {
    5.12 @@ -83,7 +83,7 @@
    5.13  			c->tags[i] = trans->tags[i];
    5.14  	}
    5.15  	else if(XGetClassHint(dpy, c->win, &ch)) {
    5.16 -		snprintf(prop, sizeof(prop), "%s:%s:%s",
    5.17 +		snprintf(prop, sizeof prop, "%s:%s:%s",
    5.18  				ch.res_class ? ch.res_class : "",
    5.19  				ch.res_name ? ch.res_name : "", c->name);
    5.20  		for(i = 0; !matched && i < len; i++)