| 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 | /* |
| 3 | * This file is a part of the libzmf 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 | |
| 17 | #include <librevenge-generators/librevenge-generators.h> |
| 18 | #include <librevenge-stream/librevenge-stream.h> |
| 19 | |
| 20 | #include <libzmf/libzmf.h> |
| 21 | |
| 22 | #ifndef PACKAGE |
| 23 | #define PACKAGE "libzmf" |
| 24 | #endif |
| 25 | #ifndef VERSION |
| 26 | #define VERSION "UNKNOWN VERSION" |
| 27 | #endif |
| 28 | |
| 29 | namespace |
| 30 | { |
| 31 | |
| 32 | int printUsage() |
| 33 | { |
| 34 | printf("`zmf2raw' is used to test " PACKAGE ".\n"); |
| 35 | printf("\n"); |
| 36 | printf("Usage: zmf2raw [OPTION] INPUT\n"); |
| 37 | printf("\t--callgraph display the call graph nesting level\n"); |
| 38 | printf("\t--help show this help message\n"); |
| 39 | printf("\t--version show version information and exit\n"); |
| 40 | return -1; |
| 41 | } |
| 42 | |
| 43 | int printVersion() |
| 44 | { |
| 45 | printf("zmf2raw " VERSION "\n"); |
| 46 | return 0; |
| 47 | } |
| 48 | |
| 49 | } // anonymous namespace |
| 50 | |
| 51 | int main(int argc, char *argv[]) |
| 52 | { |
| 53 | if (argc < 2) |
| 54 | return printUsage(); |
| 55 | |
| 56 | char *file = 0; |
| 57 | bool printCallgraph = false; |
| 58 | |
| 59 | for (int i = 1; i < argc; i++) |
| 60 | { |
| 61 | if (!strcmp(argv[i], "--callgraph")) |
| 62 | printCallgraph = 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 | |
| 76 | if (!libzmf::ZMFDocument::isSupported(&input)) |
| 77 | { |
| 78 | fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n"); |
| 79 | return 1; |
| 80 | } |
| 81 | |
| 82 | librevenge::RVNGRawDrawingGenerator painter(printCallgraph); |
| 83 | libzmf::ZMFDocument::parse(&input, &painter); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |