34 |
****************************************************************************** |
****************************************************************************** |
35 |
* |
* |
36 |
* $Log$ |
* $Log$ |
37 |
* Revision 1.2 2003/10/02 15:15:16 bh |
* Revision 1.3 2004/05/17 15:47:57 bh |
38 |
* Update to shapelib 1.2.10 |
* Update to newest shapelib and get rid of Thuban specific extensions, |
39 |
|
* i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge |
40 |
|
* |
41 |
|
* * libraries/shapelib/shpopen.c: Update to version from current |
42 |
|
* shapelib CVS. |
43 |
|
* |
44 |
|
* * libraries/shapelib/shapefil.h: Update to version from current |
45 |
|
* shapelib CVS. |
46 |
|
* |
47 |
|
* * libraries/shapelib/dbfopen.c: Update to version from current |
48 |
|
* shapelib CVS. |
49 |
|
* (DBFCommit): Effectively removed since shapelib itself has |
50 |
|
* DBFUpdateHeader now which is better for what DBFCommit wanted to |
51 |
|
* achieve. |
52 |
|
* We're now using an unmodified version of dbfopen. |
53 |
|
* |
54 |
|
* * libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py: |
55 |
|
* Update from dbflib.i |
56 |
|
* |
57 |
|
* * libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of |
58 |
|
* the commit method. This new indirection is necessary because we use the |
59 |
|
* DBFUpdateHeader function now which is not available in shapelib <= |
60 |
|
* 1.2.10 |
61 |
|
* (DBFFile::commit): Use DBFInfo_commit as implementation |
62 |
|
* (pragma __class__): New. Kludge to remove the commit method when |
63 |
|
* the DBFUpdateHeader function isn't available |
64 |
|
* (_have_commit): New. Helper for the pragma kludge. |
65 |
|
* |
66 |
|
* * libraries/pyshapelib/setup.py (dbf_macros): New. Return the |
67 |
|
* preprocessor macros needed to compile the dbflib wrapper. Determine |
68 |
|
* whether DBFUpdateHeader is available and define the right value of |
69 |
|
* HAVE_UPDATE_HEADER |
70 |
|
* (extensions): Use dbf_macros for the dbflibc extension |
71 |
|
* |
72 |
|
* * setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with |
73 |
|
* value '1' to the Lib.dbflibc extension. This simply reflects the |
74 |
|
* shapelib and pyshapelib updates |
75 |
|
* |
76 |
|
* Revision 1.53 2003/12/29 00:00:30 fwarmerdam |
77 |
|
* mark DBFWriteAttributeDirectly as SHPAPI_CALL |
78 |
|
* |
79 |
|
* Revision 1.52 2003/07/08 15:20:03 warmerda |
80 |
|
* avoid warnings about downcasting to unsigned char |
81 |
|
* |
82 |
|
* Revision 1.51 2003/07/08 13:50:15 warmerda |
83 |
|
* DBFIsAttributeNULL check for pszValue==NULL - bug 360 |
84 |
|
* |
85 |
|
* Revision 1.50 2003/04/21 18:58:25 warmerda |
86 |
|
* ensure current record is flushed at same time as header is updated |
87 |
|
* |
88 |
|
* Revision 1.49 2003/04/21 18:30:37 warmerda |
89 |
|
* added header write/update public methods |
90 |
* |
* |
91 |
* Revision 1.48 2003/03/10 14:51:27 warmerda |
* Revision 1.48 2003/03/10 14:51:27 warmerda |
92 |
* DBFWrite* calls now return FALSE if they have to truncate |
* DBFWrite* calls now return FALSE if they have to truncate |
251 |
# define TRUE 1 |
# define TRUE 1 |
252 |
#endif |
#endif |
253 |
|
|
254 |
|
#if defined(_WIN32) || defined(_WIN64) |
255 |
|
# define MS_WINDOWS |
256 |
|
#endif |
257 |
|
|
258 |
static int nStringFieldLen = 0; |
static int nStringFieldLen = 0; |
259 |
static char * pszStringField = NULL; |
static char * pszStringField = NULL; |
260 |
|
|
261 |
/************************************************************************/ |
/************************************************************************/ |
262 |
|
/* DBFSet_atof_function() */ |
263 |
|
/* */ |
264 |
|
/* This makes it possible to initialise a different atof() function */ |
265 |
|
/* which might be necessary because the standard atof() might be */ |
266 |
|
/* sensitive to locale settings. */ |
267 |
|
/* */ |
268 |
|
/* If the calling application uses a locale with different decimal_point*/ |
269 |
|
/* it should better also give us a locale agnostic atof() function. */ |
270 |
|
/* */ |
271 |
|
/* As far as I can see from Python PEP331 and GNU libc documentation */ |
272 |
|
/* there is no standard for such a function yet. */ |
273 |
|
/* */ |
274 |
|
/* [email protected] 20060924 */ |
275 |
|
/************************************************************************/ |
276 |
|
|
277 |
|
static double (* atof_function)(const char *nptr) = &atof; |
278 |
|
|
279 |
|
void SHPAPI_CALL |
280 |
|
DBFSetatof_function( double (* new_atof_function)(const char *nptr)) |
281 |
|
{ |
282 |
|
atof_function = new_atof_function; |
283 |
|
} |
284 |
|
|
285 |
|
/************************************************************************/ |
286 |
/* SfRealloc() */ |
/* SfRealloc() */ |
287 |
/* */ |
/* */ |
288 |
/* A realloc cover function that will access a NULL pointer as */ |
/* A realloc cover function that will access a NULL pointer as */ |
326 |
|
|
327 |
abyHeader[0] = 0x03; /* memo field? - just copying */ |
abyHeader[0] = 0x03; /* memo field? - just copying */ |
328 |
|
|
329 |
/* date updated on close, record count preset at zero */ |
/* write out a dummy date */ |
330 |
|
abyHeader[1] = 95; /* YY */ |
331 |
|
abyHeader[2] = 7; /* MM */ |
332 |
|
abyHeader[3] = 26; /* DD */ |
333 |
|
|
334 |
abyHeader[8] = psDBF->nHeaderLength % 256; |
/* record count preset at zero */ |
335 |
abyHeader[9] = psDBF->nHeaderLength / 256; |
|
336 |
|
abyHeader[8] = (unsigned char) (psDBF->nHeaderLength % 256); |
337 |
|
abyHeader[9] = (unsigned char) (psDBF->nHeaderLength / 256); |
338 |
|
|
339 |
abyHeader[10] = psDBF->nRecordLength % 256; |
abyHeader[10] = (unsigned char) (psDBF->nRecordLength % 256); |
340 |
abyHeader[11] = psDBF->nRecordLength / 256; |
abyHeader[11] = (unsigned char) (psDBF->nRecordLength / 256); |
341 |
|
|
342 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
343 |
/* Write the initial 32 byte file header, and all the field */ |
/* Write the initial 32 byte file header, and all the field */ |
383 |
} |
} |
384 |
|
|
385 |
/************************************************************************/ |
/************************************************************************/ |
386 |
|
/* DBFUpdateHeader() */ |
387 |
|
/************************************************************************/ |
388 |
|
|
389 |
|
void SHPAPI_CALL |
390 |
|
DBFUpdateHeader( DBFHandle psDBF ) |
391 |
|
|
392 |
|
{ |
393 |
|
unsigned char abyFileHeader[32]; |
394 |
|
|
395 |
|
if( psDBF->bNoHeader ) |
396 |
|
DBFWriteHeader( psDBF ); |
397 |
|
|
398 |
|
DBFFlushRecord( psDBF ); |
399 |
|
|
400 |
|
fseek( psDBF->fp, 0, 0 ); |
401 |
|
fread( abyFileHeader, 32, 1, psDBF->fp ); |
402 |
|
|
403 |
|
abyFileHeader[4] = (unsigned char) (psDBF->nRecords % 256); |
404 |
|
abyFileHeader[5] = (unsigned char) ((psDBF->nRecords/256) % 256); |
405 |
|
abyFileHeader[6] = (unsigned char) ((psDBF->nRecords/(256*256)) % 256); |
406 |
|
abyFileHeader[7] = (unsigned char) ((psDBF->nRecords/(256*256*256)) % 256); |
407 |
|
|
408 |
|
fseek( psDBF->fp, 0, 0 ); |
409 |
|
fwrite( abyFileHeader, 32, 1, psDBF->fp ); |
410 |
|
|
411 |
|
fflush( psDBF->fp ); |
412 |
|
} |
413 |
|
|
414 |
|
/************************************************************************/ |
415 |
/* DBFOpen() */ |
/* DBFOpen() */ |
416 |
/* */ |
/* */ |
417 |
/* Open a .dbf file. */ |
/* Open a .dbf file. */ |
421 |
DBFOpen( const char * pszFilename, const char * pszAccess ) |
DBFOpen( const char * pszFilename, const char * pszAccess ) |
422 |
|
|
423 |
{ |
{ |
424 |
DBFHandle psDBF; |
FILE* fp; |
425 |
unsigned char *pabyBuf; |
int i; |
|
int nFields, nHeadLen, nRecLen, iField, i; |
|
426 |
char *pszBasename, *pszFullname; |
char *pszBasename, *pszFullname; |
427 |
|
|
428 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
456 |
pszFullname = (char *) malloc(strlen(pszBasename) + 5); |
pszFullname = (char *) malloc(strlen(pszBasename) + 5); |
457 |
sprintf( pszFullname, "%s.dbf", pszBasename ); |
sprintf( pszFullname, "%s.dbf", pszBasename ); |
458 |
|
|
459 |
psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) ); |
fp = fopen( pszFullname, pszAccess ); |
|
psDBF->fp = fopen( pszFullname, pszAccess ); |
|
460 |
|
|
461 |
if( psDBF->fp == NULL ) |
if( fp == NULL ) |
462 |
{ |
{ |
463 |
sprintf( pszFullname, "%s.DBF", pszBasename ); |
sprintf( pszFullname, "%s.DBF", pszBasename ); |
464 |
psDBF->fp = fopen(pszFullname, pszAccess ); |
fp = fopen(pszFullname, pszAccess ); |
465 |
} |
} |
466 |
|
|
467 |
free( pszBasename ); |
free( pszBasename ); |
468 |
free( pszFullname ); |
free( pszFullname ); |
469 |
|
|
470 |
if( psDBF->fp == NULL ) |
return DBFOpenEx( fp ); |
471 |
{ |
} |
472 |
free( psDBF ); |
|
473 |
|
|
474 |
|
|
475 |
|
/************************************************************************/ |
476 |
|
/* DBFOpenW() */ |
477 |
|
/* */ |
478 |
|
/* Open a .dbf file with a wide character filename */ |
479 |
|
/************************************************************************/ |
480 |
|
|
481 |
|
#ifdef SHPAPI_HAS_WIDE |
482 |
|
|
483 |
|
DBFHandle SHPAPI_CALL |
484 |
|
DBFOpenW( const wchar_t * pszFilename, const wchar_t * pszAccess ) |
485 |
|
|
486 |
|
{ |
487 |
|
FILE* fp; |
488 |
|
int i; |
489 |
|
wchar_t *pszBasename, *pszFullname; |
490 |
|
|
491 |
|
/* -------------------------------------------------------------------- */ |
492 |
|
/* We only allow the access strings "rb" and "r+". */ |
493 |
|
/* -------------------------------------------------------------------- */ |
494 |
|
if( wcscmp(pszAccess,L"r") != 0 && wcscmp(pszAccess,L"r+") != 0 |
495 |
|
&& wcscmp(pszAccess,L"rb") != 0 && wcscmp(pszAccess,L"rb+") != 0 |
496 |
|
&& wcscmp(pszAccess,L"r+b") != 0 ) |
497 |
return( NULL ); |
return( NULL ); |
498 |
|
|
499 |
|
if( wcscmp(pszAccess,L"r") == 0 ) |
500 |
|
pszAccess = L"rb"; |
501 |
|
|
502 |
|
if( wcscmp(pszAccess,L"r+") == 0 ) |
503 |
|
pszAccess = L"rb+"; |
504 |
|
|
505 |
|
/* -------------------------------------------------------------------- */ |
506 |
|
/* Compute the base (layer) name. If there is any extension */ |
507 |
|
/* on the passed in filename we will strip it off. */ |
508 |
|
/* -------------------------------------------------------------------- */ |
509 |
|
pszBasename = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszFilename)+5)); |
510 |
|
wcscpy( pszBasename, pszFilename ); |
511 |
|
for( i = wcslen(pszBasename)-1; |
512 |
|
i > 0 && pszBasename[i] != L'.' && pszBasename[i] != L'/' |
513 |
|
&& pszBasename[i] != L'\\'; |
514 |
|
i-- ) {} |
515 |
|
|
516 |
|
if( pszBasename[i] == L'.' ) |
517 |
|
pszBasename[i] = L'\0'; |
518 |
|
|
519 |
|
pszFullname = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszBasename) + 5)); |
520 |
|
swprintf( pszFullname, L"%s.dbf", pszBasename ); |
521 |
|
|
522 |
|
fp = _wfopen( pszFullname, pszAccess ); |
523 |
|
|
524 |
|
if( fp == NULL ) |
525 |
|
{ |
526 |
|
swprintf( pszFullname, L"%s.DBF", pszBasename ); |
527 |
|
fp = _wfopen(pszFullname, pszAccess ); |
528 |
} |
} |
529 |
|
|
530 |
|
free( pszBasename ); |
531 |
|
free( pszFullname ); |
532 |
|
|
533 |
|
return DBFOpenEx( fp ); |
534 |
|
} |
535 |
|
|
536 |
|
#endif |
537 |
|
|
538 |
|
|
539 |
|
|
540 |
|
/************************************************************************/ |
541 |
|
/* DBFOpenEx() */ |
542 |
|
/* */ |
543 |
|
/* Open a .dbf file from a freshly opened FILE */ |
544 |
|
/************************************************************************/ |
545 |
|
|
546 |
|
DBFHandle SHPAPI_CALL |
547 |
|
DBFOpenEx( FILE* fp ) |
548 |
|
|
549 |
|
{ |
550 |
|
unsigned char *pabyBuf; |
551 |
|
int nFields, nHeadLen, nRecLen, iField; |
552 |
|
DBFHandle psDBF = NULL; |
553 |
|
|
554 |
|
if( fp == NULL ) |
555 |
|
{ |
556 |
|
return( NULL ); |
557 |
|
} |
558 |
|
|
559 |
|
psDBF = (DBFHandle) calloc( 1, sizeof(DBFInfo) ); |
560 |
|
psDBF->fp = fp; |
561 |
|
|
562 |
psDBF->bNoHeader = FALSE; |
psDBF->bNoHeader = FALSE; |
563 |
psDBF->nCurrentRecord = -1; |
psDBF->nCurrentRecord = -1; |
641 |
void SHPAPI_CALL |
void SHPAPI_CALL |
642 |
DBFClose(DBFHandle psDBF) |
DBFClose(DBFHandle psDBF) |
643 |
{ |
{ |
644 |
|
if( psDBF == NULL ) |
645 |
|
return; |
646 |
|
|
647 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
648 |
/* Write out header if not already written. */ |
/* Write out header if not already written. */ |
649 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
657 |
/* write access. */ |
/* write access. */ |
658 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
659 |
if( psDBF->bUpdated ) |
if( psDBF->bUpdated ) |
660 |
{ |
DBFUpdateHeader( psDBF ); |
|
unsigned char abyFileHeader[32]; |
|
|
|
|
|
fseek( psDBF->fp, 0, 0 ); |
|
|
fread( abyFileHeader, 32, 1, psDBF->fp ); |
|
|
|
|
|
abyFileHeader[1] = 95; /* YY */ |
|
|
abyFileHeader[2] = 7; /* MM */ |
|
|
abyFileHeader[3] = 26; /* DD */ |
|
|
|
|
|
abyFileHeader[4] = psDBF->nRecords % 256; |
|
|
abyFileHeader[5] = (psDBF->nRecords/256) % 256; |
|
|
abyFileHeader[6] = (psDBF->nRecords/(256*256)) % 256; |
|
|
abyFileHeader[7] = (psDBF->nRecords/(256*256*256)) % 256; |
|
|
|
|
|
fseek( psDBF->fp, 0, 0 ); |
|
|
fwrite( abyFileHeader, 32, 1, psDBF->fp ); |
|
|
} |
|
661 |
|
|
662 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
663 |
/* Close, and free resources. */ |
/* Close, and free resources. */ |
695 |
DBFCreate( const char * pszFilename ) |
DBFCreate( const char * pszFilename ) |
696 |
|
|
697 |
{ |
{ |
|
DBFHandle psDBF; |
|
698 |
FILE *fp; |
FILE *fp; |
699 |
char *pszFullname, *pszBasename; |
char *pszFullname, *pszBasename; |
700 |
int i; |
int i; |
733 |
|
|
734 |
free( pszFullname ); |
free( pszFullname ); |
735 |
|
|
736 |
|
return DBFCreateEx( fp ); |
737 |
|
} |
738 |
|
|
739 |
|
|
740 |
|
|
741 |
|
/************************************************************************/ |
742 |
|
/* DBFCreateW() */ |
743 |
|
/* */ |
744 |
|
/* Create a new .dbf file with a wide character filename */ |
745 |
|
/************************************************************************/ |
746 |
|
|
747 |
|
#ifdef SHPAPI_HAS_WIDE |
748 |
|
|
749 |
|
DBFHandle SHPAPI_CALL |
750 |
|
DBFCreateW( const wchar_t * pszFilename ) |
751 |
|
|
752 |
|
{ |
753 |
|
FILE *fp; |
754 |
|
wchar_t *pszFullname, *pszBasename; |
755 |
|
int i; |
756 |
|
|
757 |
|
/* -------------------------------------------------------------------- */ |
758 |
|
/* Compute the base (layer) name. If there is any extension */ |
759 |
|
/* on the passed in filename we will strip it off. */ |
760 |
|
/* -------------------------------------------------------------------- */ |
761 |
|
pszBasename = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszFilename)+5)); |
762 |
|
wcscpy( pszBasename, pszFilename ); |
763 |
|
for( i = wcslen(pszBasename)-1; |
764 |
|
i > 0 && pszBasename[i] != L'.' && pszBasename[i] != L'/' |
765 |
|
&& pszBasename[i] != L'\\'; |
766 |
|
i-- ) {} |
767 |
|
|
768 |
|
if( pszBasename[i] == L'.' ) |
769 |
|
pszBasename[i] = L'\0'; |
770 |
|
|
771 |
|
pszFullname = (wchar_t *) malloc(sizeof(wchar_t)*(wcslen(pszBasename) + 5)); |
772 |
|
swprintf( pszFullname, L"%s.dbf", pszBasename ); |
773 |
|
free( pszBasename ); |
774 |
|
|
775 |
|
/* -------------------------------------------------------------------- */ |
776 |
|
/* Create the file. */ |
777 |
|
/* -------------------------------------------------------------------- */ |
778 |
|
fp = _wfopen( pszFullname, L"wb" ); |
779 |
|
if( fp == NULL ) |
780 |
|
return( NULL ); |
781 |
|
|
782 |
|
fputc( 0, fp ); |
783 |
|
fclose( fp ); |
784 |
|
|
785 |
|
fp = _wfopen( pszFullname, L"rb+" ); |
786 |
|
if( fp == NULL ) |
787 |
|
return( NULL ); |
788 |
|
|
789 |
|
free( pszFullname ); |
790 |
|
|
791 |
|
return DBFCreateEx( fp ); |
792 |
|
} |
793 |
|
|
794 |
|
#endif |
795 |
|
|
796 |
|
|
797 |
|
/************************************************************************/ |
798 |
|
/* DBFCreateEx() */ |
799 |
|
/* */ |
800 |
|
/* Create a new .dbf file from a freshly created file */ |
801 |
|
/************************************************************************/ |
802 |
|
|
803 |
|
DBFHandle SHPAPI_CALL |
804 |
|
DBFCreateEx( FILE* fp ) |
805 |
|
|
806 |
|
{ |
807 |
|
DBFHandle psDBF; |
808 |
|
|
809 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
810 |
/* Create the info structure. */ |
/* Create the info structure. */ |
811 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
832 |
return( psDBF ); |
return( psDBF ); |
833 |
} |
} |
834 |
|
|
835 |
|
|
836 |
|
|
837 |
/************************************************************************/ |
/************************************************************************/ |
838 |
/* DBFAddField() */ |
/* DBFAddField() */ |
839 |
/* */ |
/* */ |
919 |
|
|
920 |
if( eType == FTString ) |
if( eType == FTString ) |
921 |
{ |
{ |
922 |
pszFInfo[16] = nWidth % 256; |
pszFInfo[16] = (unsigned char) (nWidth % 256); |
923 |
pszFInfo[17] = nWidth / 256; |
pszFInfo[17] = (unsigned char) (nWidth / 256); |
924 |
} |
} |
925 |
else |
else |
926 |
{ |
{ |
927 |
pszFInfo[16] = nWidth; |
pszFInfo[16] = (unsigned char) nWidth; |
928 |
pszFInfo[17] = nDecimals; |
pszFInfo[17] = (unsigned char) nDecimals; |
929 |
} |
} |
930 |
|
|
931 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
1015 |
/* -------------------------------------------------------------------- */ |
/* -------------------------------------------------------------------- */ |
1016 |
if( chReqType == 'N' ) |
if( chReqType == 'N' ) |
1017 |
{ |
{ |
1018 |
dDoubleField = atof(pszStringField); |
dDoubleField = (*atof_function)(pszStringField); |
1019 |
|
|
1020 |
pReturnField = &dDoubleField; |
pReturnField = &dDoubleField; |
1021 |
} |
} |
1126 |
|
|
1127 |
pszValue = DBFReadStringAttribute( psDBF, iRecord, iField ); |
pszValue = DBFReadStringAttribute( psDBF, iRecord, iField ); |
1128 |
|
|
1129 |
|
if( pszValue == NULL ) |
1130 |
|
return TRUE; |
1131 |
|
|
1132 |
switch(psDBF->pachFieldType[iField]) |
switch(psDBF->pachFieldType[iField]) |
1133 |
{ |
{ |
1134 |
case 'N': |
case 'N': |
1400 |
/* as is to the field position in the record. */ |
/* as is to the field position in the record. */ |
1401 |
/************************************************************************/ |
/************************************************************************/ |
1402 |
|
|
1403 |
int DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, |
int SHPAPI_CALL |
1404 |
|
DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField, |
1405 |
void * pValue ) |
void * pValue ) |
1406 |
|
|
1407 |
{ |
{ |
1661 |
DBFHandle newDBF; |
DBFHandle newDBF; |
1662 |
|
|
1663 |
newDBF = DBFCreate ( pszFilename ); |
newDBF = DBFCreate ( pszFilename ); |
1664 |
|
if ( newDBF == NULL ) return ( NULL ); |
1665 |
|
|
1666 |
|
DBFCloneEmptyEx( psDBF, newDBF ); |
1667 |
|
|
1668 |
|
DBFClose( newDBF ); |
1669 |
|
newDBF = DBFOpen ( pszFilename, "rb+" ); |
1670 |
|
|
1671 |
|
return ( newDBF ); |
1672 |
|
} |
1673 |
|
|
1674 |
|
|
1675 |
|
|
1676 |
|
|
1677 |
|
/************************************************************************/ |
1678 |
|
/* DBFCloneEmptyW */ |
1679 |
|
/* */ |
1680 |
|
/* Read one of the attribute fields of a record. */ |
1681 |
|
/************************************************************************/ |
1682 |
|
|
1683 |
|
#ifdef SHPAPI_HAS_WIDE |
1684 |
|
|
1685 |
|
DBFHandle SHPAPI_CALL |
1686 |
|
DBFCloneEmptyW(DBFHandle psDBF, const wchar_t * pszFilename ) |
1687 |
|
{ |
1688 |
|
DBFHandle newDBF; |
1689 |
|
|
1690 |
|
newDBF = DBFCreateW ( pszFilename ); |
1691 |
|
if ( newDBF == NULL ) return ( NULL ); |
1692 |
|
|
1693 |
|
DBFCloneEmptyEx( psDBF, newDBF ); |
1694 |
|
|
1695 |
|
DBFClose( newDBF ); |
1696 |
|
newDBF = DBFOpenW ( pszFilename, L"rb+" ); |
1697 |
|
|
1698 |
|
return ( newDBF ); |
1699 |
|
} |
1700 |
|
|
1701 |
|
#endif |
1702 |
|
|
1703 |
|
/************************************************************************/ |
1704 |
|
/* DBFCloneEmptyEx() */ |
1705 |
|
/* */ |
1706 |
|
/* Read one of the attribute fields of a record. */ |
1707 |
|
/************************************************************************/ |
1708 |
|
|
1709 |
|
void SHPAPI_CALL |
1710 |
|
DBFCloneEmptyEx(DBFHandle psDBF, DBFHandle newDBF) |
1711 |
|
{ |
1712 |
if ( newDBF == NULL ) return ( NULL ); |
if ( newDBF == NULL ) return ( NULL ); |
1713 |
|
|
1714 |
newDBF->pszHeader = (char *) malloc ( 32 * psDBF->nFields ); |
newDBF->pszHeader = (char *) malloc ( 32 * psDBF->nFields ); |
1731 |
newDBF->bUpdated = TRUE; |
newDBF->bUpdated = TRUE; |
1732 |
|
|
1733 |
DBFWriteHeader ( newDBF ); |
DBFWriteHeader ( newDBF ); |
|
DBFClose ( newDBF ); |
|
|
|
|
|
newDBF = DBFOpen ( pszFilename, "rb+" ); |
|
|
|
|
|
return ( newDBF ); |
|
1734 |
} |
} |
1735 |
|
|
1736 |
/************************************************************************/ |
/************************************************************************/ |
1767 |
|
|
1768 |
while (++i < len) |
while (++i < len) |
1769 |
if (isalpha(string[i]) && islower(string[i])) |
if (isalpha(string[i]) && islower(string[i])) |
1770 |
string[i] = toupper ((int)string[i]); |
string[i] = (char) toupper ((int)string[i]); |
1771 |
} |
} |
1772 |
|
|
1773 |
/************************************************************************/ |
/************************************************************************/ |
1800 |
} |
} |
1801 |
return(-1); |
return(-1); |
1802 |
} |
} |
|
|
|
|
/************************************************************************/ |
|
|
/* DBFCommit() */ |
|
|
/* */ |
|
|
/* Write any changes made into the file. */ |
|
|
/* */ |
|
|
/************************************************************************/ |
|
|
int SHPAPI_CALL |
|
|
DBFCommit( DBFHandle psDBF ) |
|
|
|
|
|
{ |
|
|
DBFFlushRecord( psDBF ); |
|
|
if (fflush( psDBF->fp ) == EOF) |
|
|
return FALSE; |
|
|
|
|
|
return TRUE; |
|
|
} |
|