2042 int nOldRecordLength;
2049 if (iField < 0 || iField >= psDBF->nFields)
2058 chOldType = psDBF->pachFieldType[iField];
2059 nOffset = psDBF->panFieldOffset[iField];
2060 nOldWidth = psDBF->panFieldSize[iField];
2061 nOldRecordLength = psDBF->nRecordLength;
2075 psDBF->panFieldSize[iField] = nWidth;
2076 psDBF->panFieldDecimals[iField] = nDecimals;
2077 psDBF->pachFieldType[iField] = chType;
2082 pszFInfo = psDBF->pszHeader + 32 * iField;
2084 for( i = 0; i < 32; i++ )
2087 if( (
int) strlen(pszFieldName) < 10 )
2088 strncpy( pszFInfo, pszFieldName, strlen(pszFieldName));
2090 strncpy( pszFInfo, pszFieldName, 10);
2092 pszFInfo[11] = psDBF->pachFieldType[iField];
2096 pszFInfo[16] = (
unsigned char) (nWidth % 256);
2097 pszFInfo[17] = (
unsigned char) (nWidth / 256);
2101 pszFInfo[16] = (
unsigned char) nWidth;
2102 pszFInfo[17] = (
unsigned char) nDecimals;
2108 if (nWidth != nOldWidth)
2110 for (i = iField + 1; i < psDBF->nFields; i++)
2111 psDBF->panFieldOffset[i] += nWidth - nOldWidth;
2112 psDBF->nRecordLength += nWidth - nOldWidth;
2114 psDBF->pszCurrentRecord = (
char *)
SfRealloc(psDBF->pszCurrentRecord,
2115 psDBF->nRecordLength);
2119 if ( psDBF->bNoHeader && psDBF->nRecords == 0 )
2123 psDBF->bNoHeader =
TRUE;
2126 if (nWidth < nOldWidth || (nWidth == nOldWidth && chType != chOldType))
2128 char* pszRecord = (
char *)
malloc(
sizeof(
char) * nOldRecordLength);
2129 char* pszOldField = (
char *)
malloc(
sizeof(
char) * (nOldWidth + 1));
2131 pszOldField[nOldWidth] = 0;
2134 for (iRecord = 0; iRecord < psDBF->nRecords; iRecord++)
2137 nOldRecordLength * (
SAOffset) iRecord + psDBF->nHeaderLength;
2140 psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
2141 psDBF->sHooks.FRead( pszRecord, nOldRecordLength, 1, psDBF->fp );
2143 memcpy(pszOldField, pszRecord + nOffset, nOldWidth);
2146 if (nWidth != nOldWidth)
2148 if ((chOldType ==
'N' || chOldType ==
'F') && pszOldField[0] ==
' ')
2151 memmove( pszRecord + nOffset,
2152 pszRecord + nOffset + nOldWidth - nWidth,
2155 if (nOffset + nOldWidth < nOldRecordLength)
2157 memmove( pszRecord + nOffset + nWidth,
2158 pszRecord + nOffset + nOldWidth,
2159 nOldRecordLength - (nOffset + nOldWidth));
2166 memset( pszRecord + nOffset, chFieldFill, nWidth);
2170 psDBF->nRecordLength * (
SAOffset) iRecord + psDBF->nHeaderLength;
2173 psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
2174 psDBF->sHooks.FWrite( pszRecord, psDBF->nRecordLength, 1, psDBF->fp );
2180 else if (nWidth > nOldWidth)
2182 char* pszRecord = (
char *)
malloc(
sizeof(
char) * psDBF->nRecordLength);
2183 char* pszOldField = (
char *)
malloc(
sizeof(
char) * (nOldWidth + 1));
2185 pszOldField[nOldWidth] = 0;
2188 for (iRecord = psDBF->nRecords - 1; iRecord >= 0; iRecord--)
2191 nOldRecordLength * (
SAOffset) iRecord + psDBF->nHeaderLength;
2194 psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
2195 psDBF->sHooks.FRead( pszRecord, nOldRecordLength, 1, psDBF->fp );
2197 memcpy(pszOldField, pszRecord + nOffset, nOldWidth);
2200 if (nOffset + nOldWidth < nOldRecordLength)
2202 memmove( pszRecord + nOffset + nWidth,
2203 pszRecord + nOffset + nOldWidth,
2204 nOldRecordLength - (nOffset + nOldWidth));
2210 memset( pszRecord + nOffset, chFieldFill, nWidth);
2214 if ((chOldType ==
'N' || chOldType ==
'F'))
2217 memmove( pszRecord + nOffset + nWidth - nOldWidth,
2218 pszRecord + nOffset, nOldWidth );
2219 memset( pszRecord + nOffset,
' ', nWidth - nOldWidth );
2224 memset(pszRecord + nOffset + nOldWidth,
' ', nWidth - nOldWidth);
2229 psDBF->nRecordLength * (
SAOffset) iRecord + psDBF->nHeaderLength;
2232 psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
2233 psDBF->sHooks.FWrite( pszRecord, psDBF->nRecordLength, 1, psDBF->fp );
2240 psDBF->nCurrentRecord = -1;
2241 psDBF->bCurrentRecordModified =
FALSE;
static int DBFIsValueNULL(char chType, const char *pszValue)
static void * SfRealloc(void *pMem, int nNewSize)
static char DBFGetNullCharacter(char chType)
static int DBFFlushRecord(DBFHandle psDBF)
void SHPAPI_CALL DBFUpdateHeader(DBFHandle psDBF)