1 /**********************************************************************
2  * $Id: avc.h 8c2da2c75918f3f65f0046acaebdbc929e6c162b 2018-06-24 14:47:47 +0200 Even Rouault $
3  *
4  * Name:     avc.h
5  * Project:  Arc/Info Vector coverage (AVC) BIN<->E00 conversion library
6  * Language: ANSI C
7  * Purpose:  Header file containing all definitions for the library.
8  * Author:   Daniel Morissette, dmorissette@dmsolutions.ca
9  *
10  **********************************************************************
11  * Copyright (c) 1999-2001, Daniel Morissette
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining a
14  * copy of this software and associated documentation files (the "Software"),
15  * to deal in the Software without restriction, including without limitation
16  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17  * and/or sell copies of the Software, and to permit persons to whom the
18  * Software is furnished to do so, subject to the following conditions:
19  *
20  * The above copyright notice and this permission notice shall be included
21  * in all copies or substantial portions of the Software.
22  *
23  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
26  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29  * DEALINGS IN THE SOFTWARE.
30  **********************************************************************
31  *
32  * $Log: avc.h,v $
33  * Revision 1.25  2008/07/23 20:51:38  dmorissette
34  * Fixed GCC 4.1.x compile warnings related to use of char vs unsigned char
35  * (GDAL/OGR ticket http://trac.osgeo.org/gdal/ticket/2495)
36  *
37  * Revision 1.24  2006/08/17 20:09:45  dmorissette
38  * Update for 2.0.0 release
39  *
40  * Revision 1.23  2006/08/17 18:56:42  dmorissette
41  * Support for reading standalone info tables (just tables, no coverage
42  * data) by pointing AVCE00ReadOpen() to the info directory (bug 1549).
43  *
44  * Revision 1.22  2006/06/27 18:38:43  dmorissette
45  * Cleaned up E00 reading (bug 1497, patch from James F.)
46  *
47  * Revision 1.21  2006/06/16 11:48:11  daniel
48  * New functions to read E00 files directly as opposed to translating to
49  * binary coverage. Used in the implementation of E00 read support in OGR.
50  * Contributed by James E. Flemer. (bug 1497)
51  *
52  * Revision 1.20  2006/06/14 16:31:28  daniel
53  * Added support for AVCCoverPC2 type (bug 1491)
54  *
55  * Revision 1.19  2005/06/03 03:49:58  daniel
56  * Update email address, website url, and copyright dates
57  *
58  * Revision 1.18  2005/06/03 03:29:16  daniel
59  * Ready for 1.3.0 release
60  *
61  * Revision 1.17  2004/02/11 05:49:44  daniel
62  * Added support for deleted flag in arc.dir (bug 2332)
63  *
64  * Revision 1.16  2002/02/14 16:34:15  warmerda
65  * fixed prototype name for AVCBinReadNextPrj
66  *
67  * Revision 1.15  2002/02/13 20:35:24  warmerda
68  * added AVCBinReadObject
69  *
70  * Revision 1.14  2001/11/25 21:15:23  daniel
71  * Added hack (AVC_MAP_TYPE40_TO_DOUBLE) to map type 40 fields bigger than 8
72  * digits to double precision as we generate E00 output (bug599)
73  *
74  * Revision 1.13  2001/02/20 15:24:11  daniel
75  * Updated AVC_VERSION="1.2.0 (2000-10-17)"
76  *
77  * Revision 1.12  2000/09/26 21:38:44  daniel
78  * Updated AVC_VERSION
79  *
80  * Revision 1.11  2000/09/26 20:21:04  daniel
81  * Added AVCCoverPC write
82  *
83  * Revision 1.10  2000/09/22 19:45:20  daniel
84  * Switch to MIT-style license
85  *
86  * Revision 1.9  2000/05/29 15:31:30  daniel
87  * Added Japanese DBCS support
88  *
89  * Revision 1.8  2000/01/10 02:56:01  daniel
90  * Added read support for "weird" coverages
91  *
92  * Revision 1.7  1999/12/24 07:18:34  daniel
93  * Added PC Arc/Info coverages support
94  *
95  * Revision 1.6  1999/08/23 18:15:56  daniel
96  * Added AVCE00DeleteCoverage()
97  *
98  * Revision 1.5  1999/06/08 22:07:28  daniel
99  * Added AVCReadWrite in AVCAccess type
100  *
101  * Revision 1.4  1999/05/17 16:16:41  daniel
102  * Added RXP + TXT/TX6/TX7 write support
103  *
104  * Revision 1.3  1999/05/11 02:15:04  daniel
105  * Added coverage write support
106  *
107  * Revision 1.2  1999/02/25 03:39:39  daniel
108  * Added TXT, TX6/TX7, RXP and RPL support
109  *
110  * Revision 1.1  1999/01/29 16:29:24  daniel
111  * Initial revision
112  *
113  **********************************************************************/
114 
115 #ifndef AVC_H_INCLUDED_
116 #define AVC_H_INCLUDED_
117 
118 #include "cpl_conv.h"
119 #include "cpl_string.h"
120 
121 #ifdef GDAL_COMPILATION
122 #ifdef RENAME_INTERNAL_SHAPELIB_SYMBOLS
123 #include "gdal_shapelib_symbol_rename.h"
124 #endif
125 #include "shapefil.h"
126 #else
127 #include "dbfopen.h"
128 #endif
129 
130 #include "avc_mbyte.h"
131 
132 CPL_C_START
133 
134 /*---------------------------------------------------------------------
135  * Current version of the AVCE00 library... always useful!
136  *--------------------------------------------------------------------*/
137 #define AVC_VERSION "2.0.0 (2006-08-17)"
138 
139 /* Coverage precision
140  */
141 #define AVC_DEFAULT_PREC   0
142 #define AVC_SINGLE_PREC    1
143 #define AVC_DOUBLE_PREC    2
144 
145 /* AVC_FORMAT_DBF_FLOAT used as nPrecision value only for AVCPrintRealValue()
146  */
147 #define AVC_FORMAT_DBF_FLOAT  42
148 
149 /* Coverage file types
150  */
151 typedef enum
152 {
153     AVCFileUnknown = 0,
154     AVCFileARC,
155     AVCFilePAL,
156     AVCFileCNT,
157     AVCFileLAB,
158     AVCFilePRJ,
159     AVCFileTOL,
160     AVCFileLOG,
161     AVCFileTXT,  /* TXT and TX6 share the same binary format */
162     AVCFileTX6,
163     AVCFileRXP,
164     AVCFileRPL,  /* RPL is a PAL for a region */
165     AVCFileTABLE
166 }AVCFileType;
167 
168 /* Read or Write access flag
169  */
170 typedef enum
171 {
172     AVCRead,
173     AVCWrite,
174     AVCReadWrite
175 } AVCAccess;
176 
177 /* Coverage type: PC Arc/Info or Unix Arc/Info v7
178  */
179 typedef enum
180 {
181     AVCCoverTypeUnknown = 0,
182     AVCCoverV7,
183     AVCCoverPC,
184     AVCCoverPC2,   /* Unknown version... hybrid between V7 and PC !!! */
185     AVCCoverWeird, /* Unknown version... hybrid between V7 and PC !!! */
186     AVCCoverV7Tables /* Standalone tables, only an info directory     */
187 } AVCCoverType;
188 
189 /* Enum for byte ordering
190  */
191 typedef enum
192 {
193     AVCBigEndian,    /* CPL_MSB, Motorola ordering */
194     AVCLittleEndian  /* CPL_LSB, Intel ordering */
195 } AVCByteOrder;
196 
197 /* Macros to establish byte ordering for each coverage type
198  * The rule until now: all coverage types use big endian (Motorola ordering)
199  * except PC Arc/Info coverages variant 1 (AVCCoverPC).
200  */
201 #define AVC_COVER_BYTE_ORDER(cover_type)  \
202    (((cover_type) == AVCCoverPC ) ? AVCLittleEndian : AVCBigEndian )
203 
204 /*=====================================================================
205                         Structures
206  =====================================================================*/
207 
208 /*---------------------------------------------------------------------
209  * Structures defining various Arc/Info objects types.
210  * These are shared by the Binary and the E00 functions.
211  *--------------------------------------------------------------------*/
212 
213 typedef struct AVCVertex_t
214 {
215     double      x;      /* Even for single precision, we always         */
216     double      y;      /* use doubles for the vertices in memory.      */
217 }AVCVertex;
218 
219 /*---------------------------------------------------------------------
220  * AVCArc: Information about an ARC
221  *--------------------------------------------------------------------*/
222 typedef struct AVCArc_t
223 {
224     GInt32      nArcId;
225     GInt32      nUserId;
226     GInt32      nFNode;
227     GInt32      nTNode;
228     GInt32      nLPoly;
229     GInt32      nRPoly;
230     GInt32      numVertices;
231     AVCVertex   *pasVertices;
232 }AVCArc;
233 
234 /*---------------------------------------------------------------------
235  * AVCPal: A PAL (Polygon Arc List) references all the arcs that
236  *         constitute a polygon.
237  *--------------------------------------------------------------------*/
238 typedef struct AVCPalArc_t
239 {
240     GInt32      nArcId;
241     GInt32      nFNode;
242     GInt32      nAdjPoly;
243 }AVCPalArc;
244 
245 typedef struct AVCPal_t
246 {
247     GInt32      nPolyId;
248     AVCVertex   sMin;
249     AVCVertex   sMax;
250     GInt32      numArcs;
251     AVCPalArc   *pasArcs;
252 }AVCPal;
253 
254 /*---------------------------------------------------------------------
255  * AVCCnt: Information about a CNT (polygon centroid)
256  *--------------------------------------------------------------------*/
257 typedef struct AVCCnt_t
258 {
259     GInt32      nPolyId;
260     AVCVertex   sCoord;
261     GInt32      numLabels;      /* 0 or 1 */
262     GInt32      *panLabelIds;
263 }AVCCnt;
264 
265 /*---------------------------------------------------------------------
266  * AVCLab: Information about a LAB (polygon Label)
267  *--------------------------------------------------------------------*/
268 typedef struct AVCLab_t
269 {
270     GInt32      nValue;
271     GInt32      nPolyId;
272     AVCVertex   sCoord1;
273     AVCVertex   sCoord2;
274     AVCVertex   sCoord3;
275 }AVCLab;
276 
277 /*---------------------------------------------------------------------
278  * AVCTol: Information about a TOL record (coverage tolerances)
279  *--------------------------------------------------------------------*/
280 typedef struct AVCTol_t
281 {
282     GInt32      nIndex;
283     GInt32      nFlag;
284     double      dValue;
285 }AVCTol;
286 
287 /*---------------------------------------------------------------------
288  * AVCTxt: Information about a TXT/TX6/TX7 record (annotations)
289  *--------------------------------------------------------------------*/
290 typedef struct AVCTxt_t
291 {
292     GInt32      nTxtId;
293     GInt32      nUserId;
294     GInt32      nLevel;
295     float       f_1e2;  /* Always (float)-1e+20, even for double precision! */
296     GInt32      nSymbol;
297     GInt32      numVerticesLine;
298     GInt32      n28;    /* Unknown value at byte 28 */
299     GInt32      numChars;
300     GInt32      numVerticesArrow;
301 
302     GInt16      anJust1[20];
303     GInt16      anJust2[20];
304 
305     double      dHeight;
306     double      dV2;    /* ??? */
307     double      dV3;    /* ??? */
308 
309     GByte       *pszText; /* Needs to be unsigned char for DBCS */
310 
311     AVCVertex   *pasVertices;
312 }AVCTxt;
313 
314 /*---------------------------------------------------------------------
315  * AVCRxp: Information about a RXP record (something related to regions...)
316  *--------------------------------------------------------------------*/
317 typedef struct AVCRxp_t
318 {
319     GInt32      n1;
320     GInt32      n2;
321 }AVCRxp;
322 
323 /*---------------------------------------------------------------------
324  * AVCTableDef: Definition of an INFO table's structure.
325  *               This info is read from several files:
326  *                   info/arc.dir
327  *                   info/arc####.dat
328  *                   info/arc####.nit
329  *
330  *               And the data for the table itself is stored in a binary
331  *               file in the coverage directory.
332  *--------------------------------------------------------------------*/
333 
334 typedef struct AVCFieldInfo_t
335 {
336     char        szName[17];
337     GInt16      nSize;
338     GInt16      v2;
339     GInt16      nOffset;
340     GInt16      v4;
341     GInt16      v5;
342     GInt16      nFmtWidth;
343     GInt16      nFmtPrec;
344     GInt16      nType1;
345     GInt16      nType2;
346     GInt16      v10;
347     GInt16      v11;
348     GInt16      v12;
349     GInt16      v13;
350     char        szAltName[17];
351     GInt16      nIndex;         /* >0 if valid, or -1 if field is deleted */
352 }AVCFieldInfo;
353 
354 #define AVC_FT_DATE     10
355 #define AVC_FT_CHAR     20
356 #define AVC_FT_FIXINT   30
357 #define AVC_FT_FIXNUM   40
358 #define AVC_FT_BININT   50
359 #define AVC_FT_BINFLOAT 60
360 
361 typedef struct AVCTableDef_t
362 {
363     /* Stuff read from the arc.dir file
364      * (1 record, corresponding to this table, from the arc.dir file)
365      */
366     char        szTableName[33];
367     char        szInfoFile[9];
368     GInt16      numFields;
369     GInt16      nRecSize;
370     GInt32      numRecords;
371     char        szExternal[3];  /* "XX" or "  " */
372     GInt16      bDeletedFlag;   /* 1 if deleted, 0 if table is active */
373 
374     /* Data file path read from the arc####.dat file
375      */
376     char        szDataFile[81];
377 
378     /* Field information read from the arc####.nit file
379      */
380     AVCFieldInfo *pasFieldDef;
381 } AVCTableDef;
382 
383 typedef struct AVCField_t
384 {
385     GInt16      nInt16;
386     GInt32      nInt32;
387     float       fFloat;
388     double      dDouble;
389     GByte       *pszStr;
390 } AVCField;
391 
392 /*---------------------------------------------------------------------
393  * Stuff related to buffered reading of raw binary files
394  *--------------------------------------------------------------------*/
395 
396 #define AVCRAWBIN_READBUFSIZE 1024
397 
398 typedef struct AVCRawBinFile_t
399 {
400     VSILFILE    *fp;
401     char        *pszFname;
402     AVCAccess   eAccess;
403     AVCByteOrder eByteOrder;
404     GByte       abyBuf[AVCRAWBIN_READBUFSIZE];
405     int         nOffset;        /* Location of current buffer in the file */
406     int         nCurSize;       /* Nbr of bytes currently loaded        */
407     int         nCurPos;        /* Next byte to read from abyBuf[]      */
408 
409     int         nFileDataSize;  /* File Size as stated in the header */
410                                 /* EOF=TRUE passed this point in file */
411                                 /* Set to -1 if not specified. */
412 
413     /* Handle on dataset's multibyte character encoding info. */
414     AVCDBCSInfo *psDBCSInfo;
415 
416 } AVCRawBinFile;
417 
418 /*---------------------------------------------------------------------
419  * Stuff related to reading and writing binary coverage files
420  *--------------------------------------------------------------------*/
421 
422 typedef struct AVCBinHeader_t
423 {
424     GUInt32     nSignature;
425     GInt32      nPrecision;     /* <0 for double prec., >0 for single prec. */
426     GInt32      nRecordSize;    /* nbr of 2 byte words, 0 for var. length   */
427     GInt32      nLength;        /* Overall file length, in 2 byte words     */
428 }AVCBinHeader;
429 
430 typedef struct AVCBinFile_t
431 {
432     AVCRawBinFile *psRawBinFile;
433     char          *pszFilename;
434     AVCRawBinFile *psIndexFile;   /* Index file, Write mode only */
435 
436     DBFHandle     hDBFFile;       /* Used for AVCCoverPC/PC2 DBF TABLES only */
437     int           nCurDBFRecord;  /* 0-based record index in DBF file */
438 
439     AVCCoverType  eCoverType;
440     AVCFileType   eFileType;
441     int           nPrecision;     /* AVC_SINGLE/DOUBLE_PREC  */
442 
443     union
444     {
445         AVCTableDef  *psTableDef;
446     }hdr;
447 
448     /* cur.* : temp. storage used to read one record (ARC, PAL, ... or
449      *         Table record) from the file.
450      */
451     union
452     {
453         AVCArc       *psArc;
454         AVCPal       *psPal;
455         AVCCnt       *psCnt;
456         AVCLab       *psLab;
457         AVCTol       *psTol;
458         AVCTxt       *psTxt;
459         AVCRxp       *psRxp;
460         AVCField     *pasFields;
461         char         **papszPrj;
462     }cur;
463 
464 } AVCBinFile;
465 
466 /*---------------------------------------------------------------------
467  * Stuff related to the generation of E00
468  *--------------------------------------------------------------------*/
469 
470 /*---------------------------------------------------------------------
471  *                        AVCE00GenInfo structure
472  * This structure is used by the E00 generator functions to store
473  * their buffer and their current state in case they need to be
474  * called more than once for a given object type (i.e. ARC, PAL and IFO).
475  *--------------------------------------------------------------------*/
476 
477 typedef struct AVCE00GenInfo_t
478 {
479     char        *pszBuf;
480     int         nBufSize;
481 
482     int         nPrecision;     /* AVC_SINGLE/DOUBLE_PREC       */
483     int         iCurItem;
484     int         numItems;
485 }AVCE00GenInfo;
486 
487 /*---------------------------------------------------------------------
488  * Stuff related to the parsing of E00
489  *--------------------------------------------------------------------*/
490 
491 /*---------------------------------------------------------------------
492  *                        AVCE00ParseInfo structure
493  * This structure is used by the E00 parser functions to store
494  * their buffer and their current state while parsing an object.
495  *--------------------------------------------------------------------*/
496 
497 struct AVCE00ParseInfo
498 {
499     AVCFileType eFileType = AVCFileUnknown;
500     int         nPrecision = 0;     /* AVC_SINGLE/DOUBLE_PREC       */
501     int         iCurItem = 0;
502     int         numItems = 0;
503     int         nStartLineNum = 0;
504     int         nCurLineNum = 0;
505 
506     int         nCurObjectId = 0;
507     GBool       bForceEndOfSection = 0;  /* For sections that don't have an */
508                                      /* explicit end-of-section line.   */
509     AVCFileType eSuperSectionType = AVCFileUnknown;/* For sections containing several files*/
510     char        *pszSectionHdrLine = nullptr;  /* Used by supersection types      */
511 
512     struct
513     {
514         AVCTableDef  *psTableDef = nullptr;
515     } hdr;
516     GBool       bTableHdrComplete = 0;   /* FALSE until table header is */
517                                      /* finished parsing */
518     int         nTableE00RecLength = 0;
519 
520     /* cur.* : temp. storage used to store current object (ARC, PAL, ... or
521      *         Table record) from the file.
522      */
523     union
524     {
525         AVCArc       *psArc;
526         AVCPal       *psPal;
527         AVCCnt       *psCnt;
528         AVCLab       *psLab;
529         AVCTol       *psTol;
530         AVCTxt       *psTxt;
531         AVCRxp       *psRxp;
532         AVCField     *pasFields;
533     }cur;
534     CPLStringList aosPrj;
535 
536     char        *pszBuf = nullptr;        /* Buffer used only for TABLEs  */
537     int         nBufSize = 0;
538 
AVCE00ParseInfoAVCE00ParseInfo539     AVCE00ParseInfo() { cur.psArc = nullptr; }
540 };
541 
542 /*---------------------------------------------------------------------
543  * Stuff related to the transparent binary -> E00 conversion
544  *--------------------------------------------------------------------*/
545 typedef struct AVCE00Section_t
546 {
547     AVCFileType eType;        /* File Type                      */
548     char        *pszName;     /* E00 section or Table Name      */
549     char        *pszFilename; /* Binary/E00 file filename       */
550     int         nLineNum;     /* E00 line number                */
551     int         nFeatureCount;
552 }AVCE00Section;
553 
554 typedef struct AVCE00ReadInfo_t
555 {
556     char        *pszCoverPath;
557     char        *pszInfoPath;
558     char        *pszCoverName;
559     AVCCoverType eCoverType;
560 
561     /* pasSections is built when the coverage is opened and describes
562      * the skeleton of the E00 file.
563      */
564     AVCE00Section *pasSections;
565     int            numSections;
566 
567     /* If bReadAllSections=TRUE then reading automatically continues to
568      * the next section when a section finishes. (This is the default)
569      * Otherwise, you can use AVCE00ReadGotoSection() to read one section
570      * at a time... this will set bReadAllSections=FALSE.
571      */
572     GBool         bReadAllSections;
573 
574     /* Info about the file (or E00 section) currently being processed
575      */
576     int           iCurSection;
577     AVCBinFile    *hFile;
578 
579     int           iCurStep;  /* AVC_GEN_* values, see below */
580     AVCE00GenInfo *hGenInfo;
581 
582     /* Info related to multibyte character encoding
583      */
584     AVCDBCSInfo *psDBCSInfo;
585 
586 } *AVCE00ReadPtr;
587 
588 typedef struct AVCE00ReadInfoE00_t
589 {
590     char        *pszCoverPath;
591     char        *pszCoverName;
592 
593     AVCE00ParseInfo *hParseInfo;
594     AVCFileType  eCurFileType;
595 
596     /* pasSections is built when the coverage is opened and describes
597      * the sections in the E00 file.
598      */
599     AVCE00Section *pasSections;
600     int            numSections;
601 
602     /* If bReadAllSections=TRUE then reading automatically continues to
603      * the next section when a section finishes. (This is the default)
604      * Otherwise, you can use AVCE00ReadGotoSectionE00() to read one
605      * section at a time.
606      */
607     GBool         bReadAllSections;
608 
609     /* File handle of the E00 file currently being processed
610      */
611     VSILFILE     *hFile;
612 
613 } *AVCE00ReadE00Ptr;
614 
615 /* E00 generation steps... tells the AVCE00Read*() functions which
616  * parts of the given E00 file are currently being processed.
617  */
618 #define AVC_GEN_NOTSTARTED      0
619 #define AVC_GEN_DATA            1
620 #define AVC_GEN_ENDSECTION      2
621 #define AVC_GEN_TABLEHEADER     3
622 #define AVC_GEN_TABLEDATA       4
623 
624 /*---------------------------------------------------------------------
625  * Stuff related to the transparent E00 -> binary conversion
626  *--------------------------------------------------------------------*/
627 typedef struct AVCE00WriteInfo_t
628 {
629     char        *pszCoverPath;
630     char        *pszInfoPath;
631     char        *pszCoverName;
632     AVCCoverType eCoverType;
633 
634     /* Info about the file (or E00 section) currently being processed
635      */
636     AVCFileType  eCurFileType;
637     AVCBinFile  *hFile;
638 
639     /* Requested precision for the new coverage... may differ from the
640      * precision of the E00 input lines.  (AVC_SINGLE_PREC or AVC_DOUBLE_PREC)
641      */
642     int          nPrecision;
643 
644     AVCE00ParseInfo *hParseInfo;
645 
646     /* Info related to multibyte character encoding
647      */
648     AVCDBCSInfo *psDBCSInfo;
649 
650 } *AVCE00WritePtr;
651 
652 /* Coverage generation steps... used to store the current state of the
653  * AVCE00WriteNextLine() function.
654  */
655 #define AVC_WR_TOPLEVEL         0
656 #define AVC_WR_READING_SECTION
657 
658 /*=====================================================================
659               Function prototypes (lower-level lib. functions)
660  =====================================================================*/
661 
662 /*---------------------------------------------------------------------
663  * Functions related to buffered reading of raw binary files (and writing)
664  *--------------------------------------------------------------------*/
665 AVCRawBinFile *AVCRawBinOpen(const char *pszFname, const char *pszAccess,
666                              AVCByteOrder eFileByteOrder,
667                              AVCDBCSInfo *psDBCSInfo);
668 void        AVCRawBinClose(AVCRawBinFile *psInfo);
669 void        AVCRawBinFSeek(AVCRawBinFile *psInfo, int nOffset, int nFrom);
670 GBool       AVCRawBinEOF(AVCRawBinFile *psInfo);
671 void        AVCRawBinSetFileDataSize(AVCRawBinFile *psInfo, int nDataSize);
672 int AVCRawBinIsFileGreaterThan(AVCRawBinFile *psFile, vsi_l_offset nSize);
673 
674 void        AVCRawBinReadBytes(AVCRawBinFile *psInfo, int nBytesToRead,
675                                GByte *pBuf);
676 GInt16      AVCRawBinReadInt16(AVCRawBinFile *psInfo);
677 GInt32      AVCRawBinReadInt32(AVCRawBinFile *psInfo);
678 float       AVCRawBinReadFloat(AVCRawBinFile *psInfo);
679 double      AVCRawBinReadDouble(AVCRawBinFile *psInfo);
680 void        AVCRawBinReadString(AVCRawBinFile *psFile, int nBytesToRead,
681                                 GByte *pBuf);
682 
683 void        AVCRawBinWriteBytes(AVCRawBinFile *psFile, int nBytesToWrite,
684                                 const GByte *pBuf);
685 void        AVCRawBinWriteInt16(AVCRawBinFile *psFile, GInt16 n16Value);
686 void        AVCRawBinWriteInt32(AVCRawBinFile *psFile, GInt32 n32Value);
687 void        AVCRawBinWriteFloat(AVCRawBinFile *psFile, float fValue);
688 void        AVCRawBinWriteDouble(AVCRawBinFile *psFile, double dValue);
689 void        AVCRawBinWriteZeros(AVCRawBinFile *psFile, int nBytesToWrite);
690 void        AVCRawBinWritePaddedString(AVCRawBinFile *psFile, int nFieldSize,
691                                        const GByte *pszString);
692 
693 /*---------------------------------------------------------------------
694  * Functions related to reading the binary coverage files
695  *--------------------------------------------------------------------*/
696 
697 AVCBinFile *AVCBinReadOpen(const char *pszPath, const char *pszName,
698                            AVCCoverType eCoverType, AVCFileType eType,
699                            AVCDBCSInfo *psDBCSInfo);
700 void        AVCBinReadClose(AVCBinFile *psFile);
701 
702 int         AVCBinReadRewind(AVCBinFile *psFile);
703 
704 void       *AVCBinReadObject(AVCBinFile *psFile, int iObjIndex );
705 void       *AVCBinReadNextObject(AVCBinFile *psFile);
706 AVCArc     *AVCBinReadNextArc(AVCBinFile *psFile);
707 AVCPal     *AVCBinReadNextPal(AVCBinFile *psFile);
708 AVCCnt     *AVCBinReadNextCnt(AVCBinFile *psFile);
709 AVCLab     *AVCBinReadNextLab(AVCBinFile *psFile);
710 AVCTol     *AVCBinReadNextTol(AVCBinFile *psFile);
711 AVCTxt     *AVCBinReadNextTxt(AVCBinFile *psFile);
712 AVCRxp     *AVCBinReadNextRxp(AVCBinFile *psFile);
713 AVCField   *AVCBinReadNextTableRec(AVCBinFile *psFile);
714 char      **AVCBinReadNextPrj(AVCBinFile *psFile);
715 
716 char      **AVCBinReadListTables(const char *pszInfoPath,
717                                  const char *pszCoverName,
718                                  char ***ppapszArcDatFiles,
719                                  AVCCoverType eCoverType,
720                                  AVCDBCSInfo *psDBCSInfo);
721 
722 /*---------------------------------------------------------------------
723  * Functions related to writing the binary coverage files
724  *--------------------------------------------------------------------*/
725 AVCBinFile *AVCBinWriteCreate(const char *pszPath, const char *pszName,
726                               AVCCoverType eCoverType,
727                               AVCFileType eType, int nPrecision,
728                               AVCDBCSInfo *psDBCSInfo);
729 AVCBinFile *AVCBinWriteCreateTable(const char *pszInfoPath,
730                                    const char *pszCoverName,
731                                    AVCTableDef *psSrcTableDef,
732                                    AVCCoverType eCoverType,
733                                    int nPrecision, AVCDBCSInfo *psDBCSInfo);
734 void        AVCBinWriteClose(AVCBinFile *psFile);
735 
736 int         AVCBinWriteHeader(AVCBinFile *psFile);
737 int         AVCBinWriteObject(AVCBinFile *psFile, void *psObj);
738 int         AVCBinWriteArc(AVCBinFile *psFile, AVCArc *psArc);
739 int         AVCBinWritePal(AVCBinFile *psFile, AVCPal *psPal);
740 int         AVCBinWriteCnt(AVCBinFile *psFile, AVCCnt *psCnt);
741 int         AVCBinWriteLab(AVCBinFile *psFile, AVCLab *psLab);
742 int         AVCBinWriteTol(AVCBinFile *psFile, AVCTol *psTol);
743 int         AVCBinWritePrj(AVCBinFile *psFile, char **papszPrj);
744 int         AVCBinWriteTxt(AVCBinFile *psFile, AVCTxt *psTxt);
745 int         AVCBinWriteRxp(AVCBinFile *psFile, AVCRxp *psRxp);
746 int         AVCBinWriteTableRec(AVCBinFile *psFile, AVCField *pasFields);
747 
748 /*---------------------------------------------------------------------
749  * Functions related to the generation of E00
750  *--------------------------------------------------------------------*/
751 AVCE00GenInfo  *AVCE00GenInfoAlloc(int nCoverPrecision);
752 void        AVCE00GenInfoFree(AVCE00GenInfo *psInfo);
753 void        AVCE00GenReset(AVCE00GenInfo  *psInfo);
754 
755 const char *AVCE00GenStartSection(AVCE00GenInfo *psInfo, AVCFileType eType,
756                                   const char *pszFilename);
757 const char *AVCE00GenEndSection(AVCE00GenInfo *psInfo, AVCFileType eType,
758                                 GBool bCont);
759 
760 const char *AVCE00GenObject(AVCE00GenInfo *psInfo,
761                             AVCFileType eType, void *psObj, GBool bCont);
762 const char *AVCE00GenArc(AVCE00GenInfo *psInfo, AVCArc *psArc, GBool bCont);
763 const char *AVCE00GenPal(AVCE00GenInfo *psInfo, AVCPal *psPal, GBool bCont);
764 const char *AVCE00GenCnt(AVCE00GenInfo *psInfo, AVCCnt *psCnt, GBool bCont);
765 const char *AVCE00GenLab(AVCE00GenInfo *psInfo, AVCLab *psLab, GBool bCont);
766 const char *AVCE00GenTol(AVCE00GenInfo *psInfo, AVCTol *psTol, GBool bCont);
767 const char *AVCE00GenTxt(AVCE00GenInfo *psInfo, AVCTxt *psTxt, GBool bCont);
768 const char *AVCE00GenTx6(AVCE00GenInfo *psInfo, AVCTxt *psTxt, GBool bCont);
769 const char *AVCE00GenPrj(AVCE00GenInfo *psInfo, char **papszPrj, GBool bCont);
770 const char *AVCE00GenRxp(AVCE00GenInfo *psInfo, AVCRxp *psRxp, GBool bCont);
771 
772 const char *AVCE00GenTableHdr(AVCE00GenInfo *psInfo, AVCTableDef *psDef,
773                               GBool bCont);
774 const char *AVCE00GenTableRec(AVCE00GenInfo *psInfo, int numFields,
775                               AVCFieldInfo *pasDef, AVCField *pasFields,
776                               GBool bCont);
777 
778 /*---------------------------------------------------------------------
779  * Functions related to parsing E00 lines
780  *--------------------------------------------------------------------*/
781 AVCE00ParseInfo  *AVCE00ParseInfoAlloc(void);
782 void    AVCE00ParseInfoFree(AVCE00ParseInfo *psInfo);
783 void    AVCE00ParseReset(AVCE00ParseInfo  *psInfo);
784 
785 AVCFileType AVCE00ParseSectionHeader(AVCE00ParseInfo  *psInfo,
786                                      const char *pszLine);
787 GBool   AVCE00ParseSectionEnd(AVCE00ParseInfo  *psInfo, const char *pszLine,
788                               GBool bResetParseInfo);
789 AVCFileType AVCE00ParseSuperSectionHeader(AVCE00ParseInfo  *psInfo,
790                                           const char *pszLine);
791 GBool   AVCE00ParseSuperSectionEnd(AVCE00ParseInfo  *psInfo,
792                                    const char *pszLine );
793 
794 void    *AVCE00ParseNextLine(AVCE00ParseInfo  *psInfo, const char *pszLine);
795 AVCArc  *AVCE00ParseNextArcLine(AVCE00ParseInfo *psInfo, const char *pszLine);
796 AVCPal  *AVCE00ParseNextPalLine(AVCE00ParseInfo *psInfo, const char *pszLine);
797 AVCCnt  *AVCE00ParseNextCntLine(AVCE00ParseInfo *psInfo, const char *pszLine);
798 AVCLab  *AVCE00ParseNextLabLine(AVCE00ParseInfo *psInfo, const char *pszLine);
799 AVCTol  *AVCE00ParseNextTolLine(AVCE00ParseInfo *psInfo, const char *pszLine);
800 AVCTxt  *AVCE00ParseNextTxtLine(AVCE00ParseInfo *psInfo, const char *pszLine);
801 AVCTxt  *AVCE00ParseNextTx6Line(AVCE00ParseInfo *psInfo, const char *pszLine);
802 char   **AVCE00ParseNextPrjLine(AVCE00ParseInfo *psInfo, const char *pszLine);
803 AVCRxp  *AVCE00ParseNextRxpLine(AVCE00ParseInfo *psInfo, const char *pszLine);
804 AVCTableDef *AVCE00ParseNextTableDefLine(AVCE00ParseInfo *psInfo,
805                                          const char *pszLine);
806 AVCField    *AVCE00ParseNextTableRecLine(AVCE00ParseInfo *psInfo,
807                                          const char *pszLine);
808 
809 /*---------------------------------------------------------------------
810  * Misc. functions shared by several parts of the lib.
811  *--------------------------------------------------------------------*/
812 int _AVCE00ComputeRecSize(int numFields, AVCFieldInfo *pasDef,
813                           GBool bMapType40ToDouble);
814 
815 void _AVCDestroyTableFields(AVCTableDef *psTableDef, AVCField *pasFields);
816 void _AVCDestroyTableDef(AVCTableDef *psTableDef);
817 AVCTableDef *_AVCDupTableDef(AVCTableDef *psSrcDef);
818 
819 GBool AVCFileExists(const char *pszPath, const char *pszName);
820 char *AVCAdjustCaseSensitiveFilename(char *pszFname);
821 int  AVCPrintRealValue(char *pszBuf, size_t nBufLen, int nPrecision, AVCFileType eType,
822                        double dValue);
823 
824 /*=====================================================================
825               Function prototypes (THE PUBLIC ONES)
826  =====================================================================*/
827 
828 /*---------------------------------------------------------------------
829  * Functions to read E00
830  *--------------------------------------------------------------------*/
831 AVCE00ReadE00Ptr AVCE00ReadOpenE00(const char *pszE00FileName);
832 void             AVCE00ReadCloseE00(AVCE00ReadE00Ptr psRead);
833 int              AVCE00ReadRewindE00(AVCE00ReadE00Ptr psRead);
834 void            *AVCE00ReadNextObjectE00(AVCE00ReadE00Ptr psRead);
835 
836 AVCE00Section  *AVCE00ReadSectionsListE00(AVCE00ReadE00Ptr psRead, int *numSect);
837 int             AVCE00ReadGotoSectionE00(AVCE00ReadE00Ptr psRead,
838                                          AVCE00Section *psSect,
839                                          GBool bContinue);
840 
841 /*---------------------------------------------------------------------
842  * Functions to make a binary coverage appear as E00
843  *--------------------------------------------------------------------*/
844 
845 AVCE00ReadPtr   AVCE00ReadOpen(const char *pszCoverPath);
846 void            AVCE00ReadClose(AVCE00ReadPtr psInfo);
847 const char     *AVCE00ReadNextLine(AVCE00ReadPtr psInfo);
848 int             AVCE00ReadRewind(AVCE00ReadPtr psInfo);
849 
850 AVCE00Section  *AVCE00ReadSectionsList(AVCE00ReadPtr psInfo, int *numSect);
851 int             AVCE00ReadGotoSection(AVCE00ReadPtr psInfo,
852                                       AVCE00Section *psSect,
853                                       GBool bContinue);
854 
855 /*---------------------------------------------------------------------
856  * Functions to write E00 lines to a binary coverage
857  *--------------------------------------------------------------------*/
858 
859 AVCE00WritePtr  AVCE00WriteOpen(const char *pszCoverPath,
860                                 AVCCoverType eNewCoverType, int nPrecision);
861 void            AVCE00WriteClose(AVCE00WritePtr psInfo);
862 int             AVCE00WriteNextLine(AVCE00WritePtr psInfo,
863                                     const char *pszLine);
864 int             AVCE00DeleteCoverage(const char *pszCoverPath);
865 
866 CPL_C_END
867 
868 #endif /* AVC_H_INCLUDED_ */
869