char name[256];
scan_option(argc, argv, "-n \"%s\"", name); /* since version 3
*/
char c;
scan_option(argc, argv, "-c %c", &c);
int flag;
scan_option(argc, argv, "-on[-]", &flag); /* since version
2 */
int mode;
scan_option(argc, argv, "[-+]mode", &mode); /* since version
3.01 */
int sw;
scan_option(argc, argv, "[+-]sw", &sw); /* since version 3.01
*/
int color;
scan_option(argc, argv, "-color Red Green Blue", &color);
/* since version 2 */
unsigned long plot;
scan_option(argc, argv, "-plot None|Line|Dot|Point", &plot);
/* since version 3.02 */
int width, height;
scan_option(argc, argv, "-geometry %dx%d", &width, &height);
float f;
scan_option(argc, argv, "-f %f", &f);
double d;
scan_option(argc, argv, "-d %lf", &d);
float *v = NULL; long nl = 1, nh; /* since
version 3.02 */
scan_option(argc, argv, "-v %f,..", &v, &nl,&nh);
double **m = NULL; long nrl = 1, nrh, ncl = 1, nch; /*
since version 3.02 */
scan_option(argc, argv, "-m (%lf,..),..", &m, &nrl,&nrh,
&ncl,&nch);
if (scan_option(argc, argv, "-help")) {
;
}
The scan_option is based on scanf routine. You
can design command-line options with key strings according to scanf
format. Also, a return value of scan_option is the index of the
position of the argument matched to key in command-line arguments, so you
can write more detailed code to scan subsequent arguments to matched position.
option_record options[] = { /* entry which has no or one variable
*/
{ "-t %s", title },
{ "-n \"%s\"", name }, /* since version 3 */
{ "-c %c", &c },
{ "-on[-]", &flag }, /* since version 2 */
{ "[-+]mode", &mode }, /* since version 3.01 */
{ "[+-]sw", &sw }, /* since version 3.01 */
{ "-color Red Green Blue", &color }, /* since version
2 */
{ "-plot None|Line|Dot|Point", &plot }, /*
since version 3.02 */
{ "-f %f", &f },
{ "-d %lf", &d },
{ "-help", NULL },
};
set_options(11, options);
set_option("-geom %dx%d", &width, &height);
alias_option("-geom", "-geometry"); /* since version 2 */
set_option("-v %f,..", &v, &nl,&nh); /*
since version 3.02 */
set_option("-m (%lf,..),..", &m, &nrl,&nrh, &ncl,&nch);
/*
since version 3.02 */
scan_options(argc, argv); /* scan options and set variables */
if (is_option("-help")){ /* get result on "-help" */
;
}