X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Fconf-test.c;h=47eff30ba223e3a00d06ac5da83acf3eb06fb3d4;hb=6829bc0163f6ecfc8ae70ee7b3ce2b79e7484dfe;hp=002939b14f7e41070874f01c4ea6b2442f28b0eb;hpb=3409a7fb8332502c9765706d3bd6db036e5dddf0;p=libucw.git diff --git a/lib/conf-test.c b/lib/conf-test.c index 002939b1..47eff30b 100644 --- a/lib/conf-test.c +++ b/lib/conf-test.c @@ -1,16 +1,16 @@ /* Test for configuration parser */ -#include -#include -#include - #include "lib/lib.h" #include "lib/conf.h" -static int robert=14; +#include +#include + +static u64 robert=14; static int spalek=-3; static char *heslo="prazdne"; static int nastaveni1=0,nastaveni2=1; +static double decker = 0; /* The famous London buses :-) */ static byte *set_nastaveni(struct cfitem *item, byte *value) { @@ -35,12 +35,14 @@ static byte *set_nastaveni(struct cfitem *item, byte *value) } static struct cfitem jmeno[]={ - {"robert", ct_int, &robert}, - {"spalek", ct_int, &spalek}, - {"heslo", ct_string, &heslo}, - {"nastaveni1", ct_function, &set_nastaveni}, - {"nastaveni2", ct_function, &set_nastaveni}, - {NULL, 0, NULL} + {"jmeno", CT_SECTION, NULL}, + {"robert", CT_U64, &robert}, + {"spalek", CT_INT, &spalek}, + {"heslo", CT_STRING, &heslo}, + {"nastaveni1", CT_FUNCTION, &set_nastaveni}, + {"nastaveni2", CT_FUNCTION, &set_nastaveni}, + {"decker", CT_DOUBLE, &decker}, + {NULL, CT_STOP, NULL} }; static int vek=22; @@ -48,15 +50,17 @@ static int vyska=178; static int vaha=66; static struct cfitem telo[]={ - {"vek", ct_int, &vek}, - {"vyska", ct_int, &vyska}, - {"vaha", ct_int, &vaha}, - {NULL, 0, NULL} + {"telo", CT_SECTION, NULL}, + {"vek", CT_INT, &vek}, + {"vyska", CT_INT, &vyska}, + {"vaha", CT_INT, &vaha}, + {NULL, CT_STOP, NULL} }; -static byte shortopts[] = "abcp:q:r::"; +static byte shortopts[] = CF_SHORT_OPTS "abcp:q:r::"; static struct option longopts[] = { + CF_LONG_OPTS {"ahoj", 0, 0, 'a'}, {"bida", 0, 0, 'b'}, {"citron", 0, 0, 'c'}, @@ -70,12 +74,13 @@ int main(int argc, char *argv[]) { int c; - cf_register("jmeno",jmeno); - cf_register("telo",telo); - cf_register_opts(shortopts,longopts); + log_init(argv[0]); + + cf_register(jmeno); + cf_register(telo); while(1){ - c=cf_getopt(argc,argv,NULL); + c=cf_getopt(argc,argv,shortopts,longopts,NULL); if(c==-1) break; else switch(c){ @@ -115,8 +120,8 @@ int main(int argc, char *argv[]) printf ("\n"); } - printf("robert=%d, spalek=%d, heslo=%s, nastaveni1/2=%d/%d\n", - robert,spalek,heslo,nastaveni1,nastaveni2); + printf("robert=%Ld, spalek=%d, heslo=%s, nastaveni1/2=%d/%d decker=%f\n", + (long long)robert,spalek,heslo,nastaveni1,nastaveni2,decker); printf("vek=%d, vyska=%d, vaha=%d\n", vek,vyska,vaha);