FreeBSD/tools/tools/cxgbetool/cxgbetool.c
/*
 * Parse an argument sub-vector as a { <parameter name> <value>[:<mask>] }
 * ordered tuple.  If the parameter name in the argument sub-vector does not
 * match the passed in parameter name, then a zero is returned for the
 * function and no parsing is performed.  If there is a match, then the value
 * and optional mask are parsed and returned in the provided return value
 * pointers.  If no optional mask is specified, then a default mask of all 1s
 * will be returned.
 *
 * An error in parsing the value[:mask] will result in an error message and
 * program termination.
 */
Parse an argument sub-vector as a {  [:] }
ordered tuple.  If the parameter name in the argument sub-vector does not
match the passed in parameter name, then a zero is returned for the
function and no parsing is performed.  If there is a match, then the value
and optional mask are parsed and returned in the provided return value
pointers.  If no optional mask is specified, then a default mask of all 1s
will be returned.

An error in parsing the value[:mask] will result in an error message and
program termination.
Parse an argument sub - vector as a { [ : ] } ordered tuple . If the parameter name in the argument sub - vector does not match the passed in parameter name then a zero is returned for the function and no parsing is performed . If there is a match then the value and optional mask are parsed and returned in the provided return value pointers . If no optional mask is specified then a default mask of all 1s will be returned . An error in parsing the value [ : mask ] will result in an error message and program termination .
static int
parse_val_mask(const char *param, const char *args[], uint32_t *val,
    uint32_t *mask)
{
	char *p;
	if (strcmp(param, args[0]) != 0)
		return (EINVAL);
	*val = strtoul(args[1], &p, 0);
	if (p > args[1]) {
		if (p[0] == 0) {
			*mask = ~0;
			return (0);
		}
		if (p[0] == ':' && p[1] != 0) {
			*mask = strtoul(p+1, &p, 0);
			if (p[0] == 0)
				return (0);
		}
	}
	warnx("parameter \"%s\" has bad \"value[:mask]\" %s",
	    args[0], args[1]);
	return (EINVAL);
}
static int parse_val_mask ( const char * param , const char * args [ ] , uint32_t * val , uint32_t * mask ) { char * p ; if ( strcmp ( param , args [ 0 ] ) != 0 ) return ( EINVAL ) ; * val = strtoul ( args [ 1 ] , & p , 0 ) ; if ( p > args [ 1 ] ) { if ( p [ 0 ] == 0 ) { * mask = ~ 0 ; return ( 0 ) ; } if ( p [ 0 ] == ' ' && p [ 1 ] != 0 ) { * mask = strtoul ( p + 1 , & p , 0 ) ; if ( p [ 0 ] == 0 ) return ( 0 ) ; } } warnx ( " \" \" \" \" " , args [ 0 ] , args [ 1 ] ) ; return ( EINVAL ) ; }
Parse an argument sub-vector as a { <parameter name> <value>[:<mask>] }
 ordered tuple.
Parse an argument sub - vector as a { <parameter name > <value > [ : <mask > ] } ordered tuple .