7 #include "configFile.h"
11 if (s
[0] == 'Y' || s
[0] == 'y') {
18 char *getYesOrNo(int n
)
20 return (n
!= 0 ? "YES" : "NO");
23 int getValue(char *line
, char *env
, char *val
, int len
)
26 char *offset_val_begin
;
28 char clone_env
[STR_SIZE
];
31 strcpy(clone_env
, env
);
33 offset_env
= strstr(line
, clone_env
);
35 if (offset_env
== NULL
) {
39 offset_val_begin
= strchr(offset_env
, '"');
41 if (offset_val_begin
== NULL
) {
45 offset_val_end
= strchr(offset_val_begin
+ 1, '"');
47 if (offset_val_end
== NULL
) {
51 val_len
= (int) (offset_val_end
- (offset_val_begin
+ 1));
53 if (val_len
> len
- 1) {
58 memcpy(val
, offset_val_begin
+ 1, val_len
);
63 char *setValue(char *line
, char *env
, char *val
)
66 char *offset_val_begin
;
68 char clone_env
[STR_SIZE
];
71 /*strcpy(clone_env, " ");*/
72 strcpy(clone_env
, env
);
74 offset_env
= strstr(line
, clone_env
);
76 if (offset_env
== NULL
) {
80 offset_val_begin
= strchr(offset_env
, '"');
82 if (offset_val_begin
== NULL
) {
86 offset_val_end
= strchr(offset_val_begin
+ 1, '"');
88 if (offset_val_end
== NULL
) {
92 memset(clone
, 0, STR_SIZE
);
93 strncpy(clone
, line
, (int) ((offset_val_begin
- line
) + 1));
95 strcat(clone
, offset_val_end
);
100 int getValueInConfigFile(textFile_t
* textFile
, char *env
, char *val
, int len
)
105 for (i
= 0; i
< textFile
->text
->count
; i
++) {
106 line
= (char *) (textFile
->text
->list
[i
]);
108 if (strncmp(line
, env
, strlen(env
)) == 0) {
109 return getValue(line
, env
, val
, len
);
116 int setValueInConfigFile(textFile_t
* textFile
, char *env
, char *val
)
122 for (i
= 0; i
< textFile
->text
->count
; i
++) {
123 line
= (char *) (textFile
->text
->list
[i
]);
125 if (strncmp(line
, env
, strlen(env
)) == 0) {
126 ret
= setValue(line
, env
, val
);
129 list_del_item(textFile
->text
, i
, free
);
130 list_ins(textFile
->text
, i
, ret
);
140 void loadValueFromConfigFile(textFile_t
* textFile
, char *env
, char *val
, int len
, char *butVal
)
144 if (getValueInConfigFile(textFile
, env
, val
, len
) != 0) {
147 sprintf(line
, "%s=\"%s\"", env
, butVal
);
148 list_add(textFile
->text
, strdup(line
));
150 debug("Expanding config file [%s]", line
);