본문 바로가기

IT

terminal info? status? 를 보여주는 프로그램

#include <stdio.h>

#include <termios.h>


main()

{

struct termios info;

if(tcgetattr(0,&info)==-1)

{

perror("cannot get params about stdin");

exit(1);

}


showbaud(cfgetospeed(&info));

printf("The erase character is ascii %d, ctrl -%c\n",info.c_cc[VERASE],info.c_cc[VERASE]-1+'A' );

printf("The line kill character is asciii %d, ctrl -%c\n",info.c_cc[VKILL], info.c_cc[VKILL]-1+'A');

show_some_flags(&info);

}




showbaud(int thespeed)

{

printf("the baud rate is ");


switch(thespeed)

{

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",

PARMRK,"mark parity errors",

INPCK,"enable input parity check",

ISTRIP,"strip character",

INLCR,"map nl to cr on input",

IGNCR,"ignore cr",

ICRNL,"map ct to nl on input",

IXON,"enable start/stop output",

IXOFF, "enable start/stop input off",

0, NULL

};



struct flaginfo local_flags[] = {

ISIG, "enable signals",

ICANON, "canoncal input",

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 value, struct flaginfo bitname[])

{

int i;

for (i = 0; bitname[i].fl_value; i++)

{

printf("%s is ", bitname[i].fl_name);

if(value & bitname[i].fl_value)

printf("on\n");

else

printf("off\n");

}


}



'IT' 카테고리의 다른 글

more1.c  (2) 2014.10.08
창크기 알려주는 프로그램  (0) 2014.10.08
아규먼트로 y를 주면 echo를 켜는 프로그램.  (0) 2014.10.08
echo 상태를 나타내는 코드  (0) 2014.10.08
fcntl을 이용한 (뭐하는지 모르겠는) 코드  (0) 2014.10.08