#include <stdio.h>

int main(argc,argv)
     int argc;
     char **argv;
{
  int st;
  char c[4];

  if(argc != 2) {
    fprintf(stderr,"%s [left|right]\n",argv[0]);
    exit(1);
  }
  
  if(!strcmp("left", argv[1])) {
    /* just skip the first 2 */
    read(0,c,2);
  }
   
  for(;;) {
    st = read(0,c,2);
    if (st == 0)
      break;
    if (st < 0)
      {
	perror("read");
	exit(1);
      }
    st = write(0,c,2);
    if (st < 0)
      {
	perror("write");
	exit(1);
      }
    st = read(0,c,2);
    if (st == 0)
      break;
    if (st < 0)
      {
	perror("read2");
	exit(1);
      }
  }
  exit(0);
  
}
