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

  1. /*
  2.  *    pr_gcnf -- get configuration for pr program
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <local\std.h>
  8. #include <local\printer.h>
  9. #include "print.h"
  10.  
  11. /* expected number of configuration items */
  12. #define N_NBR    12
  13.  
  14. PRINT pcnf;
  15.  
  16. int
  17. pr_gcnf(pname)
  18. char *pname;
  19. {
  20.     char line[MAXLINE];
  21.     char *s;
  22.     int cnf[N_NBR];
  23.     int n, errcount, good;
  24.     FILE *fp, *fconfig(char *, char *);
  25.  
  26.     /* get configuration file values, if any */
  27.     n = good = errcount = 0;
  28.     if ((fp = fconfig("CONFIG", "pr.cnf")) != NULL) {
  29.         while (n < N_NBR && (s = fgets(line, MAXLINE, fp)) != NULL) {
  30.             cnf[n] = atoi(s);
  31.             ++n;
  32.         }
  33.         if ((s = fgets(line, MAXLINE, fp)) == NULL)
  34.             ++errcount;
  35.         else
  36.             strcpy(pcnf.p_dest, strtok(line, " \t\n"));
  37.         if (n != N_NBR)
  38.             ++errcount;
  39.         if (errcount == 0)
  40.             good = 1;
  41.         if (fclose(fp) == -1)
  42.             fatal(pname, "cannot close config file");
  43.     }
  44.  
  45.     /* use config data is good; use defaults otherwise */
  46.     pcnf.p_top1 = good ? cnf[0]: TOP1;
  47.     pcnf.p_top2 = good ? cnf[1] : TOP2;
  48.     pcnf.p_btm = good ? cnf[2] : BOTTOM;
  49.     pcnf.p_wid = good ? cnf[3] : MAXPCOL;
  50.     pcnf.p_lmarg = good ? cnf[4] : MARGIN;
  51.     pcnf.p_rmarg = good ? cnf[5] : MARGIN;
  52.     pcnf.p_len = good ? cnf[6] : PAGELEN;
  53.     pcnf.p_lpi = good ? cnf[7] : LPI;
  54.     pcnf.p_mode = good ? cnf[8] : 0;
  55.     pcnf.p_lnum = good ? cnf[9] : 0;
  56.     pcnf.p_ff = good ? cnf[10] : 0;
  57.     pcnf.p_tabint = good ? cnf[11] : TABSPEC;
  58.     if (!good)
  59.         strcpy(pcnf.p_dest, "PRN");
  60.     if (pcnf.p_mode == 1)
  61.         pcnf.p_font = CONDENSED;
  62.     strcpy(pcnf.p_hdr, "");
  63.  
  64.     return (errcount);
  65. }
  66.