~ubuntu-branches/ubuntu/wily/libwps/wily-proposed

« back to all changes in this revision

Viewing changes to src/conv/text/wps2text.cpp

  • Committer: Package Import Robot
  • Author(s): Rene Engelhard
  • Date: 2014-08-08 01:04:46 UTC
  • mfrom: (6.1.3 experimental)
  • Revision ID: package-import@ubuntu.com-20140808010446-90v8mtp9yfyzaw0l
Tags: 0.3.0-2
* upload to unstable

* fix debian/copyright for MPL-2.0 | LGPL-2.1+ dual-license 

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include <stdio.h>
23
23
#include <string.h>
24
 
#include <libwpd-stream/libwpd-stream.h>
 
24
#include <unistd.h>
 
25
 
 
26
#include <librevenge/librevenge.h>
 
27
#include <librevenge-generators/librevenge-generators.h>
 
28
#include <librevenge-stream/librevenge-stream.h>
 
29
 
25
30
#include <libwps/libwps.h>
26
 
#include "TextDocumentGenerator.h"
 
31
 
 
32
using namespace libwps;
 
33
 
 
34
#ifdef HAVE_CONFIG_H
 
35
#include "config.h"
 
36
#endif
 
37
 
 
38
#ifndef VERSION
 
39
#define VERSION "UNKNOWN VERSION"
 
40
#endif
 
41
 
 
42
static int printUsage()
 
43
{
 
44
        printf("Usage: wps2text [OPTION] <Works Document>\n");
 
45
        printf("\n");
 
46
        printf("Options:\n");
 
47
        printf("\t-h:                Shows this help message\n");
 
48
        printf("\t-v:                Output wps2text version \n");
 
49
        return -1;
 
50
}
 
51
 
 
52
static int printVersion()
 
53
{
 
54
        printf("wps2text %s\n", VERSION);
 
55
        return 0;
 
56
}
27
57
 
28
58
int main(int argc, char *argv[])
29
59
{
30
 
        if (argc < 2)
31
 
        {
32
 
                printf("Usage: wps2text <Works Document>\n");
 
60
        bool printHelp=false;
 
61
        int ch;
 
62
 
 
63
        while ((ch = getopt(argc, argv, "hv")) != -1)
 
64
        {
 
65
                switch (ch)
 
66
                {
 
67
                case 'v':
 
68
                        printVersion();
 
69
                        return 0;
 
70
                default:
 
71
                case 'h':
 
72
                        printHelp = true;
 
73
                        break;
 
74
                }
 
75
        }
 
76
        if (argc != 1+optind || printHelp)
 
77
        {
 
78
                printUsage();
33
79
                return -1;
34
80
        }
35
81
 
36
 
        WPXFileStream input(argv[1]);
 
82
        librevenge::RVNGFileStream input(argv[optind]);
37
83
 
38
 
        WPSConfidence confidence = WPSDocument::isFileFormatSupported(&input);
39
 
        if (confidence == WPS_CONFIDENCE_NONE || confidence == WPS_CONFIDENCE_POOR)
 
84
        WPSKind kind;
 
85
        WPSConfidence confidence = WPSDocument::isFileFormatSupported(&input,kind);
 
86
        if (confidence == WPS_CONFIDENCE_NONE || kind != WPS_TEXT)
40
87
        {
41
88
                printf("ERROR: Unsupported file format!\n");
42
89
                return 1;
43
90
        }
44
91
 
45
 
        TextDocumentGenerator listenerImpl;
 
92
        librevenge::RVNGString document;
 
93
        librevenge::RVNGTextTextGenerator listenerImpl(document);
46
94
        WPSResult error = WPSDocument::parse(&input, &listenerImpl);
47
95
 
48
96
        if (error == WPS_FILE_ACCESS_ERROR)
57
105
        if (error != WPS_OK)
58
106
                return 1;
59
107
 
 
108
        printf("%s", document.cstr());
 
109
 
60
110
        return 0;
61
111
}