PostGIS 3.0.6dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ DBFReadAttribute()

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

Definition at line 934 of file dbfopen.c.

935{
936 unsigned char *pabyRec;
937 void *pReturnField = NULL;
938
939 /* -------------------------------------------------------------------- */
940 /* Verify selection. */
941 /* -------------------------------------------------------------------- */
942 if (hEntity < 0 || hEntity >= psDBF->nRecords)
943 return (NULL);
944
945 if (iField < 0 || iField >= psDBF->nFields)
946 return (NULL);
947
948 /* -------------------------------------------------------------------- */
949 /* Have we read the record? */
950 /* -------------------------------------------------------------------- */
951 if (!DBFLoadRecord(psDBF, hEntity))
952 return NULL;
953
954 pabyRec = (unsigned char *)psDBF->pszCurrentRecord;
955
956 /* -------------------------------------------------------------------- */
957 /* Ensure we have room to extract the target field. */
958 /* -------------------------------------------------------------------- */
959 if (psDBF->panFieldSize[iField] >= psDBF->nWorkFieldLength)
960 {
961 psDBF->nWorkFieldLength = psDBF->panFieldSize[iField] + 100;
962 if (psDBF->pszWorkField == NULL)
963 psDBF->pszWorkField = (char *)malloc(psDBF->nWorkFieldLength);
964 else
965 psDBF->pszWorkField = (char *)realloc(psDBF->pszWorkField, psDBF->nWorkFieldLength);
966 }
967
968 /* -------------------------------------------------------------------- */
969 /* Extract the requested field. */
970 /* -------------------------------------------------------------------- */
971 strncpy(
972 psDBF->pszWorkField, ((const char *)pabyRec) + psDBF->panFieldOffset[iField], psDBF->panFieldSize[iField]);
973 psDBF->pszWorkField[psDBF->panFieldSize[iField]] = '\0';
974
975 pReturnField = psDBF->pszWorkField;
976
977 /* -------------------------------------------------------------------- */
978 /* Decode the field. */
979 /* -------------------------------------------------------------------- */
980 if (chReqType == 'N')
981 {
982 psDBF->dfDoubleField = psDBF->sHooks.Atof(psDBF->pszWorkField);
983
984 pReturnField = &(psDBF->dfDoubleField);
985 }
986
987/* -------------------------------------------------------------------- */
988/* Should we trim white space off the string attribute value? */
989/* -------------------------------------------------------------------- */
990#ifdef TRIM_DBF_WHITESPACE
991 else
992 {
993 char *pchSrc, *pchDst;
994
995 pchDst = pchSrc = psDBF->pszWorkField;
996 while (*pchSrc == ' ')
997 pchSrc++;
998
999 while (*pchSrc != '\0')
1000 *(pchDst++) = *(pchSrc++);
1001 *pchDst = '\0';
1002
1003 while (pchDst != psDBF->pszWorkField && *(--pchDst) == ' ')
1004 *pchDst = '\0';
1005 }
1006#endif
1007
1008 return (pReturnField);
1009}
static int DBFLoadRecord(DBFHandle psDBF, int iRecord)
Definition dbfopen.c:286
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: