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

#define TRUE   1
#define FALSE  0

/*****************/
/*  main         */
/**************************************************************/

main(int argc, char *argv[])
{
FILE *ifp, *ofp;
char ch;
int index=0;

if(argc != 3)
  {
  printf("\x07\nUsage:  %s <input text filename> <output script filename>\n\n", argv[0]);
  exit(FALSE);
  }

if((ifp=fopen(argv[1],"r")) == NULL)
  {
  printf("\x07\nCannot open %s!\n\n",argv[1]);
  exit(FALSE);
  }

if(ofp=fopen(argv[2],"r"))
  {
  printf("\x07\nFile %s already exists!\n\n",argv[2]);
  fclose(ifp);
  fclose(ofp);
  exit(FALSE);
  }

if((ofp=fopen(argv[2],"w")) == NULL)
  {
  printf("\x07\nCannot create %s!\n\n",argv[2]);
  fclose(ifp);
  exit(FALSE);
  }

fputs("/* Terminus Script File */\n", ofp);
fputs("/* Created with TEXT2SCP by Don Lester */\n", ofp);

while((ch=getc(ifp)) != EOF)
  {
  if(index==0)
    fprintf(ofp, "SEND \"");

  if(ch=='\x22')
    fprintf(ofp, "\\\"");
  else
    if(ch=='\x27')
      fprintf(ofp, "\\'");
  else
    if(ch=='\x5C')
      fprintf(ofp, "\\\\");
  else
    if(ch=='\xD');
  else
    if(ch=='\xA')
      fprintf(ofp, "\\r");
  else
    if(ch=='\x1B')
      fprintf(ofp, "\\e");
  else
    if(ch=='!')
      fprintf(ofp, "^!");
  else
    if(ch=='^')
      fprintf(ofp, "^^");
  else
    if(ch=='~')
      fprintf(ofp, "^~");
  else
    if(ch=='\x0C')
      fprintf(ofp, "\\f");
  else
    if(ch=='\x09')
      fprintf(ofp, "\\t");
  else
    fprintf(ofp, "%c", ch);

  index++;

  if((index > 200) && (ch != '\xA'))
    {
    index=0;
    fprintf(ofp, "\"\n");
    }    

  if(ch=='\xA')
    {
    fprintf(ofp, "\"\n");
    index=0;
    }
  }
fputs("/* End of TEXT2SCP script */\n", ofp);

fclose(ifp);
fclose(ofp);
}
