aewl

diff main.c @ 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
line diff
     1.1 --- a/main.c	Sun Nov 26 13:31:36 2006 +0100
     1.2 +++ b/main.c	Sun Nov 26 14:26:53 2006 +0100
     1.3 @@ -227,6 +227,7 @@
     1.4  
     1.5  int
     1.6  main(int argc, char *argv[]) {
     1.7 +	char *p;
     1.8  	int r, xfd;
     1.9  	fd_set rd;
    1.10  
    1.11 @@ -270,22 +271,23 @@
    1.12  		if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
    1.13  			if(errno == EINTR)
    1.14  				continue;
    1.15 -			else
    1.16 -				eprint("select failed\n");
    1.17 +			eprint("select failed\n");
    1.18  		}
    1.19  		if(FD_ISSET(STDIN_FILENO, &rd)) {
    1.20 -			switch(r = read(STDIN_FILENO, stext, sizeof(stext) - 1)) {
    1.21 +			switch(r = read(STDIN_FILENO, stext, sizeof stext - 1)) {
    1.22  			case -1:
    1.23 -				strncpy(stext, strerror(errno), sizeof(stext));
    1.24 -				stext[sizeof(stext) - 1] = '\0';
    1.25 +				strncpy(stext, strerror(errno), sizeof stext - 1);
    1.26  				readin = False;
    1.27  				break;
    1.28  			case 0:
    1.29 -				strncpy(stext, "EOF", sizeof(stext));
    1.30 +				strncpy(stext, "EOF", sizeof stext);
    1.31  				readin = False;
    1.32  				break;
    1.33  			default:
    1.34  				stext[r - (stext[r - 1] == '\n' ? 1 : 0)] = '\0';
    1.35 +				for(p = stext + strlen(stext) - 1; p > stext && *p != '\n'; --p);
    1.36 +				if(p > stext)
    1.37 +					strncpy(stext, p + 1, sizeof stext);
    1.38  			}
    1.39  			drawstatus();
    1.40  		}