summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Tardon <dtardon@redhat.com>2016-02-21 09:27:46 +0100
committerDavid Tardon <dtardon@redhat.com>2016-02-21 15:39:28 +0100
commit7f33506a73f655754f5ec35e1a1e290ac7c39356 (patch)
treee6a0c1cc98a152e6c6a71787b2302d0a2db5cf42 /src
parent1fae47f268a6aff3ac95fadf287a1b73f26a9e62 (diff)
extend interface to cover all expected use cases
I.e., handling of multiple document formats (and kinds), password protected documents, documents in unknown encoding.
Diffstat (limited to 'src')
-rw-r--r--src/conv/html/sw6022html.cpp12
-rw-r--r--src/conv/raw/sw6022raw.cpp26
-rw-r--r--src/conv/text/sw6022text.cpp13
-rw-r--r--src/lib/Software602Document.cpp99
4 files changed, 118 insertions, 32 deletions
diff --git a/src/conv/html/sw6022html.cpp b/src/conv/html/sw6022html.cpp
index 247a669..1c08d76 100644
--- a/src/conv/html/sw6022html.cpp
+++ b/src/conv/html/sw6022html.cpp
@@ -76,14 +76,16 @@ int main(int argc, char *argv[])
librevenge::RVNGFileStream input(file);
- librevenge::RVNGString document;
- librevenge::RVNGHTMLTextGenerator documentGenerator(document);
-
- if (!Software602Document::isSupported(&input))
+ Software602Document::Kind kind = Software602Document::KIND_UNKNOWN;
+ const Software602Document::Confidence confidence = Software602Document::isSupported(&input, kind);
+ if ((kind != Software602Document::KIND_TEXT) || (confidence != Software602Document::CONFIDENCE_EXCELLENT))
fprintf(stderr, "unsupported file format\n");
return 1;
- if (!Software602Document::parse(&input, &documentGenerator))
+ librevenge::RVNGString document;
+
+ librevenge::RVNGHTMLTextGenerator documentGenerator(document);
+ if (Software602Document::parse(&input, &documentGenerator) != Software602Document::RESULT_OK)
{
fprintf(stderr, "parsing failed\n");
return 1;
diff --git a/src/conv/raw/sw6022raw.cpp b/src/conv/raw/sw6022raw.cpp
index e09dcd9..fae6dc7 100644
--- a/src/conv/raw/sw6022raw.cpp
+++ b/src/conv/raw/sw6022raw.cpp
@@ -83,12 +83,30 @@ int main(int argc, char *argv[])
librevenge::RVNGFileStream input(file);
- librevenge::RVNGRawTextGenerator documentGenerator(printIndentLevel);
+ Software602Document::Kind kind = Software602Document::KIND_UNKNOWN;
+ const Software602Document::Confidence confidence = Software602Document::isSupported(&input, kind);
+ if (confidence != Software602Document::CONFIDENCE_EXCELLENT)
+ fprintf(stderr, "unsupported file format\n");
+ return 1;
- if (!Software602Document::isSupported(&input))
+ switch (kind)
+ {
+ case Software602Document::KIND_TEXT:
+ {
+ librevenge::RVNGRawTextGenerator documentGenerator(printIndentLevel);
+ return Software602Document::parse(&input, &documentGenerator) == Software602Document::RESULT_OK;
+ }
+ case Software602Document::KIND_SPREADSHEET:
+ case Software602Document::KIND_CHART:
+ case Software602Document::KIND_DATABASE:
+ {
+ librevenge::RVNGRawSpreadsheetGenerator documentGenerator(printIndentLevel);
+ return Software602Document::parse(&input, &documentGenerator) == Software602Document::RESULT_OK;
+ }
+ default:
+ fprintf(stderr, "unsupported file format\n");
return 1;
-
- return Software602Document::parse(&input, &documentGenerator) ? 0 : 1;
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */
diff --git a/src/conv/text/sw6022text.cpp b/src/conv/text/sw6022text.cpp
index 522f209..b6cbaa3 100644
--- a/src/conv/text/sw6022text.cpp
+++ b/src/conv/text/sw6022text.cpp
@@ -80,14 +80,16 @@ int main(int argc, char *argv[])
librevenge::RVNGFileStream input(szInputFile);
- librevenge::RVNGString document;
- librevenge::RVNGTextTextGenerator documentGenerator(document, isInfo);
-
- if (!Software602Document::isSupported(&input))
+ Software602Document::Kind kind = Software602Document::KIND_UNKNOWN;
+ const Software602Document::Confidence confidence = Software602Document::isSupported(&input, kind);
+ if ((kind != Software602Document::KIND_TEXT) || (confidence != Software602Document::CONFIDENCE_EXCELLENT))
fprintf(stderr, "unsupported file format\n");
return 1;
- if (!Software602Document::parse(&input, &documentGenerator))
+ librevenge::RVNGString document;
+
+ librevenge::RVNGTextTextGenerator documentGenerator(document, isInfo);
+ if (Software602Document::parse(&input, &documentGenerator) != Software602Document::RESULT_OK)
{
fprintf(stderr, "parsing failed\n");
return 1;
@@ -95,7 +97,6 @@ int main(int argc, char *argv[])
printf("%s", document.cstr());
-
return 0;
}
diff --git a/src/lib/Software602Document.cpp b/src/lib/Software602Document.cpp
index 33c01a2..acc0670 100644
--- a/src/lib/Software602Document.cpp
+++ b/src/lib/Software602Document.cpp
@@ -35,47 +35,112 @@ RVNGInputStreamPtr getContent(librevenge::RVNGInputStream *const ip)
}
-bool Software602Document::isSupported(librevenge::RVNGInputStream *input) try
+Software602Document::Confidence Software602Document::isSupported(librevenge::RVNGInputStream *const input, Kind &kind, Type *const type, bool *const needsEncoding) try
{
if (!input)
- return false;
+ return CONFIDENCE_NONE;
RVNGInputStreamPtr content = getContent(input);
if (bool(content))
{
content->seek(0, librevenge::RVNG_SEEK_SET);
WinText602Header header(content.get());
- return header.isValid();
+ // TODO: handle encryption
+ if (header.isValid())
+ {
+ kind = KIND_TEXT;
+ if (type)
+ *type = TYPE_WINTEXT602;
+ if (needsEncoding)
+ *needsEncoding = false;
+ return CONFIDENCE_EXCELLENT;
+ }
}
- return false;
+ return CONFIDENCE_NONE;
}
catch (...)
{
- return false;
+ return CONFIDENCE_NONE;
}
-bool Software602Document::parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *document) try
+Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const char *const password)
{
- if (!input || !document)
- return false;
+ return parse(input, document, TYPE_UNKNOWN, ENCODING_UNSPECIFIED, password);
+}
- if (!Software602Document::isSupported(input))
- return false;
+Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const Type type, const char *const password)
+{
+ return parse(input, document, type, ENCODING_UNSPECIFIED, password);
+}
- RVNGInputStreamPtr content = getContent(input);
- if (bool(content))
+Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const Encoding encoding, const char *const password)
+{
+ return parse(input, document, TYPE_UNKNOWN, encoding, password);
+}
+
+Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, Type type, Encoding /*encoding*/, const char * /*password*/) try
+{
+ if (!document)
+ return RESULT_OK;
+ if (!input)
+ return RESULT_PARSE_ERROR;
+
+ if (type == TYPE_UNKNOWN)
{
- content->seek(0, librevenge::RVNG_SEEK_SET);
- WinText602Parser parser(content.get(), document);
- return parser.parse();
+ Kind kind = KIND_UNKNOWN;
+ const Confidence confidence = Software602Document::isSupported(input, kind, &type);
+ if ((kind != KIND_TEXT) || ((confidence != CONFIDENCE_EXCELLENT) && (confidence != CONFIDENCE_SUPPORTED_ENCRYPTION)))
+ return RESULT_UNSUPPORTED_FORMAT;
+ }
+
+ switch (type)
+ {
+ case TYPE_WINTEXT602:
+ {
+ RVNGInputStreamPtr content = getContent(input);
+ if (bool(content))
+ {
+ content->seek(0, librevenge::RVNG_SEEK_SET);
+ WinText602Parser parser(content.get(), document);
+ return parser.parse() ? RESULT_OK : RESULT_PARSE_ERROR;
+ }
+ break;
}
+ default:
+ return RESULT_UNSUPPORTED_FORMAT;
+ }
+
+ return RESULT_UNKNOWN_ERROR;
+}
+catch (...)
+{
+ return RESULT_UNKNOWN_ERROR;
+}
+
+Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream *input, librevenge::RVNGSpreadsheetInterface *document, const char *password)
+{
+ return parse(input, document, TYPE_UNKNOWN, ENCODING_UNSPECIFIED, password);
+}
+
+Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream *input, librevenge::RVNGSpreadsheetInterface *document, Type type, const char *password)
+{
+ return parse(input, document, type, ENCODING_UNSPECIFIED, password);
+}
- return false;
+Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream *input, librevenge::RVNGSpreadsheetInterface *document, Encoding encoding, const char *password)
+{
+ return parse(input, document, TYPE_UNKNOWN, encoding, password);
+}
+
+Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream * /*input*/, librevenge::RVNGSpreadsheetInterface * /*document*/, Type /*type*/, Encoding /*encoding*/, const char * /*password*/) try
+{
+ // TODO: implement me
+ return RESULT_UNKNOWN_ERROR;
}
catch (...)
{
- return false;
+ return RESULT_UNKNOWN_ERROR;
}
} // namespace libsw602