| 1 |
#include "leinputstream.h" |
| 2 |
#include "leoutputstream.h" |
| 3 |
#include "introspection.h" |
| 4 |
#include "utils.h" |
| 5 |
#include "pole.h" |
| 6 |
#include <QBuffer> |
| 7 |
#include <QCoreApplication> |
| 8 |
#include <QXmlStreamWriter> |
| 9 |
#include <QDebug> |
| 10 |
#include <QFile> |
| 11 |
#include <QVariant> |
| 12 |
#include <cstdio> |
| 13 |
|
| 14 |
using namespace std; |
| 15 |
|
| 16 |
void |
| 17 |
ppttoxml(const QString& file, QIODevice* out) { |
| 18 |
QXmlStreamWriter xmlout(out); |
| 19 |
xmlout.setAutoFormatting(true); |
| 20 |
xmlout.writeStartDocument(); |
| 21 |
xmlout.writeProcessingInstruction("xml-stylesheet", "type='text/xsl' href='ppttosvg.xsl'"); |
| 22 |
xmlout.writeStartElement("ppt"); |
| 23 |
POLE::Storage storage(file.toLocal8Bit()); |
| 24 |
if (!storage.open()) return; |
| 25 |
|
| 26 |
string prefix; |
| 27 |
if (storage.isDirectory("PP97_DUALSTORAGE")) { |
| 28 |
prefix = "PP97_DUALSTORAGE/"; |
| 29 |
} else { |
| 30 |
prefix = "/"; |
| 31 |
} |
| 32 |
list<string> entries = storage.entries(prefix); |
| 33 |
for (list<string>::const_iterator i=entries.begin(); i!=entries.end(); ++i) { |
| 34 |
if (!storage.isDirectory(prefix+*i)) { |
| 35 |
POLE::Stream stream(&storage, prefix+*i); |
| 36 |
QString streamname(QString::fromStdString(*i)); |
| 37 |
QByteArray array; |
| 38 |
array.resize(stream.size()); |
| 39 |
unsigned long read = stream.read((unsigned char*)array.data(), stream.size()); |
| 40 |
if (read != stream.size()) { |
| 41 |
qDebug() << "Error reading stream " << streamname; |
| 42 |
return; |
| 43 |
} |
| 44 |
// write("/tmp/"+streamname+".in", array); |
| 45 |
QBuffer buffer; |
| 46 |
buffer.setData(array); |
| 47 |
buffer.open(QIODevice::ReadOnly); |
| 48 |
LEInputStream listream(&buffer); |
| 49 |
qDebug() << "Parsing stream '" << streamname << "'"; |
| 50 |
|
| 51 |
const Introspectable* i; |
| 52 |
try { |
| 53 |
i = parse(streamname, listream); |
| 54 |
} catch (IOException& e) { |
| 55 |
qDebug() << "Error: " << e.msg; |
| 56 |
continue; |
| 57 |
} |
| 58 |
|
| 59 |
if (listream.getPosition() != (qint64)stream.size()) { |
| 60 |
qDebug() << stream.size() - listream.getPosition() |
| 61 |
<< "trailing bytes in stream " << streamname; |
| 62 |
return; |
| 63 |
} |
| 64 |
buffer.close(); |
| 65 |
|
| 66 |
xmlout.writeStartElement(i->getIntrospection()->name); |
| 67 |
if (i->getIntrospection()->name != "TODOS") { |
| 68 |
printWithExtendedParser(xmlout, i); |
| 69 |
} |
| 70 |
xmlout.writeEndElement(); |
| 71 |
|
| 72 |
buffer.buffer().clear(); |
| 73 |
buffer.open(QIODevice::WriteOnly); |
| 74 |
LEOutputStream lostream(&buffer); |
| 75 |
serialize(i, streamname, lostream); |
| 76 |
// write("/tmp/"+streamname+".out", buffer.data()); |
| 77 |
if (array != buffer.data()) { |
| 78 |
qDebug() << "Serialized data different from original in " |
| 79 |
<< streamname; |
| 80 |
} |
| 81 |
|
| 82 |
delete i; |
| 83 |
} |
| 84 |
} |
| 85 |
xmlout.writeEndElement(); |
| 86 |
xmlout.writeEndDocument(); |
| 87 |
} |
| 88 |
|
| 89 |
int |
| 90 |
main(int argc, char** argv) { |
| 91 |
QCoreApplication app(argc, argv); |
| 92 |
if (argc != 2 && argc != 3) return -1; |
| 93 |
|
| 94 |
QFile out; |
| 95 |
if (argc == 3) { |
| 96 |
out.setFileName(argv[2]); |
| 97 |
out.open(QIODevice::WriteOnly); |
| 98 |
} else { |
| 99 |
out.open(stdout, QIODevice::WriteOnly); |
| 100 |
} |
| 101 |
ppttoxml(QLatin1String(argv[1]), &out); |
| 102 |
out.close(); |
| 103 |
|
| 104 |
return 0; |
| 105 |
} |