PostGIS  3.4.0dev-r@@SVN_REVISION@@

◆ DBFCreateLL()

DBFHandle SHPAPI_CALL DBFCreateLL ( const char *  pszFilename,
const char *  pszCodePage,
SAHooks psHooks 
)

Definition at line 679 of file dbfopen.c.

681 {
682  DBFHandle psDBF;
683  SAFile fp;
684  char *pszFullname;
685  int ldid = -1;
686  char chZero = '\0';
687  int nLenWithoutExtension;
688 
689 /* -------------------------------------------------------------------- */
690 /* Compute the base (layer) name. If there is any extension */
691 /* on the passed in filename we will strip it off. */
692 /* -------------------------------------------------------------------- */
693  nLenWithoutExtension = DBFGetLenWithoutExtension(pszFilename);
694  pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5));
695  memcpy(pszFullname, pszFilename, nLenWithoutExtension);
696  memcpy(pszFullname + nLenWithoutExtension, ".dbf", 5);
697 
698 /* -------------------------------------------------------------------- */
699 /* Create the file. */
700 /* -------------------------------------------------------------------- */
701  fp = psHooks->FOpen( pszFullname, "wb" );
702  if( fp == SHPLIB_NULLPTR )
703  {
704  free( pszFullname );
705  return SHPLIB_NULLPTR;
706  }
707 
708  psHooks->FWrite( &chZero, 1, 1, fp );
709  psHooks->FClose( fp );
710 
711  fp = psHooks->FOpen( pszFullname, "rb+" );
712  if( fp == SHPLIB_NULLPTR )
713  {
714  free( pszFullname );
715  return SHPLIB_NULLPTR;
716  }
717 
718  memcpy(pszFullname + nLenWithoutExtension, ".cpg", 5);
719  if( pszCodePage != SHPLIB_NULLPTR )
720  {
721  if( strncmp( pszCodePage, "LDID/", 5 ) == 0 )
722  {
723  ldid = atoi( pszCodePage + 5 );
724  if( ldid > 255 )
725  ldid = -1; // don't use 0 to indicate out of range as LDID/0 is a valid one
726  }
727  if( ldid < 0 )
728  {
729  SAFile fpCPG = psHooks->FOpen( pszFullname, "w" );
730  psHooks->FWrite( CONST_CAST(void*, STATIC_CAST(const void*, pszCodePage)), strlen(pszCodePage), 1, fpCPG );
731  psHooks->FClose( fpCPG );
732  }
733  }
734  if( pszCodePage == SHPLIB_NULLPTR || ldid >= 0 )
735  {
736  psHooks->Remove( pszFullname );
737  }
738 
739  free( pszFullname );
740 
741 /* -------------------------------------------------------------------- */
742 /* Create the info structure. */
743 /* -------------------------------------------------------------------- */
744  psDBF = STATIC_CAST(DBFHandle, calloc(1,sizeof(DBFInfo)));
745 
746  memcpy( &(psDBF->sHooks), psHooks, sizeof(SAHooks) );
747  psDBF->fp = fp;
748  psDBF->nRecords = 0;
749  psDBF->nFields = 0;
750  psDBF->nRecordLength = 1;
751  psDBF->nHeaderLength = XBASE_FILEHDR_SZ + 1; /* + 1 for HEADER_RECORD_TERMINATOR */
752 
754  psDBF->panFieldSize = SHPLIB_NULLPTR;
756  psDBF->pachFieldType = SHPLIB_NULLPTR;
757  psDBF->pszHeader = SHPLIB_NULLPTR;
758 
759  psDBF->nCurrentRecord = -1;
760  psDBF->bCurrentRecordModified = FALSE;
762 
763  psDBF->bNoHeader = TRUE;
764 
765  psDBF->iLanguageDriver = ldid > 0 ? ldid : 0;
766  psDBF->pszCodePage = SHPLIB_NULLPTR;
767  if( pszCodePage )
768  {
769  psDBF->pszCodePage = STATIC_CAST(char *, malloc( strlen(pszCodePage) + 1 ));
770  strcpy( psDBF->pszCodePage, pszCodePage );
771  }
772  DBFSetLastModifiedDate(psDBF, 95, 7, 26); /* dummy date */
773 
775 
776  psDBF->bRequireNextWriteSeek = TRUE;
777 
778  return( psDBF );
779 }
static int DBFGetLenWithoutExtension(const char *pszBasename)
Definition: dbfopen.c:365
#define STATIC_CAST(type, x)
Definition: dbfopen.c:96
#define XBASE_FILEHDR_SZ
Definition: dbfopen.c:77
#define TRUE
Definition: dbfopen.c:73
#define FALSE
Definition: dbfopen.c:72
void SHPAPI_CALL DBFSetLastModifiedDate(DBFHandle psDBF, int nYYSince1900, int nMM, int nDD)
Definition: dbfopen.c:337
void SHPAPI_CALL DBFSetWriteEndOfFileChar(DBFHandle psDBF, int bWriteFlag)
Definition: dbfopen.c:2297
#define SHPLIB_NULLPTR
Definition: dbfopen.c:99
#define CONST_CAST(type, x)
Definition: dbfopen.c:98
void * malloc(YYSIZE_T)
void free(void *)
int * SAFile
Definition: shapefil.h:283
int nRecordLength
Definition: shapefil.h:596
int * panFieldOffset
Definition: shapefil.h:601
int * panFieldDecimals
Definition: shapefil.h:603
char * pszCodePage
Definition: shapefil.h:625
int nFields
Definition: shapefil.h:600
int nHeaderLength
Definition: shapefil.h:597
int * panFieldSize
Definition: shapefil.h:602
char * pszCurrentRecord
Definition: shapefil.h:610
int bCurrentRecordModified
Definition: shapefil.h:609
char * pszHeader
Definition: shapefil.h:606
SAFile fp
Definition: shapefil.h:592
char * pachFieldType
Definition: shapefil.h:604
int bRequireNextWriteSeek
Definition: shapefil.h:633
SAHooks sHooks
Definition: shapefil.h:590
int bNoHeader
Definition: shapefil.h:615
int iLanguageDriver
Definition: shapefil.h:624
int nRecords
Definition: shapefil.h:594
int nCurrentRecord
Definition: shapefil.h:608
SAFile(* FOpen)(const char *filename, const char *access)
Definition: shapefil.h:290
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
Definition: shapefil.h:292
int(* Remove)(const char *filename)
Definition: shapefil.h:297
int(* FClose)(SAFile file)
Definition: shapefil.h:296

References DBFInfo::bCurrentRecordModified, DBFInfo::bNoHeader, DBFInfo::bRequireNextWriteSeek, CONST_CAST, DBFGetLenWithoutExtension(), DBFSetLastModifiedDate(), DBFSetWriteEndOfFileChar(), FALSE, SAHooks::FClose, SAHooks::FOpen, DBFInfo::fp, free(), SAHooks::FWrite, DBFInfo::iLanguageDriver, malloc(), DBFInfo::nCurrentRecord, DBFInfo::nFields, DBFInfo::nHeaderLength, DBFInfo::nRecordLength, DBFInfo::nRecords, DBFInfo::pachFieldType, DBFInfo::panFieldDecimals, DBFInfo::panFieldOffset, DBFInfo::panFieldSize, DBFInfo::pszCodePage, DBFInfo::pszCurrentRecord, DBFInfo::pszHeader, SAHooks::Remove, DBFInfo::sHooks, SHPLIB_NULLPTR, STATIC_CAST, TRUE, and XBASE_FILEHDR_SZ.

Referenced by DBFCreateEx().

Here is the call graph for this function:
Here is the caller graph for this function: