#include <qfile.h>#include <iostream>#include <qcoreapplication.h>const char* c_Usage = "Usage: qtpatcher <file> <new prefix>";const char* c_Prefix = "d:\\qt\\4.3.1-msvc";const QList<QByteArray> pp = QList<QByteArray>() << QByteArray("qt_prfxpath=") + c_Prefix + QByteArray("") << QByteArray("qt_docspath=") + c_Prefix + QByteArray("\\doc") << QByteArray("qt_hdrspath=") + c_Prefix + QByteArray("\\include") << QByteArray("qt_libspath=") + c_Prefix + QByteArray("\\lib") << QByteArray("qt_binspath=") + c_Prefix + QByteArray("\\bin") << QByteArray("qt_plugpath=") + c_Prefix + QByteArray("\\plugins") << QByteArray("qt_datapath=") + c_Prefix + QByteArray("") << QByteArray("qt_trnspath=") + c_Prefix + QByteArray("\\translations") << QByteArray("qt_xmplpath=") + c_Prefix + QByteArray("\\examples") << QByteArray("qt_demopath=") + c_Prefix + QByteArray("\\demos");int findNonZeroIndex(const QByteArray & ba, int from) { while(ba[from++] == '\0'); return from - 1;}int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); if (argc != 3) { std::cout << c_Usage << std::endl; return 0; } QFile qmake(argv[1]); if (!qmake.open(QIODevice::ReadOnly)) { std::cout << "Can't open " << argv[1] << " for reading" << std::endl; return 0; } QByteArray ba = qmake.readAll(); qmake.close(); for (int i=0; i<pp.size(); i++) { int l = findNonZeroIndex(ba, ba.indexOf(pp[i]) + pp[i].length()) - ba.indexOf(pp[i]); QByteArray src = pp[i]; while((src += '\0').length() != l); QByteArray dst = src; dst.replace(c_Prefix, argv[2]); if (dst.length() < l) while((dst += '\0').length() != l); else if (dst.length() > l) dst.remove(l, dst.length()-l); ba.replace(src, dst); } if (!qmake.open(QIODevice::WriteOnly)) { std::cout << "Can't open " << argv[1] << " for writing" << std::endl; return 0; } qmake.write(ba); qmake.close(); return 0;}