⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 avc_e00read.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 5 页
字号:
    }    else if (psInfo->eCoverType == AVCCoverPC)    {        /*-------------------------------------------------------------         * PC coverages: look for "???.dbf" in the coverage directory         *               and build the table name using the coverage name         *               as the table basename, and the dbf file basename         *               as the table extension.         *------------------------------------------------------------*/        for(iFile=0; papszCoverDir && papszCoverDir[iFile]; iFile++)        {            if ((nLen = strlen(papszCoverDir[iFile])) == 7 &&                EQUAL(papszCoverDir[iFile] + nLen -4, ".dbf"))            {                papszCoverDir[iFile][nLen - 4] = '\0';                szFname = CPLSPrintf("%s.%s", psInfo->pszCoverName,                                              papszCoverDir[iFile]);                pcTmp = (char*)szFname;                for( ; *pcTmp != '\0'; pcTmp++)                    *pcTmp = toupper(*pcTmp);                papszCoverDir[iFile][nLen - 4] = '.';                papszTables = CSLAddString(papszTables, szFname);                papszFiles = CSLAddString(papszFiles, papszCoverDir[iFile]);            }        }    }    if ((numTables = CSLCount(papszTables)) > 0)    {        iSect = _AVCIncreaseSectionsArray(&(psInfo->pasSections),                                       &(psInfo->numSections), numTables+2);        psInfo->pasSections[iSect].eType = AVCFileUnknown;        psInfo->pasSections[iSect].pszName = CPLStrdup("IFO  X");        psInfo->pasSections[iSect].pszName[5] = cPrecisionCode;        iSect++;        for(iTable=0; iTable<numTables; iTable++)        {            psInfo->pasSections[iSect].eType = AVCFileTABLE;            psInfo->pasSections[iSect].pszName=CPLStrdup(papszTables[iTable]);            if (papszFiles)            {                psInfo->pasSections[iSect].pszFilename=                                              CPLStrdup(papszFiles[iTable]);            }            iSect++;        }        psInfo->pasSections[iSect].eType = AVCFileUnknown;        psInfo->pasSections[iSect].pszName = CPLStrdup("EOI");        iSect++;    }    CSLDestroy(papszTables);    CSLDestroy(papszFiles);    /*-----------------------------------------------------------------     * File ends with EOS     *----------------------------------------------------------------*/    iSect = _AVCIncreaseSectionsArray(&(psInfo->pasSections),                                   &(psInfo->numSections), 1);    psInfo->pasSections[iSect].eType = AVCFileUnknown;    psInfo->pasSections[iSect].pszName = CPLStrdup("EOS");    return nCoverPrecision;}/********************************************************************** *                         _AVCE00ReadNextTableLine() * * Return the next line of the E00 representation of a info table. * * This function is used by AVCE00ReadNextLine() to generate table * output... it should never be called directly. **********************************************************************/static const char *_AVCE00ReadNextTableLine(AVCE00ReadPtr psInfo){    const char *pszLine = NULL;    AVCE00Section *psSect;    psSect = &(psInfo->pasSections[psInfo->iCurSection]);    CPLAssert(psSect->eType == AVCFileTABLE);    if (psInfo->iCurStep == AVC_GEN_NOTSTARTED)    {        /*---------------------------------------------------------         * Open table and start returning header         *--------------------------------------------------------*/        if (psInfo->eCoverType == AVCCoverPC)        {            /*---------------------------------------------------------             * PC Arc/Info: We pass the DBF table's full filename + the             * Arc/Info table name (for E00 header)             *--------------------------------------------------------*/            char *pszFname;            pszFname = CPLStrdup(CPLSPrintf("%s%s", psInfo->pszInfoPath,                                                    psSect->pszFilename ));            psInfo->hFile = AVCBinReadOpen(pszFname, psSect->pszName,                                            psInfo->eCoverType, psSect->eType,                                           psInfo->psDBCSInfo);            CPLFree(pszFname);        }        else        {            /*---------------------------------------------------------             * AVCCoverV7 and AVCCoverWeird:              * We pass the INFO dir's path, and the Arc/Info table name             * will be searched in the arc.dir             *--------------------------------------------------------*/            psInfo->hFile = AVCBinReadOpen(psInfo->pszInfoPath,                                            psSect->pszName,                                            psInfo->eCoverType, psSect->eType,                                           psInfo->psDBCSInfo);        }        /* For some reason the file could not be opened... abort now.         * An error message should have already been produced by          * AVCBinReadOpen()         */        if (psInfo->hFile == NULL)            return NULL;        psInfo->iCurStep = AVC_GEN_TABLEHEADER;        pszLine = AVCE00GenTableHdr(psInfo->hGenInfo,                                    psInfo->hFile->hdr.psTableDef,                                    FALSE);    }            if (pszLine == NULL &&        psInfo->iCurStep == AVC_GEN_TABLEHEADER)    {        /*---------------------------------------------------------         * Continue table header         *--------------------------------------------------------*/        pszLine = AVCE00GenTableHdr(psInfo->hGenInfo,                                    psInfo->hFile->hdr.psTableDef,                                    TRUE);        if (pszLine == NULL)        {            /* Finished with table header... time to proceed with the             * table data.             * Reset the AVCE00GenInfo struct. so that it returns NULL,             * which will force reading of the first record from the              * file on the next call to AVCE00ReadNextLine()             */            AVCE00GenReset(psInfo->hGenInfo);            psInfo->iCurStep = AVC_GEN_TABLEDATA;        }    }    if (pszLine == NULL &&        psInfo->iCurStep == AVC_GEN_TABLEDATA)    {        /*---------------------------------------------------------         * Continue with records of data         *--------------------------------------------------------*/        pszLine = AVCE00GenTableRec(psInfo->hGenInfo,                                     psInfo->hFile->hdr.psTableDef->numFields,                                    psInfo->hFile->hdr.psTableDef->pasFieldDef,                                    psInfo->hFile->cur.pasFields,                                    TRUE);        if (pszLine == NULL)        {            /* Current record is finished generating... we need to read              * a new one from the file.             */            if (AVCBinReadNextObject(psInfo->hFile) != NULL)            {                pszLine = AVCE00GenTableRec(psInfo->hGenInfo,                                     psInfo->hFile->hdr.psTableDef->numFields,                                    psInfo->hFile->hdr.psTableDef->pasFieldDef,                                    psInfo->hFile->cur.pasFields,                                    FALSE);            }                    }    }    if (pszLine == NULL)    {        /*---------------------------------------------------------         * No more lines to output for this table ... Close it.         *--------------------------------------------------------*/        AVCBinReadClose(psInfo->hFile);        psInfo->hFile = NULL;        /*---------------------------------------------------------         * And now proceed to the next section...         * OK, I don't really like recursivity either... but it was         * the simplest way to do this, and anyways we should never         * have more than one level of recursivity.         *--------------------------------------------------------*/        if (psInfo->bReadAllSections)            psInfo->iCurSection++;        else            psInfo->iCurSection = psInfo->numSections;        psInfo->iCurStep = AVC_GEN_NOTSTARTED;        pszLine = AVCE00ReadNextLine(psInfo);    }    /*-----------------------------------------------------------------     * Check for errors... if any error happened, tehn return NULL     *----------------------------------------------------------------*/    if (CPLGetLastErrorNo() != 0)    {        pszLine = NULL;    }    return pszLine;}/********************************************************************** *                          AVCE00ReadNextLine() * * Returns the next line of the E00 representation of the coverage * or NULL when there are no more lines to generate, or if an error happened. * The returned line is a null-terminated string, and it does not * include a newline character. * * Call CPLGetLastErrorNo() after calling AVCE00ReadNextLine() to  * make sure that the line was generated succesfully. * * Note that AVCE00ReadNextLine() returns a reference to an * internal buffer whose contents will * be valid only until the next call to this function.  The caller should * not attempt to free() the returned pointer. **********************************************************************/const char *AVCE00ReadNextLine(AVCE00ReadPtr psInfo){    const char *pszLine = NULL;    AVCE00Section *psSect;    CPLErrorReset();    /*-----------------------------------------------------------------     * Check if we have finished generating E00 output     *----------------------------------------------------------------*/    if (psInfo->iCurSection >= psInfo->numSections)        return NULL;    psSect = &(psInfo->pasSections[psInfo->iCurSection]);    /*-----------------------------------------------------------------     * For simplicity, the generation of table output is in a separate     * function.     *----------------------------------------------------------------*/    if (psSect->eType == AVCFileTABLE)    {        return _AVCE00ReadNextTableLine(psInfo);    }    if (psSect->eType == AVCFileUnknown)    {    /*-----------------------------------------------------------------     * Section not attached to any file, used to hold header lines     * or section separators, etc... just return the line directly and     * move pointer to the next section.     *----------------------------------------------------------------*/        pszLine = psSect->pszName;        if (psInfo->bReadAllSections)            psInfo->iCurSection++;        else            psInfo->iCurSection = psInfo->numSections;        psInfo->iCurStep = AVC_GEN_NOTSTARTED;    }    /*=================================================================     *              ARC, PAL, CNT, LAB, TOL and TXT     *================================================================*/    else if (psInfo->iCurStep == AVC_GEN_NOTSTARTED &&             (psSect->eType == AVCFileARC ||              psSect->eType == AVCFilePAL ||              psSect->eType == AVCFileRPL ||              psSect->eType == AVCFileCNT ||              psSect->eType == AVCFileLAB ||              psSect->eType == AVCFileTOL ||              psSect->eType == AVCFileTXT ||              psSect->eType == AVCFileTX6 ||              psSect->eType == AVCFileRXP   ) )    {    /*-----------------------------------------------------------------     * Start processing of an ARC, PAL, CNT, LAB or TOL section:     *   Open the file, get ready to read the first object from the      *   file, and return the header line.     *  If the file fails to open then we will return NULL.     *----------------------------------------------------------------*/        psInfo->hFile = AVCBinReadOpen(psInfo->pszCoverPath,                                        psSect->pszFilename,                                        psInfo->eCoverType, psSect->eType,                                       psInfo->psDBCSInfo);        /*-------------------------------------------------------------

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -