| 177 | ****************************************************************************/ |
| 178 | |
| 179 | void parse_file(FILE *stream, struct variable_s **list) |
| 180 | { |
| 181 | struct variable_s *curr; |
| 182 | struct variable_s *prev; |
| 183 | struct variable_s *next; |
| 184 | char *varname; |
| 185 | char *varval; |
| 186 | char *ptr; |
| 187 | |
| 188 | /* Loop until the entire file has been parsed. */ |
| 189 | |
| 190 | do |
| 191 | { |
| 192 | /* Read the next line from the file */ |
| 193 | |
| 194 | ptr = read_line(stream); |
| 195 | if (ptr) |
| 196 | { |
| 197 | /* Parse the line into a variable and a value field */ |
| 198 | |
| 199 | parse_line(ptr, &varname, &varval); |
| 200 | |
| 201 | /* If the variable has no value (or the special value 'n'), then |
| 202 | * ignore it. |
| 203 | */ |
| 204 | |
| 205 | if (!varval || strcmp(varval, "n") == 0) |
| 206 | { |
| 207 | continue; |
| 208 | } |
| 209 | |
| 210 | /* Make sure that a variable name was found. */ |
| 211 | |
| 212 | if (varname) |
| 213 | { |
| 214 | int varlen = strlen(varname) + 1; |
| 215 | int vallen = 0; |
| 216 | |
| 217 | /* Get the size of the value, including the NUL terminating |
| 218 | * character. |
| 219 | */ |
| 220 | |
| 221 | if (varval) |
| 222 | { |
| 223 | vallen = strlen(varval) + 1; |
| 224 | } |
| 225 | |
| 226 | /* Allocate memory to hold the struct variable_s with the |
| 227 | * variable name and the value. |
| 228 | */ |
| 229 | |
| 230 | curr = malloc(sizeof(struct variable_s) + |
| 231 | varlen + vallen - 1); |
| 232 | if (curr) |
| 233 | { |
| 234 | /* Add the variable to the list */ |
| 235 | |
| 236 | curr->var = &curr->storage[0]; |