Debian Codegraph @

src/conv/text/cdr2text.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
17 #include <librevenge/librevenge.h>
18 #include <librevenge-generators/librevenge-generators.h>
19 #include <librevenge-stream/librevenge-stream.h>
20 #include <libcdr/libcdr.h>
21
22 #ifndef VERSION
23 #define VERSION "UNKNOWN VERSION"
24 #endif
25
26 namespace
27 {
28
29 int printUsage()
30 {
31 printf("`cdr2text' converts CorelDRAW documents to plain text.\n");
32 printf("\n");
33 printf("Usage: cdr2text [OPTION] FILE\n");
34 printf("\n");
35 printf("Options:\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("cdr2text " 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 = nullptr;
57
58 for (int i = 1; i < argc; i++)
59 {
60 if (!strcmp(argv[i], "--version"))
61 return printVersion();
62 else if (!file && strncmp(argv[i], "--", 2))
63 file = argv[i];
64 else
65 return printUsage();
66 }
67
68 if (!file)
69 return printUsage();
70
71 librevenge::RVNGFileStream input(file);
72 librevenge::RVNGStringVector pages;
73 librevenge::RVNGTextDrawingGenerator painter(pages);
74
75 if (!libcdr::CDRDocument::isSupported(&input))
76 {
77 if (!libcdr::CMXDocument::isSupported(&input))
78 {
79 fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
80 return 1;
81 }
82 else if (!libcdr::CMXDocument::parse(&input, &painter))
83 {
84 fprintf(stderr, "ERROR: Parsing of document failed!\n");
85 return 1;
86 }
87 }
88 else if (!libcdr::CDRDocument::parse(&input, &painter))
89 {
90 fprintf(stderr, "ERROR: Parsing of document failed!\n");
91 return 1;
92 }
93
94 for (unsigned i = 0; i != pages.size(); ++i)
95 printf("%s", pages[i].cstr());
96
97 return 0;
98 }
99
100 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */