/*
* Example to do slot to slot moves. The command usage is:
*
* mrd_position robot_name type address [ transport ]
*
* Type can be one of:
*
* slot, port, drive or transport
*
* The optional transport argument can be a transport address
* number, the word "default" or an empty string.
*/
#ifndef lint
static char SccsId[] = "@(#)mrd_position.c 1.2 3/5/97" ;
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mrd_common.h>
#include <mrd_message.h>
/*
* Given a string, resembling one of the element types,
* return the SCSI type code for it.
*/
struct {
int code ;
char *string ;
} etypes[] = {
TRANSPORT, "transport",
SLOT, "slot",
DRIVE, "drive",
PORT, "port",
} ;
convert_type(char *etype)
{
register i ;
/*
* For each entry in the array.
*/
for(i = 0; i < sizeof(etypes)/sizeof(etypes[0]); i++)
/*
* Do a case insensitive comparison, allowing
* abbreviations. Return as soon as a match is
* found. Return -1 if one isn't found.
*/
#ifdef vms
if( strncmp(etypes[i].string, etype, strlen(etype)) == 0 )
#else
if( strncasecmp(etypes[i].string, etype, strlen(etype)) == 0 )
#endif
return etypes[i].code ;
return -1 ;
}
main(int argc, char *argv[])
{
int status ;
int side = 1 ;
char *robot ;
char *cart = NULL ;
char *element ;
char *transport ;
int type ;
char log_info[MRD_MAX_LOG_STRING+1] ;
if( argc < 4 ) {
printf("usage: %s robot type address [ transport ]\n",
argv[0]) ;
exit(1) ;
}
robot = argv[1] ;
type = convert_type(argv[2]) ;
element = argv[3] ;
if( argc > 4 ) {
transport = argv[4] ;
/*
* If "default" or a suitable abbreviation is used
* use NULL for the transport name, to indicate that
* the SCSI default transport should be used.
*/
#ifdef vms
if( strncmp("default", transport, strlen(transport)) == 0 )
#else
if( strncasecmp("default", transport, strlen(transport)) == 0 )
#endif
transport = NULL ;
}
else
transport = "0" ;
status = mrd_position(robot, transport, element, type,
side, log_info) ;
if( status != MRD_STATUS_SUCCESS )
printf("Position failed: %s: %s.\n", mrd_strstatus(status),
log_info[0] ? log_info : "none") ;
else if ( transport == NULL )
printf("Positioned default Transport to %s #%s\n",
mrd_strelement(type), element) ;
else
printf("Positioned Transport #%s to %s #%s\n",
mrd_strelement(type), element) ;
return 0 ;
}