📄 pciname.cpp
字号:
#include "StdAfx.h"
#include ".\pciname.h"
PCIName::PCIName(void)
: fpPciids(NULL)
, m_startPos(0)
{
}
PCIName::~PCIName(void)
{
}
int PCIName::GetVendorDeviceName(unsigned long vendorId, unsigned long deviceId, char* nameVendor, char* nameDevice)
{
/*char rBuff[1024] = {0};
if(fpPciids == NULL)
{
fpPciids == fopen("pci.ids", "r");
if(fpPciids == NULL)
return -1;
}
//loop up the vendorId
fgets(rBuff, 1024, fpPciids);
*/
CStdioFile file;
CString strLine;
CString chVendor;
CString strVendorName;
CString chDevice;
CString strDeviceName;
BOOL getVendor = false;
if(!file.Open("pci.ids", CFile::modeRead))
{
return -1;
}
while(file.ReadString(strLine))
{
//get one line
if(strLine.GetAt(0) == '#')
{
//comments, continue
continue;
}
if(strLine.GetAt(0) == '\t' && strLine.GetAt(1) == '\t')
{
//subsystem
continue;
}
//should be vendor id and vendor name
//sscanf(strLine.GetBuffer(0), "%4s %s", chVendor, nameVendor);
chVendor = strLine.Left(4);
if(vendorId == _tcstoul(chVendor, 0, 16))
{
strVendorName = strLine.Mid(4);
strncpy(nameVendor, strVendorName.GetBuffer(0), 256);
getVendor = true;
continue;
}
if(getVendor)
{
if(strLine.GetAt(0) == '\t')
{
//sscanf(strLine.GetBuffer(0), "%s %s", chDevice, nameDevice);
chDevice = strLine.Mid(1, 4);
if(deviceId == _tcstoul(chDevice, 0, 16))
{
strDeviceName = strLine.Mid(7);
strncpy(nameDevice, strDeviceName.GetBuffer(0), 256);
file.Close();
return 0;
}
}
}
}
file.Close();
return -1;
}
//return the register description
int PCIName::GetRegDes(int offset, char* desString)
{
CString strLine;
CString strOffset;
CString strDes;
if(!this->fileRegDes.Open("RegDes.txt", CFile::modeRead))
{
return -1;
}
while(fileRegDes.ReadString(strLine))
{
if(strLine.GetAt(0) == '#' || strLine.GetAt(0) == ';')
{
//comments, continue
continue;
}
strOffset = strLine.Left(2);
if(offset == _tcstoul(strOffset, 0, 16))
{
strncpy(desString, strLine.GetBuffer(0) + 3, 256);
fileRegDes.Close();
return 0;
}
}
fileRegDes.Close();
return -1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -