~ubuntu-branches/ubuntu/lucid/libwpd/lucid

« back to all changes in this revision

Viewing changes to src/conv/raw/main.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Rene Engelhard
  • Date: 2007-06-15 13:28:41 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20070615132841-00nybwftc708w96n
Tags: 0.8.10-1
* New upstream release
* bump shlibs for libwpd-stream8c2a 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* libwpd
2
 
 * Copyright (C) 2002 William Lachance (wrlach@gmail.com)
3
 
 * Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
4
 
 *  
5
 
 * This library is free software; you can redistribute it and/or
6
 
 * modify it under the terms of the GNU Lesser General Public
7
 
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
9
 
 *
10
 
 * This library is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 
 * Library General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Library General Public
16
 
 * License along with this library; if not, write to the Free Software
17
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
18
 
 *
19
 
 * For further information visit http://libwpd.sourceforge.net
20
 
 */
21
 
 
22
 
/* "This product is not manufactured, approved, or supported by 
23
 
 * Corel Corporation or Corel Corporation Limited."
24
 
 */
25
 
 
26
 
#include <gsf/gsf-utils.h>
27
 
#include <gsf/gsf-input-stdio.h>
28
 
#include <stdio.h>
29
 
#include "libwpd.h"
30
 
#include "GSFStream.h"
31
 
#include "RawListener.h"
32
 
 
33
 
int main(int argc, char *argv[])
34
 
{
35
 
        bool printIndentLevel = false;
36
 
        char *file = 0;
37
 
        
38
 
        if (argc < 2)
39
 
        {
40
 
                printf("Usage: wpd2raw [OPTION] <WordPerfect Document>\n");
41
 
                return -1;
42
 
        }
43
 
        gsf_init();
44
 
 
45
 
        if (!strcmp(argv[1], "--callgraph"))
46
 
        {
47
 
                if (argc == 2)
48
 
                {
49
 
                        printf("Usage: wpd2raw [OPTION] <WordPerfect Document>\n");
50
 
                        return -1;
51
 
                }
52
 
                        
53
 
                printIndentLevel = true;
54
 
                file = argv[2];
55
 
        }
56
 
        else if (!strcmp(argv[1], "--help"))
57
 
        {
58
 
                printf("Usage: wpd2raw [OPTION] <WordPerfect Document>\n");
59
 
                printf("\n");
60
 
                printf("Options:\n");
61
 
                printf("--callgraph                 Display the call graph nesting level\n");
62
 
                printf("--help              Shows this help message\n");
63
 
                return 0;
64
 
        }
65
 
        else
66
 
                file = argv[1];
67
 
                
68
 
        
69
 
        GError   *err = 0;
70
 
        GsfInput * input = GSF_INPUT(gsf_input_stdio_new (file, &err));
71
 
        if (!input) 
72
 
        {
73
 
                g_return_val_if_fail (err != 0, 1);
74
 
                
75
 
                g_warning ("'%s' error: %s", file, err->message);
76
 
                g_error_free (err);
77
 
                gsf_shutdown();
78
 
                return 1;
79
 
        }
80
 
 
81
 
        GSFInputStream *gsfInput = new GSFInputStream(input);
82
 
 
83
 
        WPDConfidence confidence = WPDocument::isFileFormatSupported(gsfInput, false);
84
 
        if (confidence == WPD_CONFIDENCE_NONE || confidence == WPD_CONFIDENCE_POOR)
85
 
        {
86
 
                printf("ERROR: Unsupported file format!\n");
87
 
                delete gsfInput; 
88
 
                g_object_unref(input);
89
 
                gsf_shutdown();
90
 
                return 1;
91
 
        }
92
 
        
93
 
        RawListenerImpl listenerImpl(printIndentLevel);
94
 
        WPDResult error = WPDocument::parse(gsfInput, static_cast<WPXHLListenerImpl *>(&listenerImpl));
95
 
 
96
 
        if (error == WPD_FILE_ACCESS_ERROR)
97
 
                fprintf(stderr, "ERROR: File Exception!\n");
98
 
        else if (error == WPD_PARSE_ERROR)
99
 
                fprintf(stderr, "ERROR: Parse Exception!\n");
100
 
        else if (error == WPD_UNSUPPORTED_ENCRYPTION_ERROR)
101
 
                fprintf(stderr, "ERROR: File is password protected!\n");
102
 
        else if (error == WPD_OLE_ERROR)
103
 
                fprintf(stderr, "ERROR: File is an OLE document, but does not contain a WordPerfect stream!\n");
104
 
        else if (error != WPD_OK)
105
 
                fprintf(stderr, "ERROR: Unknown Error!\n");
106
 
 
107
 
        delete gsfInput;
108
 
        g_object_unref (input);
109
 
        gsf_shutdown();
110
 
 
111
 
        if (error != WPD_OK)
112
 
                return 1;
113
 
 
114
 
        return 0;
115
 
}