Debian Codegraph @

src/conv/wks2raw/wks2raw.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 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 <string.h>
25 #include <unistd.h>
26
27 #include <librevenge/librevenge.h>
28 #include <librevenge-generators/librevenge-generators.h>
29 #include <librevenge-stream/librevenge-stream.h>
30
31 #include <libwps/libwps.h>
32
33 #include "helper.h"
34
35 #ifdef HAVE_CONFIG_H
36 #include "config.h"
37 #endif
38
39 #ifndef VERSION
40 #define VERSION "UNKNOWN VERSION"
41 #endif
42
43 static int printUsage()
44 {
45 printf("`wks2raw' is used to test spreadsheet import in libwps.\n");
46 printf("Supported formats are Microsoft Works Spreadsheet and Database, Lotus Wk1-Wk4 and Quattro Pro Wq1-Wq2.\n");
47 printf("\n");
48 printf("Usage: wks2raw [OPTION] FILE\n");
49 printf("\n");
50 printf("Options:\n");
51 printf("\t-h, --help show this help message\n");
52 printf("\t-v, --version show version information\n");
53 printf("\t--callgraph display the call graph nesting level\n");
54 printf("\t--password PASSWORD set password to open the file\n");
55 printf("\n");
56 printf("Report bugs to <https://sourceforge.net/p/libwps/bugs/> or <https://bugs.documentfoundation.org/>.\n");
57 return -1;
58 }
59
60 static int printVersion()
61 {
62 printf("wks2raw %s\n", VERSION);
63 return 0;
64 }
65
66 using namespace libwps;
67
68 int main(int argc, char *argv[])
69 {
70 bool printIndentLevel = false;
71 char *file = nullptr;
72 char const *password=nullptr;
73
74 for (int arg=1; arg<argc; ++arg)
75 {
76 if (!strcmp(argv[arg], "-h") || !strcmp(argv[arg], "--help"))
77 return printUsage();
78 if (!strcmp(argv[arg], "-v") || !strcmp(argv[arg], "--version"))
79 return printVersion();
80 if (!strcmp(argv[arg], "--callgraph"))
81 {
82 printIndentLevel = true;
83 continue;
84 }
85 if (!strcmp(argv[arg], "--password"))
86 {
87 if (arg+1>=argc)
88 return printUsage();
89 password=argv[++arg];
90 continue;
91 }
92 if (file)
93 return printUsage();
94 file = argv[arg];
95 }
96 if (!file)
97 return printUsage();
98
99 WPSConfidence confidence;
100 WPSKind kind;
101 bool needCharEncoding;
102 auto input=libwpsHelper::isSupported(file,confidence, kind,needCharEncoding);
103 if (!input || confidence == WPS_CONFIDENCE_NONE || (kind != WPS_SPREADSHEET && kind != WPS_DATABASE))
104 {
105 printf("ERROR: Unsupported file format!\n");
106 return 1;
107 }
108
109 librevenge::RVNGRawSpreadsheetGenerator listenerImpl(printIndentLevel);
110 auto error= WPSDocument::parse(input.get(), &listenerImpl, password);
111
112 if (libwpsHelper::checkErrorAndPrintMessage(error))
113 return 1;
114
115 return 0;
116 }
117 /* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */