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

📄 avc_bin.c

📁 GIS系统支持库Geospatial Data Abstraction Library代码.GDAL is a translator library for raster geospatial dat
💻 C
📖 第 1 页 / 共 5 页
字号:
    {        psTxt->anJust1[i] = 0;        psTxt->anJust2[i] = 0;    }    return 0;}/********************************************************************** *                          AVCBinReadNextTxt() * * Read the next TXT/TX6/TX7 structure from the file. * * Returns a pointer to a static AVCTxt structure whose contents will be * valid only until the next call or NULL if an error happened or if EOF * was reached.   **********************************************************************/AVCTxt *AVCBinReadNextTxt(AVCBinFile *psFile){    int nStatus = 0;    if ((psFile->eFileType != AVCFileTXT && psFile->eFileType != AVCFileTX6) ||        AVCRawBinEOF(psFile->psRawBinFile) )    {        return NULL;    }    /* AVCCoverPC have a different TXT format than AVCCoverV7     *     * Note: Some Weird coverages use the PC TXT structure, and some use the     *       V7 structure.  We distinguish them using the header's precision     *       field in AVCBinReadRewind().     */    if (psFile->eFileType == AVCFileTXT &&        (psFile->eCoverType == AVCCoverPC ||         psFile->eCoverType == AVCCoverWeird) )    {            /* TXT file in PC Coverages (and some Weird Coverages)         */        nStatus = _AVCBinReadNextPCCoverageTxt(psFile->psRawBinFile,                                                psFile->cur.psTxt,                                               psFile->nPrecision);    }    else    {           /* TXT in V7 Coverages (and some Weird Coverages), and TX6/TX7 in          * all coverage types         */        nStatus = _AVCBinReadNextTxt(psFile->psRawBinFile, psFile->cur.psTxt,                                     psFile->nPrecision);    }    if (nStatus != 0)    {        return NULL;    }    return psFile->cur.psTxt;}/*===================================================================== *                              RXP *====================================================================*//********************************************************************** *                          _AVCBinReadNextRxp() * * (This function is for internal library use... external calls should * go to AVCBinReadNextRxp() instead) * * Read the next RXP (Region something...) structure from the file. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextRxp(AVCRawBinFile *psFile, AVCRxp *psRxp,                        int nPrecision){    psRxp->n1  = AVCRawBinReadInt32(psFile);    if (AVCRawBinEOF(psFile))        return -1;    psRxp->n2  = AVCRawBinReadInt32(psFile);    return 0;}/********************************************************************** *                          AVCBinReadNextRxp() * * Read the next RXP structure from the file. * * Returns a pointer to a static AVCRxp structure whose contents will be * valid only until the next call or NULL if an error happened or if EOF * was reached.   **********************************************************************/AVCRxp *AVCBinReadNextRxp(AVCBinFile *psFile){    if (psFile->eFileType != AVCFileRXP ||        AVCRawBinEOF(psFile->psRawBinFile) ||        _AVCBinReadNextRxp(psFile->psRawBinFile, psFile->cur.psRxp,                           psFile->nPrecision) !=0)    {        return NULL;    }    return psFile->cur.psRxp;}/*===================================================================== *                         NATIVE (V7.x) TABLEs * * Note: Also applies to AVCCoverWeird *====================================================================*//********************************************************************** *                          _AVCBinReadNextArcDir() * * (This function is for internal library use... external calls should * go to AVCBinReadOpen() with type AVCFileTABLE instead) * * Read the next record from an arc.dir (or "arcdr9") file. * * Note that arc.dir files have no header... they start with the * first record immediately. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextArcDir(AVCRawBinFile *psFile, AVCTableDef *psArcDir){    int i;    /* Arc/Info Table name      */    AVCRawBinReadString(psFile, 32, psArcDir->szTableName);    psArcDir->szTableName[32] = '\0';    if (AVCRawBinEOF(psFile))        return -1;    /* "ARC####" basename for .DAT and .NIT files     */    AVCRawBinReadString(psFile, 8, psArcDir->szInfoFile);    psArcDir->szInfoFile[7] = '\0';    for (i=6; i>0 && psArcDir->szInfoFile[i]==' '; i--)        psArcDir->szInfoFile[i] = '\0';    psArcDir->numFields = AVCRawBinReadInt16(psFile);    psArcDir->nRecSize  = AVCRawBinReadInt16(psFile);    AVCRawBinFSeek(psFile, 18, SEEK_CUR);     /* Skip 18 bytes */        psArcDir->bDeletedFlag = AVCRawBinReadInt16(psFile);    psArcDir->numRecords = AVCRawBinReadInt32(psFile);    AVCRawBinFSeek(psFile, 10, SEEK_CUR);     /* Skip 10 bytes */        AVCRawBinReadBytes(psFile, 2, psArcDir->szExternal);    psArcDir->szExternal[2] = '\0';    AVCRawBinFSeek(psFile, 300, SEEK_CUR);  /* Skip the remaining 300 bytes */    return 0;}/********************************************************************** *                          _AVCBinReadNextNit() * * (This function is for internal library use... external calls should * go to AVCBinReadOpen() with type AVCFileTABLE instead) * * Read the next record from an arc####.nit file. * * Note that arc####.nit files have no header... they start with the * first record immediately. * * Returns 0 on success or -1 on error. **********************************************************************/int _AVCBinReadNextArcNit(AVCRawBinFile *psFile, AVCFieldInfo *psField){    AVCRawBinReadString(psFile, 16, psField->szName);    psField->szName[16] = '\0';    if (AVCRawBinEOF(psFile))        return -1;    psField->nSize     = AVCRawBinReadInt16(psFile);    psField->v2        = AVCRawBinReadInt16(psFile);  /* Always -1 ? */    psField->nOffset   = AVCRawBinReadInt16(psFile);    psField->v4        = AVCRawBinReadInt16(psFile);  /* Always 4 ?  */    psField->v5        = AVCRawBinReadInt16(psFile);  /* Always -1 ? */    psField->nFmtWidth = AVCRawBinReadInt16(psFile);    psField->nFmtPrec  = AVCRawBinReadInt16(psFile);    psField->nType1    = AVCRawBinReadInt16(psFile);    psField->nType2    = AVCRawBinReadInt16(psFile);  /* Always 0 ? */    psField->v10       = AVCRawBinReadInt16(psFile);  /* Always -1 ? */    psField->v11       = AVCRawBinReadInt16(psFile);  /* Always -1 ? */    psField->v12       = AVCRawBinReadInt16(psFile);  /* Always -1 ? */    psField->v13       = AVCRawBinReadInt16(psFile);  /* Always -1 ? */    AVCRawBinReadString(psFile, 16, psField->szAltName);   /* Always Blank ? */    psField->szAltName[16] = '\0';    AVCRawBinFSeek(psFile, 56, SEEK_CUR);             /* Skip 56 bytes */        psField->nIndex    = AVCRawBinReadInt16(psFile);    AVCRawBinFSeek(psFile, 28, SEEK_CUR);  /* Skip the remaining 28 bytes */    return 0;}/********************************************************************** *                          _AVCBinReadGetInfoFilename() * * Look for the DAT or NIT files for a given table... returns TRUE if * they exist, or FALSE otherwise. * * If pszRetFnmae/pszRetNitFile != NULL then the filename with full path  * will be copied to the specified buffer. **********************************************************************/GBool _AVCBinReadGetInfoFilename(const char *pszInfoPath,                                  const char *pszBasename,                                 const char *pszDatOrNit,                                 AVCCoverType eCoverType,                                 char *pszRetFname){    GBool       bFilesExist = FALSE;    char        *pszBuf = NULL;    VSIStatBuf  sStatBuf;    if (pszRetFname)        pszBuf = pszRetFname;    else        pszBuf = (char*)CPLMalloc((strlen(pszInfoPath)+strlen(pszBasename)+10)*                                  sizeof(char));    if (eCoverType == AVCCoverWeird)    {        sprintf(pszBuf, "%s%s%s", pszInfoPath, pszBasename, pszDatOrNit);    }    else    {        sprintf(pszBuf, "%s%s.%s", pszInfoPath, pszBasename, pszDatOrNit);    }    AVCAdjustCaseSensitiveFilename(pszBuf);    if (VSIStat(pszBuf, &sStatBuf) == 0)        bFilesExist = TRUE;    if (eCoverType == AVCCoverWeird && !bFilesExist)    {        /* In some cases, the filename can be truncated to 8 chars         * and we end up with "ARC000DA"... check that possibility.         */        pszBuf[strlen(pszBuf)-1] = '\0';        AVCAdjustCaseSensitiveFilename(pszBuf);        if (VSIStat(pszBuf, &sStatBuf) == 0)            bFilesExist = TRUE;    }    if (pszRetFname == NULL)        CPLFree(pszBuf);    return bFilesExist;}/********************************************************************** *                          _AVCBinReadInfoFilesExist() * * Look for the DAT and NIT files for a given table... returns TRUE if * they exist, or FALSE otherwise. * * If pszRetDatFile/pszRetNitFile != NULL then the .DAT and .NIT filename * without the info path will be copied to the specified buffers. **********************************************************************/GBool _AVCBinReadInfoFileExists(const char *pszInfoPath,                                 const char *pszBasename,                                AVCCoverType eCoverType){    return (_AVCBinReadGetInfoFilename(pszInfoPath, pszBasename,                                        "dat", eCoverType, NULL) == TRUE &&            _AVCBinReadGetInfoFilename(pszInfoPath, pszBasename,                                        "nit", eCoverType, NULL) == TRUE);}/********************************************************************** *                          AVCBinReadListTables() * * Scan the arc.dir file and return stringlist with one entry for the * Arc/Info name of each table that belongs to the specified coverage. * Pass pszCoverName = NULL to get the list of all tables. * * ppapszArcDatFiles if not NULL will be set to point to a stringlist * with the corresponding "ARC????" info file basenames corresponding * to each table found. * * Note that arc.dir files have no header... they start with the * first record immediately. * * In AVCCoverWeird, the file is called "arcdr9" * * Returns a stringlist that should be deallocated by the caller * with CSLDestroy(), or NULL on error. **********************************************************************/char **AVCBinReadListTables(const char *pszInfoPath, const char *pszCoverName,                            char ***ppapszArcDatFiles, AVCCoverType eCoverType,                            AVCDBCSInfo *psDBCSInfo){    char              **papszList = NULL;    char               *pszFname;    char                szNameToFind[33] = "";    int                 nLen;    AVCRawBinFile      *hFile;    AVCTableDef         sEntry;    if (ppapszArcDatFiles)        *ppapszArcDatFiles = NULL;    /*-----------------------------------------------------------------      * All tables that belong to a given coverage have their name starting     * with the coverage name (in uppercase letters), followed by a 3      * letters extension.     *----------------------------------------------------------------*/    if (pszCoverName != NULL)        sprintf(szNameToFind, "%-.28s.", pszCoverName);    nLen = strlen(szNameToFind);    /*-----------------------------------------------------------------      * Open the arc.dir and add all entries that match the criteria     * to our list.     * In AVCCoverWeird, the file is called "arcdr9"     *----------------------------------------------------------------*/    pszFname = (char*)CPLMalloc((strlen(pszInfoPath)+9)*sizeof(char));    if (eCoverType == AVCCoverWeird)        sprintf(pszFname, "%sarcdr9", pszInfoPath);    else        sprintf(pszFname, "%sarc.dir", pszInfoPath);    AVCAdjustCaseSensitiveFilename(pszFname);    hFile = AVCRawBinOpen(pszFname, "r", AVC_COVER_BYTE_ORDER(eCoverType),                          psDBCSInfo);    if (hFile)    {        while (!AVCRawBinEOF(hFile) &&               _AVCBinReadNextArcDir(hFile, &sEntry) == 0)        {            if (/* sEntry.numRecords > 0 && (DO NOT skip empty tables) */                !sEntry.bDeletedFlag &&                (pszCoverName == NULL ||                 EQUALN(szNameToFind, sEntry.szTableName, nLen)) &&                _AVCBinReadInfoFileExists(pszInfoPath,                                           sEntry.szInfoFile,                                           eCoverType) )            {                papszList = CSLAddString(papszList, sEntry.szTableName);                if (ppapszArcDatFile

⌨️ 快捷键说明

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