home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR23 / TOUCH2.ZIP / CONF.C < prev    next >
C/C++ Source or Header  |  1993-08-14  |  22KB  |  1,095 lines

  1. /*
  2.  * conf.c - read configuration file
  3.  *
  4.  * V. Abell
  5.  */
  6.  
  7. /*
  8.  * Copyright 1993 Victor A. Abell, Lafayette, Indiana  47906.  All rights
  9.  * reserved.
  10.  *
  11.  * Written by Victor A. Abell.
  12.  *
  13.  * Permission is granted to anyone to use this software for any purpose on
  14.  * any computer system, and to alter it and redistribute it freely, subject
  15.  * to the following restrictions:
  16.  *
  17.  * 1. Victor A. Abell is not responsible for any consequences of the use of
  18.  * this software.
  19.  *
  20.  * 2. The origin of this software must not be misrepresented, either by
  21.  *    explicit claim or by omission.  Credit to Victor A. Abell must
  22.  *    appear in documentation and sources.
  23.  *
  24.  * 3. Altered versions must be plainly marked as such, and must not be
  25.  *    misrepresented as being the original software.
  26.  *
  27.  * 4. This notice may not be removed or altered.
  28.  */
  29. #ifndef lint
  30. static char copyright[] =
  31. "@(#) Copyright 1993 Victor A. Abell.\nAll rights reserved.\n";
  32. #endif
  33.  
  34. #include "touch2.h"
  35. #include <ctype.h>
  36. #include <stdlib.h>
  37. #include <string.h>
  38.  
  39. static int AsmHex(char *c);
  40. static int AsmPrStr(char **s, char *m, char *v);
  41. static short FindClr(char *v);
  42. static int SetBaudRate(char *b, char *v);
  43. static int SetBkClr(char *b, char *v);
  44. static int SetCksum(char *b, char *v);
  45. static int SetComPort(char *b, char *v);
  46. static int SetDumpFmt(char *b, char *v);
  47. static int SetPcDisp(char *b, char *v);
  48. static int SetQDumpNm(char *b, char *v);
  49. static int SetRDumpNm(char *b, char *v);
  50. static int SetFrameSz(char *b, char *v);
  51. static int SetGraphNm(char *b, char *v);
  52. static int SetNormSp(char *b, char *v);
  53. static int SetParity(char *b, char *v);
  54. static int SetPromptBkClr(char *b, char *v);
  55. static int SetPromptTxtClr(char *b, char *v);
  56. static int SetSSBits(char *b, char *v);
  57. static int SetTxtClr(char *b, char *v);
  58. static int SetDispWarn(char *b, char *v);
  59.  
  60. /*
  61.  * The Colors[] table is ordered by color index -- i.e., the color
  62.  * index is implied from the position of an entry in the table.  So
  63.  * don't change the order of the entries.
  64.  */
  65.  
  66. struct clr Colors[] = {
  67.     { "black",        _BLACK },        /* 0 */
  68.     { "blue",        _BLUE },        /* 1 */
  69.     { "green",        _GREEN },        /* 2 */
  70.     { "cyan",        _CYAN },        /* 3 */
  71.     { "red",        _RED },            /* 4 */
  72.     { "magenta",        _MAGENTA },        /* 5 */
  73.     { "brown",        _BROWN },        /* 6 */
  74.     { "white",        _WHITE },        /* 7 */
  75.     { "gray",               _GRAY },        /* 8 */
  76.     { "light blue",        _LIGHTBLUE },        /* 9 */
  77.     { "light green",    _LIGHTGREEN },        /* 10 */
  78.     { "light cyan",        _LIGHTCYAN },        /* 11 */
  79.     { "light red",        _LIGHTRED },        /* 12 */
  80.     { "light magenta",    _LIGHTMAGENTA },    /* 13 */
  81.     { "yellow",        _YELLOW },        /* 14 */
  82.     { "bright white",    _BRIGHTWHITE },        /* 15 */
  83.     { NULL,            0L },
  84. };
  85.  
  86. struct kcmd {
  87.     char *nm;            /* keyword */
  88.     int (*fun)();            /* processing function */
  89. } Keywd [] = {
  90.     { "aftergraph",        SetAftGraph },        /* also -a */
  91.     { "ag",            SetAftGraph },        /* also -a */
  92.     { "bar",        SetBarChar },        /* also -b */
  93.     { "baudrate",        SetBaudRate },
  94.     { "br",            SetBaudRate },
  95.     { "background",        SetBkClr },
  96.     { "bk",            SetBkClr },
  97.     { "beforegraph",    SetBefGraph },        /* also -B */
  98.     { "b4g",        SetBefGraph },        /* also -B */
  99.     { "checksum",        SetCksum },        /* also -C */
  100.     { "cksum",        SetCksum },        /* also -C */
  101.     { "comport",        SetComPort },
  102.     { "dump",        SetDumpFmt },        /* partially -q */
  103.     { "framesize",        SetFrameSz },
  104.     { "gmax",        SetGmaxLvl },        /* also -G */
  105.     { "gmin",        SetGminLvl },        /* also -g */
  106.     { "graphname",        SetGraphNm },
  107.     { "graphtitle",        SetGraphTtl },
  108.     { "gttl",        SetGraphTtl },
  109.     { "intersection",    SetIntChar },        /* also -i */
  110.     { "ic",            SetIntChar },        /* also -i */
  111.     { "line",        SetLineChar },        /* also -l */
  112.     { "lpp",        SetLpp },        /* also -L */
  113.     { "pcd",        SetPcDisp },        /* also -P */
  114.     { "pgctdisp",        SetPcDisp },        /* also -P */
  115.     { "port",        SetComPort },
  116.     { "promptbk",        SetPromptBkClr },
  117.     { "pbk",        SetPromptBkClr },
  118.     { "prompttext",        SetPromptTxtClr },
  119.     { "ptxt",        SetPromptTxtClr },
  120.     { "qdumpname",        SetQDumpNm },
  121.     { "rdumpname",        SetRDumpNm },
  122.     { "parity",        SetParity },
  123.     { "printer",        SetPrinter },        /* also -p */
  124.     { "startstop",        SetSSBits },
  125.     { "stst",        SetSSBits },
  126.     { "text",        SetTxtClr },
  127.     { "titlevar",        SetTtlVar },        /* also -v */
  128.     { "tv",            SetTtlVar },        /* also -v */
  129.     { "warn",        SetDispWarn, },
  130.     { NULL,            NULL },
  131. };
  132.  
  133. char *AftGraph = NULL;            /* after graph printer control */
  134. char *BefGraph = NULL;            /* before graph printer control */
  135. char Gttl[GTTLLNL+1];            /* graph title line */
  136. short Lineval = 0;            /* line value definition status */
  137. short PromptBkClrx = DEFPBCX;        /* prompt background color */
  138. short PromptTxtClrx = DEFPTCX;        /* prompt text color */
  139.  
  140.  
  141. /*
  142.  * Asm1Ch() - assemble one character
  143.  *
  144.  * return = number of characters extracted from definition string
  145.  *        (-1 = error)
  146.  */
  147.  
  148. int
  149. Asm1Ch(s, r)
  150.     char *s;            /* pointer to string that defines the
  151.                      * character */
  152.     char *r;            /* pointer to result */
  153. {
  154.     int b, i, n;
  155.     register char *c;
  156.     char tc;
  157.  
  158.     c = s;
  159.     if (*c == '\\') {
  160.  
  161.     /*
  162.      * `\' is the prefix for special strings.
  163.      */
  164.         c++;
  165.         switch(*c) {
  166.  
  167.         case 'e':                /* \e = ESC */
  168.         case 'E':
  169.             *r = ESC;
  170.             break;
  171.         case 'f':                /* \f = FF */
  172.         case 'F':
  173.             *r =  '\f';
  174.             break;
  175.         case 'n':                /* \n = LF */
  176.         case 'N':
  177.             *r = '\n';
  178.             break;
  179.         case 'r':                /* \r = CR */
  180.         case 'R':
  181.             *r = '\r';
  182.             break;
  183.         case 't':                /* \t = TAB */
  184.         case 'T':
  185.             *r = '\t';
  186.             break;
  187.         case '^':                /* \^x = CTRL-x */
  188.             tc = islower(*(++c)) ? toupper(*c) : *c;
  189.             if (tc >= '@' && tc <= 'Z')
  190.                 *r = tc - '@';
  191.             else
  192.                 return(0);
  193.             break;
  194.         case '\\':                /* \\ = \ */
  195.             *r = '\\';
  196.             break;
  197.         default:
  198.             if (*c == '0' && (*(c+1) == 't' || *(c+1) == 'o')) {
  199.  
  200.             /*
  201.              * \0tnnn = decimal character value
  202.              * \0onnn = octal character value
  203.              */
  204.                 c++;
  205.                 b = *c++ - 'o';
  206.                 for (i = n = 0; i < 3; c++, i++) {
  207.                 if ( ! isascii(*c))
  208.                     return(0);
  209.                 if (b) {
  210.                     if (*c >= '0' && *c <= '9')
  211.                     n = (n * 10) + *c - '0';
  212.                     else
  213.                     return(0);
  214.                 } else {
  215.                     if (*c >= '0' && *c <= '7')
  216.                     n = (n << 3) + *c - '0';
  217.                     else
  218.                     return(0);
  219.                 }
  220.                 }
  221.                 *r = n;
  222.                 return(c - s);
  223.             } else if (isxdigit(*c)) {
  224.  
  225.             /*
  226.              * \[0-9a-f][0-9a-f] = hexadecimal character value
  227.              */
  228.                 if ((n = AsmHex(c)) == -1)
  229.                 return(0);
  230.                 *r = n << 4;
  231.                 if ((n = AsmHex(c+1)) == -1)
  232.                 return(0);
  233.                 *r += n;
  234.                 return(c + 2 - s);
  235.             } else
  236.                 return(0);
  237.         }
  238.         return(c + 1 - s);
  239.     }
  240. /*
  241.  * Without a leading `\', characters represent themselves.
  242.  */
  243.     *r = *c;
  244.     return(1);
  245. }
  246.  
  247.  
  248. /*
  249.  * AsmHex() - assemble one hex character
  250.  */
  251.  
  252. static int
  253. AsmHex(c)
  254.     char *c;            /* character pointer */
  255. {
  256.     char tc;
  257.  
  258.     if (*c >= '0' && *c <= '9')
  259.         return((int)*c - (int)'0');
  260.     if (isascii(*c) && isalpha(*c)) {
  261.         tc = isupper(*c) ? tolower(*c) : *c;
  262.         if (tc >= 'a' && tc <= 'f')
  263.             return(10 + tc - 'a');
  264.     }
  265.     return(-1);
  266. }
  267.  
  268.  
  269. /*
  270.  * AsmPrStr() - assemble printer string
  271.  */
  272.  
  273. static int
  274. AsmPrStr(s, m, v)
  275.     char **s;            /* string destination pointer */
  276.     char *m;            /* error message value */
  277.     char *v;            /* value to assemble */
  278. {
  279.     char bf[PRTRCTLLN+1];
  280.     size_t l;
  281.  
  282.     if (CvtPrtrStr(v, bf, sizeof(bf)) == -1) {
  283.         (void) fprintf(stderr, "%s: can't convert \"%s\" to %s string.",
  284.             Pn, v, m);
  285.         return(0);
  286.     }
  287.     if (*s) {
  288.         (void) free(*s);
  289.         *s = NULL;
  290.     }
  291.     l = strlen(v) + 1;
  292.     if ((*s = (char *)malloc(l)) == NULL) {
  293.         (void) fprintf(stderr, "%s: no space for %s.\n", Pn, m);
  294.         return(0);
  295.     }
  296.     (void) strcpy(*s, v);
  297.     return(1);
  298. }
  299.  
  300.  
  301. /*
  302.  * Atof() - convert digits to floating point, recognizing either `.'
  303.  *        or `,' as the fractional separator
  304.  */
  305.  
  306. int
  307. Atof(s, d, m, t)
  308.     char *s;            /* string to convert */
  309.     double *d;            /* converted value */
  310.     char *m;            /* conversion error message */
  311.     char *t;            /* terminating character */
  312. {
  313.     char *cp;
  314.     double dig, rv, sc;
  315.     short f;
  316.  
  317.     for (cp = s, f = 0, rv = 0.0; *cp; cp++) {
  318.         if (*cp == ' ')
  319.             continue;
  320.         if (*cp == '.' || *cp == ',') {
  321.             if (f) {
  322.  
  323. Atof_error:
  324.                 if (m)
  325.                 (void) fprintf(stderr,
  326.                     "%s: can't convert %s: %s\n", Pn, m, s);
  327.                 *d = rv;
  328.                 if (t)
  329.                     *t = *cp;
  330.                 return(0);
  331.             }
  332.             f = 1;
  333.             sc = 0.1;
  334.             continue;
  335.         }
  336.         if (*cp < '0' || *cp > '9')
  337.             goto Atof_error;
  338.         dig = (double)(*cp - '0');
  339.         if (f) {
  340.             rv += dig * sc;
  341.             sc *= 0.1;
  342.         } else
  343.             rv = (rv * 10.0) + dig;
  344.     }
  345.     *d = rv;
  346.     if (t)
  347.         *t = *cp;
  348.     return(1);
  349. }
  350.  
  351.  
  352. /*
  353.  * CvtPrtrStr() - convert spacing string
  354.  */
  355.  
  356. int
  357. CvtPrtrStr(s, r, n)
  358.     char *s;            /* string to convert */
  359.     char *r;            /* result buffer */    
  360.     int n;                /* result buffer length */
  361. {
  362.     int i, l;
  363.  
  364.     for (i = 0; *s && i < (n - 1); i++) {
  365.         if ((l = Asm1Ch(s, r + i)) < 1)
  366.             return(-1);
  367.         s += l;
  368.     }
  369.     if (*s)
  370.         return(-1);
  371.     r[i] = '\0';
  372.     return(i);
  373. }
  374.  
  375.  
  376. /*
  377.  * EntPrtStr() -- enter printer control strings
  378.  */
  379.  
  380. int
  381. EntPrtStr(a, b)
  382.     char *a;            /* after graph control string */
  383.     char *b;            /* before graph control string */
  384. {
  385.     size_t len;
  386.  
  387.     if (AftGraph) {    
  388.         (void) free(AftGraph);
  389.         AftGraph = NULL;
  390.     }
  391.     if (BefGraph) {
  392.         (void) free(BefGraph);
  393.         BefGraph = NULL;
  394.     }
  395.     len = strlen(a);
  396.     if ((AftGraph = (char *)malloc(len + 1)) == NULL) {
  397.         (void) fprintf(stderr,
  398.             "%s: no space for after graph control string\n", Pn);
  399.         return(0);
  400.     }
  401.     (void) strcpy(AftGraph, a);
  402.     len = strlen(b);
  403.     if ((BefGraph = (char *)malloc(len + 1)) == NULL) {
  404.         (void) fprintf(stderr,
  405.             "%s: no space for before graph control string\n", Pn);
  406.         return(0);
  407.     }
  408.     (void) strcpy(BefGraph, b);
  409.     return(1);
  410. }
  411.  
  412.  
  413. /*
  414.  * FindClr() - find color
  415.  */
  416.  
  417. static short
  418. FindClr(v)
  419.     char *v;            /* search value */
  420. {
  421.     short i;
  422.  
  423.     for (i = 0; Colors[i].nm; i++) {
  424.         if (strcmpi(Colors[i].nm, v) == 0)
  425.             return(i);
  426.         if (strnicmp(v, "bright", 6) == 0
  427.         &&  v[6] != ' '
  428.         &&  strnicmp(Colors[i].nm, "bright ", 7) == 0
  429.         &&  strcmpi(&Colors[i].nm[7], &v[6]) == 0)
  430.             return(i);
  431.         if (strnicmp(v, "light", 5) == 0
  432.         &&  v[5] != ' '
  433.         &&  strnicmp(Colors[i].nm, "light ", 6) == 0
  434.         &&  strcmpi(&Colors[i].nm[6], &v[5]) == 0)
  435.             return(i);
  436.     }
  437.     return(-1);
  438. }
  439.  
  440.  
  441. /*
  442.  * ReadConf() - read configuration file
  443.  */
  444.  
  445. int
  446. ReadConf()
  447. {
  448.     char buf[128], *cf, *tp, *vp;
  449.     FILE *cfs;
  450.     short e = 1;
  451.     short f, len;
  452.     struct kcmd *kp, *mp;
  453.     short rv = 1;
  454.  
  455.     for (f = 0; f < 10; f++)
  456.         TtlVar[f] = NULL;
  457.     if ((cf = getenv("TOUCH2")) == NULL) {
  458.         e = 0;
  459.         cf = "TOUCH2.CF";
  460.     }
  461.     if ((cfs = fopen(cf, "rt")) == NULL) {
  462.         if ( ! e)
  463.             return(1);
  464.         (void) fprintf(stderr,
  465.             "%s: can't open configuration file \"%s\"\n", Pn, cf);
  466.         return(0);
  467.     }
  468.     while (fgets(buf, sizeof(buf), cfs)) {
  469.         if (*buf == '#' || *buf == '\n')
  470.             continue;
  471.         if ((tp = strchr(buf, '\n')) != NULL)
  472.             *tp = '\0';
  473.         if ((vp = strchr(buf, '=')) == NULL) {
  474.             (void) fprintf(stderr,
  475.                 "%s: configuration line lacks `=': %s\n",
  476.                 Pn, buf);
  477.             rv = 0;
  478.             continue;
  479.         }
  480.         for (tp = vp - 1; tp > buf; tp--) {
  481.             if (*tp != ' ') 
  482.                 break;
  483.         }
  484.         len = tp + 1 - buf;
  485.         for (vp++; *vp; vp++) {
  486.             if (*vp != ' ');
  487.                 break;
  488.         }
  489.         for (f = 0, kp = Keywd; kp->nm; kp++) {
  490.             if (strnicmp(buf, kp->nm, len) == 0) {
  491.                 f++;
  492.                 mp = kp;
  493.             }
  494.         }
  495.         if (f == 1) {
  496.             if ((*mp->fun)(buf, vp) == 0)
  497.                 rv = 0;
  498.         } else {
  499.             (void) fprintf(stderr,
  500.                 "%s: %s keyword in configuraton line: %s\n",
  501.                 Pn, (!f) ? "Unknown" : "Ambiguous", buf);
  502.             rv = 0;
  503.         }
  504.     }
  505.     (void) fclose(cfs);
  506.     if ( ! TestGlev())
  507.         rv = 0;
  508.     return(rv);
  509. }
  510.  
  511.  
  512. /*
  513.  * SetAftGraph() - set after graph printer control string
  514.  */
  515.  
  516. int
  517. SetAftGraph(b, v)
  518.     char *b;            /* configuration line buffer */
  519.     char *v;            /* start of value string */
  520. {
  521.     return(AsmPrStr(&AftGraph, "after graph printer control string", v));
  522. }
  523.  
  524.  
  525. /*
  526.  * SetBarChar() - set graph's bar character
  527.  */
  528.  
  529. int
  530. SetBarChar(b, v)
  531.     char *b;            /* configuration line buffer */
  532.     char *v;            /* start of value string */
  533. {
  534.     int i;
  535.  
  536.     i = Asm1Ch(v, BarCh);
  537.     if (i < 1 || v[i] != '\0') {
  538.         (void) fprintf(stderr, "%s: bad bar character definition: %s\n",
  539.             Pn, b);
  540.         return(0);
  541.     }
  542.     return(1);
  543. }
  544.  
  545.  
  546. /*
  547.  * SetBaudRate() - process "baudrate" line
  548.  */
  549.  
  550. static int
  551. SetBaudRate(b, v)
  552.     char *b;            /* configuration line buffer */
  553.     char *v;            /* start of value string */
  554. {
  555.     short br, bx;
  556.  
  557.     br = (short)atoi(v);
  558.     for (bx = 0; Baud[bx]; bx++) {
  559.         if (br == Baud[bx]) {
  560.             Baudx = bx;
  561.             return(1);
  562.         }
  563.     }
  564.     (void) fprintf(stderr, "%s: unknown baud rate: %s\n", Pn, b);
  565.     return(0);
  566. }
  567.  
  568.  
  569. /*
  570.  * SetBefGraph() - set before graph printer control string
  571.  */
  572.  
  573. int
  574. SetBefGraph(b, v)
  575.     char *b;            /* configuration line buffer */
  576.     char *v;            /* start of value string */
  577. {
  578.     return(AsmPrStr(&BefGraph, "before graph printer control string", v));
  579. }
  580.  
  581.  
  582. /*
  583.  * SetBkClr() - set background color
  584.  */
  585.  
  586. static int
  587. SetBkClr(b, v)
  588.     char *b;            /* configuration line buffer */
  589.     char *v;            /* start of value string */
  590. {
  591.     short i;
  592.  
  593.     if ((i = FindClr(v)) < 0) {
  594.         (void) fprintf(stderr, "%s: unknown background color: %s\n",
  595.             Pn, b);
  596.         return(0);
  597.     }
  598.     BkClrx = i;
  599.     return(1);
  600. }
  601.  
  602.  
  603. /*
  604.  * SetCksum() - set checksum status
  605.  */
  606.  
  607. static int
  608. SetCksum(b, v)
  609.     char *b;            /* configuration line buffer */
  610.     char *v;            /* start of value string */
  611. {
  612.     if (strcmpi(v, "on") == 0) {
  613.         Cksum = 1;
  614.         return(1);
  615.     } else if (strcmpi(v, "off") == 0) {
  616.         Cksum = 0;
  617.         return(1);
  618.     }
  619.     (void) fprintf(stderr, "%s: unknown checksum status: %s\n", Pn, b);
  620.     return(0);
  621. }
  622.  
  623.  
  624. /*
  625.  * SetComPort() - set COM port number ([12])
  626.  */
  627.  
  628. static int
  629. SetComPort(b, v)
  630.     char *b;            /* configuration line buffer */
  631.     char *v;            /* start of value string */
  632. {
  633.     short p;
  634.  
  635.     p = (short) atoi(v);
  636.     if (p == 1 || p == 2) {
  637.         Port = p - 1;
  638.         return(1);
  639.     }
  640.     (void) fprintf(stderr, "%s: illegal port number: %s\n", Pn, b);
  641.     return(0);
  642. }
  643.  
  644.  
  645. /*
  646.  * SetDispWarn() - set display warning status
  647.  */
  648.  
  649. static int
  650. SetDispWarn(b, v)
  651.     char *b;            /* configuration line buffer */
  652.     char *v;            /* start of value string */
  653. {
  654.     if (strcmpi(v, "on") == 0) {
  655.         Warn = 1;
  656.         return(1);
  657.     } else if (strcmpi(v, "off") == 0) {
  658.         Warn = 0;
  659.         return(1);
  660.     }
  661.     (void) fprintf(stderr, "%s: unknown display warning status: %s\n",
  662.         Pn, b);
  663.     return(0);
  664. }
  665.  
  666.  
  667. /*
  668.  * SetDumpFmt() - set dump format, raw or QuattroPro
  669.  */
  670.  
  671. int
  672. SetDumpFmt(b, v)
  673.     char *b;            /* configuration line buffer */
  674.     char *v;            /* start of value string */
  675. {
  676.     switch (*v) {
  677.  
  678.     case 'q':
  679.     case 'Q':
  680.         Qp = 1;
  681.         break;
  682.     case 'r':
  683.     case 'R':
  684.         Qp = 0;
  685.         break;
  686.     default:
  687.         (void) fprintf(stderr, "%s: unknown dump type: %s\n", Pn, b);
  688.         return(0);
  689.     }
  690.     return(1);
  691. }
  692.  
  693.  
  694. /*
  695.  * SetPcDisp() - set page count display status
  696.  */
  697.  
  698. static int
  699. SetPcDisp(b, v)
  700.     char *b;            /* configuration line buffer */
  701.     char *v;            /* start of value string */
  702. {
  703.     if (strcmpi(v, "on") == 0) {
  704.         PcDisp = 1;
  705.         return(1);
  706.     } else if (strcmpi(v, "off") == 0) {
  707.         PcDisp = 0;
  708.         return(1);
  709.     }
  710.     (void) fprintf(stderr, "%s: unknown page count status: %s\n", Pn, b);
  711.     return(0);
  712. }
  713.  
  714.  
  715. /*
  716.  * SetQDumpNm() - set QuattroPro dump file name
  717.  */
  718.  
  719. static int
  720. SetQDumpNm(b, v)
  721.     char *b;            /* configuration line buffer */
  722.     char *v;            /* start of value string */
  723. {
  724.     if (strlen(v) > DUMPFNL-1) {
  725.         (void) fprintf(stderr,
  726.             "%s: QuattroPro dump file name too long: %s\n",
  727.             Pn, b);
  728.         return(0);
  729.     }
  730.     (void) strcpy(DumpfnQ, v);
  731.     return(1);
  732. }
  733.  
  734.  
  735. /*
  736.  * SetRDumpNm() - set raw dump file name
  737.  */
  738.  
  739. static int
  740. SetRDumpNm(b, v)
  741.     char *b;            /* configuration line buffer */
  742.     char *v;            /* start of value string */
  743. {
  744.     if (strlen(v) > DUMPFNL-1) {
  745.         (void) fprintf(stderr,
  746.             "%s: raw dump file name too long: %s\n",
  747.             Pn, b);
  748.         return(0);
  749.     }
  750.     (void) strcpy(DumpfnR, v);
  751.     return(1);
  752. }
  753.  
  754.  
  755. /*
  756.  * SetFrameSz() - set frame size ([78] bits)
  757.  */
  758.  
  759. static int
  760. SetFrameSz(b, v)
  761.     char *b;            /* configuration line buffer */
  762.     char *v;            /* start of value string */
  763. {
  764.     short f;
  765.  
  766.     f = (short) atoi(v);
  767.     if (f == 7 || f == 8) {
  768.         Frame = f;
  769.         return(1);
  770.     }
  771.     (void) fprintf(stderr, "%s: illegal frame size: %s\n", Pn, b);
  772.     return(0);
  773. }
  774.  
  775.  
  776. /*
  777.  * SetGmaxLvl() - set graph's maximum level
  778.  */
  779.  
  780. int
  781. SetGmaxLvl(b, v)
  782.     char *b;            /* configuration line buffer */
  783.     char *v;            /* start of value string */
  784. {
  785.     if (Atof(v, &Gmaxl, "graph's maximum level", NULL)) {
  786.         Lineval = 1;
  787.         return(1);
  788.     }
  789.     return(0);
  790. }
  791.  
  792. /*
  793.  * SetGminLvl() - set graph's minimum level
  794.  */
  795.  
  796. int
  797. SetGminLvl(b, v)
  798.     char *b;            /* configuration line buffer */
  799.     char *v;            /* start of value string */
  800. {
  801.     if (Atof(v, &Gminl, "graph's minimum level", NULL)) {
  802.         Lineval = 1;
  803.         return(1);
  804.     }
  805.     return(0);
  806. }
  807.  
  808.  
  809. /*
  810.  * SetGraphNm() - set graph file name
  811.  */
  812.  
  813. static int
  814. SetGraphNm(b, v)
  815.     char *b;            /* configuration line buffer */
  816.     char *v;            /* start of value string */
  817. {
  818.     if (strlen(v) > DUMPFNL-1) {
  819.         (void) fprintf(stderr, "%s: graph file name too long: %s\n",
  820.             Pn, b);
  821.         return(0);
  822.     }
  823.     (void) strcpy(Graphfn, v);
  824.     return(1);
  825. }
  826.  
  827.  
  828. /*
  829.  * SetGraphTtl() - set graph title line
  830.  */
  831.  
  832. int
  833. SetGraphTtl(b, v)
  834.     char *b;            /* configuration line buffer */
  835.     char *v;            /* start of value string */
  836. {
  837.     if (strlen(v) > GTTLLNL) {
  838.         (void) fprintf(stderr, "%s: graph title line too long: %s\n",
  839.             Pn, b);
  840.         return(0);
  841.     }
  842.     (void) strcpy(Gttl, v);
  843.     return(1);
  844. }
  845.  
  846.  
  847. /*
  848.  * SetIntChar() - set graph's bar nd max/min line intersection character
  849.  */
  850.  
  851. int
  852. SetIntChar(b, v)
  853.     char *b;            /* configuration line buffer */
  854.     char *v;            /* start of value string */
  855. {
  856.     int i;
  857.  
  858.     i = Asm1Ch(v, IntCh);
  859.     if (i < 1 || v[i] != '\0') {
  860.         (void) fprintf(stderr,
  861.             "%s: bad bar and max/min line intersection character definition: %s\n",
  862.             Pn, b);
  863.         return(0);
  864.     }
  865.     return(1);
  866. }
  867.  
  868.  
  869. /*
  870.  * SetLineChar() - set graph's max/min line character
  871.  */
  872.  
  873. int
  874. SetLineChar(b, v)
  875.     char *b;            /* configuration line buffer */
  876.     char *v;            /* start of value string */
  877. {
  878.     int i;
  879.  
  880.     i = Asm1Ch(v, LineCh);
  881.     if (i < 1 || v[i] != '\0') {
  882.         (void) fprintf(stderr,
  883.             "%s: bad max/min line character definition: %s\n",
  884.             Pn, b);
  885.         return(0);
  886.     }
  887.     return(1);
  888. }
  889.  
  890.  
  891. /*
  892.  * SetLpp() - set graph lines per page
  893.  */
  894.  
  895. int
  896. SetLpp(b, v)
  897.     char *b;            /* configuration line buffer */
  898.     char *v;            /* start of value string */
  899. {
  900.     int t;
  901.  
  902.     if ((t = atoi(v)) <= HDRLPP) {
  903.         (void) fprintf(stderr,
  904.             "%s: lines per page too small (minimum = %d)\n",
  905.             Pn, HDRLPP+1);
  906.         return(0);
  907.     }
  908.     Lpp = t;
  909.     return(1);
  910. }
  911.  
  912.  
  913. /*
  914.  * SetPrinter() - set printer type
  915.  */
  916.  
  917. int
  918. SetPrinter(b, v)
  919.     char *b;            /* configuration line buffer */
  920.     char *v;            /* start of value string */
  921. {
  922.     if (strcmpi(v, "epson") == 0)
  923.         return(EntPrtStr(AFTEPSON, BEFEPSON));
  924.     else if (strcmpi(v, "pcl4") == 0)
  925.         return(EntPrtStr(AFTPCL4, BEFPCL4));
  926.     else if (strcmpi(v, "ppds") == 0)
  927.         return(EntPrtStr(AFTPPDS, BEFPPDS));
  928.     else {
  929.         (void) fprintf(stderr, "%s: unidentified printer: %s\n", Pn, b);
  930.         return(0);
  931.     }
  932.     return(1);
  933. }
  934.  
  935.  
  936. /*
  937.  * SetParity() - set parity ({none,even,odd})
  938.  */
  939.  
  940. static int
  941. SetParity(b, v)
  942.     char *b;            /* configuration line buffer */
  943.     char *v;            /* start of value string */
  944. {
  945.     short px;
  946.  
  947.     for (px = 0; px < 3; px++) {
  948.         if (strcmpi(v, Par[px].nm) == 0) {
  949.             Parx = px;
  950.             return(1);
  951.         }
  952.     }
  953.     (void) fprintf(stderr, "%s: unknown parity: %s\n", Pn, b);
  954.     return(0);
  955. }
  956.  
  957.  
  958. /*
  959.  * SetPromptBk() - set prompt background color
  960.  */
  961.  
  962. static int
  963. SetPromptBkClr(b, v)
  964.     char *b;            /* configuration line buffer */
  965.     char *v;            /* start of value string */
  966. {
  967.     short i;
  968.  
  969.     if ((i = FindClr(v)) < 0) {
  970.         (void) fprintf(stderr,
  971.             "%s: unknown prompt background color: %s\n", Pn, b);
  972.         return(0);
  973.     }
  974.     if (i > 7) {
  975.         (void) fprintf(stderr,
  976.             "%s: illegal prompt background color: %s\n", Pn, b);
  977.         return(0);
  978.     }
  979.     PromptBkClrx = i;
  980.     return(1);
  981. }
  982.  
  983.  
  984. /*
  985.  * SetPromptTxtClr() - set prompt text color
  986.  */
  987.  
  988. static int
  989. SetPromptTxtClr(b, v)
  990.     char *b;            /* configuration line buffer */
  991.     char *v;            /* start of value string */
  992. {
  993.     short i;
  994.  
  995.     if ((i = FindClr(v)) < 0) {
  996.         (void) fprintf(stderr, "%s: unknown prompt text color: %s\n",
  997.             Pn, b);
  998.         return(0);
  999.     }
  1000.     PromptTxtClrx = i;
  1001.     return(1);
  1002. }
  1003.  
  1004.  
  1005. /*
  1006.  * SetSSBits() - set start/stop bits ([12])
  1007.  */
  1008.  
  1009. static int
  1010. SetSSBits(b, v)
  1011.     char *b;            /* configuration line buffer */
  1012.     char *v;            /* start of value string */
  1013. {
  1014.     short s;
  1015.  
  1016.     s = (short) atoi(v);
  1017.     if (s == 1 || s == 2) {
  1018.         StSt = s;
  1019.         return(1);
  1020.     }
  1021.     (void) fprintf(stderr, "%s: illegal start/stop bit count: %s\n",
  1022.         Pn, b);
  1023.     return(0);
  1024. }
  1025.  
  1026.  
  1027. /*
  1028.  * SetTtlVar() - set title variable value
  1029.  *
  1030.  * titleval=n,<value>
  1031.  */
  1032.  
  1033. int
  1034. SetTtlVar(b, v)
  1035.     char *b;            /* configuration line buffer */
  1036.     char *v;            /* start of value string */
  1037. {
  1038.     short i;
  1039.  
  1040.     if (*v < '0' || *v > '9' || *(v+1) != ',') {
  1041.         (void) fprintf(stderr, "%s: improper variable index: %s\n",
  1042.             Pn, b);
  1043.         return(0);
  1044.     }
  1045.     i = (short)(*v - '0');
  1046.     if (TtlVar[i])
  1047.         (void) free(TtlVar[i]);
  1048.     if ((TtlVar[i] = (char *)malloc(strlen(v+2) + 1)) == NULL) {
  1049.         (void) fprintf(stderr,
  1050.             "%s: no space for title variable %d: %s\n",
  1051.             Pn, i, b);
  1052.         return(0);
  1053.     }
  1054.     (void) strcpy(TtlVar[i], v+2);
  1055.     return(1);
  1056. }
  1057.  
  1058.  
  1059. /*
  1060.  * SetTxtClr() - set text color
  1061.  */
  1062.  
  1063. static int
  1064. SetTxtClr(b, v)
  1065.     char *b;            /* configuration line buffer */
  1066.     char *v;            /* start of value string */
  1067. {
  1068.     short i;
  1069.  
  1070.     if ((i = FindClr(v)) < 0) {
  1071.         (void) fprintf(stderr, "%s: unknown text color: %s\n", Pn, b);
  1072.         return(0);
  1073.     }
  1074.     TxtClrx = i;
  1075.     return(1);
  1076. }
  1077.  
  1078.  
  1079. /*
  1080.  * TestGlev() - test graph level line values
  1081.  */
  1082.  
  1083. int
  1084. TestGlev()
  1085.  
  1086. {
  1087.     if (Gminl && Gmaxl && Gminl >= Gmaxl) {
  1088.         (void) fprintf(stderr,
  1089.             "%s: graph minimum level (%d) >= maximum (%d)\n",
  1090.             Pn, Gminl, Gmaxl);
  1091.         return(0);
  1092.     }
  1093.     return(1);
  1094. }
  1095.