Debian Codegraph @

src/conv/html/abw2html.cpp

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 VERSION
21 #define VERSION "UNKNOWN VERSION"
22 #endif
23
24 namespace
25 {
26
27 int printUsage()
28 {
29 printf("`abw2html' converts AbiWord documents to HTML.\n");
30 printf("\n");
31 printf("Usage: abw2html [OPTION] INPUT\n");
32 printf("\n");
33 printf("Options:\n");
34 printf("\t--help show this help message\n");
35 printf("\t--version show version information\n");
36 printf("\n");
37 printf("Report bugs to <https://bugs.documentfoundation.org/>.\n");
38 return -1;
39 }
40
41 int printVersion()
42 {
43 printf("abw2html %s\n", VERSION);
44 return 0;
45 }
46
47 } // anonymous namespace
48
49 int main(int argc, char *argv[])
50 {
51 if (argc < 2)
52 return printUsage();
53
54 char *file = nullptr;
55
56 for (int i = 1; i < argc; i++)
57 {
58 if (!strcmp(argv[i], "--version"))
59 return printVersion();
60 else if (!file && strncmp(argv[i], "--", 2))
61 file = argv[i];
62 else
63 return printUsage();
64 }
65
66 if (!file)
67 return printUsage();
68
69 librevenge::RVNGFileStream input(file);
70
71 if (!libabw::AbiDocument::isFileFormatSupported(&input))
72 {
73 fprintf(stderr, "ERROR: Unsupported file format!\n");
74 return 1;
75 }
76
77 librevenge::RVNGString document;
78 librevenge::RVNGHTMLTextGenerator documentGenerator(document);
79 if (!libabw::AbiDocument::parse(&input, &documentGenerator))
80 return 1;
81
82 printf("%s", document.cstr());
83
84 return 0;
85 }
86 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */