?? avc_e00parse.c
字號:
psInfo->eSuperSectionType = AVCFileUnknown; /* psInfo->nStartLineNum = -1; */ return TRUE; } return FALSE;}/********************************************************************** * AVCE00ParseSectionHeader() * * Check if pszLine is a valid section header line, then initialize the * ParseInfo structure to be ready to parse of object from that section. * * Returns the new section type, or AVCFileUnknown if the line is * not recognized as a valid section header. * * Note: by section header lines, we mean the "ARC 2", "PAL 2", etc. **********************************************************************/AVCFileType AVCE00ParseSectionHeader(AVCE00ParseInfo *psInfo, const char *pszLine){ AVCFileType eNewType = AVCFileUnknown; if (psInfo == NULL || psInfo->eFileType != AVCFileUnknown) { return AVCFileUnknown; } /*----------------------------------------------------------------- * Check if pszLine is a valid section header line. *----------------------------------------------------------------*/ if (psInfo->eSuperSectionType == AVCFileUnknown) { /*------------------------------------------------------------- * We're looking for a top-level section... *------------------------------------------------------------*/ if (EQUALN(pszLine, "ARC ", 5)) eNewType = AVCFileARC; else if (EQUALN(pszLine, "PAL ", 5)) eNewType = AVCFilePAL; else if (EQUALN(pszLine, "CNT ", 5)) eNewType = AVCFileCNT; else if (EQUALN(pszLine, "LAB ", 5)) eNewType = AVCFileLAB; else if (EQUALN(pszLine, "TOL ", 5)) eNewType = AVCFileTOL; else if (EQUALN(pszLine, "PRJ ", 5)) eNewType = AVCFilePRJ; else if (EQUALN(pszLine, "TXT ", 5)) eNewType = AVCFileTXT; else { eNewType = AVCFileUnknown; return AVCFileUnknown; } /*------------------------------------------------------------- * OK, we have a valid new section header. Set the precision and * get ready to read objects from it. *------------------------------------------------------------*/ if (atoi(pszLine+4) == 2) psInfo->nPrecision = AVC_SINGLE_PREC; else if (atoi(pszLine+4) == 3) psInfo->nPrecision = AVC_DOUBLE_PREC; else { CPLError(CE_Failure, CPLE_AppDefined, "Parse Error: Invalid section header line (\"%s\")!", pszLine); eNewType = AVCFileUnknown; return AVCFileUnknown; } } else { /*------------------------------------------------------------- * We're looking for a section inside a super-section... * in this case, the header line contains the subclass name, * so any non-empty line is acceptable! * Note: the precision is already set from the previous call to * AVCE00ParseSuperSectionHeader() * Note2: Inside a double precision RPL supersection, the end of * each sub-section is marked by 2 lines, just like what * happens with double precision PALs... we have to make * sure we don't catch that second line as the beginning * of a new RPL sub-section. *------------------------------------------------------------*/ if (psInfo->eSuperSectionType == AVCFileTX6 && strlen(pszLine)==0) { /* See bug 1261: It seems that empty subclass names are valid * for TX7. We don't know if that's valid for other supersection * types, so we'll handle this as a specific case just for TX7 */ eNewType = psInfo->eSuperSectionType; } else if (strlen(pszLine) > 0 && !isspace(pszLine[0]) && !EQUALN(pszLine, "JABBERWOCKY", 11) && !EQUALN(pszLine, "EOI", 3) && ! ( psInfo->eSuperSectionType == AVCFileRPL && EQUALN(pszLine, " 0.00000", 6) ) ) { eNewType = psInfo->eSuperSectionType; } else if (strlen(pszLine) == 0 && psInfo->eSuperSectionType == AVCFileTX6) { eNewType = psInfo->eSuperSectionType; } else { eNewType = AVCFileUnknown; return AVCFileUnknown; } } /*----------------------------------------------------------------- * nCurObjectId is used to keep track of sequential ids that are * not explicitly stored in E00. e.g. polygon Id in a PAL section. *----------------------------------------------------------------*/ psInfo->nCurObjectId = 0; /*----------------------------------------------------------------- * Allocate a temp. structure to use to store the objects we read * (Using Calloc() will automatically initialize the struct contents * to NULL... this is very important for ARCs and PALs) *----------------------------------------------------------------*/ _AVCE00ParseDestroyCurObject(psInfo); if (eNewType == AVCFileARC) { psInfo->cur.psArc = (AVCArc*)CPLCalloc(1, sizeof(AVCArc)); } else if (eNewType == AVCFilePAL || eNewType == AVCFileRPL ) { psInfo->cur.psPal = (AVCPal*)CPLCalloc(1, sizeof(AVCPal)); } else if (eNewType == AVCFileCNT) { psInfo->cur.psCnt = (AVCCnt*)CPLCalloc(1, sizeof(AVCCnt)); } else if (eNewType == AVCFileLAB) { psInfo->cur.psLab = (AVCLab*)CPLCalloc(1, sizeof(AVCLab)); } else if (eNewType == AVCFileTOL) { psInfo->cur.psTol = (AVCTol*)CPLCalloc(1, sizeof(AVCTol)); } else if (eNewType == AVCFilePRJ) { psInfo->cur.papszPrj = NULL; } else if (eNewType == AVCFileTXT || eNewType == AVCFileTX6) { psInfo->cur.psTxt = (AVCTxt*)CPLCalloc(1, sizeof(AVCTxt)); } else if (eNewType == AVCFileRXP) { psInfo->cur.psRxp = (AVCRxp*)CPLCalloc(1, sizeof(AVCRxp)); } else if (eNewType == AVCFileTABLE) { psInfo->cur.pasFields = NULL; psInfo->hdr.psTableDef = NULL; psInfo->bTableHdrComplete = FALSE; } else { CPLError(CE_Failure, CPLE_NotSupported, "AVCE00ParseSectionHeader(): Unsupported file type!"); eNewType = AVCFileUnknown; } if (eNewType != AVCFileUnknown) { /*----------------------------------------------------------------- * Record the start of the section (for faster seeking) *----------------------------------------------------------------*/ psInfo->nStartLineNum = psInfo->nCurLineNum; /*----------------------------------------------------------------- * Keep track of section header line... this is used for some file * types, specially the ones enclosed inside supersections. *----------------------------------------------------------------*/ CPLFree(psInfo->pszSectionHdrLine); psInfo->pszSectionHdrLine = CPLStrdup(pszLine); } psInfo->eFileType = eNewType; return psInfo->eFileType;}/********************************************************************** * AVCE00ParseSectionEnd() * * Check if pszLine marks the end of the current section. * * Passing bResetParseInfo=TRUE will reset the parser struct if an end of * section is found. Passing FALSE simply tests for the end of section * without affecting the parse info struct. * * Return TRUE if this is the end of the section (and reset the * ParseInfo structure) , or FALSE otherwise. **********************************************************************/GBool AVCE00ParseSectionEnd(AVCE00ParseInfo *psInfo, const char *pszLine, GBool bResetParseInfo){ if ( psInfo->bForceEndOfSection || ((psInfo->eFileType == AVCFileARC || psInfo->eFileType == AVCFilePAL || psInfo->eFileType == AVCFileLAB || psInfo->eFileType == AVCFileRPL || psInfo->eFileType == AVCFileCNT || psInfo->eFileType == AVCFileTOL || psInfo->eFileType == AVCFileTXT || psInfo->eFileType == AVCFileTX6 || psInfo->eFileType == AVCFileRXP ) && EQUALN(pszLine, " -1 0", 20) ) ) { /* Reset ParseInfo only if explicitly requested. */ if (bResetParseInfo) { _AVCE00ParseDestroyCurObject(psInfo); AVCE00ParseReset(psInfo); psInfo->eFileType = AVCFileUnknown; CPLFree(psInfo->pszSectionHdrLine); psInfo->pszSectionHdrLine = NULL; psInfo->bForceEndOfSection = FALSE; } return TRUE; /* YES, we reached the end */ } return FALSE; /* NO, it's not the end of section line */}/********************************************************************** * AVCE00ParseNextLine() * * Take the next line of E00 input and parse it. * * Returns NULL if the current object is not complete yet (expecting * more lines of input) or a reference to a complete object if it * is complete. * * The returned object is a reference to an internal data structure. * It should not be modified or freed by the caller. * * If the input is invalid or other problems happen, then a CPLError() * will be generated. CPLGetLastErrorNo() should be called to check * that the line was parsed succesfully. * * Note for TABLES: * When parsing input from info tables, the first valid object that * will be returned will be the AVCTableDef, and then the data records * will follow. When all the records have been read, then the * psInfo->bForceEndOfSection flag will be set to TRUE since there is * no explicit "end of table" line in E00. **********************************************************************/void *AVCE00ParseNextLine(AVCE00ParseInfo *psInfo, const char *pszLine){ void *psObj = NULL; CPLAssert(psInfo); switch(psInfo->eFileType) { case AVCFileARC: psObj = (void*)AVCE00ParseNextArcLine(psInfo, pszLine); break; case AVCFilePAL: case AVCFileRPL: psObj = (void*)AVCE00ParseNextPalLine(psInfo, pszLine); break; case AVCFileCNT: psObj = (void*)AVCE00ParseNextCntLine(psInfo, pszLine); break; case AVCFileLAB: psObj = (void*)AVCE00ParseNextLabLine(psInfo, pszLine); break; case AVCFileTOL: psObj = (void*)AVCE00ParseNextTolLine(psInfo, pszLine); break; case AVCFilePRJ: psObj = (void*)AVCE00ParseNextPrjLine(psInfo, pszLine); break; case AVCFileTXT: psObj = (void*)AVCE00ParseNextTxtLine(psInfo, pszLine); break; case AVCFileTX6: psObj = (void*)AVCE00ParseNextTx6Line(psInfo, pszLine); break; case AVCFileRXP: psObj = (void*)AVCE00ParseNextRxpLine(psInfo, pszLine); break; case AVCFileTABLE: if ( ! psInfo->bTableHdrComplete ) psObj = (void*)AVCE00ParseNextTableDefLine(psInfo, pszLine); else psObj = (void*)AVCE00ParseNextTableRecLine(psInfo, pszLine); break; default: CPLError(CE_Failure, CPLE_NotSupported, "AVCE00ParseNextLine(): Unsupported file type!"); } return psObj;}/********************************************************************** * AVCE00ParseNextArcLine() * * Take the next line of E00 input for an ARC object and parse it. * * Returns NULL if the current object is not complete yet (expecting * more lines of input) or a reference to a complete object if it * is complete. * * The returned object is a reference to an internal data structure. * It should not be modified or freed by the caller. * * If the input is invalid or other problems happen, then a CPLError() * will be generated. CPLGetLastErrorNo() should be called to check * that the line was parsed succesfully. **********************************************************************/AVCArc *AVCE00ParseNextArcLine(AVCE00ParseInfo *psInfo, const char *pszLine){ AVCArc *psArc; int nLen; CPLAssert(psInfo->eFileType == AVCFileARC); psArc = psInfo->cur.psArc;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -