File indexing completed on 2024-04-28 04:40:02

0001 #include "leinputstream.h"
0002 #include "leoutputstream.h"
0003 #include "introspection.h"
0004 #include "utils.h"
0005 #include "pole.h"
0006 #include <QBuffer>
0007 #include <QCoreApplication>
0008 #include <QXmlStreamWriter>
0009 #include <QDebug>
0010 #include <QFile>
0011 #include <QVariant>
0012 #include <cstdio>
0013 
0014 using namespace std;
0015 
0016 void
0017 ppttoxml(const QString& file, QIODevice* out) {
0018     QXmlStreamWriter xmlout(out);
0019     xmlout.setAutoFormatting(true);
0020     xmlout.writeStartDocument();
0021     xmlout.writeProcessingInstruction("xml-stylesheet", "type='text/xsl' href='ppttosvg.xsl'");
0022     xmlout.writeStartElement("ppt");
0023     POLE::Storage storage(file.toLocal8Bit());
0024     if (!storage.open()) return;
0025 
0026     string prefix;
0027     if (storage.isDirectory("PP97_DUALSTORAGE")) {
0028         prefix = "PP97_DUALSTORAGE/";
0029     } else {
0030         prefix = "/";
0031     }
0032     list<string> entries = storage.entries(prefix);
0033     for (list<string>::const_iterator i=entries.begin(); i!=entries.end(); ++i) {
0034         if (!storage.isDirectory(prefix+*i)) {
0035             POLE::Stream stream(&storage, prefix+*i);
0036             QString streamname(QString::fromStdString(*i));
0037             QByteArray array;
0038             array.resize(stream.size());
0039             unsigned long read = stream.read((unsigned char*)array.data(), stream.size());
0040             if (read != stream.size()) {
0041                 qDebug() << "Error reading stream " << streamname;
0042                 return;
0043             }
0044 //                write("/tmp/"+streamname+".in", array);
0045             QBuffer buffer;
0046             buffer.setData(array);
0047             buffer.open(QIODevice::ReadOnly);
0048             LEInputStream listream(&buffer);
0049             qDebug() << "Parsing stream '" << streamname << "'";
0050 
0051             const Introspectable* i;
0052             try {
0053                 i = parse(streamname, listream);
0054             } catch (IOException& e) {
0055                 qDebug() << "Error: " << e.msg;
0056                 continue;
0057             }
0058 
0059             if (listream.getPosition() != (qint64)stream.size()) {
0060                 qDebug() << stream.size() - listream.getPosition()
0061                     << "trailing bytes in stream " << streamname;
0062                 return;
0063             }
0064             buffer.close();
0065 
0066             xmlout.writeStartElement(i->getIntrospection()->name);
0067             if (i->getIntrospection()->name != "TODOS") {
0068                 printWithExtendedParser(xmlout, i);
0069             }
0070             xmlout.writeEndElement();
0071 
0072             buffer.buffer().clear();
0073             buffer.open(QIODevice::WriteOnly);
0074             LEOutputStream lostream(&buffer);
0075             serialize(i, streamname, lostream);
0076 //                write("/tmp/"+streamname+".out", buffer.data());
0077             if (array != buffer.data()) {
0078                 qDebug() << "Serialized data different from original in "
0079                     << streamname;
0080             }
0081 
0082             delete i;
0083         }
0084     }
0085     xmlout.writeEndElement();
0086     xmlout.writeEndDocument();
0087 }
0088 
0089 int
0090 main(int argc, char** argv) {
0091     QCoreApplication app(argc, argv);
0092     if (argc != 2 && argc != 3) return -1;
0093 
0094     QFile out;
0095     if (argc == 3) {
0096         out.setFileName(argv[2]);
0097         out.open(QIODevice::WriteOnly);
0098     } else {
0099         out.open(stdout, QIODevice::WriteOnly);
0100     }
0101     ppttoxml(QLatin1String(argv[1]), &out);
0102     out.close();
0103 
0104     return 0;
0105 }