home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / CKPM5X_S.ZIP / CKODRV.C < prev    next >
C/C++ Source or Header  |  1990-04-18  |  25KB  |  948 lines

  1. /******************************************************************************
  2. File name:  ckodrv.c    Rev: 01  Date: 02-Mar-90 Programmer: C.P.Armstrong
  3.  
  4. File title: Drivers for different types of plot dumping.
  5.  
  6. Contents:   
  7.  
  8. Modification History:
  9.     01  02-Mar-90   C.P.Armstrong   created
  10.  
  11. ******************************************************************************/
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <stdio.h>      /* This for FILE */
  15. #include <fcntl.h>      /* These two     */
  16. #include <io.h>         /* for open()    */
  17. #include <sys\types.h>
  18. #include <sys\stat.h>
  19. #include <process.h>
  20. #include "ckcasc.h"
  21. #include "ckotek.h"
  22.  
  23.  
  24. int     hpgl_open( void );
  25. void    hpgl_move(int,int);
  26. void    hpgl_draw(int,int);
  27. void    hpgl_mover(int,int);
  28. void    hpgl_drawr(int,int);
  29. void    hpgl_plot(int,int);
  30. void    hpgl_plotr(int,int);
  31. void    hpgl_close(void);
  32. void    hpgl_init(void);
  33. void    hpgl_print(char *);
  34. void    hpgl_rewind(void);
  35. int     hpgl_dump(void);
  36.  
  37. extern int dump_plot;
  38. extern int dump_format;
  39.  
  40. char command[80];
  41.  
  42. /* Screendump definitions */
  43. #define SCRDMPCOM "detach print screen"
  44. #define SCRDMP    "screen"
  45.  
  46.  
  47. /* The HPGL specific globals */
  48. FILE far * hpgl_stream=NULL;                /* Stream handle */
  49. int  far hpgl_pen=4;
  50. char far hpgl_file[]={"HPGL.PLT"};          /* Default output filename */
  51.  
  52. /******************************************************************************
  53. Function:       print_screen()
  54.  
  55. Description:    Dumps a character screen out to the printer.
  56.  
  57. Syntax:         void print_screen(screen_buffer)
  58.                     char far * screen_buffer;  Pointer to the screen buffer
  59.  
  60. Returns:        nothing
  61.  
  62. Mods:           04-Mar-90 C.P.Armstrong created
  63.  
  64. ******************************************************************************/
  65. void print_screen(screen_buffer)
  66.     char far * screen_buffer;
  67.     {
  68.     char line_buffer[83];
  69.     int dump_hand;
  70.     int charloop,lineloop;
  71.     int offset;
  72.  
  73.     line_buffer[80]=CR;
  74.     line_buffer[81]=LF;
  75.     line_buffer[82]=0;
  76.     
  77.     if((dump_hand = fileopen(SCRDMP))==0)
  78.         return;
  79.  
  80.     for(lineloop=0;lineloop<24;lineloop++)
  81.         {
  82.         offset = lineloop*160;
  83.         for(charloop=0;charloop<80;charloop++)
  84.             {
  85.             line_buffer[charloop] = screen_buffer[offset+(charloop<<1)];
  86.             }
  87.         write(dump_hand,line_buffer,82);
  88.         }
  89.     
  90.     line_buffer[0]=26;
  91.     write(dump_hand,line_buffer,1);
  92.     close(dump_hand);
  93.  
  94.     /* Spawn an asynchronous system command - don't use the kermit version */
  95.     /* of system().                                                        */
  96.     spawnlp(P_NOWAIT, "cmd.exe", "cmd", "/c", SCRDMPCOM,NULL);
  97. //    system(SCRDMPCOM);
  98.     return;
  99.     }
  100.  
  101.  
  102. /******************************************************************************
  103. Function:       gfile_dump()
  104.  
  105. Description:    Outputs the dump file to the plotter or whatever.
  106.  
  107. Syntax:         void gfile_dump()
  108.  
  109. Returns:         The error code from the relevant dump file or -999 if an
  110.                 invalid plot mode is selected.
  111.  
  112. Mods:           15-Jul-89 C.P.Armstrong created
  113.                 27-Feb-90 C.P.Armstrong Error codes
  114.  
  115. ******************************************************************************/
  116. int  gfile_dump()
  117.     {
  118.     extern int dump_plot;
  119.     extern int dump_format;
  120.     int error;
  121.     
  122.     if(!dump_plot)      /* Not dumping plot so can't print it out */
  123.         return(0);
  124.  
  125.     switch( dump_format )
  126.         {
  127.         case HPGL:
  128.             return(hpgl_dump());
  129.         case WPG:
  130. //            return(wpg_dump());
  131.         case TEK:
  132. //            return(tek_dump());
  133.         case NODMP:
  134.         default:
  135.             break;
  136.         }
  137.  
  138.     return(-999);
  139.     }
  140.  
  141. /******************************************************************************
  142. Function:       gfile_rewind()
  143.  
  144. Description:    Moves the file pointer back to the begining and rewrites
  145.                 the initialisation header.
  146.  
  147. Syntax:         void gfile_rewind()
  148.  
  149. Returns:        nothing
  150.  
  151. Mods:           15-Jul-89 C.P.Armstrong created
  152.  
  153. ******************************************************************************/
  154. void  gfile_rewind()
  155.     {
  156.     extern int dump_format;
  157.     switch( dump_format )
  158.         {
  159.         case HPGL:
  160.             hpgl_rewind();
  161.             break;
  162.         case WPG:
  163. //            wpg_rewind();
  164. //            break;
  165.         case TEK:
  166. //            tek_rewind();
  167.         case NODMP:
  168.         default:
  169.             break;
  170.         }
  171.     return;
  172.     }
  173.  
  174. /******************************************************************************
  175. Function:       gfile_print()
  176.  
  177. Description:    Prints a label at the current pen position.  To make this
  178.                 compatible with the screen movement functions it is assumed
  179.                 that the character is drawn from the upper left corner.
  180.  
  181. Syntax:         void gfile_printf(string)
  182.                     char * string;  The nul terminated string to print
  183.  
  184. Returns:        nothing
  185.  
  186. Mods:           15-Jul-89 C.P.Armstrong created
  187. ******************************************************************************/
  188. void  gfile_print(string)
  189.     char * string;
  190.     
  191.     {            
  192.     extern int dump_format;
  193.     switch( dump_format )
  194.         {
  195.         case HPGL:
  196.             hpgl_print(string);
  197.             break;
  198.         case WPG:
  199. //            wpg_print(string);
  200. //            break;
  201.         case TEK:
  202. //            tek_print(string);
  203.         case NODMP:
  204.         default:
  205.             break;
  206.         }
  207.     return;
  208.     }
  209.  
  210. /******************************************************************************
  211. Function:     gfile_plot()
  212.  
  213. Description:  HPGL plot a point command
  214.  
  215. Syntax:     void gfile_plot(x,y)
  216.                 int x,y;  Point to plot at
  217.  
  218. Returns:      nothing
  219.  
  220. Mods:       15-Jul-89 C.P.Armstrong created
  221.  
  222. ******************************************************************************/
  223. void  gfile_plot(x,y)
  224.     int x,y;    /* Position to plot at - in cartesian screen units */
  225.     {
  226.     extern int dump_format;
  227.     switch( dump_format )
  228.         {
  229.         case HPGL:
  230.             hpgl_plot(x,y);
  231.             break;
  232.         case WPG:
  233. //            wpg_plot(x,y);
  234. //            break;
  235.         case TEK:
  236. //            tek_plot(x,y);
  237.         case NODMP:
  238.         default:
  239.             break;
  240.         }
  241.  
  242.     return;
  243.     }
  244.                         
  245.  
  246. /******************************************************************************
  247. Function:       gfile_plotr()
  248.  
  249. Description:    HPGL plot a point relative to current position
  250.  
  251. Syntax:         void gfile_plotr(dx,dy)
  252.                     int dx,dy;  Point relative to current position to plot at
  253.  
  254. Returns:        nothing
  255.  
  256. Mods:           15-Jul-89 C.P.Armstrong created
  257.  
  258. ******************************************************************************/
  259. void  gfile_plotr(dx,dy)
  260.     int dx,dy;    /* Position to move pen to - in plotter suitable units */
  261.     {
  262.     extern int dump_format;
  263.     switch( dump_format )
  264.         {
  265.         case HPGL:
  266.             hpgl_plotr(dx,dy);
  267.             break;
  268.         case WPG:
  269. //            wpg_plotr(dx,dy);
  270. //            break;
  271.         case TEK:
  272. //            tek_plotr(dx,dy);
  273.         case NODMP:
  274.         default:
  275.             break;
  276.         }
  277.     return;
  278.     }
  279.  
  280. /******************************************************************************
  281. Function:       gfile_move()
  282.  
  283. Description:    Move to position
  284.  
  285. Syntax:         void gfile_move(x,y)
  286.                     int x,y;  Position to move to
  287.  
  288. Returns:        nothing
  289.  
  290. Mods:           15-Jul-89 C.P.Armstrong created
  291.  
  292. ******************************************************************************/
  293. void  gfile_move(x,y)
  294.     int x,y;    /* Position to move pen to - in plotter suitable units */
  295.     {
  296.     extern int dump_format;
  297.  
  298.     switch( dump_format )
  299.         {
  300.         case HPGL:
  301.             hpgl_move(x,y);
  302.             break;
  303.         case WPG:
  304. //            wpg_move(x,y);
  305. //            break;
  306.         case TEK:
  307. //            tek_move(x,y);
  308.         case NODMP:
  309.         default:
  310.             break;
  311.         }
  312.  
  313.     return; 
  314.     }
  315.  
  316.  
  317. /******************************************************************************
  318. Function:       gfile_draw()
  319.  
  320. Description:    HPGL Draw a line to a point
  321.  
  322. Syntax:         void gfile_draw(x,y)
  323.                     int x,y;  Point to draw to
  324.  
  325. Returns:        nothing
  326.  
  327. Mods:           15-Jul-89 C.P.Armstrong created
  328.  
  329. ******************************************************************************/
  330. void  gfile_draw(x,y)
  331.     int x,y;    /* Position to draw to - in plotter suitable units */
  332.     {
  333.     extern int dump_format;
  334.     switch( dump_format )
  335.         {
  336.         case HPGL:
  337.             hpgl_draw(x,y);
  338.             break;
  339.         case WPG:
  340. //            wpg_draw(x,y);
  341. //            break;
  342.         case TEK:
  343. //            tek_draw(x,y);
  344.         case NODMP:
  345.         default:
  346.             break;
  347.         }
  348.  
  349.     return; 
  350.     }
  351.                 
  352. /******************************************************************************
  353. Function:       gfile_mover()
  354.  
  355. Description:    HPGL Move to a point realtive to the current position
  356.  
  357. Syntax:         void gfile_mover(dx,dy)
  358.                     int dx,dy;  Relative point to move to
  359.  
  360. Returns:        nothing
  361.  
  362. Mods:           15-Jul-89 C.P.Armstrong created
  363.  
  364. ******************************************************************************/
  365. void  gfile_mover(dx,dy)
  366.     int dx,dy;    /* Position to move pen to - in plotter suitable units */
  367.     {
  368.     extern int dump_format;
  369.     switch( dump_format )
  370.         {
  371.         case HPGL:
  372.             hpgl_mover(dx,dy);
  373.             break;
  374.         case WPG:
  375. //            wpg_mover(dx,dy);
  376. //            break;
  377.         case TEK:
  378. //            tek_mover(dx,dy);
  379.         case NODMP:
  380.         default:
  381.             break;
  382.         }
  383.  
  384.     return;
  385.     }
  386.  
  387.  
  388. /******************************************************************************
  389. Function:       gfile_drawr()
  390.  
  391. Description:    HPGL Draw to a point realtive to the current position
  392.  
  393. Syntax:         void gfile_drawr(dx,dy)
  394.                     int dx,dy;  Relative point to draw to
  395.  
  396. Returns:        nothing
  397.  
  398. Mods:           15-Jul-89 C.P.Armstrong created
  399.  
  400. ******************************************************************************/
  401. void  gfile_drawr(dx,dy)
  402.     int dx,dy;    /* Position to move pen to - in plotter suitable units */
  403.     {
  404.     extern int dump_format;
  405.     switch( dump_format )
  406.         {
  407.         case HPGL:
  408.             hpgl_drawr(dx,dy);
  409.             break;
  410.         case WPG:
  411. //            wpg_drawr(dx,dy);
  412. //            break;
  413.         case TEK:
  414. //            tek_drawr(dx,dy);
  415.         case NODMP:
  416.         default:
  417.             break;
  418.         }
  419.  
  420.     return;
  421.     }
  422.  
  423.  
  424. /******************************************************************************
  425. Function:       gfile_open()
  426.  
  427. Description:    Open the dump file and initialise it
  428.  
  429. Syntax:         int gfile_open()
  430.  
  431. Returns:        NULL if file open unsuccessful
  432.                 1 if open successful
  433.  
  434. Mods:           15-Jul-89 C.P.Armstrong created
  435.  
  436. ******************************************************************************/
  437. int  gfile_open()
  438.     {
  439.     extern int dump_format;
  440.     int yeaorney;
  441.     switch( dump_format )
  442.         {
  443.         case HPGL:
  444.             yeaorney=hpgl_open();
  445.             break;
  446.         case WPG:
  447. //            yeaorney=wpg_open();
  448. //            break;
  449.         case TEK:
  450. //            yeaorney=tek_open();
  451.         case NODMP:
  452.         default:
  453.             break;
  454.         }
  455.  
  456.     return(yeaorney);
  457.     }
  458.  
  459.  
  460. /******************************************************************************
  461. Function:       gfile_init()
  462.  
  463. Description:    Writes the HPGL initialisation header onto the dump file
  464.  
  465. Syntax:         void gfile_init()
  466.  
  467. Returns:        nothing
  468.  
  469. Mods:           15-Jul-89 C.P.Armstrong created
  470.  
  471. ******************************************************************************/
  472. void  gfile_init()
  473.     {
  474.     extern int dump_format;
  475.     switch( dump_format )
  476.         {
  477.         case HPGL:
  478.             hpgl_init();
  479.             break;
  480.         case WPG:
  481. //            wpg_init();
  482. //            break;
  483.         case TEK:
  484. //            tek_init();
  485.         case NODMP:
  486.         default:
  487.             break;
  488.         }
  489.  
  490.     return;
  491.     }
  492.  
  493.  
  494. /******************************************************************************
  495. Function:       gfile_close()
  496.  
  497. Description:    Closes the HPGL dump file
  498.  
  499. Syntax:         void gfile_close()
  500.  
  501. Returns:        nothing
  502.  
  503. Mods:           15-Jul-89 C.P.Armstrong created
  504.  
  505. ******************************************************************************/
  506. void  gfile_close()
  507.     {
  508.     extern int dump_format;
  509.     switch( dump_format )
  510.         {
  511.         case HPGL:
  512.             hpgl_close();
  513.             break;
  514.         case WPG:
  515. //            wpg_close();
  516. //            break;
  517.         case TEK:
  518. //            tek_close();
  519.         case NODMP:
  520.         default:
  521.             break;
  522.         }
  523.  
  524.     return; 
  525.     }
  526.  
  527.  
  528. /****************************************************************************
  529. Function:       fileopen()
  530.  
  531. Description:    Opens a BINARY file regardless of whether it already exists.
  532.  
  533. Syntax:         int fileopen( fname )
  534.                     char * fnmae;        Name of file to be opened
  535.  
  536. Returns:        The file handle of the opened file
  537.  
  538. Rev:            7-3-88      CPArmstrong     created
  539. *****************************************************************************/
  540.                                                
  541. int  fileopen(fname)
  542.  
  543. char* fname;  /* Pointer to the name of the file to be opened */
  544.  
  545.     {
  546.     int fhout; /* File handle */
  547.  
  548.     if((fhout = open(fname,O_EXCL|O_CREAT|O_BINARY|O_WRONLY,S_IREAD|S_IWRITE)) 
  549.                 == -1)
  550.         {
  551.         if((fhout = open(fname,O_TRUNC|O_BINARY|O_RDWR)) == -1)
  552.             {
  553.             return(-1);
  554.             }
  555.         }
  556.     /* If the output file already exits it is written over */
  557.     
  558.     return(fhout);
  559.     }
  560.  
  561. /******************************************************************************
  562. Function:       hpgl_dump()
  563.  
  564. Description:    Dumps the HPGL.PLT file out using the system command specified
  565.                 above.
  566.  
  567. Syntax:         int hpgl_dump()
  568.  
  569. Returns:        0  if successful
  570.                 -1 if file reopen fails.
  571.  
  572. Mods:           25-Jun-89 C.P.Armstrong created
  573.                 27-Feb-90 C.P.Armstrong Returns error codes
  574.  
  575. ******************************************************************************/
  576. int hpgl_dump()
  577.     {
  578.     extern char command[];      /* Declared in gfiledrv.c */
  579.     extern char hpgl_file[];
  580.     extern FILE * hpgl_stream;
  581.  
  582.     fpos_t filepos;   /* File pointer value before writing */
  583.                       /* This is the way it's done in the example!!! */
  584.  
  585.     if(hpgl_stream==NULL)
  586.         return(0);
  587.     
  588.     strcpy(command,HPGL_COM);
  589.  
  590.     fgetpos(hpgl_stream,&filepos);  /* Save file position */
  591.  
  592.     fprintf(hpgl_stream,"PG;\n");   /* Page eject command */
  593.  
  594.     hpgl_close();                   /* Close the file */
  595.     
  596.     system(command);                /* Command to print the file */
  597.     
  598.     if((hpgl_stream=fopen(hpgl_file,"r+"))==NULL) /* Modify - file must exist */
  599.         {
  600.         return(-1);
  601.         }
  602.     
  603.     fsetpos(hpgl_stream,&filepos);  /* Reposition file pointer */
  604.     
  605.     return(0);
  606.     }
  607.  
  608. /******************************************************************************
  609. Function:   hpgl_rewind()
  610.  
  611. Description:    Moves the file pointer back to the begining and rewrites
  612.                 the plotter initialisation.
  613.  
  614. Syntax:     void hpgl_rewind()
  615.  
  616. Returns:        nothing
  617.  
  618. Mods:           25-Jun-89 C.P.Armstrong created
  619.  
  620. ******************************************************************************/
  621. void  hpgl_rewind()
  622.     {
  623.     extern FILE * hpgl_stream;
  624.  
  625.     if(hpgl_stream==NULL)
  626.         return;
  627.  
  628.     /* Go back to begining */
  629.     fseek(hpgl_stream,0L,SEEK_SET);
  630.     
  631.     /* Re init */
  632.     hpgl_init();
  633.     
  634.     return;
  635.     }
  636.  
  637.  
  638.  
  639. /******************************************************************************
  640. Function:   hpgl_print()
  641.  
  642. Description:    Prints a label at the current pen position.  To make this
  643.                 compatible with the screen movement functions it is assumed
  644.                 that the character is drawn from the upper left corner.  In
  645.                 reality the plotter draws characters from the bottom left.
  646.                 This function therefore does a relative move down before
  647.                 printing, followed by a relative move up after printing.
  648.  
  649. Syntax:     void hpgl_printf(string)
  650.                     char * string;  The nul terminated string to print
  651.  
  652. Returns:        nothing
  653.  
  654. Mods:           25-Jun-89 C.P.Armstrong created
  655. ******************************************************************************/
  656. void  hpgl_print(string)
  657.     char * string;
  658.     
  659.     {            
  660.     extern FILE * hpgl_stream;
  661.     char etx=3;  /* ASCII ETX - label terminator */
  662.  
  663.     if(hpgl_stream==NULL)
  664.         return;
  665.     /* Move down */
  666. //  hpgl_mover(0,-chrhit());
  667.      
  668.     /* Do label */
  669.     fprintf(hpgl_stream, "LB%s%c",string,etx);
  670.     
  671.     /* Move back up */
  672. //  hpgl_mover(0,chrhit());
  673.     
  674.     return;
  675.     }
  676.  
  677.  
  678.  
  679.  
  680.  
  681. /******************************************************************************
  682. Function:     hpgl_plot()
  683.  
  684. Description:  HPGL plot a point command
  685.  
  686. Syntax:     void hpgl_plot(x,y)
  687.                 int x,y;  Point to plot at
  688.  
  689. Returns:      nothing
  690.  
  691. Mods:       25-Jun-89 C.P.Armstrong created
  692.  
  693. ******************************************************************************/
  694. void  hpgl_plot(x,y)
  695.     int x,y;    /* Position to plot at - in plotter suitable units */
  696.     {
  697.     extern FILE * hpgl_stream;
  698.     if(hpgl_stream!=NULL)
  699.         fprintf(hpgl_stream,"PA;PU%d,%d;PD;PU\n",x,y);
  700.     return;
  701.     }
  702.                         
  703.  
  704. /******************************************************************************
  705. Function:   hpgl_plotr()
  706.  
  707. Description:    HPGL plot a point relative to current position
  708.  
  709. Syntax:     void hpgl_plotr(dx,dy)
  710.                     int dx,dy;  Point relative to current position to plot at
  711.  
  712. Returns:        nothing
  713.  
  714. Mods:           25-Jun-89 C.P.Armstrong created
  715.  
  716. ******************************************************************************/
  717. void  hpgl_plotr(dx,dy)
  718.     int dx,dy;    /* Position to move pen to - in plotter suitable units */
  719.     {
  720.     extern FILE * hpgl_stream;
  721.     if(hpgl_stream!=NULL)
  722.         fprintf(hpgl_stream,"PR;PU%d,%d;PD;PU\n",dx,dy);
  723.     return;
  724.     }
  725.  
  726.  
  727. /******************************************************************************
  728. Function:   hpgl_move()
  729.  
  730. Description:    HPGL move to position
  731.  
  732. Syntax:     void hpgl_move(x,y)
  733.                     int x,y;  Position to move to
  734.  
  735. Returns:        nothing
  736.  
  737. Mods:           25-Jun-89 C.P.Armstrong created
  738.  
  739. ******************************************************************************/
  740. void  hpgl_move(x,y)
  741.     int x,y;    /* Position to move pen to - in plotter suitable units */
  742.     {
  743.     extern FILE * hpgl_stream;
  744.     if(hpgl_stream!=NULL)
  745.         fprintf(hpgl_stream,"PA;PU%d,%d\n",x,y);
  746.     return;
  747.     }
  748.  
  749.  
  750. /******************************************************************************
  751. Function:   hpgl_draw()
  752.  
  753. Description:    HPGL Draw a line to a point
  754.  
  755. Syntax:     void hpgl_draw(x,y)
  756.                     int x,y;  Point to draw to
  757.  
  758. Returns:        nothing
  759.  
  760. Mods:           25-Jun-89 C.P.Armstrong created
  761.  
  762. ******************************************************************************/
  763. void  hpgl_draw(x,y)
  764.     int x,y;    /* Position to draw to - in plotter suitable units */
  765.     {
  766.     extern FILE * hpgl_stream;
  767.     if(hpgl_stream!=NULL)
  768.         fprintf(hpgl_stream,"PA;PD%d,%d\n",x,y);
  769.     return;
  770.     }
  771.                 
  772. /******************************************************************************
  773. Function:   hpgl_mover()
  774.  
  775. Description:    HPGL Move to a point realtive to the current position
  776.  
  777. Syntax:     void hpgl_mover(dx,dy)
  778.                     int dx,dy;  Relative point to move to
  779.  
  780. Returns:        nothing
  781.  
  782. Mods:           25-Jun-89 C.P.Armstrong created
  783.  
  784. ******************************************************************************/
  785. void  hpgl_mover(dx,dy)
  786.     int dx,dy;    /* Position to move pen to - in plotter suitable units */
  787.     {
  788.     extern FILE * hpgl_stream;
  789.     if(hpgl_stream!=NULL)
  790.         fprintf(hpgl_stream,"PR;PU%d,%d\n",dx,dy);
  791.     return;
  792.     }
  793.  
  794.  
  795. /******************************************************************************
  796. Function:   hpgl_drawr()
  797.  
  798. Description:    HPGL Draw to a point realtive to the current position
  799.  
  800. Syntax:     void hpgl_drawr(dx,dy)
  801.                     int dx,dy;  Relative point to draw to
  802.  
  803. Returns:        nothing
  804.  
  805. Mods:           25-Jun-89 C.P.Armstrong created
  806.  
  807. ******************************************************************************/
  808. void  hpgl_drawr(dx,dy)
  809.     int dx,dy;    /* Position to move pen to - in plotter suitable units */
  810.     {
  811.     extern FILE * hpgl_stream;
  812.     if(hpgl_stream!=NULL)
  813.         fprintf(hpgl_stream,"PR;PD%d,%d\n",dx,dy);
  814.     return;
  815.     }
  816.  
  817.  
  818. /******************************************************************************
  819. Function:   hpgl_open()
  820.  
  821. Description:    Open the HPGL dump file and initialise it
  822.  
  823. Syntax:     int hpgl_open()
  824.  
  825. Returns:        NULL if file open unsuccessful
  826.                 1 if open successful
  827.  
  828. Mods:           25-Jun-89 C.P.Armstrong created
  829.  
  830. ******************************************************************************/
  831. int  hpgl_open()
  832.     {
  833.     extern FILE * hpgl_stream;
  834.     extern char hpgl_file[];
  835.  
  836.     int hpgldump_hand;          /* Dump file handle */
  837.  
  838.     if(hpgl_stream!=NULL)       /* Open already - preserve status */
  839.         return(1);
  840.  
  841.     /* Open the dump file */
  842.     if( (hpgldump_hand=fileopen(hpgl_file)) == -1)
  843.         {
  844.         return(0);        
  845.         }      /* File open filaure */
  846.  
  847.  
  848.     /* Convert handle for use with fprintf etc.. */
  849.     /* Note that the b option results in there being no CRLF combinations in */
  850.     /* the file.  ME deals with this okay but TYPE requires the CR to display*/
  851.     /* properly */
  852.  
  853.     if( (hpgl_stream=fdopen(hpgldump_hand,"wb+")) == NULL)
  854.         {
  855.         return(0);        
  856.         }           /* Handle conversion error */
  857.  
  858.     /* Plotter initialise */
  859.     hpgl_init();
  860.  
  861.     return(1);
  862.     }
  863.  
  864.  
  865. /******************************************************************************
  866. Function:   hpgl_init()
  867.  
  868. Description:    Writes the HPGL initialisation header onto the dump file
  869.  
  870. Syntax:     void hpgl_init()
  871.  
  872. Returns:        nothing
  873.  
  874. Mods:           25-Jun-89 C.P.Armstrong created
  875.  
  876. ******************************************************************************/
  877. void  hpgl_init()
  878.     {
  879.     extern int hpgl_pen;
  880.     extern FILE * hpgl_stream;
  881.  
  882.     float chrscalw;   /* Chr width as %age of screen width */
  883.     float chrscalh;   /* Chr height as %age of screen height */
  884.     float t1,t2;      /* temporary values */
  885.  
  886.     if(hpgl_stream==NULL)
  887.         return;
  888.  
  889.     fprintf(hpgl_stream,"IN\n");
  890.  
  891.     /* Set scale factor so full page is sameas full screen */
  892.     fprintf(hpgl_stream,"SC%d,%d,%d,%d\n",
  893.         0,MAXXRES-1,0,MAXYRES-1);
  894.  
  895.     /* The 0.8 factor is to allow for a space between characters.  The screen */
  896.     /* width includes a space factor normally whereas the HPGL command does */
  897.     /* not allow for any space */
  898.     t1 = (float) MAXCHARWIDTH * 0.8;
  899.     t2 = (float) MAXXRES;
  900.     chrscalw = (t1/t2) *100.0;
  901.  
  902.     t1 = (float) MAXCHARHEIGHT * 0.8;
  903.     t2 = (float) MAXYRES;
  904.     chrscalh = (t1/t2) *100.0;
  905.  
  906.     /* Set the character size to correspond to the SCREEN character size */
  907.     fprintf(hpgl_stream,"SR%f,%f\n", chrscalw,chrscalh);
  908.  
  909.     /* Select a pen size - required for HP Laserjet Plotter Emulation   */
  910.     /* The SPn,w is specific to the Laserjet Emulation cartridge.  This */
  911.     /* set the pen number to the same pen as the width. Valid widths    */
  912.     /* are 1 to 48 and pens 1 to 20.                                    */
  913.     fprintf(hpgl_stream,"SP%d,%d;\n",hpgl_pen,hpgl_pen);
  914.  
  915.     /* Home the pen */
  916.     hpgl_move(0,0);
  917.     
  918.     return;
  919.     }
  920.  
  921.  
  922. /******************************************************************************
  923. Function:   hpgl_close()
  924.  
  925. Description:    Closes the HPGL dump file
  926.  
  927. Syntax:     void hpgl_close()
  928.  
  929. Returns:        nothing
  930.  
  931. Mods:           25-Jun-89 C.P.Armstrong created
  932.  
  933. ******************************************************************************/
  934. void  hpgl_close()
  935.     {
  936.     extern FILE * hpgl_stream;
  937.  
  938.     if(hpgl_stream==NULL)
  939.         return;
  940.  
  941.     /* Write an end-of-file */
  942.     fputc(26,hpgl_stream);
  943.  
  944.     /* Close the file and reset hpgl_stream to NULL */
  945.     fclose(hpgl_stream);
  946.     hpgl_stream=NULL;
  947.     }
  948.