2060{
2061 int i;
2062 int iRecord;
2063 int nOffset;
2064 int nOldWidth;
2065 int nOldRecordLength;
2067 char* pszFInfo;
2068 char chOldType;
2069 int bIsNULL;
2070 char chFieldFill;
2071
2072 if (iField < 0 || iField >= psDBF->
nFields)
2074
2075
2078
2080
2085
2086
2087
2088
2089 if( nWidth < 1 )
2090 return -1;
2091
2094
2095
2096
2097
2101
2102
2103
2104
2106
2108 pszFInfo[i] = '\0';
2109
2111
2113
2114 if( chType == 'C' )
2115 {
2116 pszFInfo[16] =
STATIC_CAST(
unsigned char, nWidth % 256);
2117 pszFInfo[17] =
STATIC_CAST(
unsigned char, nWidth / 256);
2118 }
2119 else
2120 {
2121 pszFInfo[16] =
STATIC_CAST(
unsigned char, nWidth);
2122 pszFInfo[17] =
STATIC_CAST(
unsigned char, nDecimals);
2123 }
2124
2125
2126
2127
2128 if (nWidth != nOldWidth)
2129 {
2130 for (i = iField + 1; i < psDBF->
nFields; i++)
2133
2136 }
2137
2138
2141
2142
2145
2146 if (nWidth < nOldWidth || (nWidth == nOldWidth && chType != chOldType))
2147 {
2149 char* pszOldField =
STATIC_CAST(
char *,
malloc(
sizeof(
char) * (nOldWidth + 1)));
2150
2151
2152 pszOldField[nOldWidth] = 0;
2153
2154
2155 for (iRecord = 0; iRecord < psDBF->
nRecords; iRecord++)
2156 {
2157 nRecordOffset =
2159
2160
2162 psDBF->
sHooks.
FRead( pszRecord, nOldRecordLength, 1, psDBF->
fp );
2163
2164 memcpy(pszOldField, pszRecord + nOffset, nOldWidth);
2166
2167 if (nWidth != nOldWidth)
2168 {
2169 if ((chOldType == 'N' || chOldType == 'F' || chOldType == 'D') && pszOldField[0] == ' ')
2170 {
2171
2172 memmove( pszRecord + nOffset,
2173 pszRecord + nOffset + nOldWidth - nWidth,
2174 nWidth );
2175 }
2176 if (nOffset + nOldWidth < nOldRecordLength)
2177 {
2178 memmove( pszRecord + nOffset + nWidth,
2179 pszRecord + nOffset + nOldWidth,
2180 nOldRecordLength - (nOffset + nOldWidth));
2181 }
2182 }
2183
2184
2185 if (bIsNULL)
2186 {
2187 memset( pszRecord + nOffset, chFieldFill, nWidth);
2188 }
2189
2190 nRecordOffset =
2192
2193
2196 }
2197
2199 {
2201
2202 nRecordOffset =
2204
2207 }
2208
2209
2212 }
2213 else if (nWidth > nOldWidth)
2214 {
2216 char* pszOldField =
STATIC_CAST(
char *,
malloc(
sizeof(
char) * (nOldWidth + 1)));
2217
2218
2219 pszOldField[nOldWidth] = 0;
2220
2221
2222 for (iRecord = psDBF->
nRecords - 1; iRecord >= 0; iRecord--)
2223 {
2224 nRecordOffset =
2226
2227
2229 psDBF->
sHooks.
FRead( pszRecord, nOldRecordLength, 1, psDBF->
fp );
2230
2231 memcpy(pszOldField, pszRecord + nOffset, nOldWidth);
2233
2234 if (nOffset + nOldWidth < nOldRecordLength)
2235 {
2236 memmove( pszRecord + nOffset + nWidth,
2237 pszRecord + nOffset + nOldWidth,
2238 nOldRecordLength - (nOffset + nOldWidth));
2239 }
2240
2241
2242 if (bIsNULL)
2243 {
2244 memset( pszRecord + nOffset, chFieldFill, nWidth);
2245 }
2246 else
2247 {
2248 if ((chOldType == 'N' || chOldType == 'F'))
2249 {
2250
2251 memmove( pszRecord + nOffset + nWidth - nOldWidth,
2252 pszRecord + nOffset, nOldWidth );
2253 memset( pszRecord + nOffset, ' ', nWidth - nOldWidth );
2254 }
2255 else
2256 {
2257
2258 memset(pszRecord + nOffset + nOldWidth, ' ', nWidth - nOldWidth);
2259 }
2260 }
2261
2262 nRecordOffset =
2264
2265
2268 }
2269
2271 {
2273
2274 nRecordOffset =
2276
2279 }
2280
2283 }
2284
2288
2290}
static int DBFIsValueNULL(char chType, const char *pszValue)
static void * SfRealloc(void *pMem, int nNewSize)
#define STATIC_CAST(type, x)
#define END_OF_FILE_CHARACTER
static char DBFGetNullCharacter(char chType)
static int DBFFlushRecord(DBFHandle psDBF)
void SHPAPI_CALL DBFUpdateHeader(DBFHandle psDBF)
#define XBASE_FLDNAME_LEN_WRITE
#define XBASE_FLD_MAX_WIDTH
int bCurrentRecordModified
SAOffset(* FWrite)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SAOffset(* FRead)(void *p, SAOffset size, SAOffset nmemb, SAFile file)
SAOffset(* FSeek)(SAFile file, SAOffset offset, int whence)