home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / util / printer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  3.7 KB  |  151 lines

  1. /*
  2.  *    printer -- interface functions for printer
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. #include <local\std.h>
  9. #include <local\printer.h>
  10.  
  11. PRINTER prt;    /* printer data */
  12.  
  13. /*
  14.  *    setprnt -- install printer codes from configuration
  15.  *    file for printer (defaults to Epson MX/FX series)
  16.  */
  17.  
  18. #define NSELEM    13
  19.  
  20. int
  21. setprnt()
  22. {
  23.     int n;
  24.     char *s, line[MAXLINE];
  25.     FILE *fp, *fconfig(char *, char *);
  26.  
  27.     /* use local or global config file, if any */
  28.     if ((fp = fconfig("CONFIG", "printer.cnf")) != NULL) {
  29.         n = 0;
  30.         while (fgets(line, MAXLINE, fp) != NULL) {
  31.             if ((s = strtok(line, " \t\n")) == NULL)
  32.                 return (-1);
  33.             switch (n) {
  34.             case 0:
  35.                 strcpy(prt.p_init, s);
  36.                 break;
  37.             case 1:
  38.                 strcpy(prt.p_bold, s);
  39.                 break;
  40.             case 2:
  41.                 strcpy(prt.p_ds, s);
  42.                 break;
  43.             case 3:
  44.                 strcpy(prt.p_ital, s);
  45.                 break;
  46.             case 4:
  47.                 strcpy(prt.p_cmp, s);
  48.                 break;
  49.             case 5:
  50.                 strcpy(prt.p_exp, s);
  51.                 break;
  52.             case 6:
  53.                 strcpy(prt.p_ul, s);
  54.                 break;
  55.             case 7:
  56.                 strcpy(prt.p_xbold, s); 
  57.                 break;
  58.             case 8:
  59.                 strcpy(prt.p_xds, s);
  60.                 break;
  61.             case 9:
  62.                 strcpy(prt.p_xital, s);
  63.                 break;
  64.             case 10:
  65.                 strcpy(prt.p_xcmp, s);
  66.                 break;
  67.             case 11:
  68.                 strcpy(prt.p_xexp, s);
  69.                 break;
  70.             case 12:
  71.                 strcpy(prt.p_xul, s);
  72.                 break;
  73.             default:
  74.                 /* too many lines */
  75.                 return (-1);
  76.             }
  77.             ++n;
  78.         }
  79.         if (n != NSELEM)
  80.             /* probably not enough lines */
  81.             return (-1);
  82.     }
  83.     
  84.     /* or use Epson defaults */
  85.     strcpy(prt.p_init, "\033@");    /* hardware reset */
  86.     strcpy(prt.p_bold, "\033E");    /* emphasized mode */
  87.     strcpy(prt.p_ds, "\033G");    /* double-strike mode */
  88.     strcpy(prt.p_ital, "\0334");    /* italic mode */
  89.     strcpy(prt.p_cmp, "\017");    /* condensed mode */
  90.     strcpy(prt.p_exp, "\016");    /* expanded mode */
  91.     strcpy(prt.p_ul, "\033-1");    /* underline mode */
  92.     strcpy(prt.p_xbold, "\033F");    /* cancel emphasized mode */
  93.     strcpy(prt.p_xds, "\033H");    /* cancel double-strike mode */
  94.     strcpy(prt.p_xital, "\0335");    /* cancel italic mode */
  95.     strcpy(prt.p_xcmp, "\022");    /* cancel condensed mode */
  96.     strcpy(prt.p_xexp, "\024");    /* cancel expanded mode */
  97.     strcpy(prt.p_xul, "\033-0");    /* cancel underline mode */
  98.  
  99.     return (0);
  100. }
  101.  
  102. /*
  103.  *    clrprnt -- clear printer options to default values
  104.  *    (clears individual options to avoid the "paper creep"
  105.  *    that occurs with repeated printer resets and to avoid
  106.  *    changing the printer's notion of top-of-form position)
  107.  */
  108.  
  109. int
  110. clrprnt(fout)
  111. FILE *fout;
  112. {
  113.     fputs(prt.p_xbold, fout);    /* cancel emphasized mode */
  114.     fputs(prt.p_xds, fout);        /* cancel double-strike mode */
  115.     fputs(prt.p_xital, fout);    /* cancel italic mode */
  116.     fputs(prt.p_xcmp, fout);    /* cancel condensed mode */
  117.     fputs(prt.p_xexp, fout);    /* cancel expanded mode */
  118.     fputs(prt.p_xul, fout);        /* cancel underline mode */
  119. } /* end clrprnt() */
  120.  
  121. /*
  122.  *    setfont -- set the printing font to the type specified
  123.  *    by the argument (may be a compound font specification)
  124.  */
  125.  
  126. int
  127. setfont(ftype, fout)
  128. int ftype;    /* font type specifier */
  129. FILE *fout;    /* output stream */
  130. {
  131.     clrprnt(fout);
  132.     if ((ftype & CONDENSED) == CONDENSED)
  133.         if ((ftype & DOUBLE) == DOUBLE ||
  134.             (ftype & EMPHASIZED) == EMPHASIZED)
  135.             return FAILURE;
  136.         else if (*prt.p_cmp)
  137.             fputs(prt.p_cmp, fout);
  138.     if (*prt.p_ds && (ftype & DOUBLE) == DOUBLE)
  139.         fputs(prt.p_ds, fout);
  140.     if (*prt.p_bold && (ftype & EMPHASIZED) == EMPHASIZED)
  141.         fputs(prt.p_bold, fout);
  142.     if (*prt.p_exp && (ftype & EXPANDED) == EXPANDED)
  143.         fputs(prt.p_exp, fout);
  144.     if (*prt.p_ital && (ftype & ITALICS) == ITALICS)
  145.         fputs(prt.p_ital, fout);
  146.     if (*prt.p_ul && (ftype & UNDERLINE) == UNDERLINE)
  147.         fputs(prt.p_ul, fout);
  148.  
  149.     return SUCCESS;
  150. } /* end setfont() */
  151.