| 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* |
| 3 | * This file is part of the libcdr 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 <stdio.h> |
| 15 | #include <string.h> |
| 16 | #include <librevenge/librevenge.h> |
| 17 | #include <librevenge-generators/librevenge-generators.h> |
| 18 | #include <librevenge-stream/librevenge-stream.h> |
| 19 | #include <libcdr/libcdr.h> |
| 20 | |
| 21 | #ifndef VERSION |
| 22 | #define VERSION "UNKNOWN VERSION" |
| 23 | #endif |
| 24 | |
| 25 | namespace |
| 26 | { |
| 27 | |
| 28 | int printUsage() |
| 29 | { |
| 30 | printf("`cmx2raw' is used to test import of Corel Binary Metafiles in libcdr.\n"); |
| 31 | printf("\n"); |
| 32 | printf("Usage: cmx2raw [OPTION] FILE\n"); |
| 33 | printf("\n"); |
| 34 | printf("Options:\n"); |
| 35 | printf("\t--callgraph display the call graph nesting level\n"); |
| 36 | printf("\t--help show this help message\n"); |
| 37 | printf("\t--version show version information and exit\n"); |
| 38 | printf("\n"); |
| 39 | printf("Report bugs to <https://bugs.documentfoundation.org/>.\n"); |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | int printVersion() |
| 44 | { |
| 45 | printf("cmx2raw " VERSION "\n"); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | } // anonymous namespace |
| 50 | |
| 51 | int main(int argc, char *argv[]) |
| 52 | { |
| 53 | bool printIndentLevel = false; |
| 54 | char *file = nullptr; |
| 55 | |
| 56 | if (argc < 2) |
| 57 | return printUsage(); |
| 58 | |
| 59 | for (int i = 1; i < argc; i++) |
| 60 | { |
| 61 | if (!strcmp(argv[i], "--callgraph")) |
| 62 | printIndentLevel = true; |
| 63 | else if (!strcmp(argv[i], "--version")) |
| 64 | return printVersion(); |
| 65 | else if (!file && strncmp(argv[i], "--", 2)) |
| 66 | file = argv[i]; |
| 67 | else |
| 68 | return printUsage(); |
| 69 | } |
| 70 | |
| 71 | if (!file) |
| 72 | return printUsage(); |
| 73 | |
| 74 | librevenge::RVNGFileStream input(file); |
| 75 | librevenge::RVNGRawDrawingGenerator painter(printIndentLevel); |
| 76 | |
| 77 | if (!libcdr::CMXDocument::isSupported(&input)) |
| 78 | { |
| 79 | if (!libcdr::CDRDocument::isSupported(&input)) |
| 80 | { |
| 81 | fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n"); |
| 82 | return 1; |
| 83 | } |
| 84 | else if (!libcdr::CDRDocument::parse(&input, &painter)) |
| 85 | { |
| 86 | fprintf(stderr, "ERROR: Parsing of document failed!\n"); |
| 87 | return 1; |
| 88 | } |
| 89 | } |
| 90 | else if (!libcdr::CMXDocument::parse(&input, &painter)) |
| 91 | { |
| 92 | fprintf(stderr, "ERROR: Parsing of document failed!\n"); |
| 93 | return 1; |
| 94 | } |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |