about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@gmail.com>2007-11-10 20:21:22 +0100
committerAnselm R. Garbe <garbeam@gmail.com>2007-11-10 20:21:22 +0100
commitcb4951dd54951611bb99924b9ae1d0a7c87f47cc (patch)
tree5f21fa03eeac9d7e66c570a02a5bb01a539d8669
parent667da18b31e09c7c6d9359b66ff8e2ded7b20365 (diff)
downloaddwm-cb4951dd54951611bb99924b9ae1d0a7c87f47cc.tar.gz
applied Ritesh's patch to stext handling with some minor modifications
-rw-r--r--dwm.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/dwm.c b/dwm.c
index 8da3b6f..1529372 100644
--- a/dwm.c
+++ b/dwm.c
@@ -1287,6 +1287,7 @@ restack(void) {
 void
 run(void) {
 	char *p;
+	char buf[sizeof stext];
 	fd_set rd;
 	int r, xfd;
 	unsigned int len, offset;
@@ -1298,7 +1299,7 @@ run(void) {
 	readin = True;
 	offset = 0;
 	len = sizeof stext - 1;
-	stext[len] = '\0'; /* 0-terminator is never touched */
+	buf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
 	while(running) {
 		FD_ZERO(&rd);
 		if(readin)
@@ -1310,7 +1311,7 @@ run(void) {
 			eprint("select failed\n");
 		}
 		if(FD_ISSET(STDIN_FILENO, &rd)) {
-			switch((r = read(STDIN_FILENO, stext + offset, len - offset))) {
+			switch((r = read(STDIN_FILENO, buf + offset, len - offset))) {
 			case -1:
 				strncpy(stext, strerror(errno), len);
 				readin = False;
@@ -1320,14 +1321,18 @@ run(void) {
 				readin = False;
 				break;
 			default:
-				stext[offset + r] = '\0';
-				for(p = stext; *p && *p != '\n'; p++);
-				if(*p == '\n') {
-					*p = '\0';
-					offset = 0;
-				}
-				else
-					offset = (offset + r < len - 1) ? offset + r : 0;
+				for(p = buf + offset; r > 0; p++, r--, offset++)
+					if(*p == '\n' || *p == '\0') {
+						*p = '\0';
+						strncpy(stext, buf, len);
+						p += r - 1; /* p is buf + offset + r - 1 */
+						for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
+						offset = r;
+						if(r)
+							memmove(buf, p - r + 1, r);
+						break;
+					}
+				break;
 			}
 			drawbar();
 		}
s revision' href='/acidbong/suckless/dwm/blame/config.arg.h?h=5.8.2&id=9833610356f7ce033589680fddf87000e5788774'>^
19390b1 ^
97ced11 ^
19390b1 ^

a73a882 ^
b38905b ^
a73a882 ^
19390b1 ^

0982e47 ^
19390b1 ^
b60406c ^


19390b1 ^

























a73a882 ^



d6a6eca ^
a08d83b ^



a73a882 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69