Hi guys,

need a little help from you UNIX experts. I should help a friend of mine to
port a little application from Unix to Windows. This application reads from
three terminals the user input and writes messages. I googled a bit
finding: Windows implementation of POSIX, CygWin and some other stuff out
on the net but I'm getting more confused!

The application reads chars from the terminals with this function:

char KeyStrokeAscii()
{
   char res;
   static char buf[10];
   static int total, next;

   struct termio tbuf;
   struct termio tbufsave;

   if(ioctl(0, TCGETA, &tbuf) == -1)
       perror("ioctl");

   tbufsave = tbuf;
   tbuf.c_lflag &= ~(ICANON | ECHO);
   tbuf.c_cc[4] = sizeof(buf);   /* MIN */
   tbuf.c_cc[5] = 2;             /* TIME */
   if(ioctl(0, TCSETAF, &tbuf) == -1)
       perror("ioctl2");

   if(next >= total)
      switch(total = read(0, buf, sizeof(buf))) {
      case -1:
          perror("read");
      case 0:
          perror("Mysterious EOF");
          exit(0);
      default:
          next = 0;
      }

   res= buf[next++];
   if(ioctl(0, TCSETAF, &tbufsave) == -1)
      perror("ioctl3");

   return(res);
}

and by 'gets(...)' writes by a simple 'printf(...)'.

As far I understood, each terminal is connected through a serial port and
each one's handling has his own application running.

Can someone explain me:
 - what does this 'KeyStrokeAscii' do?
 - why and how does 'gets(...)' get input from the terminal?
 - why and how does 'printf(...)' print out on the terminal?
 - under windows, what should I do: simply read and write chars on the
serial port?

Thanks,
Cabbi

Reply via email to