[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the Qt Linguist of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at qt-info@nokia.com.
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #ifndef PROPARSERUTILS_H
|
---|
| 43 | #define PROPARSERUTILS_H
|
---|
| 44 |
|
---|
| 45 | #include <QtCore/QDir>
|
---|
[561] | 46 | #ifndef QT_BOOTSTRAPPED
|
---|
[2] | 47 | #include <QtCore/QLibraryInfo>
|
---|
[561] | 48 | #endif
|
---|
[2] | 49 |
|
---|
| 50 | QT_BEGIN_NAMESPACE
|
---|
| 51 |
|
---|
[561] | 52 | #ifdef QT_BOOTSTRAPPED
|
---|
| 53 | // this is a stripped down version of the one found in QtCore
|
---|
| 54 | class QLibraryInfo
|
---|
| 55 | {
|
---|
| 56 | public:
|
---|
| 57 | enum LibraryLocation
|
---|
| 58 | {
|
---|
| 59 | PrefixPath,
|
---|
| 60 | DocumentationPath,
|
---|
| 61 | HeadersPath,
|
---|
| 62 | LibrariesPath,
|
---|
| 63 | BinariesPath,
|
---|
| 64 | PluginsPath,
|
---|
| 65 | DataPath,
|
---|
| 66 | TranslationsPath,
|
---|
| 67 | SettingsPath,
|
---|
| 68 | DemosPath,
|
---|
| 69 | ExamplesPath
|
---|
| 70 | };
|
---|
| 71 | static QString location(LibraryLocation);
|
---|
| 72 | };
|
---|
| 73 | #endif
|
---|
| 74 |
|
---|
[2] | 75 | // Pre- and postcondition macros
|
---|
| 76 | #define PRE(cond) do {if (!(cond))qt_assert(#cond,__FILE__,__LINE__);} while (0)
|
---|
| 77 | #define POST(cond) do {if (!(cond))qt_assert(#cond,__FILE__,__LINE__);} while (0)
|
---|
| 78 |
|
---|
| 79 | // This struct is from qmake, but we are not using everything.
|
---|
| 80 | struct Option
|
---|
| 81 | {
|
---|
| 82 | //simply global convenience
|
---|
| 83 | //static QString libtool_ext;
|
---|
| 84 | //static QString pkgcfg_ext;
|
---|
| 85 | //static QString prf_ext;
|
---|
| 86 | //static QString prl_ext;
|
---|
| 87 | //static QString ui_ext;
|
---|
| 88 | //static QStringList h_ext;
|
---|
| 89 | //static QStringList cpp_ext;
|
---|
| 90 | //static QString h_moc_ext;
|
---|
| 91 | //static QString cpp_moc_ext;
|
---|
| 92 | //static QString obj_ext;
|
---|
| 93 | //static QString lex_ext;
|
---|
| 94 | //static QString yacc_ext;
|
---|
| 95 | //static QString h_moc_mod;
|
---|
| 96 | //static QString cpp_moc_mod;
|
---|
| 97 | //static QString lex_mod;
|
---|
| 98 | //static QString yacc_mod;
|
---|
| 99 | static QString dir_sep;
|
---|
| 100 | static QString dirlist_sep;
|
---|
| 101 | static QString qmakespec;
|
---|
| 102 | static QChar field_sep;
|
---|
| 103 |
|
---|
| 104 | enum TARG_MODE { TARG_UNIX_MODE, TARG_WIN_MODE, TARG_MACX_MODE, TARG_MAC9_MODE, TARG_QNX6_MODE };
|
---|
| 105 | static TARG_MODE target_mode;
|
---|
| 106 | //static QString pro_ext;
|
---|
| 107 | //static QString res_ext;
|
---|
| 108 |
|
---|
| 109 | static void init()
|
---|
| 110 | {
|
---|
| 111 | #ifdef Q_OS_WIN
|
---|
| 112 | Option::dirlist_sep = QLatin1Char(';');
|
---|
| 113 | Option::dir_sep = QLatin1Char('\\');
|
---|
| 114 | #else
|
---|
| 115 | Option::dirlist_sep = QLatin1Char(':');
|
---|
| 116 | Option::dir_sep = QLatin1Char(QLatin1Char('/'));
|
---|
| 117 | #endif
|
---|
| 118 | Option::qmakespec = QString::fromLatin1(qgetenv("QMAKESPEC").data());
|
---|
| 119 | Option::field_sep = QLatin1Char(' ');
|
---|
| 120 | }
|
---|
[561] | 121 |
|
---|
| 122 | enum StringFixFlags {
|
---|
| 123 | FixNone = 0x00,
|
---|
| 124 | FixEnvVars = 0x01,
|
---|
| 125 | FixPathCanonicalize = 0x02,
|
---|
| 126 | FixPathToLocalSeparators = 0x04,
|
---|
| 127 | FixPathToTargetSeparators = 0x08
|
---|
| 128 | };
|
---|
| 129 | static QString fixString(QString string, uchar flags);
|
---|
| 130 |
|
---|
| 131 | inline static QString fixPathToLocalOS(const QString &in, bool fix_env = true, bool canonical = true)
|
---|
| 132 | {
|
---|
| 133 | uchar flags = FixPathToLocalSeparators;
|
---|
| 134 | if (fix_env)
|
---|
| 135 | flags |= FixEnvVars;
|
---|
| 136 | if (canonical)
|
---|
| 137 | flags |= FixPathCanonicalize;
|
---|
| 138 | return fixString(in, flags);
|
---|
| 139 | }
|
---|
[2] | 140 | };
|
---|
| 141 | #if defined(Q_OS_WIN32)
|
---|
| 142 | Option::TARG_MODE Option::target_mode = Option::TARG_WIN_MODE;
|
---|
| 143 | #elif defined(Q_OS_MAC)
|
---|
| 144 | Option::TARG_MODE Option::target_mode = Option::TARG_MACX_MODE;
|
---|
| 145 | #elif defined(Q_OS_QNX6)
|
---|
| 146 | Option::TARG_MODE Option::target_mode = Option::TARG_QNX6_MODE;
|
---|
| 147 | #else
|
---|
| 148 | Option::TARG_MODE Option::target_mode = Option::TARG_UNIX_MODE;
|
---|
| 149 | #endif
|
---|
| 150 |
|
---|
| 151 | QString Option::qmakespec;
|
---|
| 152 | QString Option::dirlist_sep;
|
---|
| 153 | QString Option::dir_sep;
|
---|
| 154 | QChar Option::field_sep;
|
---|
| 155 |
|
---|
| 156 | static void insertUnique(QHash<QString, QStringList> *map,
|
---|
[561] | 157 | const QString &key, const QStringList &value)
|
---|
[2] | 158 | {
|
---|
| 159 | QStringList &sl = (*map)[key];
|
---|
[561] | 160 | foreach (const QString &str, value)
|
---|
| 161 | if (!sl.contains(str))
|
---|
| 162 | sl.append(str);
|
---|
[2] | 163 | }
|
---|
| 164 |
|
---|
[561] | 165 | static void removeEach(QHash<QString, QStringList> *map,
|
---|
| 166 | const QString &key, const QStringList &value)
|
---|
| 167 | {
|
---|
| 168 | QStringList &sl = (*map)[key];
|
---|
| 169 | foreach (const QString &str, value)
|
---|
| 170 | sl.removeAll(str);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[2] | 173 | /*
|
---|
| 174 | See ProFileEvaluator::Private::visitProValue(...)
|
---|
| 175 |
|
---|
| 176 | static QStringList replaceInList(const QStringList &varList, const QRegExp ®exp,
|
---|
| 177 | const QString &replace, bool global)
|
---|
| 178 | {
|
---|
| 179 | QStringList resultList = varList;
|
---|
| 180 |
|
---|
| 181 | for (QStringList::Iterator varit = resultList.begin(); varit != resultList.end();) {
|
---|
| 182 | if (varit->contains(regexp)) {
|
---|
| 183 | *varit = varit->replace(regexp, replace);
|
---|
| 184 | if (varit->isEmpty())
|
---|
| 185 | varit = resultList.erase(varit);
|
---|
| 186 | else
|
---|
| 187 | ++varit;
|
---|
| 188 | if (!global)
|
---|
| 189 | break;
|
---|
| 190 | } else {
|
---|
| 191 | ++varit;
|
---|
| 192 | }
|
---|
| 193 | }
|
---|
| 194 | return resultList;
|
---|
| 195 | }
|
---|
| 196 | */
|
---|
| 197 |
|
---|
[561] | 198 | inline QString fixEnvVariables(const QString &x)
|
---|
[2] | 199 | {
|
---|
[561] | 200 | return Option::fixString(x, Option::FixEnvVars);
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | inline QStringList splitPathList(const QString &paths)
|
---|
| 204 | {
|
---|
[2] | 205 | return paths.split(Option::dirlist_sep);
|
---|
| 206 | }
|
---|
| 207 |
|
---|
| 208 | static QStringList split_arg_list(QString params)
|
---|
| 209 | {
|
---|
| 210 | int quote = 0;
|
---|
| 211 | QStringList args;
|
---|
| 212 |
|
---|
| 213 | const ushort LPAREN = '(';
|
---|
| 214 | const ushort RPAREN = ')';
|
---|
| 215 | const ushort SINGLEQUOTE = '\'';
|
---|
| 216 | const ushort DOUBLEQUOTE = '"';
|
---|
| 217 | const ushort COMMA = ',';
|
---|
| 218 | const ushort SPACE = ' ';
|
---|
| 219 | //const ushort TAB = '\t';
|
---|
| 220 |
|
---|
| 221 | ushort unicode;
|
---|
| 222 | const QChar *params_data = params.data();
|
---|
| 223 | const int params_len = params.length();
|
---|
| 224 | int last = 0;
|
---|
| 225 | while (last < params_len && ((params_data+last)->unicode() == SPACE
|
---|
| 226 | /*|| (params_data+last)->unicode() == TAB*/))
|
---|
| 227 | ++last;
|
---|
| 228 | for (int x = last, parens = 0; x <= params_len; x++) {
|
---|
| 229 | unicode = (params_data+x)->unicode();
|
---|
| 230 | if (x == params_len) {
|
---|
| 231 | while (x && (params_data+(x-1))->unicode() == SPACE)
|
---|
| 232 | --x;
|
---|
| 233 | QString mid(params_data+last, x-last);
|
---|
| 234 | if (quote) {
|
---|
| 235 | if (mid[0] == quote && mid[(int)mid.length()-1] == quote)
|
---|
| 236 | mid = mid.mid(1, mid.length()-2);
|
---|
| 237 | quote = 0;
|
---|
| 238 | }
|
---|
| 239 | args << mid;
|
---|
| 240 | break;
|
---|
| 241 | }
|
---|
| 242 | if (unicode == LPAREN) {
|
---|
| 243 | --parens;
|
---|
| 244 | } else if (unicode == RPAREN) {
|
---|
| 245 | ++parens;
|
---|
| 246 | } else if (quote && unicode == quote) {
|
---|
| 247 | quote = 0;
|
---|
| 248 | } else if (!quote && (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE)) {
|
---|
| 249 | quote = unicode;
|
---|
| 250 | }
|
---|
| 251 | if (!parens && !quote && unicode == COMMA) {
|
---|
| 252 | QString mid = params.mid(last, x - last).trimmed();
|
---|
| 253 | args << mid;
|
---|
| 254 | last = x+1;
|
---|
| 255 | while (last < params_len && ((params_data+last)->unicode() == SPACE
|
---|
| 256 | /*|| (params_data+last)->unicode() == TAB*/))
|
---|
| 257 | ++last;
|
---|
| 258 | }
|
---|
| 259 | }
|
---|
| 260 | return args;
|
---|
| 261 | }
|
---|
| 262 |
|
---|
| 263 | static QStringList split_value_list(const QString &vals, bool do_semicolon=false)
|
---|
| 264 | {
|
---|
| 265 | QString build;
|
---|
| 266 | QStringList ret;
|
---|
| 267 | QStack<char> quote;
|
---|
| 268 |
|
---|
| 269 | const ushort LPAREN = '(';
|
---|
| 270 | const ushort RPAREN = ')';
|
---|
| 271 | const ushort SINGLEQUOTE = '\'';
|
---|
| 272 | const ushort DOUBLEQUOTE = '"';
|
---|
| 273 | const ushort BACKSLASH = '\\';
|
---|
| 274 | const ushort SEMICOLON = ';';
|
---|
| 275 |
|
---|
| 276 | ushort unicode;
|
---|
| 277 | const QChar *vals_data = vals.data();
|
---|
| 278 | const int vals_len = vals.length();
|
---|
| 279 | for (int x = 0, parens = 0; x < vals_len; x++) {
|
---|
| 280 | unicode = vals_data[x].unicode();
|
---|
| 281 | if (x != (int)vals_len-1 && unicode == BACKSLASH &&
|
---|
| 282 | (vals_data[x+1].unicode() == SINGLEQUOTE || vals_data[x+1].unicode() == DOUBLEQUOTE)) {
|
---|
| 283 | build += vals_data[x++]; //get that 'escape'
|
---|
| 284 | } else if (!quote.isEmpty() && unicode == quote.top()) {
|
---|
| 285 | quote.pop();
|
---|
| 286 | } else if (unicode == SINGLEQUOTE || unicode == DOUBLEQUOTE) {
|
---|
| 287 | quote.push(unicode);
|
---|
| 288 | } else if (unicode == RPAREN) {
|
---|
| 289 | --parens;
|
---|
| 290 | } else if (unicode == LPAREN) {
|
---|
| 291 | ++parens;
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | if (!parens && quote.isEmpty() && ((do_semicolon && unicode == SEMICOLON) ||
|
---|
| 295 | vals_data[x] == Option::field_sep)) {
|
---|
| 296 | ret << build;
|
---|
| 297 | build.clear();
|
---|
| 298 | } else {
|
---|
| 299 | build += vals_data[x];
|
---|
| 300 | }
|
---|
| 301 | }
|
---|
| 302 | if (!build.isEmpty())
|
---|
| 303 | ret << build;
|
---|
| 304 | return ret;
|
---|
| 305 | }
|
---|
| 306 |
|
---|
| 307 | static QStringList qmake_mkspec_paths()
|
---|
| 308 | {
|
---|
| 309 | QStringList ret;
|
---|
[561] | 310 | const QString concat = QDir::separator() + QLatin1String("mkspecs");
|
---|
[2] | 311 | QByteArray qmakepath = qgetenv("QMAKEPATH");
|
---|
| 312 | if (!qmakepath.isEmpty()) {
|
---|
| 313 | const QStringList lst = splitPathList(QString::fromLocal8Bit(qmakepath));
|
---|
| 314 | for (QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it)
|
---|
| 315 | ret << ((*it) + concat);
|
---|
| 316 | }
|
---|
| 317 | ret << QLibraryInfo::location(QLibraryInfo::DataPath) + concat;
|
---|
| 318 |
|
---|
| 319 | return ret;
|
---|
| 320 | }
|
---|
| 321 |
|
---|
| 322 | QT_END_NAMESPACE
|
---|
| 323 |
|
---|
| 324 | #endif // PROPARSERUTILS_H
|
---|