2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
11 * test_key - test waiting for keystrokes.
13 * 1) test_key - no arguments should wait until stuff followed by <cr>.
14 * 2) test_key -delay n - should wait n seconds and beep then exit. If data
15 * entered before n seconds, should be printed.
16 * 3) test_key -delay n -iters j - does the above n times.
20 #include <afsconfig.h>
21 #include <afs/param.h>
25 #include <sys/types.h>
41 printf("Usage: test_key [-nobuf] [-delay seconds [-iters n]]\n");
43 ("test_key waits for keystrokes. Without options it will wait indefinitely.\n");
45 ("To show that LWP is still running there is a rotating '|' which cycles every quarter second.\n");
46 printf("-nobuf - don't buffer input. Don't need to wait for <cr>.\n");
47 printf("-delay seconds - wait for <seconds> for a keystroke.\n");
48 printf("-iters n - repeat the wait n times.\n");
50 ("-inter - wait for key and beep every five seconds until pressed(overrides other options).\n");
51 printf("-line - wait for a whole line to be typed.");
56 int waitingForAnswer
= 0;
61 static struct timeval constSleepTime
= { 1, 0 };
62 struct timeval sleepTime
;
64 while (waitingForAnswer
) {
65 sleepTime
= constSleepTime
;
66 IOMGR_Select(0, 0, 0, 0, &sleepTime
);
67 if (!waitingForAnswer
)
78 LWP_WaitProcess(&waitingForAnswer
);
85 main(int ac
, char **av
)
95 for (i
= 1; i
< ac
; i
++) {
96 if (!strcmp("-delay", av
[i
])) {
98 printf("Missing delay time for -delay option.\n");
102 printf("Delay must be at least 0 seconds.\n");
105 } else if (!strcmp("-iters", av
[i
])) {
107 printf("Missing iteration count for -iters option.\n");
111 printf("Number of iterations must be at least 0.\n");
114 } else if (!strcmp("-nobuf", av
[i
])) {
115 rc
= setvbuf(stdin
, NULL
, _IONBF
, 0);
117 perror("Setting -nobuf for stdin");
119 } else if (!strcmp("-inter", av
[i
])) {
121 } else if (!strcmp("-line", av
[i
])) {
129 LWP_CreateProcess(DotWriter
, 32000, LWP_NORMAL_PRIORITY
, (char *)0,
130 "DotWriter", &dotpid
);
141 delay
= -1; /* Means wait indefinitely. */
143 for (; iters
>= 0; iters
--) {
144 waitingForAnswer
= 1;
145 LWP_NoYieldSignal(&waitingForAnswer
);
146 rc
= LWP_WaitForKeystroke(delay
);
147 waitingForAnswer
= 0;
149 printf("\n'%c'\n", getchar());
150 printf("Flushing remaining input.\n");
151 while (LWP_WaitForKeystroke(0)) {
152 printf("'%c'\n", getchar());
155 printf("\nNo data available on this iteration.\n");
162 /* interTest() : wait for key press and beep to remind user every five
171 printf("Will print dots until you hit a key!\n");
172 /* start the dotwriter thread running */
173 waitingForAnswer
= 1;
174 LWP_NoYieldSignal(&waitingForAnswer
);
177 rc
= LWP_GetResponseKey(5, &ch
);
182 waitingForAnswer
= 0; /* turn off dotwriter lwp */
184 printf("\nYou typed %c\n", ch
);
189 /* lineTest() : wait until a whole line has been entered before processing.
198 printf("Will print dots until enter a line\n");
199 /* start the dotwriter thread running */
200 waitingForAnswer
= 1;
201 LWP_NoYieldSignal(&waitingForAnswer
);
203 rc
= LWP_GetLine(line
, 256);
205 waitingForAnswer
= 0;
207 printf("You entered : %s\n", line
);
209 printf("linebuf was too small\n");