Changeset View
Changeset View
Standalone View
Standalone View
src/core/kconfigini.cpp
Show All 20 Lines | |||||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "kconfigini_p.h" | 23 | #include "kconfigini_p.h" | ||
24 | 24 | | |||
25 | #include "kconfig.h" | 25 | #include "kconfig.h" | ||
26 | #include "kconfigbackend_p.h" | 26 | #include "kconfigbackend_p.h" | ||
27 | #include "bufferfragment_p.h" | 27 | #include "bufferfragment_p.h" | ||
28 | #include "kconfigdata.h" | 28 | #include "kconfigdata.h" | ||
29 | #include "kconfig_core_log_settings.h" | ||||
29 | 30 | | |||
30 | #include <qsavefile.h> | 31 | #include <qsavefile.h> | ||
31 | #include <qlockfile.h> | 32 | #include <qlockfile.h> | ||
32 | #include <qdatetime.h> | 33 | #include <qdatetime.h> | ||
33 | #include <qdir.h> | 34 | #include <qdir.h> | ||
34 | #include <qfile.h> | 35 | #include <qfile.h> | ||
35 | #include <qfileinfo.h> | 36 | #include <qfileinfo.h> | ||
36 | #include <qdebug.h> | 37 | #include <qdebug.h> | ||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Line(s) | 134 | if (line.at(0) == '[') { // found a group | |||
134 | groupOptionImmutable = fileOptionImmutable; | 135 | groupOptionImmutable = fileOptionImmutable; | ||
135 | 136 | | |||
136 | QByteArray newGroup; | 137 | QByteArray newGroup; | ||
137 | int start = 1, end; | 138 | int start = 1, end; | ||
138 | do { | 139 | do { | ||
139 | end = start; | 140 | end = start; | ||
140 | for (;;) { | 141 | for (;;) { | ||
141 | if (end == line.length()) { | 142 | if (end == line.length()) { | ||
142 | qWarning() << warningProlog(file, lineNo) << "Invalid group header."; | 143 | qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid group header."; | ||
143 | // XXX maybe reset the current group here? | 144 | // XXX maybe reset the current group here? | ||
144 | goto next_line; | 145 | goto next_line; | ||
145 | } | 146 | } | ||
146 | if (line.at(end) == ']') { | 147 | if (line.at(end) == ']') { | ||
147 | break; | 148 | break; | ||
148 | } | 149 | } | ||
149 | end++; | 150 | end++; | ||
150 | } | 151 | } | ||
Show All 40 Lines | 182 | } else { | |||
191 | } else { | 192 | } else { | ||
192 | BufferFragment temp = line.left(eqpos); | 193 | BufferFragment temp = line.left(eqpos); | ||
193 | temp.trim(); | 194 | temp.trim(); | ||
194 | aKey = temp; | 195 | aKey = temp; | ||
195 | line.truncateLeft(eqpos + 1); | 196 | line.truncateLeft(eqpos + 1); | ||
196 | line.trim(); | 197 | line.trim(); | ||
197 | } | 198 | } | ||
198 | if (aKey.isEmpty()) { | 199 | if (aKey.isEmpty()) { | ||
199 | qWarning() << warningProlog(file, lineNo) << "Invalid entry (empty key)"; | 200 | qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (empty key)"; | ||
200 | continue; | 201 | continue; | ||
201 | } | 202 | } | ||
202 | 203 | | |||
203 | KEntryMap::EntryOptions entryOptions = nullptr; | 204 | KEntryMap::EntryOptions entryOptions = nullptr; | ||
204 | if (groupOptionImmutable) { | 205 | if (groupOptionImmutable) { | ||
205 | entryOptions |= KEntryMap::EntryImmutable; | 206 | entryOptions |= KEntryMap::EntryImmutable; | ||
206 | } | 207 | } | ||
207 | 208 | | |||
208 | BufferFragment locale; | 209 | BufferFragment locale; | ||
209 | int start; | 210 | int start; | ||
210 | while ((start = aKey.lastIndexOf('[')) >= 0) { | 211 | while ((start = aKey.lastIndexOf('[')) >= 0) { | ||
211 | int end = aKey.indexOf(']', start); | 212 | int end = aKey.indexOf(']', start); | ||
212 | if (end < 0) { | 213 | if (end < 0) { | ||
213 | qWarning() << warningProlog(file, lineNo) | 214 | qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) | ||
214 | << "Invalid entry (missing ']')"; | 215 | << "Invalid entry (missing ']')"; | ||
215 | goto next_line; | 216 | goto next_line; | ||
216 | } else if (end > start + 1 && aKey.at(start + 1) == '$') { // found option(s) | 217 | } else if (end > start + 1 && aKey.at(start + 1) == '$') { // found option(s) | ||
217 | int i = start + 2; | 218 | int i = start + 2; | ||
218 | while (i < end) { | 219 | while (i < end) { | ||
219 | switch (aKey.at(i)) { | 220 | switch (aKey.at(i)) { | ||
220 | case 'i': | 221 | case 'i': | ||
221 | if (!kde_kiosk_exception) { | 222 | if (!kde_kiosk_exception) { | ||
Show All 13 Lines | 231 | case 'd': | |||
235 | goto next_line; | 236 | goto next_line; | ||
236 | default: | 237 | default: | ||
237 | break; | 238 | break; | ||
238 | } | 239 | } | ||
239 | i++; | 240 | i++; | ||
240 | } | 241 | } | ||
241 | } else { // found a locale | 242 | } else { // found a locale | ||
242 | if (!locale.isNull()) { | 243 | if (!locale.isNull()) { | ||
243 | qWarning() << warningProlog(file, lineNo) | 244 | qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) | ||
244 | << "Invalid entry (second locale!?)"; | 245 | << "Invalid entry (second locale!?)"; | ||
245 | goto next_line; | 246 | goto next_line; | ||
246 | } | 247 | } | ||
247 | 248 | | |||
248 | locale = aKey.mid(start + 1, end - start - 1); | 249 | locale = aKey.mid(start + 1, end - start - 1); | ||
249 | } | 250 | } | ||
250 | aKey.truncate(start); | 251 | aKey.truncate(start); | ||
251 | } | 252 | } | ||
252 | if (eqpos < 0) { // Do this here after [$d] was checked | 253 | if (eqpos < 0) { // Do this here after [$d] was checked | ||
253 | qWarning() << warningProlog(file, lineNo) << "Invalid entry (missing '=')"; | 254 | qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, lineNo) << "Invalid entry (missing '=')"; | ||
254 | continue; | 255 | continue; | ||
255 | } | 256 | } | ||
256 | printableToString(&aKey, file, lineNo); | 257 | printableToString(&aKey, file, lineNo); | ||
257 | if (!locale.isEmpty()) { | 258 | if (!locale.isEmpty()) { | ||
258 | if (locale != currentLocale && locale != currentLanguage) { | 259 | if (locale != currentLocale && locale != currentLanguage) { | ||
259 | // backward compatibility. C == en_US | 260 | // backward compatibility. C == en_US | ||
260 | if (locale.at(0) != 'C' || currentLocale != "en_US") { | 261 | if (locale.at(0) != 'C' || currentLocale != "en_US") { | ||
261 | if (merging) { | 262 | if (merging) { | ||
▲ Show 20 Lines • Show All 244 Lines • ▼ Show 20 Line(s) | 497 | if (!file.size() && (fileMode == (QFile::ReadUser | QFile::WriteUser))) { | |||
506 | } | 507 | } | ||
507 | } else { | 508 | } else { | ||
508 | // Normal case: Close the file | 509 | // Normal case: Close the file | ||
509 | if (file.commit()) { | 510 | if (file.commit()) { | ||
510 | QFile::setPermissions(filePath(), fileMode); | 511 | QFile::setPermissions(filePath(), fileMode); | ||
511 | return true; | 512 | return true; | ||
512 | } | 513 | } | ||
513 | // Couldn't write. Disk full? | 514 | // Couldn't write. Disk full? | ||
514 | qWarning() << "Couldn't write" << filePath() << ". Disk full?"; | 515 | qCWarning(KCONFIG_CORE_LOG) << "Couldn't write" << filePath() << ". Disk full?"; | ||
515 | return false; | 516 | return false; | ||
516 | } | 517 | } | ||
517 | } else { | 518 | } else { | ||
518 | // Open existing file. *DON'T* create it if it suddenly does not exist! | 519 | // Open existing file. *DON'T* create it if it suddenly does not exist! | ||
519 | #ifdef Q_OS_UNIX | 520 | #ifdef Q_OS_UNIX | ||
520 | int fd = QT_OPEN(QFile::encodeName(filePath()).constData(), O_WRONLY | O_TRUNC); | 521 | int fd = QT_OPEN(QFile::encodeName(filePath()).constData(), O_WRONLY | O_TRUNC); | ||
521 | if (fd < 0) { | 522 | if (fd < 0) { | ||
522 | return false; | 523 | return false; | ||
▲ Show 20 Lines • Show All 327 Lines • ▼ Show 20 Line(s) | 850 | if (c >= '0' && c <= '9') { | |||
850 | ret |= c - '0'; | 851 | ret |= c - '0'; | ||
851 | } else if (c >= 'a' && c <= 'f') { | 852 | } else if (c >= 'a' && c <= 'f') { | ||
852 | ret |= c - 'a' + 0x0a; | 853 | ret |= c - 'a' + 0x0a; | ||
853 | } else if (c >= 'A' && c <= 'F') { | 854 | } else if (c >= 'A' && c <= 'F') { | ||
854 | ret |= c - 'A' + 0x0a; | 855 | ret |= c - 'A' + 0x0a; | ||
855 | } else { | 856 | } else { | ||
856 | QByteArray e(str, 2); | 857 | QByteArray e(str, 2); | ||
857 | e.prepend("\\x"); | 858 | e.prepend("\\x"); | ||
858 | qWarning() << warningProlog(file, line) << "Invalid hex character " << c | 859 | qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) << "Invalid hex character " << c | ||
859 | << " in \\x<nn>-type escape sequence \"" << e.constData() << "\"."; | 860 | << " in \\x<nn>-type escape sequence \"" << e.constData() << "\"."; | ||
860 | return 'x'; | 861 | return 'x'; | ||
861 | } | 862 | } | ||
862 | } | 863 | } | ||
863 | return char(ret); | 864 | return char(ret); | ||
864 | } | 865 | } | ||
865 | 866 | | |||
866 | void KConfigIniBackend::printableToString(BufferFragment *aString, const QFile &file, int line) | 867 | void KConfigIniBackend::printableToString(BufferFragment *aString, const QFile &file, int line) | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 917 | if (i + 2 < l) { | |||
918 | i += 2; | 919 | i += 2; | ||
919 | } else { | 920 | } else { | ||
920 | *r = 'x'; | 921 | *r = 'x'; | ||
921 | i = l - 1; | 922 | i = l - 1; | ||
922 | } | 923 | } | ||
923 | break; | 924 | break; | ||
924 | default: | 925 | default: | ||
925 | *r = '\\'; | 926 | *r = '\\'; | ||
926 | qWarning() << warningProlog(file, line) | 927 | qCWarning(KCONFIG_CORE_LOG) << warningProlog(file, line) | ||
927 | << QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]); | 928 | << QStringLiteral("Invalid escape sequence \"\\%1\".").arg(str[i]); | ||
928 | } | 929 | } | ||
929 | } | 930 | } | ||
930 | } | 931 | } | ||
931 | aString->truncate(r - aString->constData()); | 932 | aString->truncate(r - aString->constData()); | ||
932 | } | 933 | } |