/* tcmdopts.c, c\lib\test
* Test cmd_options routine
*/
#include <stdio.h>
#include "cmd_opts.h"
main(argc, argv)
int argc;
char *argv[];
{
int cmd_errs, i;
static char **barg, **darg;
static struct options sw[] =
{'a',0,NULL,
'b',0,&barg,
'c',1,NULL, /* generally useless */
'd',1,&darg,
0, 0,NULL};
cmd_errs= cmd_options( & argc, argv, sw);
if (sw[0].arg_flg > 0)
printf("%d -a\n",sw[0].arg_flg);
for (i= 0; i < sw[1].arg_flg; i++)
printf("-b %s\n", barg[i]);
if (sw[2].arg_flg > 0)
printf("%d -c\n",sw[2].arg_flg);
for (i= 0; i < sw[3].arg_flg; i++)
printf("-d %s\n", darg[i]);
puts("Unclaimed:");
for (i= 1; i < argc; i++) /* argv[0] is still
the command */
printf(" %s",argv[i]);
puts("\n");
if (cmd_errs != 0)
{
printf("\7\ntcmdopts [-a] [-b<value>] -c -d<value> ...\n");
printf("\n%d Command line options invalid\n", -cmd_errs);
exit(1);
}
}