PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ DBFReadAttribute()

static void* DBFReadAttribute ( DBFHandle  psDBF,
int  hEntity,
int  iField,
char  chReqType 
)
static

Definition at line 961 of file dbfopen.c.

964 {
965  unsigned char *pabyRec;
966  void *pReturnField = NULL;
967 
968 /* -------------------------------------------------------------------- */
969 /* Verify selection. */
970 /* -------------------------------------------------------------------- */
971  if( hEntity < 0 || hEntity >= psDBF->nRecords )
972  return( NULL );
973 
974  if( iField < 0 || iField >= psDBF->nFields )
975  return( NULL );
976 
977 /* -------------------------------------------------------------------- */
978 /* Have we read the record? */
979 /* -------------------------------------------------------------------- */
980  if( !DBFLoadRecord( psDBF, hEntity ) )
981  return NULL;
982 
983  pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
984 
985 /* -------------------------------------------------------------------- */
986 /* Ensure we have room to extract the target field. */
987 /* -------------------------------------------------------------------- */
988  if( psDBF->panFieldSize[iField] >= psDBF->nWorkFieldLength )
989  {
990  psDBF->nWorkFieldLength = psDBF->panFieldSize[iField] + 100;
991  if( psDBF->pszWorkField == NULL )
992  psDBF->pszWorkField = (char *) malloc(psDBF->nWorkFieldLength);
993  else
994  psDBF->pszWorkField = (char *) realloc(psDBF->pszWorkField,
995  psDBF->nWorkFieldLength);
996  }
997 
998 /* -------------------------------------------------------------------- */
999 /* Extract the requested field. */
1000 /* -------------------------------------------------------------------- */
1001  strncpy( psDBF->pszWorkField,
1002  ((const char *) pabyRec) + psDBF->panFieldOffset[iField],
1003  psDBF->panFieldSize[iField] );
1004  psDBF->pszWorkField[psDBF->panFieldSize[iField]] = '\0';
1005 
1006  pReturnField = psDBF->pszWorkField;
1007 
1008 /* -------------------------------------------------------------------- */
1009 /* Decode the field. */
1010 /* -------------------------------------------------------------------- */
1011  if( chReqType == 'N' )
1012  {
1013  psDBF->dfDoubleField = psDBF->sHooks.Atof(psDBF->pszWorkField);
1014 
1015  pReturnField = &(psDBF->dfDoubleField);
1016  }
1017 
1018 /* -------------------------------------------------------------------- */
1019 /* Should we trim white space off the string attribute value? */
1020 /* -------------------------------------------------------------------- */
1021 #ifdef TRIM_DBF_WHITESPACE
1022  else
1023  {
1024  char *pchSrc, *pchDst;
1025 
1026  pchDst = pchSrc = psDBF->pszWorkField;
1027  while( *pchSrc == ' ' )
1028  pchSrc++;
1029 
1030  while( *pchSrc != '\0' )
1031  *(pchDst++) = *(pchSrc++);
1032  *pchDst = '\0';
1033 
1034  while( pchDst != psDBF->pszWorkField && *(--pchDst) == ' ' )
1035  *pchDst = '\0';
1036  }
1037 #endif
1038 
1039  return( pReturnField );
1040 }
static int DBFLoadRecord(DBFHandle psDBF, int iRecord)
Definition: dbfopen.c:291
void * malloc(YYSIZE_T)

References DBFLoadRecord(), and malloc().

Referenced by DBFReadDoubleAttribute(), DBFReadIntegerAttribute(), DBFReadLogicalAttribute(), and DBFReadStringAttribute().

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