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

  1. /* $Log:    getoptions.c,v $
  2.  * Revision 0.8  92/11/23  19:46:46  19:46:46  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:30  02:41:30  bt (Bo Thide')
  6.  * More bug fixes and improvements. Support for PaintJet XL
  7.  * 
  8.  * Revision 0.6  92/11/10  21:47:47  21:47:47  bt (Bo Thide')
  9.  * Bug fixes. Added -R option. Better font handling.
  10.  * 
  11.  * Revision 0.5  92/11/09  16:25:34  16:25:34  bt (Bo Thide')
  12.  * Rewrite of dospecial.c. Extended \special support
  13.  * 
  14.  * Revision 0.4  92/11/08  02:45:50  02:45:50  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:41  12:45:41  bt (Bo Thide')
  18.  * Fixed 8 bit (dc font) support.
  19.  * 
  20.  * Revision 0.2  92/08/23  17:28:57  17:28:57  bt (Bo Thide')
  21.  * Source cleaned up.  Changed certain function calls.  Removed globals.
  22.  * 
  23.  * Revision 0.1  92/08/22  23:58:47  23:58:47  bt (Bo Thide')
  24.  * First Release.
  25.  *  */
  26.  
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <unistd.h>
  30. #include "globals.h"
  31.  
  32. static char rcsid[] = "$Header: getoptions.c,v 0.8 92/11/23 19:46:46 bt Exp $";
  33.  
  34. /*
  35.  * Put the selected options into global variables
  36. */
  37.  
  38. getoptions(argc, argv, envp, bitname, dviname, usgname,
  39.    pcllevel, numcopies, device, maxdown, outreverse, resolution, twosided)
  40. int    argc;
  41. char    **argv;
  42. char    **envp;
  43. char    bitname[];
  44. char    dviname[];
  45. char    usgname[];
  46. short    *pcllevel;
  47. short    *numcopies;
  48. short    *device;
  49. short    *maxdown;
  50. bool    *outreverse;
  51. short    *resolution;
  52. short    *twosided;
  53.       char        buffer[1024];
  54.       char        *bufptr;
  55.       char        *strptr;
  56.     int        k;
  57.     int        c, errflag=0;
  58.     extern char    *optarg;
  59.     extern int    optind;
  60.  
  61.     strcpy(bitname,"");
  62.     verbose = FALSE;
  63.  
  64.     while ((c = getopt(argc, argv, "12345c:d:f:lmo:p:rR:s:tvx:X:y:?")) != EOF)
  65.  
  66.     switch (c) {
  67.     case '1':            /* PCL level 1 */
  68.     case '2':            /* PCL level 2 */
  69.     case '3':            /* PCL level 3 */
  70.     case '4':            /* PCL level 4 */
  71.     case '5':            /* PCL level 5 */
  72.         *pcllevel = -(short)atoi(argv[optind-1]);
  73.         break;
  74.     case 'c':            /* Number of copies of each page */
  75.         if((*numcopies = (short)atoi(optarg)) <= 0)
  76.             *numcopies = 1;
  77.         break;
  78.     case 'd':            /* Specify output device */
  79.         if(strcmp(optarg,"lj+") == 0)
  80.           *device = DEV_LJPLUS;
  81.         else if (strcmp(optarg,"lj2") == 0)
  82.           *device = DEV_LJ2;
  83.         else if (strcmp(optarg,"lj2d") == 0)
  84.           *device = DEV_LJ2D;
  85.         else if (strcmp(optarg,"lj2p") == 0)
  86.           *device = DEV_LJ2P;
  87.         else if (strcmp(optarg,"lj3si") == 0){
  88.           *device = DEV_LJ3SI;
  89.           *pcllevel = 5;
  90.         }
  91.         else if (strcmp(optarg,"lj3p") == 0){
  92.           *device = DEV_LJ3P;
  93.           *pcllevel = 5;
  94.         }
  95.         else if (strcmp(optarg,"pj") == 0)
  96.           *device = DEV_PJ;
  97.         else if (strcmp(optarg,"pjxl") == 0)
  98.           *device = DEV_PJXL;
  99.         break;
  100.     case 'f':            /* Max number of downloadable fonts */
  101.         
  102.         if((*maxdown = (short)atoi(optarg)) < 0)
  103.             *maxdown = 32;
  104.         break;
  105.     case 'l':            /* Landscape mode flag */
  106.         landscape = TRUE;
  107.         break;
  108.     case 'm':            /* Manual feed flag */
  109.         manualfeed = TRUE;
  110.         break;
  111.     case 'o':            /* Output file name */
  112.         strcpy(bitname, optarg);
  113.         break;
  114.     case 'p':            /* Max number of output pages */
  115.         if((maxpages = atoi(optarg)) <= 0)
  116.             maxpages = MAXPAGES;
  117.         break;
  118.     case 'r':            /* Reverse output order flag */
  119.         *outreverse *= *outreverse;
  120.         break;    
  121.     case 'R':            /* Set PCL resolution */
  122.         *resolution = (short)atoi(optarg);
  123.         break;    
  124.     case 's':            /* Start page */
  125.         startvals = 0;
  126.         startthere[0] = FALSE;
  127.             strcpy(buffer,optarg);
  128.             bufptr = buffer;
  129.         k = 0;
  130.         do { 
  131.             if(*bufptr == '*') { 
  132.                 startthere[k] = FALSE;
  133.                 bufptr++;
  134.             }
  135.             else { 
  136.                 startthere[k] = TRUE;
  137.                 startcount[k] = (long)getcount(bufptr);
  138.             }
  139.  
  140.             if((k<9) && (*bufptr == '.')) { 
  141.                 k++;
  142.                 bufptr++;
  143.             }
  144.             else 
  145.                 if((*bufptr==' ')||(*bufptr=='\0'))
  146.                     startvals = k;
  147.             else { 
  148.                 startvals = 0;
  149.                 k = 0;
  150.             }
  151.         } while(startvals != k);
  152.         break;
  153.     case 't':            /* Two-sided mode flag */
  154.         *twosided = TRUE;
  155.         break;
  156.     case 'v':            /* Verbose mode flag */
  157.         verbose = TRUE;
  158.         break;
  159.     case 'x':            /* Left offset for odd sides */
  160.         h_offset = dim_to_dots(optarg, resolution);
  161.         break;
  162.     case 'X':            /* Left offset for even sides */
  163.         r_offset = dim_to_dots(optarg, resolution);
  164.         break;
  165.     case 'y':            /* Vertical top offset */
  166.         v_offset = dim_to_dots(optarg, resolution);
  167.         break;
  168.     case '?':
  169.         errflag++;
  170.         break;
  171.     default:
  172.         break;
  173.     }
  174.  
  175.     if (errflag) {
  176.         fprintf(stderr, "\nUsage: %s [-12345lmrt] [-c <copies>] [-f <fonts>] [-o <outfile>]\n       [-p <pages>] [-R resolution] [-s <startpage>] [-x <offset>]\n       [-X <offset>] [-y <offset>] [<infile>]\n", argv[0]);
  177.         exit(2);
  178.     }
  179.  
  180.     /*
  181.       * Allow for input file names of type
  182.      * xx.dvi, xx.yy.dvi, xx, or xx.yy
  183.      * Append ".dvi" if it's not already there.
  184.      *
  185.      * Get the .dvi file name from the input line
  186.      */
  187.     strcpy(dviname, argv[optind]);
  188.     if((strstr(dviname, DVIFILE_SUFFIX)) == NULL)
  189.         strcat(dviname, DVIFILE_SUFFIX);
  190.  
  191.     /*
  192.        * Allow for output file names of type;
  193.       * xx.pcl, xx.yy.pcl, xx, or xx.yy
  194.       * Append ".pcl" if it's not already there.
  195.      *
  196.      * The .dvi file name was input via the -o option.
  197.     if((strstr(bitname, BITFILE_SUFFIX)) == NULL)
  198.         strcat(bitname, BITFILE_SUFFIX);
  199.       */
  200.  
  201.     if(verbose) { 
  202.         strcpy(usgname, dviname);
  203.         strcat(usgname, USGFILE_SUFFIX);
  204.     }
  205.  
  206.     if(*twosided) { 
  207.         if(!startvals && !(startcount[0] % 2)) { 
  208.             if(startthere[0])
  209.                 startcount[0]--;
  210.             else { 
  211.                 startthere[0] = TRUE;
  212.                 startcount[0] = 1;
  213.             }
  214.         }
  215.         if(maxpages % 2)
  216.             maxpages++;
  217.         o_offset = h_offset;
  218.         e_offset = r_offset;
  219.     }
  220.  
  221.     if(verbose) { 
  222.         fprintf(stderr,"Options selected:\n");
  223.         fprintf(stderr,"Starting page:     ");
  224.         for(k=0; k<=startvals; k++) { 
  225.             if(startthere[k])
  226.                 fprintf(stderr,"%d",startcount[k]);
  227.             else
  228.                 fprintf(stderr,"*");
  229.             if(k<startvals)
  230.                 fprintf(stderr,".");
  231.             else
  232.                 fprintf(stderr,"\n");
  233.         }
  234.         fprintf(stderr,"Maximum numbers of pages:    %d\n",maxpages);
  235.         fprintf(stderr,"Number of copies:        %d\n",*numcopies);
  236.         if(*twosided)
  237.             fprintf(stderr,"Two-sided printing\n");
  238.         if(manualfeed)
  239.             fprintf(stderr,"Feed pages maually\n");
  240.     }
  241. }
  242.