/[oroborus]/oroborus/src/parserc.c
ViewVC logotype

Diff of /oroborus/src/parserc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1.1.1 by dreamind, Thu May 23 19:55:44 2002 UTC revision 1.2 by dreamind, Thu May 30 13:57:51 2002 UTC
# Line 26  Line 26 
26  #include <string.h>  #include <string.h>
27  #include "parserc.h"  #include "parserc.h"
28    
29  int parseRc(char *file, char *dir, char *rc[][2])  int
30    parseRc (char *file, char *dir, char *rc[][2])
31  {  {
32      char filename[512], buf[512], *lvalue, *rvalue;    char filename[512], buf[512], *lvalue, *rvalue;
33      FILE *fp;    FILE *fp;
34      int i;    int i;
35    
36  #ifdef DEBUG  #ifdef DEBUG
37      printf("entering parseRc\n");    printf ("entering parseRc\n");
38  #endif  #endif
39    
40      if(dir)    if (dir)
41          snprintf(filename, sizeof(filename), "%s/%s", dir, file);      snprintf (filename, sizeof (filename), "%s/%s", dir, file);
42      else    else
43          strncpy(filename, file, sizeof(filename));      strncpy (filename, file, sizeof (filename));
44      fp = fopen(filename, "r");    fp = fopen (filename, "r");
45      if(!fp)    if (!fp)
46          return False;      return False;
47    
48      while(fgets(buf, sizeof(buf), fp))    while (fgets (buf, sizeof (buf), fp))
49      {      {
50          lvalue = strtok(buf, "=");        lvalue = strtok (buf, "=");
51          if(lvalue)        if (lvalue)
52          {          {
53              for(i = 0; rc[i][OPTION]; i++)            for (i = 0; rc[i][OPTION]; i++)
54              {              {
55                  if(!strcmp(lvalue, rc[i][OPTION]))                if (!strcmp (lvalue, rc[i][OPTION]))
56                  {                  {
57                      rvalue = strtok(NULL, "\n");                    rvalue = strtok (NULL, "\n");
58                      if(rvalue)                    if (rvalue)
59                      {                      {
60                          if(rc[i][VALUE])                        if (rc[i][VALUE])
61                              free(rc[i][VALUE]);                          free (rc[i][VALUE]);
62                          rc[i][VALUE] = strdup(rvalue);                        rc[i][VALUE] = strdup (rvalue);
63  #ifdef DEBUG  #ifdef DEBUG
64                          printf("%s=%s\n", rc[i][OPTION], rc[i][VALUE]);                        printf ("%s=%s\n", rc[i][OPTION], rc[i][VALUE]);
65  #endif  #endif
66                      }                      }
67                  }                  }
68              }              }
69          }          }
70      }      }
71      fclose(fp);    fclose (fp);
72      return True;    return True;
73  }  }
74    
75  int checkRc(char *rc[][2])  int
76    checkRc (char *rc[][2])
77  {  {
78      int i, rval = True;    int i, rval = True;
79    
80  #ifdef DEBUG  #ifdef DEBUG
81      printf("entering checkRc\n");    printf ("entering checkRc\n");
82  #endif  #endif
83    
84      for(i = 0; rc[i][OPTION]; i++)    for (i = 0; rc[i][OPTION]; i++)
85      {      {
86          if(!rc[i][VALUE])        if (!rc[i][VALUE])
87          {          {
88              fprintf(stderr, "missing value for option %s\n", rc[i][OPTION]);            fprintf (stderr, "missing value for option %s\n", rc[i][OPTION]);
89              rval = False;            rval = False;
90          }          }
91      }      }
92      return rval;    return rval;
93  }  }
94    
95  char *getValue(char *option, char *rc[][2])  char *
96    getValue (char *option, char *rc[][2])
97  {  {
98      int i;    int i;
99    
100  #ifdef DEBUG  #ifdef DEBUG
101      printf("entering getValue\n");    printf ("entering getValue\n");
102  #endif  #endif
103    
104      for(i = 0; rc[i][OPTION]; i++)    for (i = 0; rc[i][OPTION]; i++)
105          if(!strcmp(option, rc[i][OPTION]))      if (!strcmp (option, rc[i][OPTION]))
106              break;        break;
107      return rc[i][VALUE];    return rc[i][VALUE];
108  }  }
109    
110  void freeRc(char *rc[][2])  void
111    freeRc (char *rc[][2])
112  {  {
113      int i;    int i;
114    
115  #ifdef DEBUG  #ifdef DEBUG
116      printf("entering freeRc\n");    printf ("entering freeRc\n");
117  #endif  #endif
118    
119      for(i = 0; rc[i][OPTION]; i++)    for (i = 0; rc[i][OPTION]; i++)
120          free(rc[i][VALUE]);      free (rc[i][VALUE]);
121  }  }

Legend:
Removed from v.1.1.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26