FreeBSD/bin/chio/chio.c
/*
 * do_return()
 * 
 * Given an element reference, ask the changer/picker to move that
 * element back to its source slot.
 */


Given an element reference, ask the changer/picker to move that
element back to its source slot.
Given an element reference ask the changer / picker to move that element back to its source slot .
static int
do_return(const char *cname, int argc, char **argv)
{
	struct changer_element_status *ces;
	struct changer_move cmd;
	uint16_t	type, element;
	++argv; --argc;
	if (argc < 2) {
		warnx("%s: too few arguments", cname);
		goto usage;
	} else if (argc > 3) {
		warnx("%s: too many arguments", cname);
		goto usage;
	}
	type = parse_element_type(*argv);
	++argv; --argc;
	if (CHET_VT == type) {
		find_element(*argv, &type, &element);
	} else {
		element = parse_element_unit(*argv);
	}
	++argv; --argc;
	ces = get_element_status((unsigned int)type, (unsigned int)element,
	    CHET_VT == type);
	if (NULL == ces)
		errx(1, "%s: null element status pointer", cname);
	if (!(ces->ces_flags & CES_SOURCE_VALID))
		errx(1, "%s: no source information", cname);
	(void) memset(&cmd, 0, sizeof(cmd));
	cmd.cm_fromtype = type;
	cmd.cm_fromunit = element;
	cmd.cm_totype = ces->ces_source_type;
	cmd.cm_tounit = ces->ces_source_addr;
	if (ioctl(changer_fd, CHIOMOVE, &cmd) == -1)
		err(1, "%s: CHIOMOVE", changer_name);
	free(ces);
	return(0);
usage:
	(void) fprintf(stderr, "usage: %s %s "
	    "<from ET> <from EU>\n", getprogname(), cname);
	return(1);
}
static int do_return ( const char * cname , int argc , char * * argv ) { struct changer_element_status * ces ; struct changer_move cmd ; uint16_t type , element ; ++ argv ; -- argc ; if ( argc < 2 ) { warnx ( " " , cname ) ; goto usage ; } else if ( argc > 3 ) { warnx ( " " , cname ) ; goto usage ; } type = parse_element_type ( * argv ) ; ++ argv ; -- argc ; if ( CHET_VT == type ) { find_element ( * argv , & type , & element ) ; } else { element = parse_element_unit ( * argv ) ; } ++ argv ; -- argc ; ces = get_element_status ( ( unsigned int ) type , ( unsigned int ) element , CHET_VT == type ) ; if ( NULL == ces ) errx ( 1 , " " , cname ) ; if ( ! ( ces -> ces_flags & CES_SOURCE_VALID ) ) errx ( 1 , " " , cname ) ; ( void ) memset ( & cmd , 0 , sizeof ( cmd ) ) ; cmd . cm_fromtype = type ; cmd . cm_fromunit = element ; cmd . cm_totype = ces -> ces_source_type ; cmd . cm_tounit = ces -> ces_source_addr ; if ( ioctl ( changer_fd , CHIOMOVE , & cmd ) == -1 ) err ( 1 , " " , changer_name ) ; free ( ces ) ; return ( 0 ) ; usage : ( void ) fprintf ( stderr , " " " \n " , getprogname ( ) , cname ) ; return ( 1 ) ; }
do_return()
do_return ()
/* Handle voltag virtual Changer Element Type */ /* Get the status */