00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifndef PROPARSERUTILS_H
00025 #define PROPARSERUTILS_H
00026
00027 #include <QtCore/QLibraryInfo>
00028
00029
00030 #define PRE(cond) do {if(!(cond))qt_assert(#cond,__FILE__,__LINE__);} while (0)
00031 #define POST(cond) do {if(!(cond))qt_assert(#cond,__FILE__,__LINE__);} while (0)
00032
00033
00034 struct Option
00035 {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053 static QString dir_sep;
00054 static QString dirlist_sep;
00055 static QString qmakespec;
00056
00057 enum TARG_MODE { TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE, TARG_MAC9_MODE, TARG_QNX6_MODE };
00058 static TARG_MODE target_mode;
00059
00060
00061
00062
00063 static void init()
00064 {
00065 #ifdef Q_OS_WIN
00066 Option::dirlist_sep = ';';
00067 Option::dir_sep = QLatin1Char('\\');
00068 #else
00069 Option::dirlist_sep = ':';
00070 Option::dir_sep = QLatin1Char('/');
00071 #endif
00072 Option::qmakespec = qgetenv("QMAKESPEC");
00073 }
00074 };
00075 #if defined(Q_OS_WIN32)
00076 Option::TARG_MODE Option::target_mode = Option::TARG_WIN_MODE;
00077 #elif defined(Q_OS_MAC)
00078 Option::TARG_MODE Option::target_mode = Option::TARG_MACX_MODE;
00079 #elif defined(Q_OS_QNX6)
00080 Option::TARG_MODE Option::target_mode = Option::TARG_QNX6_MODE;
00081 #else
00082 Option::TARG_MODE Option::target_mode = Option::TARG_UNIX_MODE;
00083 #endif
00084
00085 QString Option::qmakespec;
00086 QString Option::dirlist_sep;
00087 QString Option::dir_sep;
00088
00089 static void unquote(QString *string)
00090 {
00091 PRE(string);
00092 if ( (string->startsWith(QLatin1Char('\"')) && string->endsWith(QLatin1Char('\"')))
00093 || (string->startsWith(QLatin1Char('\'')) && string->endsWith(QLatin1Char('\''))) )
00094 {
00095 string->remove(0,1);
00096 string->remove(string->length() - 1,1);
00097 }
00098 }
00099
00100
00101 static void insertUnique(QMap<QByteArray, QStringList> *map, const QByteArray &key, const QString &value, bool unique = true)
00102 {
00103 QStringList &sl = (*map)[key];
00104 if (!unique || (unique && !sl.contains(value))) {
00105 sl.append(value);
00106 }
00107 }
00108
00109 inline QStringList splitPathList(const QString paths) { return paths.split(Option::dirlist_sep); }
00110
00111 static QStringList split_arg_list(QString params)
00112 {
00113 int quote = 0;
00114 QStringList args;
00115
00116 const ushort LPAREN = '(';
00117 const ushort RPAREN = ')';
00118 const ushort SINGLEQUOTE = '\'';
00119 const ushort DOUBLEQUOTE = '"';
00120 const ushort COMMA = ',';
00121 const ushort SPACE = ' ';
00122
00123
00124 ushort unicode;
00125 const QChar *params_data = params.data();
00126 const int params_len = params.length();
00127 int last = 0;
00128 while(last < params_len && ((params_data+last)->unicode() == SPACE
00129 ))
00130 ++last;
00131 for(int x = last, parens = 0; x <= params_len; x++) {
00132 unicode = (params_data+x)->unicode();
00133 if(x == params_len) {
00134 while(x && (params_data+(x-1))->unicode() == SPACE)
00135 --x;
00136 QString mid(params_data+last, x-last);
00137 if(quote) {
00138 if(mid[0] == quote && mid[(int)mid.length()-1] == quote)
00139 mid = mid.mid(1, mid.length()-2);
00140 quote = 0;
00141 }
00142 args << mid;
00143 break;
00144 }
00145 if(unicode == LPAREN) {
00146 --parens;
00147 } else if(unicode == RPAREN) {
00148 ++parens;
00149 } else if(quote && unicode == quote) {
00150 quote = 0;
00151 } else if(!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) {
00152 quote = unicode;
00153 } else if(!parens && !quote && unicode == COMMA) {
00154 QString mid = params.mid(last, x - last).trimmed();
00155 args << mid;
00156 last = x+1;
00157 while(last < params_len && ((params_data+last)->unicode() == SPACE
00158 ))
00159 ++last;
00160 }
00161 }
00162 for(int i = 0; i < args.count(); i++)
00163 unquote(&args[i]);
00164 return args;
00165 }
00166
00167
00168 static QStringList qmake_mkspec_paths()
00169 {
00170 QStringList ret;
00171 const QString concat = QDir::separator() + QString("mkspecs");
00172 QByteArray qmakepath = qgetenv("QMAKEPATH");
00173 if (!qmakepath.isEmpty()) {
00174 const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath));
00175 for(QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
00176 ret << ((*it) + concat);
00177 }
00178 ret << QLibraryInfo::location(QLibraryInfo::DataPath) + concat;
00179
00180 return ret;
00181 }
00182
00183
00184 static QString getPropertyValue(const QString &v)
00185 {
00186 if(v == "QT_INSTALL_PREFIX")
00187 return QLibraryInfo::location(QLibraryInfo::PrefixPath);
00188 else if(v == "QT_INSTALL_DATA")
00189 return QLibraryInfo::location(QLibraryInfo::DataPath);
00190 else if(v == "QT_INSTALL_DOCS")
00191 return QLibraryInfo::location(QLibraryInfo::DocumentationPath);
00192 else if(v == "QT_INSTALL_HEADERS")
00193 return QLibraryInfo::location(QLibraryInfo::HeadersPath);
00194 else if(v == "QT_INSTALL_LIBS")
00195 return QLibraryInfo::location(QLibraryInfo::LibrariesPath);
00196 else if(v == "QT_INSTALL_BINS")
00197 return QLibraryInfo::location(QLibraryInfo::BinariesPath);
00198 else if(v == "QT_INSTALL_PLUGINS")
00199 return QLibraryInfo::location(QLibraryInfo::PluginsPath);
00200 else if(v == "QT_INSTALL_TRANSLATIONS")
00201 return QLibraryInfo::location(QLibraryInfo::TranslationsPath);
00202 else if(v == "QT_INSTALL_CONFIGURATION")
00203 return QLibraryInfo::location(QLibraryInfo::SettingsPath);
00204 else if(v == "QT_INSTALL_EXAMPLES")
00205 return QLibraryInfo::location(QLibraryInfo::ExamplesPath);
00206 else if(v == "QT_INSTALL_DEMOS")
00207 return QLibraryInfo::location(QLibraryInfo::DemosPath);
00208 else if(v == "QMAKE_MKSPECS")
00209 return qmake_mkspec_paths().join(Option::dirlist_sep);
00210 else if(v == "QMAKE_VERSION")
00211 return QLatin1String("1.0");
00212
00213 #ifdef QT_VERSION_STR
00214 else if(v == "QT_VERSION")
00215 return QT_VERSION_STR;
00216 #endif
00217 return QLatin1String("UNKNOWN");
00218 }
00219
00220
00221 #endif // PROPARSERUTILS_H
00222