PostGIS  2.2.8dev-r@@SVN_REVISION@@

◆ DBFReadAttribute()

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

Definition at line 957 of file dbfopen.c.

References DBFLoadRecord(), malloc(), and SHPAPI_CALL.

Referenced by DBFReadDoubleAttribute(), and DBFReadIntegerAttribute().

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