/* This file contains the tektronix dependent routines for use with plplot. */

/* Define graphics control characters. */
#define BS    8
#define HT    9
#define LF   10
#define VT   11
#define FF   12
#define CR   13
#define CAN  24
#define EM   25
#define ESC  27
#define FS   28
#define GS   29
#define US   31

#include <stdio.h>
#include "plplot.h"

static FILE *OutFile;
static int FirstClear=1;

/* Open file. */
void tekini()
{
      char FileName[80];

      printf("Enter file to receive tektronix graphics commands. ");
      scanf("%s",FileName);

      if ((OutFile = fopen(FileName,"w")) == NULL)  {
          printf("Error opening %s \n",FileName);
          exit(1);
      }
}

/* Sets the tektronix to text mode */
void tektex()
{
    fprintf(OutFile,"%c",US);
}

/* Sets the tektronix to graphics mode */
void tekgra()
{
    /* Nothing has to be done here */
}

/* Clears the tektronix screen */
void tekclr()
{
      if(FirstClear) 
        FirstClear = 0;
      else
        fprintf(OutFile,"%c%c",ESC,FF);
}

/* Change color */
void tekcol(colour)
int colour;
{
}

/* Draws a line in the current colour from (x1,y1) to (x2,y2) */
void teklin(x1,y1,x2,y2)
int x1,y1,x2,y2;
{
    int hy,ly,hx,lx;

    fprintf(OutFile,"%c",GS);
    hy = y1/32 + 32;
    ly = y1 - (y1/32)*32 + 96;
    hx = x1/32 + 32;
    lx = x1 - (x1/32)*32 + 64;
    fprintf(OutFile,"%c%c%c%c",hy,ly,hx,lx);
    hy = y2/32 + 32;
    ly = y2 - (y2/32)*32 + 96;
    hx = x2/32 + 32;
    lx = x2 - (x2/32)*32 + 64;
    fprintf(OutFile,"%c%c%c%c",hy,ly,hx,lx);
}

/* Close file */
void tektid()
{
   fclose(OutFile);
}

