Exemple #1
0
int parse_sem_id(char *entry)
{
	char 	*parm;
	int 	iter, indx1 = 0, indx2;

	while(entry[indx1] == ' ')
		indx1++;
	while(entry[indx1] && entry[indx1] != ' ')
		indx1++;
	while(entry[indx1] == ' ')
		indx1++;
	if ('\0' == entry[indx1])
	{
		assert(FALSE);
		return -1;
	}
	indx2 = indx1;
	parm = &entry[indx1];
	while(entry[indx2] && entry[indx2] != ' ')
		indx2++;
	entry[indx2] = '\0';
	if (cli_is_dcm(parm))
		return (int)STRTOUL(parm, NULL, 10);
	else if (cli_is_hex(parm + 2))
		return (int)STRTOUL(parm, NULL, 16);
	else
	{
		assert(FALSE);
		return -1;
	}
}
Exemple #2
0
/* -----------------------------------------------------
 * Check if the value is numeric if it is supposed to be
 *
 * Return:
 *	TRUE	- It is numeric or val_type is not
 *	          numeric anyway
 *	FALSE	- Is not numeric
 * -----------------------------------------------------
 */
boolean_t cli_numeric_check(CLI_ENTRY *pparm, char *val_str)
{
	boolean_t retval = TRUE;

	if (VAL_NUM == pparm->val_type)
	{
		if (pparm->hex_num)
		{
			if (!cli_is_hex(val_str))
			{
				SNPRINTF(cli_err_str, MAX_CLI_ERR_STR,
				  "Unrecognized value: %s, HEX number expected",
				  val_str);
				retval = FALSE;
			}
		} else if (!cli_is_dcm(val_str))
		{
			SNPRINTF(cli_err_str, MAX_CLI_ERR_STR,
			  "Unrecognized value: %s, Decimal number expected",
			  val_str);
			retval = FALSE;
		}
	}
	return (retval);
}
Exemple #3
0
/*
 * --------------------------------------------------
 * Convert string to number.
 *
 * Return:
 *	TRUE	- OK
 *	FALSE	- Could not convert to number
 * --------------------------------------------------
 */
boolean_t cli_str_to_num(char *str, int4 *dst)
{
	long	result;
	int	save_errno, base;

	save_errno = errno;
	errno = 0;
	if (cli_is_dcm(str))
		base = 10;
	else
		base = 16;
        result = STRTOL(str, NULL, base);
	if (
#if INT_MAX < LONG_MAX
		(INT_MIN > result || INT_MAX < result) ||	/* outside INT range */
#endif
	    (ERANGE == errno && (LONG_MIN == result || LONG_MAX == result)) || (0 == result && 0 != errno))
	{	/* out of range or other error */
		*dst = 0;
		errno = save_errno;
		return FALSE;
	} else
	{
		*dst = (int4)result;
		errno = save_errno;
		return TRUE;
	}
}
Exemple #4
0
/*
 * --------------------------------------------------
 * Find the qualifier and convert it to 64 bit decimal number.
 *
 * Return:
 *	TRUE	- OK
 *	FALSE	- Could not convert to number
 * --------------------------------------------------
 */
boolean_t cli_get_int64(char *entry, gtm_int64_t *dst)
{
    char		buf[MAX_LINE];
    char		local_str[MAX_LINE];

    assert(strlen(entry) > 0);
    strncpy(local_str, entry, SIZEOF(local_str) - 1);

    if (cli_present(local_str) == CLI_PRESENT
            && cli_get_value(local_str, buf))
    {
        if (!cli_is_dcm(buf) || !cli_str_to_int64(buf, dst))
        {
            FPRINTF(stderr, "Error: cannot convert %s value to decimal number.\n", buf);
            return FALSE;
        }
        return TRUE;
    }
    return FALSE;
}
Exemple #5
0
/*
 * --------------------------------------------------
 * Convert string to 64 bit number.
 *
 * Return:
 *	TRUE	- OK
 *	FALSE	- Could not convert to number
 * --------------------------------------------------
 */
boolean_t cli_str_to_num64(char *str, gtm_int64_t *dst)
{
	gtm_int64_t	result;
	int	save_errno, base;

	save_errno = errno;
	errno = 0;
	if (cli_is_dcm(str))
		base = 10;
	else
		base = 16;
        result = STRTO64L(str, NULL, base);
	if ((ERANGE == errno && (GTM_INT64_MIN == result || GTM_INT64_MAX == result)) || (0 == result && 0 != errno))
	{	/* out of range or other error */
		*dst = 0;
		errno = save_errno;
		return FALSE;
	} else
	{
		*dst = result;
		errno = save_errno;
		return TRUE;
	}
}