#include #include #include /** ** showtty0 ** displays some of current tty settings, using MANY tests and prints **/ void showbaud( int thespeed ); void show_some_flags( struct termios *ttyp ); void show_lflags(tcflag_t); void show_iflags(tcflag_t); int main() { struct termios ttyinfo; /* this struct holds tty info */ if ( tcgetattr( 0 , &ttyinfo ) == -1 ){ /* get info */ perror( "cannot get params about stdin"); exit(1); } /* show info */ showbaud ( cfgetospeed( &ttyinfo ) ); /* get + show baud rate */ printf("The erase character is ascii %d, Ctrl-%c\n", ttyinfo.c_cc[VERASE], ttyinfo.c_cc[VERASE]-1+'A'); printf("The line kill character is ascii %d, Ctrl-%c\n", ttyinfo.c_cc[VKILL], ttyinfo.c_cc[VKILL]-1+'A'); show_some_flags( &ttyinfo ); /* show misc. flags */ return 0; } void showbaud( int thespeed ) /* * prints the speed in english */ { printf("the baud rate is "); switch ( thespeed ){ case B300: printf("300\n"); break; case B600: printf("600\n"); break; case B1200: printf("1200\n"); break; case B1800: printf("1800\n"); break; case B2400: printf("2400\n"); break; case B4800: printf("4800\n"); break; case B9600: printf("9600\n"); break; default: printf("Fast\n"); break; } } void show_some_flags( struct termios *ttyp ) /* * show the values of two of the flag sets_: c_iflag and c_lflag * adding c_oflag and c_cflag is pretty routine - just tedious */ { show_iflags( ttyp->c_iflag ); show_lflags( ttyp->c_lflag ); } /* * use & with mask to test many of the bits in a flagset -- tedious */ void show_iflags( tcflag_t settings ) { if ( settings & IGNBRK ) printf("ON Ignore the break condition\n"); else printf("OFF Ignore the break condition\n"); if ( settings & BRKINT ) printf("ON SIGNAL interrupt on break\n"); else printf("OFF SIGNAL interrupt on break\n"); if ( settings & IGNPAR ) printf("ON Ignore chars with parity errors\n"); else printf("OFF Ignore chars with parity errors\n"); if ( settings & PARMRK ) printf("ON Mark parity errors\n"); else printf("OFF Mark parity errors\n"); if ( settings & INPCK ) printf("ON Enable input parity check\n"); else printf("OFF Enable input parity check\n"); if ( settings & ISTRIP ) printf("ON Strip character\n"); else printf("OFF Strip character\n"); if ( settings & INLCR ) printf("ON Map NL to CR on input\n"); else printf("OFF Map NL to CR on input\n"); if ( settings & IGNCR ) printf("ON Ignore CR\n"); else printf("OFF Ignore CR\n"); if ( settings & ICRNL ) printf("ON Map CR to NL on input\n"); else printf("OFF Map CR to NL on input\n"); if ( settings & IXON ) printf("ON Enable start/stop output control\n"); else printf("OFF Enable start/stop output control\n"); if ( settings & IXOFF ) printf("ON Enable start/stop input control\n"); else printf("OFF Enable start/stop input control\n"); } /* * test and show status of several local flags */ void show_lflags(tcflag_t settings) { if ( settings & ISIG ) printf("ON Enable signals\n"); else printf("OFF Enable signals\n"); if ( settings & ICANON ) printf("ON Canonical input (erase and kill)\n"); else printf("OFF Canonical input (erase and kill)\n"); if ( settings & ECHO ) printf("ON echo\n"); else printf("OFF echo\n"); if ( settings & ECHOE ) printf("ON Echo ERASE as BS-SPACE-BS\n"); else printf("OFF Echo ERASE as BS-SPACE-BS\n"); if ( settings & ECHOK ) printf("ON Echo KILL by starting new line\n"); else printf("OFF Echo KILL by starting new line\n"); }