/ Parse a json file. */ /
| 1622 | /* Parse a json file. */ |
| 1623 | /*********************************************************************************/ |
| 1624 | PBVAL BJNX::ParseJsonFile(PGLOBAL g, char *fn, int& pty, size_t& len) |
| 1625 | { |
| 1626 | char *memory; |
| 1627 | HANDLE hFile; |
| 1628 | MEMMAP mm; |
| 1629 | PBVAL jsp; |
| 1630 | |
| 1631 | // Create the mapping file object |
| 1632 | hFile = CreateFileMap(g, fn, &mm, MODE_READ, false); |
| 1633 | |
| 1634 | if (hFile == INVALID_HANDLE_VALUE) { |
| 1635 | DWORD rc = GetLastError(); |
| 1636 | |
| 1637 | if (!(*g->Message)) |
| 1638 | snprintf(g->Message, sizeof(g->Message), MSG(OPEN_MODE_ERROR), "map", (int)rc, fn); |
| 1639 | |
| 1640 | return NULL; |
| 1641 | } // endif hFile |
| 1642 | |
| 1643 | // Get the file size |
| 1644 | len = (size_t)mm.lenL; |
| 1645 | |
| 1646 | if (mm.lenH) |
| 1647 | len += mm.lenH; |
| 1648 | |
| 1649 | memory = (char *)mm.memory; |
| 1650 | |
| 1651 | if (!len) { // Empty or deleted file |
| 1652 | CloseFileHandle(hFile); |
| 1653 | return NULL; |
| 1654 | } // endif len |
| 1655 | |
| 1656 | if (!memory) { |
| 1657 | CloseFileHandle(hFile); |
| 1658 | snprintf(g->Message, sizeof(g->Message), MSG(MAP_VIEW_ERROR), fn, GetLastError()); |
| 1659 | return NULL; |
| 1660 | } // endif Memory |
| 1661 | |
| 1662 | CloseFileHandle(hFile); // Not used anymore |
| 1663 | |
| 1664 | // Parse the json file and allocate its tree structure |
| 1665 | g->Message[0] = 0; |
| 1666 | jsp = ParseJson(g, memory, len); |
| 1667 | pty = pretty; |
| 1668 | CloseMemMap(memory, len); |
| 1669 | return jsp; |
| 1670 | } // end of ParseJsonFile |
| 1671 | |
| 1672 | /*********************************************************************************/ |
| 1673 | /* Make the result according to the first argument type. */ |
no test coverage detected