Debian Codegraph @

src/conv/raw/abw2raw.cpp

raw
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the libabw 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 #include <stdio.h>
11 #include <librevenge-stream/librevenge-stream.h>
12 #include <librevenge-generators/librevenge-generators.h>
13 #include <libabw/libabw.h>
14 #include <string.h>
15
16 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19
20 #ifndef PACKAGE
21 #define PACKAGE "libabw"
22 #endif
23 #ifndef VERSION
24 #define VERSION "UNKNOWN VERSION"
25 #endif
26
27 namespace
28 {
29
30 int printUsage()
31 {
32 printf("`abw2raw' is used to test " PACKAGE ".\n");
33 printf("\n");
34 printf("Usage: abw2raw [OPTION] INPUT\n");
35 printf("\n");
36 printf("Options:\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\n");
40 printf("\n");
41 printf("Report bugs to <https://bugs.documentfoundation.org/>.\n");
42 return -1;
43 }
44
45 int printVersion()
46 {
47 printf("abw2raw %s\n", VERSION);
48 return 0;
49 }
50
51 } // anonymous namespace
52
53 int main(int argc, char *argv[])
54 {
55 bool printIndentLevel = false;
56 char *file = nullptr;
57
58 if (argc < 2)
59 return printUsage();
60
61 for (int i = 1; i < argc; i++)
62 {
63 if (!strcmp(argv[i], "--callgraph"))
64 printIndentLevel = true;
65 else if (!strcmp(argv[i], "--version"))
66 return printVersion();
67 else if (!file && 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 if (!libabw::AbiDocument::isFileFormatSupported(&input))
79 {
80 fprintf(stderr, "ERROR: Unsupported file format!\n");
81 return 1;
82 }
83
84 librevenge::RVNGRawTextGenerator documentGenerator(printIndentLevel);
85 if (libabw::AbiDocument::parse(&input, &documentGenerator))
86 return 0;
87 return 1;
88 }
89 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */