| 84 | |
| 85 | |
| 86 | SHPTreeHandle msSHPDiskTreeOpen(const char * pszTree, int debug) |
| 87 | { |
| 88 | char *pszFullname, *pszBasename; |
| 89 | SHPTreeHandle psTree; |
| 90 | |
| 91 | char pabyBuf[16]; |
| 92 | int i; |
| 93 | char bBigEndian; |
| 94 | |
| 95 | /* -------------------------------------------------------------------- */ |
| 96 | /* Establish the byte order on this machine. */ |
| 97 | /* -------------------------------------------------------------------- */ |
| 98 | i = 1; |
| 99 | if( *((uchar *) &i) == 1 ) |
| 100 | bBigEndian = MS_FALSE; |
| 101 | else |
| 102 | bBigEndian = MS_TRUE; |
| 103 | |
| 104 | /* -------------------------------------------------------------------- */ |
| 105 | /* Initialize the info structure. */ |
| 106 | /* -------------------------------------------------------------------- */ |
| 107 | psTree = (SHPTreeHandle) msSmallMalloc(sizeof(SHPTreeInfo)); |
| 108 | |
| 109 | /* -------------------------------------------------------------------- */ |
| 110 | /* Compute the base (layer) name. If there is any extension */ |
| 111 | /* on the passed in filename we will strip it off. */ |
| 112 | /* -------------------------------------------------------------------- */ |
| 113 | pszBasename = (char *) msSmallMalloc(strlen(pszTree)+5); |
| 114 | strcpy( pszBasename, pszTree ); |
| 115 | for( i = strlen(pszBasename)-1; |
| 116 | i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/' |
| 117 | && pszBasename[i] != '\\'; |
| 118 | i-- ) {} |
| 119 | |
| 120 | if( pszBasename[i] == '.' ) |
| 121 | pszBasename[i] = '\0'; |
| 122 | |
| 123 | /* -------------------------------------------------------------------- */ |
| 124 | /* Open the .shp and .shx files. Note that files pulled from */ |
| 125 | /* a PC to Unix with upper case filenames won't work! */ |
| 126 | /* -------------------------------------------------------------------- */ |
| 127 | pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5); |
| 128 | sprintf( pszFullname, "%s%s", pszBasename, MS_INDEX_EXTENSION); |
| 129 | psTree->fp = fopen(pszFullname, "rb" ); |
| 130 | |
| 131 | msFree(pszBasename); /* don't need these any more */ |
| 132 | msFree(pszFullname); |
| 133 | |
| 134 | if( psTree->fp == NULL ) { |
| 135 | msFree(psTree); |
| 136 | return( NULL ); |
| 137 | } |
| 138 | |
| 139 | fread( pabyBuf, 8, 1, psTree->fp ); |
| 140 | |
| 141 | memcpy( &psTree->signature, pabyBuf, 3 ); |
| 142 | if( strncmp(psTree->signature,"SQT",3) ) |
| 143 | { |
no test coverage detected