Debian Codegraph @

src/conv/html/wps2html.cpp

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2 /* libwps
3 * Version: MPL 2.0 / LGPLv2.1+
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 * Major Contributor(s):
10 * Copyright (C) 2002-2003 William Lachance ([email protected])
11 * Copyright (C) 2002-2004 Marc Maurer ([email protected])
12 *
13 * For minor contributions see the git repository.
14 *
15 * Alternatively, the contents of this file may be used under the terms
16 * of the GNU Lesser General Public License Version 2.1 or later
17 * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
18 * applicable instead of those above.
19 *
20 * For further information visit http://libwps.sourceforge.net
21 */
22
23 #include <stdio.h>
24 #include <unistd.h>
25
26 #include <cstring>
27
28 #include <librevenge/librevenge.h>
29 #include <librevenge-generators/librevenge-generators.h>
30 #include <librevenge-stream/librevenge-stream.h>
31
32 #include <libwps/libwps.h>
33
34 #include "helper.h"
35
36 using namespace libwps;
37
38 #ifdef HAVE_CONFIG_H
39 #include "config.h"
40 #endif
41
42 #ifndef VERSION
43 #define VERSION "UNKNOWN VERSION"
44 #endif
45
46 static int printUsage()
47 {
48 printf("`wps2html' converts various Microsoft text document formats to HTML.\n");
49 printf("Supported formats are Microsoft Works, Write and Word for DOS.\n");
50 printf("\n");
51 printf("Usage: wps2html [OPTION] FILE\n");
52 printf("\n");
53 printf("Options:\n");
54 printf("\t-e ENCODING define the file encoding, where ENCODING can be\n");
55 printf("\t\t CP037, CP424, CP437, CP737, CP500, CP775, CP850, CP852, CP855, CP856, CP857,\n");
56 printf("\t\t CP860, CP861, CP862, CP863, CP864, CP865, CP866, CP869, CP874, CP875, CP932,\n");
57 printf("\t\t CP950, CP1006, CP1026, CP1250, CP1251, CP1252, CP1253, CP1254, CP1255, CP1256,\n");
58 printf("\t\t CP1257, CP1258, MacArabic, MacCeltic, MacCEurope, MacCroation, MacCyrillic,\n");
59 printf("\t\t MacDevanage, MacFarsi, MacGaelic, MacGreek, MacGujarati, MacGurmukhi, MacHebrew,\n");
60 printf("\t\t MacIceland, MacInuit, MacRoman, MacRomanian, MacThai, MacTurkish.\n");
61 printf("\t-h show this help message\n");
62 printf("\t-p PASSWORD set password to open the file\n");
63 printf("\t-v show version information\n");
64 printf("\n");
65 printf("Report bugs to <https://sourceforge.net/p/libwps/bugs/> or <https://bugs.documentfoundation.org/>.\n");
66 return -1;
67 }
68
69 static int printVersion()
70 {
71 printf("wps2html %s\n", VERSION);
72 return 0;
73 }
74
75 int main(int argc, char *argv[])
76 {
77 bool printHelp=false;
78 int ch;
79 char const *encoding="";
80 char const *password=nullptr;
81
82 while ((ch = getopt(argc, argv, "e:hp:v")) != -1)
83 {
84 switch (ch)
85 {
86 case 'e':
87 encoding=optarg;
88 break;
89 case 'p':
90 password=optarg;
91 break;
92 case 'v':
93 printVersion();
94 return 0;
95 default:
96 case 'h':
97 printHelp = true;
98 break;
99 }
100 }
101 if (argc != 1+optind || printHelp)
102 {
103 printUsage();
104 return -1;
105 }
106
107 librevenge::RVNGFileStream input(argv[optind]);
108
109 WPSCreator creator;
110 WPSKind kind;
111 bool needCharEncoding;
112 auto confidence = WPSDocument::isFileFormatSupported(&input,kind,creator,needCharEncoding);
113 if (confidence == WPS_CONFIDENCE_NONE || kind != WPS_TEXT)
114 {
115 printf("ERROR: Unsupported file format!\n");
116 return 1;
117 }
118
119 librevenge::RVNGString document;
120 librevenge::RVNGHTMLTextGenerator listenerImpl(document);
121 auto error = WPSDocument::parse(&input, &listenerImpl, password, encoding);
122
123 if (libwpsHelper::checkErrorAndPrintMessage(error))
124 return 1;
125
126 printf("%s", document.cstr());
127
128 return 0;
129 }
130 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */