PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ DBFCreateLL()

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

Definition at line 686 of file dbfopen.c.

688 {
689  DBFHandle psDBF;
690  SAFile fp;
691  char *pszFullname;
692  int ldid = -1;
693  char chZero = '\0';
694  int nLenWithoutExtension;
695 
696 /* -------------------------------------------------------------------- */
697 /* Compute the base (layer) name. If there is any extension */
698 /* on the passed in filename we will strip it off. */
699 /* -------------------------------------------------------------------- */
700  nLenWithoutExtension = DBFGetLenWithoutExtension(pszFilename);
701  pszFullname = STATIC_CAST(char *, malloc(nLenWithoutExtension + 5));
702  if( pszFullname == SHPLIB_NULLPTR )
703  return SHPLIB_NULLPTR;
704  memcpy(pszFullname, pszFilename, nLenWithoutExtension);
705  memcpy(pszFullname + nLenWithoutExtension, ".dbf", 5);
706 
707 /* -------------------------------------------------------------------- */
708 /* Create the file. */
709 /* -------------------------------------------------------------------- */
710  fp = psHooks->FOpen( pszFullname, "wb" );
711  if( fp == SHPLIB_NULLPTR )
712  {
713  free( pszFullname );
714  return SHPLIB_NULLPTR;
715  }
716 
717  psHooks->FWrite( &chZero, 1, 1, fp );
718  psHooks->FClose( fp );
719 
720  fp = psHooks->FOpen( pszFullname, "rb+" );
721  if( fp == SHPLIB_NULLPTR )
722  {
723  free( pszFullname );
724  return SHPLIB_NULLPTR;
725  }
726 
727  memcpy(pszFullname + nLenWithoutExtension, ".cpg", 5);
728  if( pszCodePage != SHPLIB_NULLPTR )
729  {
730  if( strncmp( pszCodePage, "LDID/", 5 ) == 0 )
731  {
732  ldid = atoi( pszCodePage + 5 );
733  if( ldid > 255 )
734  ldid = -1; // don't use 0 to indicate out of range as LDID/0 is a valid one
735  }
736  if( ldid < 0 )
737  {
738  SAFile fpCPG = psHooks->FOpen( pszFullname, "w" );
739  psHooks->FWrite( CONST_CAST(void*, STATIC_CAST(const void*, pszCodePage)), strlen(pszCodePage), 1, fpCPG );
740  psHooks->FClose( fpCPG );
741  }
742  }
743  if( pszCodePage == SHPLIB_NULLPTR || ldid >= 0 )
744  {
745  psHooks->Remove( pszFullname );
746  }
747 
748  free( pszFullname );
749 
750 /* -------------------------------------------------------------------- */
751 /* Create the info structure. */
752 /* -------------------------------------------------------------------- */
753  psDBF = STATIC_CAST(DBFHandle, calloc(1,sizeof(DBFInfo)));
754 
755  memcpy( &(psDBF->sHooks), psHooks, sizeof(SAHooks) );
756  psDBF->fp = fp;
757  psDBF->nRecords = 0;
758  psDBF->nFields = 0;
759  psDBF->nRecordLength = 1;
760  psDBF->nHeaderLength = XBASE_FILEHDR_SZ + 1; /* + 1 for HEADER_RECORD_TERMINATOR */
761 
763  psDBF->panFieldSize = SHPLIB_NULLPTR;
765  psDBF->pachFieldType = SHPLIB_NULLPTR;
766  psDBF->pszHeader = SHPLIB_NULLPTR;
767 
768  psDBF->nCurrentRecord = -1;
769  psDBF->bCurrentRecordModified = FALSE;
771 
772  psDBF->bNoHeader = TRUE;
773 
774  psDBF->iLanguageDriver = ldid > 0 ? ldid : 0;
775  psDBF->pszCodePage = SHPLIB_NULLPTR;
776  if( pszCodePage )
777  {
778  psDBF->pszCodePage = STATIC_CAST(char *, malloc( strlen(pszCodePage) + 1 ));
779  strcpy( psDBF->pszCodePage, pszCodePage );
780  }
781  DBFSetLastModifiedDate(psDBF, 95, 7, 26); /* dummy date */
782 
784 
785  psDBF->bRequireNextWriteSeek = TRUE;
786 
787  return( psDBF );
788 }
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:2317
#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: