/* This file contains the IMPRESS device dependent subroutines for */
/* use with plplot. */

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

#define SET_HV_SYSTEM   0315
#define OPBYTE1         031
#define OPBYTE2         0140
#define SET_ABS_H       0207
#define SET_ABS_V       0211
#define OPWORDH1        0
#define OPWORDH2        150
#define OPWORDV1        0
#define OPWORDV2        150
#define ENDPAGE         0333

static FILE *OutFile;
static int FirstClear=1;

/* Open file.  Set up for graphics. */
void impini()
{
      char FileName[80];

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

      if ((OutFile = fopen(FileName,"w")) == NULL)  {
          printf("Error opening %s \n",FileName);
          exit(1);
      }
      fprintf(OutFile,"@Document(Language ImPress, jobheader off)");
      fprintf(OutFile,"%c%c",SET_HV_SYSTEM,OPBYTE1);
      fprintf(OutFile,"%c%c%c",SET_ABS_H,OPWORDH1,OPWORDH2);
      fprintf(OutFile,"%c%c%c",SET_ABS_V,OPWORDV1,OPWORDV2);
      fprintf(OutFile,"%c%c",SET_HV_SYSTEM,OPBYTE2);
}

/* Sets the IMPRESS to text mode */
void imptex()
{
}

/* Sets the IMPRESS to graphics mode */
void impgra()
{
}

/* Form feed */
void impclr()
{
      if(FirstClear) 
        FirstClear = 0;
      else
        fprintf(OutFile,"%c",ENDPAGE);
}

/* May put something here someday */
void impcol(colour)
int colour;
{
}

#define CREATE_PATH   0346
#define DRAW_PATH     0352
#define OPTYPE        017
#define COUNT1        0
#define COUNT2        2

void implin(x1,y1,x2,y2)
int x1,y1,x2,y2;
{
      fprintf(OutFile,"%c%c%c",CREATE_PATH,COUNT1,COUNT2);
      fprintf(OutFile,"%c%c%c%c",x1/256,x1%256,y1/256,y1%256);
      fprintf(OutFile,"%c%c%c%c",x2/256,x2%256,y2/256,y2%256);
      fprintf(OutFile,"%c%c",DRAW_PATH,OPTYPE);

}
      
/* Close graphics file */
void imptid()
{
      fprintf(OutFile,"%c",ENDPAGE);
      fclose(OutFile);
}
