add select(2)-based i/o multiplexing

master
Matthias-Christian Ott 17 years ago
parent a49919a10c
commit f9a0524f94
  1. 26
      std.c

26
std.c

@ -263,20 +263,32 @@ ungetch(int c) {
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
fd_set rfds;
int r;
if(argc == 2 && !strcmp("-v", argv[1])) if(argc == 2 && !strcmp("-v", argv[1]))
eprint("std-"VERSION", © 2008 Matthias-Christian Ott\n"); eprint("std-"VERSION", © 2008 Matthias-Christian Ott\n");
else if(argc == 1) else if(argc == 1)
eprint("usage: st [-v]\n"); eprint("usage: st [-v]\n");
getpty(); getpty();
shell(); shell();
FD_ZERO(&rfds);
FD_SET(STDIN_FILENO, &rfds);
FD_SET(ptm, &rfds);
for(;;) { for(;;) {
c = getch(); r = select(ptm + 1, &rfds, NULL, NULL, NULL);
switch(c) { if(r == -1)
case '\033': eprintn("error, cannot select");
parseesc(); if(FD_ISSET(ptm, &rfds)) {
break; c = getch();
default: switch(c) {
putchar(c); case '\033':
parseesc();
break;
default:
putchar(c);
}
fflush(stdout);
} }
} }
return 0; return 0;

Loading…
Cancel
Save