dwm-meillo
diff main.c @ 137:77922a389fa8
simplified main.c, switching back to single urxvt usage
author | arg@10ksloc.org |
---|---|
date | Fri, 21 Jul 2006 14:11:38 +0200 |
parents | 1489f6b97714 |
children | c1185dc7a36e |
line diff
1.1 --- a/main.c Fri Jul 21 11:54:14 2006 +0200 1.2 +++ b/main.c Fri Jul 21 14:11:38 2006 +0200 1.3 @@ -166,22 +166,17 @@ 1.4 int i, n; 1.5 unsigned int mask; 1.6 fd_set rd; 1.7 - Bool readstdin = True; 1.8 + Bool readin = True; 1.9 Window w; 1.10 XEvent ev; 1.11 XSetWindowAttributes wa; 1.12 1.13 - for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { 1.14 - switch (argv[i][1]) { 1.15 - default: 1.16 - eprint("usage: dwm [-v]\n"); 1.17 - break; 1.18 - case 'v': 1.19 - fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); 1.20 - exit(EXIT_SUCCESS); 1.21 - break; 1.22 - } 1.23 + if(argc == 2 && !strncmp("-v", argv[1], 3)) { 1.24 + fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); 1.25 + exit(EXIT_SUCCESS); 1.26 } 1.27 + else if(argc != 1) 1.28 + eprint("usage: dwm [-v]\n"); 1.29 1.30 dpy = XOpenDisplay(0); 1.31 if(!dpy) 1.32 @@ -256,10 +251,9 @@ 1.33 scan(); 1.34 1.35 /* main event loop, reads status text from stdin as well */ 1.36 -Mainloop: 1.37 while(running) { 1.38 FD_ZERO(&rd); 1.39 - if(readstdin) 1.40 + if(readin) 1.41 FD_SET(STDIN_FILENO, &rd); 1.42 FD_SET(ConnectionNumber(dpy), &rd); 1.43 1.44 @@ -276,20 +270,12 @@ 1.45 (handler[ev.type])(&ev); /* call handler */ 1.46 } 1.47 } 1.48 - if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) { 1.49 - i = n = 0; 1.50 - for(;;) { 1.51 - if((i = getchar()) == EOF) { 1.52 - /* broken pipe/end of producer */ 1.53 - readstdin = False; 1.54 - strcpy(stext, "broken pipe"); 1.55 - goto Mainloop; 1.56 - } 1.57 - if(i == '\n' || n >= sizeof(stext) - 1) 1.58 - break; 1.59 - stext[n++] = i; 1.60 - } 1.61 - stext[n] = 0; 1.62 + if(readin && FD_ISSET(STDIN_FILENO, &rd)) { 1.63 + readin = NULL != fgets(stext, sizeof(stext), stdin); 1.64 + if(readin) 1.65 + stext[strlen(stext) - 1] = 0; 1.66 + else 1.67 + strcpy(stext, "broken pipe"); 1.68 drawstatus(); 1.69 } 1.70 }