mi/util.c
// check that the user has supplied us with valid arguments
check that the user has supplied us with valid arguments
check that the user has supplied us with valid arguments
bool checkargs(int argc, char ** argv, char * optstr, bool *needchandev) 
{
	int ch;
	int numargs = 1; 
	bool goodargs = false;
	*needchandev = false;
	while ((ch = getopt(argc, argv, optstr)) != -1) {
		numargs++;
		switch(ch) {	
			case 'S':
				*needchandev = true;
				numargs++;
				break;
			case 's':
				*needchandev = true;
				break;
			case 'I':
				*needchandev = true;
				numargs++;
				break;
			case 'i':
				*needchandev = true;
				break;
			case 'P':
				*needchandev = true;
				numargs++;
				break;
			case 'A':
				*needchandev = true;
				numargs++;
				break;
			case 'l':
				break;
			case 'h':
				printf("help:\n");
				usage();
		}
	}
	if(argc == 3)
		*needchandev = true;
	if(*needchandev)
		numargs += 2;
	if(argc == numargs) {
		long lval;
		if( (*needchandev) && ((!ata_strtolong(argv[argc-1], &lval)) &&
			(!ata_strtolong(argv[argc-2], &lval))) )
			goodargs = true;
		else if(!(*needchandev))
			goodargs = true;
	}
	return goodargs;
}
bool checkargs ( int argc , char * * argv , char * optstr , bool * needchandev ) { int ch ; int numargs = 1 ; bool goodargs = false ; * needchandev = false ; while ( ( ch = getopt ( argc , argv , optstr ) ) != -1 ) { numargs ++ ; switch ( ch ) { case ' ' : * needchandev = true ; numargs ++ ; break ; case ' ' : * needchandev = true ; break ; case ' ' : * needchandev = true ; numargs ++ ; break ; case ' ' : * needchandev = true ; break ; case ' ' : * needchandev = true ; numargs ++ ; break ; case ' ' : * needchandev = true ; numargs ++ ; break ; case ' ' : break ; case ' ' : printf ( " \n " ) ; usage ( ) ; } } if ( argc == 3 ) * needchandev = true ; if ( * needchandev ) numargs += 2 ; if ( argc == numargs ) { long lval ; if ( ( * needchandev ) && ( ( ! ata_strtolong ( argv [ argc - 1 ] , & lval ) ) && ( ! ata_strtolong ( argv [ argc - 2 ] , & lval ) ) ) ) goodargs = true ; else if ( ! ( * needchandev ) ) goodargs = true ; } return goodargs ; }
check that the user has supplied us with valid arguments
check that the user has supplied us with valid arguments
// 1 argument, the name of the program // since we're just listing devices // found in the system, we don't need // any additional arguments or anything, // so don't do anything here. // if we've only got 3 arguments, // then we'll want to show the info // about the specified device. // then valid args