summaryrefslogtreecommitdiff
path: root/src/lib/Software602Document.cpp
blob: 5e4f0aac54508a5f3ec9634328a94e5ef2d3a55e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
 * This file is part of the libsw602 project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include <libsw602/Software602Document.h>

#include <librevenge-stream/librevenge-stream.h>

#include "WinText602Header.h"
#include "WinText602Parser.h"

using std::string;

namespace libsw602
{

namespace
{

RVNGInputStreamPtr getContent(librevenge::RVNGInputStream *const ip)
{
  const RVNGInputStreamPtr input(ip, SW602_shared_ptr_noop_deleter<librevenge::RVNGInputStream>());

  RVNGInputStreamPtr strm;
  if (input->isStructured())
    strm.reset(input->getSubStreamByName("CONTENTS"));

  return strm;
}

}

Software602Document::Confidence Software602Document::isSupported(librevenge::RVNGInputStream *const input, Kind &kind, Type *const type, bool *const needsEncoding) try
{
  if (!input)
    return CONFIDENCE_NONE;

  RVNGInputStreamPtr content = getContent(input);
  if (bool(content))
  {
    content->seek(0, librevenge::RVNG_SEEK_SET);
    WinText602Header header(*content);
    // TODO: handle encryption
    if (header.isValid())
    {
      kind = KIND_TEXT;
      if (type)
        *type = TYPE_WINTEXT602;
      if (needsEncoding)
        *needsEncoding = false;
      return CONFIDENCE_EXCELLENT;
    }
  }

  return CONFIDENCE_NONE;
}
catch (...)
{
  return CONFIDENCE_NONE;
}

Software602Document::Result Software602Document::parse(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document, const char *const password)
{
  return parse(input, document, TYPE_UNKNOWN, ENCODING_UNSPECIFIED, password);
}

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);
}

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)
  {
    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);
}

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 RESULT_UNKNOWN_ERROR;
}

} // namespace libsw602

/* vim:set shiftwidth=2 softtabstop=2 expandtab: */