/gdal-1.6.1-tcl_patched/ogr/ogrsf_frmts/geoconcept/geoconcept.c
C | 2086 lines | 1874 code | 92 blank | 120 comment | 335 complexity | 1419c9356c9df4d522c7f3744520222e MD5 | raw file
Possible License(s): LGPL-2.0, GPL-3.0, BSD-3-Clause, LGPL-3.0
Large files files are truncated, but you can click here to view the full file
- /**********************************************************************
- * $Id: geoconcept.c
- *
- * Name: geoconcept.c
- * Project: OpenGIS Simple Features Reference Implementation
- * Purpose: Implements Physical Access class.
- * Language: C
- *
- **********************************************************************
- * Copyright (c) 2007, Geoconcept and IGN
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- **********************************************************************/
- #include <math.h>
- #include "geoconcept.h"
- #include "cpl_conv.h"
- #include "cpl_string.h"
- #include "ogr_core.h"
- GCIO_CVSID("$Id: geoconcept.c,v 1.0.0 2007-11-03 20:58:19 drichard Exp $")
- #define kItemSize_GCIO 256
- #define kExtraSize_GCIO 4096
- #define kIdSize_GCIO 12
- #define UNDEFINEDID_GCIO 199901L
- static char* gkGCCharset[]=
- {
- /* 0 */ "",
- /* 1 */ "ANSI",
- /* 2 */ "DOS",
- /* 3 */ "MAC"
- };
- static char* gkGCAccess[]=
- {
- /* 0 */ "",
- /* 1 */ "NO",
- /* 2 */ "READ",
- /* 3 */ "UPDATE",
- /* 4 */ "WRITE"
- };
- static char* gkGCStatus[]=
- {
- /* 0 */ "NONE",
- /* 1 */ "MEMO",
- /* 2 */ "EOF"
- };
- static char* gk3D[]=
- {
- /* 0 */ "",
- /* 1 */ "2D",
- /* 2 */ "3DM",
- /* 3 */ "3D"
- };
- static char* gkGCTypeKind[]=
- {
- /* 0 */ "",
- /* 1 */ "POINT",
- /* 2 */ "LINE",
- /* 3 */ "TEXT",
- /* 4 */ "POLYGON",
- /* 5 */ "MEMO",
- /* 6 */ "INT",
- /* 7 */ "REAL",
- /* 8 */ "LENGTH",
- /* 9 */ "AREA",
- /*10 */ "POSITION",
- /*11 */ "DATE",
- /*12 */ "TIME",
- /*13 */ "CHOICE",
- /*14 */ "MEMO"
- };
- /* -------------------------------------------------------------------- */
- /* GCIO API Prototypes */
- /* -------------------------------------------------------------------- */
- /* -------------------------------------------------------------------- */
- static char GCIOAPI_CALL1(*) _getHeaderValue_GCIO ( const char *s )
- {
- char *b, *e;
- if( (b= strchr(s,'='))==NULL ) return NULL;
- b++;
- while (isspace(*b)) b++;
- e= b;
- while (*e!='\0' && !isspace(*e)) e++;
- *e= '\0';
- return b;
- }/* _getHeaderValue_GCIO */
- /* -------------------------------------------------------------------- */
- const char GCIOAPI_CALL1(*) GCCharset2str_GCIO ( GCCharset cs )
- {
- switch (cs) {
- case vANSI_GCIO :
- case vDOS_GCIO :
- case vMAC_GCIO :
- case vWriteAccess_GCIO :
- return gkGCCharset[cs];
- default :
- return gkGCCharset[vUnknownCharset_GCIO];
- }
- }/* GCCharset2str_GCIO */
- /* -------------------------------------------------------------------- */
- GCCharset GCIOAPI_CALL str2GCCharset_GCIO ( const char* s)
- {
- if (strcmp(s,gkGCCharset[vANSI_GCIO])==0) return vANSI_GCIO;
- if (strcmp(s,gkGCCharset[vDOS_GCIO])==0) return vDOS_GCIO;
- if (strcmp(s,gkGCCharset[vMAC_GCIO])==0) return vMAC_GCIO;
- return vUnknownCharset_GCIO;
- }/* str2GCCharset_GCIO */
- /* -------------------------------------------------------------------- */
- const char GCIOAPI_CALL1(*) GCAccessMode2str_GCIO ( GCAccessMode mode )
- {
- switch (mode) {
- case vNoAccess_GCIO :
- case vReadAccess_GCIO :
- case vUpdateAccess_GCIO :
- case vWriteAccess_GCIO :
- return gkGCAccess[mode];
- default :
- return gkGCAccess[vUnknownAccessMode_GCIO];
- }
- }/* GCAccessMode2str_GCIO */
- /* -------------------------------------------------------------------- */
- GCAccessMode GCIOAPI_CALL str2GCAccessMode_GCIO ( const char* s)
- {
- if (strcmp(s,gkGCAccess[vNoAccess_GCIO])==0) return vNoAccess_GCIO;
- if (strcmp(s,gkGCAccess[vReadAccess_GCIO])==0) return vReadAccess_GCIO;
- if (strcmp(s,gkGCAccess[vUpdateAccess_GCIO])==0) return vUpdateAccess_GCIO;
- if (strcmp(s,gkGCAccess[vWriteAccess_GCIO])==0) return vWriteAccess_GCIO;
- return vUnknownAccessMode_GCIO;
- }/* str2GCAccessMode_GCIO */
- /* -------------------------------------------------------------------- */
- const char GCIOAPI_CALL1(*) GCAccessStatus2str_GCIO ( GCAccessStatus stts )
- {
- switch (stts) {
- case vMemoStatus_GCIO :
- case vEof_GCIO :
- return gkGCStatus[stts];
- default :
- return gkGCStatus[vNoStatus_GCIO];
- }
- }/* GCAccessStatus2str_GCIO */
- /* -------------------------------------------------------------------- */
- GCAccessStatus GCIOAPI_CALL str2GCAccessStatus_GCIO ( const char* s)
- {
- if (strcmp(s,gkGCStatus[vMemoStatus_GCIO])==0) return vMemoStatus_GCIO;
- if (strcmp(s,gkGCStatus[vEof_GCIO])==0) return vEof_GCIO;
- return vNoStatus_GCIO;
- }/* str2GCAccessStatus_GCIO */
- /* -------------------------------------------------------------------- */
- const char GCIOAPI_CALL1(*) GCDim2str_GCIO ( GCDim sys )
- {
- switch (sys) {
- case v2D_GCIO :
- case v3D_GCIO :
- case v3DM_GCIO :
- return gk3D[sys];
- default :
- return gk3D[vUnknown3D_GCIO];
- }
- }/* GCDim2str_GCIO */
- /* -------------------------------------------------------------------- */
- GCDim GCIOAPI_CALL str2GCDim ( const char* s )
- {
- if (strcmp(s,gk3D[v2D_GCIO])==0) return v2D_GCIO;
- if (strcmp(s,gk3D[v3D_GCIO])==0) return v3D_GCIO;
- if (strcmp(s,gk3D[v3DM_GCIO])==0) return v3DM_GCIO;
- return vUnknown3D_GCIO;
- }/* str2GCDim */
- /* -------------------------------------------------------------------- */
- const char GCIOAPI_CALL1(*) GCTypeKind2str_GCIO ( GCTypeKind item )
- {
- switch (item) {
- case vPoint_GCIO :
- case vLine_GCIO :
- case vText_GCIO :
- case vPoly_GCIO :
- case vMemoFld_GCIO :
- case vIntFld_GCIO :
- case vRealFld_GCIO :
- case vLengthFld_GCIO :
- case vAreaFld_GCIO :
- case vPositionFld_GCIO :
- case vDateFld_GCIO :
- case vTimeFld_GCIO :
- case vChoiceFld_GCIO :
- case vInterFld_GCIO :
- return gkGCTypeKind[item];
- default :
- return gkGCTypeKind[vUnknownItemType_GCIO];
- }
- }/* GCTypeKind2str_GCIO */
- /* -------------------------------------------------------------------- */
- GCTypeKind GCIOAPI_CALL str2GCTypeKind_GCIO ( const char *s )
- {
- if (strcmp(s,gkGCTypeKind[vPoint_GCIO])==0) return vPoint_GCIO;
- if (strcmp(s,gkGCTypeKind[vLine_GCIO])==0) return vLine_GCIO;
- if (strcmp(s,gkGCTypeKind[vText_GCIO])==0) return vText_GCIO;
- if (strcmp(s,gkGCTypeKind[vPoly_GCIO])==0) return vPoly_GCIO;
- if (strcmp(s,gkGCTypeKind[vMemoFld_GCIO])==0) return vMemoFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vIntFld_GCIO])==0) return vIntFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vRealFld_GCIO])==0) return vRealFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vLengthFld_GCIO])==0) return vLengthFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vAreaFld_GCIO])==0) return vAreaFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vPositionFld_GCIO])==0) return vPositionFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vDateFld_GCIO])==0) return vDateFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vTimeFld_GCIO])==0) return vTimeFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vChoiceFld_GCIO])==0) return vChoiceFld_GCIO;
- if (strcmp(s,gkGCTypeKind[vInterFld_GCIO])==0) return vInterFld_GCIO;
- return vUnknownItemType_GCIO;
- }/* str2GCTypeKind_GCIO */
- /* -------------------------------------------------------------------- */
- static const char GCIOAPI_CALL1(*) _metaDelimiter2str_GCIO ( char delim )
- {
- switch( delim ) {
- case '\t' :
- return "tab";
- default :
- return "\t";
- }
- }/* _metaDelimiter2str_GCIO */
- /* -------------------------------------------------------------------- */
- static long GCIOAPI_CALL _read_GCIO (
- GCExportFileH* hGXT
- )
- {
- FILE* h;
- long nread;
- int c;
- char *result;
- h= GetGCHandle_GCIO(hGXT);
- nread= 0L;
- result= GetGCCache_GCIO(hGXT);
- SetGCCurrentOffset_GCIO(hGXT, VSIFTell(h));/* keep offset of beginning of lines */
- while ((c= VSIFGetc(h))!=EOF)
- {
- c= (0x00FF & (unsigned char)(c));
- switch (c) {
- case 0X1A : continue ; /* PC end-of-file */
- case '\r' : /* PC '\r\n' line, MAC '\r' */
- if ((c= VSIFGetc(h))!='\n')
- {
- VSIUngetc(c,h);
- c= '\n';
- }
- case '\n' :
- SetGCCurrentLinenum_GCIO(hGXT,GetGCCurrentLinenum_GCIO(hGXT)+1L);
- if (nread==0L) continue;
- *result= '\0';
- return nread;
- default :
- *result= (char)c;
- result++;
- nread++;
- if (nread == kCacheSize_GCIO)
- {
- CPLError( CE_Failure, CPLE_OutOfMemory,
- "Too many characters at line %lu.\n", GetGCCurrentLinenum_GCIO(hGXT));
- return EOF;
- }
- }/* switch */
- }/* while */
- *result= '\0';
- if (c==EOF)
- {
- SetGCStatus_GCIO(hGXT, vEof_GCIO);
- if (nread==0L)
- {
- return EOF;
- }
- }
- return nread;
- }/* _read_GCIO */
- /* -------------------------------------------------------------------- */
- static long GCIOAPI_CALL _get_GCIO (
- GCExportFileH* hGXT
- )
- {
- if (GetGCStatus_GCIO(hGXT)==vEof_GCIO)
- {
- SetGCCache_GCIO(hGXT,"");
- SetGCWhatIs_GCIO(hGXT, vUnknownIO_ItemType_GCIO);
- return EOF;
- }
- if (GetGCStatus_GCIO(hGXT)==vMemoStatus_GCIO)
- {
- SetGCStatus_GCIO(hGXT, vNoStatus_GCIO);
- return GetGCCurrentOffset_GCIO(hGXT);
- }
- if (_read_GCIO(hGXT)==EOF)
- {
- SetGCWhatIs_GCIO(hGXT, vUnknownIO_ItemType_GCIO);
- return EOF;
- }
- SetGCWhatIs_GCIO(hGXT, vStdCol_GCIO);
- if (strstr(GetGCCache_GCIO(hGXT),kCom_GCIO)==GetGCCache_GCIO(hGXT))
- { /* // */
- SetGCWhatIs_GCIO(hGXT, vComType_GCIO);
- if (strstr(GetGCCache_GCIO(hGXT),kHeader_GCIO)==GetGCCache_GCIO(hGXT))
- { /* //# */
- SetGCWhatIs_GCIO(hGXT, vHeader_GCIO);
- }
- else
- {
- if (strstr(GetGCCache_GCIO(hGXT),kPragma_GCIO)==GetGCCache_GCIO(hGXT))
- { /* //$ */
- SetGCWhatIs_GCIO(hGXT, vPragma_GCIO);
- }
- }
- }
- return GetGCCurrentOffset_GCIO(hGXT);
- }/* _get_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _InitExtent_GCIO (
- GCExtent* theExtent
- )
- {
- theExtent->XUL= HUGE_VAL;
- theExtent->YUL= -HUGE_VAL;
- theExtent->XLR= -HUGE_VAL;
- theExtent->YLR= HUGE_VAL;
- }/* _InitExtent_GCIO */
- /* -------------------------------------------------------------------- */
- GCExtent GCIOAPI_CALL1(*) CreateExtent_GCIO (
- double Xmin,
- double Ymin,
- double Xmax,
- double Ymax
- )
- {
- GCExtent* theExtent;
- if( !(theExtent= CPLMalloc(sizeof(GCExtent))) )
- {
- CPLError( CE_Failure, CPLE_OutOfMemory,
- "failed to create a Geoconcept extent for '[%g %g,%g %g]'.\n",
- Xmin, Ymin,Xmax, Ymax);
- return NULL;
- }
- _InitExtent_GCIO(theExtent);
- theExtent->XUL= Xmin;
- theExtent->YUL= Ymax;
- theExtent->XLR= Xmax;
- theExtent->YLR= Ymin;
- return theExtent;
- }/* CreateExtent_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _ReInitExtent_GCIO (
- GCExtent* theExtent
- )
- {
- _InitExtent_GCIO(theExtent);
- }/* _ReInitExtent_GCIO */
- /* -------------------------------------------------------------------- */
- void GCIOAPI_CALL DestroyExtent_GCIO (
- GCExtent** theExtent
- )
- {
- _ReInitExtent_GCIO(*theExtent);
- CPLFree(*theExtent);
- *theExtent= NULL;
- }/* DestroyExtent_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _InitField_GCIO (
- GCField* theField
- )
- {
- SetFieldName_GCIO(theField, NULL);
- SetFieldID_GCIO(theField, UNDEFINEDID_GCIO);
- SetFieldKind_GCIO(theField, vUnknownItemType_GCIO);
- SetFieldExtra_GCIO(theField, NULL);
- SetFieldList_GCIO(theField, NULL);
- }/* _InitField_GCIO */
- /* -------------------------------------------------------------------- */
- static const char GCIOAPI_CALL1(*) _NormalizeFieldName_GCIO (
- const char* name
- )
- {
- if( name[0]=='@' )
- {
- if( EQUAL(name, "@Identificateur") || EQUAL(name, kIdentifier_GCIO) )
- {
- return kIdentifier_GCIO;
- }
- else if( EQUAL(name, "@Type") || EQUAL(name, kClass_GCIO) )
- {
- return kClass_GCIO;
- }
- else if( EQUAL(name, "@Sous-type") || EQUAL(name, kSubclass_GCIO) )
- {
- return kSubclass_GCIO;
- }
- else if( EQUAL(name, "@Nom") || EQUAL(name, kName_GCIO) )
- {
- return kName_GCIO;
- }
- else if( EQUAL(name, kNbFields_GCIO) )
- {
- return kNbFields_GCIO;
- }
- else if( EQUAL(name, kX_GCIO) )
- {
- return kX_GCIO;
- }
- else if( EQUAL(name, kY_GCIO) )
- {
- return kY_GCIO;
- }
- else if( EQUAL(name, "@X'") || EQUAL(name, kXP_GCIO) )
- {
- return kXP_GCIO;
- }
- else if( EQUAL(name, "@Y'") || EQUAL(name, kYP_GCIO) )
- {
- return kYP_GCIO;
- }
- else if( EQUAL(name, kGraphics_GCIO) )
- {
- return kGraphics_GCIO;
- }
- else if( EQUAL(name, kAngle_GCIO) )
- {
- return kAngle_GCIO;
- }
- else
- {
- return name;
- }
- }
- else
- {
- return name;
- }
- }/* _NormalizeFieldName_GCIO */
- /* -------------------------------------------------------------------- */
- static GCField GCIOAPI_CALL1(*) _CreateField_GCIO (
- const char* name,
- long id,
- GCTypeKind knd,
- const char* extra,
- const char* enums
- )
- {
- GCField* theField;
- if( !(theField= CPLMalloc(sizeof(GCField))) )
- {
- CPLError( CE_Failure, CPLE_OutOfMemory,
- "failed to create a Geoconcept field for '%s'.\n",
- name);
- return NULL;
- }
- _InitField_GCIO(theField);
- SetFieldName_GCIO(theField, CPLStrdup(name));
- SetFieldID_GCIO(theField, id);
- SetFieldKind_GCIO(theField, knd);
- if( extra && extra[0]!='\0' ) SetFieldExtra_GCIO(theField, CPLStrdup(extra));
- if( enums && enums[0]!='\0' ) SetFieldList_GCIO(theField, CSLTokenizeString2(enums,";",0));
- return theField;
- }/* _CreateField_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _ReInitField_GCIO (
- GCField* theField
- )
- {
- if( GetFieldName_GCIO(theField) )
- {
- CPLFree(GetFieldName_GCIO(theField));
- }
- if( GetFieldExtra_GCIO(theField) )
- {
- CPLFree( GetFieldExtra_GCIO(theField) );
- }
- if( GetFieldList_GCIO(theField) )
- {
- CSLDestroy( GetFieldList_GCIO(theField) );
- }
- _InitField_GCIO(theField);
- }/* _ReInitField_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _DestroyField_GCIO (
- GCField** theField
- )
- {
- _ReInitField_GCIO(*theField);
- CPLFree(*theField);
- *theField= NULL;
- }/* _DestroyField_GCIO */
- /* -------------------------------------------------------------------- */
- static int GCIOAPI_CALL _findFieldByName_GCIO (
- CPLList* fields,
- const char* name
- )
- {
- GCField* theField;
- if( fields )
- {
- CPLList* e;
- int n, i;
- if( (n= CPLListCount(fields))>0 )
- {
- for( i= 0; i<n; i++)
- {
- if( (e= CPLListGet(fields,i)) )
- {
- if( (theField= (GCField*)CPLListGetData(e)) )
- {
- if( EQUAL(GetFieldName_GCIO(theField),name) )
- {
- return i;
- }
- }
- }
- }
- }
- }
- return -1;
- }/* _findFieldByName_GCIO */
- /* -------------------------------------------------------------------- */
- static GCField GCIOAPI_CALL1(*) _getField_GCIO (
- CPLList* fields,
- int where
- )
- {
- CPLList* e;
- if( (e= CPLListGet(fields,where)) )
- return (GCField*)CPLListGetData(e);
- return NULL;
- }/* _getField_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _InitSubType_GCIO (
- GCSubType* theSubType
- )
- {
- SetSubTypeGCHandle_GCIO(theSubType, NULL);
- SetSubTypeType_GCIO(theSubType, NULL);
- SetSubTypeName_GCIO(theSubType, NULL);
- SetSubTypeFields_GCIO(theSubType, NULL); /* GCField */
- SetSubTypeFeatureDefn_GCIO(theSubType, NULL);
- SetSubTypeKind_GCIO(theSubType, vUnknownItemType_GCIO);
- SetSubTypeID_GCIO(theSubType, UNDEFINEDID_GCIO);
- SetSubTypeDim_GCIO(theSubType, v2D_GCIO);
- SetSubTypeNbFields_GCIO(theSubType, -1);
- SetSubTypeNbFeatures_GCIO(theSubType, 0L);
- SetSubTypeBOF_GCIO(theSubType, -1L);
- SetSubTypeBOFLinenum_GCIO(theSubType, 0L);
- SetSubTypeExtent_GCIO(theSubType, NULL);
- SetSubTypeHeaderWritten_GCIO(theSubType, FALSE);
- }/* _InitSubType_GCIO */
- /* -------------------------------------------------------------------- */
- static GCSubType GCIOAPI_CALL1(*) _CreateSubType_GCIO (
- const char* subtypName,
- long id,
- GCTypeKind knd,
- GCDim sys
- )
- {
- GCSubType* theSubType;
- if( !(theSubType= CPLMalloc(sizeof(GCSubType))) )
- {
- CPLError( CE_Failure, CPLE_OutOfMemory,
- "failed to create a Geoconcept subtype for '%s'.\n",
- subtypName);
- return NULL;
- }
- _InitSubType_GCIO(theSubType);
- SetSubTypeName_GCIO(theSubType, CPLStrdup(subtypName));
- SetSubTypeID_GCIO(theSubType, id);
- SetSubTypeKind_GCIO(theSubType, knd);
- SetSubTypeDim_GCIO(theSubType, sys);
- return theSubType;
- }/* _CreateSubType_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _ReInitSubType_GCIO (
- GCSubType* theSubType
- )
- {
- if( GetSubTypeFeatureDefn_GCIO(theSubType) )
- {
- OGR_FD_Release(GetSubTypeFeatureDefn_GCIO(theSubType));
- }
- if( GetSubTypeFields_GCIO(theSubType) )
- {
- CPLList* e;
- GCField* theField;
- int i, n;
- if( (n= CPLListCount(GetSubTypeFields_GCIO(theSubType)))>0 )
- {
- for (i= 0; i<n; i++)
- {
- if( (e= CPLListGet(GetSubTypeFields_GCIO(theSubType),i)) )
- {
- if( (theField= (GCField*)CPLListGetData(e)) )
- {
- _DestroyField_GCIO(&theField);
- }
- }
- }
- }
- CPLListDestroy(GetSubTypeFields_GCIO(theSubType));
- }
- if( GetSubTypeName_GCIO(theSubType) )
- {
- CPLFree( GetSubTypeName_GCIO(theSubType) );
- }
- if( GetSubTypeExtent_GCIO(theSubType) )
- {
- DestroyExtent_GCIO(&(GetSubTypeExtent_GCIO(theSubType)));
- }
- _InitSubType_GCIO(theSubType);
- }/* _ReInitSubType_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _DestroySubType_GCIO (
- GCSubType** theSubType
- )
- {
- _ReInitSubType_GCIO(*theSubType);
- CPLFree(*theSubType);
- *theSubType= NULL;
- }/* _DestroySubType_GCIO */
- /* -------------------------------------------------------------------- */
- static int GCIOAPI_CALL _findSubTypeByName_GCIO (
- GCType* theClass,
- const char* subtypName
- )
- {
- GCSubType* theSubType;
- if( GetTypeSubtypes_GCIO(theClass) )
- {
- CPLList* e;
- int n, i;
- if( (n= CPLListCount(GetTypeSubtypes_GCIO(theClass)))>0 )
- {
- if( *subtypName=='*' ) return 0;
- for( i = 0; i < n; i++)
- {
- if( (e= CPLListGet(GetTypeSubtypes_GCIO(theClass),i)) )
- {
- if( (theSubType= (GCSubType*)CPLListGetData(e)) )
- {
- if( EQUAL(GetSubTypeName_GCIO(theSubType),subtypName) )
- {
- return i;
- }
- }
- }
- }
- }
- }
- return -1;
- }/* _findSubTypeByName_GCIO */
- /* -------------------------------------------------------------------- */
- static GCSubType GCIOAPI_CALL1(*) _getSubType_GCIO (
- GCType* theClass,
- int where
- )
- {
- CPLList* e;
- if( (e= CPLListGet(GetTypeSubtypes_GCIO(theClass),where)) )
- return (GCSubType*)CPLListGetData(e);
- return NULL;
- }/* _getSubType_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _InitType_GCIO (
- GCType* theClass
- )
- {
- SetTypeName_GCIO(theClass, NULL);
- SetTypeSubtypes_GCIO(theClass, NULL);/* GCSubType */
- SetTypeFields_GCIO(theClass, NULL); /* GCField */
- SetTypeID_GCIO(theClass, UNDEFINEDID_GCIO);
- }/* _InitType_GCIO */
- /* -------------------------------------------------------------------- */
- static GCType GCIOAPI_CALL1(*) _CreateType_GCIO (
- const char* typName,
- long id
- )
- {
- GCType* theClass;
- if( !(theClass= CPLMalloc(sizeof(GCType))) )
- {
- CPLError( CE_Failure, CPLE_OutOfMemory,
- "failed to create a Geoconcept type for '%s#%ld'.\n",
- typName, id);
- return NULL;
- }
- _InitType_GCIO(theClass);
- SetTypeName_GCIO(theClass, CPLStrdup(typName));
- SetTypeID_GCIO(theClass, id);
- return theClass;
- }/* _CreateType_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _ReInitType_GCIO (
- GCType* theClass
- )
- {
- if( GetTypeSubtypes_GCIO(theClass) )
- {
- CPLList* e;
- GCSubType* theSubType;
- int i, n;
- if( (n= CPLListCount(GetTypeSubtypes_GCIO(theClass)))>0 )
- {
- for (i= 0; i<n; i++)
- {
- if( (e= CPLListGet(GetTypeSubtypes_GCIO(theClass),i)) )
- {
- if( (theSubType= (GCSubType*)CPLListGetData(e)) )
- {
- _DestroySubType_GCIO(&theSubType);
- }
- }
- }
- }
- CPLListDestroy(GetTypeSubtypes_GCIO(theClass));
- }
- if( GetTypeFields_GCIO(theClass) )
- {
- CPLList* e;
- GCField* theField;
- int i, n;
- if( (n= CPLListCount(GetTypeFields_GCIO(theClass)))>0 )
- {
- for (i= 0; i<n; i++)
- {
- if( (e= CPLListGet(GetTypeFields_GCIO(theClass),i)) )
- {
- if( (theField= (GCField*)CPLListGetData(e)) )
- {
- _DestroyField_GCIO(&theField);
- }
- }
- }
- }
- CPLListDestroy(GetTypeFields_GCIO(theClass));
- }
- if( GetTypeName_GCIO(theClass) )
- {
- CPLFree( GetTypeName_GCIO(theClass) );
- }
- _InitType_GCIO(theClass);
- }/* _ReInitType_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _DestroyType_GCIO (
- GCType** theClass
- )
- {
- _ReInitType_GCIO(*theClass);
- CPLFree(*theClass);
- *theClass= NULL;
- }/* _DestroyType_GCIO */
- /* -------------------------------------------------------------------- */
- static int GCIOAPI_CALL _findTypeByName_GCIO (
- GCExportFileH* hGXT,
- const char* typName
- )
- {
- GCType* theClass;
- GCExportFileMetadata* header;
- header= GetGCMeta_GCIO(hGXT);
- if( GetMetaTypes_GCIO(header) )
- {
- CPLList* e;
- int n, i;
- if( (n= CPLListCount(GetMetaTypes_GCIO(header)))>0 )
- {
- if( *typName=='*' ) return 0;
- for( i = 0; i < n; i++)
- {
- if( (e= CPLListGet(GetMetaTypes_GCIO(header),i)) )
- {
- if( (theClass= (GCType*)CPLListGetData(e)) )
- {
- if( EQUAL(GetTypeName_GCIO(theClass),typName) )
- {
- return i;
- }
- }
- }
- }
- }
- }
- return -1;
- }/* _findTypeByName_GCIO */
- /* -------------------------------------------------------------------- */
- static GCType GCIOAPI_CALL1(*) _getType_GCIO (
- GCExportFileH* hGXT,
- int where
- )
- {
- CPLList* e;
- if( (e= CPLListGet(GetMetaTypes_GCIO(GetGCMeta_GCIO(hGXT)),where)) )
- return (GCType*)CPLListGetData(e);
- return NULL;
- }/* _getType_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _InitHeader_GCIO (
- GCExportFileMetadata* header
- )
- {
- SetMetaVersion_GCIO(header, NULL);
- SetMetaDelimiter_GCIO(header, kTAB_GCIO[0]);
- SetMetaQuotedText_GCIO(header, FALSE);
- SetMetaCharset_GCIO(header, vANSI_GCIO);
- SetMetaUnit_GCIO(header, "m");
- SetMetaFormat_GCIO(header, 2);
- SetMetaSysCoord_GCIO(header, NULL); /* GCSysCoord */
- SetMetaSRS_GCIO(header, NULL);
- SetMetaTypes_GCIO(header, NULL); /* GCType */
- SetMetaFields_GCIO(header, NULL); /* GCField */
- SetMetaResolution_GCIO(header, 0.1);
- SetMetaExtent_GCIO(header, NULL);
- }/* _InitHeader_GCIO */
- /* -------------------------------------------------------------------- */
- GCExportFileMetadata GCIOAPI_CALL1(*) CreateHeader_GCIO ( )
- {
- GCExportFileMetadata* m;
- if( !(m= CPLMalloc(sizeof(GCExportFileMetadata)) ) )
- {
- CPLError( CE_Failure, CPLE_OutOfMemory,
- "failed to create Geoconcept metadata.\n");
- return NULL;
- }
- _InitHeader_GCIO(m);
- return m;
- }/* CreateHeader_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _ReInitHeader_GCIO (
- GCExportFileMetadata* header
- )
- {
- if( GetMetaVersion_GCIO(header) )
- {
- CPLFree( GetMetaVersion_GCIO(header) );
- }
- if( GetMetaExtent_GCIO(header) )
- {
- DestroyExtent_GCIO(&(GetMetaExtent_GCIO(header)));
- }
- if( GetMetaTypes_GCIO(header) )
- {
- CPLList* e;
- GCType* theClass;
- int i, n;
- if( (n= CPLListCount(GetMetaTypes_GCIO(header)))>0 )
- {
- for (i= 0; i<n; i++)
- {
- if( (e= CPLListGet(GetMetaTypes_GCIO(header),i)) )
- {
- if( (theClass= (GCType*)CPLListGetData(e)) )
- {
- _DestroyType_GCIO(&theClass);
- }
- }
- }
- }
- CPLListDestroy(GetMetaTypes_GCIO(header));
- }
- if( GetMetaFields_GCIO(header) )
- {
- CPLList* e;
- GCField* theField;
- int i, n;
- if( (n= CPLListCount(GetMetaFields_GCIO(header)))>0 )
- {
- for (i= 0; i<n; i++)
- {
- if( (e= CPLListGet(GetMetaFields_GCIO(header),i)) )
- {
- if( (theField= (GCField*)CPLListGetData(e)) )
- {
- _DestroyField_GCIO(&theField);
- }
- }
- }
- }
- CPLListDestroy(GetMetaFields_GCIO(header));
- }
- if( GetMetaSRS_GCIO(header) )
- {
- OSRRelease( GetMetaSRS_GCIO(header) );
- }
- if( GetMetaSysCoord_GCIO(header) )
- {
- DestroySysCoord_GCSRS(&(GetMetaSysCoord_GCIO(header)));
- }
- _InitHeader_GCIO(header);
- }/* _ReInitHeader_GCIO */
- /* -------------------------------------------------------------------- */
- void GCIOAPI_CALL DestroyHeader_GCIO (
- GCExportFileMetadata** m
- )
- {
- _ReInitHeader_GCIO(*m);
- CPLFree(*m);
- *m= NULL;
- }/* DestroyHeader_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _Init_GCIO (
- GCExportFileH* H
- )
- {
- SetGCCache_GCIO(H,"");
- SetGCPath_GCIO(H, NULL);
- SetGCBasename_GCIO(H, NULL);
- SetGCExtension_GCIO(H, NULL);
- SetGCHandle_GCIO(H, NULL);
- SetGCCurrentOffset_GCIO(H, 0L);
- SetGCCurrentLinenum_GCIO(H, 0L);
- SetGCNbObjects_GCIO(H, 0L);
- SetGCMeta_GCIO(H, NULL);
- SetGCMode_GCIO(H, vNoAccess_GCIO);
- SetGCStatus_GCIO(H, vNoStatus_GCIO);
- SetGCWhatIs_GCIO(H, vUnknownIO_ItemType_GCIO);
- }/* _Init_GCIO */
- /* -------------------------------------------------------------------- */
- static GCExportFileH GCIOAPI_CALL1(*) _Create_GCIO (
- const char* pszGeoconceptFile,
- const char *ext,
- const char* mode
- )
- {
- GCExportFileH* hGXT;
- if( !(hGXT= CPLMalloc(sizeof(GCExportFileH)) ) )
- {
- CPLError( CE_Failure, CPLE_OutOfMemory,
- "failed to create a Geoconcept handle for '%s' (%s).\n",
- pszGeoconceptFile, mode);
- return NULL;
- }
- _Init_GCIO(hGXT);
- SetGCPath_GCIO(hGXT, CPLStrdup(CPLGetDirname(pszGeoconceptFile)));
- SetGCBasename_GCIO(hGXT, CPLStrdup(CPLGetBasename(pszGeoconceptFile)));
- SetGCExtension_GCIO(hGXT, CPLStrdup(ext? ext:"gxt"));
- SetGCMode_GCIO(hGXT, (mode[0]=='w'? vWriteAccess_GCIO : (mode[0]=='a'? vUpdateAccess_GCIO:vReadAccess_GCIO)));
- return hGXT;
- }/* _Create_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _ReInit_GCIO (
- GCExportFileH* hGXT
- )
- {
- if( GetGCMeta_GCIO(hGXT) )
- {
- DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
- }
- if( GetGCHandle_GCIO(hGXT) )
- {
- VSIFClose(GetGCHandle_GCIO(hGXT));
- }
- if( GetGCExtension_GCIO(hGXT) )
- {
- CPLFree(GetGCExtension_GCIO(hGXT));
- }
- if( GetGCBasename_GCIO(hGXT) )
- {
- CPLFree(GetGCBasename_GCIO(hGXT));
- }
- if( GetGCPath_GCIO(hGXT) )
- {
- CPLFree(GetGCPath_GCIO(hGXT));
- }
- SetGCCache_GCIO(hGXT,"");
- _Init_GCIO(hGXT);
- }/* _ReInit_GCIO */
- /* -------------------------------------------------------------------- */
- static void GCIOAPI_CALL _Destroy_GCIO (
- GCExportFileH** hGXT,
- int delFile
- )
- {
- if( delFile && GetGCMode_GCIO(*hGXT)==vWriteAccess_GCIO )
- {
- VSIFClose(GetGCHandle_GCIO(*hGXT));
- SetGCHandle_GCIO(*hGXT, NULL);
- VSIUnlink(CPLFormFilename(GetGCPath_GCIO(*hGXT),GetGCBasename_GCIO(*hGXT),GetGCExtension_GCIO(*hGXT)));
- }
- _ReInit_GCIO(*hGXT);
- CPLFree(*hGXT);
- *hGXT= NULL;
- }/* _Destroy_GCIO */
- /* -------------------------------------------------------------------- */
- static int _checkSchema_GCIO (
- GCExportFileH* hGXT
- )
- {
- GCExportFileMetadata* Meta;
- int nT, iT, nS, iS, nF, iF, nU, iId, iCl, iSu, iNa, iNb, iX, iY, iXP, iYP, iGr, iAn;
- GCField* theField;
- GCSubType* theSubType;
- GCType* theClass;
- CPLList* e;
- if( !(Meta= GetGCMeta_GCIO(hGXT)) )
- {
- return TRUE; /* FIXME */
- }
- if( (nT= CPLListCount(GetMetaTypes_GCIO(Meta)))==0 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept schema without types!\n" );
- return FALSE;
- }
- for (iT= 0; iT<nT; iT++)
- {
- if( (e= CPLListGet(GetMetaTypes_GCIO(Meta),iT)) )
- {
- if( (theClass= (GCType*)CPLListGetData(e)) )
- {
- if( (nS= CPLListCount(GetTypeSubtypes_GCIO(theClass)))==0 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept type %s without sub-types!\n",
- GetTypeName_GCIO(theClass) );
- return FALSE;
- }
- for (iS= 0; iS<nS; iS++)
- {
- if( (e= CPLListGet(GetTypeSubtypes_GCIO(theClass),iS)) )
- {
- if( (theSubType= (GCSubType*)CPLListGetData(e)) )
- {
- if( (nF= CPLListCount(GetSubTypeFields_GCIO(theSubType)))==0 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept sub-type %s.%s without fields!\n",
- GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- nU= 0;
- iId= iCl= iSu= iNa= iNb= iX= iY= iXP= iYP= iGr= iAn= -1;
- for (iF= 0; iF<nF; iF++)
- {
- if( (e= CPLListGet(GetSubTypeFields_GCIO(theSubType),iF)) )
- {
- if( (theField= (GCField*)CPLListGetData(e)) )
- {
- if( IsPrivateField_GCIO(theField) )
- {
- if( EQUAL(GetFieldName_GCIO(theField),kIdentifier_GCIO) )
- iId= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kClass_GCIO) )
- iCl= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kSubclass_GCIO) )
- iSu= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kName_GCIO) )
- iNa= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kNbFields_GCIO) )
- iNb= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kX_GCIO) )
- iX= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kY_GCIO) )
- iY= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kXP_GCIO) )
- iXP= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kYP_GCIO) )
- iYP= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kGraphics_GCIO) )
- iGr= iF;
- else if( EQUAL(GetFieldName_GCIO(theField),kAngle_GCIO) )
- iAn= iF;
- }
- else
- {
- nU++;
- }
- }
- }
- }
- if( iId==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kIdentifier_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- else if( iId!=0 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s must be the first field of %s.%s!\n",
- kIdentifier_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iCl==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kClass_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- else if( iCl-iId!=1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s must be the second field of %s.%s!\n",
- kClass_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iSu==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kSubclass_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- else if( iSu-iCl!=1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s must be the third field of %s.%s!\n",
- kSubclass_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if (iNa==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kName_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- else if( iNa-iSu!=1)
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s must be the forth field of %s.%s!\n",
- kName_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iNb==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kNbFields_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iX==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kX_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iY==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kY_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iY-iX!=1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept geometry fields %s, %s must be consecutive for %s.%s!\n",
- kX_GCIO, kY_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( GetSubTypeKind_GCIO(theSubType)==vLine_GCIO )
- {
- if( iXP==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kXP_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iYP==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kYP_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iYP-iXP!=1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept geometry fields %s, %s must be consecutive for %s.%s!\n",
- kXP_GCIO, kYP_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- if( iXP-iY!=1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept geometry fields %s, %s, %s, %s must be consecutive for %s.%s!\n",
- kX_GCIO, kY_GCIO, kXP_GCIO, kYP_GCIO,
- GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- }
- else
- {
- if( iXP!=-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept sub-type %s.%s has a mandatory field %s only required on linear type!\n",
- GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType), kXP_GCIO );
- return FALSE;
- }
- if( iYP!=-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept sub-type %s.%s has a mandatory field %s only required on linear type!\n",
- GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType), kYP_GCIO );
- return FALSE;
- }
- }
- if( GetSubTypeKind_GCIO(theSubType)==vLine_GCIO ||
- GetSubTypeKind_GCIO(theSubType)==vPoly_GCIO )
- {
- if( iGr==-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept mandatory field %s is missing on %s.%s!\n",
- kGraphics_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- else
- {
- if( (iYP!=-1 && iGr-iYP!=1) || (iGr-iY!=1) )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept geometry fields %s, %s must be consecutive for %s.%s!\n",
- iYP!=-1? kYP_GCIO:kY_GCIO, kGraphics_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
- return FALSE;
- }
- }
- if( iAn!=-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept sub-type %s.%s has a field %s only required on ponctual or text type!\n",
- GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType), kAngle_GCIO );
- return FALSE;
- }
- }
- else
- {
- if( iGr!=-1 )
- {
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept sub-type %s.%s has a mandatory field %s only required on linear or polygonal type!\n",
- GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType), kGraphics_GCIO );
- return FALSE;
- }
- }
- SetSubTypeNbFields_GCIO(theSubType,nU);
- SetSubTypeGCHandle_GCIO(theSubType,hGXT);
- }
- }
- }
- }
- }
- }
- return TRUE;
- }/* _checkSchema_GCIO */
- /* -------------------------------------------------------------------- */
- static GCExportFileMetadata GCIOAPI_CALL1(*) _parsePragma_GCIO (
- GCExportFileH* hGXT
- )
- {
- GCExportFileMetadata* Meta;
- char* p, *e;
- Meta= GetGCMeta_GCIO(hGXT);
- if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataVERSION_GCIO))!=NULL )
- {
- /* //$VERSION char* */
- p+= strlen(kMetadataVERSION_GCIO);
- while( isspace(*p) ) p++;
- e= p;
- while( isalpha(*p) ) p++;
- *p= '\0';
- SetMetaVersion_GCIO(Meta,CPLStrdup(e));
- return Meta;
- }
- if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataDELIMITER_GCIO))!=NULL )
- {
- /* //$DELIMITER "char*" */
- if( (p= strchr(p,'"')) )
- {
- p++;
- e= p;
- while( *p!='"' && *p!='\0' ) p++;
- *p= '\0';
- if( !( EQUAL(e,"tab") || EQUAL(e,kTAB_GCIO) ) )
- {
- CPLDebug("GEOCONCEPT","%s%s only supports \"tab\" value",
- kPragma_GCIO, kMetadataDELIMITER_GCIO);
- SetMetaDelimiter_GCIO(Meta,kTAB_GCIO[0]);
- } else {
- SetMetaDelimiter_GCIO(Meta,kTAB_GCIO[0]);
- }
- }
- return Meta;
- }
- if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataQUOTEDTEXT_GCIO))!=NULL )
- {
- /* //$QUOTED-TEXT "char*" */
- if( (p= strchr(p,'"')) )
- {
- p++;
- e= p;
- while( *p!='"' && *p!='\0' ) p++;
- *p= '\0';
- if( EQUAL(e,"no") )
- {
- SetMetaQuotedText_GCIO(Meta,FALSE);
- }
- else
- {
- SetMetaQuotedText_GCIO(Meta,TRUE);
- }
- }
- return Meta;
- }
- if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataCHARSET_GCIO))!=NULL )
- {
- /* //$CHARSET char* */
- p+= strlen(kMetadataCHARSET_GCIO);
- while( isspace(*p) ) p++;
- e= p;
- while( isalpha(*p) ) p++;
- *p= '\0';
- SetMetaCharset_GCIO(Meta,str2GCCharset_GCIO(e));
- return Meta;
- }
- if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataUNIT_GCIO))!=NULL )
- {
- /* //$UNIT Distance|Angle:char* */
- if( (p= strchr(p,':')) )
- {
- p++;
- while( isspace(*p) ) p++;
- e= p;
- while( isalpha(*p) || *p=='.' ) p++;
- *p= '\0';
- SetMetaUnit_GCIO(Meta,e);/* FIXME : check value ? */
- }
- return Meta;
- }
- if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataFORMAT_GCIO))!=NULL )
- {
- /* //$FORMAT 1|2 */
- p+= strlen(kMetadataFORMAT_GCIO);
- while( isspace(*p) ) p++;
- e= p;
- if( *e=='1' )
- {
- SetMetaFormat_GCIO(Meta,1);
- }
- else
- {
- SetMetaFormat_GCIO(Meta,2);
- }
- return Meta;
- }
- if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataSYSCOORD_GCIO))!=NULL )
- {
- int v, z;
- GCSysCoord* syscoord;
- /* //$SYSCOORD {Type: int} [ ; { TimeZone: TimeZoneValue } ] */
- v= -1, z= -1;
- if( (p= strchr(p,':')) )
- {
- p++;
- while( isspace(*p) ) p++;
- e= p;
- if( *p=='-') p++; /* allow -1 as SysCoord */
- while( isdigit(*p) ) p++;
- *p= '\0';
- if( sscanf(e,"%d",&v)!= 1 )
- {
- DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
- CPLError( CE_Failure, CPLE_AppDefined,
- "Invalid SRS identifier. "
- "Geoconcept export syntax error at line %ld.",
- GetGCCurrentLinenum_GCIO(hGXT) );
- return NULL;
- }
- if( (p= strrchr(GetGCCache_GCIO(hGXT),';')) )
- {
- if( (p= strchr(p,':')) )
- {
- p++;
- while( isspace(*p) ) p++;
- e= p;
- if( *p=='-') p++; /* allow -1 as TimeZone */
- while( isdigit(*p) ) p++;
- *p= '\0';
- if( sscanf(e,"%d",&z)!= 1 )
- {
- DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
- CPLError( CE_Failure, CPLE_AppDefined,
- "Invalid TimeZone. "
- "Geoconcept export syntax error at line %ld.",
- GetGCCurrentLinenum_GCIO(hGXT) );
- return NULL;
- }
- }
- }
- if( !(syscoord= CreateSysCoord_GCSRS(v,z)) )
- {
- DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
- return NULL;
- }
- SetMetaSysCoord_GCIO(Meta,syscoord);
- }
- return Meta;
- }
- if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataFIELDS_GCIO))!=NULL )
- {
- char **kv, **vl, *nm, **fl;
- int whereClass, v, i, n;
- GCType* theClass;
- GCSubType* theSubType;
- GCField* theField;
- /* //$FIELDS Class=char*;Subclass=char*;Kind=1..4;Fields=(Private#)?char*\s((Private#)?char*)* */
- p+= strlen(kMetadataFIELDS_GCIO);
- while( isspace(*p) ) p++;
- kv= CSLTokenizeString2(p,";",0);
- if( !kv || CSLCount(kv)!=4 )
- {
- CSLDestroy(kv);
- DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept export syntax error at line %ld.\n",
- GetGCCurrentLinenum_GCIO(hGXT) );
- return NULL;
- }
- /* Class=char* */
- vl= CSLTokenizeString2(kv[0],"=",0);
- if( !vl || CSLCount(vl)!=2 )
- {
- CSLDestroy(vl);
- CSLDestroy(kv);
- DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
- CPLError( CE_Failure, CPLE_AppDefined,
- "Geoconcept export syntax error at line %ld.\n",
- GetGCCurrentLinenum_GCIO(hGXT) );
- return NULL;
- }
- if( !EQUAL(vl[0], "Class") )
- {
- CSLDestroy(vl);
- CSLDestroy(kv);
- DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
- CPLError( CE_Failure, CPLE_AppDefined,
- "'Class' expected.\n"
- "Geoconcept export syntax er…
Large files files are truncated, but you can click here to view the full file