PageRenderTime 53ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/gdal-1.6.1-tcl_patched/ogr/ogrsf_frmts/geoconcept/geoconcept.c

http://tcl-map.googlecode.com/
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

  1. /**********************************************************************
  2. * $Id: geoconcept.c
  3. *
  4. * Name: geoconcept.c
  5. * Project: OpenGIS Simple Features Reference Implementation
  6. * Purpose: Implements Physical Access class.
  7. * Language: C
  8. *
  9. **********************************************************************
  10. * Copyright (c) 2007, Geoconcept and IGN
  11. *
  12. * Permission is hereby granted, free of charge, to any person obtaining a
  13. * copy of this software and associated documentation files (the "Software"),
  14. * to deal in the Software without restriction, including without limitation
  15. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  16. * and/or sell copies of the Software, and to permit persons to whom the
  17. * Software is furnished to do so, subject to the following conditions:
  18. *
  19. * The above copyright notice and this permission notice shall be included
  20. * in all copies or substantial portions of the Software.
  21. *
  22. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  23. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  24. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  25. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  26. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  27. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  28. * DEALINGS IN THE SOFTWARE.
  29. **********************************************************************/
  30. #include <math.h>
  31. #include "geoconcept.h"
  32. #include "cpl_conv.h"
  33. #include "cpl_string.h"
  34. #include "ogr_core.h"
  35. GCIO_CVSID("$Id: geoconcept.c,v 1.0.0 2007-11-03 20:58:19 drichard Exp $")
  36. #define kItemSize_GCIO 256
  37. #define kExtraSize_GCIO 4096
  38. #define kIdSize_GCIO 12
  39. #define UNDEFINEDID_GCIO 199901L
  40. static char* gkGCCharset[]=
  41. {
  42. /* 0 */ "",
  43. /* 1 */ "ANSI",
  44. /* 2 */ "DOS",
  45. /* 3 */ "MAC"
  46. };
  47. static char* gkGCAccess[]=
  48. {
  49. /* 0 */ "",
  50. /* 1 */ "NO",
  51. /* 2 */ "READ",
  52. /* 3 */ "UPDATE",
  53. /* 4 */ "WRITE"
  54. };
  55. static char* gkGCStatus[]=
  56. {
  57. /* 0 */ "NONE",
  58. /* 1 */ "MEMO",
  59. /* 2 */ "EOF"
  60. };
  61. static char* gk3D[]=
  62. {
  63. /* 0 */ "",
  64. /* 1 */ "2D",
  65. /* 2 */ "3DM",
  66. /* 3 */ "3D"
  67. };
  68. static char* gkGCTypeKind[]=
  69. {
  70. /* 0 */ "",
  71. /* 1 */ "POINT",
  72. /* 2 */ "LINE",
  73. /* 3 */ "TEXT",
  74. /* 4 */ "POLYGON",
  75. /* 5 */ "MEMO",
  76. /* 6 */ "INT",
  77. /* 7 */ "REAL",
  78. /* 8 */ "LENGTH",
  79. /* 9 */ "AREA",
  80. /*10 */ "POSITION",
  81. /*11 */ "DATE",
  82. /*12 */ "TIME",
  83. /*13 */ "CHOICE",
  84. /*14 */ "MEMO"
  85. };
  86. /* -------------------------------------------------------------------- */
  87. /* GCIO API Prototypes */
  88. /* -------------------------------------------------------------------- */
  89. /* -------------------------------------------------------------------- */
  90. static char GCIOAPI_CALL1(*) _getHeaderValue_GCIO ( const char *s )
  91. {
  92. char *b, *e;
  93. if( (b= strchr(s,'='))==NULL ) return NULL;
  94. b++;
  95. while (isspace(*b)) b++;
  96. e= b;
  97. while (*e!='\0' && !isspace(*e)) e++;
  98. *e= '\0';
  99. return b;
  100. }/* _getHeaderValue_GCIO */
  101. /* -------------------------------------------------------------------- */
  102. const char GCIOAPI_CALL1(*) GCCharset2str_GCIO ( GCCharset cs )
  103. {
  104. switch (cs) {
  105. case vANSI_GCIO :
  106. case vDOS_GCIO :
  107. case vMAC_GCIO :
  108. case vWriteAccess_GCIO :
  109. return gkGCCharset[cs];
  110. default :
  111. return gkGCCharset[vUnknownCharset_GCIO];
  112. }
  113. }/* GCCharset2str_GCIO */
  114. /* -------------------------------------------------------------------- */
  115. GCCharset GCIOAPI_CALL str2GCCharset_GCIO ( const char* s)
  116. {
  117. if (strcmp(s,gkGCCharset[vANSI_GCIO])==0) return vANSI_GCIO;
  118. if (strcmp(s,gkGCCharset[vDOS_GCIO])==0) return vDOS_GCIO;
  119. if (strcmp(s,gkGCCharset[vMAC_GCIO])==0) return vMAC_GCIO;
  120. return vUnknownCharset_GCIO;
  121. }/* str2GCCharset_GCIO */
  122. /* -------------------------------------------------------------------- */
  123. const char GCIOAPI_CALL1(*) GCAccessMode2str_GCIO ( GCAccessMode mode )
  124. {
  125. switch (mode) {
  126. case vNoAccess_GCIO :
  127. case vReadAccess_GCIO :
  128. case vUpdateAccess_GCIO :
  129. case vWriteAccess_GCIO :
  130. return gkGCAccess[mode];
  131. default :
  132. return gkGCAccess[vUnknownAccessMode_GCIO];
  133. }
  134. }/* GCAccessMode2str_GCIO */
  135. /* -------------------------------------------------------------------- */
  136. GCAccessMode GCIOAPI_CALL str2GCAccessMode_GCIO ( const char* s)
  137. {
  138. if (strcmp(s,gkGCAccess[vNoAccess_GCIO])==0) return vNoAccess_GCIO;
  139. if (strcmp(s,gkGCAccess[vReadAccess_GCIO])==0) return vReadAccess_GCIO;
  140. if (strcmp(s,gkGCAccess[vUpdateAccess_GCIO])==0) return vUpdateAccess_GCIO;
  141. if (strcmp(s,gkGCAccess[vWriteAccess_GCIO])==0) return vWriteAccess_GCIO;
  142. return vUnknownAccessMode_GCIO;
  143. }/* str2GCAccessMode_GCIO */
  144. /* -------------------------------------------------------------------- */
  145. const char GCIOAPI_CALL1(*) GCAccessStatus2str_GCIO ( GCAccessStatus stts )
  146. {
  147. switch (stts) {
  148. case vMemoStatus_GCIO :
  149. case vEof_GCIO :
  150. return gkGCStatus[stts];
  151. default :
  152. return gkGCStatus[vNoStatus_GCIO];
  153. }
  154. }/* GCAccessStatus2str_GCIO */
  155. /* -------------------------------------------------------------------- */
  156. GCAccessStatus GCIOAPI_CALL str2GCAccessStatus_GCIO ( const char* s)
  157. {
  158. if (strcmp(s,gkGCStatus[vMemoStatus_GCIO])==0) return vMemoStatus_GCIO;
  159. if (strcmp(s,gkGCStatus[vEof_GCIO])==0) return vEof_GCIO;
  160. return vNoStatus_GCIO;
  161. }/* str2GCAccessStatus_GCIO */
  162. /* -------------------------------------------------------------------- */
  163. const char GCIOAPI_CALL1(*) GCDim2str_GCIO ( GCDim sys )
  164. {
  165. switch (sys) {
  166. case v2D_GCIO :
  167. case v3D_GCIO :
  168. case v3DM_GCIO :
  169. return gk3D[sys];
  170. default :
  171. return gk3D[vUnknown3D_GCIO];
  172. }
  173. }/* GCDim2str_GCIO */
  174. /* -------------------------------------------------------------------- */
  175. GCDim GCIOAPI_CALL str2GCDim ( const char* s )
  176. {
  177. if (strcmp(s,gk3D[v2D_GCIO])==0) return v2D_GCIO;
  178. if (strcmp(s,gk3D[v3D_GCIO])==0) return v3D_GCIO;
  179. if (strcmp(s,gk3D[v3DM_GCIO])==0) return v3DM_GCIO;
  180. return vUnknown3D_GCIO;
  181. }/* str2GCDim */
  182. /* -------------------------------------------------------------------- */
  183. const char GCIOAPI_CALL1(*) GCTypeKind2str_GCIO ( GCTypeKind item )
  184. {
  185. switch (item) {
  186. case vPoint_GCIO :
  187. case vLine_GCIO :
  188. case vText_GCIO :
  189. case vPoly_GCIO :
  190. case vMemoFld_GCIO :
  191. case vIntFld_GCIO :
  192. case vRealFld_GCIO :
  193. case vLengthFld_GCIO :
  194. case vAreaFld_GCIO :
  195. case vPositionFld_GCIO :
  196. case vDateFld_GCIO :
  197. case vTimeFld_GCIO :
  198. case vChoiceFld_GCIO :
  199. case vInterFld_GCIO :
  200. return gkGCTypeKind[item];
  201. default :
  202. return gkGCTypeKind[vUnknownItemType_GCIO];
  203. }
  204. }/* GCTypeKind2str_GCIO */
  205. /* -------------------------------------------------------------------- */
  206. GCTypeKind GCIOAPI_CALL str2GCTypeKind_GCIO ( const char *s )
  207. {
  208. if (strcmp(s,gkGCTypeKind[vPoint_GCIO])==0) return vPoint_GCIO;
  209. if (strcmp(s,gkGCTypeKind[vLine_GCIO])==0) return vLine_GCIO;
  210. if (strcmp(s,gkGCTypeKind[vText_GCIO])==0) return vText_GCIO;
  211. if (strcmp(s,gkGCTypeKind[vPoly_GCIO])==0) return vPoly_GCIO;
  212. if (strcmp(s,gkGCTypeKind[vMemoFld_GCIO])==0) return vMemoFld_GCIO;
  213. if (strcmp(s,gkGCTypeKind[vIntFld_GCIO])==0) return vIntFld_GCIO;
  214. if (strcmp(s,gkGCTypeKind[vRealFld_GCIO])==0) return vRealFld_GCIO;
  215. if (strcmp(s,gkGCTypeKind[vLengthFld_GCIO])==0) return vLengthFld_GCIO;
  216. if (strcmp(s,gkGCTypeKind[vAreaFld_GCIO])==0) return vAreaFld_GCIO;
  217. if (strcmp(s,gkGCTypeKind[vPositionFld_GCIO])==0) return vPositionFld_GCIO;
  218. if (strcmp(s,gkGCTypeKind[vDateFld_GCIO])==0) return vDateFld_GCIO;
  219. if (strcmp(s,gkGCTypeKind[vTimeFld_GCIO])==0) return vTimeFld_GCIO;
  220. if (strcmp(s,gkGCTypeKind[vChoiceFld_GCIO])==0) return vChoiceFld_GCIO;
  221. if (strcmp(s,gkGCTypeKind[vInterFld_GCIO])==0) return vInterFld_GCIO;
  222. return vUnknownItemType_GCIO;
  223. }/* str2GCTypeKind_GCIO */
  224. /* -------------------------------------------------------------------- */
  225. static const char GCIOAPI_CALL1(*) _metaDelimiter2str_GCIO ( char delim )
  226. {
  227. switch( delim ) {
  228. case '\t' :
  229. return "tab";
  230. default :
  231. return "\t";
  232. }
  233. }/* _metaDelimiter2str_GCIO */
  234. /* -------------------------------------------------------------------- */
  235. static long GCIOAPI_CALL _read_GCIO (
  236. GCExportFileH* hGXT
  237. )
  238. {
  239. FILE* h;
  240. long nread;
  241. int c;
  242. char *result;
  243. h= GetGCHandle_GCIO(hGXT);
  244. nread= 0L;
  245. result= GetGCCache_GCIO(hGXT);
  246. SetGCCurrentOffset_GCIO(hGXT, VSIFTell(h));/* keep offset of beginning of lines */
  247. while ((c= VSIFGetc(h))!=EOF)
  248. {
  249. c= (0x00FF & (unsigned char)(c));
  250. switch (c) {
  251. case 0X1A : continue ; /* PC end-of-file */
  252. case '\r' : /* PC '\r\n' line, MAC '\r' */
  253. if ((c= VSIFGetc(h))!='\n')
  254. {
  255. VSIUngetc(c,h);
  256. c= '\n';
  257. }
  258. case '\n' :
  259. SetGCCurrentLinenum_GCIO(hGXT,GetGCCurrentLinenum_GCIO(hGXT)+1L);
  260. if (nread==0L) continue;
  261. *result= '\0';
  262. return nread;
  263. default :
  264. *result= (char)c;
  265. result++;
  266. nread++;
  267. if (nread == kCacheSize_GCIO)
  268. {
  269. CPLError( CE_Failure, CPLE_OutOfMemory,
  270. "Too many characters at line %lu.\n", GetGCCurrentLinenum_GCIO(hGXT));
  271. return EOF;
  272. }
  273. }/* switch */
  274. }/* while */
  275. *result= '\0';
  276. if (c==EOF)
  277. {
  278. SetGCStatus_GCIO(hGXT, vEof_GCIO);
  279. if (nread==0L)
  280. {
  281. return EOF;
  282. }
  283. }
  284. return nread;
  285. }/* _read_GCIO */
  286. /* -------------------------------------------------------------------- */
  287. static long GCIOAPI_CALL _get_GCIO (
  288. GCExportFileH* hGXT
  289. )
  290. {
  291. if (GetGCStatus_GCIO(hGXT)==vEof_GCIO)
  292. {
  293. SetGCCache_GCIO(hGXT,"");
  294. SetGCWhatIs_GCIO(hGXT, vUnknownIO_ItemType_GCIO);
  295. return EOF;
  296. }
  297. if (GetGCStatus_GCIO(hGXT)==vMemoStatus_GCIO)
  298. {
  299. SetGCStatus_GCIO(hGXT, vNoStatus_GCIO);
  300. return GetGCCurrentOffset_GCIO(hGXT);
  301. }
  302. if (_read_GCIO(hGXT)==EOF)
  303. {
  304. SetGCWhatIs_GCIO(hGXT, vUnknownIO_ItemType_GCIO);
  305. return EOF;
  306. }
  307. SetGCWhatIs_GCIO(hGXT, vStdCol_GCIO);
  308. if (strstr(GetGCCache_GCIO(hGXT),kCom_GCIO)==GetGCCache_GCIO(hGXT))
  309. { /* // */
  310. SetGCWhatIs_GCIO(hGXT, vComType_GCIO);
  311. if (strstr(GetGCCache_GCIO(hGXT),kHeader_GCIO)==GetGCCache_GCIO(hGXT))
  312. { /* //# */
  313. SetGCWhatIs_GCIO(hGXT, vHeader_GCIO);
  314. }
  315. else
  316. {
  317. if (strstr(GetGCCache_GCIO(hGXT),kPragma_GCIO)==GetGCCache_GCIO(hGXT))
  318. { /* //$ */
  319. SetGCWhatIs_GCIO(hGXT, vPragma_GCIO);
  320. }
  321. }
  322. }
  323. return GetGCCurrentOffset_GCIO(hGXT);
  324. }/* _get_GCIO */
  325. /* -------------------------------------------------------------------- */
  326. static void GCIOAPI_CALL _InitExtent_GCIO (
  327. GCExtent* theExtent
  328. )
  329. {
  330. theExtent->XUL= HUGE_VAL;
  331. theExtent->YUL= -HUGE_VAL;
  332. theExtent->XLR= -HUGE_VAL;
  333. theExtent->YLR= HUGE_VAL;
  334. }/* _InitExtent_GCIO */
  335. /* -------------------------------------------------------------------- */
  336. GCExtent GCIOAPI_CALL1(*) CreateExtent_GCIO (
  337. double Xmin,
  338. double Ymin,
  339. double Xmax,
  340. double Ymax
  341. )
  342. {
  343. GCExtent* theExtent;
  344. if( !(theExtent= CPLMalloc(sizeof(GCExtent))) )
  345. {
  346. CPLError( CE_Failure, CPLE_OutOfMemory,
  347. "failed to create a Geoconcept extent for '[%g %g,%g %g]'.\n",
  348. Xmin, Ymin,Xmax, Ymax);
  349. return NULL;
  350. }
  351. _InitExtent_GCIO(theExtent);
  352. theExtent->XUL= Xmin;
  353. theExtent->YUL= Ymax;
  354. theExtent->XLR= Xmax;
  355. theExtent->YLR= Ymin;
  356. return theExtent;
  357. }/* CreateExtent_GCIO */
  358. /* -------------------------------------------------------------------- */
  359. static void GCIOAPI_CALL _ReInitExtent_GCIO (
  360. GCExtent* theExtent
  361. )
  362. {
  363. _InitExtent_GCIO(theExtent);
  364. }/* _ReInitExtent_GCIO */
  365. /* -------------------------------------------------------------------- */
  366. void GCIOAPI_CALL DestroyExtent_GCIO (
  367. GCExtent** theExtent
  368. )
  369. {
  370. _ReInitExtent_GCIO(*theExtent);
  371. CPLFree(*theExtent);
  372. *theExtent= NULL;
  373. }/* DestroyExtent_GCIO */
  374. /* -------------------------------------------------------------------- */
  375. static void GCIOAPI_CALL _InitField_GCIO (
  376. GCField* theField
  377. )
  378. {
  379. SetFieldName_GCIO(theField, NULL);
  380. SetFieldID_GCIO(theField, UNDEFINEDID_GCIO);
  381. SetFieldKind_GCIO(theField, vUnknownItemType_GCIO);
  382. SetFieldExtra_GCIO(theField, NULL);
  383. SetFieldList_GCIO(theField, NULL);
  384. }/* _InitField_GCIO */
  385. /* -------------------------------------------------------------------- */
  386. static const char GCIOAPI_CALL1(*) _NormalizeFieldName_GCIO (
  387. const char* name
  388. )
  389. {
  390. if( name[0]=='@' )
  391. {
  392. if( EQUAL(name, "@Identificateur") || EQUAL(name, kIdentifier_GCIO) )
  393. {
  394. return kIdentifier_GCIO;
  395. }
  396. else if( EQUAL(name, "@Type") || EQUAL(name, kClass_GCIO) )
  397. {
  398. return kClass_GCIO;
  399. }
  400. else if( EQUAL(name, "@Sous-type") || EQUAL(name, kSubclass_GCIO) )
  401. {
  402. return kSubclass_GCIO;
  403. }
  404. else if( EQUAL(name, "@Nom") || EQUAL(name, kName_GCIO) )
  405. {
  406. return kName_GCIO;
  407. }
  408. else if( EQUAL(name, kNbFields_GCIO) )
  409. {
  410. return kNbFields_GCIO;
  411. }
  412. else if( EQUAL(name, kX_GCIO) )
  413. {
  414. return kX_GCIO;
  415. }
  416. else if( EQUAL(name, kY_GCIO) )
  417. {
  418. return kY_GCIO;
  419. }
  420. else if( EQUAL(name, "@X'") || EQUAL(name, kXP_GCIO) )
  421. {
  422. return kXP_GCIO;
  423. }
  424. else if( EQUAL(name, "@Y'") || EQUAL(name, kYP_GCIO) )
  425. {
  426. return kYP_GCIO;
  427. }
  428. else if( EQUAL(name, kGraphics_GCIO) )
  429. {
  430. return kGraphics_GCIO;
  431. }
  432. else if( EQUAL(name, kAngle_GCIO) )
  433. {
  434. return kAngle_GCIO;
  435. }
  436. else
  437. {
  438. return name;
  439. }
  440. }
  441. else
  442. {
  443. return name;
  444. }
  445. }/* _NormalizeFieldName_GCIO */
  446. /* -------------------------------------------------------------------- */
  447. static GCField GCIOAPI_CALL1(*) _CreateField_GCIO (
  448. const char* name,
  449. long id,
  450. GCTypeKind knd,
  451. const char* extra,
  452. const char* enums
  453. )
  454. {
  455. GCField* theField;
  456. if( !(theField= CPLMalloc(sizeof(GCField))) )
  457. {
  458. CPLError( CE_Failure, CPLE_OutOfMemory,
  459. "failed to create a Geoconcept field for '%s'.\n",
  460. name);
  461. return NULL;
  462. }
  463. _InitField_GCIO(theField);
  464. SetFieldName_GCIO(theField, CPLStrdup(name));
  465. SetFieldID_GCIO(theField, id);
  466. SetFieldKind_GCIO(theField, knd);
  467. if( extra && extra[0]!='\0' ) SetFieldExtra_GCIO(theField, CPLStrdup(extra));
  468. if( enums && enums[0]!='\0' ) SetFieldList_GCIO(theField, CSLTokenizeString2(enums,";",0));
  469. return theField;
  470. }/* _CreateField_GCIO */
  471. /* -------------------------------------------------------------------- */
  472. static void GCIOAPI_CALL _ReInitField_GCIO (
  473. GCField* theField
  474. )
  475. {
  476. if( GetFieldName_GCIO(theField) )
  477. {
  478. CPLFree(GetFieldName_GCIO(theField));
  479. }
  480. if( GetFieldExtra_GCIO(theField) )
  481. {
  482. CPLFree( GetFieldExtra_GCIO(theField) );
  483. }
  484. if( GetFieldList_GCIO(theField) )
  485. {
  486. CSLDestroy( GetFieldList_GCIO(theField) );
  487. }
  488. _InitField_GCIO(theField);
  489. }/* _ReInitField_GCIO */
  490. /* -------------------------------------------------------------------- */
  491. static void GCIOAPI_CALL _DestroyField_GCIO (
  492. GCField** theField
  493. )
  494. {
  495. _ReInitField_GCIO(*theField);
  496. CPLFree(*theField);
  497. *theField= NULL;
  498. }/* _DestroyField_GCIO */
  499. /* -------------------------------------------------------------------- */
  500. static int GCIOAPI_CALL _findFieldByName_GCIO (
  501. CPLList* fields,
  502. const char* name
  503. )
  504. {
  505. GCField* theField;
  506. if( fields )
  507. {
  508. CPLList* e;
  509. int n, i;
  510. if( (n= CPLListCount(fields))>0 )
  511. {
  512. for( i= 0; i<n; i++)
  513. {
  514. if( (e= CPLListGet(fields,i)) )
  515. {
  516. if( (theField= (GCField*)CPLListGetData(e)) )
  517. {
  518. if( EQUAL(GetFieldName_GCIO(theField),name) )
  519. {
  520. return i;
  521. }
  522. }
  523. }
  524. }
  525. }
  526. }
  527. return -1;
  528. }/* _findFieldByName_GCIO */
  529. /* -------------------------------------------------------------------- */
  530. static GCField GCIOAPI_CALL1(*) _getField_GCIO (
  531. CPLList* fields,
  532. int where
  533. )
  534. {
  535. CPLList* e;
  536. if( (e= CPLListGet(fields,where)) )
  537. return (GCField*)CPLListGetData(e);
  538. return NULL;
  539. }/* _getField_GCIO */
  540. /* -------------------------------------------------------------------- */
  541. static void GCIOAPI_CALL _InitSubType_GCIO (
  542. GCSubType* theSubType
  543. )
  544. {
  545. SetSubTypeGCHandle_GCIO(theSubType, NULL);
  546. SetSubTypeType_GCIO(theSubType, NULL);
  547. SetSubTypeName_GCIO(theSubType, NULL);
  548. SetSubTypeFields_GCIO(theSubType, NULL); /* GCField */
  549. SetSubTypeFeatureDefn_GCIO(theSubType, NULL);
  550. SetSubTypeKind_GCIO(theSubType, vUnknownItemType_GCIO);
  551. SetSubTypeID_GCIO(theSubType, UNDEFINEDID_GCIO);
  552. SetSubTypeDim_GCIO(theSubType, v2D_GCIO);
  553. SetSubTypeNbFields_GCIO(theSubType, -1);
  554. SetSubTypeNbFeatures_GCIO(theSubType, 0L);
  555. SetSubTypeBOF_GCIO(theSubType, -1L);
  556. SetSubTypeBOFLinenum_GCIO(theSubType, 0L);
  557. SetSubTypeExtent_GCIO(theSubType, NULL);
  558. SetSubTypeHeaderWritten_GCIO(theSubType, FALSE);
  559. }/* _InitSubType_GCIO */
  560. /* -------------------------------------------------------------------- */
  561. static GCSubType GCIOAPI_CALL1(*) _CreateSubType_GCIO (
  562. const char* subtypName,
  563. long id,
  564. GCTypeKind knd,
  565. GCDim sys
  566. )
  567. {
  568. GCSubType* theSubType;
  569. if( !(theSubType= CPLMalloc(sizeof(GCSubType))) )
  570. {
  571. CPLError( CE_Failure, CPLE_OutOfMemory,
  572. "failed to create a Geoconcept subtype for '%s'.\n",
  573. subtypName);
  574. return NULL;
  575. }
  576. _InitSubType_GCIO(theSubType);
  577. SetSubTypeName_GCIO(theSubType, CPLStrdup(subtypName));
  578. SetSubTypeID_GCIO(theSubType, id);
  579. SetSubTypeKind_GCIO(theSubType, knd);
  580. SetSubTypeDim_GCIO(theSubType, sys);
  581. return theSubType;
  582. }/* _CreateSubType_GCIO */
  583. /* -------------------------------------------------------------------- */
  584. static void GCIOAPI_CALL _ReInitSubType_GCIO (
  585. GCSubType* theSubType
  586. )
  587. {
  588. if( GetSubTypeFeatureDefn_GCIO(theSubType) )
  589. {
  590. OGR_FD_Release(GetSubTypeFeatureDefn_GCIO(theSubType));
  591. }
  592. if( GetSubTypeFields_GCIO(theSubType) )
  593. {
  594. CPLList* e;
  595. GCField* theField;
  596. int i, n;
  597. if( (n= CPLListCount(GetSubTypeFields_GCIO(theSubType)))>0 )
  598. {
  599. for (i= 0; i<n; i++)
  600. {
  601. if( (e= CPLListGet(GetSubTypeFields_GCIO(theSubType),i)) )
  602. {
  603. if( (theField= (GCField*)CPLListGetData(e)) )
  604. {
  605. _DestroyField_GCIO(&theField);
  606. }
  607. }
  608. }
  609. }
  610. CPLListDestroy(GetSubTypeFields_GCIO(theSubType));
  611. }
  612. if( GetSubTypeName_GCIO(theSubType) )
  613. {
  614. CPLFree( GetSubTypeName_GCIO(theSubType) );
  615. }
  616. if( GetSubTypeExtent_GCIO(theSubType) )
  617. {
  618. DestroyExtent_GCIO(&(GetSubTypeExtent_GCIO(theSubType)));
  619. }
  620. _InitSubType_GCIO(theSubType);
  621. }/* _ReInitSubType_GCIO */
  622. /* -------------------------------------------------------------------- */
  623. static void GCIOAPI_CALL _DestroySubType_GCIO (
  624. GCSubType** theSubType
  625. )
  626. {
  627. _ReInitSubType_GCIO(*theSubType);
  628. CPLFree(*theSubType);
  629. *theSubType= NULL;
  630. }/* _DestroySubType_GCIO */
  631. /* -------------------------------------------------------------------- */
  632. static int GCIOAPI_CALL _findSubTypeByName_GCIO (
  633. GCType* theClass,
  634. const char* subtypName
  635. )
  636. {
  637. GCSubType* theSubType;
  638. if( GetTypeSubtypes_GCIO(theClass) )
  639. {
  640. CPLList* e;
  641. int n, i;
  642. if( (n= CPLListCount(GetTypeSubtypes_GCIO(theClass)))>0 )
  643. {
  644. if( *subtypName=='*' ) return 0;
  645. for( i = 0; i < n; i++)
  646. {
  647. if( (e= CPLListGet(GetTypeSubtypes_GCIO(theClass),i)) )
  648. {
  649. if( (theSubType= (GCSubType*)CPLListGetData(e)) )
  650. {
  651. if( EQUAL(GetSubTypeName_GCIO(theSubType),subtypName) )
  652. {
  653. return i;
  654. }
  655. }
  656. }
  657. }
  658. }
  659. }
  660. return -1;
  661. }/* _findSubTypeByName_GCIO */
  662. /* -------------------------------------------------------------------- */
  663. static GCSubType GCIOAPI_CALL1(*) _getSubType_GCIO (
  664. GCType* theClass,
  665. int where
  666. )
  667. {
  668. CPLList* e;
  669. if( (e= CPLListGet(GetTypeSubtypes_GCIO(theClass),where)) )
  670. return (GCSubType*)CPLListGetData(e);
  671. return NULL;
  672. }/* _getSubType_GCIO */
  673. /* -------------------------------------------------------------------- */
  674. static void GCIOAPI_CALL _InitType_GCIO (
  675. GCType* theClass
  676. )
  677. {
  678. SetTypeName_GCIO(theClass, NULL);
  679. SetTypeSubtypes_GCIO(theClass, NULL);/* GCSubType */
  680. SetTypeFields_GCIO(theClass, NULL); /* GCField */
  681. SetTypeID_GCIO(theClass, UNDEFINEDID_GCIO);
  682. }/* _InitType_GCIO */
  683. /* -------------------------------------------------------------------- */
  684. static GCType GCIOAPI_CALL1(*) _CreateType_GCIO (
  685. const char* typName,
  686. long id
  687. )
  688. {
  689. GCType* theClass;
  690. if( !(theClass= CPLMalloc(sizeof(GCType))) )
  691. {
  692. CPLError( CE_Failure, CPLE_OutOfMemory,
  693. "failed to create a Geoconcept type for '%s#%ld'.\n",
  694. typName, id);
  695. return NULL;
  696. }
  697. _InitType_GCIO(theClass);
  698. SetTypeName_GCIO(theClass, CPLStrdup(typName));
  699. SetTypeID_GCIO(theClass, id);
  700. return theClass;
  701. }/* _CreateType_GCIO */
  702. /* -------------------------------------------------------------------- */
  703. static void GCIOAPI_CALL _ReInitType_GCIO (
  704. GCType* theClass
  705. )
  706. {
  707. if( GetTypeSubtypes_GCIO(theClass) )
  708. {
  709. CPLList* e;
  710. GCSubType* theSubType;
  711. int i, n;
  712. if( (n= CPLListCount(GetTypeSubtypes_GCIO(theClass)))>0 )
  713. {
  714. for (i= 0; i<n; i++)
  715. {
  716. if( (e= CPLListGet(GetTypeSubtypes_GCIO(theClass),i)) )
  717. {
  718. if( (theSubType= (GCSubType*)CPLListGetData(e)) )
  719. {
  720. _DestroySubType_GCIO(&theSubType);
  721. }
  722. }
  723. }
  724. }
  725. CPLListDestroy(GetTypeSubtypes_GCIO(theClass));
  726. }
  727. if( GetTypeFields_GCIO(theClass) )
  728. {
  729. CPLList* e;
  730. GCField* theField;
  731. int i, n;
  732. if( (n= CPLListCount(GetTypeFields_GCIO(theClass)))>0 )
  733. {
  734. for (i= 0; i<n; i++)
  735. {
  736. if( (e= CPLListGet(GetTypeFields_GCIO(theClass),i)) )
  737. {
  738. if( (theField= (GCField*)CPLListGetData(e)) )
  739. {
  740. _DestroyField_GCIO(&theField);
  741. }
  742. }
  743. }
  744. }
  745. CPLListDestroy(GetTypeFields_GCIO(theClass));
  746. }
  747. if( GetTypeName_GCIO(theClass) )
  748. {
  749. CPLFree( GetTypeName_GCIO(theClass) );
  750. }
  751. _InitType_GCIO(theClass);
  752. }/* _ReInitType_GCIO */
  753. /* -------------------------------------------------------------------- */
  754. static void GCIOAPI_CALL _DestroyType_GCIO (
  755. GCType** theClass
  756. )
  757. {
  758. _ReInitType_GCIO(*theClass);
  759. CPLFree(*theClass);
  760. *theClass= NULL;
  761. }/* _DestroyType_GCIO */
  762. /* -------------------------------------------------------------------- */
  763. static int GCIOAPI_CALL _findTypeByName_GCIO (
  764. GCExportFileH* hGXT,
  765. const char* typName
  766. )
  767. {
  768. GCType* theClass;
  769. GCExportFileMetadata* header;
  770. header= GetGCMeta_GCIO(hGXT);
  771. if( GetMetaTypes_GCIO(header) )
  772. {
  773. CPLList* e;
  774. int n, i;
  775. if( (n= CPLListCount(GetMetaTypes_GCIO(header)))>0 )
  776. {
  777. if( *typName=='*' ) return 0;
  778. for( i = 0; i < n; i++)
  779. {
  780. if( (e= CPLListGet(GetMetaTypes_GCIO(header),i)) )
  781. {
  782. if( (theClass= (GCType*)CPLListGetData(e)) )
  783. {
  784. if( EQUAL(GetTypeName_GCIO(theClass),typName) )
  785. {
  786. return i;
  787. }
  788. }
  789. }
  790. }
  791. }
  792. }
  793. return -1;
  794. }/* _findTypeByName_GCIO */
  795. /* -------------------------------------------------------------------- */
  796. static GCType GCIOAPI_CALL1(*) _getType_GCIO (
  797. GCExportFileH* hGXT,
  798. int where
  799. )
  800. {
  801. CPLList* e;
  802. if( (e= CPLListGet(GetMetaTypes_GCIO(GetGCMeta_GCIO(hGXT)),where)) )
  803. return (GCType*)CPLListGetData(e);
  804. return NULL;
  805. }/* _getType_GCIO */
  806. /* -------------------------------------------------------------------- */
  807. static void GCIOAPI_CALL _InitHeader_GCIO (
  808. GCExportFileMetadata* header
  809. )
  810. {
  811. SetMetaVersion_GCIO(header, NULL);
  812. SetMetaDelimiter_GCIO(header, kTAB_GCIO[0]);
  813. SetMetaQuotedText_GCIO(header, FALSE);
  814. SetMetaCharset_GCIO(header, vANSI_GCIO);
  815. SetMetaUnit_GCIO(header, "m");
  816. SetMetaFormat_GCIO(header, 2);
  817. SetMetaSysCoord_GCIO(header, NULL); /* GCSysCoord */
  818. SetMetaSRS_GCIO(header, NULL);
  819. SetMetaTypes_GCIO(header, NULL); /* GCType */
  820. SetMetaFields_GCIO(header, NULL); /* GCField */
  821. SetMetaResolution_GCIO(header, 0.1);
  822. SetMetaExtent_GCIO(header, NULL);
  823. }/* _InitHeader_GCIO */
  824. /* -------------------------------------------------------------------- */
  825. GCExportFileMetadata GCIOAPI_CALL1(*) CreateHeader_GCIO ( )
  826. {
  827. GCExportFileMetadata* m;
  828. if( !(m= CPLMalloc(sizeof(GCExportFileMetadata)) ) )
  829. {
  830. CPLError( CE_Failure, CPLE_OutOfMemory,
  831. "failed to create Geoconcept metadata.\n");
  832. return NULL;
  833. }
  834. _InitHeader_GCIO(m);
  835. return m;
  836. }/* CreateHeader_GCIO */
  837. /* -------------------------------------------------------------------- */
  838. static void GCIOAPI_CALL _ReInitHeader_GCIO (
  839. GCExportFileMetadata* header
  840. )
  841. {
  842. if( GetMetaVersion_GCIO(header) )
  843. {
  844. CPLFree( GetMetaVersion_GCIO(header) );
  845. }
  846. if( GetMetaExtent_GCIO(header) )
  847. {
  848. DestroyExtent_GCIO(&(GetMetaExtent_GCIO(header)));
  849. }
  850. if( GetMetaTypes_GCIO(header) )
  851. {
  852. CPLList* e;
  853. GCType* theClass;
  854. int i, n;
  855. if( (n= CPLListCount(GetMetaTypes_GCIO(header)))>0 )
  856. {
  857. for (i= 0; i<n; i++)
  858. {
  859. if( (e= CPLListGet(GetMetaTypes_GCIO(header),i)) )
  860. {
  861. if( (theClass= (GCType*)CPLListGetData(e)) )
  862. {
  863. _DestroyType_GCIO(&theClass);
  864. }
  865. }
  866. }
  867. }
  868. CPLListDestroy(GetMetaTypes_GCIO(header));
  869. }
  870. if( GetMetaFields_GCIO(header) )
  871. {
  872. CPLList* e;
  873. GCField* theField;
  874. int i, n;
  875. if( (n= CPLListCount(GetMetaFields_GCIO(header)))>0 )
  876. {
  877. for (i= 0; i<n; i++)
  878. {
  879. if( (e= CPLListGet(GetMetaFields_GCIO(header),i)) )
  880. {
  881. if( (theField= (GCField*)CPLListGetData(e)) )
  882. {
  883. _DestroyField_GCIO(&theField);
  884. }
  885. }
  886. }
  887. }
  888. CPLListDestroy(GetMetaFields_GCIO(header));
  889. }
  890. if( GetMetaSRS_GCIO(header) )
  891. {
  892. OSRRelease( GetMetaSRS_GCIO(header) );
  893. }
  894. if( GetMetaSysCoord_GCIO(header) )
  895. {
  896. DestroySysCoord_GCSRS(&(GetMetaSysCoord_GCIO(header)));
  897. }
  898. _InitHeader_GCIO(header);
  899. }/* _ReInitHeader_GCIO */
  900. /* -------------------------------------------------------------------- */
  901. void GCIOAPI_CALL DestroyHeader_GCIO (
  902. GCExportFileMetadata** m
  903. )
  904. {
  905. _ReInitHeader_GCIO(*m);
  906. CPLFree(*m);
  907. *m= NULL;
  908. }/* DestroyHeader_GCIO */
  909. /* -------------------------------------------------------------------- */
  910. static void GCIOAPI_CALL _Init_GCIO (
  911. GCExportFileH* H
  912. )
  913. {
  914. SetGCCache_GCIO(H,"");
  915. SetGCPath_GCIO(H, NULL);
  916. SetGCBasename_GCIO(H, NULL);
  917. SetGCExtension_GCIO(H, NULL);
  918. SetGCHandle_GCIO(H, NULL);
  919. SetGCCurrentOffset_GCIO(H, 0L);
  920. SetGCCurrentLinenum_GCIO(H, 0L);
  921. SetGCNbObjects_GCIO(H, 0L);
  922. SetGCMeta_GCIO(H, NULL);
  923. SetGCMode_GCIO(H, vNoAccess_GCIO);
  924. SetGCStatus_GCIO(H, vNoStatus_GCIO);
  925. SetGCWhatIs_GCIO(H, vUnknownIO_ItemType_GCIO);
  926. }/* _Init_GCIO */
  927. /* -------------------------------------------------------------------- */
  928. static GCExportFileH GCIOAPI_CALL1(*) _Create_GCIO (
  929. const char* pszGeoconceptFile,
  930. const char *ext,
  931. const char* mode
  932. )
  933. {
  934. GCExportFileH* hGXT;
  935. if( !(hGXT= CPLMalloc(sizeof(GCExportFileH)) ) )
  936. {
  937. CPLError( CE_Failure, CPLE_OutOfMemory,
  938. "failed to create a Geoconcept handle for '%s' (%s).\n",
  939. pszGeoconceptFile, mode);
  940. return NULL;
  941. }
  942. _Init_GCIO(hGXT);
  943. SetGCPath_GCIO(hGXT, CPLStrdup(CPLGetDirname(pszGeoconceptFile)));
  944. SetGCBasename_GCIO(hGXT, CPLStrdup(CPLGetBasename(pszGeoconceptFile)));
  945. SetGCExtension_GCIO(hGXT, CPLStrdup(ext? ext:"gxt"));
  946. SetGCMode_GCIO(hGXT, (mode[0]=='w'? vWriteAccess_GCIO : (mode[0]=='a'? vUpdateAccess_GCIO:vReadAccess_GCIO)));
  947. return hGXT;
  948. }/* _Create_GCIO */
  949. /* -------------------------------------------------------------------- */
  950. static void GCIOAPI_CALL _ReInit_GCIO (
  951. GCExportFileH* hGXT
  952. )
  953. {
  954. if( GetGCMeta_GCIO(hGXT) )
  955. {
  956. DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
  957. }
  958. if( GetGCHandle_GCIO(hGXT) )
  959. {
  960. VSIFClose(GetGCHandle_GCIO(hGXT));
  961. }
  962. if( GetGCExtension_GCIO(hGXT) )
  963. {
  964. CPLFree(GetGCExtension_GCIO(hGXT));
  965. }
  966. if( GetGCBasename_GCIO(hGXT) )
  967. {
  968. CPLFree(GetGCBasename_GCIO(hGXT));
  969. }
  970. if( GetGCPath_GCIO(hGXT) )
  971. {
  972. CPLFree(GetGCPath_GCIO(hGXT));
  973. }
  974. SetGCCache_GCIO(hGXT,"");
  975. _Init_GCIO(hGXT);
  976. }/* _ReInit_GCIO */
  977. /* -------------------------------------------------------------------- */
  978. static void GCIOAPI_CALL _Destroy_GCIO (
  979. GCExportFileH** hGXT,
  980. int delFile
  981. )
  982. {
  983. if( delFile && GetGCMode_GCIO(*hGXT)==vWriteAccess_GCIO )
  984. {
  985. VSIFClose(GetGCHandle_GCIO(*hGXT));
  986. SetGCHandle_GCIO(*hGXT, NULL);
  987. VSIUnlink(CPLFormFilename(GetGCPath_GCIO(*hGXT),GetGCBasename_GCIO(*hGXT),GetGCExtension_GCIO(*hGXT)));
  988. }
  989. _ReInit_GCIO(*hGXT);
  990. CPLFree(*hGXT);
  991. *hGXT= NULL;
  992. }/* _Destroy_GCIO */
  993. /* -------------------------------------------------------------------- */
  994. static int _checkSchema_GCIO (
  995. GCExportFileH* hGXT
  996. )
  997. {
  998. GCExportFileMetadata* Meta;
  999. int nT, iT, nS, iS, nF, iF, nU, iId, iCl, iSu, iNa, iNb, iX, iY, iXP, iYP, iGr, iAn;
  1000. GCField* theField;
  1001. GCSubType* theSubType;
  1002. GCType* theClass;
  1003. CPLList* e;
  1004. if( !(Meta= GetGCMeta_GCIO(hGXT)) )
  1005. {
  1006. return TRUE; /* FIXME */
  1007. }
  1008. if( (nT= CPLListCount(GetMetaTypes_GCIO(Meta)))==0 )
  1009. {
  1010. CPLError( CE_Failure, CPLE_AppDefined,
  1011. "Geoconcept schema without types!\n" );
  1012. return FALSE;
  1013. }
  1014. for (iT= 0; iT<nT; iT++)
  1015. {
  1016. if( (e= CPLListGet(GetMetaTypes_GCIO(Meta),iT)) )
  1017. {
  1018. if( (theClass= (GCType*)CPLListGetData(e)) )
  1019. {
  1020. if( (nS= CPLListCount(GetTypeSubtypes_GCIO(theClass)))==0 )
  1021. {
  1022. CPLError( CE_Failure, CPLE_AppDefined,
  1023. "Geoconcept type %s without sub-types!\n",
  1024. GetTypeName_GCIO(theClass) );
  1025. return FALSE;
  1026. }
  1027. for (iS= 0; iS<nS; iS++)
  1028. {
  1029. if( (e= CPLListGet(GetTypeSubtypes_GCIO(theClass),iS)) )
  1030. {
  1031. if( (theSubType= (GCSubType*)CPLListGetData(e)) )
  1032. {
  1033. if( (nF= CPLListCount(GetSubTypeFields_GCIO(theSubType)))==0 )
  1034. {
  1035. CPLError( CE_Failure, CPLE_AppDefined,
  1036. "Geoconcept sub-type %s.%s without fields!\n",
  1037. GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1038. return FALSE;
  1039. }
  1040. nU= 0;
  1041. iId= iCl= iSu= iNa= iNb= iX= iY= iXP= iYP= iGr= iAn= -1;
  1042. for (iF= 0; iF<nF; iF++)
  1043. {
  1044. if( (e= CPLListGet(GetSubTypeFields_GCIO(theSubType),iF)) )
  1045. {
  1046. if( (theField= (GCField*)CPLListGetData(e)) )
  1047. {
  1048. if( IsPrivateField_GCIO(theField) )
  1049. {
  1050. if( EQUAL(GetFieldName_GCIO(theField),kIdentifier_GCIO) )
  1051. iId= iF;
  1052. else if( EQUAL(GetFieldName_GCIO(theField),kClass_GCIO) )
  1053. iCl= iF;
  1054. else if( EQUAL(GetFieldName_GCIO(theField),kSubclass_GCIO) )
  1055. iSu= iF;
  1056. else if( EQUAL(GetFieldName_GCIO(theField),kName_GCIO) )
  1057. iNa= iF;
  1058. else if( EQUAL(GetFieldName_GCIO(theField),kNbFields_GCIO) )
  1059. iNb= iF;
  1060. else if( EQUAL(GetFieldName_GCIO(theField),kX_GCIO) )
  1061. iX= iF;
  1062. else if( EQUAL(GetFieldName_GCIO(theField),kY_GCIO) )
  1063. iY= iF;
  1064. else if( EQUAL(GetFieldName_GCIO(theField),kXP_GCIO) )
  1065. iXP= iF;
  1066. else if( EQUAL(GetFieldName_GCIO(theField),kYP_GCIO) )
  1067. iYP= iF;
  1068. else if( EQUAL(GetFieldName_GCIO(theField),kGraphics_GCIO) )
  1069. iGr= iF;
  1070. else if( EQUAL(GetFieldName_GCIO(theField),kAngle_GCIO) )
  1071. iAn= iF;
  1072. }
  1073. else
  1074. {
  1075. nU++;
  1076. }
  1077. }
  1078. }
  1079. }
  1080. if( iId==-1 )
  1081. {
  1082. CPLError( CE_Failure, CPLE_AppDefined,
  1083. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1084. kIdentifier_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1085. return FALSE;
  1086. }
  1087. else if( iId!=0 )
  1088. {
  1089. CPLError( CE_Failure, CPLE_AppDefined,
  1090. "Geoconcept mandatory field %s must be the first field of %s.%s!\n",
  1091. kIdentifier_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1092. return FALSE;
  1093. }
  1094. if( iCl==-1 )
  1095. {
  1096. CPLError( CE_Failure, CPLE_AppDefined,
  1097. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1098. kClass_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1099. return FALSE;
  1100. }
  1101. else if( iCl-iId!=1 )
  1102. {
  1103. CPLError( CE_Failure, CPLE_AppDefined,
  1104. "Geoconcept mandatory field %s must be the second field of %s.%s!\n",
  1105. kClass_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1106. return FALSE;
  1107. }
  1108. if( iSu==-1 )
  1109. {
  1110. CPLError( CE_Failure, CPLE_AppDefined,
  1111. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1112. kSubclass_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1113. return FALSE;
  1114. }
  1115. else if( iSu-iCl!=1 )
  1116. {
  1117. CPLError( CE_Failure, CPLE_AppDefined,
  1118. "Geoconcept mandatory field %s must be the third field of %s.%s!\n",
  1119. kSubclass_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1120. return FALSE;
  1121. }
  1122. if (iNa==-1 )
  1123. {
  1124. CPLError( CE_Failure, CPLE_AppDefined,
  1125. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1126. kName_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1127. return FALSE;
  1128. }
  1129. else if( iNa-iSu!=1)
  1130. {
  1131. CPLError( CE_Failure, CPLE_AppDefined,
  1132. "Geoconcept mandatory field %s must be the forth field of %s.%s!\n",
  1133. kName_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1134. return FALSE;
  1135. }
  1136. if( iNb==-1 )
  1137. {
  1138. CPLError( CE_Failure, CPLE_AppDefined,
  1139. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1140. kNbFields_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1141. return FALSE;
  1142. }
  1143. if( iX==-1 )
  1144. {
  1145. CPLError( CE_Failure, CPLE_AppDefined,
  1146. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1147. kX_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1148. return FALSE;
  1149. }
  1150. if( iY==-1 )
  1151. {
  1152. CPLError( CE_Failure, CPLE_AppDefined,
  1153. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1154. kY_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1155. return FALSE;
  1156. }
  1157. if( iY-iX!=1 )
  1158. {
  1159. CPLError( CE_Failure, CPLE_AppDefined,
  1160. "Geoconcept geometry fields %s, %s must be consecutive for %s.%s!\n",
  1161. kX_GCIO, kY_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1162. return FALSE;
  1163. }
  1164. if( GetSubTypeKind_GCIO(theSubType)==vLine_GCIO )
  1165. {
  1166. if( iXP==-1 )
  1167. {
  1168. CPLError( CE_Failure, CPLE_AppDefined,
  1169. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1170. kXP_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1171. return FALSE;
  1172. }
  1173. if( iYP==-1 )
  1174. {
  1175. CPLError( CE_Failure, CPLE_AppDefined,
  1176. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1177. kYP_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1178. return FALSE;
  1179. }
  1180. if( iYP-iXP!=1 )
  1181. {
  1182. CPLError( CE_Failure, CPLE_AppDefined,
  1183. "Geoconcept geometry fields %s, %s must be consecutive for %s.%s!\n",
  1184. kXP_GCIO, kYP_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1185. return FALSE;
  1186. }
  1187. if( iXP-iY!=1 )
  1188. {
  1189. CPLError( CE_Failure, CPLE_AppDefined,
  1190. "Geoconcept geometry fields %s, %s, %s, %s must be consecutive for %s.%s!\n",
  1191. kX_GCIO, kY_GCIO, kXP_GCIO, kYP_GCIO,
  1192. GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1193. return FALSE;
  1194. }
  1195. }
  1196. else
  1197. {
  1198. if( iXP!=-1 )
  1199. {
  1200. CPLError( CE_Failure, CPLE_AppDefined,
  1201. "Geoconcept sub-type %s.%s has a mandatory field %s only required on linear type!\n",
  1202. GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType), kXP_GCIO );
  1203. return FALSE;
  1204. }
  1205. if( iYP!=-1 )
  1206. {
  1207. CPLError( CE_Failure, CPLE_AppDefined,
  1208. "Geoconcept sub-type %s.%s has a mandatory field %s only required on linear type!\n",
  1209. GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType), kYP_GCIO );
  1210. return FALSE;
  1211. }
  1212. }
  1213. if( GetSubTypeKind_GCIO(theSubType)==vLine_GCIO ||
  1214. GetSubTypeKind_GCIO(theSubType)==vPoly_GCIO )
  1215. {
  1216. if( iGr==-1 )
  1217. {
  1218. CPLError( CE_Failure, CPLE_AppDefined,
  1219. "Geoconcept mandatory field %s is missing on %s.%s!\n",
  1220. kGraphics_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1221. return FALSE;
  1222. }
  1223. else
  1224. {
  1225. if( (iYP!=-1 && iGr-iYP!=1) || (iGr-iY!=1) )
  1226. {
  1227. CPLError( CE_Failure, CPLE_AppDefined,
  1228. "Geoconcept geometry fields %s, %s must be consecutive for %s.%s!\n",
  1229. iYP!=-1? kYP_GCIO:kY_GCIO, kGraphics_GCIO, GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType) );
  1230. return FALSE;
  1231. }
  1232. }
  1233. if( iAn!=-1 )
  1234. {
  1235. CPLError( CE_Failure, CPLE_AppDefined,
  1236. "Geoconcept sub-type %s.%s has a field %s only required on ponctual or text type!\n",
  1237. GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType), kAngle_GCIO );
  1238. return FALSE;
  1239. }
  1240. }
  1241. else
  1242. {
  1243. if( iGr!=-1 )
  1244. {
  1245. CPLError( CE_Failure, CPLE_AppDefined,
  1246. "Geoconcept sub-type %s.%s has a mandatory field %s only required on linear or polygonal type!\n",
  1247. GetTypeName_GCIO(theClass), GetSubTypeName_GCIO(theSubType), kGraphics_GCIO );
  1248. return FALSE;
  1249. }
  1250. }
  1251. SetSubTypeNbFields_GCIO(theSubType,nU);
  1252. SetSubTypeGCHandle_GCIO(theSubType,hGXT);
  1253. }
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. return TRUE;
  1260. }/* _checkSchema_GCIO */
  1261. /* -------------------------------------------------------------------- */
  1262. static GCExportFileMetadata GCIOAPI_CALL1(*) _parsePragma_GCIO (
  1263. GCExportFileH* hGXT
  1264. )
  1265. {
  1266. GCExportFileMetadata* Meta;
  1267. char* p, *e;
  1268. Meta= GetGCMeta_GCIO(hGXT);
  1269. if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataVERSION_GCIO))!=NULL )
  1270. {
  1271. /* //$VERSION char* */
  1272. p+= strlen(kMetadataVERSION_GCIO);
  1273. while( isspace(*p) ) p++;
  1274. e= p;
  1275. while( isalpha(*p) ) p++;
  1276. *p= '\0';
  1277. SetMetaVersion_GCIO(Meta,CPLStrdup(e));
  1278. return Meta;
  1279. }
  1280. if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataDELIMITER_GCIO))!=NULL )
  1281. {
  1282. /* //$DELIMITER "char*" */
  1283. if( (p= strchr(p,'"')) )
  1284. {
  1285. p++;
  1286. e= p;
  1287. while( *p!='"' && *p!='\0' ) p++;
  1288. *p= '\0';
  1289. if( !( EQUAL(e,"tab") || EQUAL(e,kTAB_GCIO) ) )
  1290. {
  1291. CPLDebug("GEOCONCEPT","%s%s only supports \"tab\" value",
  1292. kPragma_GCIO, kMetadataDELIMITER_GCIO);
  1293. SetMetaDelimiter_GCIO(Meta,kTAB_GCIO[0]);
  1294. } else {
  1295. SetMetaDelimiter_GCIO(Meta,kTAB_GCIO[0]);
  1296. }
  1297. }
  1298. return Meta;
  1299. }
  1300. if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataQUOTEDTEXT_GCIO))!=NULL )
  1301. {
  1302. /* //$QUOTED-TEXT "char*" */
  1303. if( (p= strchr(p,'"')) )
  1304. {
  1305. p++;
  1306. e= p;
  1307. while( *p!='"' && *p!='\0' ) p++;
  1308. *p= '\0';
  1309. if( EQUAL(e,"no") )
  1310. {
  1311. SetMetaQuotedText_GCIO(Meta,FALSE);
  1312. }
  1313. else
  1314. {
  1315. SetMetaQuotedText_GCIO(Meta,TRUE);
  1316. }
  1317. }
  1318. return Meta;
  1319. }
  1320. if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataCHARSET_GCIO))!=NULL )
  1321. {
  1322. /* //$CHARSET char* */
  1323. p+= strlen(kMetadataCHARSET_GCIO);
  1324. while( isspace(*p) ) p++;
  1325. e= p;
  1326. while( isalpha(*p) ) p++;
  1327. *p= '\0';
  1328. SetMetaCharset_GCIO(Meta,str2GCCharset_GCIO(e));
  1329. return Meta;
  1330. }
  1331. if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataUNIT_GCIO))!=NULL )
  1332. {
  1333. /* //$UNIT Distance|Angle:char* */
  1334. if( (p= strchr(p,':')) )
  1335. {
  1336. p++;
  1337. while( isspace(*p) ) p++;
  1338. e= p;
  1339. while( isalpha(*p) || *p=='.' ) p++;
  1340. *p= '\0';
  1341. SetMetaUnit_GCIO(Meta,e);/* FIXME : check value ? */
  1342. }
  1343. return Meta;
  1344. }
  1345. if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataFORMAT_GCIO))!=NULL )
  1346. {
  1347. /* //$FORMAT 1|2 */
  1348. p+= strlen(kMetadataFORMAT_GCIO);
  1349. while( isspace(*p) ) p++;
  1350. e= p;
  1351. if( *e=='1' )
  1352. {
  1353. SetMetaFormat_GCIO(Meta,1);
  1354. }
  1355. else
  1356. {
  1357. SetMetaFormat_GCIO(Meta,2);
  1358. }
  1359. return Meta;
  1360. }
  1361. if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataSYSCOORD_GCIO))!=NULL )
  1362. {
  1363. int v, z;
  1364. GCSysCoord* syscoord;
  1365. /* //$SYSCOORD {Type: int} [ ; { TimeZone: TimeZoneValue } ] */
  1366. v= -1, z= -1;
  1367. if( (p= strchr(p,':')) )
  1368. {
  1369. p++;
  1370. while( isspace(*p) ) p++;
  1371. e= p;
  1372. if( *p=='-') p++; /* allow -1 as SysCoord */
  1373. while( isdigit(*p) ) p++;
  1374. *p= '\0';
  1375. if( sscanf(e,"%d",&v)!= 1 )
  1376. {
  1377. DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
  1378. CPLError( CE_Failure, CPLE_AppDefined,
  1379. "Invalid SRS identifier. "
  1380. "Geoconcept export syntax error at line %ld.",
  1381. GetGCCurrentLinenum_GCIO(hGXT) );
  1382. return NULL;
  1383. }
  1384. if( (p= strrchr(GetGCCache_GCIO(hGXT),';')) )
  1385. {
  1386. if( (p= strchr(p,':')) )
  1387. {
  1388. p++;
  1389. while( isspace(*p) ) p++;
  1390. e= p;
  1391. if( *p=='-') p++; /* allow -1 as TimeZone */
  1392. while( isdigit(*p) ) p++;
  1393. *p= '\0';
  1394. if( sscanf(e,"%d",&z)!= 1 )
  1395. {
  1396. DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
  1397. CPLError( CE_Failure, CPLE_AppDefined,
  1398. "Invalid TimeZone. "
  1399. "Geoconcept export syntax error at line %ld.",
  1400. GetGCCurrentLinenum_GCIO(hGXT) );
  1401. return NULL;
  1402. }
  1403. }
  1404. }
  1405. if( !(syscoord= CreateSysCoord_GCSRS(v,z)) )
  1406. {
  1407. DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
  1408. return NULL;
  1409. }
  1410. SetMetaSysCoord_GCIO(Meta,syscoord);
  1411. }
  1412. return Meta;
  1413. }
  1414. if( (p= strstr(GetGCCache_GCIO(hGXT),kMetadataFIELDS_GCIO))!=NULL )
  1415. {
  1416. char **kv, **vl, *nm, **fl;
  1417. int whereClass, v, i, n;
  1418. GCType* theClass;
  1419. GCSubType* theSubType;
  1420. GCField* theField;
  1421. /* //$FIELDS Class=char*;Subclass=char*;Kind=1..4;Fields=(Private#)?char*\s((Private#)?char*)* */
  1422. p+= strlen(kMetadataFIELDS_GCIO);
  1423. while( isspace(*p) ) p++;
  1424. kv= CSLTokenizeString2(p,";",0);
  1425. if( !kv || CSLCount(kv)!=4 )
  1426. {
  1427. CSLDestroy(kv);
  1428. DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
  1429. CPLError( CE_Failure, CPLE_AppDefined,
  1430. "Geoconcept export syntax error at line %ld.\n",
  1431. GetGCCurrentLinenum_GCIO(hGXT) );
  1432. return NULL;
  1433. }
  1434. /* Class=char* */
  1435. vl= CSLTokenizeString2(kv[0],"=",0);
  1436. if( !vl || CSLCount(vl)!=2 )
  1437. {
  1438. CSLDestroy(vl);
  1439. CSLDestroy(kv);
  1440. DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
  1441. CPLError( CE_Failure, CPLE_AppDefined,
  1442. "Geoconcept export syntax error at line %ld.\n",
  1443. GetGCCurrentLinenum_GCIO(hGXT) );
  1444. return NULL;
  1445. }
  1446. if( !EQUAL(vl[0], "Class") )
  1447. {
  1448. CSLDestroy(vl);
  1449. CSLDestroy(kv);
  1450. DestroyHeader_GCIO(&(GetGCMeta_GCIO(hGXT)));
  1451. CPLError( CE_Failure, CPLE_AppDefined,
  1452. "'Class' expected.\n"
  1453. "Geoconcept export syntax er…

Large files files are truncated, but you can click here to view the full file