void playit(void) { char *opts; /* * set up defaults for slow terminals */ if (baudrate() <= 1200) { terse = TRUE; jump = TRUE; see_floor = FALSE; } if (md_hasclreol()) inv_type = INV_CLEAR; /* * parse environment declaration of options */ if ((opts = getenv("ROGUEOPTS")) != NULL) parse_opts(opts); oldpos = hero; oldrp = roomin(&hero); while (playing) command(); /* Command execution */ endit(0); }
int main(void) { int b; initscr(); b = baudrate(); printw("This terminal's baud rate is %d.\n",b); refresh(); getch(); endwin(); return 0; }
//--------------------------------------------------------------------------- void GPSDialog::on_startStopButton_clicked() { if(gps->isOpen()) { gps->close(); } else { gps->deviceName(ui->gpsPortEd->text()); gps->baudRate(baudrate()); gps->flowControl(flowtype()); if(!gps->open()) QMessageBox::critical(this, "Failed to open port!", gps->ioError()); } ui->startStopButton->setText(gps->isOpen() ? "Stop":"Start"); }
/* * Insert an N milli-second delay by inserting pad characters * into the output stream. */ int delay_output(int ms) { int null = '\0'; unsigned int number, baud; baud = baudrate(); if (!no_pad_char) { if (pad_char != NULL) null = *pad_char; number = (baud / 10 * ms) / 1000; while (0 < number--) (void) __m_putchar(null); } return (OK); }
int main(int argc, char **argv) { int retval; struct timeval t, tod; struct timezone tz; fd_set rset; FD_ZERO(&rset); setbuf(stdout, outbuf); srandomdev(); signal(SIGINT, leave); signal(SIGQUIT, leave); signal(SIGTSTP, suspend); /* process control signal */ initscr(); cbreak(); noecho(); keypad(stdscr, TRUE); slow = (baudrate() <= 1200); clear(); if (COLS < 18 || LINES < 5) { endwin(); errx(1, "screen too small"); } if (argc == 2) start_len = atoi(argv[1]); if ((start_len <= 0) || (start_len > ((LINES-3) * (COLS-2)) / 3)) start_len = LENGTH; stw = newwin(1, COLS-1, 0, 0); tv = newwin(LINES-1, COLS-1, 1, 0); box(tv, '*', '*'); scrollok(tv, FALSE); scrollok(stw, FALSE); wmove(stw, 0, 0); wprintw(stw, " Worm"); refresh(); wrefresh(stw); wrefresh(tv); life(); /* Create the worm */ prize(); /* Put up a goal */ while(1) { if (wantleave) { endwin(); /* XXX signal race */ exit(0); } if (wantsuspend) { move(LINES-1, 0); refresh(); endwin(); fflush(stdout); kill(getpid(), SIGSTOP); signal(SIGTSTP, suspend); cbreak(); noecho(); setup(); wantsuspend = 0; } if (running) { running--; process(lastch); } else { /* fflush(stdout); */ /* Delay could be a command line option */ t.tv_sec = 1; t.tv_usec = 0; (void)gettimeofday(&tod, &tz); FD_SET(STDIN_FILENO, &rset); retval = select(STDIN_FILENO + 1, &rset, NULL, NULL, &t); if (retval > 0) process(getch()); else process(lastch); } } }
int set_serial (struct serial *s, struct serial_mode *serial_mode) { #ifdef WIN32 COMMTIMEOUTS timeouts; DCB dcbSerial; memset (&dcbSerial, 0, sizeof (dcbSerial)); dcbSerial.DCBlength = sizeof (dcbSerial); if (!GetCommState (s->h, &dcbSerial)) { return (-1); } dcbSerial.BaudRate = serial_mode->baud_rate; dcbSerial.ByteSize = serial_mode->data_bits; switch (serial_mode->stop_bits) { case 1: dcbSerial.StopBits = ONESTOPBIT; break; case 2: dcbSerial.StopBits = TWOSTOPBITS; break; default: error (1, 0, "invalid stop bit setting"); } switch (serial_mode->parity) { case UART_ODDPARITY: dcbSerial.Parity = ODDPARITY; dcbSerial.fParity = TRUE; break; case UART_EVENPARITY: dcbSerial.Parity = EVENPARITY; dcbSerial.fParity = TRUE; break; case UART_NOPARITY: dcbSerial.Parity = NOPARITY; dcbSerial.fParity = FALSE; break; default: error (1, 0, "invalid parity serial_mode"); } if (!SetCommState (s->h, &dcbSerial)) { error (0, 0, "could not set serial port settings"); return (-1); } timeouts.ReadIntervalTimeout = 0; timeouts.ReadTotalTimeoutConstant = 10; timeouts.ReadTotalTimeoutMultiplier = 0; timeouts.WriteTotalTimeoutConstant = 10; timeouts.WriteTotalTimeoutMultiplier = 10; if (!SetCommTimeouts (s->h, &timeouts)) { return (-1); } #else struct termios termios; speed_t speed; tcgetattr (s->fd, &termios); cfmakeraw (&termios); termios.c_cflag &= ~CSIZE; switch (serial_mode->data_bits) { case 8: termios.c_cflag |= CS8; break; case 7: termios.c_cflag |= CS7; break; case 6: termios.c_cflag |= CS6; break; case 5: termios.c_cflag |= CS5; break; default: error (1, 0, "invalid serial byte size"); } switch (serial_mode->stop_bits) { case 2: termios.c_cflag |= CSTOPB; break; case 1: termios.c_cflag &= ~CSTOPB; break; default: error (1, 0, "invalid number of stop bits"); } switch (serial_mode->parity) { case UART_ODDPARITY: termios.c_cflag |= PARENB; termios.c_cflag |= PARODD; break; case UART_EVENPARITY: termios.c_cflag |= PARENB; termios.c_cflag &= ~PARODD; break; case UART_NOPARITY: termios.c_cflag &= ~PARENB; break; default: error (1, 0, "invalid parity serial_mode"); } if (baudrate (serial_mode->baud_rate, &speed) == -1) { error (0, 0, "warning: unsupported baud rate: %d", serial_mode->baud_rate); return (-1); } if (cfsetspeed (&termios, speed) == -1) error (1, 0, "could not set serial baud rate"); termios.c_cc [VTIME] = 1; termios.c_cc [VMIN] = 0; if (tcsetattr (s->fd, TCSANOW, &termios) == -1) error (1, 0, "could not set serial attributes"); #endif return (0); }
newterm(NCURSES_CONST char *name, FILE *ofp, FILE *ifp) { int value; int errret; SCREEN *current; SCREEN *result = 0; TERMINAL *its_term; START_TRACE(); T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp)); _nc_init_pthreads(); _nc_lock_global(curses); current = SP; its_term = (SP ? SP->_term : 0); /* this loads the capability entry, then sets LINES and COLS */ if (setupterm(name, fileno(ofp), &errret) != ERR) { int slk_format = _nc_globals.slk_format; /* * This actually allocates the screen structure, and saves the original * terminal settings. */ _nc_set_screen(0); /* allow user to set maximum escape delay from the environment */ if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { set_escdelay(value); } if (_nc_setupscreen(LINES, COLS, ofp, _nc_prescreen.filter_mode, slk_format) == ERR) { _nc_set_screen(current); result = 0; } else { assert(SP != 0); /* * In setupterm() we did a set_curterm(), but it was before we set * SP. So the "current" screen's terminal pointer was overwritten * with a different terminal. Later, in _nc_setupscreen(), we set * SP and the terminal pointer in the new screen. * * Restore the terminal-pointer for the pre-existing screen, if * any. */ if (current) current->_term = its_term; /* if the terminal type has real soft labels, set those up */ if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format)) _nc_slk_initialize(stdscr, COLS); SP->_ifd = fileno(ifp); typeahead(fileno(ifp)); #ifdef TERMIOS SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && !(cur_term->Ottyb.c_iflag & ISTRIP)); #else SP->_use_meta = FALSE; #endif SP->_endwin = FALSE; /* * Check whether we can optimize scrolling under dumb terminals in * case we do not have any of these capabilities, scrolling * optimization will be useless. */ SP->_scrolling = ((scroll_forward && scroll_reverse) || ((parm_rindex || parm_insert_line || insert_line) && (parm_index || parm_delete_line || delete_line))); baudrate(); /* sets a field in the SP structure */ SP->_keytry = 0; /* * Check for mismatched graphic-rendition capabilities. Most SVr4 * terminfo trees contain entries that have rmul or rmso equated to * sgr0 (Solaris curses copes with those entries). We do this only * for curses, since many termcap applications assume that * smso/rmso and smul/rmul are paired, and will not function * properly if we remove rmso or rmul. Curses applications * shouldn't be looking at this detail. */ #define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) SP->_use_rmso = SGR0_TEST(exit_standout_mode); SP->_use_rmul = SGR0_TEST(exit_underline_mode); /* compute movement costs so we can do better move optimization */ _nc_mvcur_init(); /* initialize terminal to a sane state */ _nc_screen_init(); /* Initialize the terminal line settings. */ _nc_initscr(); _nc_signal_handler(TRUE); result = SP; } } _nc_unlock_global(curses); returnSP(result); }
/* * Syntax for -m: * [port-type][test baudrate]:terminal-type * The baud rate tests are: >, <, @, =, ! */ void add_mapping(const char *port, char *arg) { MAP *mapp; char *copy, *p, *termp; copy = strdup(arg); mapp = malloc((u_int)sizeof(MAP)); if (copy == NULL || mapp == NULL) err(1, "malloc"); mapp->next = NULL; if (maplist == NULL) cur = maplist = mapp; else { cur->next = mapp; cur = mapp; } mapp->porttype = arg; mapp->conditional = 0; arg = strpbrk(arg, "><@=!:"); if (arg == NULL) { /* [?]term */ mapp->type = mapp->porttype; mapp->porttype = NULL; goto done; } if (arg == mapp->porttype) /* [><@=! baud]:term */ mapp->porttype = termp = NULL; else termp = arg; for (;; ++arg) /* Optional conditionals. */ switch(*arg) { case '<': if (mapp->conditional & GT) goto badmopt; mapp->conditional |= LT; break; case '>': if (mapp->conditional & LT) goto badmopt; mapp->conditional |= GT; break; case '@': case '=': /* Not documented. */ mapp->conditional |= EQ; break; case '!': mapp->conditional |= NOT; break; default: goto next; } next: if (*arg == ':') { if (mapp->conditional) goto badmopt; ++arg; } else { /* Optional baudrate. */ arg = strchr(p = arg, ':'); if (arg == NULL) goto badmopt; *arg++ = '\0'; mapp->speed = baudrate(p); } if (*arg == '\0') /* Non-optional type. */ goto badmopt; mapp->type = arg; /* Terminate porttype, if specified. */ if (termp != NULL) *termp = '\0'; /* If a NOT conditional, reverse the test. */ if (mapp->conditional & NOT) mapp->conditional = ~mapp->conditional & (EQ | GT | LT); /* If user specified a port with an option flag, set it. */ done: if (port) { if (mapp->porttype) badmopt: errx(1, "illegal -m option format: %s", copy); mapp->porttype = port; } #ifdef MAPDEBUG (void)printf("port: %s\n", mapp->porttype ? mapp->porttype : "ANY"); (void)printf("type: %s\n", mapp->type); (void)printf("conditional: "); p = ""; if (mapp->conditional & GT) { (void)printf("GT"); p = "/"; } if (mapp->conditional & EQ) { (void)printf("%sEQ", p); p = "/"; } if (mapp->conditional & LT) (void)printf("%sLT", p); (void)printf("\nspeed: %d\n", mapp->speed); #endif free(copy); }
tgetent(char *bufp, const char *name) { int errcode; int n; bool found_cache = FALSE; START_TRACE(); T((T_CALLED("tgetent()"))); _nc_setupterm((NCURSES_CONST char *) name, STDOUT_FILENO, &errcode, TRUE); /* * In general we cannot tell if the fixed sgr0 is still used by the * caller, but if tgetent() is called with the same buffer, that is * good enough, since the previous data would be invalidated by the * current call. * * bufp may be a null pointer, e.g., GNU termcap. That allocates data, * which is good until the next tgetent() call. The conventional termcap * is inconvenient because of the fixed buffer size, but because it uses * caller-supplied buffers, can have multiple terminal descriptions in * use at a given time. */ for (n = 0; n < TGETENT_MAX; ++n) { bool same_result = (MyCache[n].last_used && MyCache[n].last_bufp == bufp); if (same_result) { CacheInx = n; if (FIX_SGR0 != 0) { FreeAndNull(FIX_SGR0); } /* * Also free the terminfo data that we loaded (much bigger leak). */ if (LAST_TRM != 0 && LAST_TRM != cur_term) { TERMINAL *trm = LAST_TRM; del_curterm(LAST_TRM); for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) if (LAST_TRM == trm) LAST_TRM = 0; CacheInx = n; } found_cache = TRUE; break; } } if (!found_cache) { int best = 0; for (CacheInx = 0; CacheInx < TGETENT_MAX; ++CacheInx) { if (LAST_SEQ < MyCache[best].sequence) { best = CacheInx; } } CacheInx = best; } LAST_TRM = cur_term; LAST_SEQ = ++CacheSeq; PC = 0; UP = 0; BC = 0; FIX_SGR0 = 0; /* don't free it - application may still use */ if (errcode == 1) { if (cursor_left) if ((backspaces_with_bs = (char) !strcmp(cursor_left, "\b")) == 0) backspace_if_not_bs = cursor_left; /* we're required to export these */ if (pad_char != NULL) PC = pad_char[0]; if (cursor_up != NULL) UP = cursor_up; if (backspace_if_not_bs != NULL) BC = backspace_if_not_bs; if ((FIX_SGR0 = _nc_trim_sgr0(&(cur_term->type))) != 0) { if (!strcmp(FIX_SGR0, exit_attribute_mode)) { if (FIX_SGR0 != exit_attribute_mode) { free(FIX_SGR0); } FIX_SGR0 = 0; } } LAST_BUF = bufp; LAST_USE = TRUE; SetNoPadding(SP); (void) baudrate(); /* sets ospeed as a side-effect */ /* LINT_PREPRO #if 0*/ #include <capdefaults.c> /* LINT_PREPRO #endif*/ } returnCode(errcode); }
static void speed(void) { printf("%s\n", baudrate(cfgetospeed(&ts))); }
int main (int argc, char const * argv []) { static char const * optv [] = { "f:l:s:t:qv", "", "Serial Line Rate Tester", "f f\tsend file (f)", "l f\tserial port is (f) [" SERIAL_PORT "]", "s n\tport speed [ 115200 ]", "t n\ttransmit for (n) seconds [ 15 ]", "q\tquiet mode", "v\tverbose mode", (char const *) (0) }; int fd; signed c; optind = 1; char const *line = SERIAL_PORT; struct _file_ file = { -1, NULL }; speed_t speed = B115200; size_t time = 15; size_t chunk_size = 256; struct termios termios; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'f': file.name = optarg; if (!strcmp (file.name, "-")) file.file = STDIN_FILENO; else { file.file = open (file.name, O_BINARY | O_RDONLY); if (file.file == - 1) { error (1, errno, "could not open %s", file.name); } } break; case 'l': line = optarg; break; case 's': if (baudrate (uintspec (optarg, 0, UINT_MAX), & speed)) { error (1, 0, "could not set baud rate"); } break; case 't': time = uintspec (optarg, 0, SIZE_MAX); break; default: break; } } argc -= optind; argv += optind; fd = open (line, O_RDWR | O_NONBLOCK | O_NOCTTY); if (fd == - 1) { error (1, errno, "could not open %s", line); } if (fcntl(fd, F_SETFL, 0) == -1) { error (1, errno, "failed to set tty flags"); } if (tcgetattr (fd, & termios) == - 1) { error (1, errno, "could not get tty attributes"); } cfmakeraw (& termios); termios.c_cflag = CS8 | CREAD | CLOCAL; if (cfsetspeed (& termios, speed) == - 1) { error (1, errno, "could not set tty speed"); } if (tcsetattr (fd, TCSANOW, & termios) == - 1) { error (1, errno, "could not set tty attributes"); } ttysend (file.file, fd, time, chunk_size); close (fd); return (0); }
SCREEN * newterm(NCURSES_CONST char *name, FILE * ofp, FILE * ifp) { int errret; int slk_format = _nc_slk_format; SCREEN *current; #ifdef TRACE int t = _nc_getenv_num("NCURSES_TRACE"); if (t >= 0) trace(t); #endif T((T_CALLED("newterm(\"%s\",%p,%p)"), name, ofp, ifp)); /* this loads the capability entry, then sets LINES and COLS */ if (setupterm(name, fileno(ofp), &errret) == ERR) return 0; /* implement filter mode */ if (filter_mode) { LINES = 1; if (VALID_NUMERIC(init_tabs)) TABSIZE = init_tabs; else TABSIZE = 8; T(("TABSIZE = %d", TABSIZE)); clear_screen = 0; cursor_down = parm_down_cursor = 0; cursor_address = 0; cursor_up = parm_up_cursor = 0; row_address = 0; cursor_home = carriage_return; } /* If we must simulate soft labels, grab off the line to be used. We assume that we must simulate, if it is none of the standard formats (4-4 or 3-2-3) for which there may be some hardware support. */ if (num_labels <= 0 || !SLK_STDFMT(slk_format)) if (slk_format) { if (ERR == _nc_ripoffline(-SLK_LINES(slk_format), _nc_slk_initialize)) return 0; } /* this actually allocates the screen structure, and saves the * original terminal settings. */ current = SP; _nc_set_screen(0); if (_nc_setupscreen(LINES, COLS, ofp) == ERR) { _nc_set_screen(current); return 0; } /* if the terminal type has real soft labels, set those up */ if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format)) _nc_slk_initialize(stdscr, COLS); SP->_ifd = fileno(ifp); SP->_checkfd = fileno(ifp); typeahead(fileno(ifp)); #ifdef TERMIOS SP->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 && !(cur_term->Ottyb.c_iflag & ISTRIP)); #else SP->_use_meta = FALSE; #endif SP->_endwin = FALSE; /* Check whether we can optimize scrolling under dumb terminals in case * we do not have any of these capabilities, scrolling optimization * will be useless. */ SP->_scrolling = ((scroll_forward && scroll_reverse) || ((parm_rindex || parm_insert_line || insert_line) && (parm_index || parm_delete_line || delete_line))); baudrate(); /* sets a field in the SP structure */ SP->_keytry = 0; /* * Check for mismatched graphic-rendition capabilities. Most SVr4 * terminfo trees contain entries that have rmul or rmso equated to * sgr0 (Solaris curses copes with those entries). We do this only for * curses, since many termcap applications assume that smso/rmso and * smul/rmul are paired, and will not function properly if we remove * rmso or rmul. Curses applications shouldn't be looking at this * detail. */ #define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) SP->_use_rmso = SGR0_TEST(exit_standout_mode); SP->_use_rmul = SGR0_TEST(exit_underline_mode); #if USE_WIDEC_SUPPORT /* * XFree86 xterm can be configured to support UTF-8 based on environment * variable settings. */ { char *s; s = getenv("LC_ALL"); if (s == NULL || *s == '\0') { s = getenv("LC_CTYPE"); if (s == NULL || *s == '\0') { s = getenv("LANG"); } } if (s != NULL && *s != '\0' && strstr(s, "UTF-8") != NULL) { SP->_outch = _nc_utf8_outch; } } #endif /* compute movement costs so we can do better move optimization */ _nc_mvcur_init(); /* initialize terminal to a sane state */ _nc_screen_init(); /* Initialize the terminal line settings. */ _nc_initscr(); _nc_signal_handler(TRUE); T((T_RETURN("%p"), SP)); return (SP); }
/*** Fetch the output speed of the terminal. @function baudrate @treturn int output speed of the terminal in bits-per-second @see baudrate(3x) */ static int Pbaudrate(lua_State *L) { return pushintresult(baudrate()); }
int main (int argc, char const * argv []) { static char const * optv [] = { "cl:rs:t:qv", "", "Serial Line Rate Tester", "c\tconsume received data (do not output to stdout)", "l f\tserial port is (f) [" SERIAL_PORT "]", "r\tprint the receive data rate to stdout", "s n\tport speed [ 115200 ]", "t n\treceive for (n) seconds [ 10 ]", "q\tquiet mode", "v\tverbose mode", (char const *) (0) }; struct termios termios; char * line = SERIAL_PORT; double rate = 0; speed_t speed = B115200; size_t time = 10; size_t chunk_size = 256; flag_t flags = 0; signed consume = 0; signed rflag = 0; signed fd; signed c; optind = 1; while ((c = getoptv (argc, argv, optv)) != -1) { switch ((char) (c)) { case 'c': consume = 1; break; case 'r': rflag = 1; break; case 'l': line = optarg; break; case 's': if (baudrate (uintspec (optarg, 0, UINT_MAX), &speed)) { error (1, 0, "could not set baud rate"); } break; case 't': time = uintspec (optarg, 0, SIZE_MAX); break; case 'v': _setbits (flags, TTYRECV_VERBOSE); break; default: break; } } argc -= optind; argv += optind; fd = open (line, O_RDWR | O_NONBLOCK | O_NOCTTY); if (fd == - 1) { error (1, errno, "could not open %s", line); } if (fcntl(fd, F_SETFL, 0) == -1) { error (1, errno, "failed to set tty flags"); } if (tcgetattr (fd, & termios) == - 1) { error (1, errno, "could not get tty attributes"); } cfmakeraw (& termios); termios.c_cflag = CS8 | CREAD | CLOCAL; if (cfsetspeed (& termios, speed) == - 1) { error (1, errno, "could not set tty speed"); } if (tcsetattr (fd, TCSANOW, &termios) == -1) { error (1, errno, "could not set tty attributes"); } if (!consume) { rate = ttyrecv (fd, STDOUT_FILENO, time, chunk_size, flags); } else { rate = ttyrecv (fd, -1, time, chunk_size, flags); } if (rflag) { fprintf (stderr, "%.02f Kbps\n", rate); } close (fd); return (0); }
int main (int argc, char const * argv []) { static char const * optv [] = { "s:", PUTOPTV_S_FUNNEL, "copy one or more files to a serial device", "s n\tline speed is (n) [115200]", (char const *)(0) }; struct termios restore; struct termios current; speed_t speed = B115200; byte buffer [512]; signed c; while ((c = getoptv (argc, argv, optv)) != -1) { switch (c) { case 's': if (baudrate (uintspec (optarg, 0, UINT_MAX), &speed)) { error (1, 0, "could not set baud rate"); } break; default: break; } } argc -= optind; argv += optind; if (!isatty (STDOUT_FILENO)) { error (1, ENOTSUP, "stdout must be a serial line device"); } tcflush (STDOUT_FILENO, TCIFLUSH); tcgetattr (STDOUT_FILENO, &restore); memset (¤t, 0, sizeof (current)); current.c_cflag = speed | CS8 | CLOCAL | CREAD; current.c_iflag = IGNPAR; current.c_oflag = 0; current.c_lflag = 0; current.c_cc [VTIME] = 0; current.c_cc [VMIN] = 5; tcsetattr (STDOUT_FILENO, TCSANOW, ¤t); if (!argc) { copy (STDIN_FILENO, STDOUT_FILENO, buffer, sizeof (buffer)); } while ((argc) && (* argv)) { if (efreopen (* argv, "rb", stdin)) { copy (STDIN_FILENO, STDOUT_FILENO, buffer, sizeof (buffer)); } argc--; argv++; } tcsetattr (STDOUT_FILENO, TCSANOW, &restore); exit (0); }
/* ** curses_setup(exec_name) ** ** Startup ncurses */ void curses_setup( char *exec_name) { int status; static TERMTYPE term; char tty_filename[2048]; tty_init(); /** See if the terminal is in the terminfo data base. This call has two useful benefits, 1) it returns the filename of the terminfo entry, and 2) it searches only terminfo's. This allows us to abort before ncurses starts scanning the termcap file. **/ if ((status = _nc_read_entry(tty_basename, tty_filename, &term)) == 0) { const TERMTYPE *fallback = _nc_fallback(tty_basename); if (fallback) { term = *fallback; sprintf(tty_filename, "(fallback)%s", tty_basename); status = 1; } else { fprintf(stderr, "Terminal not found: TERM=%s\n", tty_basename); show_usage(exec_name); exit(1); } } if (status == -1) { fprintf(stderr, "Terminfo database is inaccessible\n"); exit(1); } /** This call will load the terminfo data base and set the cur-term variable. Only terminals that actually exist will get here so its OK to ignore errors. This is a good thing since ncurses does not permit (os) or (gn) to be set. **/ setupterm(tty_basename, 1, &status); /** Get the current terminal definitions. This must be done before getting the baudrate. **/ _nc_get_curterm(&cur_term->Nttyb); tty_baud_rate = baudrate(); tty_cps = (tty_baud_rate << 1) / tty_frame_size; /* set up the defaults */ replace_mode = TRUE; scan_mode = 0; char_count = 0; select_delay_type = debug_level = 0; char_mask = (meta_on && meta_on[0] == '\0') ? ALLOW_PARITY : STRIP_PARITY; /* Don't change the XON/XOFF modes yet. */ select_xon_xoff = initial_stty_query(TTY_XON_XOFF) ? 1 : needs_xon_xoff; fflush(stdout); /* flush any output */ tty_set(); go_home(); /* set can_go_home */ put_clear(); /* set can_clear_screen */ if (send_reset_init) { reset_init(); } /* I assume that the reset and init strings may not have the correct pads. (Because that part of the test comes much later.) Because of this, I allow the terminal some time to catch up. */ fflush(stdout); /* waste some time */ sleep(1); /* waste more time */ charset_can_test(); can_test("lines cols cr nxon rf if iprog rmp smcup rmcup", FLAG_CAN_TEST); edit_init(); /* initialize the edit data base */ if (send_reset_init && enter_ca_mode) { tc_putp(enter_ca_mode); put_clear(); /* just in case we switched pages */ } put_crlf(); ptext("Using terminfo from: "); ptextln(tty_filename); put_crlf(); if (tty_can_sync == SYNC_NEEDED) { verify_time(); } display_basic(); }
int tty_baudrate (void) { return baudrate (); }
static void list(int aflag, int hflag) { int i, d = 0; speed_t is, os; is = cfgetispeed(&ts); os = cfgetospeed(&ts); if (is == os) printf("speed %s baud;", baudrate(is)); else printf("ispeed %s baud; ospeed %s baud;", baudrate(is), baudrate(os)); if (aflag == 0) { for (i = 0; modes[i].m_name; i++) { if (modes[i].m_type == M_PCFLAG) d += listmode(ts.c_cflag, modes[i], aflag, 1); } d = 0; } if (sysv3 && aflag == 0) { putchar('\n'); } else { putchar(sysv3 ? ' ' : '\n'); printf("rows = %d%s columns = %d; " "ypixels = %d%s xpixels = %d%s\n", (int)ws.ws_row, aflag&&hflag ? "" : ";", (int)ws.ws_col, (int)ws.ws_ypixel, aflag&&hflag ? "" : ";", (int)ws.ws_xpixel, aflag&&hflag ? "" : ";"); } if ((ts.c_lflag&ICANON) == 0) printf("min = %d; time = %d;\n", (int)ts.c_cc[VMIN], (int)ts.c_cc[VTIME]); for (i = 0; modes[i].m_name; i++) { if (modes[i].m_flg&040) continue; switch (modes[i].m_type) { case M_NSEPAR: if (sysv3) break; case M_SEPAR: if (d && (modes[i].m_flg&8 || (modes[i].m_flg&(aflag?2:4)) == 0)) { fputs(modes[i].m_name, stdout); d = 0; } break; case M_IFLAG: d += listmode(ts.c_iflag, modes[i], aflag, d); break; case M_OFLAG: d += listmode(ts.c_oflag, modes[i], aflag, d); break; case M_CFLAG: d += listmode(ts.c_cflag, modes[i], aflag, d); break; case M_LFLAG: d += listmode(ts.c_lflag, modes[i], aflag, d); break; case M_CC: if (hflag == 0) d += listchar(ts.c_cc, modes[i], aflag, d); break; } if (d >= 72 && aflag == 0) { putchar('\n'); d = 0; } } if (d && aflag == 0) putchar('\n'); }