File: e00compr.txt

package info (click to toggle)
e00compr 1.0.1-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 316 kB
  • sloc: ansic: 1,316; makefile: 64
file content (618 lines) | stat: -rwxr-xr-x 23,273 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
                                E00compr 1.0

                     Compressed E00 Read/Write Library

                 By Daniel Morissette, dmorissette@mapgears.com
                   --------------------------------------
  The latest version of this documentation and of the whole package can be
                 obtained from http://avce00.maptools.org/
                   --------------------------------------

Table of Contents

   * Copyright and License terms
   * What is E00compr?
   * Building the package
   * Using the 'e00conv' Conversion program
   * How to use the library in your programs
   * Library functions to Read compressed E00 files
        o Example
        o E00ReadPtr data type
        o E00ReadOpen()
        o E00ReadCallbackOpen()
        o E00ReadClose()
        o E00ReadNextLine()
        o E00ReadRewind()
   * Library functions to Write compressed E00 files
        o Example
        o E00WritePtr data type
        o E00WriteOpen()
        o E00WriteCallbackOpen()
        o E00WriteClose()
        o E00WriteNextLine()
   * Trapping errors reported by the library
        o CPLSetErrorHandler()
        o CPLError()
        o CPLGetLastErrorNo()
        o CPLGetLastErrorMsg()
        o Errors generated by the library and their meaning

Copyright and License terms

The most part of the E00COMPR library is
   Copyright (c) 1998-2005, Daniel Morissette (dmorissette@mapgears.com)
it also contains portions (CPL lib) that are
   Copyright (c) 1998-1999, Frank Warmerdam (warmerdam@pobox.com)

The AVCE00 library and the supporting CPL code are freely available under
the following Open Source license terms:

   Copyright (c) 1998-2005, Daniel Morissette
   Portions Copyright (c) 1998-1999, Frank Warmerdam

   Permission is hereby granted, free of charge, to any person obtaining a
   copy of this software and associated documentation files (the
   "Software"), to deal in the Software without restriction, including
   without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense, and/or sell copies of the Software, and to
   permit persons to whom the Software is furnished to do so, subject to
   the following conditions:

   The above copyright notice and this permission notice shall be included
   in all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


What is E00compr?

E00compr is an ANSI C library that reads and writes Arc/Info compressed E00
files. Both "PARTIAL" and "FULL" compression levels are supported.

This package can be divided in three parts:

   * The 'e00conv' command-line program. This program takes a E00 file as
     input (compressed or not) and copies it to a new file with the
     requested compression level (NONE, PARTIAL or FULL).

   * A set of library functions to read compressed E00 files. These
     functions read a E00 file (compressed or not) and return a stream of
     uncompressed lines, making the E00 file appear as if it was not
     compressed.

   * A set of library functions to write compressed E00 files. These
     functions take one line after another from what should be a
     uncompressed E00 file, and write them to a file with the requested
     compression level, either NONE, PARTIAL or FULL.

Building the package

The library has already been succesfully built on Windows (with MSVC++ 4
and 5), and on Linux (with gcc).

Windows users:

     A MSVC++ 4 makefile (e00compr.mak) to build the 'e00conv.exe'
     command-line program is included with the distribution. You should
     have no problem opening this file with MSVC++ and building the package
     directly.

     MSVC++ 5 will ask you if you want to convert the makefile to the new
     project format. Answer "Yes" and you should be just fine.

     If you are using another development environment, then you will likley
     need to build your own project. Include the following files in your
     project:

          e00compr.h
          e00read.c
          e00write.c

          cpl_port.h
          cpl_conv.h
          cpl_error.h
          cpl_vsi.h
          cpl_conv.c
          cpl_error.c
          cpl_vsisimple.c

Unix users:

     A Makefile is included with the distribution. Its default target will
     build the 'e00conv' executable using gcc. Take a look at the
     definitions at the top of the Makefile to see if you need to modify it
     to build in your own environment.

     In most cases, building the package should be as simple as extracting
     the distribution files to a empty directory, and then going to this
     directory and typing make.

     If you encounter problems with the Makefile, then make sure that it
     contains Unix line breaks. The line breaks are sometimes altered when
     the distribution is copied between PCs and Unix systems, and Make
     doesn't seem to like Makefiles that contain DOS CR-LF line breaks.

Using the 'e00conv' Conversion Program

'e00conv' is a command-line executable that takes a E00 file as input
(compressed or not) and copies it to a new file with the requested
compression level (NONE, PARTIAL or FULL).

     e00conv <input_file> <output_file> [NONE|PARTIAL|FULL]

        o input_file is the name of the E00 file to read from.

        o output_file is the name of the file to create. If the file
          already exists then it is overwritten.

        o The last argument is optional and specifies the compression level
          to use when creating the output file (one of NONE, PARTIAL or
          FULL). The default is NONE (uncompressed).

How to use the library in your programs

                   --------------------------------------
    Note: If you are not planning to use the library in your programs,
                     then you can stop reading here...
           the rest of this document won't be of any use to you!
                   --------------------------------------

To use the library in your programs, include the file "e00compr.h", and
link with the "e00compr.a" library produced by the Unix Makefile.

If you are working in a Windows development environment (i.e. with
projects, no Makefiles!) then add all the C files from the distribution to
your project, except "e00conv.c".

Library functions to Read compressed E00 files

All the read functions are defined inside "e00read.c". Information about
the file currently being read is stored inside an internal structure. You
do not need to understand the contents of this structure to use the
library.

All you need is to declare a E00ReadPtr variable which will serve as a
handle on the input file for all the other functions.

You use the following functions to read a E00 file:

    E00ReadPtr  E00ReadOpen(const char *pszFname);
    void        E00ReadClose(E00ReadPtr hInfo);

    const char *E00ReadNextLine(E00ReadPtr hInfo);
    void        E00ReadRewind(E00ReadPtr hInfo);

Each function is described after the example below.

Example:

     This short example uses the library to read a E00 compressed file
     ("test.e00") and prints the uncompressed result to stdout.

     /**********************************************************************
      *                          ex_read.c
      *
      * This example program illustrates the use of the E00ReadOpen()
      * and associated compressed E00 read functions.
      **********************************************************************/

     #include <stdio.h>

     #include "e00compr.h"

     int main(int argc, char *argv[])
     {
         E00ReadPtr  hReadPtr;
         const char  *pszLine;

         /* Open input */
         hReadPtr = E00ReadOpen("test.e00");

         if (hReadPtr)
         {
             /* Read lines from input until we reach EOF */
             while((pszLine = E00ReadNextLine(hReadPtr)) != NULL)
             {
                 if (CPLGetLastErrorNo() == 0)
                     printf("%s\n", pszLine);
                 else
                 {
                     /* An error happened while reading the last line... */
                     break;
                 }
             }

             /* Close input file */
             E00ReadClose(hReadPtr);
         }
         else
         {
             /* ERROR ... failed to open input file */
         }

         return 0;
     }


E00ReadPtr data type

     A variable of type E00ReadPtr serves as a handle on the current input
     file.

     The handle is allocated by E00ReadOpen(), and you must call
     E00ReadClose() to properly release the memory associated with it.

E00ReadOpen()

     E00ReadPtr E00ReadOpen(const char *pszFname);

     Opens a E00 input file and returns a E00ReadPtr handle.

     The input file can be in compressed or uncompressed format.
     E00ReadClose() will eventually have to be called to release the
     returned handle.

     Returns NULL if the file could not be opened or if it does not appear
     to be a valid E00 file.

E00ReadCallbackOpen()

     E00ReadPtr  E00ReadCallbackOpen(void *pRefData,
                                     const char * (*pfnReadNextLine)(void *),
                                     void (*pfnReadRewind)(void *));

     This is an alternative to E00ReadOpen() for cases where you have to do
     all the file management yourself. You open/close the file yourself and
     provide 2 callback functions: to read from the file and rewind the
     file pointer.

     pRefData is your own handle on the physical file and can be whatever
     you want... it is not used by the library, it will be passed directly
     to your 2 callback functions when they are called.

     The callback functions must have the following C prototype:

         const char *myReadNextLine(void *pRefData);
         void        myReadRewind(void *pRefData);


          myReadNextLine() should return a reference to its own internal
          buffer, or NULL if an error happens or when EOF is reached.

     E00ReadCallbackOpen() returns a E00ReadPtr handle or NULL if the file
     does not appear to be a valid E00 file.

     For an example of the use of this method, see the file ex_readcb.c
     included in the library distribution.

E00ReadClose()

     void E00ReadClose(E00ReadPtr hInfo);

     Closes the physical file and releases any memory associated with a
     E00ReadPtr handle.

E00ReadNextLine()

     const char *E00ReadNextLine(E00ReadPtr hInfo);

     Returns the next line of input from the E00 file in uncompressed form
     or NULL if we reached EOF or if an error happened. The returned line
     is a null-terminated string, and it does not include a newline
     character. Call CPLGetLastErrorNo() after calling E00ReadNextLine() to
     make sure that the whole line was read succesfully.

     Note that E00ReadNextLine() returns a reference to an internal buffer
     whose contents will be valid only until the next call to this
     function. The caller should not attempt to free() the returned
     pointer.

E00ReadRewind()

     void E00ReadRewind(E00ReadPtr hInfo);

     Rewinds the E00ReadPtr just like the stdio rewind() function would do.

     Useful when you have to do multiple read passes on the same input
     file.

Library functions to Write compressed E00 files

The write functions are defined inside "e00write.c". The information about
the file currently being written is stored inside an internal structure. As
for the read library, you do not need to understand the contents of this
structure to use the library.

Your program has to declare a E00WritePtr variable which will serve as a
handle on the output file for all the other functions.

You use the following functions to write a E00 file:

    E00WritePtr E00WriteOpen(const char *pszFname, int nComprLevel);
    void        E00WriteClose(E00WritePtr hInfo);

    int         E00WriteNextLine(E00WritePtr hInfo, const char *pszLine);

Each function is described after the example below.

Example:

     This example is a simpler version of the "e00conv.c" program that is
     included with this distribution. It uses the read library to read a
     E00 file ("test1.e00") and uses the write library to copy its contents
     one line at a time to a new E00 file ("test2.e00") with FULL
     compression:

     /**********************************************************************
      *                          ex_write.c
      *
      * This example program illustrates the use of the E00WriteOpen()
      * and associated compressed E00 write functions.
      **********************************************************************/
     #include <stdio.h>

     #include "e00compr.h"

     int main(int argc, char *argv[])
     {
         E00ReadPtr  hReadPtr;
         E00WritePtr hWritePtr;
         const char  *pszLine;
         int         nStatus = 0;

         /* Open input file */
         hReadPtr = E00ReadOpen("test1.e00");

         if (hReadPtr)
         {
             /* Open output file */
             hWritePtr = E00WriteOpen("test2.e00", E00_COMPR_FULL);

             if (hWritePtr)
             {
                 /* Read lines from input until we reach EOF */
                 while((pszLine = E00ReadNextLine(hReadPtr)) != NULL)
                 {
                     if ((nStatus = CPLGetLastErrorNo()) == 0)
                         nStatus = E00WriteNextLine(hWritePtr, pszLine);

                     if (nStatus != 0)
                     {
                         /* An error happened while converting the last
                          * line... abort*/
                         break;
                     }
                 }
                 /* Close output file. */
                 E00WriteClose(hWritePtr);
             }
             else
             {
                 /* ERROR ... failed to open output file */
                 nStatus = CPLGetLastErrorNo();
             }

             /* Close input file. */
             E00ReadClose(hReadPtr);
         }
         else
         {
             /* ERROR ... failed to open input file */
             nStatus = CPLGetLastErrorNo();
         }

         return nStatus;
     }

E00WritePtr data type

     A variable of type E00WritePtr serves as a handle on the current input
     file.

     The handle is allocated by E00WriteOpen(), and you must call
     E00WriteClose() to properly release the memory associated with it.

E00WriteOpen()

     E00WritePtr E00WriteOpen(const char *pszFname, int nComprLevel);

     Creates a new E00 file for output with the specified compression
     level, and returns a E00WritePtr handle for it. If the file already
     exists, then it is overwritten.

     nComprLevel is one of Arc/Info's 3 levels of compression:

        o E00_COMPR_NONE - creates an uncompressed file.
        o E00_COMPR_PARTIAL - creates a file with PARTIAL compression.
        o E00_COMPR_FULL - creates a file with FULL compression.

     Returns NULL if the file could not be opened.

E00WriteCallbackOpen()

     E00WritePtr E00WriteCallbackOpen(void *pRefData,
                                      int (*pfnWriteNextLine)(void *, const char *),
                                      int nComprLevel);

     This is an alternative to E00WriteOpen() for cases where you have to
     do all the file management yourself. You open/close the file yourself
     and provide a callback function to write one line at a time to the
     file.

     pRefData is your own handle on the physical file and can be whatever
     you want... it is not used by the library, it will be passed directly
     to your callback function when it is called.

     The callback function must have the following C prototype:

         int    myWriteNextLine(void *pRefData, const char *pszLine);

          myWriteNextLine() should return a positive value on success (the
          number of chars written, like printf() does) or -1 if an error
          happened.

          The value passed by the library in pszLine is not terminated by a
          '\n' character... it is assumed that your myWriteNextLine()
          implementation will take care of terminating the line with a '\n'
          if necessary.

     nComprLevel is one of Arc/Info's 3 levels of compression:

        o E00_COMPR_NONE - creates an uncompressed file.
        o E00_COMPR_PARTIAL - creates a file with PARTIAL compression.
        o E00_COMPR_FULL - creates a file with FULL compression.

     E00WriteCallbackOpen() returns a new E00ReadWritePtr handle and
     E00WriteClose() will eventually have to be called to release the
     resources used by the new handle.

     For an example of the use of this method, see the file ex_writecb.c
     included in the library distribution.

