/*
 *   ami2win v 1.1 - Copyright © 2001 Kalle Räisänen.
 *   Converts Unix/Amiga-textfiles to Windows format.
 */

#include <stdio.h>

#include <exec/types.h>

#include <dos/dos.h>

#include <clib/dos_protos.h>

#define NL    10
#define CR    13
#define TRUE   1
#define FALSE  0

static UBYTE *VersTag = "\0 $VER: ami2win 1.1";

int compare(char *s, char *t)
{
   int i = 0;

   while(s[i] == t[i])
      {
      if(s[i] == '\0')
         return 1;
      i++;
      }
   return 0;
}

main(int argc, char *argv[])
{
   BPTR file, file2;
   int ch, show = FALSE;

   if(argc > 2)
      {
      if((argc > 3) && (compare(argv[3], "--show") || compare(argv[3], "-s")))
         show = TRUE;
      else
         printf("%s: working...",argv[0]);
      if((file = Open(argv[1], MODE_OLDFILE)) && (file2 = Open(argv[2], MODE_NEWFILE)))
         {
         while ((ch = FGetC(file)) != EOF)
            {
            if(show)
               printf("%c", ch);
            if(ch != CR)
               FPutC(ch, file2);
            if(ch == NL)
               FPutC(CR, file2);
            }
         Close(file);
         Close(file2);
         printf("\r%s: done!!!   \n",argv[0]);
         }
      else
         {
         printf("\n%s: File-error!!!\n",argv[0]);
         return 10;
         }
      }
   else
      {
      printf("Usage: %s source destination [--show|-s]\n",argv[0]);
      return 10;
      }
   return 0;
}
