⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bootlib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
    *ppString = pString;    return (TRUE);    }/********************************************************************************* getNum - get a numeric value from a string*/LOCAL BOOL getNum    (    FAST char **ppString,    int *pNum    )    {    skipSpace (ppString);    if (sscanf (*ppString, "%d", pNum) != 1)	return (FALSE);    /* skip over number */    while (isdigit (**ppString))	(*ppString)++;    return (TRUE);    }/********************************************************************************* getAssign - get an assignment out of a string*/LOCAL BOOL getAssign    (    FAST char **ppString,    char *valName,    char *pVal,    int maxLen    )    {    skipSpace (ppString);    if (!getConst (ppString, valName))	return (FALSE);    skipSpace (ppString);    if (!getConst (ppString, "="))	return (FALSE);    return (getWord (ppString, pVal, maxLen, " \t"));    }/********************************************************************************* getAssignNum - get a numeric assignment out of a string*/LOCAL BOOL getAssignNum    (    FAST char **ppString,    char *valName,    int *pVal    )    {    char buf [BOOT_FIELD_LEN];    char *pBuf = buf;    char *pTempString;    int tempVal;    /* we don't modify *ppString or *pVal until we know we have a good scan */    /* first pick up next field into buf */    pTempString = *ppString;    if (!getAssign (&pTempString, valName, buf, sizeof (buf)))	return (FALSE);    /* now scan buf for a valid number */    if ((bootScanNum (&pBuf, &tempVal, FALSE) != OK) || (*pBuf != EOS))	return (FALSE);    /* update string pointer and return value */    *ppString = pTempString;    *pVal = tempVal;    return (TRUE);    }/********************************************************************************* printClear - print string with '?' for unprintable characters*/LOCAL void printClear    (    FAST char *param    )    {    FAST char ch;    while ((ch = *(param++)) != EOS)	printf ("%c", (isascii (ch) && isprint (ch)) ? ch : '?');    }/********************************************************************************* printParamNum - print number parameter*/LOCAL void printParamNum    (    char *paramName,    int  value,    BOOL hex    )    {    printf (hex ? "%-*s: 0x%x \n" : "%-*s: %d \n", PARAM_PRINT_WIDTH,	    paramName, value);    }/********************************************************************************* printParamString - print string parameter*/LOCAL void printParamString    (    char *paramName,    char *param    )    {    if (param [0] != EOS)	{	printf ("%-*s: ", PARAM_PRINT_WIDTH, paramName);	printClear (param);	printf ("\n");	}    }/********************************************************************************* promptParamBootDevice - prompt the user for the boot device** This routine reads the boot device name, and an optional unit number.* If the unit number is not supplied, it defaults to 0.** - carriage return leaves the parameter unmodified;* - "." clears the parameter (null boot device and 0 unit number).*/LOCAL int promptParamBootDevice    (    char *paramName,    FAST char *param,    int *pValue,    int sizeParamName    )    {    FAST int i;    int value;    char buf[BOOT_FIELD_LEN];    char *pBuf;    sprintf(buf, "%s%d", param, *pValue);    printf ("%-*s: ", PARAM_PRINT_WIDTH, strBootDevice);    printClear (buf);    if (*buf != EOS)	printf (" ");    if ((i = promptRead (buf, sizeParamName)) != 0)	return (i);    if (buf[0] == '.')	{	param[0] = EOS;               /* just '.'; make empty fields */        *pValue = 0;	return (1);	}    i = 0;    /* Extract first part of name of boot device. */    while (!isdigit(buf[i]) && buf[i] != '=' && buf[i] != EOS)       {        param[i] = buf[i];        i++;       }    param[i] = EOS;    /* Extract unit number, if specified. */    if (isdigit(buf[i]))     /* Digit before equal sign is unit number. */      {       pBuf = &buf[i];       if (bootScanNum (&pBuf, &value, FALSE) != OK)          {	  printf ("invalid unit number.\n");          return (-98);          }       strcat(param, pBuf);      }   else                          /* No unit number specified. */      {       value = 0;       if (buf[i] == '=')          strcat(param, &buf[i]);    /* Append remaining boot device name. */      }    *pValue = value;     return (1);    }/********************************************************************************* promptParamString - prompt the user for a string parameter** - carriage return leaves the parameter unmodified;* - "." clears the parameter (null string).*/LOCAL int promptParamString    (    char *paramName,    FAST char *param,    int sizeParamName    )    {    FAST int i;    char buf [BOOT_FIELD_LEN];    printf ("%-*s: ", PARAM_PRINT_WIDTH, paramName);    printClear (param);    if (*param != EOS)	printf (" ");    if ((i = promptRead (buf, sizeParamName)) != 0)	return (i);    if (buf[0] == '.')	{	param [0] = EOS;	/* just '.'; make empty field */	return (1);	}    strcpy (param, buf);	/* update parameter */    return (1);    }/********************************************************************************* promptParamNum - prompt the user for a parameter** - carriage return leaves the parameter unmodified;* - "." clears the parameter (0)*/LOCAL int promptParamNum    (    char *paramName,    int *pValue,    BOOL hex    )    {    char buf [BOOT_FIELD_LEN];    char *pBuf;    int value;    int i;    printf (hex ? "%-*s: 0x%x " : "%-*s: %d ", PARAM_PRINT_WIDTH, paramName,	    *pValue);    if ((i = promptRead (buf, sizeof (buf))) != 0)	return (i);    if (buf[0] == '.')	{	*pValue = 0;		/* just '.'; make empty field (0) */	return (1);	}    /* scan for number */    pBuf = buf;    if ((bootScanNum (&pBuf, &value, FALSE) != OK) || (*pBuf != EOS))	{	printf ("invalid number.\n");	return (-98);	}    *pValue = value;    return (1);    }/********************************************************************************* promptRead - read the result of a prompt and check for special cases** Special cases:*    '-'  = previous field*    '^D' = quit*    CR   = leave field unchanged*    too many characters = error** RETURNS:*    0 = OK*    1 = skip this field*   -1 = go to previous field*  -98 = ERROR*  -99 = quit*/LOCAL int promptRead    (    char *buf,    int bufLen    )    {    FAST int i;    i = fioRdString (STD_IN, buf, bufLen);    if (i == EOF)	return (-99);			/* EOF; quit */    if (i == 1)	return (1);			/* just CR; leave field unchanged */    if ((i == 2) && (buf[0] == '-'))	return (-1);			/* '-'; go back up */    if (i >= bufLen)	{	printf ("too big - maximum field width = %d.\n", bufLen);	/* We mustn't take into account the end of the string */ 	while((i = fioRdString(STD_IN, buf, bufLen)) >= bufLen);	return (-98);	}    return (0);    }/********************************************************************************* skipSpace - advance pointer past white space** Increments the string pointer passed as a parameter to the next* non-white-space character in the string.*/LOCAL void skipSpace    (    FAST char **strptr  /* pointer to pointer to string */    )    {    while (isspace (**strptr))	++*strptr;    }/******************************************************************************** bootScanNum - scan string for numeric value** This routine scans the specified string for a numeric value.  The string* pointer is updated to reflect where the scan stopped, and the value is* returned via pValue.  The value will be scanned by default in decimal unless* hex==TRUE.  In either case, preceding the value with "0x" or "$" forces* hex.  Spaces before and after number are skipped.** RETURNS: OK if value scanned successfully, otherwise ERROR.** EXAMPLES:*	bootScanNum (&string, &value, FALSE);*    with:*	string = "   0xf34  ";*	    returns OK, string points to EOS, value=0xf34*	string = "   0xf34r  ";*	    returns OK, string points to 'r', value=0xf34*	string = "   r0xf34  ";*	    returns ERROR, string points to 'r', value unchanged** NOMANUAL*/STATUS bootScanNum    (    FAST char **ppString,    int *pValue,    FAST BOOL hex    )    {    FAST char *pStr;    FAST char ch;    FAST int n;    FAST int value = 0;    skipSpace (ppString);    /* pick base */    if (**ppString == '$')	{	++*ppString;	hex = TRUE;	}    else if (strncmp (*ppString, "0x", 2) == 0)	{	*ppString += 2;	hex = TRUE;	}    /* scan string */    pStr = *ppString;    FOREVER	{	ch = *pStr;	if (!isascii (ch))	    break;	if (isdigit (ch))	    n = ch - '0';	else	    {	    if (!hex)		break;	    if (isupper (ch))		ch = tolower (ch);	    if ((ch < 'a') || (ch > 'f'))		break;	    n = ch - 'a' + 10;	    }	value = (value * (hex ? 16 : 10)) + n;	++pStr;	}    /* error if we didn't scan any characters */    if (pStr == *ppString)	return (ERROR);    /* update users string ptr to point to character that stopped the scan */    *ppString = pStr;    skipSpace (ppString);    *pValue = value;    return (OK);    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -