Debian Codegraph @

src/conv/html/mwaw2html.cpp

raw
1 /* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
2 /* libmwaw
3 * Version: MPL 2.0 / LGPLv2+
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 2.0 (the "License"); you may not use this file except in compliance with
7 * the License or as specified alternatively below. You may obtain a copy of
8 * the License at http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * Major Contributor(s):
16 * Copyright (C) 2002 William Lachance ([email protected])
17 * Copyright (C) 2002,2004 Marc Maurer ([email protected])
18 * Copyright (C) 2004-2006 Fridrich Strba ([email protected])
19 * Copyright (C) 2006, 2007 Andrew Ziem
20 * Copyright (C) 2011, 2012 Alonso Laurent ([email protected])
21 *
22 *
23 * All Rights Reserved.
24 *
25 * For minor contributions see the git repository.
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
29 * in which case the provisions of the LGPLv2+ are applicable
30 * instead of those above.
31 */
32
33 #include <stdio.h>
34 #include <unistd.h>
35
36 #include <cstring>
37
38 #include <librevenge/librevenge.h>
39 #include <librevenge-generators/librevenge-generators.h>
40 #include <librevenge-stream/librevenge-stream.h>
41
42 #include <libmwaw/libmwaw.hxx>
43
44 #ifdef HAVE_CONFIG_H
45 #include "config.h"
46 #endif
47
48
49 #include "helper.h"
50
51 #ifndef VERSION
52 #define VERSION "UNKNOWN VERSION"
53 #endif
54
55 static int printUsage()
56 {
57 printf("Usage: mwaw2html [OPTION] <Text Mac Document>\n");
58 printf("\n");
59 printf("Options:\n");
60 printf("\t-h: Shows this help message\n");
61 printf("\t-v: Output mwaw2html version \n");
62 return -1;
63 }
64
65 static int printVersion()
66 {
67 printf("mwaw2html %s\n", VERSION);
68 return 0;
69 }
70
71 int main(int argc, char *argv[])
72 {
73 char const *file = 0;
74 bool printHelp=false;
75 int ch;
76
77 while ((ch = getopt(argc, argv, "hv")) != -1) {
78 switch (ch) {
79 case 'v':
80 printVersion();
81 return 0;
82 default:
83 case 'h':
84 printHelp = true;
85 break;
86 }
87 }
88 if (argc != 1+optind || printHelp) {
89 printUsage();
90 return -1;
91 }
92 file=argv[optind];
93
94 MWAWDocument::Kind kind;
95 auto confidence = MWAWDocument::MWAW_C_NONE;
96 auto input=libmwawHelper::isSupported(file, confidence, kind);
97 if (!input || confidence != MWAWDocument::MWAW_C_EXCELLENT) {
98 printf("ERROR: Unsupported file format!\n");
99 return 1;
100 }
101 if (kind != MWAWDocument::MWAW_K_TEXT) {
102 printf("ERROR: find a not text document!\n");
103 return 1;
104 }
105 auto error=MWAWDocument::MWAW_R_OK;
106 librevenge::RVNGString document;
107 try {
108 librevenge::RVNGHTMLTextGenerator documentGenerator(document);
109 error = MWAWDocument::parse(input.get(), &documentGenerator);
110 }
111 catch (MWAWDocument::Result &err) {
112 error=err;
113 }
114 catch (...) {
115 error=MWAWDocument::MWAW_R_UNKNOWN_ERROR;
116 }
117
118 if (libmwawHelper::checkErrorAndPrintMessage(error))
119 return 1;
120 printf("%s", document.cstr());
121
122 return 0;
123 }
124 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: