| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
/** \file MWAWDocument.cxx |
| 35 |
* libmwaw API: implementation of main interface functions |
| 36 |
*/ |
| 37 |
|
| 38 |
#include "MWAWHeader.hxx" |
| 39 |
#include "MWAWGraphicDecoder.hxx" |
| 40 |
#include "MWAWParser.hxx" |
| 41 |
#include "MWAWPropertyHandler.hxx" |
| 42 |
#include "MWAWRSRCParser.hxx" |
| 43 |
#include "MWAWSpreadsheetDecoder.hxx" |
| 44 |
|
| 45 |
#include <libmwaw/libmwaw.hxx> |
| 46 |
|
| 47 |
#include "ActaParser.hxx" |
| 48 |
#include "ApplePictParser.hxx" |
| 49 |
#include "BeagleWksParser.hxx" |
| 50 |
#include "BeagleWksBMParser.hxx" |
| 51 |
#include "BeagleWksDBParser.hxx" |
| 52 |
#include "BeagleWksDRParser.hxx" |
| 53 |
#include "BeagleWksSSParser.hxx" |
| 54 |
#include "CanvasParser.hxx" |
| 55 |
#include "Canvas5BMParser.hxx" |
| 56 |
#include "Canvas5Parser.hxx" |
| 57 |
#include "ClarisDrawParser.hxx" |
| 58 |
#include "ClarisWksParser.hxx" |
| 59 |
#include "ClarisWksBMParser.hxx" |
| 60 |
#include "ClarisWksPRParser.hxx" |
| 61 |
#include "ClarisWksSSParser.hxx" |
| 62 |
#include "CorelPainterParser.hxx" |
| 63 |
#include "CricketDrawParser.hxx" |
| 64 |
#include "DocMkrParser.hxx" |
| 65 |
#include "DrawTableParser.hxx" |
| 66 |
#include "EDocParser.hxx" |
| 67 |
#include "FreeHandParser.hxx" |
| 68 |
#include "FullWrtParser.hxx" |
| 69 |
#include "GreatWksParser.hxx" |
| 70 |
#include "GreatWksBMParser.hxx" |
| 71 |
#include "GreatWksDBParser.hxx" |
| 72 |
#include "GreatWksDRParser.hxx" |
| 73 |
#include "GreatWksSSParser.hxx" |
| 74 |
#include "HanMacWrdJParser.hxx" |
| 75 |
#include "HanMacWrdKParser.hxx" |
| 76 |
#include "JazzSSParser.hxx" |
| 77 |
#include "JazzWriterParser.hxx" |
| 78 |
#include "LightWayTxtParser.hxx" |
| 79 |
#include "MacDocParser.hxx" |
| 80 |
#include "MacDraftParser.hxx" |
| 81 |
#include "MacDraft5Parser.hxx" |
| 82 |
#include "MacDrawParser.hxx" |
| 83 |
#include "MacDrawProParser.hxx" |
| 84 |
#include "MacPaintParser.hxx" |
| 85 |
#include "MacWrtParser.hxx" |
| 86 |
#include "MacWrtProParser.hxx" |
| 87 |
#include "MarinerWrtParser.hxx" |
| 88 |
#include "MaxWrtParser.hxx" |
| 89 |
#include "MindWrtParser.hxx" |
| 90 |
#include "MoreParser.hxx" |
| 91 |
#include "MouseWrtParser.hxx" |
| 92 |
#include "MsWksParser.hxx" |
| 93 |
#include "MsWksDBParser.hxx" |
| 94 |
#include "MsWksDRParser.hxx" |
| 95 |
#include "MsWksSSParser.hxx" |
| 96 |
#include "MsWrd1Parser.hxx" |
| 97 |
#include "MsWrdParser.hxx" |
| 98 |
#include "MultiplanParser.hxx" |
| 99 |
#include "NisusWrtParser.hxx" |
| 100 |
#include "PixelPaintParser.hxx" |
| 101 |
#include "PowerPoint1Parser.hxx" |
| 102 |
#include "PowerPoint3Parser.hxx" |
| 103 |
#include "PowerPoint7Parser.hxx" |
| 104 |
#include "RagTimeParser.hxx" |
| 105 |
#include "RagTime5Parser.hxx" |
| 106 |
#include "RagTime5SSParser.hxx" |
| 107 |
#include "ReadySetGoParser.hxx" |
| 108 |
#include "ScoopParser.hxx" |
| 109 |
#include "ScriptWriterParser.hxx" |
| 110 |
#include "SpringBoardParser.hxx" |
| 111 |
#include "StudentWritingCParser.hxx" |
| 112 |
#include "StyleParser.hxx" |
| 113 |
#include "SuperPaintParser.hxx" |
| 114 |
#include "TeachTxtParser.hxx" |
| 115 |
#include "WingzParser.hxx" |
| 116 |
#include "WordMakerParser.hxx" |
| 117 |
#include "WriteNowParser.hxx" |
| 118 |
#include "WriterPlsParser.hxx" |
| 119 |
#include "ZWrtParser.hxx" |
| 120 |
|
| 121 |
/** small namespace use to define private class/method used by MWAWDocument */ |
| 122 |
namespace MWAWDocumentInternal |
| 123 |
{ |
| 124 |
std::shared_ptr<MWAWGraphicParser> getGraphicParserFromHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 125 |
std::shared_ptr<MWAWPresentationParser> getPresentationParserFromHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 126 |
std::shared_ptr<MWAWSpreadsheetParser> getSpreadsheetParserFromHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 127 |
std::shared_ptr<MWAWTextParser> getTextParserFromHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header); |
| 128 |
MWAWHeader *getHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, bool strict); |
| 129 |
bool checkBasicMacHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader &header, bool strict); |
| 130 |
} |
| 131 |
|
| 132 |
MWAWDocument::Confidence MWAWDocument::isFileFormatSupported(librevenge::RVNGInputStream *input, MWAWDocument::Type &type, Kind &kind) |
| 133 |
try |
| 134 |
{ |
| 135 |
type = MWAW_T_UNKNOWN; |
| 136 |
kind = MWAW_K_UNKNOWN; |
| 137 |
|
| 138 |
if (!input) { |
| 139 |
MWAW_DEBUG_MSG(("MWAWDocument::isFileFormatSupported(): no input\n")); |
| 140 |
return MWAW_C_NONE; |
| 141 |
} |
| 142 |
|
| 143 |
MWAWInputStreamPtr ip(new MWAWInputStream(input, false, true)); |
| 144 |
MWAWInputStreamPtr rsrc=ip->getResourceForkStream(); |
| 145 |
std::shared_ptr<MWAWRSRCParser> rsrcParser; |
| 146 |
if (rsrc) |
| 147 |
rsrcParser.reset(new MWAWRSRCParser(rsrc)); |
| 148 |
|
| 149 |
std::shared_ptr<MWAWHeader> header; |
| 150 |
#ifdef DEBUG |
| 151 |
header.reset(MWAWDocumentInternal::getHeader(ip, rsrcParser, false)); |
| 152 |
#else |
| 153 |
header.reset(MWAWDocumentInternal::getHeader(ip, rsrcParser, true)); |
| 154 |
#endif |
| 155 |
|
| 156 |
if (!header.get()) |
| 157 |
return MWAW_C_NONE; |
| 158 |
type = static_cast<MWAWDocument::Type>(header->getType()); |
| 159 |
kind = static_cast<MWAWDocument::Kind>(header->getKind()); |
| 160 |
Confidence confidence = MWAW_C_NONE; |
| 161 |
|
| 162 |
switch (type) { |
| 163 |
case MWAW_T_ACTA: |
| 164 |
case MWAW_T_APPLEPICT: |
| 165 |
case MWAW_T_BEAGLEWORKS: |
| 166 |
case MWAW_T_CANVAS: |
| 167 |
case MWAW_T_CLARISDRAW: |
| 168 |
case MWAW_T_CLARISRESOLVE: |
| 169 |
case MWAW_T_CLARISWORKS: |
| 170 |
case MWAW_T_CORELPAINTER: |
| 171 |
case MWAW_T_CRICKETDRAW: |
| 172 |
case MWAW_T_DOCMAKER: |
| 173 |
case MWAW_T_DRAWINGTABLE: |
| 174 |
case MWAW_T_EDOC: |
| 175 |
case MWAW_T_FREEHAND: |
| 176 |
case MWAW_T_FULLPAINT: |
| 177 |
case MWAW_T_FULLWRITE: |
| 178 |
case MWAW_T_GREATWORKS: |
| 179 |
case MWAW_T_HANMACWORDJ: |
| 180 |
case MWAW_T_HANMACWORDK: |
| 181 |
case MWAW_T_LIGHTWAYTEXT: |
| 182 |
case MWAW_T_JAZZLOTUS: |
| 183 |
case MWAW_T_MACDOC: |
| 184 |
case MWAW_T_MACDRAFT: |
| 185 |
case MWAW_T_MACDRAW: |
| 186 |
case MWAW_T_MACDRAWPRO: |
| 187 |
case MWAW_T_MACPAINT: |
| 188 |
case MWAW_T_MACWRITE: |
| 189 |
case MWAW_T_MACWRITEPRO: |
| 190 |
case MWAW_T_MARINERWRITE: |
| 191 |
case MWAW_T_MAXWRITE: |
| 192 |
case MWAW_T_MINDWRITE: |
| 193 |
case MWAW_T_MORE: |
| 194 |
case MWAW_T_MOUSEWRITE: |
| 195 |
case MWAW_T_MICROSOFTMULTIPLAN: |
| 196 |
case MWAW_T_MICROSOFTWORD: |
| 197 |
case MWAW_T_MICROSOFTWORKS: |
| 198 |
case MWAW_T_NISUSWRITER: |
| 199 |
case MWAW_T_PIXELPAINT: |
| 200 |
case MWAW_T_POWERPOINT: |
| 201 |
case MWAW_T_RAGTIME: |
| 202 |
case MWAW_T_READYSETGO: |
| 203 |
case MWAW_T_SCOOP: |
| 204 |
case MWAW_T_SCRIPTWRITER: |
| 205 |
case MWAW_T_SPRINGBOARD_PUBLISHER: |
| 206 |
case MWAW_T_STUDENTWRITING: |
| 207 |
case MWAW_T_STYLE: |
| 208 |
case MWAW_T_SUPERPAINT: |
| 209 |
case MWAW_T_TEACHTEXT: |
| 210 |
case MWAW_T_TEXEDIT: |
| 211 |
case MWAW_T_WINGZ: |
| 212 |
case MWAW_T_WORDMAKER: |
| 213 |
case MWAW_T_WRITENOW: |
| 214 |
case MWAW_T_WRITERPLUS: |
| 215 |
case MWAW_T_XPRESS: |
| 216 |
case MWAW_T_ZWRITE: |
| 217 |
confidence = MWAW_C_EXCELLENT; |
| 218 |
break; |
| 219 |
|
| 220 |
case MWAW_T_ADOBEILLUSTRATOR: |
| 221 |
case MWAW_T_DBASE: |
| 222 |
case MWAW_T_FAMILYTREEMAKER: |
| 223 |
case MWAW_T_FILEMAKER: |
| 224 |
case MWAW_T_FOXBASE: |
| 225 |
case MWAW_T_FRAMEMAKER: |
| 226 |
case MWAW_T_FULLIMPACT: |
| 227 |
case MWAW_T_INFOGENIE: |
| 228 |
case MWAW_T_KALEIDAGRAPH: |
| 229 |
case MWAW_T_MICROSOFTFILE: |
| 230 |
case MWAW_T_OVERVUE: |
| 231 |
case MWAW_T_PAGEMAKER: |
| 232 |
case MWAW_T_SYMPOSIUM: |
| 233 |
case MWAW_T_TRAPEZE: |
| 234 |
case MWAW_T_4DIMENSION: |
| 235 |
|
| 236 |
case MWAW_T_RESERVED18: |
| 237 |
case MWAW_T_RESERVED19: |
| 238 |
case MWAW_T_RESERVED20: |
| 239 |
case MWAW_T_RESERVED21: |
| 240 |
case MWAW_T_RESERVED22: |
| 241 |
case MWAW_T_RESERVED23: |
| 242 |
case MWAW_T_RESERVED24: |
| 243 |
case MWAW_T_RESERVED25: |
| 244 |
case MWAW_T_RESERVED26: |
| 245 |
case MWAW_T_RESERVED27: |
| 246 |
case MWAW_T_RESERVED28: |
| 247 |
case MWAW_T_RESERVED29: |
| 248 |
|
| 249 |
case MWAW_T_UNKNOWN: |
| 250 |
#if !defined(__clang__) |
| 251 |
default: |
| 252 |
#endif |
| 253 |
break; |
| 254 |
} |
| 255 |
|
| 256 |
return confidence; |
| 257 |
} |
| 258 |
catch (...) |
| 259 |
{ |
| 260 |
MWAW_DEBUG_MSG(("MWAWDocument::isFileFormatSupported: exception catched\n")); |
| 261 |
type = MWAW_T_UNKNOWN; |
| 262 |
kind = MWAW_K_UNKNOWN; |
| 263 |
return MWAW_C_NONE; |
| 264 |
} |
| 265 |
|
| 266 |
MWAWDocument::Result MWAWDocument::parse(librevenge::RVNGInputStream *input, librevenge::RVNGDrawingInterface *documentInterface, char const *) |
| 267 |
try |
| 268 |
{ |
| 269 |
if (!input) |
| 270 |
return MWAW_R_UNKNOWN_ERROR; |
| 271 |
|
| 272 |
MWAWInputStreamPtr ip(new MWAWInputStream(input, false, true)); |
| 273 |
MWAWInputStreamPtr rsrc=ip->getResourceForkStream(); |
| 274 |
std::shared_ptr<MWAWRSRCParser> rsrcParser; |
| 275 |
if (rsrc) { |
| 276 |
rsrcParser.reset(new MWAWRSRCParser(rsrc)); |
| 277 |
rsrcParser->setAsciiName("RSRC"); |
| 278 |
rsrcParser->parse(); |
| 279 |
} |
| 280 |
std::shared_ptr<MWAWHeader> header(MWAWDocumentInternal::getHeader(ip, rsrcParser, false)); |
| 281 |
|
| 282 |
if (!header.get()) return MWAW_R_UNKNOWN_ERROR; |
| 283 |
|
| 284 |
auto parser=MWAWDocumentInternal::getGraphicParserFromHeader(ip, rsrcParser, header.get()); |
| 285 |
if (!parser) return MWAW_R_UNKNOWN_ERROR; |
| 286 |
parser->parse(documentInterface); |
| 287 |
|
| 288 |
return MWAW_R_OK; |
| 289 |
} |
| 290 |
catch (libmwaw::FileException) |
| 291 |
{ |
| 292 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: File exception trapped\n")); |
| 293 |
return MWAW_R_FILE_ACCESS_ERROR; |
| 294 |
} |
| 295 |
catch (libmwaw::ParseException) |
| 296 |
{ |
| 297 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: Parse exception trapped\n")); |
| 298 |
return MWAW_R_PARSE_ERROR; |
| 299 |
} |
| 300 |
catch (...) |
| 301 |
{ |
| 302 |
//fixme: too generic |
| 303 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: Unknown exception trapped\n")); |
| 304 |
return MWAW_R_UNKNOWN_ERROR; |
| 305 |
} |
| 306 |
|
| 307 |
MWAWDocument::Result MWAWDocument::parse(librevenge::RVNGInputStream *input, librevenge::RVNGPresentationInterface *documentInterface, char const *) |
| 308 |
try |
| 309 |
{ |
| 310 |
if (!input) |
| 311 |
return MWAW_R_UNKNOWN_ERROR; |
| 312 |
|
| 313 |
MWAWInputStreamPtr ip(new MWAWInputStream(input, false, true)); |
| 314 |
MWAWInputStreamPtr rsrc=ip->getResourceForkStream(); |
| 315 |
std::shared_ptr<MWAWRSRCParser> rsrcParser; |
| 316 |
if (rsrc) { |
| 317 |
rsrcParser.reset(new MWAWRSRCParser(rsrc)); |
| 318 |
rsrcParser->setAsciiName("RSRC"); |
| 319 |
rsrcParser->parse(); |
| 320 |
} |
| 321 |
std::shared_ptr<MWAWHeader> header(MWAWDocumentInternal::getHeader(ip, rsrcParser, false)); |
| 322 |
|
| 323 |
if (!header.get()) return MWAW_R_UNKNOWN_ERROR; |
| 324 |
|
| 325 |
auto parser=MWAWDocumentInternal::getPresentationParserFromHeader(ip, rsrcParser, header.get()); |
| 326 |
if (!parser) return MWAW_R_UNKNOWN_ERROR; |
| 327 |
parser->parse(documentInterface); |
| 328 |
|
| 329 |
return MWAW_R_OK; |
| 330 |
} |
| 331 |
catch (libmwaw::FileException) |
| 332 |
{ |
| 333 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: File exception trapped\n")); |
| 334 |
return MWAW_R_FILE_ACCESS_ERROR; |
| 335 |
} |
| 336 |
catch (libmwaw::ParseException) |
| 337 |
{ |
| 338 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: Parse exception trapped\n")); |
| 339 |
return MWAW_R_PARSE_ERROR; |
| 340 |
} |
| 341 |
catch (...) |
| 342 |
{ |
| 343 |
//fixme: too generic |
| 344 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: Unknown exception trapped\n")); |
| 345 |
return MWAW_R_UNKNOWN_ERROR; |
| 346 |
} |
| 347 |
|
| 348 |
MWAWDocument::Result MWAWDocument::parse(librevenge::RVNGInputStream *input, librevenge::RVNGSpreadsheetInterface *documentInterface, char const *) |
| 349 |
try |
| 350 |
{ |
| 351 |
if (!input) |
| 352 |
return MWAW_R_UNKNOWN_ERROR; |
| 353 |
|
| 354 |
MWAWInputStreamPtr ip(new MWAWInputStream(input, false, true)); |
| 355 |
MWAWInputStreamPtr rsrc=ip->getResourceForkStream(); |
| 356 |
std::shared_ptr<MWAWRSRCParser> rsrcParser; |
| 357 |
if (rsrc) { |
| 358 |
rsrcParser.reset(new MWAWRSRCParser(rsrc)); |
| 359 |
rsrcParser->setAsciiName("RSRC"); |
| 360 |
rsrcParser->parse(); |
| 361 |
} |
| 362 |
std::shared_ptr<MWAWHeader> header(MWAWDocumentInternal::getHeader(ip, rsrcParser, false)); |
| 363 |
|
| 364 |
if (!header.get()) return MWAW_R_UNKNOWN_ERROR; |
| 365 |
|
| 366 |
auto parser=MWAWDocumentInternal::getSpreadsheetParserFromHeader(ip, rsrcParser, header.get()); |
| 367 |
if (!parser) return MWAW_R_UNKNOWN_ERROR; |
| 368 |
parser->parse(documentInterface); |
| 369 |
|
| 370 |
return MWAW_R_OK; |
| 371 |
} |
| 372 |
catch (libmwaw::FileException) |
| 373 |
{ |
| 374 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: File exception trapped\n")); |
| 375 |
return MWAW_R_FILE_ACCESS_ERROR; |
| 376 |
} |
| 377 |
catch (libmwaw::ParseException) |
| 378 |
{ |
| 379 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: Parse exception trapped\n")); |
| 380 |
return MWAW_R_PARSE_ERROR; |
| 381 |
} |
| 382 |
catch (...) |
| 383 |
{ |
| 384 |
//fixme: too generic |
| 385 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: Unknown exception trapped\n")); |
| 386 |
return MWAW_R_UNKNOWN_ERROR; |
| 387 |
} |
| 388 |
|
| 389 |
MWAWDocument::Result MWAWDocument::parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *documentInterface, char const * /*password*/) |
| 390 |
try |
| 391 |
{ |
| 392 |
if (!input) |
| 393 |
return MWAW_R_UNKNOWN_ERROR; |
| 394 |
|
| 395 |
MWAWInputStreamPtr ip(new MWAWInputStream(input, false, true)); |
| 396 |
MWAWInputStreamPtr rsrc=ip->getResourceForkStream(); |
| 397 |
std::shared_ptr<MWAWRSRCParser> rsrcParser; |
| 398 |
if (rsrc) { |
| 399 |
rsrcParser.reset(new MWAWRSRCParser(rsrc)); |
| 400 |
rsrcParser->setAsciiName("RSRC"); |
| 401 |
rsrcParser->parse(); |
| 402 |
} |
| 403 |
std::shared_ptr<MWAWHeader> header(MWAWDocumentInternal::getHeader(ip, rsrcParser, false)); |
| 404 |
|
| 405 |
if (!header.get()) return MWAW_R_UNKNOWN_ERROR; |
| 406 |
|
| 407 |
auto parser=MWAWDocumentInternal::getTextParserFromHeader(ip, rsrcParser, header.get()); |
| 408 |
if (!parser) return MWAW_R_UNKNOWN_ERROR; |
| 409 |
parser->parse(documentInterface); |
| 410 |
|
| 411 |
return MWAW_R_OK; |
| 412 |
} |
| 413 |
catch (libmwaw::FileException) |
| 414 |
{ |
| 415 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: File exception trapped\n")); |
| 416 |
return MWAW_R_FILE_ACCESS_ERROR; |
| 417 |
} |
| 418 |
catch (libmwaw::ParseException) |
| 419 |
{ |
| 420 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: Parse exception trapped\n")); |
| 421 |
return MWAW_R_PARSE_ERROR; |
| 422 |
} |
| 423 |
catch (...) |
| 424 |
{ |
| 425 |
//fixme: too generic |
| 426 |
MWAW_DEBUG_MSG(("MWAWDocument::parse: Unknown exception trapped\n")); |
| 427 |
return MWAW_R_UNKNOWN_ERROR; |
| 428 |
} |
| 429 |
|
| 430 |
bool MWAWDocument::decodeGraphic(librevenge::RVNGBinaryData const &binary, librevenge::RVNGDrawingInterface *paintInterface) |
| 431 |
try |
| 432 |
{ |
| 433 |
if (!paintInterface || !binary.size()) { |
| 434 |
MWAW_DEBUG_MSG(("MWAWDocument::decodeGraphic: called with no data or no converter\n")); |
| 435 |
return false; |
| 436 |
} |
| 437 |
MWAWGraphicDecoder tmpHandler(paintInterface); |
| 438 |
if (!tmpHandler.checkData(binary) || !tmpHandler.readData(binary)) return false; |
| 439 |
return true; |
| 440 |
} |
| 441 |
catch (...) |
| 442 |
{ |
| 443 |
MWAW_DEBUG_MSG(("MWAWDocument::decodeGraphic: unknown error\n")); |
| 444 |
return false; |
| 445 |
} |
| 446 |
|
| 447 |
bool MWAWDocument::decodeSpreadsheet(librevenge::RVNGBinaryData const &binary, librevenge::RVNGSpreadsheetInterface *sheetInterface) |
| 448 |
try |
| 449 |
{ |
| 450 |
if (!sheetInterface || !binary.size()) { |
| 451 |
MWAW_DEBUG_MSG(("MWAWDocument::decodeSpreadsheet: called with no data or no converter\n")); |
| 452 |
return false; |
| 453 |
} |
| 454 |
MWAWSpreadsheetDecoder tmpHandler(sheetInterface); |
| 455 |
if (!tmpHandler.checkData(binary) || !tmpHandler.readData(binary)) return false; |
| 456 |
return true; |
| 457 |
} |
| 458 |
catch (...) |
| 459 |
{ |
| 460 |
MWAW_DEBUG_MSG(("MWAWDocument::decodeSpreadsheet: unknown error\n")); |
| 461 |
return false; |
| 462 |
} |
| 463 |
|
| 464 |
bool MWAWDocument::decodeText(librevenge::RVNGBinaryData const &, librevenge::RVNGTextInterface *) |
| 465 |
{ |
| 466 |
MWAW_DEBUG_MSG(("MWAWDocument::decodeText: unimplemented\n")); |
| 467 |
return false; |
| 468 |
} |
| 469 |
|
| 470 |
namespace MWAWDocumentInternal |
| 471 |
{ |
| 472 |
/** return the header corresponding to an input. Or 0L if no input are found */ |
| 473 |
MWAWHeader *getHeader(MWAWInputStreamPtr &ip, |
| 474 |
MWAWRSRCParserPtr const &rsrcParser, |
| 475 |
bool strict) |
| 476 |
try |
| 477 |
{ |
| 478 |
std::vector<MWAWHeader> listHeaders; |
| 479 |
|
| 480 |
if (!ip.get()) return nullptr; |
| 481 |
|
| 482 |
if (ip->hasDataFork()) { |
| 483 |
/** avoid very short file */ |
| 484 |
if (!ip->hasResourceFork() && ip->size() < 10) return nullptr; |
| 485 |
|
| 486 |
ip->seek(0, librevenge::RVNG_SEEK_SET); |
| 487 |
ip->setReadInverted(false); |
| 488 |
} |
| 489 |
else if (!ip->hasResourceFork()) |
| 490 |
return nullptr; |
| 491 |
|
| 492 |
listHeaders = MWAWHeader::constructHeader(ip, rsrcParser); |
| 493 |
size_t numHeaders = listHeaders.size(); |
| 494 |
if (numHeaders==0) return nullptr; |
| 495 |
|
| 496 |
for (int step=0; step<2; ++step) { |
| 497 |
for (size_t i = 0; i < numHeaders; i++) { |
| 498 |
if (!MWAWDocumentInternal::checkBasicMacHeader(ip, rsrcParser, listHeaders[i], step==0)) |
| 499 |
continue; |
| 500 |
return new MWAWHeader(listHeaders[i]); |
| 501 |
} |
| 502 |
if (strict) break; |
| 503 |
} |
| 504 |
return nullptr; |
| 505 |
} |
| 506 |
catch (libmwaw::FileException) |
| 507 |
{ |
| 508 |
MWAW_DEBUG_MSG(("MWAWDocumentInternal::MWAWDocument[getHeader]:File exception trapped\n")); |
| 509 |
return nullptr; |
| 510 |
} |
| 511 |
catch (libmwaw::ParseException) |
| 512 |
{ |
| 513 |
MWAW_DEBUG_MSG(("MWAWDocumentInternal::getHeader:Parse exception trapped\n")); |
| 514 |
return nullptr; |
| 515 |
} |
| 516 |
catch (...) |
| 517 |
{ |
| 518 |
//fixme: too generic |
| 519 |
MWAW_DEBUG_MSG(("MWAWDocumentInternal::getHeader:Unknown exception trapped\n")); |
| 520 |
return nullptr; |
| 521 |
} |
| 522 |
|
| 523 |
std::shared_ptr<MWAWGraphicParser> getGraphicParserFromHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 524 |
{ |
| 525 |
std::shared_ptr<MWAWGraphicParser> parser; |
| 526 |
if (!header) |
| 527 |
return parser; |
| 528 |
if (header->getKind()!=MWAWDocument::MWAW_K_DRAW && header->getKind()!=MWAWDocument::MWAW_K_PAINT) |
| 529 |
return parser; |
| 530 |
if (header->getKind()==MWAWDocument::MWAW_K_DRAW && header->getType()==MWAWDocument::MWAW_T_CLARISWORKS) |
| 531 |
return parser; |
| 532 |
|
| 533 |
try { |
| 534 |
switch (header->getType()) { |
| 535 |
case MWAWDocument::MWAW_T_APPLEPICT: |
| 536 |
parser.reset(new ApplePictParser(input, rsrcParser, header)); |
| 537 |
break; |
| 538 |
case MWAWDocument::MWAW_T_BEAGLEWORKS: |
| 539 |
if (header->getKind()==MWAWDocument::MWAW_K_PAINT) |
| 540 |
parser.reset(new BeagleWksBMParser(input, rsrcParser, header)); |
| 541 |
else |
| 542 |
parser.reset(new BeagleWksDRParser(input, rsrcParser, header)); |
| 543 |
break; |
| 544 |
case MWAWDocument::MWAW_T_CANVAS: |
| 545 |
if (header->getKind()==MWAWDocument::MWAW_K_DRAW) { |
| 546 |
if (header->getMajorVersion()<=3) |
| 547 |
parser.reset(new CanvasParser(input, rsrcParser, header)); |
| 548 |
else |
| 549 |
parser.reset(new Canvas5Parser(input, rsrcParser, header)); |
| 550 |
} |
| 551 |
else if (header->getMajorVersion()>=5) |
| 552 |
parser.reset(new Canvas5BMParser(input, rsrcParser, header)); |
| 553 |
break; |
| 554 |
case MWAWDocument::MWAW_T_DRAWINGTABLE: |
| 555 |
parser.reset(new DrawTableParser(input, rsrcParser, header)); |
| 556 |
break; |
| 557 |
case MWAWDocument::MWAW_T_CLARISDRAW: |
| 558 |
parser.reset(new ClarisDrawParser(input, rsrcParser, header)); |
| 559 |
break; |
| 560 |
case MWAWDocument::MWAW_T_CLARISWORKS: |
| 561 |
if (header->getKind()==MWAWDocument::MWAW_K_PAINT) |
| 562 |
parser.reset(new ClarisWksBMParser(input, rsrcParser, header)); |
| 563 |
break; |
| 564 |
case MWAWDocument::MWAW_T_CORELPAINTER: |
| 565 |
parser.reset(new CorelPainterParser(input, rsrcParser, header)); |
| 566 |
break; |
| 567 |
case MWAWDocument::MWAW_T_CRICKETDRAW: |
| 568 |
parser.reset(new CricketDrawParser(input, rsrcParser, header)); |
| 569 |
break; |
| 570 |
case MWAWDocument::MWAW_T_FULLPAINT: // same format as MacPaint, so ok... |
| 571 |
parser.reset(new MacPaintParser(input, rsrcParser, header)); |
| 572 |
break; |
| 573 |
case MWAWDocument::MWAW_T_FREEHAND: |
| 574 |
parser.reset(new FreeHandParser(input, rsrcParser, header)); |
| 575 |
break; |
| 576 |
case MWAWDocument::MWAW_T_GREATWORKS: |
| 577 |
if (header->getKind()==MWAWDocument::MWAW_K_PAINT) |
| 578 |
parser.reset(new GreatWksBMParser(input, rsrcParser, header)); |
| 579 |
else |
| 580 |
parser.reset(new GreatWksDRParser(input, rsrcParser, header)); |
| 581 |
break; |
| 582 |
case MWAWDocument::MWAW_T_MACDRAFT: |
| 583 |
if (header->getMajorVersion()<=1) |
| 584 |
parser.reset(new MacDraftParser(input, rsrcParser, header)); |
| 585 |
else |
| 586 |
parser.reset(new MacDraft5Parser(input, rsrcParser, header)); |
| 587 |
break; |
| 588 |
case MWAWDocument::MWAW_T_MACDRAW: |
| 589 |
parser.reset(new MacDrawParser(input, rsrcParser, header)); |
| 590 |
break; |
| 591 |
case MWAWDocument::MWAW_T_MACDRAWPRO: |
| 592 |
parser.reset(new MacDrawProParser(input, rsrcParser, header)); |
| 593 |
break; |
| 594 |
case MWAWDocument::MWAW_T_MACPAINT: |
| 595 |
parser.reset(new MacPaintParser(input, rsrcParser, header)); |
| 596 |
break; |
| 597 |
case MWAWDocument::MWAW_T_MICROSOFTWORKS: |
| 598 |
parser.reset(new MsWksDRParser(input, rsrcParser, header)); |
| 599 |
break; |
| 600 |
case MWAWDocument::MWAW_T_PIXELPAINT: |
| 601 |
parser.reset(new PixelPaintParser(input, rsrcParser, header)); |
| 602 |
break; |
| 603 |
case MWAWDocument::MWAW_T_READYSETGO: |
| 604 |
parser.reset(new ReadySetGoParser(input, rsrcParser, header)); |
| 605 |
break; |
| 606 |
case MWAWDocument::MWAW_T_SCOOP: |
| 607 |
parser.reset(new ScoopParser(input, rsrcParser, header)); |
| 608 |
break; |
| 609 |
case MWAWDocument::MWAW_T_SPRINGBOARD_PUBLISHER: |
| 610 |
parser.reset(new SpringBoardParser(input, rsrcParser, header)); |
| 611 |
break; |
| 612 |
case MWAWDocument::MWAW_T_SUPERPAINT: |
| 613 |
parser.reset(new SuperPaintParser(input, rsrcParser, header)); |
| 614 |
break; |
| 615 |
|
| 616 |
// TODO: first separate graphic format to other formats, then implement parser... |
| 617 |
case MWAWDocument::MWAW_T_ACTA: |
| 618 |
case MWAWDocument::MWAW_T_ADOBEILLUSTRATOR: |
| 619 |
case MWAWDocument::MWAW_T_CLARISRESOLVE: |
| 620 |
case MWAWDocument::MWAW_T_DBASE: |
| 621 |
case MWAWDocument::MWAW_T_DOCMAKER: |
| 622 |
case MWAWDocument::MWAW_T_EDOC: |
| 623 |
case MWAWDocument::MWAW_T_FAMILYTREEMAKER: |
| 624 |
case MWAWDocument::MWAW_T_FILEMAKER: |
| 625 |
case MWAWDocument::MWAW_T_FOXBASE: |
| 626 |
case MWAWDocument::MWAW_T_FRAMEMAKER: |
| 627 |
case MWAWDocument::MWAW_T_FULLIMPACT: |
| 628 |
case MWAWDocument::MWAW_T_FULLWRITE: |
| 629 |
case MWAWDocument::MWAW_T_INFOGENIE: |
| 630 |
case MWAWDocument::MWAW_T_JAZZLOTUS: |
| 631 |
case MWAWDocument::MWAW_T_KALEIDAGRAPH: |
| 632 |
case MWAWDocument::MWAW_T_HANMACWORDJ: |
| 633 |
case MWAWDocument::MWAW_T_HANMACWORDK: |
| 634 |
case MWAWDocument::MWAW_T_LIGHTWAYTEXT: |
| 635 |
case MWAWDocument::MWAW_T_MACDOC: |
| 636 |
case MWAWDocument::MWAW_T_MACWRITE: |
| 637 |
case MWAWDocument::MWAW_T_MACWRITEPRO: |
| 638 |
case MWAWDocument::MWAW_T_MARINERWRITE: |
| 639 |
case MWAWDocument::MWAW_T_MAXWRITE: |
| 640 |
case MWAWDocument::MWAW_T_MINDWRITE: |
| 641 |
case MWAWDocument::MWAW_T_MICROSOFTFILE: |
| 642 |
case MWAWDocument::MWAW_T_MICROSOFTMULTIPLAN: |
| 643 |
case MWAWDocument::MWAW_T_MICROSOFTWORD: |
| 644 |
case MWAWDocument::MWAW_T_MORE: |
| 645 |
case MWAWDocument::MWAW_T_MOUSEWRITE: |
| 646 |
case MWAWDocument::MWAW_T_NISUSWRITER: |
| 647 |
case MWAWDocument::MWAW_T_OVERVUE: |
| 648 |
case MWAWDocument::MWAW_T_PAGEMAKER: |
| 649 |
case MWAWDocument::MWAW_T_POWERPOINT: |
| 650 |
case MWAWDocument::MWAW_T_RAGTIME: |
| 651 |
case MWAWDocument::MWAW_T_SCRIPTWRITER: |
| 652 |
case MWAWDocument::MWAW_T_STUDENTWRITING: |
| 653 |
case MWAWDocument::MWAW_T_STYLE: |
| 654 |
case MWAWDocument::MWAW_T_SYMPOSIUM: |
| 655 |
case MWAWDocument::MWAW_T_TEACHTEXT: |
| 656 |
case MWAWDocument::MWAW_T_TEXEDIT: |
| 657 |
case MWAWDocument::MWAW_T_TRAPEZE: |
| 658 |
case MWAWDocument::MWAW_T_WINGZ: |
| 659 |
case MWAWDocument::MWAW_T_WORDMAKER: |
| 660 |
case MWAWDocument::MWAW_T_WRITENOW: |
| 661 |
case MWAWDocument::MWAW_T_WRITERPLUS: |
| 662 |
case MWAWDocument::MWAW_T_XPRESS: |
| 663 |
case MWAWDocument::MWAW_T_ZWRITE: |
| 664 |
case MWAWDocument::MWAW_T_4DIMENSION: |
| 665 |
|
| 666 |
case MWAWDocument::MWAW_T_RESERVED18: |
| 667 |
case MWAWDocument::MWAW_T_RESERVED19: |
| 668 |
case MWAWDocument::MWAW_T_RESERVED20: |
| 669 |
case MWAWDocument::MWAW_T_RESERVED21: |
| 670 |
case MWAWDocument::MWAW_T_RESERVED22: |
| 671 |
case MWAWDocument::MWAW_T_RESERVED23: |
| 672 |
case MWAWDocument::MWAW_T_RESERVED24: |
| 673 |
case MWAWDocument::MWAW_T_RESERVED25: |
| 674 |
case MWAWDocument::MWAW_T_RESERVED26: |
| 675 |
case MWAWDocument::MWAW_T_RESERVED27: |
| 676 |
case MWAWDocument::MWAW_T_RESERVED28: |
| 677 |
case MWAWDocument::MWAW_T_RESERVED29: |
| 678 |
|
| 679 |
case MWAWDocument::MWAW_T_UNKNOWN: |
| 680 |
#if !defined(__clang__) |
| 681 |
default: |
| 682 |
#endif |
| 683 |
break; |
| 684 |
} |
| 685 |
} |
| 686 |
catch (...) { |
| 687 |
} |
| 688 |
return parser; |
| 689 |
} |
| 690 |
|
| 691 |
std::shared_ptr<MWAWPresentationParser> getPresentationParserFromHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 692 |
{ |
| 693 |
std::shared_ptr<MWAWPresentationParser> parser; |
| 694 |
if (!header) |
| 695 |
return parser; |
| 696 |
if (header->getKind()!=MWAWDocument::MWAW_K_PRESENTATION) |
| 697 |
return parser; |
| 698 |
|
| 699 |
try { |
| 700 |
switch (header->getType()) { |
| 701 |
case MWAWDocument::MWAW_T_CLARISWORKS: |
| 702 |
parser.reset(new ClarisWksPRParser(input, rsrcParser, header)); |
| 703 |
break; |
| 704 |
case MWAWDocument::MWAW_T_POWERPOINT: |
| 705 |
if (header->getMajorVersion()<=2) |
| 706 |
parser.reset(new PowerPoint1Parser(input, rsrcParser, header)); |
| 707 |
else if (header->getMajorVersion()<=4) |
| 708 |
parser.reset(new PowerPoint3Parser(input, rsrcParser, header)); |
| 709 |
else |
| 710 |
parser.reset(new PowerPoint7Parser(input, rsrcParser, header)); |
| 711 |
break; |
| 712 |
|
| 713 |
case MWAWDocument::MWAW_T_ACTA: |
| 714 |
case MWAWDocument::MWAW_T_ADOBEILLUSTRATOR: |
| 715 |
case MWAWDocument::MWAW_T_APPLEPICT: |
| 716 |
case MWAWDocument::MWAW_T_BEAGLEWORKS: |
| 717 |
case MWAWDocument::MWAW_T_CANVAS: |
| 718 |
case MWAWDocument::MWAW_T_CLARISDRAW: |
| 719 |
case MWAWDocument::MWAW_T_CLARISRESOLVE: |
| 720 |
case MWAWDocument::MWAW_T_CORELPAINTER: |
| 721 |
case MWAWDocument::MWAW_T_CRICKETDRAW: |
| 722 |
case MWAWDocument::MWAW_T_DBASE: |
| 723 |
case MWAWDocument::MWAW_T_DOCMAKER: |
| 724 |
case MWAWDocument::MWAW_T_DRAWINGTABLE: |
| 725 |
case MWAWDocument::MWAW_T_EDOC: |
| 726 |
case MWAWDocument::MWAW_T_FAMILYTREEMAKER: |
| 727 |
case MWAWDocument::MWAW_T_FILEMAKER: |
| 728 |
case MWAWDocument::MWAW_T_FREEHAND: |
| 729 |
case MWAWDocument::MWAW_T_FOXBASE: |
| 730 |
case MWAWDocument::MWAW_T_FRAMEMAKER: |
| 731 |
case MWAWDocument::MWAW_T_FULLIMPACT: |
| 732 |
case MWAWDocument::MWAW_T_FULLPAINT: |
| 733 |
case MWAWDocument::MWAW_T_FULLWRITE: |
| 734 |
case MWAWDocument::MWAW_T_GREATWORKS: |
| 735 |
case MWAWDocument::MWAW_T_INFOGENIE: |
| 736 |
case MWAWDocument::MWAW_T_KALEIDAGRAPH: |
| 737 |
case MWAWDocument::MWAW_T_JAZZLOTUS: |
| 738 |
case MWAWDocument::MWAW_T_HANMACWORDJ: |
| 739 |
case MWAWDocument::MWAW_T_HANMACWORDK: |
| 740 |
case MWAWDocument::MWAW_T_LIGHTWAYTEXT: |
| 741 |
case MWAWDocument::MWAW_T_MACDOC: |
| 742 |
case MWAWDocument::MWAW_T_MACDRAFT: |
| 743 |
case MWAWDocument::MWAW_T_MACDRAW: |
| 744 |
case MWAWDocument::MWAW_T_MACDRAWPRO: |
| 745 |
case MWAWDocument::MWAW_T_MACPAINT: |
| 746 |
case MWAWDocument::MWAW_T_MACWRITE: |
| 747 |
case MWAWDocument::MWAW_T_MACWRITEPRO: |
| 748 |
case MWAWDocument::MWAW_T_MARINERWRITE: |
| 749 |
case MWAWDocument::MWAW_T_MAXWRITE: |
| 750 |
case MWAWDocument::MWAW_T_MINDWRITE: |
| 751 |
case MWAWDocument::MWAW_T_MICROSOFTFILE: |
| 752 |
case MWAWDocument::MWAW_T_MICROSOFTMULTIPLAN: |
| 753 |
case MWAWDocument::MWAW_T_MICROSOFTWORD: |
| 754 |
case MWAWDocument::MWAW_T_MICROSOFTWORKS: |
| 755 |
case MWAWDocument::MWAW_T_MORE: |
| 756 |
case MWAWDocument::MWAW_T_MOUSEWRITE: |
| 757 |
case MWAWDocument::MWAW_T_NISUSWRITER: |
| 758 |
case MWAWDocument::MWAW_T_OVERVUE: |
| 759 |
case MWAWDocument::MWAW_T_PAGEMAKER: |
| 760 |
case MWAWDocument::MWAW_T_PIXELPAINT: |
| 761 |
case MWAWDocument::MWAW_T_RAGTIME: |
| 762 |
case MWAWDocument::MWAW_T_READYSETGO: |
| 763 |
case MWAWDocument::MWAW_T_SCOOP: |
| 764 |
case MWAWDocument::MWAW_T_SCRIPTWRITER: |
| 765 |
case MWAWDocument::MWAW_T_SPRINGBOARD_PUBLISHER: |
| 766 |
case MWAWDocument::MWAW_T_STUDENTWRITING: |
| 767 |
case MWAWDocument::MWAW_T_STYLE: |
| 768 |
case MWAWDocument::MWAW_T_SUPERPAINT: |
| 769 |
case MWAWDocument::MWAW_T_SYMPOSIUM: |
| 770 |
case MWAWDocument::MWAW_T_TEACHTEXT: |
| 771 |
case MWAWDocument::MWAW_T_TEXEDIT: |
| 772 |
case MWAWDocument::MWAW_T_TRAPEZE: |
| 773 |
case MWAWDocument::MWAW_T_WINGZ: |
| 774 |
case MWAWDocument::MWAW_T_WORDMAKER: |
| 775 |
case MWAWDocument::MWAW_T_WRITENOW: |
| 776 |
case MWAWDocument::MWAW_T_WRITERPLUS: |
| 777 |
case MWAWDocument::MWAW_T_XPRESS: |
| 778 |
case MWAWDocument::MWAW_T_ZWRITE: |
| 779 |
case MWAWDocument::MWAW_T_4DIMENSION: |
| 780 |
|
| 781 |
case MWAWDocument::MWAW_T_RESERVED18: |
| 782 |
case MWAWDocument::MWAW_T_RESERVED19: |
| 783 |
case MWAWDocument::MWAW_T_RESERVED20: |
| 784 |
case MWAWDocument::MWAW_T_RESERVED21: |
| 785 |
case MWAWDocument::MWAW_T_RESERVED22: |
| 786 |
case MWAWDocument::MWAW_T_RESERVED23: |
| 787 |
case MWAWDocument::MWAW_T_RESERVED24: |
| 788 |
case MWAWDocument::MWAW_T_RESERVED25: |
| 789 |
case MWAWDocument::MWAW_T_RESERVED26: |
| 790 |
case MWAWDocument::MWAW_T_RESERVED27: |
| 791 |
case MWAWDocument::MWAW_T_RESERVED28: |
| 792 |
case MWAWDocument::MWAW_T_RESERVED29: |
| 793 |
|
| 794 |
case MWAWDocument::MWAW_T_UNKNOWN: |
| 795 |
#if !defined(__clang__) |
| 796 |
default: |
| 797 |
#endif |
| 798 |
break; |
| 799 |
} |
| 800 |
} |
| 801 |
catch (...) { |
| 802 |
} |
| 803 |
return parser; |
| 804 |
} |
| 805 |
|
| 806 |
/** Factory wrapper to construct a parser corresponding to an spreadsheet header */ |
| 807 |
std::shared_ptr<MWAWSpreadsheetParser> getSpreadsheetParserFromHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 808 |
{ |
| 809 |
std::shared_ptr<MWAWSpreadsheetParser> parser; |
| 810 |
if (!header) |
| 811 |
return parser; |
| 812 |
if (header->getKind()!=MWAWDocument::MWAW_K_SPREADSHEET && header->getKind()!=MWAWDocument::MWAW_K_DATABASE) |
| 813 |
return parser; |
| 814 |
|
| 815 |
try { |
| 816 |
switch (header->getType()) { |
| 817 |
case MWAWDocument::MWAW_T_BEAGLEWORKS: |
| 818 |
if (header->getKind()==MWAWDocument::MWAW_K_SPREADSHEET) |
| 819 |
parser.reset(new BeagleWksSSParser(input, rsrcParser, header)); |
| 820 |
else |
| 821 |
parser.reset(new BeagleWksDBParser(input, rsrcParser, header)); |
| 822 |
break; |
| 823 |
case MWAWDocument::MWAW_T_CLARISRESOLVE: |
| 824 |
parser.reset(new WingzParser(input, rsrcParser, header)); |
| 825 |
break; |
| 826 |
case MWAWDocument::MWAW_T_CLARISWORKS: |
| 827 |
parser.reset(new ClarisWksSSParser(input, rsrcParser, header)); |
| 828 |
break; |
| 829 |
case MWAWDocument::MWAW_T_GREATWORKS: |
| 830 |
if (header->getKind()==MWAWDocument::MWAW_K_SPREADSHEET) |
| 831 |
parser.reset(new GreatWksSSParser(input, rsrcParser, header)); |
| 832 |
else |
| 833 |
parser.reset(new GreatWksDBParser(input, rsrcParser, header)); |
| 834 |
break; |
| 835 |
case MWAWDocument::MWAW_T_JAZZLOTUS: |
| 836 |
parser.reset(new JazzSSParser(input, rsrcParser, header)); |
| 837 |
break; |
| 838 |
case MWAWDocument::MWAW_T_MICROSOFTMULTIPLAN: |
| 839 |
parser.reset(new MultiplanParser(input, rsrcParser, header)); |
| 840 |
break; |
| 841 |
case MWAWDocument::MWAW_T_MICROSOFTWORKS: |
| 842 |
if (header->getKind()==MWAWDocument::MWAW_K_SPREADSHEET) |
| 843 |
parser.reset(new MsWksSSParser(input, rsrcParser, header)); |
| 844 |
else |
| 845 |
parser.reset(new MsWksDBParser(input, rsrcParser, header)); |
| 846 |
break; |
| 847 |
case MWAWDocument::MWAW_T_RAGTIME: |
| 848 |
if (header->getMajorVersion()>=5) |
| 849 |
parser.reset(new RagTime5SSParser(input, rsrcParser, header)); |
| 850 |
break; |
| 851 |
case MWAWDocument::MWAW_T_WINGZ: |
| 852 |
parser.reset(new WingzParser(input, rsrcParser, header)); |
| 853 |
break; |
| 854 |
// TODO |
| 855 |
case MWAWDocument::MWAW_T_FULLIMPACT: |
| 856 |
case MWAWDocument::MWAW_T_KALEIDAGRAPH: |
| 857 |
case MWAWDocument::MWAW_T_TRAPEZE: |
| 858 |
|
| 859 |
// no spreadsheet, but some database |
| 860 |
case MWAWDocument::MWAW_T_ACTA: |
| 861 |
case MWAWDocument::MWAW_T_ADOBEILLUSTRATOR: |
| 862 |
case MWAWDocument::MWAW_T_APPLEPICT: |
| 863 |
case MWAWDocument::MWAW_T_CANVAS: |
| 864 |
case MWAWDocument::MWAW_T_CLARISDRAW: |
| 865 |
case MWAWDocument::MWAW_T_CORELPAINTER: |
| 866 |
case MWAWDocument::MWAW_T_CRICKETDRAW: |
| 867 |
case MWAWDocument::MWAW_T_DBASE: |
| 868 |
case MWAWDocument::MWAW_T_DOCMAKER: |
| 869 |
case MWAWDocument::MWAW_T_DRAWINGTABLE: |
| 870 |
case MWAWDocument::MWAW_T_EDOC: |
| 871 |
case MWAWDocument::MWAW_T_FAMILYTREEMAKER: |
| 872 |
case MWAWDocument::MWAW_T_FILEMAKER: |
| 873 |
case MWAWDocument::MWAW_T_FOXBASE: |
| 874 |
case MWAWDocument::MWAW_T_FRAMEMAKER: |
| 875 |
case MWAWDocument::MWAW_T_FREEHAND: |
| 876 |
case MWAWDocument::MWAW_T_FULLPAINT: |
| 877 |
case MWAWDocument::MWAW_T_FULLWRITE: |
| 878 |
case MWAWDocument::MWAW_T_HANMACWORDJ: |
| 879 |
case MWAWDocument::MWAW_T_HANMACWORDK: |
| 880 |
case MWAWDocument::MWAW_T_INFOGENIE: |
| 881 |
case MWAWDocument::MWAW_T_LIGHTWAYTEXT: |
| 882 |
case MWAWDocument::MWAW_T_MACDOC: |
| 883 |
case MWAWDocument::MWAW_T_MACDRAFT: |
| 884 |
case MWAWDocument::MWAW_T_MACDRAW: |
| 885 |
case MWAWDocument::MWAW_T_MACDRAWPRO: |
| 886 |
case MWAWDocument::MWAW_T_MACPAINT: |
| 887 |
case MWAWDocument::MWAW_T_MACWRITE: |
| 888 |
case MWAWDocument::MWAW_T_MACWRITEPRO: |
| 889 |
case MWAWDocument::MWAW_T_MARINERWRITE: |
| 890 |
case MWAWDocument::MWAW_T_MAXWRITE: |
| 891 |
case MWAWDocument::MWAW_T_MICROSOFTFILE: |
| 892 |
case MWAWDocument::MWAW_T_MICROSOFTWORD: |
| 893 |
case MWAWDocument::MWAW_T_MINDWRITE: |
| 894 |
case MWAWDocument::MWAW_T_MORE: |
| 895 |
case MWAWDocument::MWAW_T_MOUSEWRITE: |
| 896 |
case MWAWDocument::MWAW_T_NISUSWRITER: |
| 897 |
case MWAWDocument::MWAW_T_OVERVUE: |
| 898 |
case MWAWDocument::MWAW_T_PAGEMAKER: |
| 899 |
case MWAWDocument::MWAW_T_POWERPOINT: |
| 900 |
case MWAWDocument::MWAW_T_PIXELPAINT: |
| 901 |
case MWAWDocument::MWAW_T_READYSETGO: |
| 902 |
case MWAWDocument::MWAW_T_SCOOP: |
| 903 |
case MWAWDocument::MWAW_T_SCRIPTWRITER: |
| 904 |
case MWAWDocument::MWAW_T_SPRINGBOARD_PUBLISHER: |
| 905 |
case MWAWDocument::MWAW_T_STUDENTWRITING: |
| 906 |
case MWAWDocument::MWAW_T_STYLE: |
| 907 |
case MWAWDocument::MWAW_T_SUPERPAINT: |
| 908 |
case MWAWDocument::MWAW_T_SYMPOSIUM: |
| 909 |
case MWAWDocument::MWAW_T_TEACHTEXT: |
| 910 |
case MWAWDocument::MWAW_T_TEXEDIT: |
| 911 |
case MWAWDocument::MWAW_T_WORDMAKER: |
| 912 |
case MWAWDocument::MWAW_T_WRITENOW: |
| 913 |
case MWAWDocument::MWAW_T_WRITERPLUS: |
| 914 |
case MWAWDocument::MWAW_T_XPRESS: |
| 915 |
case MWAWDocument::MWAW_T_ZWRITE: |
| 916 |
case MWAWDocument::MWAW_T_4DIMENSION: |
| 917 |
|
| 918 |
case MWAWDocument::MWAW_T_RESERVED18: |
| 919 |
case MWAWDocument::MWAW_T_RESERVED19: |
| 920 |
case MWAWDocument::MWAW_T_RESERVED20: |
| 921 |
case MWAWDocument::MWAW_T_RESERVED21: |
| 922 |
case MWAWDocument::MWAW_T_RESERVED22: |
| 923 |
case MWAWDocument::MWAW_T_RESERVED23: |
| 924 |
case MWAWDocument::MWAW_T_RESERVED24: |
| 925 |
case MWAWDocument::MWAW_T_RESERVED25: |
| 926 |
case MWAWDocument::MWAW_T_RESERVED26: |
| 927 |
case MWAWDocument::MWAW_T_RESERVED27: |
| 928 |
case MWAWDocument::MWAW_T_RESERVED28: |
| 929 |
case MWAWDocument::MWAW_T_RESERVED29: |
| 930 |
|
| 931 |
case MWAWDocument::MWAW_T_UNKNOWN: |
| 932 |
#if !defined(__clang__) |
| 933 |
default: |
| 934 |
#endif |
| 935 |
break; |
| 936 |
} |
| 937 |
} |
| 938 |
catch (...) { |
| 939 |
} |
| 940 |
return parser; |
| 941 |
} |
| 942 |
|
| 943 |
/** Factory wrapper to construct a parser corresponding to an text header */ |
| 944 |
std::shared_ptr<MWAWTextParser> getTextParserFromHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader *header) |
| 945 |
{ |
| 946 |
std::shared_ptr<MWAWTextParser> parser; |
| 947 |
if (!header) |
| 948 |
return parser; |
| 949 |
// removeme: actually ClarisWorks draw file are exported as text file |
| 950 |
if (header->getKind()!=MWAWDocument::MWAW_K_TEXT && |
| 951 |
(header->getKind()!=MWAWDocument::MWAW_K_DRAW || header->getType()!=MWAWDocument::MWAW_T_CLARISWORKS)) |
| 952 |
return parser; |
| 953 |
try { |
| 954 |
switch (header->getType()) { |
| 955 |
case MWAWDocument::MWAW_T_ACTA: |
| 956 |
parser.reset(new ActaParser(input, rsrcParser, header)); |
| 957 |
break; |
| 958 |
case MWAWDocument::MWAW_T_BEAGLEWORKS: |
| 959 |
parser.reset(new BeagleWksParser(input, rsrcParser, header)); |
| 960 |
break; |
| 961 |
case MWAWDocument::MWAW_T_CLARISWORKS: |
| 962 |
parser.reset(new ClarisWksParser(input, rsrcParser, header)); |
| 963 |
break; |
| 964 |
case MWAWDocument::MWAW_T_DOCMAKER: |
| 965 |
parser.reset(new DocMkrParser(input, rsrcParser, header)); |
| 966 |
break; |
| 967 |
case MWAWDocument::MWAW_T_EDOC: |
| 968 |
parser.reset(new EDocParser(input, rsrcParser, header)); |
| 969 |
break; |
| 970 |
case MWAWDocument::MWAW_T_FULLWRITE: |
| 971 |
parser.reset(new FullWrtParser(input, rsrcParser, header)); |
| 972 |
break; |
| 973 |
case MWAWDocument::MWAW_T_GREATWORKS: |
| 974 |
parser.reset(new GreatWksParser(input, rsrcParser, header)); |
| 975 |
break; |
| 976 |
case MWAWDocument::MWAW_T_HANMACWORDJ: |
| 977 |
parser.reset(new HanMacWrdJParser(input, rsrcParser, header)); |
| 978 |
break; |
| 979 |
case MWAWDocument::MWAW_T_HANMACWORDK: |
| 980 |
parser.reset(new HanMacWrdKParser(input, rsrcParser, header)); |
| 981 |
break; |
| 982 |
case MWAWDocument::MWAW_T_JAZZLOTUS: |
| 983 |
parser.reset(new JazzWriterParser(input, rsrcParser, header)); |
| 984 |
break; |
| 985 |
case MWAWDocument::MWAW_T_LIGHTWAYTEXT: |
| 986 |
parser.reset(new LightWayTxtParser(input, rsrcParser, header)); |
| 987 |
break; |
| 988 |
case MWAWDocument::MWAW_T_MACDOC: |
| 989 |
parser.reset(new MacDocParser(input, rsrcParser, header)); |
| 990 |
break; |
| 991 |
case MWAWDocument::MWAW_T_MACWRITE: |
| 992 |
parser.reset(new MacWrtParser(input, rsrcParser, header)); |
| 993 |
break; |
| 994 |
case MWAWDocument::MWAW_T_MACWRITEPRO: |
| 995 |
parser.reset(new MacWrtProParser(input, rsrcParser, header)); |
| 996 |
break; |
| 997 |
case MWAWDocument::MWAW_T_MARINERWRITE: |
| 998 |
parser.reset(new MarinerWrtParser(input, rsrcParser, header)); |
| 999 |
break; |
| 1000 |
case MWAWDocument::MWAW_T_MAXWRITE: |
| 1001 |
parser.reset(new MaxWrtParser(input, rsrcParser, header)); |
| 1002 |
break; |
| 1003 |
case MWAWDocument::MWAW_T_MICROSOFTWORD: |
| 1004 |
if (header->getMajorVersion()==1) |
| 1005 |
parser.reset(new MsWrd1Parser(input, rsrcParser, header)); |
| 1006 |
else |
| 1007 |
parser.reset(new MsWrdParser(input, rsrcParser, header)); |
| 1008 |
break; |
| 1009 |
case MWAWDocument::MWAW_T_MICROSOFTWORKS: |
| 1010 |
parser.reset(new MsWksParser(input, rsrcParser, header)); |
| 1011 |
break; |
| 1012 |
case MWAWDocument::MWAW_T_MINDWRITE: |
| 1013 |
parser.reset(new MindWrtParser(input, rsrcParser, header)); |
| 1014 |
break; |
| 1015 |
case MWAWDocument::MWAW_T_MORE: |
| 1016 |
parser.reset(new MoreParser(input, rsrcParser, header)); |
| 1017 |
break; |
| 1018 |
case MWAWDocument::MWAW_T_MOUSEWRITE: |
| 1019 |
parser.reset(new MouseWrtParser(input, rsrcParser, header)); |
| 1020 |
break; |
| 1021 |
case MWAWDocument::MWAW_T_NISUSWRITER: |
| 1022 |
parser.reset(new NisusWrtParser(input, rsrcParser, header)); |
| 1023 |
break; |
| 1024 |
case MWAWDocument::MWAW_T_RAGTIME: |
| 1025 |
if (header->getMajorVersion()<5) |
| 1026 |
parser.reset(new RagTimeParser(input, rsrcParser, header)); |
| 1027 |
else |
| 1028 |
parser.reset(new RagTime5Parser(input, rsrcParser, header)); |
| 1029 |
break; |
| 1030 |
case MWAWDocument::MWAW_T_SCRIPTWRITER: |
| 1031 |
parser.reset(new ScriptWriterParser(input, rsrcParser, header)); |
| 1032 |
break; |
| 1033 |
case MWAWDocument::MWAW_T_STUDENTWRITING: |
| 1034 |
parser.reset(new StudentWritingCParser(input, rsrcParser, header)); |
| 1035 |
break; |
| 1036 |
case MWAWDocument::MWAW_T_STYLE: |
| 1037 |
parser.reset(new StyleParser(input, rsrcParser, header)); |
| 1038 |
break; |
| 1039 |
case MWAWDocument::MWAW_T_TEACHTEXT: |
| 1040 |
case MWAWDocument::MWAW_T_TEXEDIT: |
| 1041 |
parser.reset(new TeachTxtParser(input, rsrcParser, header)); |
| 1042 |
break; |
| 1043 |
case MWAWDocument::MWAW_T_WORDMAKER: |
| 1044 |
parser.reset(new WordMakerParser(input, rsrcParser, header)); |
| 1045 |
break; |
| 1046 |
case MWAWDocument::MWAW_T_WRITENOW: |
| 1047 |
parser.reset(new WriteNowParser(input, rsrcParser, header)); |
| 1048 |
break; |
| 1049 |
case MWAWDocument::MWAW_T_WRITERPLUS: |
| 1050 |
parser.reset(new WriterPlsParser(input, rsrcParser, header)); |
| 1051 |
break; |
| 1052 |
case MWAWDocument::MWAW_T_ZWRITE: |
| 1053 |
parser.reset(new ZWrtParser(input, rsrcParser, header)); |
| 1054 |
break; |
| 1055 |
|
| 1056 |
case MWAWDocument::MWAW_T_ADOBEILLUSTRATOR: |
| 1057 |
case MWAWDocument::MWAW_T_APPLEPICT: |
| 1058 |
case MWAWDocument::MWAW_T_CANVAS: |
| 1059 |
case MWAWDocument::MWAW_T_CLARISDRAW: |
| 1060 |
case MWAWDocument::MWAW_T_CLARISRESOLVE: |
| 1061 |
case MWAWDocument::MWAW_T_CORELPAINTER: |
| 1062 |
case MWAWDocument::MWAW_T_CRICKETDRAW: |
| 1063 |
case MWAWDocument::MWAW_T_DBASE: |
| 1064 |
case MWAWDocument::MWAW_T_DRAWINGTABLE: |
| 1065 |
case MWAWDocument::MWAW_T_FAMILYTREEMAKER: |
| 1066 |
case MWAWDocument::MWAW_T_FILEMAKER: |
| 1067 |
case MWAWDocument::MWAW_T_FOXBASE: |
| 1068 |
case MWAWDocument::MWAW_T_FREEHAND: |
| 1069 |
case MWAWDocument::MWAW_T_FULLIMPACT: |
| 1070 |
case MWAWDocument::MWAW_T_FULLPAINT: |
| 1071 |
case MWAWDocument::MWAW_T_FRAMEMAKER: |
| 1072 |
case MWAWDocument::MWAW_T_INFOGENIE: |
| 1073 |
case MWAWDocument::MWAW_T_KALEIDAGRAPH: |
| 1074 |
case MWAWDocument::MWAW_T_MACDRAFT: |
| 1075 |
case MWAWDocument::MWAW_T_MACDRAW: |
| 1076 |
case MWAWDocument::MWAW_T_MACDRAWPRO: |
| 1077 |
case MWAWDocument::MWAW_T_MACPAINT: |
| 1078 |
case MWAWDocument::MWAW_T_MICROSOFTFILE: |
| 1079 |
case MWAWDocument::MWAW_T_MICROSOFTMULTIPLAN: |
| 1080 |
case MWAWDocument::MWAW_T_OVERVUE: |
| 1081 |
case MWAWDocument::MWAW_T_PAGEMAKER: |
| 1082 |
case MWAWDocument::MWAW_T_PIXELPAINT: |
| 1083 |
case MWAWDocument::MWAW_T_POWERPOINT: |
| 1084 |
case MWAWDocument::MWAW_T_READYSETGO: |
| 1085 |
case MWAWDocument::MWAW_T_SCOOP: |
| 1086 |
case MWAWDocument::MWAW_T_SPRINGBOARD_PUBLISHER: |
| 1087 |
case MWAWDocument::MWAW_T_SUPERPAINT: |
| 1088 |
case MWAWDocument::MWAW_T_SYMPOSIUM: |
| 1089 |
case MWAWDocument::MWAW_T_TRAPEZE: |
| 1090 |
case MWAWDocument::MWAW_T_WINGZ: |
| 1091 |
case MWAWDocument::MWAW_T_XPRESS: |
| 1092 |
case MWAWDocument::MWAW_T_4DIMENSION: |
| 1093 |
|
| 1094 |
case MWAWDocument::MWAW_T_RESERVED18: |
| 1095 |
case MWAWDocument::MWAW_T_RESERVED19: |
| 1096 |
case MWAWDocument::MWAW_T_RESERVED20: |
| 1097 |
case MWAWDocument::MWAW_T_RESERVED21: |
| 1098 |
case MWAWDocument::MWAW_T_RESERVED22: |
| 1099 |
case MWAWDocument::MWAW_T_RESERVED23: |
| 1100 |
case MWAWDocument::MWAW_T_RESERVED24: |
| 1101 |
case MWAWDocument::MWAW_T_RESERVED25: |
| 1102 |
case MWAWDocument::MWAW_T_RESERVED26: |
| 1103 |
case MWAWDocument::MWAW_T_RESERVED27: |
| 1104 |
case MWAWDocument::MWAW_T_RESERVED28: |
| 1105 |
case MWAWDocument::MWAW_T_RESERVED29: |
| 1106 |
|
| 1107 |
case MWAWDocument::MWAW_T_UNKNOWN: |
| 1108 |
#if !defined(__clang__) |
| 1109 |
default: |
| 1110 |
#endif |
| 1111 |
break; |
| 1112 |
} |
| 1113 |
} |
| 1114 |
catch (...) { |
| 1115 |
} |
| 1116 |
return parser; |
| 1117 |
} |
| 1118 |
|
| 1119 |
/** Wrapper to check a basic header of a mac file */ |
| 1120 |
bool checkBasicMacHeader(MWAWInputStreamPtr &input, MWAWRSRCParserPtr const &rsrcParser, MWAWHeader &header, bool strict) |
| 1121 |
try |
| 1122 |
{ |
| 1123 |
std::shared_ptr<MWAWParser> parser=getTextParserFromHeader(input, rsrcParser, &header); |
| 1124 |
if (!parser) |
| 1125 |
parser=getSpreadsheetParserFromHeader(input, rsrcParser, &header); |
| 1126 |
if (!parser) |
| 1127 |
parser=getGraphicParserFromHeader(input, rsrcParser, &header); |
| 1128 |
if (!parser) |
| 1129 |
parser=getPresentationParserFromHeader(input, rsrcParser, &header); |
| 1130 |
if (!parser) |
| 1131 |
return false; |
| 1132 |
return parser->checkHeader(&header, strict); |
| 1133 |
} |
| 1134 |
catch (...) |
| 1135 |
{ |
| 1136 |
MWAW_DEBUG_MSG(("MWAWDocumentInternal::checkBasicMacHeader:Unknown exception trapped\n")); |
| 1137 |
return false; |
| 1138 |
} |
| 1139 |
|
| 1140 |
} |
| 1141 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |