1971 int nOldRecordLength;
1978 if (iField < 0 || iField >= psDBF->nFields)
1987 chOldType = psDBF->pachFieldType[iField];
1988 nOffset = psDBF->panFieldOffset[iField];
1989 nOldWidth = psDBF->panFieldSize[iField];
1990 nOldRecordLength = psDBF->nRecordLength;
2004 psDBF->panFieldSize[iField] = nWidth;
2005 psDBF->panFieldDecimals[iField] = nDecimals;
2006 psDBF->pachFieldType[iField] = chType;
2011 pszFInfo = psDBF->pszHeader + 32 * iField;
2013 for (i = 0; i < 32; i++)
2016 snprintf(pszFInfo, 10,
"%s", pszFieldName);
2018 pszFInfo[11] = psDBF->pachFieldType[iField];
2022 pszFInfo[16] = (
unsigned char)(nWidth % 256);
2023 pszFInfo[17] = (
unsigned char)(nWidth / 256);
2027 pszFInfo[16] = (
unsigned char)nWidth;
2028 pszFInfo[17] = (
unsigned char)nDecimals;
2034 if (nWidth != nOldWidth)
2036 for (i = iField + 1; i < psDBF->nFields; i++)
2037 psDBF->panFieldOffset[i] += nWidth - nOldWidth;
2038 psDBF->nRecordLength += nWidth - nOldWidth;
2040 psDBF->pszCurrentRecord = (
char *)
SfRealloc(psDBF->pszCurrentRecord, psDBF->nRecordLength);
2044 if (psDBF->bNoHeader && psDBF->nRecords == 0)
2048 psDBF->bNoHeader =
TRUE;
2051 if (nWidth < nOldWidth || (nWidth == nOldWidth && chType != chOldType))
2053 char *pszRecord = (
char *)
malloc(
sizeof(
char) * nOldRecordLength);
2054 char *pszOldField = (
char *)
malloc(
sizeof(
char) * (nOldWidth + 1));
2056 pszOldField[nOldWidth] = 0;
2059 for (iRecord = 0; iRecord < psDBF->nRecords; iRecord++)
2061 nRecordOffset = nOldRecordLength * (
SAOffset)iRecord + psDBF->nHeaderLength;
2064 psDBF->sHooks.FSeek(psDBF->fp, nRecordOffset, 0);
2065 psDBF->sHooks.FRead(pszRecord, nOldRecordLength, 1, psDBF->fp);
2067 memcpy(pszOldField, pszRecord + nOffset, nOldWidth);
2070 if (nWidth != nOldWidth)
2072 if ((chOldType ==
'N' || chOldType ==
'F') && pszOldField[0] ==
' ')
2075 memmove(pszRecord + nOffset, pszRecord + nOffset + nOldWidth - nWidth, nWidth);
2077 if (nOffset + nOldWidth < nOldRecordLength)
2079 memmove(pszRecord + nOffset + nWidth,
2080 pszRecord + nOffset + nOldWidth,
2081 nOldRecordLength - (nOffset + nOldWidth));
2088 memset(pszRecord + nOffset, chFieldFill, nWidth);
2091 nRecordOffset = psDBF->nRecordLength * (
SAOffset)iRecord + psDBF->nHeaderLength;
2094 psDBF->sHooks.FSeek(psDBF->fp, nRecordOffset, 0);
2095 psDBF->sHooks.FWrite(pszRecord, psDBF->nRecordLength, 1, psDBF->fp);
2101 else if (nWidth > nOldWidth)
2103 char *pszRecord = (
char *)
malloc(
sizeof(
char) * psDBF->nRecordLength);
2104 char *pszOldField = (
char *)
malloc(
sizeof(
char) * (nOldWidth + 1));
2106 pszOldField[nOldWidth] = 0;
2109 for (iRecord = psDBF->nRecords - 1; iRecord >= 0; iRecord--)
2111 nRecordOffset = nOldRecordLength * (
SAOffset)iRecord + psDBF->nHeaderLength;
2114 psDBF->sHooks.FSeek(psDBF->fp, nRecordOffset, 0);
2115 psDBF->sHooks.FRead(pszRecord, nOldRecordLength, 1, psDBF->fp);
2117 memcpy(pszOldField, pszRecord + nOffset, nOldWidth);
2120 if (nOffset + nOldWidth < nOldRecordLength)
2122 memmove(pszRecord + nOffset + nWidth,
2123 pszRecord + nOffset + nOldWidth,
2124 nOldRecordLength - (nOffset + nOldWidth));
2130 memset(pszRecord + nOffset, chFieldFill, nWidth);
2134 if ((chOldType ==
'N' || chOldType ==
'F'))
2138 pszRecord + nOffset + nWidth - nOldWidth, pszRecord + nOffset, nOldWidth);
2139 memset(pszRecord + nOffset,
' ', nWidth - nOldWidth);
2144 memset(pszRecord + nOffset + nOldWidth,
' ', nWidth - nOldWidth);
2148 nRecordOffset = psDBF->nRecordLength * (
SAOffset)iRecord + psDBF->nHeaderLength;
2151 psDBF->sHooks.FSeek(psDBF->fp, nRecordOffset, 0);
2152 psDBF->sHooks.FWrite(pszRecord, psDBF->nRecordLength, 1, psDBF->fp);
2159 psDBF->nCurrentRecord = -1;
2160 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)