Mapper
ReadConfig.c
Go to the documentation of this file.
1 /* ReadConfig
2  * reads the sws.config file and returns answers based on
3  * query tokens
4  */
5 
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <unistd.h>
9 #include <string.h>
10 
11 int ReadConfig(char *answer, char *query)
12 {
13 char *penv, *p;
14 FILE *fpin;
15 char fname[400];
16 char buff[200];
17 int err;
18 
19  penv = getenv("SWSLOC");
20  if(!penv) return(-1);
21 
22  sprintf(fname,"%s/sws.config", penv);
23 
24  if((fpin = fopen(fname,"r")) == NULL)
25  return(-2);
26 
27  err = -3;
28 
29  while(fgets(buff, sizeof(buff), fpin) != NULL)
30  {
31  if(buff[0] != '#')
32  {
33  p = strtok(buff, "=");
34  if(strstr(p,query))
35  {
36  p = strtok('\0'," ");
37  strcpy(answer, p);
38  err = 0;
39  }
40  }
41  }
42 
43  fclose(fpin);
44  return(err);
45 }
int ReadConfig(char *answer, char *query)
Definition: ReadConfig.c:11
fclose(fp)
sprintf(fbuf,"/usr/mapper/nexrad/ngrid.%02d-%02d-%02d-%02d", year, month, day, hour)
char fname[100]
Definition: send_afos.c:6