#include <stdio.h>

#include "arg.h"
#include "common.h"
#include "crd_ut10xx.h"

int
main(int argc, const char **argv)
{
	const char *help = 
		"\n\tinit [-help] [-devnum=num]\n\n"
		"\t-help\n"
		"\t\tPrint this information.\n\n"
		"\t-devnum\n"
		"\t\tSpecifies number of device which should be initialised.\n"
		"\t\tNumbers of devices can be foun calling info program.\n"
		"\t\tDefault value of this number is equal 0 and correspond to\n"
		"\t\tthe first device attached to host.\n\n";
	
	CRD_UT10XX_t *ut;
	
	int devnum = 0;
	int status;
	
	if ( prologue(argv, help) )
		return (-1);
	
	if ( arg_getall(argv, "i", "-devnum", &devnum) < 0 )
		return (-2);
	
	if ( (ut = CRD_UT10XX_find_by_index(devnum)) == 0 )
	{
		epilogue(stderr, "there is no device of this number, use 'info'"
			" to check\n", 0, 0);
		return (-3);
	}
	
	CRD_UT10XX_session_open(ut);
	status = CRD_UT10XX_cmd_dev_init(ut);
	CRD_UT10XX_session_close(ut);
	
	return (epilogue(stderr, 0, status, ut));
}
