+/*
+ * Reads key by either getch() (WAIT_FOREVER mode) or select()
+ * (WAIT_TIMEOUT mode). Returns -1 upon error, 0 for timeout, or
+ * pressed key code.
+ */
+int wait_key()
+{
+ int i = 0;
+ fd_set rds;
+ struct timeval timeout;
+ extern int wait_mode;
+
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
+ FD_ZERO(&rds);
+ FD_SET(0, &rds);
+
+ if (wait_mode == WAIT_TIMEOUT) {
+ /*
+ * wait up to timeout until anything is avail. for reading
+ * on stdin
+ */
+ i = select(1, &rds, NULL, NULL, &timeout);
+
+ /* not timed out => anything avail. for reading in rds */
+ if (i > 0)
+ i = getc(stdin);
+
+ /* error occured */
+ if (i == -1) {
+ print_helperr(SELECT);
+ getch();
+ }
+
+ /* also happens: i = 0 => timeout => release */
+
+ } else { /* wait_mode = WAIT_FOREVER */
+ i = getch();
+ }
+
+ return i;
+}
+
+int help_ysn()
+{
+ char c;
+
+ print_help (_("Y - Yes; Any other key - No (it's safer to answer No)"));
+ c = getch();
+ clear_main(0);
+ if (c == 'y' || c == 'Y')
+ return 0;
+
+ return 1;
+}
+