1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <stdio.h> #include <termios.h>
main() { struct termios ttyinfo; if (tcgetattr(0, &ttyinfo) == -1) { perror("cannot get params about stdin"); exit(1); }
showband(cfgetospeed(&ttyinfo)); 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); }
showband(int thespeed)
{ 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; } }
struct flaginfo {int fl_value; char * fl_name};
struct flaginfo input_flags[] = { IGNBRK, "Ignore break condition", BRKINT, "Signal interrupt on break", IGNPAR, "Ignore chars with parity errors", PARMRK, "Mark parity errors", INPCK, "Enable input parity check", ISTRIP, "Strip character", INLCR, "Map NL to CR on input", IGNCR, "Ignore CR", ICRNL, "Map CR to NL on input", IXON, "Enable start/stop ouput control", IXOFF, "Enable start/stop input control", 0, NULL };
struct flaginfo local_flags[] = { ISIG, "Enable signals", ICANON, "Canonical input(erase and kill)", ECHO, "Enable echo", ECHOE, "Echo ERASE as BS-SPACE-BS", ECHOK, "Echo KILL by starting new line", 0, NULL };
show_some_flags(struct termios *ttyp)
{ show_flagset(ttyp->c_iflag, input_flags); show_flagset(ttyp->c_lflag, local_flags); }
show_flagset(int thevalue, struct flaginfo thebitnames[])
{ int i; for (i = 0; thebitnames[i].fl_value; ++i) { printf("%s is ", thebitnames[i].fl_name); if (thevalue & thebitnames[i].fl_value) printf("ON\n"); else printf("OFF\n"); } }
|