Block* readBlock(int part, u32int addr) { u32int start, end; u64int offset; int n, nn; Block *b; uchar *buf; start = partStart(part); end = partEnd(part); if(addr >= end-start) { werrstr("bad addr 0x%.8ux; wanted 0x%.8ux - 0x%.8ux", addr, start, end); return nil; } b = allocBlock(); b->addr = addr; buf = b->data; offset = ((u64int)(addr+start))*h.blockSize; n = h.blockSize; while(n > 0) { nn = pread(fd, buf, n, offset); if(nn < 0) { blockPut(b); return nil; } if(nn == 0) { werrstr("short read"); blockPut(b); return nil; } n -= nn; offset += nn; buf += nn; } return b; }
int main(int /*argc*/, char ** /*argv*/) { QByteArray output = "digraph filters {\n"; // The following code is shamelessly copied over from Calligra::Graph::buildGraph // It wasn't feasible to do some serious changes in the lib for that tiny bit // of duplicated code in a test file. QList<QString> vertices; // to keep track of already inserted values, not performance critical // Make sure that all available parts are added to the graph const QList<KoDocumentEntry> parts(KoDocumentEntry::query()); QList<KoDocumentEntry>::ConstIterator partIt(parts.begin()); QList<KoDocumentEntry>::ConstIterator partEnd(parts.end()); while (partIt != partEnd) { //kDebug() << ( *partIt ).service()->desktopEntryName(); QStringList nativeMimeTypes = (*partIt).loader()->metaData().value("MetaData").toObject().value("X-KDE-ExtraNativeMimeTypes").toString().split(','); nativeMimeTypes += (*partIt).loader()->metaData().value("MetaData").toObject().value("X-KDE-NativeMimeType").toString(); QStringList::ConstIterator it = nativeMimeTypes.constBegin(); QStringList::ConstIterator end = nativeMimeTypes.constEnd(); for (; it != end; ++it) { QString key = *it; //kDebug() <<"" << key; if (!key.isEmpty()) { output += " \""; output += key.toLatin1(); output += "\" [shape=box, style=filled, fillcolor=lightblue];\n"; if (! vertices.contains(key)) vertices.append(key); } } ++partIt; } const QList<KoFilterEntry::Ptr> filters(KoFilterEntry::query()); // no constraint here - we want *all* :) QList<KoFilterEntry::Ptr>::ConstIterator it = filters.begin(); QList<KoFilterEntry::Ptr>::ConstIterator end = filters.end(); for (; it != end; ++it) { qDebug() << "import" << (*it)->import << " export" << (*it)->export_; // First add the "starting points" QStringList::ConstIterator importIt = (*it)->import.constBegin(); QStringList::ConstIterator importEnd = (*it)->import.constEnd(); for (; importIt != importEnd; ++importIt) { // already there? if (! vertices.contains(*importIt)) { vertices.append(*importIt); output += " \""; output += (*importIt).toLatin1(); output += "\";\n"; } } QStringList::ConstIterator exportIt = (*it)->export_.constBegin(); QStringList::ConstIterator exportEnd = (*it)->export_.constEnd(); for (; exportIt != exportEnd; ++exportIt) { // First make sure the export vertex is in place if (! vertices.contains(*exportIt)) { output += " \""; output += (*exportIt).toLatin1(); output += "\";\n"; vertices.append(*exportIt); } // Then create the appropriate edges importIt = (*it)->import.constBegin(); for (; importIt != importEnd; ++importIt) { output += " \""; output += (*importIt).toLatin1(); output += "\" -> \""; output += (*exportIt).toLatin1(); if (KoFilterManager::filterAvailable(*it)) output += "\";\n"; else output += "\" [style=dotted];\n"; } } } output += "}\n"; QFile f("graph.dot"); if (f.open(QIODevice::WriteOnly)) f.write(output); f.close(); return 0; }