| 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("`qxp2raw' is used to test libqxp.\n"); |
| 31 |
std::printf("\n"); |
| 32 |
std::printf("Usage: qxp2raw [OPTION] FILE\n"); |
| 33 |
std::printf("\n"); |
| 34 |
std::printf("Options:\n"); |
| 35 |
std::printf("\t--callgraph display the call graph nesting level\n"); |
| 36 |
std::printf("\t--help show this help message\n"); |
| 37 |
std::printf("\t--version print version and exit\n"); |
| 38 |
std::printf("\n"); |
| 39 |
std::printf("Report bugs to <http://bugs.documentfoundation.org/>.\n"); |
| 40 |
return -1; |
| 41 |
} |
| 42 |
|
| 43 |
int printVersion() |
| 44 |
{ |
| 45 |
std::printf("qxp2raw " VERSION "\n"); |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
} // anonymous namespace |
| 50 |
|
| 51 |
using libqxp::QXPDocument; |
| 52 |
|
| 53 |
int main(int argc, char *argv[]) |
| 54 |
{ |
| 55 |
bool printIndentLevel = false; |
| 56 |
char *file = 0; |
| 57 |
|
| 58 |
if (argc < 2) |
| 59 |
return printUsage(); |
| 60 |
|
| 61 |
for (int i = 1; i < argc; i++) |
| 62 |
{ |
| 63 |
if (!std::strcmp(argv[i], "--callgraph")) |
| 64 |
printIndentLevel = true; |
| 65 |
else if (!std::strcmp(argv[i], "--version")) |
| 66 |
return printVersion(); |
| 67 |
else if (!file && std::strncmp(argv[i], "--", 2)) |
| 68 |
file = argv[i]; |
| 69 |
else |
| 70 |
return printUsage(); |
| 71 |
} |
| 72 |
|
| 73 |
if (!file) |
| 74 |
return printUsage(); |
| 75 |
|
| 76 |
librevenge::RVNGFileStream input(file); |
| 77 |
|
| 78 |
QXPDocument::Type type = QXPDocument::TYPE_UNKNOWN; |
| 79 |
const bool supported = QXPDocument::isSupported(&input, &type); |
| 80 |
if (!supported|| (type != QXPDocument::TYPE_DOCUMENT && type != QXPDocument::TYPE_TEMPLATE)) |
| 81 |
{ |
| 82 |
std::cerr << "ERROR: Unsupported file format" << std::endl; |
| 83 |
return 1; |
| 84 |
} |
| 85 |
|
| 86 |
librevenge::RVNGRawDrawingGenerator documentGenerator(printIndentLevel); |
| 87 |
|
| 88 |
return (QXPDocument::RESULT_OK == QXPDocument::parse(&input, &documentGenerator)) ? 0 : 1; |
| 89 |
} |
| 90 |
|
| 91 |
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ |