home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / 07config / mx.c next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.7 KB  |  127 lines

  1. /*
  2.  *    mx -- control Epson MX-series printer
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <local\std.h>
  8. #include <local\printer.h>
  9.  
  10. extern PRINTER prt;    /* printer data */
  11.  
  12. main(argc, argv)
  13. int argc;
  14. char **argv;
  15. {
  16.     int ch, font;
  17.     BOOLEAN errflag;    /* option error */
  18.     BOOLEAN clrflag;    /* clear special fonts */
  19.     BOOLEAN rflag;        /* hardware reset */
  20.     BOOLEAN tflag;        /* top-of-form */
  21.     FILE *fout;
  22.     static char pgm[MAXNAME + 1] = { "mx" };
  23.  
  24.     extern void fatal(char *, char *, int);
  25.     extern char *getpname(char *, char *);
  26.     extern int getopt(int, char **, char *);
  27.     extern char *optarg;
  28.     extern int optind, opterr;
  29.     extern int setprnt();
  30.     extern int clrprnt(FILE *);
  31.     extern int setfont(int, FILE *);
  32.  
  33.     if (_osmajor >= 3)
  34.         getpname(*argv, pgm);
  35.  
  36.     if (setprnt() == -1) {
  37.         fprintf(stderr, "%s: Bad printer configuration\n", pgm);
  38.         exit(1);
  39.     }
  40.  
  41.     /* interpret command line */
  42.     errflag = clrflag = rflag = tflag = FALSE;
  43.     font = 0;
  44.     fout = stdprn;
  45.     while ((ch = getopt(argc, argv, "bcdefino:prtu")) != EOF) {
  46.         switch (ch) {
  47.         case 'b':
  48.             /* set bold */
  49.             font |= EMPHASIZED;
  50.             break;
  51.         case 'c':
  52.             /* set compressed */
  53.             font |= CONDENSED;
  54.             break;
  55.         case 'd':
  56.             /* set double strike */
  57.             font |= DOUBLE;
  58.             break;
  59.         case 'e':
  60.             /* set double strike */
  61.             font |= EXPANDED;
  62.             break;
  63.         case 'i':
  64.             /* set italic */
  65.             font |= ITALICS;
  66.             break;
  67.         case 'n':
  68.             /* set normal (clear all special fonts) */
  69.             clrflag = TRUE;
  70.             break;
  71.         case 'o':
  72.             /* use specified output stream */
  73.             if ((fout = fopen(optarg, "w")) == NULL)
  74.                 fatal(pgm, "cannot open output stream", 1);
  75.             break;
  76.         case 'p':
  77.             /* preview control strings on stdout */
  78.             fout = stdout;
  79.             break;
  80.         case 'r':
  81.             /* hardware reset */
  82.             rflag = TRUE;
  83.             break;
  84.         case 't':
  85.             /* top of form */
  86.             tflag = TRUE;
  87.             break;
  88.         case 'u':
  89.             /* set underline */
  90.             font |= UNDERLINE;
  91.             break;
  92.         case '?':
  93.             /* unknown option */
  94.             errflag = TRUE;
  95.             break;
  96.         }
  97.     }
  98.  
  99.     /* report errors, if any */
  100.     if (errflag == TRUE || argc == 1) {
  101.         fprintf(stderr, "Usage: %s -option\n", pgm);
  102.         fprintf(stderr,
  103.             "b=bold, c=compressed, d=double strike, e=expanded\n");
  104.         fprintf(stderr,
  105.             "i=italic, n=normal, o file=output to file\n");
  106.         fprintf(stderr,
  107.             "p=preview, r=reset, t=top-of-form, u=underline\n");
  108.         exit(2);
  109.     }
  110.  
  111.     /* do hardware reset and formfeed first */
  112.     if (rflag == TRUE)
  113.         fputs(prt.p_init, fout);
  114.     else if (tflag == TRUE)
  115.         fputc('\f', fout);
  116.  
  117.     /* clear or set the aggregate font */
  118.     if (clrflag == TRUE)
  119.         clrprnt(fout);
  120.     else if (setfont(font, fout) == FAILURE) {
  121.         fprintf(stderr, "%s: Bad font spec\n", pgm);
  122.         exit(3);
  123.     }
  124.  
  125.     exit(0);
  126. }
  127.