home *** CD-ROM | disk | FTP | other *** search
- /*
- readcfg.c
- Written by D'Arcy J.M. Cain
-
- Reads configuration file for feedpipe
- fills in the fp_cfg array and returns the number of active lines
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <ctype.h>
- #include <malloc.h>
- #include "feedpipe.h"
-
- int readcfg(FILE *fp)
- {
- char *str;
- int nents = 0, k;
-
- if ((fp_cfg = malloc(1)) == NULL)
- return(0);
-
- while ((str = xgetline(fp, 1)) != NULL)
- {
- if ((fp_cfg = realloc(fp_cfg, sizeof(FP_CFG) * (nents+1))) == NULL)
- {
- free(str);
- return(0);
- }
-
- if ((fp_cfg[nents].name = strtok(str, " \t")) == NULL ||
- (fp_cfg[nents].owner = strtok(NULL, " \t")) == NULL ||
- (fp_cfg[nents].group = strtok(NULL, " \t")) == NULL )
- {
- free(fp_cfg);
- fprintf(stderr, "%s: Invalid configuration for \"%s\"\n",
- progname, str);
- return(0);
- }
-
- if (!strcmp(fp_cfg[nents].owner, "-"))
- fp_cfg[nents].owner = NULL;
-
- if (!strcmp(fp_cfg[nents].group, "-"))
- fp_cfg[nents].group = NULL;
-
- fp_cfg[nents].cmd = fp_cfg[nents].group;
-
- while (*fp_cfg[nents].cmd++)
- ;
-
- fp_cfg[nents].mode = strtol(fp_cfg[nents].cmd, &fp_cfg[nents].cmd, 0);
-
- while (isspace(*fp_cfg[nents].cmd))
- *fp_cfg[nents].cmd++ = 0;
-
- if (!*fp_cfg[nents].cmd)
- {
- free(fp_cfg);
- fprintf(stderr, "%s: Invalid configuration for \"%s\"\n",
- progname, str);
- return(0);
- }
-
- for (k = 0; k < nents; k++)
- {
- if (!strcmp(fp_cfg[k].name, fp_cfg[nents].name))
- {
- free(fp_cfg);
- fprintf(stderr, "%s: Duplicate pipe \"%s\"\n", progname, str);
- return(0);
- }
- }
-
- nents++;
- }
-
- if (!nents)
- free(fp_cfg);
-
- return(nents);
- }
-