------------------------------------------------------------------------------------ Determine if the given parameter is a constant (ENUM or FLAG) ------------------------------------------------------------------------------------
| 1594 | // Determine if the given parameter is a constant (ENUM or FLAG) |
| 1595 | // ------------------------------------------------------------------------------------ |
| 1596 | bool IsHeaderConstant(const char *CommentString, char *szComment, char *inst_source, char *gui_inst_source) |
| 1597 | { |
| 1598 | char lpszHeaders[MAX_PATH] = ""; |
| 1599 | char lpszApiConstant[MAX_PATH] = ""; |
| 1600 | char szConstantComment[MAX_COMMENT_SIZE] = ""; |
| 1601 | char valueIndex[MAX_PATH] = ""; |
| 1602 | char *next_token = nullptr; |
| 1603 | bool found = false; |
| 1604 | bool result = false; |
| 1605 | bool instHex = false; |
| 1606 | bool instFunctPointer = false; |
| 1607 | duint instConst = 0; |
| 1608 | duint fileConst = 0; |
| 1609 | const int safety_chars = 5; |
| 1610 | |
| 1611 | if (CommentString[0] == '[') |
| 1612 | { |
| 1613 | // extract the constant identifier |
| 1614 | GetConstantValue(lpszApiConstant, CommentString); |
| 1615 | const char *ptrVarName = strchr(CommentString, ']'); |
| 1616 | if (ptrVarName != NULL) |
| 1617 | ptrVarName++; // get the pointer to the var name |
| 1618 | |
| 1619 | if (inst_source != NULL) |
| 1620 | { |
| 1621 | if(instHex = IsHex(inst_source)) |
| 1622 | instConst = hextoduint(inst_source); |
| 1623 | } |
| 1624 | |
| 1625 | if (gui_inst_source != NULL) |
| 1626 | { |
| 1627 | string subName = StripFunctNameFromInst(gui_inst_source); |
| 1628 | instFunctPointer = subName != ""; |
| 1629 | } |
| 1630 | |
| 1631 | // get the headers files list where to search the constant |
| 1632 | Utf8Ini *defApiFile = apiDefPointer->second; |
| 1633 | string header = defApiFile->GetValue(szAPIFunction, "Header"); |
| 1634 | if (header.length() == 0) |
| 1635 | return false; |
| 1636 | |
| 1637 | strcpy_s(lpszHeaders, MAX_PATH, header.c_str()); |
| 1638 | // search through the headers files for the constant |
| 1639 | char *token = strtok_s(lpszHeaders, ";", &next_token); |
| 1640 | while (token || !found) |
| 1641 | { |
| 1642 | char singlefile[MAX_PATH] = ""; |
| 1643 | strcpy_s(singlefile, token); |
| 1644 | TruncateString(singlefile, '.'); // strip the .api part |
| 1645 | |
| 1646 | auto search = apiHFiles.find(singlefile); |
| 1647 | if (search != apiHFiles.end()) |
| 1648 | { |
| 1649 | Utf8Ini *defApiHFile = search->second; |
| 1650 | |
| 1651 | string base = defApiHFile->GetValue(lpszApiConstant, "Base"); |
| 1652 | string htype = defApiHFile->GetValue(lpszApiConstant, "Type"); |
| 1653 | string hheader = defApiHFile->GetValue(lpszApiConstant, "Header"); |
no test coverage detected