/[thuban]/branches/WIP-pyshapelib-bramz/libraries/shapelib/dbfopen.c
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/libraries/shapelib/dbfopen.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1612 by jan, Tue Aug 19 21:29:25 2003 UTC revision 2212 by bh, Mon May 17 15:47:57 2004 UTC
# Line 3  Line 3 
3   *   *
4   * Project:  Shapelib   * Project:  Shapelib
5   * Purpose:  Implementation of .dbf access API documented in dbf_api.html.   * Purpose:  Implementation of .dbf access API documented in dbf_api.html.
6   * Author:   Frank Warmerdam, [email protected]   * Author:   Frank Warmerdam, [email protected]
7   *   *
8   ******************************************************************************   ******************************************************************************
9   * Copyright (c) 1999, Frank Warmerdam   * Copyright (c) 1999, Frank Warmerdam
# Line 34  Line 34 
34   ******************************************************************************   ******************************************************************************
35   *   *
36   * $Log$   * $Log$
37   * Revision 1.1  2003/08/19 21:29:25  jan   * Revision 1.3  2004/05/17 15:47:57  bh
38   * These files have been moved here from thuban/extensions/shapelib/   * Update to newest shapelib and get rid of Thuban specific extensions,
39   * See there in the Attic for the older history.   * i.e. use the new DBFUpdateHeader instead of our DBFCommit kludge
40   *   *
41   * Revision 1.4  2002/08/22 16:00:01  bh   * * libraries/shapelib/shpopen.c: Update to version from current
42   * * extensions/shapelib/shapefil.h (DBFCommit),   * shapelib CVS.
43   * extensions/shapelib/dbfopen.c (DBFCommit): New API function to   *
44   * commit any changes made to the DBF file.   * * libraries/shapelib/shapefil.h: Update to version from current
45   *   * shapelib CVS.
46   * Revision 1.3  2002/05/07 14:09:45  bh   *
47   * * extensions/shapelib/shpopen.c, extensions/shapelib/shapefil.h,   * * libraries/shapelib/dbfopen.c: Update to version from current
48   * extensions/shapelib/dbfopen.c: Really update to the versions of   * shapelib CVS.
49   * shapelib 1.2.9. For some reason it wasn't really done on   * (DBFCommit): Effectively removed since shapelib itself has
50   * 2002-04-11.   * DBFUpdateHeader now which is better for what DBFCommit wanted to
51     * achieve.
52     * We're now using an unmodified version of dbfopen.
53     *
54     * * libraries/pyshapelib/dbflib_wrap.c, libraries/pyshapelib/dbflib.py:
55     * Update from dbflib.i
56     *
57     * * libraries/pyshapelib/dbflib.i (DBFInfo_commit): New. Implementation of
58     * the commit method.  This new indirection is necessary because we use the
59     * DBFUpdateHeader function now which is not available in shapelib <=
60     * 1.2.10
61     * (DBFFile::commit): Use DBFInfo_commit as implementation
62     * (pragma __class__): New. Kludge to remove the commit method when
63     * the DBFUpdateHeader function isn't available
64     * (_have_commit): New. Helper for the pragma kludge.
65     *
66     * * libraries/pyshapelib/setup.py (dbf_macros): New. Return the
67     * preprocessor macros needed to compile the dbflib wrapper.  Determine
68     * whether DBFUpdateHeader is available and define the right value of
69     * HAVE_UPDATE_HEADER
70     * (extensions): Use dbf_macros for the dbflibc extension
71     *
72     * * setup.py (extensions): Add the HAVE_UPDATE_HEADER macro with
73     * value '1' to the Lib.dbflibc extension.  This simply reflects the
74     * shapelib and pyshapelib updates
75     *
76     * Revision 1.53  2003/12/29 00:00:30  fwarmerdam
77     * mark DBFWriteAttributeDirectly as SHPAPI_CALL
78     *
79     * Revision 1.52  2003/07/08 15:20:03  warmerda
80     * avoid warnings about downcasting to unsigned char
81     *
82     * Revision 1.51  2003/07/08 13:50:15  warmerda
83     * DBFIsAttributeNULL check for pszValue==NULL - bug 360
84     *
85     * Revision 1.50  2003/04/21 18:58:25  warmerda
86     * ensure current record is flushed at same time as header is updated
87     *
88     * Revision 1.49  2003/04/21 18:30:37  warmerda
89     * added header write/update public methods
90     *
91     * Revision 1.48  2003/03/10 14:51:27  warmerda
92     * DBFWrite* calls now return FALSE if they have to truncate
93     *
94     * Revision 1.47  2002/11/20 03:32:22  warmerda
95     * Ensure field name in DBFGetFieldIndex() is properly terminated.
96     *
97     * Revision 1.46  2002/10/09 13:10:21  warmerda
98     * Added check that width is positive.
99     *
100     * Revision 1.45  2002/09/29 00:00:08  warmerda
101     * added FTLogical and logical attribute read/write calls
102     *
103     * Revision 1.44  2002/05/07 13:46:11  warmerda
104     * Added DBFWriteAttributeDirectly().
105     *
106     * Revision 1.43  2002/02/13 19:39:21  warmerda
107     * Fix casting issues in DBFCloneEmpty().
108     *
109     * Revision 1.42  2002/01/15 14:36:07  warmerda
110     * updated email address
111     *
112     * Revision 1.41  2002/01/15 14:31:49  warmerda
113     * compute rather than copying nHeaderLength in DBFCloneEmpty()
114     *
115     * Revision 1.40  2002/01/09 04:32:35  warmerda
116     * fixed to read correct amount of header
117     *
118     * Revision 1.39  2001/12/11 22:41:03  warmerda
119     * improve io related error checking when reading header
120     *
121     * Revision 1.38  2001/11/28 16:07:31  warmerda
122     * Cleanup to avoid compiler warnings as suggested by Richard Hash.
123   *   *
124   * Revision 1.37  2001/07/04 05:18:09  warmerda   * Revision 1.37  2001/07/04 05:18:09  warmerda
125   * do last fix properly   * do last fix properly
# Line 226  static void DBFWriteHeader(DBFHandle psD Line 298  static void DBFWriteHeader(DBFHandle psD
298    
299      abyHeader[0] = 0x03;                /* memo field? - just copying   */      abyHeader[0] = 0x03;                /* memo field? - just copying   */
300    
301      /* date updated on close, record count preset at zero */      /* write out a dummy date */
302        abyHeader[1] = 95;                  /* YY */
303        abyHeader[2] = 7;                   /* MM */
304        abyHeader[3] = 26;                  /* DD */
305    
306      abyHeader[8] = psDBF->nHeaderLength % 256;      /* record count preset at zero */
307      abyHeader[9] = psDBF->nHeaderLength / 256;  
308        abyHeader[8] = (unsigned char) (psDBF->nHeaderLength % 256);
309        abyHeader[9] = (unsigned char) (psDBF->nHeaderLength / 256);
310            
311      abyHeader[10] = psDBF->nRecordLength % 256;      abyHeader[10] = (unsigned char) (psDBF->nRecordLength % 256);
312      abyHeader[11] = psDBF->nRecordLength / 256;      abyHeader[11] = (unsigned char) (psDBF->nRecordLength / 256);
313    
314  /* -------------------------------------------------------------------- */  /* -------------------------------------------------------------------- */
315  /*      Write the initial 32 byte file header, and all the field        */  /*      Write the initial 32 byte file header, and all the field        */
# Line 278  static void DBFFlushRecord( DBFHandle ps Line 355  static void DBFFlushRecord( DBFHandle ps
355  }  }
356    
357  /************************************************************************/  /************************************************************************/
358    /*                          DBFUpdateHeader()                           */
359    /************************************************************************/
360    
361    void SHPAPI_CALL
362    DBFUpdateHeader( DBFHandle psDBF )
363    
364    {
365        unsigned char               abyFileHeader[32];
366    
367        if( psDBF->bNoHeader )
368            DBFWriteHeader( psDBF );
369    
370        DBFFlushRecord( psDBF );
371    
372        fseek( psDBF->fp, 0, 0 );
373        fread( abyFileHeader, 32, 1, psDBF->fp );
374        
375        abyFileHeader[4] = (unsigned char) (psDBF->nRecords % 256);
376        abyFileHeader[5] = (unsigned char) ((psDBF->nRecords/256) % 256);
377        abyFileHeader[6] = (unsigned char) ((psDBF->nRecords/(256*256)) % 256);
378        abyFileHeader[7] = (unsigned char) ((psDBF->nRecords/(256*256*256)) % 256);
379        
380        fseek( psDBF->fp, 0, 0 );
381        fwrite( abyFileHeader, 32, 1, psDBF->fp );
382    
383        fflush( psDBF->fp );
384    }
385    
386    /************************************************************************/
387  /*                              DBFOpen()                               */  /*                              DBFOpen()                               */
388  /*                                                                      */  /*                                                                      */
389  /*      Open a .dbf file.                                               */  /*      Open a .dbf file.                                               */
# Line 289  DBFOpen( const char * pszFilename, const Line 395  DBFOpen( const char * pszFilename, const
395  {  {
396      DBFHandle           psDBF;      DBFHandle           psDBF;
397      unsigned char               *pabyBuf;      unsigned char               *pabyBuf;
398      int                 nFields, nRecords, nHeadLen, nRecLen, iField, i;      int                 nFields, nHeadLen, nRecLen, iField, i;
399      char                *pszBasename, *pszFullname;      char                *pszBasename, *pszFullname;
400    
401  /* -------------------------------------------------------------------- */  /* -------------------------------------------------------------------- */
# Line 349  DBFOpen( const char * pszFilename, const Line 455  DBFOpen( const char * pszFilename, const
455  /*  Read Table Header info                                              */  /*  Read Table Header info                                              */
456  /* -------------------------------------------------------------------- */  /* -------------------------------------------------------------------- */
457      pabyBuf = (unsigned char *) malloc(500);      pabyBuf = (unsigned char *) malloc(500);
458      fread( pabyBuf, 32, 1, psDBF->fp );      if( fread( pabyBuf, 32, 1, psDBF->fp ) != 1 )
459        {
460            fclose( psDBF->fp );
461            free( pabyBuf );
462            free( psDBF );
463            return NULL;
464        }
465    
466      psDBF->nRecords = nRecords =      psDBF->nRecords =
467       pabyBuf[4] + pabyBuf[5]*256 + pabyBuf[6]*256*256 + pabyBuf[7]*256*256*256;       pabyBuf[4] + pabyBuf[5]*256 + pabyBuf[6]*256*256 + pabyBuf[7]*256*256*256;
468    
469      psDBF->nHeaderLength = nHeadLen = pabyBuf[8] + pabyBuf[9]*256;      psDBF->nHeaderLength = nHeadLen = pabyBuf[8] + pabyBuf[9]*256;
# Line 369  DBFOpen( const char * pszFilename, const Line 481  DBFOpen( const char * pszFilename, const
481      psDBF->pszHeader = (char *) pabyBuf;      psDBF->pszHeader = (char *) pabyBuf;
482    
483      fseek( psDBF->fp, 32, 0 );      fseek( psDBF->fp, 32, 0 );
484      fread( pabyBuf, nHeadLen, 1, psDBF->fp );      if( fread( pabyBuf, nHeadLen-32, 1, psDBF->fp ) != 1 )
485        {
486            fclose( psDBF->fp );
487            free( pabyBuf );
488            free( psDBF );
489            return NULL;
490        }
491    
492      psDBF->panFieldOffset = (int *) malloc(sizeof(int) * nFields);      psDBF->panFieldOffset = (int *) malloc(sizeof(int) * nFields);
493      psDBF->panFieldSize = (int *) malloc(sizeof(int) * nFields);      psDBF->panFieldSize = (int *) malloc(sizeof(int) * nFields);
# Line 424  DBFClose(DBFHandle psDBF) Line 542  DBFClose(DBFHandle psDBF)
542  /*      write access.                                                   */  /*      write access.                                                   */
543  /* -------------------------------------------------------------------- */  /* -------------------------------------------------------------------- */
544      if( psDBF->bUpdated )      if( psDBF->bUpdated )
545      {          DBFUpdateHeader( psDBF );
         unsigned char           abyFileHeader[32];  
   
         fseek( psDBF->fp, 0, 0 );  
         fread( abyFileHeader, 32, 1, psDBF->fp );  
   
         abyFileHeader[1] = 95;                  /* YY */  
         abyFileHeader[2] = 7;                   /* MM */  
         abyFileHeader[3] = 26;                  /* DD */  
   
         abyFileHeader[4] = psDBF->nRecords % 256;  
         abyFileHeader[5] = (psDBF->nRecords/256) % 256;  
         abyFileHeader[6] = (psDBF->nRecords/(256*256)) % 256;  
         abyFileHeader[7] = (psDBF->nRecords/(256*256*256)) % 256;  
   
         fseek( psDBF->fp, 0, 0 );  
         fwrite( abyFileHeader, 32, 1, psDBF->fp );  
     }  
546    
547  /* -------------------------------------------------------------------- */  /* -------------------------------------------------------------------- */
548  /*      Close, and free resources.                                      */  /*      Close, and free resources.                                      */
# Line 571  DBFAddField(DBFHandle psDBF, const char Line 672  DBFAddField(DBFHandle psDBF, const char
672      if( eType != FTDouble && nDecimals != 0 )      if( eType != FTDouble && nDecimals != 0 )
673          return( -1 );          return( -1 );
674    
675        if( nWidth < 1 )
676            return -1;
677    
678  /* -------------------------------------------------------------------- */  /* -------------------------------------------------------------------- */
679  /*      SfRealloc all the arrays larger to hold the additional field      */  /*      SfRealloc all the arrays larger to hold the additional field      */
680  /*      information.                                                    */  /*      information.                                                    */
# Line 597  DBFAddField(DBFHandle psDBF, const char Line 701  DBFAddField(DBFHandle psDBF, const char
701      psDBF->panFieldSize[psDBF->nFields-1] = nWidth;      psDBF->panFieldSize[psDBF->nFields-1] = nWidth;
702      psDBF->panFieldDecimals[psDBF->nFields-1] = nDecimals;      psDBF->panFieldDecimals[psDBF->nFields-1] = nDecimals;
703    
704      if( eType == FTString )      if( eType == FTLogical )
705            psDBF->pachFieldType[psDBF->nFields-1] = 'L';
706        else if( eType == FTString )
707          psDBF->pachFieldType[psDBF->nFields-1] = 'C';          psDBF->pachFieldType[psDBF->nFields-1] = 'C';
708      else      else
709          psDBF->pachFieldType[psDBF->nFields-1] = 'N';          psDBF->pachFieldType[psDBF->nFields-1] = 'N';
# Line 624  DBFAddField(DBFHandle psDBF, const char Line 730  DBFAddField(DBFHandle psDBF, const char
730    
731      if( eType == FTString )      if( eType == FTString )
732      {      {
733          pszFInfo[16] = nWidth % 256;          pszFInfo[16] = (unsigned char) (nWidth % 256);
734          pszFInfo[17] = nWidth / 256;          pszFInfo[17] = (unsigned char) (nWidth / 256);
735      }      }
736      else      else
737      {      {
738          pszFInfo[16] = nWidth;          pszFInfo[16] = (unsigned char) nWidth;
739          pszFInfo[17] = nDecimals;          pszFInfo[17] = (unsigned char) nDecimals;
740      }      }
741            
742  /* -------------------------------------------------------------------- */  /* -------------------------------------------------------------------- */
# Line 803  DBFReadStringAttribute( DBFHandle psDBF, Line 909  DBFReadStringAttribute( DBFHandle psDBF,
909  }  }
910    
911  /************************************************************************/  /************************************************************************/
912    /*                        DBFReadLogicalAttribute()                     */
913    /*                                                                      */
914    /*      Read a logical attribute.                                       */
915    /************************************************************************/
916    
917    const char SHPAPI_CALL1(*)
918    DBFReadLogicalAttribute( DBFHandle psDBF, int iRecord, int iField )
919    
920    {
921        return( (const char *) DBFReadAttribute( psDBF, iRecord, iField, 'L' ) );
922    }
923    
924    /************************************************************************/
925  /*                         DBFIsAttributeNULL()                         */  /*                         DBFIsAttributeNULL()                         */
926  /*                                                                      */  /*                                                                      */
927  /*      Return TRUE if value for field is NULL.                         */  /*      Return TRUE if value for field is NULL.                         */
# Line 818  DBFIsAttributeNULL( DBFHandle psDBF, int Line 937  DBFIsAttributeNULL( DBFHandle psDBF, int
937    
938      pszValue = DBFReadStringAttribute( psDBF, iRecord, iField );      pszValue = DBFReadStringAttribute( psDBF, iRecord, iField );
939    
940        if( pszValue == NULL )
941            return TRUE;
942    
943      switch(psDBF->pachFieldType[iField])      switch(psDBF->pachFieldType[iField])
944      {      {
945        case 'N':        case 'N':
# Line 837  DBFIsAttributeNULL( DBFHandle psDBF, int Line 959  DBFIsAttributeNULL( DBFHandle psDBF, int
959          /* empty string fields are considered NULL */          /* empty string fields are considered NULL */
960          return strlen(pszValue) == 0;          return strlen(pszValue) == 0;
961      }      }
     return FALSE;  
