IT

canonical

kio467 2014. 10. 19. 20:58

#include<stdio.h>

#include<termios.h>

#define QUESTION"do ya wanna "


int get_response(char *q)

{

printf("%s? (y/n) : ",q);

while(1)

{

switch(getchar())

{

case 'y':

case 'Y': return 0;

case 'n':

case 'N':

case EOF: return 1;

}

}

}


/*

int main()

{

int res;

res = respon(que);

return res;

}

*/

int set_crmode()

{

struct termios ttystate;


tcgetattr(0,&ttystate);

ttystate.c_lflag &= ~ICANON;

ttystate.c_cc[VMIN] = 1;

tcsetattr(0, TCSANOW, &ttystate);

}


int tty_mode(int how)

{

static struct termios original_mode;

if(how ==0)

{

tcgetattr(0,&original_mode);

return 0;

}

return tcsetattr(0, TCSANOW, &original_mode);

}



int main()

{

int response;

tty_mode(0);

set_crmode();

response = get_response(QUESTION);

tty_mode(1);

return response;

}