Rev 4488 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4488 | Rev 4515 | ||
---|---|---|---|
Line 90... | Line 90... | ||
90 | * If tvp is nil, wait forever, but return if select is interrupted. |
90 | * If tvp is nil, wait forever, but return if select is interrupted. |
91 | * |
91 | * |
92 | * Return 0 => no input, 1 => can read() from stdin |
92 | * Return 0 => no input, 1 => can read() from stdin |
93 | * |
93 | * |
94 | */ |
94 | */ |
95 | int |
- | |
96 | rwait(struct timeval *tvp) |
95 | int rwait(struct timeval *tvp) |
97 | { |
96 | { |
98 | struct timeval starttv, endtv, *s; |
97 | struct timeval starttv, endtv, *s; |
99 | static ipc_call_t charcall; |
98 | static ipc_call_t charcall; |
100 | ipcarg_t rc; |
99 | ipcarg_t rc; |
101 | 100 | ||
Line 115... | Line 114... | ||
115 | again: |
114 | again: |
116 | if (!getchar_inprog) { |
115 | if (!getchar_inprog) { |
117 | getchar_inprog = async_send_0(fphone(stdin), |
116 | getchar_inprog = async_send_0(fphone(stdin), |
118 | CONSOLE_GET_EVENT, &charcall); |
117 | CONSOLE_GET_EVENT, &charcall); |
119 | } |
118 | } |
- | 119 | ||
120 | if (!s) |
120 | if (!s) |
121 | async_wait_for(getchar_inprog, &rc); |
121 | async_wait_for(getchar_inprog, &rc); |
122 | else if (async_wait_timeout(getchar_inprog, &rc, s->tv_usec) == ETIMEOUT) { |
122 | else if (async_wait_timeout(getchar_inprog, &rc, s->tv_usec) == ETIMEOUT) { |
123 | tvp->tv_sec = 0; |
123 | tvp->tv_sec = 0; |
124 | tvp->tv_usec = 0; |
124 | tvp->tv_usec = 0; |
125 | return (0); |
125 | return (0); |
126 | } |
126 | } |
- | 127 | ||
127 | getchar_inprog = 0; |
128 | getchar_inprog = 0; |
128 | if (rc) { |
129 | if (rc) |
129 | stop("end of file, help"); |
130 | stop("end of file, help"); |
130 | } |
131 | |
131 | if (IPC_GET_ARG1(charcall) == KEY_RELEASE) |
132 | if (IPC_GET_ARG1(charcall) == KEY_RELEASE) |
132 | goto again; |
133 | goto again; |
133 | 134 | ||
134 | lastchar = IPC_GET_ARG4(charcall); |
135 | lastchar = IPC_GET_ARG4(charcall); |
135 | } |
136 | } |
- | 137 | ||
136 | if (tvp) { |
138 | if (tvp) { |
137 | /* since there is input, we may not have timed out */ |
139 | /* since there is input, we may not have timed out */ |
138 | (void) gettimeofday(&endtv, NULL); |
140 | (void) gettimeofday(&endtv, NULL); |
139 | TV_SUB(&endtv, &starttv); |
141 | TV_SUB(&endtv, &starttv); |
140 | TV_SUB(tvp, &endtv); /* adjust *tvp by elapsed time */ |
142 | TV_SUB(tvp, &endtv); /* adjust *tvp by elapsed time */ |
141 | } |
143 | } |
- | 144 | ||
142 | return (1); |
145 | return 1; |
143 | } |
146 | } |
144 | 147 | ||
145 | /* |
148 | /* |
146 | * `sleep' for the current turn time (using select). |
149 | * `sleep' for the current turn time (using select). |
147 | * Eat any input that might be available. |
150 | * Eat any input that might be available. |
148 | */ |
151 | */ |
149 | void |
- | |
150 | tsleep(void) |
152 | void tsleep(void) |
151 | { |
153 | { |
152 | struct timeval tv; |
154 | struct timeval tv; |
153 | 155 | ||
154 | tv.tv_sec = 0; |
156 | tv.tv_sec = 0; |
155 | tv.tv_usec = fallrate; |
157 | tv.tv_usec = fallrate; |
Line 161... | Line 163... | ||
161 | } |
163 | } |
162 | 164 | ||
163 | /* |
165 | /* |
164 | * getchar with timeout. |
166 | * getchar with timeout. |
165 | */ |
167 | */ |
166 | int |
- | |
167 | tgetchar(void) |
168 | int tgetchar(void) |
168 | { |
169 | { |
169 | static struct timeval timeleft; |
170 | static struct timeval timeleft; |
170 | char c; |
171 | char c; |
171 | 172 | ||
172 | /* |
173 | /* |
Line 181... | Line 182... | ||
181 | if (!TV_POS(&timeleft)) { |
182 | if (!TV_POS(&timeleft)) { |
182 | faster(); /* go faster */ |
183 | faster(); /* go faster */ |
183 | timeleft.tv_sec = 0; |
184 | timeleft.tv_sec = 0; |
184 | timeleft.tv_usec = fallrate; |
185 | timeleft.tv_usec = fallrate; |
185 | } |
186 | } |
- | 187 | ||
186 | if (!rwait(&timeleft)) |
188 | if (!rwait(&timeleft)) |
187 | return (-1); |
189 | return -1; |
- | 190 | ||
188 | c = lastchar; |
191 | c = lastchar; |
189 | lastchar = '\0'; |
192 | lastchar = '\0'; |
190 | return ((int)(unsigned char)c); |
193 | return ((int) (unsigned char) c); |
191 | } |
194 | } |
192 | 195 | ||
193 | /** @} |
196 | /** @} |
194 | */ |
197 | */ |
195 | - |