1 /* Test for configuration parser */
12 static char *heslo="prazdne";
13 static int nastaveni1=0,nastaveni2=1;
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_INT, &robert},
40 {"spalek", CT_INT, &spalek},
41 {"heslo", CT_STRING, &heslo},
42 {"nastaveni1", CT_FUNCTION, &set_nastaveni},
43 {"nastaveni2", CT_FUNCTION, &set_nastaveni},
51 static struct cfitem telo[]={
52 {"telo", CT_SECTION, NULL},
53 {"vek", CT_INT, &vek},
54 {"vyska", CT_INT, &vyska},
55 {"vaha", CT_INT, &vaha},
59 static byte shortopts[] = CF_SHORT_OPTS "abcp:q:r::";
60 static struct option longopts[] =
65 {"citron", 0, 0, 'c'},
67 {"qwerty", 1, 0, 'q'},
72 int main(int argc, char *argv[])
82 c=cf_getopt(argc,argv,shortopts,longopts,NULL);
89 printf("option %c\n",c);
94 printf("option %c with parameter %s\n",c,optarg);
98 printf("option r with optional parameter %s\n",optarg);
100 printf("option r without optional parameter\n");
103 //printf("invalid parameter %d: %s\n",optind,argv[optind]);
106 //printf("missing parameter for %d: %s\n",optind,argv[optind]);
109 printf("getopt is confused, it returns %c\n",c);
116 printf ("non-option ARGV-elements: ");
117 while (optind < argc)
118 printf ("%s ", argv[optind++]);
122 printf("robert=%d, spalek=%d, heslo=%s, nastaveni1/2=%d/%d\n",
123 robert,spalek,heslo,nastaveni1,nastaveni2);
124 printf("vek=%d, vyska=%d, vaha=%d\n",