/*
	Converts between Flexowriter and ASCII code.

	(C) Copyright 2001 by Mogens Kjaer


   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>

extern unsigned char flx2a(char, int*);
extern unsigned char remove_parity(unsigned char);

#define BUFFERSIZE 1024

int main()
{
  int uppercase;
  int i,blen;
  char buffer[BUFFERSIZE];
  unsigned char c1,c2;

  uppercase=0;

  while( (blen=read(0, buffer, BUFFERSIZE))>0 )
  {
    for(i=0; i<blen; i++)
    {
      c1=remove_parity(buffer[i]);

      if(c1==64)
        printf("\n");
      else
      {
        c2=flx2a(c1, &uppercase);
	if(c2 == 255)
	{
	  if(c1 != 58 && c1 != 60) printf("#%3.3d", c1);
	}
	else
	{
	  printf("%c", c2);
	}
      }
    }
  }
  return 0;
}

