1 /* Test for configuration parser */
11 static char *heslo="prazdne";
12 static int nastaveni1=0,nastaveni2=1;
13 static double decker = 0; /* The famous London buses :-) */
15 static byte *set_nastaveni(struct cfitem *item, byte *value)
18 if(!strcasecmp(value,"one"))
20 else if(!strcasecmp(value,"two"))
22 else if(!strcasecmp(value,"three"))
24 else if(!strcasecmp(value,"four"))
27 return "Invalid value of nastaveni";
28 if(!strcasecmp(item->name,"nastaveni1"))
30 else if(!strcasecmp(item->name,"nastaveni2"))
33 return "Internal error of nastaveni";
37 static struct cfitem jmeno[]={
38 {"jmeno", CT_SECTION, NULL},
39 {"robert", CT_U64, &robert},
40 {"spalek", CT_INT, &spalek},
41 {"heslo", CT_STRING, &heslo},
42 {"nastaveni1", CT_FUNCTION, &set_nastaveni},
43 {"nastaveni2", CT_FUNCTION, &set_nastaveni},
44 {"decker", CT_DOUBLE, &decker},
52 static struct cfitem telo[]={
53 {"telo", CT_SECTION, NULL},
54 {"vek", CT_INT, &vek},
55 {"vyska", CT_INT, &vyska},
56 {"vaha", CT_INT, &vaha},
60 static byte shortopts[] = CF_SHORT_OPTS "abcp:q:r::";
61 static struct option longopts[] =
66 {"citron", 0, 0, 'c'},
68 {"qwerty", 1, 0, 'q'},
73 int main(int argc, char *argv[])
83 c=cf_getopt(argc,argv,shortopts,longopts,NULL);
90 printf("option %c\n",c);
95 printf("option %c with parameter %s\n",c,optarg);
99 printf("option r with optional parameter %s\n",optarg);
101 printf("option r without optional parameter\n");
104 //printf("invalid parameter %d: %s\n",optind,argv[optind]);
107 //printf("missing parameter for %d: %s\n",optind,argv[optind]);
110 printf("getopt is confused, it returns %c\n",c);
117 printf ("non-option ARGV-elements: ");
118 while (optind < argc)
119 printf ("%s ", argv[optind++]);
123 printf("robert=%Ld, spalek=%d, heslo=%s, nastaveni1/2=%d/%d decker=%f\n",
124 (long long)robert,spalek,heslo,nastaveni1,nastaveni2,decker);
125 printf("vek=%d, vyska=%d, vaha=%d\n",