home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume6 / newbatcha / parse.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-30  |  3.9 KB  |  203 lines

  1. /*
  2.  *
  3.  *    parse.c - nbatcher line parser for the control file
  4.  *
  5.  *
  6.  *    R.J. Esposito
  7.  *    Bell of Penna.
  8.  *    June 1986
  9.  *
  10.  */
  11.  
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #include <ctype.h>
  15. #include "nbatcher.h"
  16.  
  17. #define MAX_BYTES    1000000L    /* max allowable bytes */
  18.  
  19. parse_entry (line)
  20. char *line;
  21. {
  22.     register char    *p;
  23.     short    num, upper;
  24.     short    lower, dash;
  25.     long    l_num;
  26.  
  27.     upper = 23;    /* upper hour limit */
  28.     lower = 0;    /* lower hour limit */
  29.     dash = 0;
  30.  
  31.     clear_entry (&ep);    /* zero out the structure */
  32.  
  33.     p = (char *) ep.site;
  34.  
  35.     /* get the site name and copy
  36.        it to the structure */
  37.  
  38.     while (*line && *line != COLON)
  39.         *p++ = *line++;
  40.     *p = '\0';
  41.     if (*++line == '\n' || *line == '\0')
  42.         xerror ("illegal number of fields\n");
  43.  
  44.     /* check that its valid */
  45.  
  46.     if (ep.site[0] == '\0')
  47.         xerror ("null site name in control file\n");
  48.  
  49.     /* now, parse the hour string and check
  50.        for valid syntax */
  51.  
  52.     p = (char *) ep.hour;
  53.     while (*line && *line != COLON)
  54.         *p++ = *line++;
  55.  
  56.     *p = '\0';
  57.     if (*++line == '\n' || *line == '\0')
  58.         xerror ("illegal number of fields\n");
  59.  
  60.     if (ep.hour[0] == '\0')
  61.         xerror ("null hour string in control file\n");
  62.  
  63.     /* now re-scan the hour in structure and
  64.        weed out the badies */
  65.  
  66.     if (ep.hour[0] == '*' && ep.hour[1] != '\0')
  67.         xerror ("invalid hour string syntax: %s\n", ep.hour);
  68.     else if (ep.hour[0] == '*')
  69.         goto h_skip;
  70.  
  71.     if (strcmp(ep.hour, "off", 3) == 0 && ep.hour[3] != '\0')
  72.         xerror ("invalid hour string syntax: %s\n", ep.hour);
  73.     else if (strncmp(ep.hour, "off", 3) == 0)
  74.         goto h_skip;
  75.  
  76.     p = (char *) ep.hour;
  77.     if (!isdigit(*p))
  78.         xerror ("non-numeric char in hour string: %c\n", *p);
  79.  
  80.     while (*p) {
  81.         num = 0;
  82.         do {
  83.             num = num*10 + (*p - '0');
  84.         } while (isdigit(*++p));
  85.  
  86.         if (num < lower || num > upper)
  87.             xerror ("illegal hour: %d\n", num);
  88.  
  89.         if (!*p)
  90.             break;
  91.  
  92.         if (*p == '-' && dash)
  93.             xerror ("syntax error in hour field\n");
  94.         else if (*p == '-')
  95.             dash = TRUE;
  96.  
  97.         if (*p != ',' && *p != '-')
  98.             xerror ("non-numeric char in hour string: %c\n", *p);
  99.         else if (!isdigit(*++p))
  100.             xerror ("syntax error in hour field\n");
  101.  
  102.     }
  103.  
  104.     /* now that thats over with, let do the compression
  105.        field.  Only 9-16 is allowed, except a null field
  106.        indicates no compression for this site. */
  107.  
  108. h_skip:
  109.     num = 0;
  110.     while (*line && *line != COLON) {
  111.         if (!isdigit(*line))
  112.             xerror ("non-numeric in compression field\n");
  113.         num = num*10 + (*line++ - '0');
  114.     }
  115.     if (*++line == '\n' || *line == '\0')
  116.         xerror ("illegal number of fields\n");
  117.  
  118.     if (num != 0 && (num < 9 || num > 16))
  119.         xerror ("illegal compression bits: %d\n", num);
  120.  
  121.     ep.c_bits = num;
  122.  
  123.     /* now check the max. bytes for UUCP queue.
  124.        Note: There is a max. allowable # of bytes
  125.          here, set at 1MB.  Change it at your
  126.          own risk.
  127.     */
  128.  
  129.     l_num = 0;
  130.     while (*line && *line != COLON) {
  131.         if (!isdigit(*line))
  132.             xerror ("non-numeric in max. bytes field\n");
  133.  
  134.         l_num = l_num*10 + (*line++ - '0');
  135.     }
  136.  
  137.     if (l_num > MAX_BYTES)
  138.         xerror ("%ld max. bytes exceeds allowable maximun\n", l_num);
  139.  
  140.     if (l_num != 0)
  141.         ep.m_bytes = l_num;
  142.     else
  143.         ep.m_bytes = DFL_BYTES;
  144.  
  145.     /* and finally the command line (if there is one) */
  146.  
  147.     p = (char *) ep.command;
  148.  
  149.     if (*++line != '\n' && *line != '\0') {
  150.         while (*line && *line != '\n')
  151.             *p++ = *line++;
  152.  
  153.         *p = '\0';
  154.     }
  155. }
  156.  
  157. #ifdef USE_PORT_CODE
  158. xerror (fmt, a1, a2)
  159. char *fmt;
  160. char *a1, *a2;
  161. {
  162.     char    buf[BUFSIZ];
  163.  
  164.     sprintf (buf, fmt, a1, a2);
  165.     printf ("nbatcher: %s\n", fmt);
  166.     exit (99);
  167. }
  168.  
  169. #else
  170. xerror (fmt, argp)
  171. char *fmt;
  172. int argp;
  173. {
  174.     char    buf[BUFSIZ];
  175.     char    fbuf[BUFSIZ];
  176.     FILE    prwbuf;
  177.     register char    *cp;
  178.     
  179.     prwbuf._flag = _IOWRT;
  180.     prwbuf._file = _NFILE;
  181.     prwbuf._cnt = 32767;
  182.     prwbuf._ptr = (unsigned char *)buf;
  183.     prwbuf._base = (unsigned char *)buf;
  184.     sprintf (fbuf, "%s: %s", "nbatcher", fmt);
  185.     _doprnt (fbuf, (char *)&argp, &prwbuf);
  186.     putc ('\0', &prwbuf);
  187.     for (cp = buf; *cp != '\0'; cp++)
  188.         putchar (*cp);
  189.  
  190.     exit (99);
  191. }
  192. #endif    /* USE_PORT_CODE */
  193.  
  194. clear_entry (s)
  195. char *s;
  196. {
  197.     register int i;
  198.  
  199.     for (i=0; i<sizeof(struct file_entry); *s++ = '\0', i++)
  200.                 ;
  201.  
  202. }
  203.