107 #include <grass/shapefil.h>
114 SHP_CVSID(
"$Id: dbfopen.c 32581 2008-08-06 19:30:45Z neteler $")
128 static void * SfRealloc(
void * pMem,
int nNewSize )
132 return( (
void *)
malloc(nNewSize) );
134 return( (
void *) realloc(pMem,nNewSize) );
146 static void DBFWriteHeader(DBFHandle psDBF)
152 if( !psDBF->bNoHeader )
155 psDBF->bNoHeader =
FALSE;
172 abyHeader[8] = (
unsigned char) (psDBF->nHeaderLength % 256);
173 abyHeader[9] = (
unsigned char) (psDBF->nHeaderLength / 256);
175 abyHeader[10] = (
unsigned char) (psDBF->nRecordLength % 256);
176 abyHeader[11] = (
unsigned char) (psDBF->nRecordLength / 256);
182 psDBF->sHooks.FSeek( psDBF->fp, 0, 0 );
183 psDBF->sHooks.FWrite( abyHeader, XBASE_FLDHDR_SZ, 1, psDBF->fp );
184 psDBF->sHooks.FWrite( psDBF->pszHeader, XBASE_FLDHDR_SZ, psDBF->nFields,
190 if( psDBF->nHeaderLength > 32*psDBF->nFields + 32 )
195 psDBF->sHooks.FWrite( &cNewline, 1, 1, psDBF->fp );
205 static int DBFFlushRecord( DBFHandle psDBF )
210 if( psDBF->bCurrentRecordModified && psDBF->nCurrentRecord > -1 )
212 psDBF->bCurrentRecordModified =
FALSE;
215 psDBF->nRecordLength * (
SAOffset) psDBF->nCurrentRecord
216 + psDBF->nHeaderLength;
218 if( psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 ) != 0
219 || psDBF->sHooks.FWrite( psDBF->pszCurrentRecord,
220 psDBF->nRecordLength,
221 1, psDBF->fp ) != 1 )
224 CPLError( CE_Failure, CPLE_FileIO,
225 "Failure writing DBF record %d.",
226 psDBF->nCurrentRecord );
228 fprintf( stderr,
"Failure writing DBF record %d.",
229 psDBF->nCurrentRecord );
242 static int DBFLoadRecord( DBFHandle psDBF,
int iRecord )
245 if( psDBF->nCurrentRecord != iRecord )
249 if( !DBFFlushRecord( psDBF ) )
253 psDBF->nRecordLength * (
SAOffset) iRecord + psDBF->nHeaderLength;
255 if( psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, SEEK_SET ) != 0 )
258 CPLError( CE_Failure, CPLE_FileIO,
259 "fseek(%ld) failed on DBF file.\n",
260 (
long) nRecordOffset );
262 fprintf( stderr,
"fseek(%ld) failed on DBF file.\n",
263 (
long) nRecordOffset );
268 if( psDBF->sHooks.FRead( psDBF->pszCurrentRecord,
269 psDBF->nRecordLength, 1, psDBF->fp ) != 1 )
272 CPLError( CE_Failure, CPLE_FileIO,
273 "fread(%d) failed on DBF file.\n",
274 psDBF->nRecordLength );
276 fprintf( stderr,
"fread(%d) failed on DBF file.\n",
277 psDBF->nRecordLength );
282 psDBF->nCurrentRecord = iRecord;
296 unsigned char abyFileHeader[32];
298 if( psDBF->bNoHeader )
299 DBFWriteHeader( psDBF );
301 DBFFlushRecord( psDBF );
303 psDBF->sHooks.FSeek( psDBF->fp, 0, 0 );
304 psDBF->sHooks.FRead( abyFileHeader, 32, 1, psDBF->fp );
306 abyFileHeader[4] = (
unsigned char) (psDBF->nRecords % 256);
307 abyFileHeader[5] = (
unsigned char) ((psDBF->nRecords/256) % 256);
308 abyFileHeader[6] = (
unsigned char) ((psDBF->nRecords/(256*256)) % 256);
309 abyFileHeader[7] = (
unsigned char) ((psDBF->nRecords/(256*256*256)) % 256);
311 psDBF->sHooks.FSeek( psDBF->fp, 0, 0 );
312 psDBF->sHooks.FWrite( abyFileHeader, 32, 1, psDBF->fp );
314 psDBF->sHooks.FFlush( psDBF->fp );
324 DBFOpen(
const char * pszFilename,
const char * pszAccess )
331 return DBFOpenLL( pszFilename, pszAccess, &sHooks );
345 unsigned char *pabyBuf;
346 int nFields, nHeadLen, iField, i;
347 char *pszBasename, *pszFullname;
352 if( strcmp(pszAccess,
"r") != 0 && strcmp(pszAccess,
"r+") != 0
353 && strcmp(pszAccess,
"rb") != 0 && strcmp(pszAccess,
"rb+") != 0
354 && strcmp(pszAccess,
"r+b") != 0 )
357 if( strcmp(pszAccess,
"r") == 0 )
360 if( strcmp(pszAccess,
"r+") == 0 )
367 pszBasename = (
char *)
malloc(strlen(pszFilename)+5);
368 strcpy( pszBasename, pszFilename );
369 for( i = strlen(pszBasename)-1;
370 i > 0 && pszBasename[i] !=
'.' && pszBasename[i] !=
'/'
371 && pszBasename[i] !=
'\\';
374 if( pszBasename[i] ==
'.' )
375 pszBasename[i] =
'\0';
377 pszFullname = (
char *)
malloc(strlen(pszBasename) + 5);
378 sprintf( pszFullname,
"%s.dbf", pszBasename );
380 psDBF = (DBFHandle) calloc( 1,
sizeof(DBFInfo) );
381 psDBF->fp = psHooks->
FOpen( pszFullname, pszAccess );
382 memcpy( &(psDBF->sHooks), psHooks,
sizeof(
SAHooks) );
384 if( psDBF->fp ==
NULL )
386 sprintf( pszFullname,
"%s.DBF", pszBasename );
387 psDBF->fp = psDBF->sHooks.FOpen(pszFullname, pszAccess );
393 if( psDBF->fp ==
NULL )
399 psDBF->bNoHeader =
FALSE;
400 psDBF->nCurrentRecord = -1;
401 psDBF->bCurrentRecordModified =
FALSE;
406 pabyBuf = (
unsigned char *)
malloc(500);
407 if( psDBF->sHooks.FRead( pabyBuf, 32, 1, psDBF->fp ) != 1 )
409 psDBF->sHooks.FClose( psDBF->fp );
416 pabyBuf[4] + pabyBuf[5]*256 + pabyBuf[6]*256*256 + pabyBuf[7]*256*256*256;
418 psDBF->nHeaderLength = nHeadLen = pabyBuf[8] + pabyBuf[9]*256;
419 psDBF->nRecordLength = pabyBuf[10] + pabyBuf[11]*256;
421 psDBF->nFields = nFields = (nHeadLen - 32) / 32;
423 psDBF->pszCurrentRecord = (
char *)
malloc(psDBF->nRecordLength);
429 pabyBuf = (
unsigned char *) SfRealloc(pabyBuf,nHeadLen);
430 psDBF->pszHeader = (
char *) pabyBuf;
432 psDBF->sHooks.FSeek( psDBF->fp, 32, 0 );
433 if( psDBF->sHooks.FRead( pabyBuf, nHeadLen-32, 1, psDBF->fp ) != 1 )
435 psDBF->sHooks.FClose( psDBF->fp );
437 free( psDBF->pszCurrentRecord );
442 psDBF->panFieldOffset = (
int *)
malloc(
sizeof(
int) * nFields);
443 psDBF->panFieldSize = (
int *)
malloc(
sizeof(
int) * nFields);
444 psDBF->panFieldDecimals = (
int *)
malloc(
sizeof(
int) * nFields);
445 psDBF->pachFieldType = (
char *)
malloc(
sizeof(
char) * nFields);
447 for( iField = 0; iField < nFields; iField++ )
449 unsigned char *pabyFInfo;
451 pabyFInfo = pabyBuf+iField*32;
453 if( pabyFInfo[11] ==
'N' || pabyFInfo[11] ==
'F' )
455 psDBF->panFieldSize[iField] = pabyFInfo[16];
456 psDBF->panFieldDecimals[iField] = pabyFInfo[17];
460 psDBF->panFieldSize[iField] = pabyFInfo[16];
461 psDBF->panFieldDecimals[iField] = 0;
473 psDBF->pachFieldType[iField] = (char) pabyFInfo[11];
475 psDBF->panFieldOffset[iField] = 1;
477 psDBF->panFieldOffset[iField] =
478 psDBF->panFieldOffset[iField-1] + psDBF->panFieldSize[iField-1];
494 if( psDBF->bNoHeader )
495 DBFWriteHeader( psDBF );
497 DBFFlushRecord( psDBF );
503 if( psDBF->bUpdated )
509 psDBF->sHooks.FClose( psDBF->fp );
511 if( psDBF->panFieldOffset !=
NULL )
513 free( psDBF->panFieldOffset );
514 free( psDBF->panFieldSize );
515 free( psDBF->panFieldDecimals );
516 free( psDBF->pachFieldType );
519 if( psDBF->pszWorkField !=
NULL )
520 free( psDBF->pszWorkField );
522 free( psDBF->pszHeader );
523 free( psDBF->pszCurrentRecord );
557 char *pszFullname, *pszBasename;
565 pszBasename = (
char *)
malloc(strlen(pszFilename)+5);
566 strcpy( pszBasename, pszFilename );
567 for( i = strlen(pszBasename)-1;
568 i > 0 && pszBasename[i] !=
'.' && pszBasename[i] !=
'/'
569 && pszBasename[i] !=
'\\';
572 if( pszBasename[i] ==
'.' )
573 pszBasename[i] =
'\0';
575 pszFullname = (
char *)
malloc(strlen(pszBasename) + 5);
576 sprintf( pszFullname,
"%s.dbf", pszBasename );
582 fp = psHooks->
FOpen( pszFullname,
"wb" );
586 psHooks->
FWrite( &chZero, 1, 1, fp );
589 fp = psHooks->
FOpen( pszFullname,
"rb+" );
598 psDBF = (DBFHandle) calloc(1,
sizeof(DBFInfo));
600 memcpy( &(psDBF->sHooks), psHooks,
sizeof(
SAHooks) );
604 psDBF->nRecordLength = 1;
605 psDBF->nHeaderLength = 33;
607 psDBF->panFieldOffset =
NULL;
608 psDBF->panFieldSize =
NULL;
609 psDBF->panFieldDecimals =
NULL;
610 psDBF->pachFieldType =
NULL;
611 psDBF->pszHeader =
NULL;
613 psDBF->nCurrentRecord = -1;
614 psDBF->bCurrentRecordModified =
FALSE;
615 psDBF->pszCurrentRecord =
NULL;
617 psDBF->bNoHeader =
TRUE;
631 DBFFieldType eType,
int nWidth,
int nDecimals )
634 char chNativeType =
'C';
636 if( eType == FTLogical )
638 else if( eType == FTString )
656 char chType,
int nWidth,
int nDecimals )
665 if( psDBF->nRecords > 0 )
668 if( !psDBF->bNoHeader )
683 psDBF->panFieldOffset = (
int *)
684 SfRealloc( psDBF->panFieldOffset,
sizeof(
int) * psDBF->nFields );
686 psDBF->panFieldSize = (
int *)
687 SfRealloc( psDBF->panFieldSize,
sizeof(
int) * psDBF->nFields );
689 psDBF->panFieldDecimals = (
int *)
690 SfRealloc( psDBF->panFieldDecimals,
sizeof(
int) * psDBF->nFields );
692 psDBF->pachFieldType = (
char *)
693 SfRealloc( psDBF->pachFieldType,
sizeof(
char) * psDBF->nFields );
698 psDBF->panFieldOffset[psDBF->nFields-1] = psDBF->nRecordLength;
699 psDBF->nRecordLength += nWidth;
700 psDBF->panFieldSize[psDBF->nFields-1] = nWidth;
701 psDBF->panFieldDecimals[psDBF->nFields-1] = nDecimals;
702 psDBF->pachFieldType[psDBF->nFields-1] = chType;
707 psDBF->nHeaderLength += 32;
708 psDBF->bUpdated =
FALSE;
710 psDBF->pszHeader = (
char *) SfRealloc(psDBF->pszHeader,psDBF->nFields*32);
712 pszFInfo = psDBF->pszHeader + 32 * (psDBF->nFields-1);
714 for( i = 0; i < 32; i++ )
717 if( (
int) strlen(pszFieldName) < 10 )
718 strncpy( pszFInfo, pszFieldName, strlen(pszFieldName));
720 strncpy( pszFInfo, pszFieldName, 10);
722 pszFInfo[11] = psDBF->pachFieldType[psDBF->nFields-1];
726 pszFInfo[16] = (
unsigned char) (nWidth % 256);
727 pszFInfo[17] = (
unsigned char) (nWidth / 256);
731 pszFInfo[16] = (
unsigned char) nWidth;
732 pszFInfo[17] = (
unsigned char) nDecimals;
738 psDBF->pszCurrentRecord = (
char *) SfRealloc(psDBF->pszCurrentRecord,
739 psDBF->nRecordLength);
741 return( psDBF->nFields-1 );
750 static void *DBFReadAttribute(DBFHandle psDBF,
int hEntity,
int iField,
754 unsigned char *pabyRec;
755 void *pReturnField =
NULL;
760 if( hEntity < 0 || hEntity >= psDBF->nRecords )
763 if( iField < 0 || iField >= psDBF->nFields )
769 if( !DBFLoadRecord( psDBF, hEntity ) )
772 pabyRec = (
unsigned char *) psDBF->pszCurrentRecord;
777 if( psDBF->panFieldSize[iField] >= psDBF->nWorkFieldLength )
779 psDBF->nWorkFieldLength = psDBF->panFieldSize[iField] + 100;
780 if( psDBF->pszWorkField ==
NULL )
781 psDBF->pszWorkField = (
char *)
malloc(psDBF->nWorkFieldLength);
783 psDBF->pszWorkField = (
char *) realloc(psDBF->pszWorkField,
784 psDBF->nWorkFieldLength);
790 strncpy( psDBF->pszWorkField,
791 ((
const char *) pabyRec) + psDBF->panFieldOffset[iField],
792 psDBF->panFieldSize[iField] );
793 psDBF->pszWorkField[psDBF->panFieldSize[iField]] =
'\0';
795 pReturnField = psDBF->pszWorkField;
800 if( chReqType ==
'N' )
802 psDBF->dfDoubleField = atof(psDBF->pszWorkField);
804 pReturnField = &(psDBF->dfDoubleField);
810 #ifdef TRIM_DBF_WHITESPACE
813 char *pchSrc, *pchDst;
815 pchDst = pchSrc = psDBF->pszWorkField;
816 while( *pchSrc ==
' ' )
819 while( *pchSrc !=
'\0' )
820 *(pchDst++) = *(pchSrc++);
823 while( pchDst != psDBF->pszWorkField && *(--pchDst) ==
' ' )
828 return( pReturnField );
843 pdValue = (
double *) DBFReadAttribute( psDBF, iRecord, iField,
'N' );
845 if( pdValue ==
NULL )
848 return( (
int) *pdValue );
863 pdValue = (
double *) DBFReadAttribute( psDBF, iRecord, iField,
'N' );
865 if( pdValue ==
NULL )
881 return( (
const char *) DBFReadAttribute( psDBF, iRecord, iField,
'C' ) );
894 return( (
const char *) DBFReadAttribute( psDBF, iRecord, iField,
'L' ) );
909 const char *pszValue;
914 if( pszValue ==
NULL )
917 switch(psDBF->pachFieldType[iField])
926 if( pszValue[0] ==
'*' )
929 for( i = 0; pszValue[i] !=
'\0'; i++ )
931 if( pszValue[i] !=
' ' )
938 return strncmp(pszValue,
"00000000",8) == 0;
942 return pszValue[0] ==
'?';
946 return strlen(pszValue) == 0;
960 return( psDBF->nFields );
973 return( psDBF->nRecords );
984 int * pnWidth,
int * pnDecimals )
987 if( iField < 0 || iField >= psDBF->nFields )
990 if( pnWidth !=
NULL )
991 *pnWidth = psDBF->panFieldSize[iField];
993 if( pnDecimals !=
NULL )
994 *pnDecimals = psDBF->panFieldDecimals[iField];
996 if( pszFieldName !=
NULL )
1000 strncpy( pszFieldName, (
char *) psDBF->pszHeader+iField*32, 11 );
1001 pszFieldName[11] =
'\0';
1002 for( i = 10; i > 0 && pszFieldName[i] ==
' '; i-- )
1003 pszFieldName[i] =
'\0';
1006 if ( psDBF->pachFieldType[iField] ==
'L' )
1009 else if( psDBF->pachFieldType[iField] ==
'N'
1010 || psDBF->pachFieldType[iField] ==
'F' )
1012 if( psDBF->panFieldDecimals[iField] > 0 )
1016 return( FTInteger );
1030 static int DBFWriteAttribute(DBFHandle psDBF,
int hEntity,
int iField,
1034 int i, j, nRetResult =
TRUE;
1035 unsigned char *pabyRec;
1036 char szSField[400], szFormat[20];
1041 if( hEntity < 0 || hEntity > psDBF->nRecords )
1044 if( psDBF->bNoHeader )
1045 DBFWriteHeader(psDBF);
1050 if( hEntity == psDBF->nRecords )
1052 if( !DBFFlushRecord( psDBF ) )
1056 for( i = 0; i < psDBF->nRecordLength; i++ )
1057 psDBF->pszCurrentRecord[i] =
' ';
1059 psDBF->nCurrentRecord = hEntity;
1066 if( !DBFLoadRecord( psDBF, hEntity ) )
1069 pabyRec = (
unsigned char *) psDBF->pszCurrentRecord;
1071 psDBF->bCurrentRecordModified =
TRUE;
1072 psDBF->bUpdated =
TRUE;
1079 if( pValue ==
NULL )
1081 switch(psDBF->pachFieldType[iField])
1086 memset( (
char *) (pabyRec+psDBF->panFieldOffset[iField]),
'*',
1087 psDBF->panFieldSize[iField] );
1092 memset( (
char *) (pabyRec+psDBF->panFieldOffset[iField]),
'0',
1093 psDBF->panFieldSize[iField] );
1098 memset( (
char *) (pabyRec+psDBF->panFieldOffset[iField]),
'?',
1099 psDBF->panFieldSize[iField] );
1104 memset( (
char *) (pabyRec+psDBF->panFieldOffset[iField]),
' ',
1105 psDBF->panFieldSize[iField] );
1114 switch( psDBF->pachFieldType[iField] )
1119 if( psDBF->panFieldDecimals[iField] == 0 )
1121 int nWidth = psDBF->panFieldSize[iField];
1123 if( (
int)
sizeof(szSField)-2 < nWidth )
1124 nWidth =
sizeof(szSField)-2;
1126 sprintf( szFormat,
"%%%dd", nWidth );
1127 sprintf(szSField, szFormat, (
int) *((
double *) pValue) );
1128 if( (
int)strlen(szSField) > psDBF->panFieldSize[iField] )
1130 szSField[psDBF->panFieldSize[iField]] =
'\0';
1134 strncpy((
char *) (pabyRec+psDBF->panFieldOffset[iField]),
1135 szSField, strlen(szSField) );
1139 int nWidth = psDBF->panFieldSize[iField];
1141 if( (
int)
sizeof(szSField)-2 < nWidth )
1142 nWidth =
sizeof(szSField)-2;
1144 sprintf( szFormat,
"%%%d.%df",
1145 nWidth, psDBF->panFieldDecimals[iField] );
1146 sprintf(szSField, szFormat, *((
double *) pValue) );
1147 if( (
int) strlen(szSField) > psDBF->panFieldSize[iField] )
1149 szSField[psDBF->panFieldSize[iField]] =
'\0';
1152 strncpy((
char *) (pabyRec+psDBF->panFieldOffset[iField]),
1153 szSField, strlen(szSField) );
1158 if (psDBF->panFieldSize[iField] >= 1 &&
1159 (*(
char*)pValue ==
'F' || *(
char*)pValue ==
'T'))
1160 *(pabyRec+psDBF->panFieldOffset[iField]) = *(
char*)pValue;
1164 if( (
int) strlen((
char *) pValue) > psDBF->panFieldSize[iField] )
1166 j = psDBF->panFieldSize[iField];
1171 memset( pabyRec+psDBF->panFieldOffset[iField],
' ',
1172 psDBF->panFieldSize[iField] );
1173 j = strlen((
char *) pValue);
1176 strncpy((
char *) (pabyRec+psDBF->panFieldOffset[iField]),
1177 (
char *) pValue, j );
1181 return( nRetResult );
1198 unsigned char *pabyRec;
1203 if( hEntity < 0 || hEntity > psDBF->nRecords )
1206 if( psDBF->bNoHeader )
1207 DBFWriteHeader(psDBF);
1212 if( hEntity == psDBF->nRecords )
1214 if( !DBFFlushRecord( psDBF ) )
1218 for( i = 0; i < psDBF->nRecordLength; i++ )
1219 psDBF->pszCurrentRecord[i] =
' ';
1221 psDBF->nCurrentRecord = hEntity;
1228 if( !DBFLoadRecord( psDBF, hEntity ) )
1231 pabyRec = (
unsigned char *) psDBF->pszCurrentRecord;
1236 if( (
int)strlen((
char *) pValue) > psDBF->panFieldSize[iField] )
1237 j = psDBF->panFieldSize[iField];
1240 memset( pabyRec+psDBF->panFieldOffset[iField],
' ',
1241 psDBF->panFieldSize[iField] );
1242 j = strlen((
char *) pValue);
1245 strncpy((
char *) (pabyRec+psDBF->panFieldOffset[iField]),
1246 (
char *) pValue, j );
1248 psDBF->bCurrentRecordModified =
TRUE;
1249 psDBF->bUpdated =
TRUE;
1265 return( DBFWriteAttribute( psDBF, iRecord, iField, (
void *) &dValue ) );
1279 double dValue = nValue;
1281 return( DBFWriteAttribute( psDBF, iRecord, iField, (
void *) &dValue ) );
1292 const char * pszValue )
1295 return( DBFWriteAttribute( psDBF, iRecord, iField, (
void *) pszValue ) );
1308 return( DBFWriteAttribute( psDBF, iRecord, iField,
NULL ) );
1322 return( DBFWriteAttribute( psDBF, iRecord, iField, (
void *) (&lValue) ) );
1336 unsigned char *pabyRec;
1341 if( hEntity < 0 || hEntity > psDBF->nRecords )
1344 if( psDBF->bNoHeader )
1345 DBFWriteHeader(psDBF);
1350 if( hEntity == psDBF->nRecords )
1352 if( !DBFFlushRecord( psDBF ) )
1356 for( i = 0; i < psDBF->nRecordLength; i++ )
1357 psDBF->pszCurrentRecord[i] =
' ';
1359 psDBF->nCurrentRecord = hEntity;
1366 if( !DBFLoadRecord( psDBF, hEntity ) )
1369 pabyRec = (
unsigned char *) psDBF->pszCurrentRecord;
1371 memcpy ( pabyRec, pRawTuple, psDBF->nRecordLength );
1373 psDBF->bCurrentRecordModified =
TRUE;
1374 psDBF->bUpdated =
TRUE;
1390 if( hEntity < 0 || hEntity >= psDBF->nRecords )
1393 if( !DBFLoadRecord( psDBF, hEntity ) )
1396 return (
const char *) psDBF->pszCurrentRecord;
1411 if ( newDBF ==
NULL )
return (
NULL );
1413 newDBF->nFields = psDBF->nFields;
1414 newDBF->nRecordLength = psDBF->nRecordLength;
1415 newDBF->nHeaderLength = psDBF->nHeaderLength;
1417 newDBF->pszHeader = (
char *)
malloc ( newDBF->nHeaderLength );
1418 memcpy ( newDBF->pszHeader, psDBF->pszHeader, newDBF->nHeaderLength );
1420 newDBF->panFieldOffset = (
int *)
malloc (
sizeof(
int) * psDBF->nFields );
1421 memcpy ( newDBF->panFieldOffset, psDBF->panFieldOffset,
sizeof(
int) * psDBF->nFields );
1422 newDBF->panFieldSize = (
int *)
malloc (
sizeof(
int) * psDBF->nFields );
1423 memcpy ( newDBF->panFieldSize, psDBF->panFieldSize,
sizeof(
int) * psDBF->nFields );
1424 newDBF->panFieldDecimals = (
int *)
malloc (
sizeof(
int) * psDBF->nFields );
1425 memcpy ( newDBF->panFieldDecimals, psDBF->panFieldDecimals,
sizeof(
int) * psDBF->nFields );
1426 newDBF->pachFieldType = (
char *)
malloc (
sizeof(
char) * psDBF->nFields );
1427 memcpy ( newDBF->pachFieldType, psDBF->pachFieldType,
sizeof(
char)*psDBF->nFields );
1429 newDBF->bNoHeader =
TRUE;
1430 newDBF->bUpdated =
TRUE;
1432 DBFWriteHeader ( newDBF );
1435 newDBF =
DBFOpen ( pszFilename,
"rb+" );
1455 if( iField >=0 && iField < psDBF->nFields )
1456 return psDBF->pachFieldType[iField];
1465 static void str_to_upper (
char *
string)
1470 len = strlen (
string);
1473 if (isalpha(
string[i]) && islower(
string[i]))
1474 string[i] = (char) toupper ((
int)
string[i]);
1489 char name[12], name1[12], name2[12];
1492 strncpy(name1, pszFieldName,11);
1494 str_to_upper(name1);
1499 strncpy(name2,name,11);
1500 str_to_upper(name2);
1502 if(!strncmp(name1,name2,10))
1521 if( iShape < 0 || iShape >= psDBF->nRecords )
1527 if( !DBFLoadRecord( psDBF, iShape ) )
1533 return psDBF->pszCurrentRecord[0] ==
'*';
1549 if( iShape < 0 || iShape >= psDBF->nRecords )
1556 if( !DBFLoadRecord( psDBF, iShape ) )
1567 if( psDBF->pszCurrentRecord[0] != chNewFlag )
1569 psDBF->bCurrentRecordModified =
TRUE;
1570 psDBF->bUpdated =
TRUE;
1571 psDBF->pszCurrentRecord[0] = chNewFlag;
int SHPAPI_CALL DBFAddNativeFieldType(DBFHandle psDBF, const char *pszFieldName, char chType, int nWidth, int nDecimals)
int SHPAPI_CALL DBFWriteIntegerAttribute(DBFHandle psDBF, int iRecord, int iField, int nValue)
double SHPAPI_CALL DBFReadDoubleAttribute(DBFHandle psDBF, int iRecord, int iField)
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
const char SHPAPI_CALL1 * DBFReadLogicalAttribute(DBFHandle psDBF, int iRecord, int iField){return((const char *) DBFReadAttribute(psDBF, iRecord, iField, 'L')
void SHPAPI_CALL DBFClose(DBFHandle psDBF)
int SHPAPI_CALL DBFMarkRecordDeleted(DBFHandle psDBF, int iShape, int bIsDeleted)
void SHPAPI_CALL DBFUpdateHeader(DBFHandle psDBF)
DBFHandle SHPAPI_CALL DBFCreateLL(const char *pszFilename, SAHooks *psHooks)
int SHPAPI_CALL DBFGetFieldCount(DBFHandle psDBF)
SAFile(* FOpen)(const char *filename, const char *path)
DBFHandle SHPAPI_CALL DBFCloneEmpty(DBFHandle psDBF, const char *pszFilename)
char SHPAPI_CALL DBFGetNativeFieldType(DBFHandle psDBF, int iField)
const char SHPAPI_CALL1 * DBFReadStringAttribute(DBFHandle psDBF, int iRecord, int iField){return((const char *) DBFReadAttribute(psDBF, iRecord, iField, 'C')
int SHPAPI_CALL DBFAddField(DBFHandle psDBF, const char *pszFieldName, DBFFieldType eType, int nWidth, int nDecimals)
int(* FClose)(SAFile file)
int SHPAPI_CALL DBFWriteLogicalAttribute(DBFHandle psDBF, int iRecord, int iField, const char lValue)
int SHPAPI_CALL DBFGetRecordCount(DBFHandle psDBF)
DBFFieldType SHPAPI_CALL DBFGetFieldInfo(DBFHandle psDBF, int iField, char *pszFieldName, int *pnWidth, int *pnDecimals)
int SHPAPI_CALL DBFWriteDoubleAttribute(DBFHandle psDBF, int iRecord, int iField, double dValue)
int SHPAPI_CALL DBFWriteStringAttribute(DBFHandle psDBF, int iRecord, int iField, const char *pszValue)
int SHPAPI_CALL DBFIsAttributeNULL(DBFHandle psDBF, int iRecord, int iField)
DBFHandle SHPAPI_CALL DBFOpen(const char *pszFilename, const char *pszAccess)
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
int SHPAPI_CALL DBFIsRecordDeleted(DBFHandle psDBF, int iShape)
int SHPAPI_CALL DBFGetFieldIndex(DBFHandle psDBF, const char *pszFieldName)
SHP_CVSID("$Id: safileio.c,v 1.4 2008/01/16 20:05:14 bram Exp $")
void SASetupDefaultHooks(SAHooks *psHooks)
DBFHandle SHPAPI_CALL DBFCreate(const char *pszFilename)
DBFHandle SHPAPI_CALL DBFOpenLL(const char *pszFilename, const char *pszAccess, SAHooks *psHooks)
int SHPAPI_CALL DBFWriteTuple(DBFHandle psDBF, int hEntity, void *pRawTuple)
const char SHPAPI_CALL1 * DBFReadTuple(DBFHandle psDBF, int hEntity){return(NULL
int SHPAPI_CALL DBFReadIntegerAttribute(DBFHandle psDBF, int iRecord, int iField)
int SHPAPI_CALL DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, void *pValue)
int SHPAPI_CALL DBFWriteNULLAttribute(DBFHandle psDBF, int iRecord, int iField)