1 /*
2 * lookat_configfile.c
3 *
4 * Copyright (C) 2003 Staf Wagemakers Belgie/Belgium
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22 #include "xmalloc.h"
23 #include "configfile.h"
24 #include <stdio.h>
25 #include <errno.h>
26
lookat_get_config(FILE * fp,char * var_name)27 char * lookat_get_config(FILE *fp, char *var_name) {
28 char **cc=NULL;
29 char *cp=NULL;
30 char *ret=NULL;
31
32 cc=get_config_array(fp,var_name);
33 if(cc==NULL) return(NULL);
34 if(!strcmp(cc[0],"=")) {
35 if(cc[1]!=NULL) cp=cc[1];
36 }
37 else {
38 cp=cc[0];
39 }
40
41 if(cp!=NULL) {
42 ret = xmalloc(strlen(cp)+1);
43 ret = strcpy(ret,cp);
44 }
45
46 free_string_array(cc);
47 return(ret);
48 }
49
lookat_get_next_config(FILE * fp)50 char ** lookat_get_next_config (FILE *fp) {
51 char **cc=NULL;
52 char *var_name=NULL,*var_value=NULL;
53 char *cp=NULL;
54 char **ret=NULL;
55
56 cc=get_next_config_array(fp);
57 if(cc==NULL) return(NULL);
58
59 if(cc[0]!=NULL) {
60 var_name=xmalloc(strlen(cc[0])+1);
61 strcpy(var_name,cc[0]);
62 }
63
64 if(cc[1]!=NULL) {
65 if(!strcmp(cc[1],"=")) cp=cc[2];
66 else cp=cc[1];
67
68 if(cp!=NULL) {
69 var_value=xmalloc(strlen(cp)+1);
70 strcpy(var_value,cp);
71 }
72 }
73
74 if((var_name!=NULL)&&(var_value!=NULL)) {
75 ret=xcalloc(3,sizeof(char *));
76 ret[0]=var_name;
77 ret[1]=var_value;
78 }
79
80 free_string_array(cc);
81
82 return(ret);
83 }
84
85