Changeset 5052046 in mainline
- Timestamp:
- 2006-05-31T16:37:57Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1c20e22
- Parents:
- c0e674a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tetris/input.c
rc0e674a r5052046 51 51 52 52 #include <async.h> 53 #include "../console/console.h" 53 54 54 55 /* return true iff the given timeval is positive */ … … 65 66 } 66 67 68 /* We will use a hack here - if lastchar is non-zero, it is 69 * the last character read. We will somehow simulate the select 70 * semantics. 71 */ 67 72 static aid_t getchar_inprog = 0; 73 static char lastchar = '\0'; 68 74 69 75 /* … … 76 82 * 77 83 * Return 0 => no input, 1 => can read() from stdin 84 * 78 85 */ 79 86 int … … 81 88 { 82 89 struct timeval starttv, endtv, *s; 83 fd_set fds; 90 static ipc_call_t charcall; 91 int rc; 84 92 85 93 #define NILTZ ((struct timezone *)0) … … 97 105 s = NULL; 98 106 again: 99 FD_ZERO(&fds); 100 FD_SET(STDIN_FILENO, &fds); 101 switch (select(STDIN_FILENO + 1, &fds, (fd_set *)0, (fd_set *)0, s)) { 102 103 case -1: 104 if (tvp == 0) 105 return (-1); 106 if (errno == EINTR) 107 goto again; 108 stop("select failed, help"); 109 /* NOTREACHED */ 110 111 case 0: /* timed out */ 112 tvp->tv_sec = 0; 113 tvp->tv_usec = 0; 114 return (0); 107 if (!lastchar) { 108 if (!getchar_inprog) 109 getchar_inprog = async_send_2(1,CONSOLE_GETCHAR,0,0,&charcall); 110 if (async_wait_timeout(getchar_inprog, &rc, s->tv_usec) == ETIMEOUT) { 111 tvp->tv_sec = 0; 112 tvp->tv_usec = 0; 113 return (0); 114 } 115 getchar_inprog = 0; 116 if (rc) { 117 stop("end of file, help"); 118 } 119 lastchar = IPC_GET_ARG1(charcall); 115 120 } 116 121 if (tvp) { … … 136 141 tv.tv_usec = fallrate; 137 142 while (TV_POS(&tv)) 138 if (rwait(&tv) && read(STDIN_FILENO, &c, 1) != 1) 143 if (rwait(&tv)) { 144 lastchar = '\0'; 145 } else 139 146 break; 140 147 } … … 165 172 if (!rwait(&timeleft)) 166 173 return (-1); 167 if (read(STDIN_FILENO, &c, 1) != 1)168 stop("end of file, help");174 c = lastchar; 175 lastchar = '\0'; 169 176 return ((int)(unsigned char)c); 170 177 }
Note:
See TracChangeset
for help on using the changeset viewer.