Debian Codegraph @

src/conv/text/qxp2text.cpp

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the libqxp project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #ifdef HAVE_CONFIG_H
11 #include "config.h"
12 #endif
13
14 #include <cstdio>
15 #include <cstring>
16 #include <iostream>
17 #include <memory>
18
19 #include <librevenge/librevenge.h>
20 #include <librevenge-generators/librevenge-generators.h>
21 #include <librevenge-stream/librevenge-stream.h>
22
23 #include <libqxp/libqxp.h>
24
25 namespace
26 {
27
28 int printUsage()
29 {
30 std::printf("`qxp2text' converts QuarkXPress documents to plain text.\n");
31 std::printf("\n");
32 std::printf("Usage: qxp2text [OPTION] FILE\n");
33 std::printf("\n");
34 std::printf("Options:\n");
35 std::printf("\t--help show this help message\n");
36 std::printf("\t--version print version and exit\n");
37 std::printf("\n");
38 std::printf("Report bugs to <http://bugs.documentfoundation.org/>.\n");
39 return -1;
40 }
41
42 int printVersion()
43 {
44 std::printf("qxp2text " VERSION "\n");
45 return 0;
46 }
47
48 } // anonymous namespace
49
50 using libqxp::QXPDocument;
51
52 int main(int argc, char *argv[])
53 {
54 if (argc < 2)
55 return printUsage();
56
57 char *file = 0;
58
59 for (int i = 1; i < argc; i++)
60 {
61 if (!std::strcmp(argv[i], "--version"))
62 return printVersion();
63 else if (!file && std::strncmp(argv[i], "--", 2))
64 file = argv[i];
65 else
66 return printUsage();
67 }
68
69 if (!file)
70 return printUsage();
71
72 librevenge::RVNGFileStream input(file);
73
74 QXPDocument::Type type = QXPDocument::TYPE_UNKNOWN;
75 const bool supported = QXPDocument::isSupported(&input, &type);
76 if (!supported|| (type != QXPDocument::TYPE_DOCUMENT && type != QXPDocument::TYPE_TEMPLATE))
77 {
78 std::cerr << "ERROR: Unsupported file format" << std::endl;
79 return 1;
80 }
81
82 librevenge::RVNGStringVector pages;
83 librevenge::RVNGTextDrawingGenerator documentGenerator(pages);
84
85 if (QXPDocument::RESULT_OK != QXPDocument::parse(&input, &documentGenerator))
86 return 1;
87
88 for (unsigned i = 0; i != pages.size(); ++i)
89 {
90 std::puts(pages[i].cstr());
91 std::puts("\n");
92 }
93
94 return 0;
95 }
96
97 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */