#wwekljrw
[test2] #sfljkl'sdf
#dfghjkl
+true= enaBle
+false= no
t2="qweqwe#asd"
t2="qweqwe#as\"d" #HEH
t5="hsdf
S:'test' K:'asdfas' V:'
HAHA
'
+S:'test2' K:'true' V:'enaBle'
+S:'test2' K:'false' V:'no'
S:'test2' K:'t2' V:'qweqwe#asd'
S:'test2' K:'t2' V:'qweqwe#as"d'
S:'test2' K:'t5' V:'hsdf
\
sdf sdf sdf
'
+test2.true: 1
+test2.false: 0
int
main(int argn, char *argv[] ) {
InfMap *map, *ptr;
+ int boolval;
if ( argn!=2 ) {
puts("Usage:");
);
ptr++;
}
+
+ INFGetBoolean(map, "test2", "true", &boolval);
+ printf("test2.true: %d\n", boolval);
+ INFGetBoolean(map, "test2", "false", &boolval);
+ printf("test2.false: %d\n", boolval);
INFFree(map);
return 0;
}
return 1;
}
+static int
+parseBool(char *str)
+{
+ struct {
+ char *key;
+ int val;
+ }
+ bdata[] =
+ {
+ {"1", 1},
+ {"0", 0},
+ {"on", 1},
+ {"off", 0},
+ {"enable", 1},
+ {"disable", 0},
+ {"true", 1},
+ {"false", 0},
+ {"yes", 1},
+ {"no", 0}
+ };
+ int i;
+
+ while(*str && isspace(*str))
+ str++;
+
+ for(i=0;i<lengthof(bdata);i++)
+ if ( strcasecmp(bdata[i].key, str) == 0 )
+ return bdata[i].val;
+
+ tlog(TL_ALARM|TL_EXIT, "Unknown value '%s' for boolean variable", str);
+
+ return 0;
+}
+
+int
+INFGetBoolean(InfMap *inf, char *sect, char *key, int *val) {
+ inf = INFFindInfMap(inf, sect, key);
+ if (inf) {
+ *val=parseBool(inf->value);
+ return 0;
+ }
+ return 1;
+}
+
int INFGetFloat(InfMap *inf, char *sect, char *key, float *val);
int INFGetDouble(InfMap *inf, char *sect, char *key, double *val);
int INFGetString(InfMap *inf, char *sect, char *key, char **val);
-
+int INFGetBoolean(InfMap *inf, char *sect, char *key, int *val);
#endif
#define offsetof(type, field) ((int) &((type *)0)->field)
#endif /* offsetof */
+#ifndef lengthof
+#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
+#endif
+
#ifndef TYPEALIGN
#define TYPEALIGN(ALIGNVAL,LEN) \
(((long) (LEN) + ((ALIGNVAL) - 1)) & ~((long) ((ALIGNVAL) - 1)))