E00WriteClose()

     void E00WriteClose(E00WritePtr hInfo);

     Closes the physical file and release any memory associated with a
     E00WritePtr handle.

E00WriteNextLine()

     int E00WriteNextLine(E00WritePtr hInfo, const char *pszLine);

     Takes the next line of what should be headed to a uncompressed E00
     file, converts it to the requested compression level, and writes the
     (compressed) result to the output file.

     pszLine should be a null-terminated string with a maximum of 80
     characters (E00 lines cannot be longer than 80 characters). Do NOT
     include a '\n' at the end of the line, it will be added automatically
     by the function if it is needed.

     Returns 0 if the line was processed succesfully, or an error number
     (see error codes below) if an error happened.

     Note that this function does not do any syntax check on the input you
     provide. It assumes that what you pass to it is a valid stream of E00
     lines as they would appear in an uncompressed E00 file.

Trapping errors reported by the library

When errors happen, the library's default behavior is to report an error
message on stderr, and to fail nicely, usually by simulating a EOF
situation. Errors are reported through the function CPLError() defined in
"cpl_error.c".

While this is sufficient for the purposes of the 'e00conv' command-line
program, you may want to trap and handle errors yourself if you use the
library in a bigger application (a GUI application for instance).

CPLSetErrorHandler()

     void  CPLSetErrorHandler(void (*pfnErrorHandler)(CPLErr, int, const char *));

     You can use CPLSetErrorHandler() to override the default error handler
     function. Your new error handler should be a C function with the
     following prototype:

          void MyErrorHandler(CPLErr eErrClass, int err_no, const char *msg);

     And you register it with the following call at the beginning of your
     program:

          CPLSetErrorHandler( MyErrorHandler );

CPLError()

     void CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...);

     The library reports errors through this function. It's default
     behavior is to display the error messages to stderr, but it can be
     overridden using CPLSetErrorHandler().

     You can call CPLGetLastErrorNo() or CPLGetLastErrorMsg() to get the
     last error number and string.

     eErrClass defines the severity of the error:

         typedef enum
         {
             CE_None = 0,
             CE_Log = 1,
             CE_Warning = 2,
             CE_Failure = 3,
             CE_Fatal = 4
         } CPLErr;

     Error class CE_Fatal will abort the execution of the program, it is
     mainly used for out of memory errors, or unrecoverable situations of
     that kind. All the other error classes return control to the calling
     function.

CPLGetLastErrorNo()

     int         CPLGetLastErrorNo();

     Returns the number of the last error that was produced. Returns 0 if
     the last library function that was called completed without any error.
     See the list of possible error numbers below.

     Note: This function works even if you redefined your own error handler
     using CPLSetErrorHandler() .

CPLGetLastErrorMsg()

     const char *CPLGetLastErrorMsg();

     Returns a reference to a static buffer containing the last error
     message that was produced. The caller should not attempt to free this
     buffer. Returns an empty string ("") if the last library function that
     was called completed without any error.

     Note: This function works even if you redefined your own error handler
     using CPLSetErrorHandler() .

Errors generated by the library and their meaning:

The values for the error codes returned by the library are defined in the
file cpl_error.h.

     #define CPLE_OutOfMemory                2
     #define CPLE_FileIO                     3
     #define CPLE_OpenFailed                 4
     #define CPLE_IllegalArg                 5
     #define CPLE_NotSupported               6
     #define CPLE_AssertionFailed            7

The following errors codes can be returned:

         Error Code                       Description
    0                    Success, no error.
    CPLE_OutOfMemory     Memory allocation failed. This is a fatal
                         error, it will abort the program execution.
                         There is currently no proper way to recover
                         from it.
    CPLE_FileIO          Unexpected error reading or writing to a
                         file. This can also happen if an input file
                         is corrupt.
    CPLE_OpenFailed      Failed to open the input ou output file.
                         Check for permissions, disk space, etc.
    CPLE_IllegalArg      Illegal argument passed to one of the
    CPLE_AssertionFailed library's functions. This is a kind of
                         internal error that should not happen unless
                         the lib is modified or is not used as it is
                         expected.
    CPLE_NotSupported    One of the functions encountered an
                         unsupported/unexpected case in one of the
                         files. This error can also be a sign that the
                         file is corrupt.

  ------------------------------------------------------------------------
Last Update: $Date: 2009-02-24 20:03:50 $
Daniel Morissette, dmorissette@mapgears.com