📄 avc_e00read.c
字号:
return NULL; } /*----------------------------------------------------------------- * Build the E00 file squeleton and be ready to return a E00 header... * We'll also read the coverage precision by the same way. *----------------------------------------------------------------*/ 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;}/********************************************************************** * 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);}/********************************************************************** * _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; } 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 bFoundArcFile, bFoundTableFile; /*----------------------------------------------------------------- * Scan the list of files, looking for well known filenames. * Start with V7 Coverages... they are the easiest to recognize * because of the ".adf" file extension *----------------------------------------------------------------*/ for(i=0; papszCoverDir && papszCoverDir[i]; i++) { nLen = strlen(papszCoverDir[i]); if (nLen > 4 && EQUAL(papszCoverDir[i]+nLen-4, ".adf") ) { return AVCCoverV7; } } /*----------------------------------------------------------------- * Check for PC Arc/Info coverage. * PC coverage files have no extension (e.g. "ARC", "PAL", etc...), * and their tables filenames are in the form "???.dbf" *----------------------------------------------------------------*/ bFoundArcFile = bFoundTableFile = FALSE; for(i=0; papszCoverDir && papszCoverDir[i]; i++) { nLen = strlen(papszCoverDir[i]); 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 (nLen == 7 && EQUAL(papszCoverDir[i]+nLen-4, ".dbf") ) { bFoundTableFile = TRUE; } } if (bFoundArcFile && bFoundTableFile) return AVCCoverPC; /*----------------------------------------------------------------- * And finally the weird coverages. * Their coverage files have no extension just like PC Coverages, * and their 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!). *----------------------------------------------------------------*/ bFoundArcFile = bFoundTableFile = FALSE; for(i=0; papszCoverDir && papszCoverDir[i]; i++) { 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; } } if (bFoundArcFile && bFoundTableFile) return AVCCoverWeird; return AVCCoverTypeUnknown;}/********************************************************************** * _AVCE00ReadAddJabberwockySection() * * Add to the squeleton a section that contains subsections * for all the files with a given extension. * * Returns Updated Coverage precision **********************************************************************/static int _AVCE00ReadAddJabberwockySection(AVCE00ReadPtr psInfo, AVCFileType eFileType, const char *pszSectionName, int nCoverPrecision, const char *pszFileExtension, char **papszCoverDir ){ int iSect, iDirEntry, nLen, nExtLen; GBool bFoundFiles = FALSE; AVCBinFile *psFile=NULL; nExtLen = strlen(pszFileExtension); /*----------------------------------------------------------------- * Scan the directory for files with a ".txt" extension. *----------------------------------------------------------------*/ for (iDirEntry=0; papszCoverDir && papszCoverDir[iDirEntry]; iDirEntry++) { nLen = strlen(papszCoverDir[iDirEntry]); if (nLen > nExtLen && EQUAL(papszCoverDir[iDirEntry] + nLen-nExtLen, pszFileExtension) && (psFile = AVCBinReadOpen(psInfo->pszCoverPath, papszCoverDir[iDirEntry], psInfo->eCoverType, eFileType, psInfo->psDBCSInfo)) != NULL) { if (nCoverPrecision == AVC_DEFAULT_PREC) nCoverPrecision = psFile->nPrecision; AVCBinReadClose(psFile); if (bFoundFiles == FALSE) { /* Insert a "TX6 #" header before the first TX6 file */ iSect = _AVCIncreaseSectionsArray(&(psInfo->pasSections), &(psInfo->numSections), 1); psInfo->pasSections[iSect].eType = AVCFileUnknown; psInfo->pasSections[iSect].pszName = CPLStrdup(CPLSPrintf("%s %c", pszSectionName, (nCoverPrecision==AVC_DOUBLE_PREC)?'3':'2')); bFoundFiles = TRUE; } /* Add this file to the squeleton */ iSect = _AVCIncreaseSectionsArray(&(psInfo->pasSections), &(psInfo->numSections), 1); psInfo->pasSections[iSect].eType = eFileType; psInfo->pasSections[iSect].pszFilename= CPLStrdup(papszCoverDir[iDirEntry]); /* pszName will contain only the classname without the file * extension */ psInfo->pasSections[iSect].pszName = CPLStrdup(papszCoverDir[iDirEntry]); psInfo->pasSections[iSect].pszName[nLen-nExtLen] = '\0'; } } if (bFoundFiles) { /* Add a line to close the TX6 section. */ iSect = _AVCIncreaseSectionsArray(&(psInfo->pasSections), &(psInfo->numSections), 1); psInfo->pasSections[iSect].eType = AVCFileUnknown; psInfo->pasSections[iSect].pszName = CPLStrdup("JABBERWOCKY"); } return nCoverPrecision;}/********************************************************************** * _AVCE00ReadBuildSqueleton() * * Build the squeleton of the E00 file corresponding to the specified * coverage and set the appropriate fields in the AVCE00ReadPtr struct. * * Note that the order of the sections in the squeleton is important * since some software may rely on this ordering when they read E00 files. * * The function returns the coverage precision that it will read from one * of the file headers.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -