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

📄 licensefile.cpp

📁 跨操作系统的微型中间件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
                LicenseConfigFile::ToLower  Called By:    LicenseConfigFile::LocateKeyRange                LicenseConfigFile::SetItemValue  Input:        pszKeyName      - 以NULL结尾的字符串指针,指示需要返回值的Key                pszSectionBegin - 指向需要搜索区域的开始地址                pszSectionEnd   - 指向需要搜索区域的最后一个字符的下一个地址  Output:                       pszKeyBegin     - 接收Key项的开始地址                pszKeyEnd       - 接收Key项的下一行的开始字节地址                          指向最后一个有效字符的下一个地址  Return:       定位成功,返回TRUE;失败,返回FALSE  Others:       本函数不是UNICODE版本*************************************************/unsigned long LicenseConfigFile::LocateKeyRange(const char *pszKeyName, 										  const char *pszSectionBegin, 										  const char *pszSectionEnd, 										  char * &pszKeyBegin, 										  char * &pszKeyEnd){    char *pszLowerKey;    /* 参数合法性检查 */    if ((NULL == pszKeyName) || (NULL == pszSectionBegin)        || (NULL == pszSectionEnd))    {        return FALSE;    }    if (pszSectionBegin >= pszSectionEnd)    {        return FALSE;    }    /* 冗余检查代码,不用测试 */    if ((NULL == m_pszContent) || (NULL == m_pszShadow))    {        return FALSE;    }    /* 将KeyName转换成小写 */    pszLowerKey = strdup(pszKeyName);    ToLower(pszLowerKey, strlen(pszLowerKey));    /* 在Shadow中定位,然后,计算出正确的指针 */    char    *pszKeyBeginOnShadow;    /* 得到Key在Shadow中的位置 */    pszKeyBeginOnShadow = LocateStr( pszLowerKey,                                      MapToShadow(pszSectionBegin),                                      MapToShadow(pszSectionEnd) );    if (NULL == pszKeyBeginOnShadow)    {        /* 释放资源 */        free(pszLowerKey);        return FALSE;    }    /* 释放资源 */    free(pszLowerKey);    pszKeyBegin = MapToContent(pszKeyBeginOnShadow);    pszKeyEnd = pszKeyBegin + strlen(pszKeyName);    /* 在指定范围内寻找关键字后面的'=' */    for (; pszKeyEnd < pszSectionEnd; pszKeyEnd++)    {        if ((*pszKeyEnd != ' ') && (*pszKeyEnd != '\t'))        {            break;        }    }    if (*pszKeyEnd != '=')    {        /* 找到的字符串不是关键字,采用递归方式查找指定范围中的下一个位置 */        char *pszSearchBegin;       /* 指示搜索区域的开始位置 */                                    /* 避免在LocateKeyRange中,对pszValueBegin修改                                    后,影响搜索区域的开始位置 */        pszSearchBegin = pszKeyEnd;        return LocateKeyRange( pszKeyName,                                pszSearchBegin,                                pszSectionEnd,                               pszKeyBegin,                               pszKeyEnd );    }    /* 过滤'='后面的字符 */    for (pszKeyEnd++; pszKeyEnd < pszSectionEnd; pszKeyEnd++)    {        if ((*pszKeyEnd == '\r') || (*pszKeyEnd == '\n'))        {            break;        }    }    /* 定位后面的取值范围 */    for (; pszKeyEnd < pszSectionEnd; pszKeyEnd++)    {        if ((*pszKeyEnd != '\r') && (*pszKeyEnd != '\n'))        {            break;        }    }    if (pszKeyEnd > pszKeyBegin)    {        return TRUE;    }    else    {        return FALSE;    }}/*************************************************  Function:     LocateKeyValue  Description:  在指定的缓冲区范围中搜索Key,返回与Key匹配的值的开始地址和结束地址。                注意:指定范围的结尾地址和返回的取值结束地址,都是指向最后一个有效                空间后面的地址。  Calls:        LicenseConfigFile::LocateKeyValue                LicenseConfigFile::LocateStr                LicenseConfigFile::MapToContent                LicenseConfigFile::MapToShadow                ::ToLower  Called By:    LicenseConfigFile::GetItemValue                LicenseConfigFile::LocateKeyValue                  Input:        pszKeyName      - 以NULL结尾的字符串指针,指示需要返回值的Key                pszSectionBegin - 指向需要搜索区域的开始地址                pszSectionEnd   - 指向需要搜索区域的最后一个字符的下一个地址  Output:       pszValueBegin   - 接收返回值的开始地址                pszValueEnd     - 接收返回值的结束地址                          指向最后一个有效字符的下一个地址  Return:       定位成功,返回TRUE;失败,返回FALSE  Others:       本函数不是UNICODE版本*************************************************/unsigned long LicenseConfigFile::LocateKeyValue( const char *pszKeyName,                                    const char *pszSectionBegin,                                    const char *pszSectionEnd,                                    char * &pszValueBegin,                                    char * &pszValueEnd ){    char *pszLowerKey;    /* 参数合法性检查 */    if ((NULL == pszKeyName) || (NULL == pszSectionBegin)        || (NULL == pszSectionEnd))    {        return FALSE;    }    if (pszSectionBegin >= pszSectionEnd)    {        return FALSE;    }    /* 冗余检查代码,不用测试 */    if ((NULL == m_pszContent) || (NULL == m_pszShadow))    {        return FALSE;    }    /* 将KeyName转换成小写 */    pszLowerKey = strdup(pszKeyName);    ToLower(pszLowerKey, strlen(pszLowerKey));    /* 在Shadow中定位,然后,计算出正确的指针 */    char    *pszKeyBeginOnShadow;    /* 得到Key在Shadow中的位置 */    pszKeyBeginOnShadow = LocateStr( pszLowerKey,                                      MapToShadow(pszSectionBegin),                                      MapToShadow(pszSectionEnd) );    if (NULL == pszKeyBeginOnShadow)    {        /* 释放资源 */        free(pszLowerKey);        return FALSE;    }    /* 释放资源 */    free(pszLowerKey);    pszValueBegin = MapToContent(pszKeyBeginOnShadow) + strlen(pszKeyName);    /* 在指定范围内寻找关键字后面的'=' */    for (; pszValueBegin < pszSectionEnd; pszValueBegin++)    {        if ((*pszValueBegin != ' ') && (*pszValueBegin != '\t'))        {            break;        }    }    if (*pszValueBegin != '=')    {        /* 找到的字符串不是关键字,采用递归方式查找指定范围中的下一个位置 */        char *pszSearchBegin;       /* 指示搜索区域的开始位置 */                                    /* 避免在LocateKeyValue中,对pszValueBegin修改                                    后,影响搜索区域的开始位置 */        pszSearchBegin = pszValueBegin;        return LocateKeyValue( pszKeyName,                                pszSearchBegin,                                pszSectionEnd,                               pszValueBegin,                               pszValueEnd );    }    /* 过滤'='后面的空格 */    for (pszValueBegin++; pszValueBegin < pszSectionEnd; pszValueBegin++)    {        if ((*pszValueBegin == '\r') || (*pszValueBegin == '\n')             || ((*pszValueBegin != '\t') && (*pszValueBegin != ' ')))        {            break;        }    }    pszValueEnd = pszValueBegin;        /* 过滤空格后,定位后面的取值范围 */    for (; pszValueEnd < pszSectionEnd; pszValueEnd++)    {        if ((*pszValueEnd == '\t')            /* || (*pszValueEnd == ' ') */ /* 注释本处代码,则返回值中允许带空格 */            || (*pszValueEnd == '\r') || (*pszValueEnd == '\n'))        {            break;        }    }    if (pszValueEnd > pszValueBegin)    {        return TRUE;    }    else    {        return FALSE;    }}/*************************************************  Function:     LocateStr  Description:  在缓冲区中指定的范围内搜索CharSet,返回CharSet在缓冲区中的开始地址。                本函数核列字母的大小写                注意:整个缓冲区应该是NULL结尾的字符串。  Calls:        strstr()  Called By:    LicenseConfigFile::LocateKeyValue                LicenseConfigFile::LocateKeyRange                LicenseConfigFile::LocateSection                  Input:        pszCharSet      - 以NULL结尾的字符串指针,指示需要搜索的字符串                pszBegin        - 指向需要搜索区域的开始地址                pszEnd          - 指向需要搜索区域的最后一个字符的下一个地址  Output:         Return:       搜索成功,返回一个有效的指针;失败,返回NULL  Others:       *************************************************/char *LicenseConfigFile::LocateStr( const char *pszCharSet,                               const char *pszBegin,                               const char *pszEnd ){    char *pFind;    /* 参数合法性检查 */    if ((NULL == pszCharSet) || (NULL == pszBegin)        || (NULL == pszEnd))    {        return NULL;    }    if (pszBegin >= pszEnd)    {        return NULL;    }    /* 搜索字符串在缓冲区中的位置 */    pFind = strstr(pszBegin, pszCharSet);    if ((NULL == pFind) || ((pFind + strlen(pszCharSet)) > pszEnd))    {        return NULL;    }    else    {        return pFind;    }}/*************************************************  Function:     MapToContent  Description:  从Shadow的地址映射到Content。  Calls:        assert();  Called By:    LicenseConfigFile::LocateKeyValue                LicenseConfigFile::LocateKeyRange                LicenseConfigFile::LocateSection                LicenseConfigFile::uT_main  Input:        const char *p     - 指向Shadow中的地址  Output:       无  Return:       如果p是Shadow中的有效地址,返回指向Content中的对应地址  Others:       *************************************************/char *LicenseConfigFile::MapToContent(const char *p){    assert(m_pszContent);    assert(m_pszShadow);    assert((char *)p >= m_pszShadow);    assert((char *)p <= (m_pszShadow + m_nSize));    return (m_pszContent + (p - m_pszShadow));}/*************************************************  Function:     MapToShadow  Description:  从Content的地址映射到Shadow。  Calls:          Called By:    LicenseConfigFile::LocateKeyValue                LicenseConfigFile::LocateKeyRange                LicenseConfigFile::uT_main  Input:        const char *p     - 指向Shadow中的地址  Output:       无  Return:       如果p是Content中的有效地址,返回指向Shadow中的对应地址  Others:       *************************************************/char *LicenseConfigFile::MapToShadow(const char *p){    assert(m_pszContent);    assert(m_pszShadow);    assert((char *)p >= m_pszContent);    assert((char *)p <= (m_pszContent + m_nSize));    return (m_pszShadow + (p - m_pszContent));}#endif

⌨️ 快捷键说明

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