PostGIS  2.2.7dev-r@@SVN_REVISION@@
const char SHPAPI_CALL1* DBFGetCodePage ( DBFHandle  psDBF)

Definition at line 1795 of file dbfopen.c.

1796 {
1797  if( psDBF == NULL )
1798  return NULL;
1799  return psDBF->pszCodePage;
1800 }
1801 
1802 /************************************************************************/
1803 /* DBFDeleteField() */
1804 /* */
1805 /* Remove a field from a .dbf file */
1806 /************************************************************************/
1807 
1808 int SHPAPI_CALL
1809 DBFDeleteField(DBFHandle psDBF, int iField)
1810 {
1811  int nOldRecordLength, nOldHeaderLength;
1812  int nDeletedFieldOffset, nDeletedFieldSize;
1813  SAOffset nRecordOffset;
1814  char* pszRecord;
1815  int i, iRecord;
1816 
1817  if (iField < 0 || iField >= psDBF->nFields)
1818  return FALSE;
1819 
1820  /* make sure that everything is written in .dbf */
1821  if( !DBFFlushRecord( psDBF ) )
1822  return FALSE;
1823 
1824  /* get information about field to be deleted */
1825  nOldRecordLength = psDBF->nRecordLength;
1826  nOldHeaderLength = psDBF->nHeaderLength;
1827  nDeletedFieldOffset = psDBF->panFieldOffset[iField];
1828  nDeletedFieldSize = psDBF->panFieldSize[iField];
1829 
1830  /* update fields info */
1831  for (i = iField + 1; i < psDBF->nFields; i++)
1832  {
1833  psDBF->panFieldOffset[i-1] = psDBF->panFieldOffset[i] - nDeletedFieldSize;
1834  psDBF->panFieldSize[i-1] = psDBF->panFieldSize[i];
1835  psDBF->panFieldDecimals[i-1] = psDBF->panFieldDecimals[i];
1836  psDBF->pachFieldType[i-1] = psDBF->pachFieldType[i];
1837  }
1838 
1839  /* resize fields arrays */
1840  psDBF->nFields--;
1841 
1842  psDBF->panFieldOffset = (int *)
1843  SfRealloc( psDBF->panFieldOffset, sizeof(int) * psDBF->nFields );
1844 
1845  psDBF->panFieldSize = (int *)
1846  SfRealloc( psDBF->panFieldSize, sizeof(int) * psDBF->nFields );
1847 
1848  psDBF->panFieldDecimals = (int *)
1849  SfRealloc( psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields );
1850 
1851  psDBF->pachFieldType = (char *)
1852  SfRealloc( psDBF->pachFieldType, sizeof(char) * psDBF->nFields );
1853 
1854  /* update header information */
1855  psDBF->nHeaderLength -= 32;
1856  psDBF->nRecordLength -= nDeletedFieldSize;
1857 
1858  /* overwrite field information in header */
1859  memmove(psDBF->pszHeader + iField*32,
1860  psDBF->pszHeader + (iField+1)*32,
1861  sizeof(char) * (psDBF->nFields - iField)*32);
1862 
1863  psDBF->pszHeader = (char *) SfRealloc(psDBF->pszHeader,psDBF->nFields*32);
1864 
1865  /* update size of current record appropriately */
1866  psDBF->pszCurrentRecord = (char *) SfRealloc(psDBF->pszCurrentRecord,
1867  psDBF->nRecordLength);
1868 
1869  /* we're done if we're dealing with not yet created .dbf */
1870  if ( psDBF->bNoHeader && psDBF->nRecords == 0 )
1871  return TRUE;
1872 
1873  /* force update of header with new header and record length */
1874  psDBF->bNoHeader = TRUE;
1875  DBFUpdateHeader( psDBF );
1876 
1877  /* alloc record */
1878  pszRecord = (char *) malloc(sizeof(char) * nOldRecordLength);
1879 
1880  /* shift records to their new positions */
1881  for (iRecord = 0; iRecord < psDBF->nRecords; iRecord++)
1882  {
1883  nRecordOffset =
1884  nOldRecordLength * (SAOffset) iRecord + nOldHeaderLength;
1885 
1886  /* load record */
1887  psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
1888  psDBF->sHooks.FRead( pszRecord, nOldRecordLength, 1, psDBF->fp );
1889 
1890  nRecordOffset =
1891  psDBF->nRecordLength * (SAOffset) iRecord + psDBF->nHeaderLength;
1892 
1893  /* move record in two steps */
1894  psDBF->sHooks.FSeek( psDBF->fp, nRecordOffset, 0 );
1895  psDBF->sHooks.FWrite( pszRecord, nDeletedFieldOffset, 1, psDBF->fp );
1896  psDBF->sHooks.FWrite( pszRecord + nDeletedFieldOffset + nDeletedFieldSize,
1897  nOldRecordLength - nDeletedFieldOffset - nDeletedFieldSize,
1898  1, psDBF->fp );
1899 
1900  }
1901 
1902  /* TODO: truncate file */
1903 
1904  /* free record */
1905  free(pszRecord);
1906 
1907  psDBF->nCurrentRecord = -1;
1908  psDBF->bCurrentRecordModified = FALSE;
1909 
1910  return TRUE;
1911 }
static void * SfRealloc(void *pMem, int nNewSize)
Definition: dbfopen.c:179
unsigned long SAOffset
Definition: shapefil.h:250
static int DBFFlushRecord(DBFHandle psDBF)
Definition: dbfopen.c:258
#define SHPAPI_CALL
Definition: shapefil.h:207
#define FALSE
Definition: dbfopen.c:168
void free(void *)
void * malloc(YYSIZE_T)
#define TRUE
Definition: dbfopen.c:169
int SHPAPI_CALL DBFDeleteField(DBFHandle hDBF, int iField)
void SHPAPI_CALL DBFUpdateHeader(DBFHandle psDBF)
Definition: dbfopen.c:334