/ Parse a json file. */ /
| 1846 | /* Parse a json file. */ |
| 1847 | /*********************************************************************************/ |
| 1848 | static PJSON ParseJsonFile(PGLOBAL g, char *fn, int *pretty, size_t& len) |
| 1849 | { |
| 1850 | char *memory; |
| 1851 | HANDLE hFile; |
| 1852 | MEMMAP mm; |
| 1853 | PJSON jsp; |
| 1854 | |
| 1855 | /*******************************************************************************/ |
| 1856 | /* Create the mapping file object. */ |
| 1857 | /*******************************************************************************/ |
| 1858 | hFile = CreateFileMap(g, fn, &mm, MODE_READ, false); |
| 1859 | |
| 1860 | if (hFile == INVALID_HANDLE_VALUE) { |
| 1861 | DWORD rc = GetLastError(); |
| 1862 | |
| 1863 | if (!(*g->Message)) |
| 1864 | snprintf(g->Message, sizeof(g->Message), MSG(OPEN_MODE_ERROR), "map", (int)rc, fn); |
| 1865 | |
| 1866 | return NULL; |
| 1867 | } // endif hFile |
| 1868 | |
| 1869 | /*******************************************************************************/ |
| 1870 | /* Get the file size. */ |
| 1871 | /*******************************************************************************/ |
| 1872 | len = (size_t)mm.lenL; |
| 1873 | |
| 1874 | if (mm.lenH) |
| 1875 | len += ((size_t)mm.lenH * 0x000000001LL); |
| 1876 | |
| 1877 | memory = (char *)mm.memory; |
| 1878 | |
| 1879 | if (!len) { // Empty or deleted file |
| 1880 | CloseFileHandle(hFile); |
| 1881 | return NULL; |
| 1882 | } // endif len |
| 1883 | |
| 1884 | if (!memory) { |
| 1885 | CloseFileHandle(hFile); |
| 1886 | snprintf(g->Message, sizeof(g->Message), MSG(MAP_VIEW_ERROR), fn, GetLastError()); |
| 1887 | return NULL; |
| 1888 | } // endif Memory |
| 1889 | |
| 1890 | CloseFileHandle(hFile); // Not used anymore |
| 1891 | |
| 1892 | /*********************************************************************************/ |
| 1893 | /* Parse the json file and allocate its tree structure. */ |
| 1894 | /*********************************************************************************/ |
| 1895 | g->Message[0] = 0; |
| 1896 | jsp = ParseJson(g, memory, len, pretty); |
| 1897 | CloseMemMap(memory, len); |
| 1898 | return jsp; |
| 1899 | } // end of ParseJsonFile |
| 1900 | |
| 1901 | /*********************************************************************************/ |
| 1902 | /* Return a json file contains. */ |
no test coverage detected