/* tb.c - arg_parse test program */

static char rcsid[] = "$Header: /gourd/usr2/ph/sys/libsys/libarg/RCS/tb.c,v 4.2 94/08/03 20:09:48 ph Exp Locker: ph $";

#include <stdio.h>
#include <stdlib.h>

#include "arg.h"
static double dxs = 1., dys = .75;
static int x1 = 0, y1 = 0, x2 = 99, y2 = 99;
static char *chanlist = "rgba";

static void arg_people(int argc, char **argv) {
    int i;

    for (i=0; i<argc; i++)
	printf("person[%d]=%s\n", i, argv[i]);
}

static void arg_dsize(int argc, char **argv) {
    if (argc<1 || argc>3) {
	fprintf(stderr, "-dsize wants 1 or 2 args\n");
	exit(1);
    }
    /* illustrate two methods for argument conversion */
    dxs = atof(argv[0]);			/* constant conversion */
    if (argc>1) dys = expr_eval(argv[1]);	/* expression conversion */
    else dys = .75*dxs;
}

Arg_form *fb_init() {
    return arg_to_form(0,
	"-w%d%d%d%d", &x1, &y1, &x2, &y2, "set screen window",
	"-ch%S", &chanlist, "set channels [default=%s]", chanlist,
    0);
}

void main(int argc, char **argv) {
    int fast, xs = 512, ys = 486;
    double scale = 1.;
    char *fromfile, tofile[80], *child = "jim";
    Arg_form *arg_fb;

    arg_fb = fb_init();
    if (arg_parse(argc, argv,
	"", "Usage: %s [options]", argv[0],
	"", "This program does nothing but test arg_parse",
	"%S %s", &fromfile, tofile, "fromfile and tofile",
	"[%F]", &scale, "set scale [default=%g]", scale,
	"", ARG_SUBR(arg_people), "names of people",
	"-fast", ARG_FLAG(&fast), "do it faster",
	"-ch %S", &child, "set child name",
	"-srcsize %d[%d]", &xs, &ys, "set source size [default=%d,%d]", xs, ys,
	"-dstsize", ARG_SUBR(arg_dsize), "set dest size",
	"-fb", ARG_SUBLIST(arg_fb), "FB COMMANDS",
    0) < 0)
	exit(1);

    printf("from=%s to=%s scale=%g fast=%d child=%s src=%dx%d dst=%gx%g\n",
	fromfile, tofile, scale, fast, child, xs, ys, dxs, dys);
    printf("window={%d,%d,%d,%d} chan=%s\n", x1, y1, x2, y2, chanlist);
}

