This is the code (found somewhere in the net) from which I've extracted a function to be used by my program.
Even studying it, I still don't understand the great part of these lines...
By the way I guess this program deals with the terminal specifically, which is not what I really need, am I wrong?
Code:
#include <termios.h>
#include <iostream>
int main(void)
{
int count;
int jndex;
int result;
int virgin;
char echoed_data;
char in_buffer[80];
struct termios tp1;
struct termios tp2;
virgin=1;
echoed_data='X';
printf("Type a space character to exit.\n");
tcgetattr(0,&tp1);
tp2=tp1;
tp2.c_iflag&=~ICRNL;
tp2.c_lflag&=~ICANON;
tp2.c_lflag&=~ECHO;
tp2.c_cc[VMIN ]=1;
tp2.c_cc[VTIME]=0;
tp2.c_cc[VINTR]=0xFF;
tp2.c_cc[VSUSP]=0xFF;
tp2.c_cc[VQUIT]=0xFF;
tcsetattr(0,TCSANOW,&tp2);
do {
in_buffer[0]=0;
count=read(0,in_buffer,1);
if(virgin)
{
virgin=0;
tp2.c_cc[VMIN]=0;
tcsetattr(0,TCSANOW,&tp2);
}
if(count>0)
echoed_data=in_buffer[0];
printf("%d: ", echoed_data);
printf("%d\n", 256 + echoed_data);
fflush(stdout);
} while(echoed_data!=0x20);
printf("\n");
tcsetattr(0,TCSANOW,&tp1);
return 0;
}