Debian Codegraph @

src/conv/text/cmx2text.cpp

raw symbols SCIP
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("`cmx2text' converts Corel Binary Metafiles to plain text.\n");
31 printf("\n");
32 printf("Usage: cmx2text [OPTION] FILE\n");
33 printf("\n");
34 printf("Options:\n");
35 printf("\t--help show this help message\n");
36 printf("\t--version show version information and exit\n");
37 printf("\n");
38 printf("Report bugs to <https://bugs.documentfoundation.org/>.\n");
39 return -1;
40 }
41
42 int printVersion()
43 {
44 printf("cmx2text " VERSION "\n");
45 return 0;
46 }
47
48 } // anonymous namespace
49
50 int main(int argc, char *argv[])
51 {
52 if (argc < 2)
53 return printUsage();
54
55 char *file = nullptr;
56
57 for (int i = 1; i < argc; i++)
58 {
59 if (!strcmp(argv[i], "--version"))
60 return printVersion();
61 else if (!file && strncmp(argv[i], "--", 2))
62 file = argv[i];
63 else
64 return printUsage();
65 }
66
67 if (!file)
68 return printUsage();
69
70 librevenge::RVNGFileStream input(file);
71 librevenge::RVNGStringVector pages;
72 librevenge::RVNGTextDrawingGenerator painter(pages);
73
74 if (!libcdr::CMXDocument::isSupported(&input))
75 {
76 if (!libcdr::CDRDocument::isSupported(&input))
77 {
78 fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
79 return 1;
80 }
81 else if (!libcdr::CDRDocument::parse(&input, &painter))
82 {
83 fprintf(stderr, "ERROR: Parsing of document failed!\n");
84 return 1;
85 }
86 }
87 else if (!libcdr::CMXDocument::parse(&input, &painter))
88 {
89 fprintf(stderr, "ERROR: Parsing of document failed!\n");
90 return 1;
91 }
92
93 for (unsigned i = 0; i != pages.size(); ++i)
94 printf("%s", pages[i].cstr());
95
96 return 0;
97 }
98
99 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */