int awaitkey(int timeout, int tell) { struct linux_termios orig_termios, raw_termios; int c = 0; int i; /* set raw mode */ linux_tcgetattr(infd, &orig_termios); raw_termios = orig_termios; linux_cfmakeraw(&raw_termios); linux_tcsetattr(infd, LINUX_TCSETS, &raw_termios); for (i = timeout; i > 0; i--) { if (tell) { char numbuf[20]; int len, j; sprintf(numbuf, "%d ", i); len = strlen(numbuf); for (j = 0; j < len; j++) numbuf[len + j] = '\b'; numbuf[len + j] = '\0'; printf("%s", numbuf); } c = common_getc(infd, 1); if (c == 0) c = -1; if (c >= 0) break; } if (i == 0) c = '\0'; /* set original mode */ linux_tcsetattr(infd, LINUX_TCSETS, &orig_termios); if (tell) printf("0 \n"); return c; }
void consinit(int dev, int speed) { struct linux_termios termios; int fd; switch (dev) { case CONSDEV_COM0: iodev = dev; break; case CONSDEV_GLASS: default: glass_console: iodev = CONSDEV_GLASS; break; } if (infd >= 0 && infd == outfd) { uclose(infd); infd = 0; outfd = 1; } if (iodev == CONSDEV_GLASS) { infd = 0; outfd = 1; strlcpy(bi_cons.devname, "glass", sizeof(bi_cons.devname)); bi_cons.addr = -1; bi_cons.speed = -1; } else { fd = uopen(comdevname[iodev - CONSDEV_COM0], LINUX_O_RDWR); if (fd < 0) goto glass_console; infd = outfd = fd; /* set speed */ linux_tcgetattr(fd, &termios); if (linux_cfsetspeed(&termios, speed) < 0) { speed = 9600; if (linux_cfsetspeed(&termios, speed) < 0) goto glass_console; } if (linux_tcsetattr(fd, LINUX_TCSETS, &termios) < 0) goto glass_console; snprintf(bi_cons.devname, sizeof(bi_cons.devname), "com%d", iodev - CONSDEV_COM0); bi_cons.addr = -1; bi_cons.speed = speed; } BI_ADD(&bi_cons, BTINFO_CONSDEV, sizeof(bi_cons)); }
/** Setup the terminal for our use */ static void linux_console_startup(void) { struct termios t; if (linux_tcgetattr(0, &t)) { DBG("linux_console tcgetattr failed (%s)", linux_strerror(linux_errno)); return; } saved_termios = t; /* Disable canonical mode and echo. Let readline handle that */ t.c_lflag &= ~(ECHO | ICANON); /* stop ^C from sending a signal */ t.c_cc[VINTR] = 0; if (linux_tcsetattr(0, TCSAFLUSH, &t)) DBG("linux_console tcsetattr failed (%s)", linux_strerror(linux_errno)); }
/** Restores original terminal attributes on shutdown */ static void linux_console_shutdown(int flags __unused) { if (linux_tcsetattr(0, TCSAFLUSH, &saved_termios)) DBG("linux_console tcsetattr failed (%s)", linux_strerror(linux_errno)); }