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