コード例 #1
0
ファイル: platform_config.c プロジェクト: huiweics/IES
/* GetStrMap
 * \ingroup intPlatform
 *
 * \desc            Get string equivalent of the specified value given
 *                  the string mapping.
 *
 * \param[in]       value is the value on which to operate.
 *
 * \param[in]       strMap points to an array of fm_platformStrMap, where the
 *                  mapping of a string representation of a specific value.
 *
 * \param[in]       size is the size of the strMap array.
 *
 * \param[in]       hexVal is whether to display value in hex format.
 *
 * \param[out]      strBuf is the pointer to the buffer where the out is stored.
 *
 * \param[in]       strLen is the length of the strBuf.
 *
 * \return          string representation of the value or UNKNOWN.
 *
 *****************************************************************************/
static fm_text GetStrMap(fm_int             value,
                         fm_platformStrMap *strMap,
                         fm_int             size,
                         fm_bool            hexVal,
                         fm_text            strBuf,
                         fm_int             strLen)
{
    fm_int         cnt;

    for (cnt = 0 ; cnt < size ; cnt++)
    {
        if (value == strMap[cnt].value)
        {
            if (strBuf == NULL)
            {
                return strMap[cnt].desc;
            }
            FM_SPRINTF_S(strBuf,
                     strLen,
                     hexVal?"%s(0x%x)":"%s(%d)",
                     strMap[cnt].desc,
                     value);
            return strBuf;
        }
    }

    if (strBuf == NULL)
    {
        return "UNKNOWN";
    }

    FM_SNPRINTF_S(strBuf, strLen, "UNKNOWN(%d)", value);

    return strBuf;

}   /* end GetStrMap */
コード例 #2
0
ファイル: fm_api_glob.c プロジェクト: andriymoroz/IES
/** fmLoadPortRemapTable
 * \ingroup intSwitch
 *
 * \desc            Load a new port mapping table from a given file.
 *
 * \param[in]       filename is the file name.
 *
 * \param[in]       portTable is ptr to table where to store port read from file
 *
 * \param[in]       origTable is ptr to the original port mapping table
 *
 * \param[in]       maxport is number of entries in portTable
 *
 * \return          FM_OK or FM_FAIL if unable to read table from file
 *
 *****************************************************************************/
fm_status fmLoadPortRemapTable(fm_char *filename,
                               fm_int *portTable,
                               fm_int *origTable,
                               fm_int maxport)
{
    FILE       *fp;
    fm_char    *pch;
    fm_char     line[200];
    fm_int      i;
    fm_int      j;
    fm_int      portNum;
    fm_char *   context;
    fm_uint     s1max;
    fm_uint     lineLeft;

    if ((fp = fopen(filename,"r")) == NULL)
    {
        FM_LOG_PRINT("cannot open file %s \n", filename);
        return(FM_FAIL);
    }

    /* Display the original port mapping table. */
    FM_CLEAR(line);
    lineLeft = sizeof(line);
    FM_SPRINTF_S(line, lineLeft, "\noriginalTable[%d,", origTable[0]);
    i = strlen(line);
    lineLeft -= i;
    pch = &line[i];

    for (i = 1 ; i < maxport ; i++)
    {
        FM_SPRINTF_S(pch, lineLeft, "%d,",origTable[i]);
        j = strlen(pch);
        lineLeft -= j;
        pch += j;
    }

    /* Reposition back to the trailing comma, then overwrite it */
    --pch;
    *pch = ']';
    FM_LOG_PRINT("%s\n", line);

    while ( fgets(line,200,fp) != NULL )
    {
        if (strstr(line,"mappingTable") != NULL)
        {
            FM_LOG_PRINT("%s\n", line);
            if ((pch = strchr(line,'[')) != NULL)
            {
                i       = 0;
                context = NULL;
                s1max   = RSIZE_MAX - 1;
                pch     = FM_STRTOK_S(++pch, &s1max, " ,", &context);

                while (pch != NULL && i < maxport)
                {
                    portNum = atoi(pch);
                    if (portNum >= 0 && portNum < maxport)
                    {
                        portTable[i++] = portNum;
                        pch = FM_STRTOK_S(NULL, &s1max, " ,]", &context);
                    }
                    else
                    {
                        FM_LOG_PRINT("*** Invalid port number %d ***\n",portNum);
                        fclose(fp);
                        return(FM_FAIL);
                    }
                }
            }
        }
    }

    fclose(fp);

    return FM_OK;

}   /* end fmLoadPortRemapTable */