~ubuntu-branches/ubuntu/karmic/libwpd/karmic

« back to all changes in this revision

Viewing changes to src/conv/raw/wpd2raw.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 <stdio.h>
 
27
#include "libwpd.h"
 
28
#include "WPXStreamImplementation.h"
 
29
#include "RawListener.h"
 
30
 
 
31
int main(int argc, char *argv[])
 
32
{
 
33
        bool printIndentLevel = false;
 
34
        char *file = 0;
 
35
        
 
36
        if (argc < 2)
 
37
        {
 
38
                printf("Usage: wpd2raw [OPTION] <WordPerfect Document>\n");
 
39
                return -1;
 
40
        }
 
41
 
 
42
        if (!strcmp(argv[1], "--callgraph"))
 
43
        {
 
44
                if (argc == 2)
 
45
                {
 
46
                        printf("Usage: wpd2raw [OPTION] <WordPerfect Document>\n");
 
47
                        return -1;
 
48
                }
 
49
                        
 
50
                printIndentLevel = true;
 
51
                file = argv[2];
 
52
        }
 
53
        else if (!strcmp(argv[1], "--help"))
 
54
        {
 
55
                printf("Usage: wpd2raw [OPTION] <WordPerfect Document>\n");
 
56
                printf("\n");
 
57
                printf("Options:\n");
 
58
                printf("--callgraph                 Display the call graph nesting level\n");
 
59
                printf("--help              Shows this help message\n");
 
60
                return 0;
 
61
        }
 
62
        else
 
63
                file = argv[1];
 
64
                
 
65
        WPXInputStream* input = new WPXFileStream(file);
 
66
 
 
67
        WPDConfidence confidence = WPDocument::isFileFormatSupported(input, false);
 
68
        if (confidence == WPD_CONFIDENCE_NONE || confidence == WPD_CONFIDENCE_POOR)
 
69
        {
 
70
                printf("ERROR: Unsupported file format!\n");
 
71
                delete input; 
 
72
                return 1;
 
73
        }
 
74
        
 
75
        RawListenerImpl listenerImpl(printIndentLevel);
 
76
        WPDResult error = WPDocument::parse(input, static_cast<WPXHLListenerImpl *>(&listenerImpl));
 
77
 
 
78
        if (error == WPD_FILE_ACCESS_ERROR)
 
79
                fprintf(stderr, "ERROR: File Exception!\n");
 
80
        else if (error == WPD_PARSE_ERROR)
 
81
                fprintf(stderr, "ERROR: Parse Exception!\n");
 
82
        else if (error == WPD_UNSUPPORTED_ENCRYPTION_ERROR)
 
83
                fprintf(stderr, "ERROR: File is password protected!\n");
 
84
        else if (error == WPD_OLE_ERROR)
 
85
                fprintf(stderr, "ERROR: File is an OLE document, but does not contain a WordPerfect stream!\n");
 
86
        else if (error != WPD_OK)
 
87
                fprintf(stderr, "ERROR: Unknown Error!\n");
 
88
 
 
89
        delete input;
 
90
 
 
91
        if (error != WPD_OK)
 
92
                return 1;
 
93
 
 
94
        return 0;
 
95
}