?? avc_e00read.c
字號(hào):
*----------------------------------------------------------------*/ nCoverPrecision = _AVCE00ReadBuildSqueleton(psInfo, papszCoverDir); /* Ignore warnings produced while building squeleton */ CPLErrorReset(); CSLDestroy(papszCoverDir); papszCoverDir = NULL; psInfo->iCurSection = 0; psInfo->iCurStep = AVC_GEN_NOTSTARTED; psInfo->bReadAllSections = TRUE; /*----------------------------------------------------------------- * Init the E00 generator. *----------------------------------------------------------------*/ psInfo->hGenInfo = AVCE00GenInfoAlloc(nCoverPrecision); /*----------------------------------------------------------------- * Init multibyte encoding info *----------------------------------------------------------------*/ psInfo->psDBCSInfo = AVCAllocDBCSInfo(); /*----------------------------------------------------------------- * If an error happened during the open call, cleanup and return NULL. *----------------------------------------------------------------*/ if (CPLGetLastErrorNo() != 0) { AVCE00ReadClose(psInfo); psInfo = NULL; } return psInfo;}/********************************************************************** * AVCE00ReadOpenE00() * * Open a E00 file for reading. * * Returns a new AVCE00ReadE00Ptr handle or NULL if the file could * not be opened or if it does not appear to be a valid E00 file. * * The handle will eventually have to be released with * AVCE00ReadCloseE00(). **********************************************************************/AVCE00ReadE00Ptr AVCE00ReadOpenE00(const char *pszE00FileName){ AVCE00ReadE00Ptr psRead; VSIStatBuf sStatBuf; FILE *fp; char *p; CPLErrorReset(); /*----------------------------------------------------------------- * pszE00FileName must be a valid file that can be opened for * reading *----------------------------------------------------------------*/ if (pszE00FileName == NULL || strlen(pszE00FileName) == 0 || VSIStat(pszE00FileName, &sStatBuf) == -1 || VSI_ISDIR(sStatBuf.st_mode)) { CPLError(CE_Failure, CPLE_OpenFailed, "Invalid E00 file path: %s.", pszE00FileName?pszE00FileName:"(NULL)"); return NULL; } if (NULL == (fp = fopen(pszE00FileName, "r"))) return NULL; /*----------------------------------------------------------------- * Alloc the AVCE00ReadE00Ptr handle *----------------------------------------------------------------*/ psRead = (AVCE00ReadE00Ptr)CPLCalloc(1, sizeof(struct AVCE00ReadInfoE00_t)); psRead->hFile = fp; psRead->pszCoverPath = CPLStrdup(pszE00FileName); psRead->eCurFileType = AVCFileUnknown; /*----------------------------------------------------------------- * Extract the coverage name from the coverage path. *----------------------------------------------------------------*/ if (NULL != (p = strrchr(psRead->pszCoverPath, '/')) || NULL != (p = strrchr(psRead->pszCoverPath, '\\')) || NULL != (p = strrchr(psRead->pszCoverPath, ':'))) { psRead->pszCoverName = CPLStrdup(p + 1); } else { psRead->pszCoverName = CPLStrdup(psRead->pszCoverPath); } if (NULL != (p = strrchr(psRead->pszCoverName, '.'))) { *p = '\0'; } /*----------------------------------------------------------------- * Make sure there was no error until now before we scan file. *----------------------------------------------------------------*/ if (CPLGetLastErrorNo() != 0) { AVCE00ReadCloseE00(psRead); return NULL; } psRead->hParseInfo = AVCE00ParseInfoAlloc(); /*----------------------------------------------------------------- * Scan the E00 file for sections *----------------------------------------------------------------*/ _AVCE00ReadScanE00(psRead); AVCE00ReadRewindE00(psRead); CPLErrorReset(); if (psRead->numSections < 1) { AVCE00ReadCloseE00(psRead); return NULL; } psRead->bReadAllSections = TRUE; /*----------------------------------------------------------------- * If an error happened during the open call, cleanup and return NULL. *----------------------------------------------------------------*/ if (CPLGetLastErrorNo() != 0) { AVCE00ReadCloseE00(psRead); psRead = NULL; } return psRead;}/********************************************************************** * AVCE00ReadClose() * * Close a coverage and release all memory used by the AVCE00ReadPtr * handle. **********************************************************************/void AVCE00ReadClose(AVCE00ReadPtr psInfo){ CPLErrorReset(); if (psInfo == NULL) return; CPLFree(psInfo->pszCoverPath); CPLFree(psInfo->pszInfoPath); CPLFree(psInfo->pszCoverName); if (psInfo->hFile) AVCBinReadClose(psInfo->hFile); if (psInfo->hGenInfo) AVCE00GenInfoFree(psInfo->hGenInfo); if (psInfo->pasSections) { int i; for(i=0; i<psInfo->numSections; i++) { CPLFree(psInfo->pasSections[i].pszName); CPLFree(psInfo->pasSections[i].pszFilename); } CPLFree(psInfo->pasSections); } AVCFreeDBCSInfo(psInfo->psDBCSInfo); CPLFree(psInfo);}/********************************************************************** * AVCE00ReadCloseE00() * * Close a coverage and release all memory used by the AVCE00ReadE00Ptr * handle. **********************************************************************/void AVCE00ReadCloseE00(AVCE00ReadE00Ptr psRead){ CPLErrorReset(); if (psRead == NULL) return; CPLFree(psRead->pszCoverPath); CPLFree(psRead->pszCoverName); if (psRead->hFile) { fclose(psRead->hFile); psRead->hFile = 0; } if (psRead->pasSections) { int i; for(i=0; i<psRead->numSections; i++) { CPLFree(psRead->pasSections[i].pszName); CPLFree(psRead->pasSections[i].pszFilename); } CPLFree(psRead->pasSections); } /* These Free calls handle NULL's */ AVCE00ParseInfoFree(psRead->hParseInfo); psRead->hParseInfo = NULL; CPLFree(psRead);}/********************************************************************** * _AVCIncreaseSectionsArray() * * Add a number of structures to the Sections array and return the * index of the first one that was added. Note that the address of the * original array (*pasArray) is quite likely to change! * * The value of *pnumItems will be updated to reflect the new array size. **********************************************************************/static int _AVCIncreaseSectionsArray(AVCE00Section **pasArray, int *pnumItems, int numToAdd){ int i; *pasArray = (AVCE00Section*)CPLRealloc(*pasArray, (*pnumItems+numToAdd)* sizeof(AVCE00Section)); for(i=0; i<numToAdd; i++) { (*pasArray)[*pnumItems+i].eType = AVCFileUnknown; (*pasArray)[*pnumItems+i].pszName = NULL; (*pasArray)[*pnumItems+i].pszFilename = NULL; (*pasArray)[*pnumItems+i].nLineNum = 0; (*pasArray)[*pnumItems+i].nFeatureCount = -1; } i = *pnumItems; (*pnumItems) += numToAdd; return i;}/********************************************************************** * _AVCE00ReadFindCoverType() * * This functions tries to establish the coverage type by looking * at the coverage directory listing passed as argument. * * Returns one of AVCCoverV7 for Arc/Info V7 (Unix) coverages, or * AVCCoverPC for PC Arc/Info coverages. * AVCCoverWeird for an hybrid between V7 and PC * * If coverage type cannot be established then AVCCoverTypeUnknown is * returned. **********************************************************************/static AVCCoverType _AVCE00ReadFindCoverType(char **papszCoverDir){ int i, nLen; GBool bFoundAdfFile=FALSE, bFoundArcFile=FALSE, bFoundTableFile=FALSE, bFoundDbfFile=FALSE; /*----------------------------------------------------------------- * Scan the list of files, looking for well known filenames. * Start with the funky types first... *----------------------------------------------------------------*/ for(i=0; papszCoverDir && papszCoverDir[i]; i++) { nLen = strlen(papszCoverDir[i]); if (nLen > 4 && EQUAL(papszCoverDir[i]+nLen-4, ".adf") ) { bFoundAdfFile = TRUE; } else if (nLen > 4 && EQUAL(papszCoverDir[i]+nLen-4, ".dbf") ) { bFoundDbfFile = TRUE; } else if (EQUAL(papszCoverDir[i], "arc") || EQUAL(papszCoverDir[i], "cnt") || EQUAL(papszCoverDir[i], "pal") || EQUAL(papszCoverDir[i], "lab") || EQUAL(papszCoverDir[i], "prj") || EQUAL(papszCoverDir[i], "tol") ) { bFoundArcFile = TRUE; } else if (EQUAL(papszCoverDir[i], "aat") || EQUAL(papszCoverDir[i], "pat") || EQUAL(papszCoverDir[i], "bnd") || EQUAL(papszCoverDir[i], "tic") ) { bFoundTableFile = TRUE; } } /*----------------------------------------------------------------- * Check for PC Arc/Info coverage - variant 1. * These PC coverages have files with no extension (e.g. "ARC","PAL",...) * and their tables filenames are in the form "???.dbf" *----------------------------------------------------------------*/ if (bFoundArcFile && bFoundDbfFile) return AVCCoverPC; /*----------------------------------------------------------------- * Check for PC Arc/Info coverage - variant 2. * looks like a hybrid between AVCCoverPC and AVCCoverV7 * These PC coverages have files with .adf extension (e.g."ARC.ADF"), * and their tables filenames are in the form "???.dbf" *----------------------------------------------------------------*/ if (bFoundAdfFile && bFoundDbfFile) return AVCCoverPC2; /*----------------------------------------------------------------- * Check for the weird coverages. * Their coverage files have no extension just like PC Coverages, * and their tables have 3 letters filenames with no extension * either (e.g. "AAT", "PAT", etc.) * They also have a ../info directory, but we don't really need * to check that (not yet!).
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -