/* * Example of mrd_find_cartridge(3mrd). The command usage is: * * mrd_find robot_name volume_tag */ #ifndef lint static char SccsId[] = "@(#)mrd_find.c 1.2 3/5/97" ; #endif #include <stdio.h> #include <stdlib.h> #include <string.h> #include <mrd_common.h> #include <mrd_message.h> main(int argc, char *argv[]) { element_info_t element ; /* Element data result */ int status ; /* status from mrd_find_cartridge(3mrd) */ char *robot ; /* Medium changer to search */ char *volume_tag ; /* Volume tag for which to search */ int type ; /* Element type result */ char *content ; /* element content */ char *format ; /* format to print element data */ char address[MRD_NAME_SIZE+1] ; /* Element name result */ char log_info[MRD_MAX_LOG_STRING+1] ; /* error text */ char exception[BUFSIZ+1] ; /* exception buffer */ /* * There are two required arguments; robot name and volume tag. */ if( argc < 3 ) { printf("usage: %s robot volume-tag\n", argv[0]) ; exit(1) ; } robot = argv[1] ; volume_tag = argv[2] ; /* * Search all of the elements at the same time. With the * type set to zero, the values of element_address ("") * and element_count (0), don't matter. */ status = mrd_find_cartridge(robot, volume_tag, 0, "", 0, &element, address, &type, log_info) ; if( status != MRD_STATUS_SUCCESS ) printf("Can't find volume %s: %s: %s.\n", mrd_strstatus(status), log_info[0] ? log_info : "none") ; /* * Need to print out the results of the find. This is * similar to that used by mrd_show, but is a bit more * extensive to show more features. */ format = "%s\t%s\t%s\n" ; /* default format */ if( element.name[0] ) content = element.name ; else if( element.state & ELEMENT_FULL ) content = "Full" ; else if( element.state & ELEMENT_EXCEPT ) { format = "%s\t%s\t%s\t%s\n" ; content = "Exception" ; (void)mrd_strexcept(element.data.asc, element.data.ascq, exception, BUFSIZ) ; } else content = "Empty" ; if( element.state & ELEMENT_EXCEPT ) printf(format, mrd_strelement(type), address, content, exception) ; else printf(format, mrd_strelement(type), address, content) ; return 0 ; }