home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / printer / dvi2pcl.lha / main.c < prev    next >
C/C++ Source or Header  |  1992-11-25  |  5KB  |  215 lines

  1. /* $Log:    main.c,v $
  2.  * Revision 0.8  92/11/23  19:46:49  19:46:49  bt (Bo Thide')
  3.  * Fixed resolution bug. Portable downloading. Added/changed options. PJXL color support
  4.  * 
  5.  * Revision 0.7  92/11/13  02:41:34  02:41:34  bt (Bo Thide')
  6.  * More bug fixes and improvements. Support for PaintJet XL
  7.  * 
  8.  * Revision 0.6  92/11/10  21:47:50  21:47:50  bt (Bo Thide')
  9.  * Bug fixes. Added -R option. Better font handling.
  10.  * 
  11.  * Revision 0.5  92/11/09  16:25:37  16:25:37  bt (Bo Thide')
  12.  * Rewrite of dospecial.c. Extended \special support
  13.  * 
  14.  * Revision 0.4  92/11/08  02:45:53  02:45:53  bt (Bo Thide')
  15.  * Changed to portable bit manipulations. Replaced strrstr for non-POSIX compliant C. Fixed numerous bugs. Added support for more \special's.
  16.  * 
  17.  * Revision 0.3  92/08/24  12:45:44  12:45:44  bt (Bo Thide')
  18.  * Fixed 8 bit (dc font) support.
  19.  * 
  20.  * Revision 0.2  92/08/23  17:28:58  17:28:58  bt (Bo Thide')
  21.  * Source cleaned up.  Changed certain function calls.  Removed globals.
  22.  * 
  23.  * Revision 0.1  92/08/22  23:58:48  23:58:48  bt (Bo Thide')
  24.  * First Release.
  25.  *  */
  26.  
  27. #pragma COPYRIGHT "Bo Thide' and Helmut Kopka, 1992"
  28. #include <stdio.h>
  29. #include <string.h>
  30. #include "globals.h"
  31. #include "paths.h"
  32. #include "pcl.h"
  33.  
  34. static char rcsid[] = "$Header: main.c,v 0.8 92/11/23 19:46:49 bt Exp $";
  35.  
  36. static char fatal_error[] = "This was a fatal error.\n";
  37. static char copyright[] = "Copyright (c) Bo Thide' and Helmut Kopka, 1992.";
  38.  
  39. #ifdef TIMING
  40. #include <sys/timeb.h>
  41. #endif /* TIMING */
  42.  
  43. main(argc, argv, envp)
  44. int    argc;
  45. char    **argv;
  46. char    **envp;
  47. {
  48.     char    bitname[NAMELENGTH];
  49.     char    curname[NAMELENGTH];
  50.     char    dviname[NAMELENGTH];
  51.     char    usgname[NAMELENGTH];
  52.     bool    outreverse=TRUE;
  53.     short    device=DEV_LJPLUS;
  54.     short    maxdown=MAXDOWN;
  55.     short    numcopies=1;
  56.     short    pcllevel=PCLLEVEL;
  57.     short    resolution=RESOLUTION;
  58.     short    twosided=FALSE;
  59.     long    startloc=0;
  60.     FILE    *bitfile;
  61.     FILE    *dvifile;
  62.     FILE    *resfile;
  63.     FILE    *usgfile;
  64.  
  65. #ifdef TIMING
  66.     struct timeb timebuffer;
  67.     double  start_time, time;
  68.  
  69.         ftime(&timebuffer);
  70.         start_time = (double)((timebuffer.time) + (timebuffer.millitm)/1000.0);
  71. #endif /* TIMING */
  72.  
  73.     /* Get things started properly */
  74.     initialize();
  75.  
  76.     /* Process all dvi2pcl options and construct the filenames. */
  77.     getoptions(argc, argv, envp, bitname, dviname, usgname,
  78.       &pcllevel, &numcopies, &device, &maxdown, &outreverse,
  79.       &resolution, &twosided);
  80.  
  81.     /*
  82.      * Open the output bitfile or, if bitname is an empty string, stdout.
  83.      */
  84.     if(strcmp(bitname, "") == 0) {
  85.         bitfile = stdout;
  86.     }
  87.     else {
  88.         if((bitfile = fopen(bitname,"w")) == NULL) {
  89.             fprintf(stderr,"Cannot open the bit file %s for output.\n", bitname);
  90.         exit(-1);
  91.         }
  92.     }
  93.  
  94.     /*
  95.      * Open the input dvifile or stdin.
  96.      */
  97.     if(strcmp(dviname, DVIFILE_SUFFIX) == 0) {
  98.         dvifile = stdin;
  99.      }
  100.     else {
  101.         if((dvifile = fopen(dviname,"r")) == NULL) {
  102.             fprintf(stderr,"Cannot open the dvi file %s for input.\n", dviname);
  103.         exit(-1);
  104.         }
  105.     }
  106.  
  107.     /*
  108.      * Open the input resident font info file
  109.      */
  110.     strcpy(curname, respath);
  111.     if((resfile = fopen(curname,"r")) == NULL) {
  112.         fprintf(stderr,"Cannot open the resident font file %s for input.\n", curname);
  113.         exit(-1);
  114.     }
  115.  
  116.     /* Prescan the input file. */ 
  117.     preamble(dvifile, resolution);
  118.     startloc = skippages(bitfile, dvifile, pcllevel, resolution);    
  119.     if(!inpostamble){
  120.         /* If not in postamble, prescan the file up to maxpages */
  121.         while(maxpages-- > 0){
  122.             /* Prescan up to maxpages or postamble */
  123.             prescanpage(bitfile, dvifile, pcllevel, resolution);
  124.             if(inpostamble){
  125.                 postamble(dvifile);
  126.                 break;    /* font_def agreement */
  127.                   }
  128.             if(!betweenpages(dvifile, PRESCAN_ON))
  129.                 break;
  130.             }
  131.     }
  132.  
  133.     /* Initialize the printer */
  134.     fprintf(bitfile, PCL4_INIT_PRINTER);
  135.     fprintf(bitfile, PCL4_COPIES, numcopies);
  136.     fprintf(bitfile, PCL4_RESOLUTION, resolution);
  137.     fprintf(bitfile, PCL5_PRINT_DIRECTION, 0);
  138.  
  139.     /* Download the defined fonts */
  140.     cachefonts(bitfile, resfile, maxdown, device);
  141.  
  142.     /* Now do the main work */
  143.     if(twosided)
  144.         doodevpages(bitfile, dvifile, pcllevel, outreverse,
  145.           resolution, device);
  146.     else
  147.         doallpages(bitfile, dvifile, pcllevel, outreverse,
  148.           resolution, device);
  149.     fprintf(bitfile, PCL4_CLEAN_PRINTER);
  150.  
  151. #ifdef TIMING
  152.                 ftime(&timebuffer);
  153.                 time = ((timebuffer.time) + (timebuffer.millitm)/1000.0)
  154.                     -start_time;
  155.                 fprintf(stderr,"Time of complete run:        %.3lf sec,  %.3lf sec/page  (%.2lf ppm)\n",
  156.         time, time/actualpagecount, (double)(actualpagecount*60)/time);
  157. #endif /* TIMING */
  158.  
  159.  
  160.     if(verbose){
  161.         fprintf(stderr,"%s done.\n",argv[0]);
  162.         if((usgfile = fopen(usgname,"w")) == NULL) {
  163.             fprintf(stderr,"Cannot open the output file %s\n", usgname);
  164.             exit(-1);
  165.         }
  166.         diagnostics(usgfile);
  167.     }
  168.  
  169.     exit(0);
  170. }
  171.    
  172. /*
  173.  * Error and die routines.
  174.  * Print error messages and exits.
  175.  */
  176.  
  177. prerror(s)
  178. char *s;
  179. {
  180.     fprintf(stderr,s);
  181.     fprintf(stderr,fatal_error);
  182.     fflush(stderr);
  183.     exit(-1);
  184. }
  185.  
  186. void sterror(s, st)
  187. char *s;
  188. char *st;
  189. {
  190.     fprintf(stderr,s, st);
  191.     fprintf(stderr,fatal_error);
  192.     fflush(stderr);
  193.     exit(-1);
  194. }
  195.  
  196. valerror(s,v)
  197. char *s;
  198. int  v;
  199. {
  200.     fprintf(stderr,s,v);
  201.     fprintf(stderr,fatal_error);
  202.     fflush(stderr);
  203.     exit(-1);
  204. }
  205.  
  206. valvalerror(s,u,v)
  207. char *s;
  208. int u,v;
  209. {
  210.     fprintf(stderr,s,u,v);
  211.     fprintf(stderr,fatal_error);
  212.     fflush(stderr);
  213.     exit(-1);
  214. }
  215.