3
Compressed E00 Read/Write Library
5
By Daniel Morissette, dmorissette@dmsolutions.ca
6
--------------------------------------
7
The latest version of this documentation and of the whole package can be
8
obtained from http://avce00.maptools.org/
9
--------------------------------------
13
* Copyright and License terms
15
* Building the package
16
* Using the 'e00conv' Conversion program
17
* How to use the library in your programs
18
* Library functions to Read compressed E00 files
20
o E00ReadPtr data type
22
o E00ReadCallbackOpen()
26
* Library functions to Write compressed E00 files
28
o E00WritePtr data type
30
o E00WriteCallbackOpen()
33
* Trapping errors reported by the library
34
o CPLSetErrorHandler()
37
o CPLGetLastErrorMsg()
38
o Errors generated by the library and their meaning
40
Copyright and License terms
42
The most part of the E00COMPR library is
43
Copyright (c) 1998-2005, Daniel Morissette (dmorissette@dmsolutions.ca)
44
it also contains portions (CPL lib) that are
45
Copyright (c) 1998-1999, Frank Warmerdam (warmerdam@pobox.com)
47
The AVCE00 library and the supporting CPL code are freely available under
48
the following Open Source license terms:
50
Copyright (c) 1998-2005, Daniel Morissette
51
Portions Copyright (c) 1998-1999, Frank Warmerdam
53
Permission is hereby granted, free of charge, to any person obtaining a
54
copy of this software and associated documentation files (the
55
"Software"), to deal in the Software without restriction, including
56
without limitation the rights to use, copy, modify, merge, publish,
57
distribute, sublicense, and/or sell copies of the Software, and to
58
permit persons to whom the Software is furnished to do so, subject to
59
the following conditions:
61
The above copyright notice and this permission notice shall be included
62
in all copies or substantial portions of the Software.
64
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
65
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
66
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
67
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
68
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
69
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
70
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
75
E00compr is an ANSI C library that reads and writes Arc/Info compressed E00
76
files. Both "PARTIAL" and "FULL" compression levels are supported.
78
This package can be divided in three parts:
80
* The 'e00conv' command-line program. This program takes a E00 file as
81
input (compressed or not) and copies it to a new file with the
82
requested compression level (NONE, PARTIAL or FULL).
84
* A set of library functions to read compressed E00 files. These
85
functions read a E00 file (compressed or not) and return a stream of
86
uncompressed lines, making the E00 file appear as if it was not
89
* A set of library functions to write compressed E00 files. These
90
functions take one line after another from what should be a
91
uncompressed E00 file, and write them to a file with the requested
92
compression level, either NONE, PARTIAL or FULL.
96
The library has already been succesfully built on Windows (with MSVC++ 4
97
and 5), and on Linux (with gcc).
101
A MSVC++ 4 makefile (e00compr.mak) to build the 'e00conv.exe'
102
command-line program is included with the distribution. You should
103
have no problem opening this file with MSVC++ and building the package
106
MSVC++ 5 will ask you if you want to convert the makefile to the new
107
project format. Answer "Yes" and you should be just fine.
109
If you are using another development environment, then you will likley
110
need to build your own project. Include the following files in your
127
A Makefile is included with the distribution. Its default target will
128
build the 'e00conv' executable using gcc. Take a look at the
129
definitions at the top of the Makefile to see if you need to modify it
130
to build in your own environment.
132
In most cases, building the package should be as simple as extracting
133
the distribution files to a empty directory, and then going to this
134
directory and typing make.
136
If you encounter problems with the Makefile, then make sure that it
137
contains Unix line breaks. The line breaks are sometimes altered when
138
the distribution is copied between PCs and Unix systems, and Make
139
doesn't seem to like Makefiles that contain DOS CR-LF line breaks.
141
Using the 'e00conv' Conversion Program
143
'e00conv' is a command-line executable that takes a E00 file as input
144
(compressed or not) and copies it to a new file with the requested
145
compression level (NONE, PARTIAL or FULL).
147
e00conv <input_file> <output_file> [NONE|PARTIAL|FULL]
149
o input_file is the name of the E00 file to read from.
151
o output_file is the name of the file to create. If the file
152
already exists then it is overwritten.
154
o The last argument is optional and specifies the compression level
155
to use when creating the output file (one of NONE, PARTIAL or
156
FULL). The default is NONE (uncompressed).
158
How to use the library in your programs
160
--------------------------------------
161
Note: If you are not planning to use the library in your programs,
162
then you can stop reading here...
163
the rest of this document won't be of any use to you!
164
--------------------------------------
166
To use the library in your programs, include the file "e00compr.h", and
167
link with the "e00compr.a" library produced by the Unix Makefile.
169
If you are working in a Windows development environment (i.e. with
170
projects, no Makefiles!) then add all the C files from the distribution to
171
your project, except "e00conv.c".
173
Library functions to Read compressed E00 files
175
All the read functions are defined inside "e00read.c". Information about
176
the file currently being read is stored inside an internal structure. You
177
do not need to understand the contents of this structure to use the
180
All you need is to declare a E00ReadPtr variable which will serve as a
181
handle on the input file for all the other functions.
183
You use the following functions to read a E00 file:
185
E00ReadPtr E00ReadOpen(const char *pszFname);
186
void E00ReadClose(E00ReadPtr hInfo);
188
const char *E00ReadNextLine(E00ReadPtr hInfo);
189
void E00ReadRewind(E00ReadPtr hInfo);
191
Each function is described after the example below.
195
This short example uses the library to read a E00 compressed file
196
("test.e00") and prints the uncompressed result to stdout.
198
/**********************************************************************
201
* This example program illustrates the use of the E00ReadOpen()
202
* and associated compressed E00 read functions.
203
**********************************************************************/
207
#include "e00compr.h"
209
int main(int argc, char *argv[])
215
hReadPtr = E00ReadOpen("test.e00");
219
/* Read lines from input until we reach EOF */
220
while((pszLine = E00ReadNextLine(hReadPtr)) != NULL)
222
if (CPLGetLastErrorNo() == 0)
223
printf("%s\n", pszLine);
226
/* An error happened while reading the last line... */
231
/* Close input file */
232
E00ReadClose(hReadPtr);
236
/* ERROR ... failed to open input file */
245
A variable of type E00ReadPtr serves as a handle on the current input
248
The handle is allocated by E00ReadOpen(), and you must call
249
E00ReadClose() to properly release the memory associated with it.
253
E00ReadPtr E00ReadOpen(const char *pszFname);
255
Opens a E00 input file and returns a E00ReadPtr handle.
257
The input file can be in compressed or uncompressed format.
258
E00ReadClose() will eventually have to be called to release the
261
Returns NULL if the file could not be opened or if it does not appear
262
to be a valid E00 file.
264
E00ReadCallbackOpen()
266
E00ReadPtr E00ReadCallbackOpen(void *pRefData,
267
const char * (*pfnReadNextLine)(void *),
268
void (*pfnReadRewind)(void *));
270
This is an alternative to E00ReadOpen() for cases where you have to do
271
all the file management yourself. You open/close the file yourself and
272
provide 2 callback functions: to read from the file and rewind the
275
pRefData is your own handle on the physical file and can be whatever
276
you want... it is not used by the library, it will be passed directly
277
to your 2 callback functions when they are called.
279
The callback functions must have the following C prototype:
281
const char *myReadNextLine(void *pRefData);
282
void myReadRewind(void *pRefData);
285
myReadNextLine() should return a reference to its own internal
286
buffer, or NULL if an error happens or when EOF is reached.
288
E00ReadCallbackOpen() returns a E00ReadPtr handle or NULL if the file
289
does not appear to be a valid E00 file.
291
For an example of the use of this method, see the file ex_readcb.c
292
included in the library distribution.
296
void E00ReadClose(E00ReadPtr hInfo);
298
Closes the physical file and releases any memory associated with a
303
const char *E00ReadNextLine(E00ReadPtr hInfo);
305
Returns the next line of input from the E00 file in uncompressed form
306
or NULL if we reached EOF or if an error happened. The returned line
307
is a null-terminated string, and it does not include a newline
308
character. Call CPLGetLastErrorNo() after calling E00ReadNextLine() to
309
make sure that the whole line was read succesfully.
311
Note that E00ReadNextLine() returns a reference to an internal buffer
312
whose contents will be valid only until the next call to this
313
function. The caller should not attempt to free() the returned
318
void E00ReadRewind(E00ReadPtr hInfo);
320
Rewinds the E00ReadPtr just like the stdio rewind() function would do.
322
Useful when you have to do multiple read passes on the same input
325
Library functions to Write compressed E00 files
327
The write functions are defined inside "e00write.c". The information about
328
the file currently being written is stored inside an internal structure. As
329
for the read library, you do not need to understand the contents of this
330
structure to use the library.
332
Your program has to declare a E00WritePtr variable which will serve as a
333
handle on the output file for all the other functions.
335
You use the following functions to write a E00 file:
337
E00WritePtr E00WriteOpen(const char *pszFname, int nComprLevel);
338
void E00WriteClose(E00WritePtr hInfo);
340
int E00WriteNextLine(E00WritePtr hInfo, const char *pszLine);
342
Each function is described after the example below.
346
This example is a simpler version of the "e00conv.c" program that is
347
included with this distribution. It uses the read library to read a
348
E00 file ("test1.e00") and uses the write library to copy its contents
349
one line at a time to a new E00 file ("test2.e00") with FULL
352
/**********************************************************************
355
* This example program illustrates the use of the E00WriteOpen()
356
* and associated compressed E00 write functions.
357
**********************************************************************/
360
#include "e00compr.h"
362
int main(int argc, char *argv[])
365
E00WritePtr hWritePtr;
369
/* Open input file */
370
hReadPtr = E00ReadOpen("test1.e00");
374
/* Open output file */
375
hWritePtr = E00WriteOpen("test2.e00", E00_COMPR_FULL);
379
/* Read lines from input until we reach EOF */
380
while((pszLine = E00ReadNextLine(hReadPtr)) != NULL)
382
if ((nStatus = CPLGetLastErrorNo()) == 0)
383
nStatus = E00WriteNextLine(hWritePtr, pszLine);
387
/* An error happened while converting the last
392
/* Close output file. */
393
E00WriteClose(hWritePtr);
397
/* ERROR ... failed to open output file */
398
nStatus = CPLGetLastErrorNo();
401
/* Close input file. */
402
E00ReadClose(hReadPtr);
406
/* ERROR ... failed to open input file */
407
nStatus = CPLGetLastErrorNo();
413
E00WritePtr data type
415
A variable of type E00WritePtr serves as a handle on the current input
418
The handle is allocated by E00WriteOpen(), and you must call
419
E00WriteClose() to properly release the memory associated with it.
423
E00WritePtr E00WriteOpen(const char *pszFname, int nComprLevel);
425
Creates a new E00 file for output with the specified compression
426
level, and returns a E00WritePtr handle for it. If the file already
427
exists, then it is overwritten.
429
nComprLevel is one of Arc/Info's 3 levels of compression:
431
o E00_COMPR_NONE - creates an uncompressed file.
432
o E00_COMPR_PARTIAL - creates a file with PARTIAL compression.
433
o E00_COMPR_FULL - creates a file with FULL compression.
435
Returns NULL if the file could not be opened.
437
E00WriteCallbackOpen()
439
E00WritePtr E00WriteCallbackOpen(void *pRefData,
440
int (*pfnWriteNextLine)(void *, const char *),
443
This is an alternative to E00WriteOpen() for cases where you have to
444
do all the file management yourself. You open/close the file yourself
445
and provide a callback function to write one line at a time to the
448
pRefData is your own handle on the physical file and can be whatever
449
you want... it is not used by the library, it will be passed directly
450
to your callback function when it is called.
452
The callback function must have the following C prototype:
454
int myWriteNextLine(void *pRefData, const char *pszLine);
456
myWriteNextLine() should return a positive value on success (the
457
number of chars written, like printf() does) or -1 if an error
460
The value passed by the library in pszLine is not terminated by a
461
'\n' character... it is assumed that your myWriteNextLine()
462
implementation will take care of terminating the line with a '\n'
465
nComprLevel is one of Arc/Info's 3 levels of compression:
467
o E00_COMPR_NONE - creates an uncompressed file.
468
o E00_COMPR_PARTIAL - creates a file with PARTIAL compression.
469
o E00_COMPR_FULL - creates a file with FULL compression.
471
E00WriteCallbackOpen() returns a new E00ReadWritePtr handle and
472
E00WriteClose() will eventually have to be called to release the
473
resources used by the new handle.
475
For an example of the use of this method, see the file ex_writecb.c
476
included in the library distribution.
480
void E00WriteClose(E00WritePtr hInfo);
482
Closes the physical file and release any memory associated with a
487
int E00WriteNextLine(E00WritePtr hInfo, const char *pszLine);
489
Takes the next line of what should be headed to a uncompressed E00
490
file, converts it to the requested compression level, and writes the
491
(compressed) result to the output file.
493
pszLine should be a null-terminated string with a maximum of 80
494
characters (E00 lines cannot be longer than 80 characters). Do NOT
495
include a '\n' at the end of the line, it will be added automatically
496
by the function if it is needed.
498
Returns 0 if the line was processed succesfully, or an error number
499
(see error codes below) if an error happened.
501
Note that this function does not do any syntax check on the input you
502
provide. It assumes that what you pass to it is a valid stream of E00
503
lines as they would appear in an uncompressed E00 file.
505
Trapping errors reported by the library
507
When errors happen, the library's default behavior is to report an error
508
message on stderr, and to fail nicely, usually by simulating a EOF
509
situation. Errors are reported through the function CPLError() defined in
512
While this is sufficient for the purposes of the 'e00conv' command-line
513
program, you may want to trap and handle errors yourself if you use the
514
library in a bigger application (a GUI application for instance).
518
void CPLSetErrorHandler(void (*pfnErrorHandler)(CPLErr, int, const char *));
520
You can use CPLSetErrorHandler() to override the default error handler
521
function. Your new error handler should be a C function with the
524
void MyErrorHandler(CPLErr eErrClass, int err_no, const char *msg);
526
And you register it with the following call at the beginning of your
529
CPLSetErrorHandler( MyErrorHandler );
533
void CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...);
535
The library reports errors through this function. It's default
536
behavior is to display the error messages to stderr, but it can be
537
overridden using CPLSetErrorHandler().
539
You can call CPLGetLastErrorNo() or CPLGetLastErrorMsg() to get the
540
last error number and string.
542
eErrClass defines the severity of the error:
553
Error class CE_Fatal will abort the execution of the program, it is
554
mainly used for out of memory errors, or unrecoverable situations of
555
that kind. All the other error classes return control to the calling
560
int CPLGetLastErrorNo();
562
Returns the number of the last error that was produced. Returns 0 if
563
the last library function that was called completed without any error.
564
See the list of possible error numbers below.
566
Note: This function works even if you redefined your own error handler
567
using CPLSetErrorHandler() .
571
const char *CPLGetLastErrorMsg();
573
Returns a reference to a static buffer containing the last error
574
message that was produced. The caller should not attempt to free this
575
buffer. Returns an empty string ("") if the last library function that
576
was called completed without any error.
578
Note: This function works even if you redefined your own error handler
579
using CPLSetErrorHandler() .
581
Errors generated by the library and their meaning:
583
The values for the error codes returned by the library are defined in the
586
#define CPLE_OutOfMemory 2
587
#define CPLE_FileIO 3
588
#define CPLE_OpenFailed 4
589
#define CPLE_IllegalArg 5
590
#define CPLE_NotSupported 6
591
#define CPLE_AssertionFailed 7
593
The following errors codes can be returned:
595
Error Code Description
597
CPLE_OutOfMemory Memory allocation failed. This is a fatal
598
error, it will abort the program execution.
599
There is currently no proper way to recover
601
CPLE_FileIO Unexpected error reading or writing to a
602
file. This can also happen if an input file
604
CPLE_OpenFailed Failed to open the input ou output file.
605
Check for permissions, disk space, etc.
606
CPLE_IllegalArg Illegal argument passed to one of the
607
CPLE_AssertionFailed library's functions. This is a kind of
608
internal error that should not happen unless
609
the lib is modified or is not used as it is
611
CPLE_NotSupported One of the functions encountered an
612
unsupported/unexpected case in one of the
613
files. This error can also be a sign that the
616
------------------------------------------------------------------------
617
Last Update: $Date: 2005/09/17 14:50:29 $
618
Daniel Morissette, dmorissette@dmsolutions.ca