2081{
2082 int i;
2083 int iRecord;
2084 int nOffset;
2085 int nOldWidth;
2086 int nOldRecordLength;
2088 char* pszFInfo;
2089 char chOldType;
2090 int bIsNULL;
2091 char chFieldFill;
2092
2093 if (iField < 0 || iField >= psDBF->
nFields)
2095
2096
2099
2101
2106
2107
2108
2109
2110 if( nWidth < 1 )
2111 return -1;
2112
2115
2116
2117
2118
2122
2123
2124
2125
2127
2129 pszFInfo[i] = '\0';
2130
2132
2134
2135 if( chType == 'C' )
2136 {
2137 pszFInfo[16] =
STATIC_CAST(
unsigned char, nWidth % 256);
2138 pszFInfo[17] =
STATIC_CAST(
unsigned char, nWidth / 256);
2139 }
2140 else
2141 {
2142 pszFInfo[16] =
STATIC_CAST(
unsigned char, nWidth);
2143 pszFInfo[17] =
STATIC_CAST(
unsigned char, nDecimals);
2144 }
2145
2146
2147
2148
2149 if (nWidth != nOldWidth)
2150 {
2151 for (i = iField + 1; i < psDBF->
nFields; i++)
2154
2157 }
2158
2159
2162
2163
2166
2167 if (nWidth < nOldWidth || (nWidth == nOldWidth && chType != chOldType))
2168 {
2170 char* pszOldField =
STATIC_CAST(
char *,
malloc(
sizeof(
char) * (nOldWidth + 1)));
2171
2172
2173 pszOldField[nOldWidth] = 0;
2174
2175
2176 for (iRecord = 0; iRecord < psDBF->
nRecords; iRecord++)
2177 {
2178 nRecordOffset =
2180
2181
2183 psDBF->
sHooks.
FRead( pszRecord, nOldRecordLength, 1, psDBF->
fp );
2184
2185 memcpy(pszOldField, pszRecord + nOffset, nOldWidth);
2187
2188 if (nWidth != nOldWidth)
2189 {
2190 if ((chOldType == 'N' || chOldType == 'F' || chOldType == 'D') && pszOldField[0] == ' ')
2191 {
2192
2193 memmove( pszRecord + nOffset,
2194 pszRecord + nOffset + nOldWidth - nWidth,
2195 nWidth );
2196 }
2197 if (nOffset + nOldWidth < nOldRecordLength)
2198 {
2199 memmove( pszRecord + nOffset + nWidth,
2200 pszRecord + nOffset + nOldWidth,
2201 nOldRecordLength - (nOffset + nOldWidth));
2202 }
2203 }
2204
2205
2206 if (bIsNULL)
2207 {
2208 memset( pszRecord + nOffset, chFieldFill, nWidth);
2209 }
2210
2211 nRecordOffset =
2213
2214
2217 }
2218
2220 {
2222
2223 nRecordOffset =
2225
2228 }
2229
2230
2233 }
2234 else if (nWidth > nOldWidth)
2235 {
2237 char* pszOldField =
STATIC_CAST(
char *,
malloc(
sizeof(
char) * (nOldWidth + 1)));
2238
2239
2240 pszOldField[nOldWidth] = 0;
2241
2242
2243 for (iRecord = psDBF->
nRecords - 1; iRecord >= 0; iRecord--)
2244 {
2245 nRecordOffset =
2247
2248
2250 psDBF->
sHooks.
FRead( pszRecord, nOldRecordLength, 1, psDBF->
fp );
2251
2252 memcpy(pszOldField, pszRecord + nOffset, nOldWidth);
2254
2255 if (nOffset + nOldWidth < nOldRecordLength)
2256 {
2257 memmove( pszRecord + nOffset + nWidth,
2258 pszRecord + nOffset + nOldWidth,
2259 nOldRecordLength - (nOffset + nOldWidth));
2260 }
2261
2262
2263 if (bIsNULL)
2264 {
2265 memset( pszRecord + nOffset, chFieldFill, nWidth);
2266 }
2267 else
2268 {
2269 if ((chOldType == 'N' || chOldType == 'F'))
2270 {
2271
2272 memmove( pszRecord + nOffset + nWidth - nOldWidth,
2273 pszRecord + nOffset, nOldWidth );
2274 memset( pszRecord + nOffset, ' ', nWidth - nOldWidth );
2275 }
2276 else
2277 {
2278
2279 memset(pszRecord + nOffset + nOldWidth, ' ', nWidth - nOldWidth);
2280 }
2281 }
2282
2283 nRecordOffset =
2285
2286
2289 }
2290
2292 {
2294
2295 nRecordOffset =
2297
2300 }
2301
2304 }
2305
2309
2311}
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)