962  }  }
963    
964  /************************************************************************/  /************************************************************************/
# Line 896  DBFGetFieldInfo( DBFHandle psDBF, int iF Line 1017  DBFGetFieldInfo( DBFHandle psDBF, int iF
1017              pszFieldName[i] = '\0';              pszFieldName[i] = '\0';
1018      }      }
1019    
1020      if( psDBF->pachFieldType[iField] == 'N'      if ( psDBF->pachFieldType[iField] == 'L' )
1021          || psDBF->pachFieldType[iField] == 'F'          return( FTLogical);
1022          || psDBF->pachFieldType[iField] == 'D' )  
1023        else if( psDBF->pachFieldType[iField] == 'N'
1024                 || psDBF->pachFieldType[iField] == 'F'
1025                 || psDBF->pachFieldType[iField] == 'D' )
1026      {      {
1027          if( psDBF->panFieldDecimals[iField] > 0 )          if( psDBF->panFieldDecimals[iField] > 0 )
1028              return( FTDouble );              return( FTDouble );
# Line 921  static int DBFWriteAttribute(DBFHandle p Line 1045  static int DBFWriteAttribute(DBFHandle p
1045                               void * pValue )                               void * pValue )
1046    
1047  {  {
1048      int         nRecordOffset, i, j;      int         nRecordOffset, i, j, nRetResult = TRUE;
1049      unsigned char       *pabyRec;      unsigned char       *pabyRec;
1050      char        szSField[400], szFormat[20];      char        szSField[400], szFormat[20];
1051    
# Line 1024  static int DBFWriteAttribute(DBFHandle p Line 1148  static int DBFWriteAttribute(DBFHandle p
1148              sprintf( szFormat, "%%%dd", nWidth );              sprintf( szFormat, "%%%dd", nWidth );
1149              sprintf(szSField, szFormat, (int) *((double *) pValue) );              sprintf(szSField, szFormat, (int) *((double *) pValue) );
1150              if( (int)strlen(szSField) > psDBF->panFieldSize[iField] )              if( (int)strlen(szSField) > psDBF->panFieldSize[iField] )
1151                {
1152                  szSField[psDBF->panFieldSize[iField]] = '\0';                  szSField[psDBF->panFieldSize[iField]] = '\0';
1153                    nRetResult = FALSE;
1154                }
1155    
1156              strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),              strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1157                      szSField, strlen(szSField) );                      szSField, strlen(szSField) );
# Line 1040  static int DBFWriteAttribute(DBFHandle p Line 1167  static int DBFWriteAttribute(DBFHandle p
1167                       nWidth, psDBF->panFieldDecimals[iField] );                       nWidth, psDBF->panFieldDecimals[iField] );
1168              sprintf(szSField, szFormat, *((double *) pValue) );              sprintf(szSField, szFormat, *((double *) pValue) );
1169              if( (int) strlen(szSField) > psDBF->panFieldSize[iField] )              if( (int) strlen(szSField) > psDBF->panFieldSize[iField] )
1170                {
1171                  szSField[psDBF->panFieldSize[iField]] = '\0';                  szSField[psDBF->panFieldSize[iField]] = '\0';
1172                    nRetResult = FALSE;
1173                }
1174              strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),              strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1175                      szSField, strlen(szSField) );                      szSField, strlen(szSField) );
1176          }          }
1177          break;          break;
1178    
1179          case 'L':
1180            if (psDBF->panFieldSize[iField] >= 1  &&
1181                (*(char*)pValue == 'F' || *(char*)pValue == 'T'))
1182                *(pabyRec+psDBF->panFieldOffset[iField]) = *(char*)pValue;
1183            break;
1184    
1185        default:        default:
1186          if( (int) strlen((char *) pValue) > psDBF->panFieldSize[iField] )          if( (int) strlen((char *) pValue) > psDBF->panFieldSize[iField] )
1187            {
1188              j = psDBF->panFieldSize[iField];              j = psDBF->panFieldSize[iField];
1189                nRetResult = FALSE;
1190            }
1191          else          else
1192          {          {
1193              memset( pabyRec+psDBF->panFieldOffset[iField], ' ',              memset( pabyRec+psDBF->panFieldOffset[iField], ' ',
# Line 1061  static int DBFWriteAttribute(DBFHandle p Line 1200  static int DBFWriteAttribute(DBFHandle p
1200          break;          break;
1201      }      }
1202    
1203        return( nRetResult );
1204    }
1205    
1206    /************************************************************************/
1207    /*                     DBFWriteAttributeDirectly()                      */
1208    /*                                                                      */
1209    /*      Write an attribute record to the file, but without any          */
1210    /*      reformatting based on type.  The provided buffer is written     */
1211    /*      as is to the field position in the record.                      */
1212    /************************************************************************/
1213    
1214    int SHPAPI_CALL
1215    DBFWriteAttributeDirectly(DBFHandle psDBF, int hEntity, int iField,
1216                                  void * pValue )
1217    
1218    {
1219        int         nRecordOffset, i, j;
1220        unsigned char       *pabyRec;
1221    
1222    /* -------------------------------------------------------------------- */
1223    /*      Is this a valid record?                                         */
1224    /* -------------------------------------------------------------------- */
1225        if( hEntity < 0 || hEntity > psDBF->nRecords )
1226            return( FALSE );
1227    
1228        if( psDBF->bNoHeader )
1229            DBFWriteHeader(psDBF);
1230    
1231    /* -------------------------------------------------------------------- */
1232    /*      Is this a brand new record?                                     */
1233    /* -------------------------------------------------------------------- */
1234        if( hEntity == psDBF->nRecords )
1235        {
1236            DBFFlushRecord( psDBF );
1237    
1238            psDBF->nRecords++;
1239            for( i = 0; i < psDBF->nRecordLength; i++ )
1240                psDBF->pszCurrentRecord[i] = ' ';
1241    
1242            psDBF->nCurrentRecord = hEntity;
1243        }
1244    
1245    /* -------------------------------------------------------------------- */
1246    /*      Is this an existing record, but different than the last one     */
1247    /*      we accessed?                                                    */
1248    /* -------------------------------------------------------------------- */
1249        if( psDBF->nCurrentRecord != hEntity )
1250        {
1251            DBFFlushRecord( psDBF );
1252    
1253            nRecordOffset = psDBF->nRecordLength * hEntity + psDBF->nHeaderLength;
1254    
1255            fseek( psDBF->fp, nRecordOffset, 0 );
1256            fread( psDBF->pszCurrentRecord, psDBF->nRecordLength, 1, psDBF->fp );
1257    
1258            psDBF->nCurrentRecord = hEntity;
1259        }
1260    
1261        pabyRec = (unsigned char *) psDBF->pszCurrentRecord;
1262    
1263    /* -------------------------------------------------------------------- */
1264    /*      Assign all the record fields.                                   */
1265    /* -------------------------------------------------------------------- */
1266        if( (int)strlen((char *) pValue) > psDBF->panFieldSize[iField] )
1267            j = psDBF->panFieldSize[iField];
1268        else
1269        {
1270            memset( pabyRec+psDBF->panFieldOffset[iField], ' ',
1271                    psDBF->panFieldSize[iField] );
1272            j = strlen((char *) pValue);
1273        }
1274    
1275        strncpy((char *) (pabyRec+psDBF->panFieldOffset[iField]),
1276                (char *) pValue, j );
1277    
1278        psDBF->bCurrentRecordModified = TRUE;
1279        psDBF->bUpdated = TRUE;
1280    
1281      return( TRUE );      return( TRUE );
1282  }  }
1283    
# Line 1122  DBFWriteNULLAttribute( DBFHandle psDBF, Line 1339  DBFWriteNULLAttribute( DBFHandle psDBF,
1339  }  }
1340    
1341  /************************************************************************/  /************************************************************************/
1342    /*                      DBFWriteLogicalAttribute()                      */
1343    /*                                                                      */
1344    /*      Write a logical attribute.                                      */
1345    /************************************************************************/
1346    
1347    int SHPAPI_CALL
1348    DBFWriteLogicalAttribute( DBFHandle psDBF, int iRecord, int iField,
1349                           const char lValue)
1350    
1351    {
1352        return( DBFWriteAttribute( psDBF, iRecord, iField, (void *) (&lValue) ) );
1353    }
1354    
1355    /************************************************************************/
1356  /*                         DBFWriteTuple()                              */  /*                         DBFWriteTuple()                              */
1357  /*                                                                      */  /*                                                                      */
1358  /*      Write an attribute record to the file.                          */  /*      Write an attribute record to the file.                          */
# Line 1243  DBFCloneEmpty(DBFHandle psDBF, const cha Line 1474  DBFCloneEmpty(DBFHandle psDBF, const cha
1474     newDBF = DBFCreate ( pszFilename );     newDBF = DBFCreate ( pszFilename );
1475     if ( newDBF == NULL ) return ( NULL );     if ( newDBF == NULL ) return ( NULL );
1476        
1477     newDBF->pszHeader = (void *) malloc ( 32 * psDBF->nFields );     newDBF->pszHeader = (char *) malloc ( 32 * psDBF->nFields );
1478     memcpy ( newDBF->pszHeader, psDBF->pszHeader, 32 * psDBF->nFields );     memcpy ( newDBF->pszHeader, psDBF->pszHeader, 32 * psDBF->nFields );
1479        
1480     newDBF->nFields = psDBF->nFields;     newDBF->nFields = psDBF->nFields;
1481     newDBF->nRecordLength = psDBF->nRecordLength;     newDBF->nRecordLength = psDBF->nRecordLength;
1482     newDBF->nHeaderLength = psDBF->nHeaderLength;     newDBF->nHeaderLength = 32 * (psDBF->nFields+1);
1483            
1484     newDBF->panFieldOffset = (void *) malloc ( sizeof(int) * psDBF->nFields );     newDBF->panFieldOffset = (int *) malloc ( sizeof(int) * psDBF->nFields );
1485     memcpy ( newDBF->panFieldOffset, psDBF->panFieldOffset, sizeof(int) * psDBF->nFields );     memcpy ( newDBF->panFieldOffset, psDBF->panFieldOffset, sizeof(int) * psDBF->nFields );
1486     newDBF->panFieldSize = (void *) malloc ( sizeof(int) * psDBF->nFields );     newDBF->panFieldSize = (int *) malloc ( sizeof(int) * psDBF->nFields );
1487     memcpy ( newDBF->panFieldSize, psDBF->panFieldSize, sizeof(int) * psDBF->nFields );     memcpy ( newDBF->panFieldSize, psDBF->panFieldSize, sizeof(int) * psDBF->nFields );
1488     newDBF->panFieldDecimals = (void *) malloc ( sizeof(int) * psDBF->nFields );     newDBF->panFieldDecimals = (int *) malloc ( sizeof(int) * psDBF->nFields );
1489     memcpy ( newDBF->panFieldDecimals, psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields );     memcpy ( newDBF->panFieldDecimals, psDBF->panFieldDecimals, sizeof(int) * psDBF->nFields );
1490     newDBF->pachFieldType = (void *) malloc ( sizeof(int) * psDBF->nFields );     newDBF->pachFieldType = (char *) malloc ( sizeof(int) * psDBF->nFields );
1491     memcpy ( newDBF->pachFieldType, psDBF->pachFieldType, sizeof(int) * psDBF->nFields );     memcpy ( newDBF->pachFieldType, psDBF->pachFieldType, sizeof(int) * psDBF->nFields );
1492    
1493     newDBF->bNoHeader = TRUE;     newDBF->bNoHeader = TRUE;
# Line 1304  static void str_to_upper (char *string) Line 1535  static void str_to_upper (char *string)
1535    
1536      while (++i < len)      while (++i < len)
1537          if (isalpha(string[i]) && islower(string[i]))          if (isalpha(string[i]) && islower(string[i]))
1538              string[i] = toupper ((int)string[i]);              string[i] = (char) toupper ((int)string[i]);
1539  }  }
1540    
1541  /************************************************************************/  /************************************************************************/
# Line 1323  DBFGetFieldIndex(DBFHandle psDBF, const Line 1554  DBFGetFieldIndex(DBFHandle psDBF, const
1554      int           i;      int           i;
1555    
1556      strncpy(name1, pszFieldName,11);      strncpy(name1, pszFieldName,11);
1557        name1[11] = '\0';
1558      str_to_upper(name1);      str_to_upper(name1);
1559    
1560      for( i = 0; i < DBFGetFieldCount(psDBF); i++ )      for( i = 0; i < DBFGetFieldCount(psDBF); i++ )
# Line 1336  DBFGetFieldIndex(DBFHandle psDBF, const Line 1568  DBFGetFieldIndex(DBFHandle psDBF, const
1568      }      }
1569      return(-1);      return(-1);
1570  }  }
   
 /************************************************************************/  
 /*                          DBFCommit()                                 */  
 /*                                                                      */  
 /*      Write any changes made into the file.                           */  
 /*                                                                      */  
 /************************************************************************/  
 int SHPAPI_CALL  
 DBFCommit( DBFHandle psDBF )  
   
 {  
     DBFFlushRecord( psDBF );  
     if (fflush( psDBF->fp ) == EOF)  
         return FALSE;  
   
     return TRUE;  
 }  

Legend:
Removed from v.1612  
changed lines
  Added in v.2212

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26