Debian Codegraph @

src/conv/raw/mwaw2raw.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 <string.h>
35
36 #include <librevenge/librevenge.h>
37 #include <librevenge-generators/librevenge-generators.h>
38 #include <librevenge-stream/librevenge-stream.h>
39
40 #include <libmwaw/libmwaw.hxx>
41
42 #ifdef HAVE_CONFIG_H
43 #include "config.h"
44 #endif
45
46 #include "helper.h"
47
48 #ifndef VERSION
49 #define VERSION "UNKNOWN VERSION"
50 #endif
51
52 static int printUsage()
53 {
54 printf("Usage: mwaw2raw [OPTION] <Text Document>\n");
55 printf("\n");
56 printf("Options:\n");
57 printf("\t--callgraph: Display the call graph nesting level\n");
58 printf("\t-h, --help: Shows this help message\n");
59 printf("\t-v, --version: Output mwaw2raw version \n");
60 return -1;
61 }
62
63 static int printVersion()
64 {
65 printf("mwaw2raw %s\n", VERSION);
66 return 0;
67 }
68
69 int main(int argc, char *argv[])
70 {
71 bool printIndentLevel = false;
72 char *file = NULL;
73
74 if (argc < 2)
75 return printUsage();
76
77 for (int i = 1; i < argc; i++) {
78 if (!strcmp(argv[i], "--callgraph"))
79 printIndentLevel = true;
80 else if (!strcmp(argv[i], "-v") || !strcmp(argv[i], "--version"))
81 return printVersion();
82 else if (!file && strncmp(argv[i], "--", 2) && strcmp(argv[i], "-h"))
83 file = argv[i];
84 else
85 return printUsage();
86 }
87
88 if (!file)
89 return printUsage();
90
91 MWAWDocument::Kind kind;
92 auto confidence = MWAWDocument::MWAW_C_NONE;
93 auto input=libmwawHelper::isSupported(file, confidence, kind);
94 if (!input || confidence != MWAWDocument::MWAW_C_EXCELLENT) {
95 printf("ERROR: Unsupported file format!\n");
96 return 1;
97 }
98
99 auto error = MWAWDocument::MWAW_R_OK;
100 try {
101 if (kind == MWAWDocument::MWAW_K_DRAW || kind == MWAWDocument::MWAW_K_PAINT) {
102 librevenge::RVNGRawDrawingGenerator documentGenerator(printIndentLevel);
103 error=MWAWDocument::parse(input.get(), &documentGenerator);
104 }
105 else if (kind == MWAWDocument::MWAW_K_SPREADSHEET || kind == MWAWDocument::MWAW_K_DATABASE) {
106 librevenge::RVNGRawSpreadsheetGenerator documentGenerator(printIndentLevel);
107 error=MWAWDocument::parse(input.get(), &documentGenerator);
108 }
109 else if (kind == MWAWDocument::MWAW_K_PRESENTATION) {
110 librevenge::RVNGRawPresentationGenerator documentGenerator(printIndentLevel);
111 error=MWAWDocument::parse(input.get(), &documentGenerator);
112 }
113 else {
114 librevenge::RVNGRawTextGenerator documentGenerator(printIndentLevel);
115 error=MWAWDocument::parse(input.get(), &documentGenerator);
116 }
117 }
118 catch (MWAWDocument::Result const &err) {
119 error=err;
120 }
121 catch (...) {
122 error = MWAWDocument::MWAW_R_UNKNOWN_ERROR;
123 }
124
125 if (libmwawHelper::checkErrorAndPrintMessage(error))
126 return 1;
127
128 return 0;
129 }
130 // vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: