1 /* Test for configuration parser */
11 static char *heslo="prazdne";
12 static int nastaveni1=0,nastaveni2=1;
14 static byte *set_nastaveni(struct cfitem *item, byte *value)
17 if(!strcasecmp(value,"one"))
19 else if(!strcasecmp(value,"two"))
21 else if(!strcasecmp(value,"three"))
23 else if(!strcasecmp(value,"four"))
26 return "Invalid value of nastaveni";
27 if(!strcasecmp(item->name,"nastaveni1"))
29 else if(!strcasecmp(item->name,"nastaveni2"))
32 return "Internal error of nastaveni";
36 static struct cfitem jmeno[]={
37 {"jmeno", CT_SECTION, NULL},
38 {"robert", CT_INT, &robert},
39 {"spalek", CT_INT, &spalek},
40 {"heslo", CT_STRING, &heslo},
41 {"nastaveni1", CT_FUNCTION, &set_nastaveni},
42 {"nastaveni2", CT_FUNCTION, &set_nastaveni},
50 static struct cfitem telo[]={
51 {"telo", CT_SECTION, NULL},
52 {"vek", CT_INT, &vek},
53 {"vyska", CT_INT, &vyska},
54 {"vaha", CT_INT, &vaha},
58 static byte shortopts[] = CF_SHORT_OPTS "abcp:q:r::";
59 static struct option longopts[] =
64 {"citron", 0, 0, 'c'},
66 {"qwerty", 1, 0, 'q'},
71 int main(int argc, char *argv[])
81 c=cf_getopt(argc,argv,shortopts,longopts,NULL);
88 printf("option %c\n",c);
93 printf("option %c with parameter %s\n",c,optarg);
97 printf("option r with optional parameter %s\n",optarg);
99 printf("option r without optional parameter\n");
102 //printf("invalid parameter %d: %s\n",optind,argv[optind]);
105 //printf("missing parameter for %d: %s\n",optind,argv[optind]);
108 printf("getopt is confused, it returns %c\n",c);
115 printf ("non-option ARGV-elements: ");
116 while (optind < argc)
117 printf ("%s ", argv[optind++]);
121 printf("robert=%d, spalek=%d, heslo=%s, nastaveni1/2=%d/%d\n",
122 robert,spalek,heslo,nastaveni1,nastaveni2);
123 printf("vek=%d, vyska=%d, vaha=%d\n",