/ msDBFWriteAttribute() */ */ Write an attribute record to the file. */ /
| 691 | /* Write an attribute record to the file. */ |
| 692 | /************************************************************************/ |
| 693 | static int msDBFWriteAttribute(DBFHandle psDBF, int hEntity, int iField, void * pValue ) |
| 694 | { |
| 695 | unsigned int nRecordOffset; |
| 696 | int i, j; |
| 697 | uchar *pabyRec; |
| 698 | char szSField[40], szFormat[12]; |
| 699 | |
| 700 | /* -------------------------------------------------------------------- */ |
| 701 | /* Is this a valid record? */ |
| 702 | /* -------------------------------------------------------------------- */ |
| 703 | if( hEntity < 0 || hEntity > psDBF->nRecords ) |
| 704 | return( MS_FALSE ); |
| 705 | |
| 706 | if( psDBF->bNoHeader ) |
| 707 | writeHeader(psDBF); |
| 708 | |
| 709 | /* -------------------------------------------------------------------- */ |
| 710 | /* Is this a brand new record? */ |
| 711 | /* -------------------------------------------------------------------- */ |
| 712 | if( hEntity == psDBF->nRecords ) |
| 713 | { |
| 714 | flushRecord( psDBF ); |
| 715 | |
| 716 | psDBF->nRecords++; |
| 717 | for( i = 0; i < psDBF->nRecordLength; i++ ) |
| 718 | psDBF->pszCurrentRecord[i] = ' '; |
| 719 | |
| 720 | psDBF->nCurrentRecord = hEntity; |
| 721 | } |
| 722 | |
| 723 | /* -------------------------------------------------------------------- */ |
| 724 | /* Is this an existing record, but different than the last one */ |
| 725 | /* we accessed? */ |
| 726 | /* -------------------------------------------------------------------- */ |
| 727 | if( psDBF->nCurrentRecord != hEntity ) |
| 728 | { |
| 729 | flushRecord( psDBF ); |
| 730 | |
| 731 | nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength; |
| 732 | |
| 733 | safe_fseek( psDBF->fp, nRecordOffset, 0 ); |
| 734 | fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp ); |
| 735 | |
| 736 | psDBF->nCurrentRecord = hEntity; |
| 737 | } |
| 738 | |
| 739 | pabyRec = (uchar *) psDBF->pszCurrentRecord; |
| 740 | |
| 741 | /* -------------------------------------------------------------------- */ |
| 742 | /* Assign all the record fields. */ |
| 743 | /* -------------------------------------------------------------------- */ |
| 744 | switch( psDBF->pachFieldType[iField] ) { |
| 745 | case 'D': |
| 746 | case 'N': |
| 747 | case 'F': |
| 748 | if( psDBF->panFieldDecimals[iField] == 0 ) { |
| 749 | snprintf( szFormat, sizeof(szFormat), "%%%dd", psDBF->panFieldSize[iField] ); |
| 750 | snprintf(szSField, sizeof(szSField), szFormat, (int) *((double *) pValue) ); |
no test coverage detected