File: e00conv.c

package info (click to toggle)
e00compr 1.0.0-7
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 272 kB
  • ctags: 238
  • sloc: ansic: 1,316; makefile: 69
file content (155 lines) | stat: -rw-r--r-- 5,249 bytes parent folder | download | duplicates (2)
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
/**********************************************************************
 * $Id: e00conv.c,v 1.7 2005/09/17 14:22:05 daniel Exp $
 *
 * Name:     e00conv.c
 * Project:  Compressed E00 Read/Write library
 * Language: ANSI C
 * Purpose:  Command-line program that uses the Compressed E00 
 *           Read/Write library to convert a E00 file from one level
 *           of compression to another.
 *           (Note: the current version only writes uncompressed E00)
 * Author:   Daniel Morissette, dmorissette@dmsolutions.ca
 *
 * $Log: e00conv.c,v $
 * Revision 1.7  2005/09/17 14:22:05  daniel
 * Switch to MIT license, update refs to website and email address, and
 * prepare for 1.0.0 release.
 *
 * Revision 1.6  1999/02/25 18:29:51  daniel
 * Now use CPL error handling and memory allocations
 *
 * Revision 1.5  1998/11/13 15:40:38  daniel
 * Added support for wirting compressed files.
 *
 * Revision 1.4  1998/11/02 18:37:04  daniel
 * New file header, and added E00ErrorReset()
 *
 * Revision 1.1  1998/10/29 13:26:00  daniel
 * Initial revision
 *
 **********************************************************************
 * Copyright (c) 1998-2005, Daniel Morissette
 *
 * 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.
 * 
 **********************************************************************/

#include <stdio.h>
#include <ctype.h>

#include "e00compr.h"

/**********************************************************************
 *                          main()
 *
 **********************************************************************/
int main(int argc, char *argv[])
{
    E00ReadPtr  hReadPtr;
    E00WritePtr hWritePtr;
    const char  *pszInFile = NULL, *pszOutFile = NULL;
    const char  *pszLine;
    int         nStatus = 0, nComprLevel = E00_COMPR_NONE;

    /* ----------------------------------------------------------------
     * Parse input parameters
     * ---------------------------------------------------------------*/

    if (argc >= 4)
    {
        /* 4th param is compression level (NONE, PARTIAL or FULL)
         * Default is NONE.  
         *
         * We simply check the first char: N, P or F
         */
        switch(toupper(argv[3][0]))
        {
          case 'F':
            nComprLevel = E00_COMPR_FULL;
            break;
          case 'P':
            nComprLevel = E00_COMPR_PARTIAL;
            break;
          case 'N':
          default:
            nComprLevel = E00_COMPR_NONE;
        }
    }

    if (argc >= 3)
    {
        /* Input and output file names
         */
        pszInFile = argv[1];
        pszOutFile = argv[2];
    }
    else
    {
        printf("\n");
        printf("E00CONV - Version %s\n", E00COMPR_VERSION);
        printf("    Converts Arc/Info E00 files from one level of compression to another.\n");
        printf("    Copyright (c) 1999-2005, Daniel Morissette (dmorissette@dmsolutions.ca)\n");
        printf("    E00COMPR web page:  http://avce00.maptools.org/\n");
        printf("\n");
        printf("Usage: e00conv <input_file> <output_file> [NONE|PARTIAL|FULL]\n");
        printf("\n");
        return 1;
    }

    /* ----------------------------------------------------------------
     * Open files and proceed with the conversion
     * ---------------------------------------------------------------*/
    hReadPtr = E00ReadOpen(pszInFile);

    if (hReadPtr)
    {
        hWritePtr = E00WriteOpen(pszOutFile, nComprLevel);

        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 files.
             */
            E00WriteClose(hWritePtr);
        }
        else
            nStatus = CPLGetLastErrorNo();

        E00ReadClose(hReadPtr);
    }
    else
        nStatus = CPLGetLastErrorNo();

    return nStatus;
}