/*    msp1k_c                    Feb 24th 1991 1pm
*    try  printing this file ? 
*    driving Citizen MSP-10 printer ( = FX-80 ) from Small-C 
*/

#include <stdio_h>
char file[42], c;
int  fd, *msp;

main() {
   printf("Enter name of file to be sent to MSP-10 printer:\n");
   gets(file);
   fd = fopen(file,"r");
   if(fd == NULL)   {
      printf("Unable to open file: %s\n",file);
      printf("\nAny key to exit\n");
      getchar(c);
      exit(1);
   }
   else   {   
      printf("Ready to send %s to MSP-10\n",file);
   }
   msp = fopen("ser1hc","w");
   printf("fd = %d   msp = %d\n",fd,msp);
   printf("If above looks ok [SPACE BAR] to continue\n  x to exit\n");
   c = getchar();
   if(c == 'x') {
      exit(1);
   }
   if (msp != NULL)  {
      stdprint(msp);
      epsfont(msp);
      fputc(27,msp);          /*  sets printer for    */
      fputc(109,msp);         /*     Standard         */   
      fputc(0,msp);           /*       EPSON          */
      fputc(EOF,msp);         /*   Character Set      */       
      printfile(fd,msp);   
      fclose(fd);
      leave(msp);
   }      
   printf(" + once more to really exit(1); !!\n");
   getchar(c);
   exit(1);
}

/* E N D  O F  M A I N - - - - - - - - - - - - - - - - - - - */

/*  FUNCTION CALLS : 

 stdprint(msp)       standardize printer to default settings 
 epsfont(msp)        set printer for Epson FX styles
 ibmfont(msp)        set printer for ibm styles
 newline(msp)        CR + LF + '\n'
 leave(msp)          close file to printer and leave this exercise
 printit(c,msp)      printer does one character at a time
 printfile(fd,msp)   send entire file to printer
 epsstd(c,msp)       printer does entire Epson standard set
 epsgra(c,msp)       printer does entire Epson graphics set
 ibmstd(c,msp)       printer does entire IBM character set
 ibmacc(c,msp)       printer does entire IBM accented character set

*/

/*  * STDPRINT set printer to power on defaults *  */
stdprint(msp)
   int msp; {
      printf("@ stdprint : msp = %d\n",msp);
      if (msp != NULL)   {
         fputc(27,msp);
         fputc(64,msp);
         newline(msp);
      }
   }  

/*  * EPSFONT  select Epson FX fonts *  */
epsfont(msp)
   int msp; {
      printf("@ epsfont : msp = %d\n",msp);
      if (msp != NULL)  {
         /* fputs("@ epsfont",msp);    */
         newline(msp);
         fputc(EOF,msp);
         fputc(27,msp);
         fputc(126,msp);
         fputc(53,msp);
         fputc(0,msp);
         fputc(EOF,msp);
      }
   }

/*  * IBMFONT select IBM Graphics fonts *  */
ibmfont(msp)
   int msp; {
      printf("@ ibmfont : msp = %d\n",msp);
      if (msp != NULL)  {
         /* fputs("@ ibmfont",msp);    */
         newline(msp);
         fputc(27,msp);
         fputc(126,msp);
         fputc(53,msp);
         fputc(1,msp);
      }
   }

/*  * NEWLINE line feed and carriage return *  */
newline(msp)
   int msp; {
      /* printf("@ newline : msp = %d\n",msp);     */
      if (msp != NULL)  {
         fputc(10,msp);
 fputc(13,msp);
 fputc(138,msp);
 fputc(141,msp);
         printf("\n");
      }
   }

/*  * LEAVE  leave this program *  */
leave(msp)
   int msp; {
      printf("\n@ leave : msp = %d\n",msp);
      if (msp != NULL)  {
         printf("\n\nAny key when you're ready to leave\n");
         getchar();
         fclose(msp); 
      }
   }

/*  * PRINTIT  print to screen and to printer *  */
printit(c,msp)
   char c;
   int msp; {
      if (msp != NULL)  {
         fputc(c,msp);
         fputc(c,stdout);
      }
   }

/*  * PRINTFILE prints file to stdout & to printer *  */
printfile(fd,msp)
   int fd, msp;   {
      char c;
      int i;
      while(((msp != NULL) && (( c = getc(fd)) != EOF)))  {
         fputc(c,msp);
         fputc(c,stdout);
         if(iscntrl(c)) {
            if( c == 10 )  {
               fputc(10,msp);
       fputc(13,msp);             
       fputc(138,msp);
       fputc(141,msp); 
            }
            if( c == 9 )   {
               fputc(27,msp);
       fputc(102,msp);
       fputc(0,msp);
               fputc(3,msp);  /* sets printhead 3 spaces right  */
    } 
         }
      }
   }

/*  *  E P S O N   S T A N D A R D   C H A R A C T E R   S E T   *  */
epsstd(c,msp)
   char c;
   int msp; {
      printf("@ epsstd : msp = %d\n",msp);
      if (msp != NULL)  {
         printf("@ epsstd Doing Standard Epson Character Set\n");
         fputc(EOF,msp);
         stdprint(msp);
         epsfont(msp);
         fputc(27,msp);
         fputc(109,msp);
         fputc(0,msp);
         fputc(EOF,msp);
         for(c=32; c<=126; c++)  {
            printit(c,msp);
         }
         newline(msp);   
         for(c=161; c<=254; c++) {
            printit(c,msp);
         }
         newline(msp);   
      }
   }

/*  *  E P S O N   G R A P H I C S   S E T   *  */
epsgra(c,msp)
   char c;
   int msp; {
      printf("@ epsgra : msp = %d\n",msp);
      if (msp != NULL)  {
         fputs("@ epsgra",msp);
         fputc(EOF,msp);
         printf("Doing Epson Graphics Only Characters\n");
         stdprint(msp);
         epsfont(msp);
         fputc(27,msp);
         fputc(109,msp);
         fputc(4,msp);
         fputc(EOF,msp);
         for(c=128; c<=159; c++) {
            printit(c,msp);
         }
         newline(msp);   
      }
   }

/*  *  I B M   S T A N D A R D   C H A R A C T E R   S E T   *  */
ibmstd(c,msp)
   char c;
   int msp; {
      printf("@ ibmstd : msp = %d\n",msp);
      if (msp != NULL)  {
         fputs("@ ibmstd",msp);
         newline(msp);
         printf("Doing IBM Standard Character Set\n");
         stdprint(msp);
         ibmfont(msp);
         fputc(27,msp);
         fputc(55,msp);
         fputc(EOF,msp);
         printit(21,msp);
         for(c=32; c<=126; c++)  {
            printit(c,msp);
         }
         newline(msp);
         fputs("IBM Extended",msp);
         newline(msp);
         fputc(EOF,msp);
         for(c=160; c<=254; c++) {
            printit(c,msp);
         }
         newline(msp);   
      }
   }

/*  * I B M  A C C E N T E D   C H A R A C T E R S   *  */
ibmacc(c,msp)
   char c;
   int msp; {
      printf("@ ibmacc : msp = %d\n",msp);
      if (msp != NULL)  {
         fputs("@ ibmacc",msp);
         newline(msp);
         printf("Doing IBM Accented Characters Set\n");
         stdprint(msp);
         ibmfont(msp);
         fputc(27,msp);
         fputc(54,msp);
         for(c=3; c<=6; c++)  {
            printit(c,msp);
         } 
         for(c=128; c<=159; c++) {
            printit(c,msp);
         }
         newline(msp);   
      }
   }

