?? avc_e00read.c
字號:
*----------------------------------------------------------------*/ if (bFoundArcFile && bFoundTableFile) return AVCCoverWeird; /*----------------------------------------------------------------- * V7 Coverages... they are the easiest to recognize * because of the ".adf" file extension *----------------------------------------------------------------*/ if (bFoundAdfFile) return AVCCoverV7; 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;}/********************************************************************** * _AVCE00ReadNextLineE00() * * Processes the next line of input from the E00 file. * (See AVCE00WriteNextLine() for similar processing.) * * Returns the next object from the E00 file, or NULL. **********************************************************************/static void *_AVCE00ReadNextLineE00(AVCE00ReadE00Ptr psRead, const char *pszLine){ int nStatus = 0; void *psObj = 0; AVCE00ParseInfo *psInfo = psRead->hParseInfo; CPLErrorReset(); ++psInfo->nCurLineNum; if (psInfo->bForceEndOfSection) { /*------------------------------------------------------------- * The last call encountered an implicit end of section, so * we close the section now without waiting for an end-of-section * line (there won't be any!)... and get ready to proceed with * the next section. * This is used for TABLEs. *------------------------------------------------------------*/ AVCE00ParseSectionEnd(psInfo, pszLine, TRUE); psRead->eCurFileType = AVCFileUnknown; } /*----------------------------------------------------------------- * If we're at the top level inside a supersection... check if this * supersection ends here. *----------------------------------------------------------------*/ if (AVCE00ParseSuperSectionEnd(psInfo, pszLine) == TRUE) { /* Nothing to do... it's all been done by the call to * AVCE00ParseSuperSectionEnd() */ } else if (psRead->eCurFileType == AVCFileUnknown) { /*------------------------------------------------------------- * We're at the top level or inside a supersection... waiting * to encounter a valid section or supersection header * (i.e. "ARC 2", etc...) *------------------------------------------------------------*/ /*------------------------------------------------------------- * First check for a supersection header (TX6, RXP, IFO, ...) *------------------------------------------------------------*/ if ( AVCE00ParseSuperSectionHeader(psInfo, pszLine) == AVCFileUnknown ) { /*--------------------------------------------------------- * This was not a supersection header... check if it's a simple * section header *--------------------------------------------------------*/ psRead->eCurFileType = AVCE00ParseSectionHeader(psInfo, pszLine); } else { /* got supersection */ } if (psRead->eCurFileType == AVCFileTABLE) { /*--------------------------------------------------------- * send the first header line to the parser and wait until * the whole header has been read. *--------------------------------------------------------*/ AVCE00ParseNextLine(psInfo, pszLine); } else if (psRead->eCurFileType != AVCFileUnknown) { /*--------------------------------------------------------- * found a valid section header *--------------------------------------------------------*/ } } else if (psRead->eCurFileType == AVCFileTABLE && ! psInfo->bTableHdrComplete ) { /*------------------------------------------------------------- * We're reading a TABLE header... continue reading lines * from the header * * Note: When parsing a TABLE, the first object returned will * be the AVCTableDef, then data records will follow. *------------------------------------------------------------*/ psObj = AVCE00ParseNextLine(psInfo, pszLine); if (psObj) { /* got table header */ /* TODO: Enable return of table definition? */ psObj = NULL; } } else { /*------------------------------------------------------------- * We're are in the middle of a section... first check if we * have reached the end. * * note: The first call to AVCE00ParseSectionEnd() with FALSE will * not reset the parser until we close the file... and then * we call the function again to reset the parser. *------------------------------------------------------------*/ if (AVCE00ParseSectionEnd(psInfo, pszLine, FALSE)) { psRead->eCurFileType = AVCFileUnknown; AVCE00ParseSectionEnd(psInfo, pszLine, TRUE); } else /*------------------------------------------------------------- * ... not at the end yet, so continue reading objects. *------------------------------------------------------------*/ { psObj = AVCE00ParseNextLine(psInfo, pszLine); if (psObj) { /* got object */ } } } if (CPLGetLastErrorNo() != 0) nStatus = -1; return psObj;}/********************************************************************** * _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. **********************************************************************/static int _AVCE00ReadBuildSqueleton(AVCE00ReadPtr psInfo, char **papszCoverDir){ int iSect, iTable, numTables, iFile, nLen; char **papszTables, **papszFiles, szCWD[75]="", *pcTmp; char *pszEXPPath=NULL; int nCoverPrecision = AVC_DEFAULT_PREC; char cPrecisionCode = '2'; const char *szFname = NULL; AVCBinFile *psFile=NULL; psInfo->numSections = 0; psInfo->pasSections = NULL; /*----------------------------------------------------------------- * Build the absolute coverage path to include in the EXP 0 line * This line usually contains the full path of the E00 file that * is being created, but since the lib does not write the output * file directly, there is no simple way to get that value. Instead, * we will use the absolute coverage path to which we add a .E00 * extension. * We need also make sure cover path is all in uppercase. *----------------------------------------------------------------*/#ifdef WIN32 if (psInfo->pszCoverPath[0] != '\\' && !(isalpha(psInfo->pszCoverPath[0]) && psInfo->pszCoverPath[1] == ':'))#else if (psInfo->pszCoverPath[0] != '/')#endif { if (getcwd(szCWD, 74) == NULL) szCWD[0] = '\0'; /* Failed: buffer may be too small */ nLen = strlen(szCWD);#ifdef WIN32 if (nLen > 0 && szCWD[nLen -1] != '\\') strcat(szCWD, "\\");#else if (nLen > 0 && szCWD[nLen -1] != '/') strcat(szCWD, "/");#endif } pszEXPPath = CPLStrdup(CPLSPrintf("EXP 0 %s%-.*s.E00", szCWD, strlen(psInfo->pszCoverPath)-1, psInfo->pszCoverPath)); pcTmp = pszEXPPath; for( ; *pcTmp != '\0'; pcTmp++) *pcTmp = toupper(*pcTmp); /*----------------------------------------------------------------- * EXP Header *----------------------------------------------------------------*/ iSect = _AVCIncreaseSectionsArray(&(psInfo->pasSections), &(psInfo->numSections), 1); psInfo->pasSections[iSect].eType = AVCFileUnknown; psInfo->pasSections[iSect].pszName = pszEXPPath; /*----------------------------------------------------------------- * We have to try to open each file as we go for 2 reasons: * - To validate the file's signature in order to detect cases like a user * that places files such as "mystuff.txt" in the cover directory... * this has already happened and obviously lead to problems!) * - We also need to find the coverage's precision from the headers *----------------------------------------------------------------*/ /*----------------------------------------------------------------- * ARC section (arc.adf) *----------------------------------------------------------------*/ szFname = (psInfo->eCoverType==AVCCoverV7 || psInfo->eCoverType==AVCCoverPC2 ) ? "arc.adf": "arc"; if ( (iFile=CSLFindString(papszCoverDir, szFname)) != -1 && (psFile = AVCBinReadOpen(psInfo->pszCoverPath, szFname, psInfo->eCoverType, AVCFileARC, psInfo->psDBCSInfo)) != NULL) { if (nCoverPrecision == AVC_DEFAULT_PREC) nCoverPrecision = psFile->nPrecision;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -