PostGIS  2.1.10dev-r@@SVN_REVISION@@
static int DBFWriteAttribute ( DBFHandle  psDBF,
int  hEntity,
int  iField,
void *  pValue 
)
static

Definition at line 1268 of file dbfopen.c.

References DBFFlushRecord(), DBFGetNullCharacter(), DBFLoadRecord(), DBFWriteHeader(), FALSE, and TRUE.

Referenced by DBFWriteDoubleAttribute(), DBFWriteIntegerAttribute(), DBFWriteLogicalAttribute(), DBFWriteNULLAttribute(), and DBFWriteStringAttribute().

1271 {
1272  int i, j, nRetResult = TRUE;
1273  unsigned char *pabyRec;
1274  char szSField[400], szFormat[20];
1275 
1276 /* -------------------------------------------------------------------- */
1277 /* Is this a valid record? */
1278 /* -------------------------------------------------------------------- */
1279  if( hEntity < 0 || hEntity > psDBF->nRecords )
1280  return( FALSE );
1281 
1282  if( psDBF->bNoHeader )
1283  DBFWriteHeader(psDBF);
1284 
1285 /* -------------------------------------------------------------------- */
1286 /* Is this a brand new record? */
1287 /* -------------------------------------------------------------------- */
1288  if( hEntity == psDBF->nRecords )
1289  {
1290  if( !DBFFlushRecord( psDBF ) )
1291  return FALSE;
1292 
1293  psDBF->nRecords++;
1294  for( i = 0; i < psDBF->nRecordLength; i++ )
1295  psDBF->pszCurrentRecord[i] = ' ';
1296 
1297  psDBF->nCurrentRecord = hEntity;
1298  }
1299 
1300 /* -------------------------------------------------------------------- */
1301 /* Is this an existing record, but different than the last one */
1302 /* we accessed? */
1303 /* -------------------------------------------------------------------- */
1304  if( !DBFLoadRecord( psDBF, hEntity ) )
1305  return FALSE;
1306 
1307  pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
1308 
1309  psDBF->bCurrentRecordModified = TRUE;
1310  psDBF->bUpdated = TRUE;
1311 
1312 /* -------------------------------------------------------------------- */
1313 /* Translate NULL value to valid DBF file representation. */
1314 /* */
1315 /* Contributed by Jim Matthews. */
1316 /* -------------------------------------------------------------------- */
1317  if( pValue == NULL )
1318  {
1319  memset( (char *) (pabyRec+psDBF->panFieldOffset[iField]),
1320  DBFGetNullCharacter(psDBF->pachFieldType[iField]),
1321  psDBF->panFieldSize[iField] );
1322  return TRUE;
1323  }
1324 
1325 /* -------------------------------------------------------------------- */
1326 /* Assign all the record fields. */
1327 /* -------------------------------------------------------------------- */
1328  switch( psDBF->pachFieldType[iField] )
1329  {
1330  case 'D':
1331  case 'N':
1332  case 'F':
1333  if( psDBF->panFieldDecimals[iField] == 0 )
1334  {
1335  int nWidth = psDBF->panFieldSize[iField];
1336 
1337  if( (int) sizeof(szSField)-2 < nWidth )
1338  nWidth = sizeof(szSField)-2;
1339 
1340  sprintf( szFormat, "%%%dd", nWidth );
1341  sprintf(szSField, szFormat, (int) *((double *) pValue) );
1342  if( (int)strlen(szSField) > psDBF->panFieldSize[iField] )
1343  {
1344  szSField[psDBF->panFieldSize[iField]] = '\0';
1345  nRetResult = FALSE;
1346  }
1347 
1348  strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1349  szSField, strlen(szSField) );
1350  }
1351  else
1352  {
1353  int nWidth = psDBF->panFieldSize[iField];
1354 
1355  if( (int) sizeof(szSField)-2 < nWidth )
1356  nWidth = sizeof(szSField)-2;
1357 
1358  sprintf( szFormat, "%%%d.%df",
1359  nWidth, psDBF->panFieldDecimals[iField] );
1360  sprintf(szSField, szFormat, *((double *) pValue) );
1361  if( (int) strlen(szSField) > psDBF->panFieldSize[iField] )
1362  {
1363  szSField[psDBF->panFieldSize[iField]] = '\0';
1364  nRetResult = FALSE;
1365  }
1366  strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1367  szSField, strlen(szSField) );
1368  }
1369  break;
1370 
1371  case 'L':
1372  if (psDBF->panFieldSize[iField] >= 1 &&
1373  (*(char*)pValue == 'F' || *(char*)pValue == 'T'))
1374  *(pabyRec+psDBF->panFieldOffset[iField]) = *(char*)pValue;
1375  break;
1376 
1377  default:
1378  if( (int) strlen((char *) pValue) > psDBF->panFieldSize[iField] )
1379  {
1380  j = psDBF->panFieldSize[iField];
1381  nRetResult = FALSE;
1382  }
1383  else
1384  {
1385  memset( pabyRec+psDBF->panFieldOffset[iField], ' ',
1386  psDBF->panFieldSize[iField] );
1387  j = strlen((char *) pValue);
1388  }
1389 
1390  strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1391  (char *) pValue, j );
1392  break;
1393  }
1394 
1395  return( nRetResult );
1396 }
static int DBFLoadRecord(DBFHandle psDBF, int iRecord)
Definition: dbfopen.c:292
static void DBFWriteHeader(DBFHandle psDBF)
Definition: dbfopen.c:198
static int DBFFlushRecord(DBFHandle psDBF)
Definition: dbfopen.c:259
#define FALSE
Definition: dbfopen.c:169
static char DBFGetNullCharacter(char chType)
Definition: dbfopen.c:793
#define TRUE
Definition: dbfopen.c:170

Here is the call graph for this function:

Here is the caller graph for this function: