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