/***********
 * THIS PROGRAM IS WRITTEN TO CONVERT THE Language.DOC INTO A FILE WHICH
 * DOESN'T CONTAIN ANY <CSI> (0x9B) CODES ANYMORE.
 *
 * TO COMPILE USING DICE 2.06.18R:
 * DCC ConvDoc.c -oConvDoc -1.3 -r -v
 *
 *
 * © Klaas  van Gend
 *   Hoekerstraat 9b
 *   5987 AN  EGCHEL
 *   The Netherlands
 *
 */

#include <stdio.h>
#include <stdlib.h>

FILE *infile = NULL;
FILE *outfile = NULL;


main (int argc, char **argv)
{
  int dummy;

  if (argc != 3 || argv[1][0] == '?')
    {
      printf ("%s <infile> <outfile>\n", argv[0]);
      printf ("To convert docs with 0x9b-codes to standard ASCII.\n");
      Quit ();
    }


  if (!(infile = (FILE *) fopen (argv[1], "r")))
    {
      printf ("'%s' not found...\n", argv[1]);
      Quit ();
    }
  if (!(outfile = (FILE *) fopen (argv[2], "w")))
    {
      printf ("Can't open output-file '%s'\n", argv[2]);
      Quit ();
    }
  printf ("Files successfully opened\n");

/*** start checking***/
  while ((dummy = fgetc (infile)) != EOF)
    {
      if (dummy == 0x9b)	/* BINGO */
	{
	  while (fgetc (infile) != 'm') ;
	  continue;
	}
      fputc (dummy, outfile);
    }
  printf ("Finished...\n");
  Quit ();
}

Quit ()
{
  if (outfile)
    fclose (outfile);
  if (infile)
    fclose (infile);
  exit (0);
}
