31 files changed, 1035 insertions, 598 deletions
diff --git a/qmake/tools/qbitarray.cpp b/qmake/tools/qbitarray.cpp index 4f4e14b..1aaf963 100644 --- a/qmake/tools/qbitarray.cpp +++ b/qmake/tools/qbitarray.cpp | |||
@@ -196,9 +196,10 @@ void QBitArray::pad0() | |||
196 | */ | 196 | */ |
197 | 197 | ||
198 | /*! | 198 | /*! |
199 | Resizes the bit array to \a size bits and returns TRUE if the bit | 199 | Resizes the bit array to \a size bits and returns TRUE if the bit |
200 | array could be resized; otherwise returns FALSE. | 200 | array could be resized; otherwise returns FALSE. The array becomes |
201 | a null array if \a size == 0. | ||
201 | 202 | ||
202 | If the array is expanded, the new bits are set to 0. | 203 | If the array is expanded, the new bits are set to 0. |
203 | 204 | ||
204 | \sa size() | 205 | \sa size() |
diff --git a/qmake/tools/qbuffer.cpp b/qmake/tools/qbuffer.cpp index b213dd9..0fc90e4 100644 --- a/qmake/tools/qbuffer.cpp +++ b/qmake/tools/qbuffer.cpp | |||
@@ -195,10 +195,10 @@ bool QBuffer::open( int m ) | |||
195 | return FALSE; | 195 | return FALSE; |
196 | } | 196 | } |
197 | setMode( m ); | 197 | setMode( m ); |
198 | if ( m & IO_Truncate ) { // truncate buffer | 198 | if ( m & IO_Truncate ) { // truncate buffer |
199 | a.resize( 0 ); | 199 | a.resize( 1 ); |
200 | a_len = 0; | 200 | a_len = 1; |
201 | } | 201 | } |
202 | if ( m & IO_Append ) { // append to end of buffer | 202 | if ( m & IO_Append ) { // append to end of buffer |
203 | ioIndex = a.size(); | 203 | ioIndex = a.size(); |
204 | } else { | 204 | } else { |
diff --git a/qmake/tools/qcomlibrary.cpp b/qmake/tools/qcomlibrary.cpp index a7162fc..2a1b75a 100644 --- a/qmake/tools/qcomlibrary.cpp +++ b/qmake/tools/qcomlibrary.cpp | |||
@@ -62,8 +62,12 @@ QComLibrary::QComLibrary( const QString &filename ) | |||
62 | QComLibrary::~QComLibrary() | 62 | QComLibrary::~QComLibrary() |
63 | { | 63 | { |
64 | if ( autoUnload() ) | 64 | if ( autoUnload() ) |
65 | unload(); | 65 | unload(); |
66 | if ( libiface ) | ||
67 | libiface->release(); | ||
68 | if ( entry ) | ||
69 | entry->release(); | ||
66 | } | 70 | } |
67 | 71 | ||
68 | bool QComLibrary::unload() | 72 | bool QComLibrary::unload() |
69 | { | 73 | { |
@@ -390,12 +394,11 @@ void QComLibrary::createInstanceInternal() | |||
390 | QCString key; | 394 | QCString key; |
391 | bool query_done = FALSE; | 395 | bool query_done = FALSE; |
392 | bool warn_mismatch = TRUE; | 396 | bool warn_mismatch = TRUE; |
393 | 397 | ||
394 | if ( ! query_done ) { | ||
395 | |||
396 | #ifdef QT_THREAD_SUPPORT | 398 | #ifdef QT_THREAD_SUPPORT |
397 | QMutexLocker locker( qt_global_mutexpool->get( &cache ) ); | 399 | QMutexLocker locker( qt_global_mutexpool ? |
400 | qt_global_mutexpool->get( &cache ) : 0 ); | ||
398 | #endif // QT_THREAD_SUPPORT | 401 | #endif // QT_THREAD_SUPPORT |
399 | 402 | ||
400 | if ( ! cache ) { | 403 | if ( ! cache ) { |
401 | cache = new QSettings; | 404 | cache = new QSettings; |
@@ -414,9 +417,8 @@ void QComLibrary::createInstanceInternal() | |||
414 | query_done = TRUE; | 417 | query_done = TRUE; |
415 | warn_mismatch = FALSE; | 418 | warn_mismatch = FALSE; |
416 | } | 419 | } |
417 | } | 420 | } |
418 | } | ||
419 | 421 | ||
420 | #if defined(Q_OS_UNIX) | 422 | #if defined(Q_OS_UNIX) |
421 | if ( ! query_done ) { | 423 | if ( ! query_done ) { |
422 | // get the query information directly from the plugin without loading | 424 | // get the query information directly from the plugin without loading |
@@ -460,13 +462,8 @@ void QComLibrary::createInstanceInternal() | |||
460 | << key | 462 | << key |
461 | << lastModified; | 463 | << lastModified; |
462 | 464 | ||
463 | if ( queried != reg ) { | 465 | if ( queried != reg ) { |
464 | |||
465 | #ifdef QT_THREAD_SUPPORT | ||
466 | QMutexLocker locker( qt_global_mutexpool->get( &cache ) ); | ||
467 | #endif // QT_THREAD_SUPPORT | ||
468 | |||
469 | cache->writeEntry( regkey, queried ); | 466 | cache->writeEntry( regkey, queried ); |
470 | // delete the cache, which forces the settings to be written | 467 | // delete the cache, which forces the settings to be written |
471 | delete cache; | 468 | delete cache; |
472 | cache = 0; | 469 | cache = 0; |
diff --git a/qmake/tools/qconfig.cpp b/qmake/tools/qconfig.cpp index 433827c..5297a4e 100644 --- a/qmake/tools/qconfig.cpp +++ b/qmake/tools/qconfig.cpp | |||
@@ -1,13 +1,13 @@ | |||
1 | /* Install paths from configure */ | 1 | /* Install paths from configure */ |
2 | 2 | ||
3 | static const char QT_INSTALL_PREFIX [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2"; | 3 | static const char QT_INSTALL_PREFIX [256] = "/opt/qt-x11-free-3.1.2"; |
4 | static const char QT_INSTALL_BINS [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/bin"; | 4 | static const char QT_INSTALL_BINS [256] = "/opt/qt-x11-free-3.1.2/bin"; |
5 | static const char QT_INSTALL_DOCS [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/doc"; | 5 | static const char QT_INSTALL_DOCS [256] = "/opt/qt-x11-free-3.1.2/doc"; |
6 | static const char QT_INSTALL_HEADERS[256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/include"; | 6 | static const char QT_INSTALL_HEADERS[256] = "/opt/qt-x11-free-3.1.2/include"; |
7 | static const char QT_INSTALL_LIBS [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/lib"; | 7 | static const char QT_INSTALL_LIBS [256] = "/opt/qt-x11-free-3.1.2/lib"; |
8 | static const char QT_INSTALL_PLUGINS[256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/plugins"; | 8 | static const char QT_INSTALL_PLUGINS[256] = "/opt/qt-x11-free-3.1.2/plugins"; |
9 | static const char QT_INSTALL_DATA [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2"; | 9 | static const char QT_INSTALL_DATA [256] = "/opt/qt-x11-free-3.1.2"; |
10 | 10 | ||
11 | const char *qInstallPath() { return QT_INSTALL_PREFIX; } | 11 | const char *qInstallPath() { return QT_INSTALL_PREFIX; } |
12 | const char *qInstallPathDocs() { return QT_INSTALL_DOCS; } | 12 | const char *qInstallPathDocs() { return QT_INSTALL_DOCS; } |
13 | const char *qInstallPathHeaders() { return QT_INSTALL_HEADERS; } | 13 | const char *qInstallPathHeaders() { return QT_INSTALL_HEADERS; } |
diff --git a/qmake/tools/qcriticalsection_p.cpp b/qmake/tools/qcriticalsection_p.cpp index 60fc8bd..c375730 100644 --- a/qmake/tools/qcriticalsection_p.cpp +++ b/qmake/tools/qcriticalsection_p.cpp | |||
@@ -2,10 +2,8 @@ | |||
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of QCriticalSection class | 4 | ** Implementation of QCriticalSection class |
5 | ** | 5 | ** |
6 | ** Created : | ||
7 | ** | ||
8 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. | 6 | ** Copyright (C) 2001 Trolltech AS. All rights reserved. |
9 | ** | 7 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 8 | ** This file is part of the tools module of the Qt GUI Toolkit. |
11 | ** | 9 | ** |
diff --git a/qmake/tools/qcstring.cpp b/qmake/tools/qcstring.cpp index cf1b853..4651b97 100644 --- a/qmake/tools/qcstring.cpp +++ b/qmake/tools/qcstring.cpp | |||
@@ -140,8 +140,19 @@ char *qstrncpy( char *dst, const char *src, uint len ) | |||
140 | return dst; | 140 | return dst; |
141 | } | 141 | } |
142 | 142 | ||
143 | /*! | 143 | /*! |
144 | \fn uint qstrlen( const char *str ); | ||
145 | |||
146 | \relates QCString | ||
147 | |||
148 | A safe strlen function. | ||
149 | |||
150 | Returns the number of characters that precede the terminating '\0'. | ||
151 | or 0 if \a str is 0. | ||
152 | */ | ||
153 | |||
154 | /*! | ||
144 | \fn int qstrcmp( const char *str1, const char *str2 ); | 155 | \fn int qstrcmp( const char *str1, const char *str2 ); |
145 | 156 | ||
146 | \relates QCString | 157 | \relates QCString |
147 | 158 | ||
@@ -298,9 +309,10 @@ Q_UINT16 qChecksum( const char *data, uint len ) | |||
298 | { | 309 | { |
299 | if ( !crc_tbl_init ) { // create lookup table | 310 | if ( !crc_tbl_init ) { // create lookup table |
300 | 311 | ||
301 | #ifdef QT_THREAD_SUPPORT | 312 | #ifdef QT_THREAD_SUPPORT |
302 | QMutexLocker locker( qt_global_mutexpool->get( &crc_tbl_init ) ); | 313 | QMutexLocker locker( qt_global_mutexpool ? |
314 | qt_global_mutexpool->get( &crc_tbl_init ) : 0 ); | ||
303 | #endif // QT_THREAD_SUPPORT | 315 | #endif // QT_THREAD_SUPPORT |
304 | 316 | ||
305 | if ( !crc_tbl_init ) { | 317 | if ( !crc_tbl_init ) { |
306 | createCRC16Table(); | 318 | createCRC16Table(); |
@@ -318,20 +330,26 @@ Q_UINT16 qChecksum( const char *data, uint len ) | |||
318 | } | 330 | } |
319 | return ~crc & 0xffff; | 331 | return ~crc & 0xffff; |
320 | } | 332 | } |
321 | 333 | ||
322 | /*! \fn QByteArray qCompress( const QByteArray& data) | 334 | /*! |
335 | \fn QByteArray qCompress( const QByteArray& data ) | ||
336 | |||
323 | \relates QByteArray | 337 | \relates QByteArray |
324 | \overload | 338 | |
339 | Compresses the array \a data and returns the compressed byte | ||
340 | array. | ||
341 | |||
342 | \sa qUncompress() | ||
325 | */ | 343 | */ |
326 | 344 | ||
327 | /*! | 345 | /*! |
328 | \relates QByteArray | 346 | \relates QByteArray |
329 | 347 | ||
348 | \overload | ||
349 | |||
330 | Compresses the array \a data which is \a nbytes long and returns the | 350 | Compresses the array \a data which is \a nbytes long and returns the |
331 | compressed byte array. | 351 | compressed byte array. |
332 | |||
333 | \sa qUncompress() | ||
334 | */ | 352 | */ |
335 | 353 | ||
336 | #ifndef QT_NO_COMPRESS | 354 | #ifndef QT_NO_COMPRESS |
337 | QByteArray qCompress( const uchar* data, int nbytes ) | 355 | QByteArray qCompress( const uchar* data, int nbytes ) |
@@ -378,22 +396,34 @@ QByteArray qCompress( const uchar* data, int nbytes ) | |||
378 | return bazip; | 396 | return bazip; |
379 | } | 397 | } |
380 | #endif | 398 | #endif |
381 | 399 | ||
382 | /*! \fn QByteArray qUncompress( const QByteArray& data ) | 400 | /*! |
401 | \fn QByteArray qUncompress( const QByteArray& data ) | ||
402 | |||
383 | \relates QByteArray | 403 | \relates QByteArray |
384 | \overload | 404 | |
405 | Uncompresses the array \a data and returns the uncompressed byte | ||
406 | array. | ||
407 | |||
408 | Returns an empty QByteArray if the input data was corrupt. | ||
409 | \omit | ||
410 | ADD THE FOLLOWING FOR Qt 4.0 | ||
411 | This function will uncompress data compressed with qCompress() | ||
412 | from this and any earlier Qt version, back to Qt 3.1 when this | ||
413 | feature was added. | ||
414 | \endomit | ||
415 | |||
416 | \sa qCompress() | ||
385 | */ | 417 | */ |
386 | 418 | ||
387 | /*! | 419 | /*! |
388 | \relates QByteArray | 420 | \relates QByteArray |
389 | 421 | ||
422 | \overload | ||
423 | |||
390 | Uncompresses the array \a data which is \a nbytes long and returns | 424 | Uncompresses the array \a data which is \a nbytes long and returns |
391 | the uncompressed byte array. | 425 | the uncompressed byte array. |
392 | |||
393 | Returns an empty QByteArray if the input data was corrupt. | ||
394 | |||
395 | \sa qCompress() | ||
396 | */ | 426 | */ |
397 | 427 | ||
398 | #ifndef QT_NO_COMPRESS | 428 | #ifndef QT_NO_COMPRESS |
399 | QByteArray qUncompress( const uchar* data, int nbytes ) | 429 | QByteArray qUncompress( const uchar* data, int nbytes ) |
@@ -935,15 +965,19 @@ int QCString::find( char c, int index, bool cs ) const | |||
935 | */ | 965 | */ |
936 | 966 | ||
937 | int QCString::find( const char *str, int index, bool cs ) const | 967 | int QCString::find( const char *str, int index, bool cs ) const |
938 | { | 968 | { |
969 | return find( str, index, cs, length() ); | ||
970 | } | ||
971 | |||
972 | int QCString::find( const char *str, int index, bool cs, uint l ) const | ||
973 | { | ||
939 | if ( (uint)index >= size() ) | 974 | if ( (uint)index >= size() ) |
940 | return -1; | 975 | return -1; |
941 | if ( !str ) | 976 | if ( !str ) |
942 | return -1; | 977 | return -1; |
943 | if ( !*str ) | 978 | if ( !*str ) |
944 | return index; | 979 | return index; |
945 | const uint l = length(); | ||
946 | const uint sl = qstrlen( str ); | 980 | const uint sl = qstrlen( str ); |
947 | if ( sl + index > l ) | 981 | if ( sl + index > l ) |
948 | return -1; | 982 | return -1; |
949 | 983 | ||
@@ -1151,10 +1185,11 @@ int QCString::contains( char c, bool cs ) const | |||
1151 | int QCString::contains( const char *str, bool cs ) const | 1185 | int QCString::contains( const char *str, bool cs ) const |
1152 | { | 1186 | { |
1153 | int count = 0; | 1187 | int count = 0; |
1154 | int i = -1; | 1188 | int i = -1; |
1189 | uint l = length(); | ||
1155 | // use find for the faster hashing algorithm | 1190 | // use find for the faster hashing algorithm |
1156 | while ( ( i = find ( str, i+1, cs ) ) != -1 ) | 1191 | while ( ( i = find ( str, i+1, cs, l ) ) != -1 ) |
1157 | count++; | 1192 | count++; |
1158 | return count; | 1193 | return count; |
1159 | } | 1194 | } |
1160 | 1195 | ||
@@ -1172,9 +1207,8 @@ int QCString::contains( const char *str, bool cs ) const | |||
1172 | \endcode | 1207 | \endcode |
1173 | 1208 | ||
1174 | \sa right(), mid() | 1209 | \sa right(), mid() |
1175 | */ | 1210 | */ |
1176 | |||
1177 | QCString QCString::left( uint len ) const | 1211 | QCString QCString::left( uint len ) const |
1178 | { | 1212 | { |
1179 | if ( isEmpty() ) { | 1213 | if ( isEmpty() ) { |
1180 | QCString empty; | 1214 | QCString empty; |
@@ -1496,17 +1530,19 @@ QCString &QCString::insert( uint index, const char *s ) | |||
1496 | uint olen = length(); | 1530 | uint olen = length(); |
1497 | int nlen = olen + len; | 1531 | int nlen = olen + len; |
1498 | if ( index >= olen ) { // insert after end of string | 1532 | if ( index >= olen ) { // insert after end of string |
1499 | detach(); | 1533 | detach(); |
1500 | if ( QByteArray::resize(nlen+index-olen+1) ) { | 1534 | if ( QByteArray::resize(nlen+index-olen+1, QByteArray::SpeedOptim ) ) { |
1501 | memset( data()+olen, ' ', index-olen ); | 1535 | memset( data()+olen, ' ', index-olen ); |
1502 | memcpy( data()+index, s, len+1 ); | 1536 | memcpy( data()+index, s, len+1 ); |
1503 | } | 1537 | } |
1504 | } else if ( QByteArray::resize(nlen+1) ) {// normal insert | 1538 | } else { |
1505 | detach(); | 1539 | detach(); |
1540 | if ( QByteArray::resize(nlen+1, QByteArray::SpeedOptim ) ) {// normal insert | ||
1506 | memmove( data()+index+len, data()+index, olen-index+1 ); | 1541 | memmove( data()+index+len, data()+index, olen-index+1 ); |
1507 | memcpy( data()+index, s, len ); | 1542 | memcpy( data()+index, s, len ); |
1508 | } | 1543 | } |
1544 | } | ||
1509 | return *this; | 1545 | return *this; |
1510 | } | 1546 | } |
1511 | 1547 | ||
1512 | /*! | 1548 | /*! |
@@ -1568,9 +1604,9 @@ QCString &QCString::remove( uint index, uint len ) | |||
1568 | } | 1604 | } |
1569 | } else if ( len != 0 ) { | 1605 | } else if ( len != 0 ) { |
1570 | detach(); | 1606 | detach(); |
1571 | memmove( data()+index, data()+index+len, olen-index-len+1 ); | 1607 | memmove( data()+index, data()+index+len, olen-index-len+1 ); |
1572 | QByteArray::resize(olen-len+1); | 1608 | QByteArray::resize(olen-len+1, QByteArray::SpeedOptim ); |
1573 | } | 1609 | } |
1574 | return *this; | 1610 | return *this; |
1575 | } | 1611 | } |
1576 | 1612 | ||
@@ -1630,8 +1666,9 @@ QCString &QCString::replace( char c, const char *after ) | |||
1630 | s.replace( "Greek", "English" ); | 1666 | s.replace( "Greek", "English" ); |
1631 | // s == "English is English" | 1667 | // s == "English is English" |
1632 | \endcode | 1668 | \endcode |
1633 | */ | 1669 | */ |
1670 | |||
1634 | QCString &QCString::replace( const char *before, const char *after ) | 1671 | QCString &QCString::replace( const char *before, const char *after ) |
1635 | { | 1672 | { |
1636 | if ( before == after || isNull() ) | 1673 | if ( before == after || isNull() ) |
1637 | return *this; | 1674 | return *this; |
@@ -1645,18 +1682,18 @@ QCString &QCString::replace( const char *before, const char *after ) | |||
1645 | uint len = length(); | 1682 | uint len = length(); |
1646 | 1683 | ||
1647 | if ( bl == al ) { | 1684 | if ( bl == al ) { |
1648 | if ( bl ) { | 1685 | if ( bl ) { |
1649 | while( (index = find( before, index ) ) != -1 ) { | 1686 | while( (index = find( before, index, TRUE, len ) ) != -1 ) { |
1650 | memcpy( d+index, after, al ); | 1687 | memcpy( d+index, after, al ); |
1651 | index += bl; | 1688 | index += bl; |
1652 | } | 1689 | } |
1653 | } | 1690 | } |
1654 | } else if ( al < bl ) { | 1691 | } else if ( al < bl ) { |
1655 | uint to = 0; | 1692 | uint to = 0; |
1656 | uint movestart = 0; | 1693 | uint movestart = 0; |
1657 | uint num = 0; | 1694 | uint num = 0; |
1658 | while( (index = find( before, index ) ) != -1 ) { | 1695 | while( (index = find( before, index, TRUE, len ) ) != -1 ) { |
1659 | if ( num ) { | 1696 | if ( num ) { |
1660 | int msize = index - movestart; | 1697 | int msize = index - movestart; |
1661 | if ( msize > 0 ) { | 1698 | if ( msize > 0 ) { |
1662 | memmove( d + to, d + movestart, msize ); | 1699 | memmove( d + to, d + movestart, msize ); |
@@ -1685,9 +1722,9 @@ QCString &QCString::replace( const char *before, const char *after ) | |||
1685 | while( index != -1 ) { | 1722 | while( index != -1 ) { |
1686 | uint indices[4096]; | 1723 | uint indices[4096]; |
1687 | uint pos = 0; | 1724 | uint pos = 0; |
1688 | while( pos < 4095 ) { | 1725 | while( pos < 4095 ) { |
1689 | index = find(before, index); | 1726 | index = find(before, index, TRUE, len); |
1690 | if ( index == -1 ) | 1727 | if ( index == -1 ) |
1691 | break; | 1728 | break; |
1692 | indices[pos++] = index; | 1729 | indices[pos++] = index; |
1693 | index += bl; | 1730 | index += bl; |
@@ -1762,9 +1799,9 @@ QCString &QCString::replace( char c1, char c2 ) | |||
1762 | */ | 1799 | */ |
1763 | 1800 | ||
1764 | int QCString::find( const QRegExp& rx, int index ) const | 1801 | int QCString::find( const QRegExp& rx, int index ) const |
1765 | { | 1802 | { |
1766 | QString d = QString::fromLatin1( data() ); | 1803 | QString d = QString::fromAscii( data() ); |
1767 | return d.find( rx, index ); | 1804 | return d.find( rx, index ); |
1768 | } | 1805 | } |
1769 | 1806 | ||
1770 | /*! | 1807 | /*! |
@@ -1782,9 +1819,9 @@ int QCString::find( const QRegExp& rx, int index ) const | |||
1782 | */ | 1819 | */ |
1783 | 1820 | ||
1784 | int QCString::findRev( const QRegExp& rx, int index ) const | 1821 | int QCString::findRev( const QRegExp& rx, int index ) const |
1785 | { | 1822 | { |
1786 | QString d = QString::fromLatin1( data() ); | 1823 | QString d = QString::fromAscii( data() ); |
1787 | return d.findRev( rx, index ); | 1824 | return d.findRev( rx, index ); |
1788 | } | 1825 | } |
1789 | 1826 | ||
1790 | /*! | 1827 | /*! |
@@ -1807,9 +1844,9 @@ int QCString::findRev( const QRegExp& rx, int index ) const | |||
1807 | */ | 1844 | */ |
1808 | 1845 | ||
1809 | int QCString::contains( const QRegExp &rx ) const | 1846 | int QCString::contains( const QRegExp &rx ) const |
1810 | { | 1847 | { |
1811 | QString d = QString::fromLatin1( data() ); | 1848 | QString d = QString::fromAscii( data() ); |
1812 | return d.contains( rx ); | 1849 | return d.contains( rx ); |
1813 | } | 1850 | } |
1814 | 1851 | ||
1815 | 1852 | ||
@@ -1837,10 +1874,10 @@ int QCString::contains( const QRegExp &rx ) const | |||
1837 | */ | 1874 | */ |
1838 | 1875 | ||
1839 | QCString &QCString::replace( const QRegExp &rx, const char *str ) | 1876 | QCString &QCString::replace( const QRegExp &rx, const char *str ) |
1840 | { | 1877 | { |
1841 | QString d = QString::fromLatin1( data() ); | 1878 | QString d = QString::fromAscii( data() ); |
1842 | QString r = QString::fromLatin1( str ); | 1879 | QString r = QString::fromAscii( str ); |
1843 | d.replace( rx, r ); | 1880 | d.replace( rx, r ); |
1844 | setStr( d.ascii() ); | 1881 | setStr( d.ascii() ); |
1845 | return *this; | 1882 | return *this; |
1846 | } | 1883 | } |
@@ -2198,9 +2235,9 @@ QCString& QCString::operator+=( const char *str ) | |||
2198 | return *this; // nothing to append | 2235 | return *this; // nothing to append |
2199 | detach(); | 2236 | detach(); |
2200 | uint len1 = length(); | 2237 | uint len1 = length(); |
2201 | uint len2 = qstrlen(str); | 2238 | uint len2 = qstrlen(str); |
2202 | if ( !QByteArray::resize( len1 + len2 + 1 ) ) | 2239 | if ( !QByteArray::resize( len1 + len2 + 1, QByteArray::SpeedOptim ) ) |
2203 | return *this; // no memory | 2240 | return *this; // no memory |
2204 | memcpy( data() + len1, str, len2 + 1 ); | 2241 | memcpy( data() + len1, str, len2 + 1 ); |
2205 | return *this; | 2242 | return *this; |
2206 | } | 2243 | } |
@@ -2214,9 +2251,9 @@ QCString& QCString::operator+=( const char *str ) | |||
2214 | QCString &QCString::operator+=( char c ) | 2251 | QCString &QCString::operator+=( char c ) |
2215 | { | 2252 | { |
2216 | detach(); | 2253 | detach(); |
2217 | uint len = length(); | 2254 | uint len = length(); |
2218 | if ( !QByteArray::resize( len + 2 ) ) | 2255 | if ( !QByteArray::resize( len + 2, QByteArray::SpeedOptim ) ) |
2219 | return *this; // no memory | 2256 | return *this; // no memory |
2220 | *(data() + len) = c; | 2257 | *(data() + len) = c; |
2221 | *(data() + len+1) = '\0'; | 2258 | *(data() + len+1) = '\0'; |
2222 | return *this; | 2259 | return *this; |
diff --git a/qmake/tools/qdatastream.cpp b/qmake/tools/qdatastream.cpp index 9c573c7..51a1448 100644 --- a/qmake/tools/qdatastream.cpp +++ b/qmake/tools/qdatastream.cpp | |||
@@ -749,10 +749,18 @@ QDataStream &QDataStream::readRawBytes( char *s, uint len ) | |||
749 | { | 749 | { |
750 | CHECK_STREAM_PRECOND | 750 | CHECK_STREAM_PRECOND |
751 | if ( printable ) { // printable data | 751 | if ( printable ) { // printable data |
752 | register Q_INT8 *p = (Q_INT8*)s; | 752 | register Q_INT8 *p = (Q_INT8*)s; |
753 | if ( version() < 4 ) { | ||
754 | while ( len-- ) { | ||
755 | Q_INT32 tmp; | ||
756 | *this >> tmp; | ||
757 | *p++ = tmp; | ||
758 | } | ||
759 | } else { | ||
753 | while ( len-- ) | 760 | while ( len-- ) |
754 | *this >> *p++; | 761 | *this >> *p++; |
762 | } | ||
755 | } else { // read data char array | 763 | } else { // read data char array |
756 | dev->readBlock( s, len ); | 764 | dev->readBlock( s, len ); |
757 | } | 765 | } |
758 | return *this; | 766 | return *this; |
@@ -1011,11 +1019,17 @@ QDataStream &QDataStream::writeBytes(const char *s, uint len) | |||
1011 | QDataStream &QDataStream::writeRawBytes( const char *s, uint len ) | 1019 | QDataStream &QDataStream::writeRawBytes( const char *s, uint len ) |
1012 | { | 1020 | { |
1013 | CHECK_STREAM_PRECOND | 1021 | CHECK_STREAM_PRECOND |
1014 | if ( printable ) { // write printable | 1022 | if ( printable ) { // write printable |
1023 | if ( version() < 4 ) { | ||
1024 | register char *p = (char *)s; | ||
1025 | while ( len-- ) | ||
1026 | *this << *p++; | ||
1027 | } else { | ||
1015 | register Q_INT8 *p = (Q_INT8*)s; | 1028 | register Q_INT8 *p = (Q_INT8*)s; |
1016 | while ( len-- ) | 1029 | while ( len-- ) |
1017 | *this << *p++; | 1030 | *this << *p++; |
1031 | } | ||
1018 | } else { // write data char array | 1032 | } else { // write data char array |
1019 | dev->writeBlock( s, len ); | 1033 | dev->writeBlock( s, len ); |
1020 | } | 1034 | } |
1021 | return *this; | 1035 | return *this; |
diff --git a/qmake/tools/qdatetime.cpp b/qmake/tools/qdatetime.cpp index 93e40a8..3137877 100644 --- a/qmake/tools/qdatetime.cpp +++ b/qmake/tools/qdatetime.cpp | |||
@@ -4,9 +4,9 @@ | |||
4 | ** Implementation of date and time classes | 4 | ** Implementation of date and time classes |
5 | ** | 5 | ** |
6 | ** Created : 940124 | 6 | ** Created : 940124 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
@@ -34,9 +34,8 @@ | |||
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | // Get the system specific includes and defines | ||
39 | #include "qplatformdefs.h" | 38 | #include "qplatformdefs.h" |
40 | 39 | ||
41 | #include "qdatetime.h" | 40 | #include "qdatetime.h" |
42 | #include "qdatastream.h" | 41 | #include "qdatastream.h" |
@@ -894,8 +893,14 @@ QDate QDate::addYears( int nyears ) const | |||
894 | { | 893 | { |
895 | int y, m, d; | 894 | int y, m, d; |
896 | julianToGregorian( jd, y, m, d ); | 895 | julianToGregorian( jd, y, m, d ); |
897 | y += nyears; | 896 | y += nyears; |
897 | |||
898 | QDate tmp(y,m,1); | ||
899 | |||
900 | if( d > tmp.daysInMonth() ) | ||
901 | d = tmp.daysInMonth(); | ||
902 | |||
898 | QDate date(y, m, d); | 903 | QDate date(y, m, d); |
899 | return date; | 904 | return date; |
900 | } | 905 | } |
901 | 906 | ||
@@ -989,15 +994,27 @@ QDate QDate::currentDate( Qt::TimeSpec ts ) | |||
989 | else | 994 | else |
990 | GetSystemTime( &t ); | 995 | GetSystemTime( &t ); |
991 | d.jd = gregorianToJulian( t.wYear, t.wMonth, t.wDay ); | 996 | d.jd = gregorianToJulian( t.wYear, t.wMonth, t.wDay ); |
992 | #else | 997 | #else |
998 | // posix compliant system | ||
993 | time_t ltime; | 999 | time_t ltime; |
994 | time( <ime ); | 1000 | time( <ime ); |
995 | tm *t; | 1001 | tm *t; |
1002 | |||
1003 | # if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) | ||
1004 | // use the reentrant versions of localtime() and gmtime() where available | ||
1005 | tm res; | ||
1006 | if ( ts == Qt::LocalTime ) | ||
1007 | t = localtime_r( <ime, &res ); | ||
1008 | else | ||
1009 | t = gmtime_r( <ime, &res ); | ||
1010 | # else | ||
996 | if ( ts == Qt::LocalTime ) | 1011 | if ( ts == Qt::LocalTime ) |
997 | t = localtime( <ime ); | 1012 | t = localtime( <ime ); |
998 | else | 1013 | else |
999 | t = gmtime( <ime ); | 1014 | t = gmtime( <ime ); |
1015 | # endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS | ||
1016 | |||
1000 | d.jd = gregorianToJulian( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday ); | 1017 | d.jd = gregorianToJulian( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday ); |
1001 | #endif | 1018 | #endif |
1002 | return d; | 1019 | return d; |
1003 | } | 1020 | } |
@@ -1652,17 +1669,28 @@ bool QTime::currentTime( QTime *ct, Qt::TimeSpec ts ) | |||
1652 | } | 1669 | } |
1653 | ct->ds = (uint)( MSECS_PER_HOUR*t.wHour + MSECS_PER_MIN*t.wMinute + | 1670 | ct->ds = (uint)( MSECS_PER_HOUR*t.wHour + MSECS_PER_MIN*t.wMinute + |
1654 | 1000*t.wSecond + t.wMilliseconds ); | 1671 | 1000*t.wSecond + t.wMilliseconds ); |
1655 | #elif defined(Q_OS_UNIX) | 1672 | #elif defined(Q_OS_UNIX) |
1673 | // posix compliant system | ||
1656 | struct timeval tv; | 1674 | struct timeval tv; |
1657 | gettimeofday( &tv, 0 ); | 1675 | gettimeofday( &tv, 0 ); |
1658 | time_t ltime = tv.tv_sec; | 1676 | time_t ltime = tv.tv_sec; |
1659 | tm *t; | 1677 | tm *t; |
1660 | if ( ts == Qt::LocalTime ) { | 1678 | |
1679 | # if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) | ||
1680 | // use the reentrant versions of localtime() and gmtime() where available | ||
1681 | tm res; | ||
1682 | if ( ts == Qt::LocalTime ) | ||
1683 | t = localtime_r( <ime, &res ); | ||
1684 | else | ||
1685 | t = gmtime_r( <ime, &res ); | ||
1686 | # else | ||
1687 | if ( ts == Qt::LocalTime ) | ||
1661 | t = localtime( <ime ); | 1688 | t = localtime( <ime ); |
1662 | } else { | 1689 | else |
1663 | t = gmtime( <ime ); | 1690 | t = gmtime( <ime ); |
1664 | } | 1691 | # endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS |
1692 | |||
1665 | ct->ds = (uint)( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + | 1693 | ct->ds = (uint)( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min + |
1666 | 1000 * t->tm_sec + tv.tv_usec / 1000 ); | 1694 | 1000 * t->tm_sec + tv.tv_usec / 1000 ); |
1667 | #else | 1695 | #else |
1668 | time_t ltime; // no millisecond resolution | 1696 | time_t ltime; // no millisecond resolution |
@@ -1705,11 +1733,11 @@ bool QTime::isValid( int h, int m, int s, int ms ) | |||
1705 | Sets this time to the current time. This is practical for timing: | 1733 | Sets this time to the current time. This is practical for timing: |
1706 | 1734 | ||
1707 | \code | 1735 | \code |
1708 | QTime t; | 1736 | QTime t; |
1709 | t.start(); // start clock | 1737 | t.start(); |
1710 | ... // some lengthy task | 1738 | some_lengthy_task(); |
1711 | qDebug( "%d\n", t.elapsed() ); // prints the number of msecs elapsed | 1739 | qDebug( "Time elapsed: %d ms", t.elapsed() ); |
1712 | \endcode | 1740 | \endcode |
1713 | 1741 | ||
1714 | \sa restart(), elapsed(), currentTime() | 1742 | \sa restart(), elapsed(), currentTime() |
1715 | */ | 1743 | */ |
@@ -1959,8 +1987,24 @@ void QDateTime::setTime_t( uint secsSince1Jan1970UTC ) | |||
1959 | void QDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts ) | 1987 | void QDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts ) |
1960 | { | 1988 | { |
1961 | time_t tmp = (time_t) secsSince1Jan1970UTC; | 1989 | time_t tmp = (time_t) secsSince1Jan1970UTC; |
1962 | tm *brokenDown = 0; | 1990 | tm *brokenDown = 0; |
1991 | |||
1992 | #if defined(Q_OS_UNIX) && defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) | ||
1993 | // posix compliant system | ||
1994 | // use the reentrant versions of localtime() and gmtime() where available | ||
1995 | tm res; | ||
1996 | if ( ts == Qt::LocalTime ) | ||
1997 | brokenDown = localtime_r( &tmp, &res ); | ||
1998 | if ( !brokenDown ) { | ||
1999 | brokenDown = gmtime_r( &tmp, &res ); | ||
2000 | if ( !brokenDown ) { | ||
2001 | d.jd = QDate::gregorianToJulian( 1970, 1, 1 ); | ||
2002 | t.ds = 0; | ||
2003 | return; | ||
2004 | } | ||
2005 | } | ||
2006 | #else | ||
1963 | if ( ts == Qt::LocalTime ) | 2007 | if ( ts == Qt::LocalTime ) |
1964 | brokenDown = localtime( &tmp ); | 2008 | brokenDown = localtime( &tmp ); |
1965 | if ( !brokenDown ) { | 2009 | if ( !brokenDown ) { |
1966 | brokenDown = gmtime( &tmp ); | 2010 | brokenDown = gmtime( &tmp ); |
@@ -1969,8 +2013,10 @@ void QDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts ) | |||
1969 | t.ds = 0; | 2013 | t.ds = 0; |
1970 | return; | 2014 | return; |
1971 | } | 2015 | } |
1972 | } | 2016 | } |
2017 | #endif | ||
2018 | |||
1973 | d.jd = QDate::gregorianToJulian( brokenDown->tm_year + 1900, | 2019 | d.jd = QDate::gregorianToJulian( brokenDown->tm_year + 1900, |
1974 | brokenDown->tm_mon + 1, | 2020 | brokenDown->tm_mon + 1, |
1975 | brokenDown->tm_mday ); | 2021 | brokenDown->tm_mday ); |
1976 | t.ds = MSECS_PER_HOUR * brokenDown->tm_hour + | 2022 | t.ds = MSECS_PER_HOUR * brokenDown->tm_hour + |
diff --git a/qmake/tools/qdir.cpp b/qmake/tools/qdir.cpp index 418ea49..5714878 100644 --- a/qmake/tools/qdir.cpp +++ b/qmake/tools/qdir.cpp | |||
@@ -4,9 +4,9 @@ | |||
4 | ** Implementation of QDir class | 4 | ** Implementation of QDir class |
5 | ** | 5 | ** |
6 | ** Created : 950427 | 6 | ** Created : 950427 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
@@ -42,15 +42,20 @@ | |||
42 | #include <private/qdir_p.h> | 42 | #include <private/qdir_p.h> |
43 | #include "qfileinfo.h" | 43 | #include "qfileinfo.h" |
44 | #include "qregexp.h" | 44 | #include "qregexp.h" |
45 | #include "qstringlist.h" | 45 | #include "qstringlist.h" |
46 | #include <stdlib.h> | 46 | #include <limits.h> |
47 | #include <ctype.h> | ||
48 | 47 | ||
48 | #if defined(Q_FS_FAT) && !defined(Q_OS_UNIX) | ||
49 | const bool CaseSensitiveFS = FALSE; | ||
50 | #else | ||
51 | const bool CaseSensitiveFS = TRUE; | ||
52 | #endif | ||
49 | 53 | ||
50 | 54 | ||
51 | /*! | 55 | /*! |
52 | \class QDir | 56 | \class QDir |
57 | \reentrant | ||
53 | \brief The QDir class provides access to directory structures and their contents in a platform-independent way. | 58 | \brief The QDir class provides access to directory structures and their contents in a platform-independent way. |
54 | 59 | ||
55 | \ingroup io | 60 | \ingroup io |
56 | \mainclass | 61 | \mainclass |
@@ -229,8 +234,16 @@ QDir::QDir( const QDir &d ) | |||
229 | filtS = d.filtS; | 234 | filtS = d.filtS; |
230 | sortS = d.sortS; | 235 | sortS = d.sortS; |
231 | } | 236 | } |
232 | 237 | ||
238 | /*! | ||
239 | Refreshes the directory information. | ||
240 | */ | ||
241 | void QDir::refresh() const | ||
242 | { | ||
243 | QDir* that = (QDir*) this; | ||
244 | that->dirty = TRUE; | ||
245 | } | ||
233 | 246 | ||
234 | void QDir::init() | 247 | void QDir::init() |
235 | { | 248 | { |
236 | fList = 0; | 249 | fList = 0; |
@@ -381,12 +394,38 @@ QString QDir::absFilePath( const QString &fileName, | |||
381 | if ( acceptAbsPath && !isRelativePath( fileName ) ) | 394 | if ( acceptAbsPath && !isRelativePath( fileName ) ) |
382 | return fileName; | 395 | return fileName; |
383 | 396 | ||
384 | QString tmp = absPath(); | 397 | QString tmp = absPath(); |
398 | #ifdef Q_OS_WIN32 | ||
399 | if ( fileName[0].isLetter() && fileName[1] == ':' ) { | ||
400 | int drv = fileName.upper()[0].latin1() - 'A' + 1; | ||
401 | if ( _getdrive() != drv ) { | ||
402 | if ( qt_winunicode ) { | ||
403 | TCHAR buf[PATH_MAX]; | ||
404 | ::_tgetdcwd( drv, buf, PATH_MAX ); | ||
405 | tmp.setUnicodeCodes( (ushort*)buf, ::_tcslen(buf) ); | ||
406 | } else { | ||
407 | char buf[PATH_MAX]; | ||
408 | ::_getdcwd( drv, buf, PATH_MAX ); | ||
409 | tmp = buf; | ||
410 | } | ||
411 | if ( !tmp.endsWith("\\") ) | ||
412 | tmp += "\\"; | ||
413 | tmp += fileName.right( fileName.length() - 2 ); | ||
414 | int x; | ||
415 | for ( x = 0; x < (int) tmp.length(); x++ ) { | ||
416 | if ( tmp[x] == '\\' ) | ||
417 | tmp[x] = '/'; | ||
418 | } | ||
419 | } | ||
420 | } else | ||
421 | #endif | ||
422 | { | ||
385 | if ( tmp.isEmpty() || (tmp[(int)tmp.length()-1] != '/' && !!fileName && | 423 | if ( tmp.isEmpty() || (tmp[(int)tmp.length()-1] != '/' && !!fileName && |
386 | fileName[0] != '/') ) | 424 | fileName[0] != '/') ) |
387 | tmp += '/'; | 425 | tmp += '/'; |
388 | tmp += fileName; | 426 | tmp += fileName; |
427 | } | ||
389 | return tmp; | 428 | return tmp; |
390 | } | 429 | } |
391 | 430 | ||
392 | 431 | ||
@@ -933,9 +972,10 @@ QDir &QDir::operator=( const QString &path ) | |||
933 | \code | 972 | \code |
934 | // The current directory is "/usr/local" | 973 | // The current directory is "/usr/local" |
935 | QDir d1( "/usr/local/bin" ); | 974 | QDir d1( "/usr/local/bin" ); |
936 | QDir d2( "bin" ); | 975 | QDir d2( "bin" ); |
937 | if ( d1 != d2 ) qDebug( "They differ\n" ); // This is printed | 976 | if ( d1 != d2 ) |
977 | qDebug( "They differ" ); | ||
938 | \endcode | 978 | \endcode |
939 | */ | 979 | */ |
940 | 980 | ||
941 | /*! | 981 | /*! |
@@ -948,9 +988,10 @@ QDir &QDir::operator=( const QString &path ) | |||
948 | // The current directory is "/usr/local" | 988 | // The current directory is "/usr/local" |
949 | QDir d1( "/usr/local/bin" ); | 989 | QDir d1( "/usr/local/bin" ); |
950 | QDir d2( "bin" ); | 990 | QDir d2( "bin" ); |
951 | d2.convertToAbs(); | 991 | d2.convertToAbs(); |
952 | if ( d1 == d2 ) qDebug( "They're the same\n" ); // This is printed | 992 | if ( d1 == d2 ) |
993 | qDebug( "They're the same" ); | ||
953 | \endcode | 994 | \endcode |
954 | */ | 995 | */ |
955 | 996 | ||
956 | bool QDir::operator==( const QDir &d ) const | 997 | bool QDir::operator==( const QDir &d ) const |
@@ -1086,29 +1127,41 @@ QDir QDir::root() | |||
1086 | 1127 | ||
1087 | \sa home() | 1128 | \sa home() |
1088 | */ | 1129 | */ |
1089 | 1130 | ||
1090 | QStringList qt_makeFilterList( const QString &filter ) | 1131 | QValueList<QRegExp> qt_makeFilterList( const QString &filter ) |
1091 | { | 1132 | { |
1133 | QValueList<QRegExp> regExps; | ||
1092 | if ( filter.isEmpty() ) | 1134 | if ( filter.isEmpty() ) |
1093 | return QStringList(); | 1135 | return regExps; |
1094 | 1136 | ||
1095 | QChar sep( ';' ); | 1137 | QChar sep( ';' ); |
1096 | int i = filter.find( sep, 0 ); | 1138 | int i = filter.find( sep, 0 ); |
1097 | if ( i == -1 && filter.find( ' ', 0 ) != -1 ) | 1139 | if ( i == -1 && filter.find( ' ', 0 ) != -1 ) |
1098 | sep = QChar( ' ' ); | 1140 | sep = QChar( ' ' ); |
1099 | 1141 | ||
1100 | QStringList list = QStringList::split( sep, filter ); | 1142 | QStringList list = QStringList::split( sep, filter ); |
1101 | QStringList::Iterator it = list.begin(); | 1143 | QStringList::Iterator it = list.begin(); |
1102 | QStringList list2; | 1144 | while ( it != list.end() ) { |
1145 | regExps << QRegExp( (*it).stripWhiteSpace(), CaseSensitiveFS, TRUE ); | ||
1146 | ++it; | ||
1147 | } | ||
1148 | return regExps; | ||
1149 | } | ||
1103 | 1150 | ||
1104 | for ( ; it != list.end(); ++it ) { | 1151 | bool qt_matchFilterList( const QValueList<QRegExp>& filters, |
1105 | QString s = *it; | 1152 | const QString &fileName ) |
1106 | list2 << s.stripWhiteSpace(); | 1153 | { |
1154 | QValueList<QRegExp>::ConstIterator rit = filters.begin(); | ||
1155 | while ( rit != filters.end() ) { | ||
1156 | if ( (*rit).exactMatch(fileName) ) | ||
1157 | return TRUE; | ||
1158 | ++rit; | ||
1107 | } | 1159 | } |
1108 | return list2; | 1160 | return FALSE; |
1109 | } | 1161 | } |
1110 | 1162 | ||
1163 | |||
1111 | /*! | 1164 | /*! |
1112 | \overload | 1165 | \overload |
1113 | 1166 | ||
1114 | Returns TRUE if the \a fileName matches any of the wildcard (glob) | 1167 | Returns TRUE if the \a fileName matches any of the wildcard (glob) |
@@ -1122,13 +1175,9 @@ QStringList qt_makeFilterList( const QString &filter ) | |||
1122 | bool QDir::match( const QStringList &filters, const QString &fileName ) | 1175 | bool QDir::match( const QStringList &filters, const QString &fileName ) |
1123 | { | 1176 | { |
1124 | QStringList::ConstIterator sit = filters.begin(); | 1177 | QStringList::ConstIterator sit = filters.begin(); |
1125 | while ( sit != filters.end() ) { | 1178 | while ( sit != filters.end() ) { |
1126 | #if defined(Q_FS_FAT) && !defined(Q_OS_UNIX) | 1179 | QRegExp rx( *sit, CaseSensitiveFS, TRUE ); |
1127 | QRegExp rx( *sit, FALSE, TRUE ); // The FAT FS is not case sensitive.. | ||
1128 | #else | ||
1129 | QRegExp rx( *sit, TRUE, TRUE ); // ..while others are. | ||
1130 | #endif | ||
1131 | if ( rx.exactMatch(fileName) ) | 1180 | if ( rx.exactMatch(fileName) ) |
1132 | return TRUE; | 1181 | return TRUE; |
1133 | ++sit; | 1182 | ++sit; |
1134 | } | 1183 | } |
@@ -1146,10 +1195,9 @@ bool QDir::match( const QStringList &filters, const QString &fileName ) | |||
1146 | */ | 1195 | */ |
1147 | 1196 | ||
1148 | bool QDir::match( const QString &filter, const QString &fileName ) | 1197 | bool QDir::match( const QString &filter, const QString &fileName ) |
1149 | { | 1198 | { |
1150 | QStringList lst = qt_makeFilterList( filter ); | 1199 | return qt_matchFilterList( qt_makeFilterList(filter), fileName ); |
1151 | return match( lst, fileName ); | ||
1152 | } | 1200 | } |
1153 | 1201 | ||
1154 | 1202 | ||
1155 | /*! | 1203 | /*! |
diff --git a/qmake/tools/qdir_unix.cpp b/qmake/tools/qdir_unix.cpp index 57fe3c5..6a7adda 100644 --- a/qmake/tools/qdir_unix.cpp +++ b/qmake/tools/qdir_unix.cpp | |||
@@ -4,9 +4,9 @@ | |||
4 | ** Implementation of QDir class | 4 | ** Implementation of QDir class |
5 | ** | 5 | ** |
6 | ** Created : 950628 | 6 | ** Created : 950628 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2003 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
@@ -50,8 +50,9 @@ | |||
50 | #endif // QT_THREAD_SUPPORT | 50 | #endif // QT_THREAD_SUPPORT |
51 | 51 | ||
52 | #include <stdlib.h> | 52 | #include <stdlib.h> |
53 | #include <limits.h> | 53 | #include <limits.h> |
54 | #include <errno.h> | ||
54 | 55 | ||
55 | 56 | ||
56 | void QDir::slashify( QString& ) | 57 | void QDir::slashify( QString& ) |
57 | { | 58 | { |
@@ -69,19 +70,18 @@ QString QDir::homeDirPath() | |||
69 | 70 | ||
70 | QString QDir::canonicalPath() const | 71 | QString QDir::canonicalPath() const |
71 | { | 72 | { |
72 | QString r; | 73 | QString r; |
73 | |||
74 | char cur[PATH_MAX+1]; | 74 | char cur[PATH_MAX+1]; |
75 | if ( ::getcwd( cur, PATH_MAX ) ) | 75 | if ( ::getcwd( cur, PATH_MAX ) ) { |
76 | if ( ::chdir(QFile::encodeName(dPath)) >= 0 ) { | ||
77 | char tmp[PATH_MAX+1]; | 76 | char tmp[PATH_MAX+1]; |
78 | if ( ::getcwd( tmp, PATH_MAX ) ) | 77 | if( ::realpath( QFile::encodeName( dPath ), tmp ) ) |
79 | r = QFile::decodeName(tmp); | 78 | r = QFile::decodeName(tmp); |
79 | slashify( r ); | ||
80 | |||
81 | // always make sure we go back to the current dir | ||
80 | ::chdir( cur ); | 82 | ::chdir( cur ); |
81 | } | 83 | } |
82 | |||
83 | slashify( r ); | ||
84 | return r; | 84 | return r; |
85 | } | 85 | } |
86 | 86 | ||
87 | bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const | 87 | bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const |
@@ -89,14 +89,15 @@ bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const | |||
89 | #if defined(Q_OS_MACX) // Mac X doesn't support trailing /'s | 89 | #if defined(Q_OS_MACX) // Mac X doesn't support trailing /'s |
90 | QString name = dirName; | 90 | QString name = dirName; |
91 | if (dirName[dirName.length() - 1] == "/") | 91 | if (dirName[dirName.length() - 1] == "/") |
92 | name = dirName.left( dirName.length() - 1 ); | 92 | name = dirName.left( dirName.length() - 1 ); |
93 | return ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 ) | 93 | int status = |
94 | == 0; | 94 | ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 ); |
95 | #else | 95 | #else |
96 | return ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 ) | 96 | int status = |
97 | == 0; | 97 | ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 ); |
98 | #endif | 98 | #endif |
99 | return status == 0; | ||
99 | } | 100 | } |
100 | 101 | ||
101 | bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const | 102 | bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const |
102 | { | 103 | { |
@@ -185,9 +186,9 @@ bool QDir::readDirEntries( const QString &nameFilter, | |||
185 | fList->clear(); | 186 | fList->clear(); |
186 | fiList->clear(); | 187 | fiList->clear(); |
187 | } | 188 | } |
188 | 189 | ||
189 | QStringList filters = qt_makeFilterList( nameFilter ); | 190 | QValueList<QRegExp> filters = qt_makeFilterList( nameFilter ); |
190 | 191 | ||
191 | bool doDirs = (filterSpec & Dirs)!= 0; | 192 | bool doDirs = (filterSpec & Dirs)!= 0; |
192 | bool doFiles = (filterSpec & Files)!= 0; | 193 | bool doFiles = (filterSpec & Files)!= 0; |
193 | bool noSymLinks = (filterSpec & NoSymLinks) != 0; | 194 | bool noSymLinks = (filterSpec & NoSymLinks) != 0; |
@@ -196,25 +197,29 @@ bool QDir::readDirEntries( const QString &nameFilter, | |||
196 | bool doExecable = (filterSpec & Executable) != 0; | 197 | bool doExecable = (filterSpec & Executable) != 0; |
197 | bool doHidden = (filterSpec & Hidden)!= 0; | 198 | bool doHidden = (filterSpec & Hidden)!= 0; |
198 | bool doSystem = (filterSpec & System) != 0; | 199 | bool doSystem = (filterSpec & System) != 0; |
199 | 200 | ||
200 | #if defined(Q_OS_OS2EMX) | ||
201 | //QRegExp wc( nameFilter, FALSE, TRUE );// wild card, case insensitive | ||
202 | #else | ||
203 | //QRegExp wc( nameFilter, TRUE, TRUE );// wild card, case sensitive | ||
204 | #endif | ||
205 | QFileInfo fi; | 201 | QFileInfo fi; |
206 | DIR *dir; | 202 | DIR *dir; |
207 | dirent *file; | 203 | dirent *file; |
208 | 204 | ||
209 | dir = opendir( QFile::encodeName(dPath) ); | 205 | dir = opendir( QFile::encodeName(dPath) ); |
210 | if ( !dir ) | 206 | if ( !dir ) |
211 | return FALSE; // cannot read the directory | 207 | return FALSE; // cannot read the directory |
212 | 208 | ||
213 | while ( (file = readdir(dir)) ) { | 209 | #if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN) |
210 | union { | ||
211 | struct dirent mt_file; | ||
212 | char b[sizeof(struct dirent) + MAXNAMLEN + 1]; | ||
213 | } u; | ||
214 | while ( readdir_r(dir, &u.mt_file, &file ) == 0 && file ) | ||
215 | #else | ||
216 | while ( (file = readdir(dir)) ) | ||
217 | #endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS | ||
218 | { | ||
214 | QString fn = QFile::decodeName(file->d_name); | 219 | QString fn = QFile::decodeName(file->d_name); |
215 | fi.setFile( *this, fn ); | 220 | fi.setFile( *this, fn ); |
216 | if ( !match( filters, fn ) && !(allDirs && fi.isDir()) ) | 221 | if ( !qt_matchFilterList(filters, fn) && !(allDirs && fi.isDir()) ) |
217 | continue; | 222 | continue; |
218 | if ( (doDirs && fi.isDir()) || (doFiles && fi.isFile()) || | 223 | if ( (doDirs && fi.isDir()) || (doFiles && fi.isFile()) || |
219 | (doSystem && (!fi.isFile() && !fi.isDir())) ) { | 224 | (doSystem && (!fi.isFile() && !fi.isDir())) ) { |
220 | if ( noSymLinks && fi.isSymLink() ) | 225 | if ( noSymLinks && fi.isSymLink() ) |
@@ -275,9 +280,10 @@ const QFileInfoList * QDir::drives() | |||
275 | 280 | ||
276 | if ( !knownMemoryLeak ) { | 281 | if ( !knownMemoryLeak ) { |
277 | 282 | ||
278 | #ifdef QT_THREAD_SUPPORT | 283 | #ifdef QT_THREAD_SUPPORT |
279 | QMutexLocker locker( qt_global_mutexpool->get( &knownMemoryLeak ) ); | 284 | QMutexLocker locker( qt_global_mutexpool ? |
285 | qt_global_mutexpool->get( &knownMemoryLeak ) : 0 ); | ||
280 | #endif // QT_THREAD_SUPPORT | 286 | #endif // QT_THREAD_SUPPORT |
281 | 287 | ||
282 | if ( !knownMemoryLeak ) { | 288 | if ( !knownMemoryLeak ) { |
283 | knownMemoryLeak = new QFileInfoList; | 289 | knownMemoryLeak = new QFileInfoList; |
diff --git a/qmake/tools/qfile.cpp b/qmake/tools/qfile.cpp index a578b49..c088b55 100644 --- a/qmake/tools/qfile.cpp +++ b/qmake/tools/qfile.cpp | |||
@@ -87,9 +87,9 @@ extern bool qt_file_access( const QString& fn, int t ); | |||
87 | if ( file.open( IO_ReadOnly ) ) { | 87 | if ( file.open( IO_ReadOnly ) ) { |
88 | QTextStream stream( &file ); | 88 | QTextStream stream( &file ); |
89 | QString line; | 89 | QString line; |
90 | int i = 1; | 90 | int i = 1; |
91 | while ( !stream.eof() ) { | 91 | while ( !stream.atEnd() ) { |
92 | line = stream.readLine(); // line of text excluding '\n' | 92 | line = stream.readLine(); // line of text excluding '\n' |
93 | printf( "%3d: %s\n", i++, line.latin1() ); | 93 | printf( "%3d: %s\n", i++, line.latin1() ); |
94 | lines += line; | 94 | lines += line; |
95 | } | 95 | } |
@@ -289,8 +289,9 @@ void QFile::flush() | |||
289 | */ | 289 | */ |
290 | 290 | ||
291 | /*! | 291 | /*! |
292 | Returns TRUE if the end of file has been reached; otherwise returns FALSE. | 292 | Returns TRUE if the end of file has been reached; otherwise returns FALSE. |
293 | If QFile has not been open()'d, then the behavior is undefined. | ||
293 | 294 | ||
294 | \sa size() | 295 | \sa size() |
295 | */ | 296 | */ |
296 | 297 | ||
diff --git a/qmake/tools/qfile_unix.cpp b/qmake/tools/qfile_unix.cpp index 2d5a856..460bf06 100644 --- a/qmake/tools/qfile_unix.cpp +++ b/qmake/tools/qfile_unix.cpp | |||
@@ -434,13 +434,16 @@ bool QFile::open( int m, int f ) | |||
434 | 434 | ||
435 | QIODevice::Offset QFile::size() const | 435 | QIODevice::Offset QFile::size() const |
436 | { | 436 | { |
437 | struct stat st; | 437 | struct stat st; |
438 | int ret = 0; | ||
438 | if ( isOpen() ) { | 439 | if ( isOpen() ) { |
439 | ::fstat( fh ? fileno(fh) : fd, &st ); | 440 | ret = ::fstat( fh ? fileno(fh) : fd, &st ); |
440 | } else { | 441 | } else { |
441 | ::stat( QFile::encodeName(fn), &st ); | 442 | ret = ::stat( QFile::encodeName(fn), &st ); |
442 | } | 443 | } |
444 | if ( ret == -1 ) | ||
445 | return 0; | ||
443 | #if defined(QT_LARGEFILE_SUPPORT) && !defined(QT_ABI_64BITOFFSET) | 446 | #if defined(QT_LARGEFILE_SUPPORT) && !defined(QT_ABI_64BITOFFSET) |
444 | return (uint)st.st_size > UINT_MAX ? UINT_MAX : (QIODevice::Offset)st.st_size; | 447 | return (uint)st.st_size > UINT_MAX ? UINT_MAX : (QIODevice::Offset)st.st_size; |
445 | #else | 448 | #else |
446 | return st.st_size; | 449 | return st.st_size; |
@@ -537,9 +540,9 @@ Q_LONG QFile::readBlock( char *p, Q_ULONG len ) | |||
537 | if ( !ungetchBuffer.isEmpty() ) { | 540 | if ( !ungetchBuffer.isEmpty() ) { |
538 | // need to add these to the returned string. | 541 | // need to add these to the returned string. |
539 | uint l = ungetchBuffer.length(); | 542 | uint l = ungetchBuffer.length(); |
540 | while( nread < l ) { | 543 | while( nread < l ) { |
541 | *p = ungetchBuffer[ l - nread - 1 ]; | 544 | *p = ungetchBuffer.at( l - nread - 1 ); |
542 | p++; | 545 | p++; |
543 | nread++; | 546 | nread++; |
544 | } | 547 | } |
545 | ungetchBuffer.truncate( l - nread ); | 548 | ungetchBuffer.truncate( l - nread ); |
@@ -628,9 +631,11 @@ Q_LONG QFile::writeBlock( const char *p, Q_ULONG len ) | |||
628 | /*! | 631 | /*! |
629 | Returns the file handle of the file. | 632 | Returns the file handle of the file. |
630 | 633 | ||
631 | This is a small positive integer, suitable for use with C library | 634 | This is a small positive integer, suitable for use with C library |
632 | functions such as fdopen() and fcntl(), as well as with QSocketNotifier. | 635 | functions such as fdopen() and fcntl(). On systems that use file |
636 | descriptors for sockets (ie. Unix systems, but not Windows) the handle | ||
637 | can be used with QSocketNotifier as well. | ||
633 | 638 | ||
634 | If the file is not open or there is an error, handle() returns -1. | 639 | If the file is not open or there is an error, handle() returns -1. |
635 | 640 | ||
636 | \sa QSocketNotifier | 641 | \sa QSocketNotifier |
diff --git a/qmake/tools/qfileinfo.cpp b/qmake/tools/qfileinfo.cpp index 3af7932..a78f4fa 100644 --- a/qmake/tools/qfileinfo.cpp +++ b/qmake/tools/qfileinfo.cpp | |||
@@ -634,8 +634,10 @@ QDateTime QFileInfo::lastRead() const | |||
634 | 634 | ||
635 | This function returns the same as filePath(), unless isRelative() | 635 | This function returns the same as filePath(), unless isRelative() |
636 | is TRUE. | 636 | is TRUE. |
637 | 637 | ||
638 | If the QFileInfo is empty it returns QDir::currentDirPath(). | ||
639 | |||
638 | This function can be time consuming under Unix (in the order of | 640 | This function can be time consuming under Unix (in the order of |
639 | milliseconds). | 641 | milliseconds). |
640 | 642 | ||
641 | \sa isRelative(), filePath() | 643 | \sa isRelative(), filePath() |
@@ -643,9 +645,9 @@ QDateTime QFileInfo::lastRead() const | |||
643 | QString QFileInfo::absFilePath() const | 645 | QString QFileInfo::absFilePath() const |
644 | { | 646 | { |
645 | QString tmp; | 647 | QString tmp; |
646 | if ( QDir::isRelativePath(fn) | 648 | if ( QDir::isRelativePath(fn) |
647 | #if defined(Q_OS_WIN32) || defined(Q_OS_WIN64) | 649 | #if defined(Q_OS_WIN32) |
648 | && fn[1] != ':' | 650 | && fn[1] != ':' |
649 | #endif | 651 | #endif |
650 | ) { | 652 | ) { |
651 | tmp = QDir::currentDirPath(); | 653 | tmp = QDir::currentDirPath(); |
diff --git a/qmake/tools/qfileinfo_unix.cpp b/qmake/tools/qfileinfo_unix.cpp index f7c3a97..364f219 100644 --- a/qmake/tools/qfileinfo_unix.cpp +++ b/qmake/tools/qfileinfo_unix.cpp | |||
@@ -213,11 +213,11 @@ uint QFileInfo::groupId() const | |||
213 | Example: | 213 | Example: |
214 | \code | 214 | \code |
215 | QFileInfo fi( "/tmp/archive.tar.gz" ); | 215 | QFileInfo fi( "/tmp/archive.tar.gz" ); |
216 | if ( fi.permission( QFileInfo::WriteUser | QFileInfo::ReadGroup ) ) | 216 | if ( fi.permission( QFileInfo::WriteUser | QFileInfo::ReadGroup ) ) |
217 | qWarning( "I can change the file; my group can read the file."); | 217 | qWarning( "I can change the file; my group can read the file" ); |
218 | if ( fi.permission( QFileInfo::WriteGroup | QFileInfo::WriteOther ) ) | 218 | if ( fi.permission( QFileInfo::WriteGroup | QFileInfo::WriteOther ) ) |
219 | qWarning( "The group or others can change the file!" ); | 219 | qWarning( "The group or others can change the file" ); |
220 | \endcode | 220 | \endcode |
221 | 221 | ||
222 | \sa isReadable(), isWritable(), isExecutable() | 222 | \sa isReadable(), isWritable(), isExecutable() |
223 | */ | 223 | */ |
diff --git a/qmake/tools/qgarray.cpp b/qmake/tools/qgarray.cpp index 45c45ce..0a522e4 100644 --- a/qmake/tools/qgarray.cpp +++ b/qmake/tools/qgarray.cpp | |||
@@ -34,11 +34,15 @@ | |||
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #include "qglobal.h" // needed to define Q_WS_WIN | 38 | #include "qglobal.h" |
39 | #ifdef Q_WS_WIN | 39 | #if defined(Q_CC_BOR) |
40 | #include "qt_windows.h" // needed for bsearch on some platforms | 40 | // needed for qsort() because of a std namespace problem on Borland |
41 | # include "qplatformdefs.h" | ||
42 | #elif defined(Q_WS_WIN) | ||
43 | // needed for bsearch on some platforms | ||
44 | # include "qt_windows.h" | ||
41 | #endif | 45 | #endif |
42 | 46 | ||
43 | #define QGARRAY_CPP | 47 | #define QGARRAY_CPP |
44 | #include "qgarray.h" | 48 | #include "qgarray.h" |
@@ -48,9 +52,15 @@ | |||
48 | #ifdef QT_THREAD_SUPPORT | 52 | #ifdef QT_THREAD_SUPPORT |
49 | # include <private/qmutexpool_p.h> | 53 | # include <private/qmutexpool_p.h> |
50 | #endif // QT_THREAD_SUPPORT | 54 | #endif // QT_THREAD_SUPPORT |
51 | 55 | ||
52 | #define USE_MALLOC // comment to use new/delete | 56 | /* |
57 | If USE_MALLOC isn't defined, we use new[] and delete[] to allocate | ||
58 | memory. The documentation for QMemArray<T>::assign() explicitly | ||
59 | mentions that the array is freed using free(), so don't mess around | ||
60 | with USE_MALLOC unless you know what you're doing. | ||
61 | */ | ||
62 | #define USE_MALLOC | ||
53 | 63 | ||
54 | #undef NEW | 64 | #undef NEW |
55 | #undef DELETE | 65 | #undef DELETE |
56 | 66 | ||
@@ -134,9 +144,13 @@ QGArray::QGArray( int size ) | |||
134 | if ( size == 0 ) // zero length | 144 | if ( size == 0 ) // zero length |
135 | return; | 145 | return; |
136 | shd->data = NEW(char,size); | 146 | shd->data = NEW(char,size); |
137 | Q_CHECK_PTR( shd->data ); | 147 | Q_CHECK_PTR( shd->data ); |
138 | shd->len = size; | 148 | shd->len = |
149 | #ifdef QT_QGARRAY_SPEED_OPTIM | ||
150 | shd->maxl = | ||
151 | #endif | ||
152 | size; | ||
139 | } | 153 | } |
140 | 154 | ||
141 | /*! | 155 | /*! |
142 | Constructs a shallow copy of \a a. | 156 | Constructs a shallow copy of \a a. |
@@ -211,37 +225,72 @@ bool QGArray::isEqual( const QGArray &a ) const | |||
211 | } | 225 | } |
212 | 226 | ||
213 | 227 | ||
214 | /*! | 228 | /*! |
215 | Resizes the array to \a newsize bytes. | 229 | Resizes the array to \a newsize bytes. \a optim is either |
230 | MemOptim (the default) or SpeedOptim. | ||
216 | */ | 231 | */ |
217 | 232 | bool QGArray::resize( uint newsize, Optimization optim ) | |
218 | bool QGArray::resize( uint newsize ) | ||
219 | { | 233 | { |
220 | if ( newsize == shd->len ) // nothing to do | 234 | #ifndef QT_QGARRAY_SPEED_OPTIM |
235 | Q_UNUSED(optim); | ||
236 | #endif | ||
237 | |||
238 | if ( newsize == shd->len | ||
239 | #ifdef QT_QGARRAY_SPEED_OPTIM | ||
240 | && newsize == shd->maxl | ||
241 | #endif | ||
242 | ) // nothing to do | ||
221 | return TRUE; | 243 | return TRUE; |
222 | if ( newsize == 0 ) { // remove array | 244 | if ( newsize == 0 ) { // remove array |
223 | duplicate( 0, 0 ); | 245 | duplicate( 0, 0 ); |
224 | return TRUE; | 246 | return TRUE; |
225 | } | 247 | } |
248 | |||
249 | uint newmaxl = newsize; | ||
250 | #ifdef QT_QGARRAY_SPEED_OPTIM | ||
251 | if ( optim == SpeedOptim ) { | ||
252 | if ( newsize <= shd->maxl && | ||
253 | ( newsize * 4 > shd->maxl || shd->maxl <= 4 ) ) { | ||
254 | shd->len = newsize; | ||
255 | return TRUE; | ||
256 | } | ||
257 | newmaxl = 4; | ||
258 | while ( newmaxl < newsize ) | ||
259 | newmaxl *= 2; | ||
260 | // try to spare some memory | ||
261 | if ( newmaxl >= 1024 * 1024 && newsize <= newmaxl - (newmaxl >> 2) ) | ||
262 | newmaxl -= newmaxl >> 2; | ||
263 | } | ||
264 | shd->maxl = newmaxl; | ||
265 | #endif | ||
266 | |||
226 | if ( shd->data ) { // existing data | 267 | if ( shd->data ) { // existing data |
227 | #if defined(DONT_USE_REALLOC) | 268 | #if defined(DONT_USE_REALLOC) |
228 | char *newdata = NEW(char,newsize);// manual realloc | 269 | char *newdata = NEW(char,newsize);// manual realloc |
229 | memcpy( newdata, shd->data, QMIN(shd->len,newsize) ); | 270 | memcpy( newdata, shd->data, QMIN(shd->len,newmaxl) ); |
230 | DELETE(shd->data); | 271 | DELETE(shd->data); |
231 | shd->data = newdata; | 272 | shd->data = newdata; |
232 | #else | 273 | #else |
233 | shd->data = (char *)realloc( shd->data, newsize ); | 274 | shd->data = (char *)realloc( shd->data, newmaxl ); |
234 | #endif | 275 | #endif |
235 | } else { | 276 | } else { |
236 | shd->data = NEW(char,newsize); | 277 | shd->data = NEW(char,newmaxl); |
237 | } | 278 | } |
238 | if ( !shd->data ) // no memory | 279 | if ( !shd->data ) // no memory |
239 | return FALSE; | 280 | return FALSE; |
240 | shd->len = newsize; | 281 | shd->len = newsize; |
241 | return TRUE; | 282 | return TRUE; |
242 | } | 283 | } |
243 | 284 | ||
285 | /*!\overload | ||
286 | */ | ||
287 | bool QGArray::resize( uint newsize ) | ||
288 | { | ||
289 | return resize( newsize, MemOptim ); | ||
290 | } | ||
291 | |||
292 | |||
244 | /*! | 293 | /*! |
245 | Fills the array with the repeated occurrences of \a d, which is | 294 | Fills the array with the repeated occurrences of \a d, which is |
246 | \a sz bytes long. | 295 | \a sz bytes long. |
247 | If \a len is specified as different from -1, then the array will be | 296 | If \a len is specified as different from -1, then the array will be |
@@ -318,9 +367,13 @@ QGArray &QGArray::assign( const char *d, uint len ) | |||
318 | if ( shd->data ) | 367 | if ( shd->data ) |
319 | DELETE(shd->data); | 368 | DELETE(shd->data); |
320 | } | 369 | } |
321 | shd->data = (char *)d; | 370 | shd->data = (char *)d; |
322 | shd->len = len; | 371 | shd->len = |
372 | #ifdef QT_QGARRAY_SPEED_OPTIM | ||
373 | shd->maxl = | ||
374 | #endif | ||
375 | len; | ||
323 | return *this; | 376 | return *this; |
324 | } | 377 | } |
325 | 378 | ||
326 | /*! | 379 | /*! |
@@ -363,9 +416,13 @@ QGArray &QGArray::duplicate( const QGArray &a ) | |||
363 | memcpy( shd->data, a.shd->data, a.shd->len ); | 416 | memcpy( shd->data, a.shd->data, a.shd->len ); |
364 | } else { | 417 | } else { |
365 | shd->data = 0; | 418 | shd->data = 0; |
366 | } | 419 | } |
367 | shd->len = a.shd->len; | 420 | shd->len = |
421 | #ifdef QT_QGARRAY_SPEED_OPTIM | ||
422 | shd->maxl = | ||
423 | #endif | ||
424 | a.shd->len; | ||
368 | if ( oldptr ) | 425 | if ( oldptr ) |
369 | DELETE(oldptr); | 426 | DELETE(oldptr); |
370 | return *this; | 427 | return *this; |
371 | } | 428 | } |
@@ -401,9 +458,13 @@ QGArray &QGArray::duplicate( const char *d, uint len ) | |||
401 | if ( shd->data ) | 458 | if ( shd->data ) |
402 | DELETE(shd->data); | 459 | DELETE(shd->data); |
403 | } | 460 | } |
404 | shd->data = data; | 461 | shd->data = data; |
405 | shd->len = len; | 462 | shd->len = |
463 | #ifdef QT_QGARRAY_SPEED_OPTIM | ||
464 | shd->maxl = | ||
465 | #endif | ||
466 | len; | ||
406 | return *this; | 467 | return *this; |
407 | } | 468 | } |
408 | 469 | ||
409 | /*! | 470 | /*! |
@@ -658,9 +719,10 @@ void QGArray::sort( uint sz ) | |||
658 | if ( numItems < 2 ) | 719 | if ( numItems < 2 ) |
659 | return; | 720 | return; |
660 | 721 | ||
661 | #ifdef QT_THREAD_SUPPORT | 722 | #ifdef QT_THREAD_SUPPORT |
662 | QMutexLocker locker( qt_global_mutexpool->get( &cmp_item_size ) ); | 723 | QMutexLocker locker( qt_global_mutexpool ? |
724 | qt_global_mutexpool->get( &cmp_item_size ) : 0 ); | ||
663 | #endif // QT_THREAD_SUPPORT | 725 | #endif // QT_THREAD_SUPPORT |
664 | 726 | ||
665 | cmp_item_size = sz; | 727 | cmp_item_size = sz; |
666 | qsort( shd->data, numItems, sz, cmp_arr ); | 728 | qsort( shd->data, numItems, sz, cmp_arr ); |
@@ -676,9 +738,10 @@ int QGArray::bsearch( const char *d, uint sz ) const | |||
676 | if ( !numItems ) | 738 | if ( !numItems ) |
677 | return -1; | 739 | return -1; |
678 | 740 | ||
679 | #ifdef QT_THREAD_SUPPORT | 741 | #ifdef QT_THREAD_SUPPORT |
680 | QMutexLocker locker( qt_global_mutexpool->get( &cmp_item_size ) ); | 742 | QMutexLocker locker( qt_global_mutexpool ? |
743 | qt_global_mutexpool->get( &cmp_item_size ) : 0 ); | ||
681 | #endif // QT_THREAD_SUPPORT | 744 | #endif // QT_THREAD_SUPPORT |
682 | 745 | ||
683 | cmp_item_size = sz; | 746 | cmp_item_size = sz; |
684 | char* r = (char*)::bsearch( d, shd->data, numItems, sz, cmp_arr ); | 747 | char* r = (char*)::bsearch( d, shd->data, numItems, sz, cmp_arr ); |
diff --git a/qmake/tools/qgdict.cpp b/qmake/tools/qgdict.cpp index c431ff8..3d49fc7 100644 --- a/qmake/tools/qgdict.cpp +++ b/qmake/tools/qgdict.cpp | |||
@@ -203,9 +203,12 @@ QGDict::QGDict( uint len, KeyType kt, bool caseSensitive, bool copyKeys ) | |||
203 | 203 | ||
204 | 204 | ||
205 | void QGDict::init( uint len, KeyType kt, bool caseSensitive, bool copyKeys ) | 205 | void QGDict::init( uint len, KeyType kt, bool caseSensitive, bool copyKeys ) |
206 | { | 206 | { |
207 | vec = new QBaseBucket *[vlen = len]; // allocate hash table | 207 | vlen = len; |
208 | if ( vlen == 0 ) | ||
209 | vlen = 17; | ||
210 | vec = new QBaseBucket *[vlen]; | ||
208 | Q_CHECK_PTR( vec ); | 211 | Q_CHECK_PTR( vec ); |
209 | memset( (char*)vec, 0, vlen*sizeof(QBaseBucket*) ); | 212 | memset( (char*)vec, 0, vlen*sizeof(QBaseBucket*) ); |
210 | numItems = 0; | 213 | numItems = 0; |
211 | iterators = 0; | 214 | iterators = 0; |
diff --git a/qmake/tools/qglist.cpp b/qmake/tools/qglist.cpp index 155d585..bd27f8a 100644 --- a/qmake/tools/qglist.cpp +++ b/qmake/tools/qglist.cpp | |||
@@ -328,14 +328,10 @@ QLNode *QGList::locate( uint index ) | |||
328 | register QLNode *node; | 328 | register QLNode *node; |
329 | int distance = index - curIndex; // node distance to cur node | 329 | int distance = index - curIndex; // node distance to cur node |
330 | bool forward; // direction to traverse | 330 | bool forward; // direction to traverse |
331 | 331 | ||
332 | if ( index >= numNodes ) { | 332 | if ( index >= numNodes ) |
333 | #if defined(QT_CHECK_RANGE) | ||
334 | qWarning( "QGList::locate: Index %d out of range", index ); | ||
335 | #endif | ||
336 | return 0; | 333 | return 0; |
337 | } | ||
338 | 334 | ||
339 | if ( distance < 0 ) | 335 | if ( distance < 0 ) |
340 | distance = -distance; | 336 | distance = -distance; |
341 | if ( (uint)distance < index && (uint)distance < numNodes - index ) { | 337 | if ( (uint)distance < index && (uint)distance < numNodes - index ) { |
diff --git a/qmake/tools/qglobal.cpp b/qmake/tools/qglobal.cpp index 47cd6bd..342005d 100644 --- a/qmake/tools/qglobal.cpp +++ b/qmake/tools/qglobal.cpp | |||
@@ -148,9 +148,30 @@ bool qSysInfo( int *wordSize, bool *bigEndian ) | |||
148 | si_alreadyDone = TRUE; | 148 | si_alreadyDone = TRUE; |
149 | return TRUE; | 149 | return TRUE; |
150 | } | 150 | } |
151 | 151 | ||
152 | #if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) | 152 | #if !defined(QWS) && defined(Q_OS_MAC) |
153 | |||
154 | #include "qt_mac.h" | ||
155 | |||
156 | int qMacVersion() | ||
157 | { | ||
158 | static int macver = Qt::MV_Unknown; | ||
159 | static bool first = TRUE; | ||
160 | if(first) { | ||
161 | first = FALSE; | ||
162 | long gestalt_version; | ||
163 | if(Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) { | ||
164 | if(gestalt_version >= 0x1020 && gestalt_version < 0x1030) | ||
165 | macver = Qt::MV_10_DOT_2; | ||
166 | else if(gestalt_version >= 0x1010 && gestalt_version < 0x1020) | ||
167 | macver = Qt::MV_10_DOT_1; | ||
168 | } | ||
169 | } | ||
170 | return macver; | ||
171 | } | ||
172 | Qt::MacintoshVersion qt_macver = (Qt::MacintoshVersion)qMacVersion(); | ||
173 | #elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN) | ||
153 | bool qt_winunicode; | 174 | bool qt_winunicode; |
154 | 175 | ||
155 | #include "qt_windows.h" | 176 | #include "qt_windows.h" |
156 | 177 | ||
@@ -320,9 +341,21 @@ static QtMsgHandler handler = 0; // pointer to debug handler | |||
320 | static const int QT_BUFFER_LENGTH = 8196;// internal buffer length | 341 | static const int QT_BUFFER_LENGTH = 8196;// internal buffer length |
321 | 342 | ||
322 | 343 | ||
323 | #ifdef Q_OS_MAC | 344 | #ifdef Q_OS_MAC |
324 | const unsigned char * p_str(const char * c, int len=-1) | 345 | QString cfstring2qstring(CFStringRef str) |
346 | { | ||
347 | CFIndex length = CFStringGetLength(str); | ||
348 | if(const UniChar *chars = CFStringGetCharactersPtr(str)) | ||
349 | return QString((QChar *)chars, length); | ||
350 | UniChar *buffer = (UniChar*)malloc(length * sizeof(UniChar)); | ||
351 | CFStringGetCharacters(str, CFRangeMake(0, length), buffer); | ||
352 | QString ret((QChar *)buffer, length); | ||
353 | free(buffer); | ||
354 | return ret; | ||
355 | } | ||
356 | |||
357 | unsigned char * p_str(const char * c, int len=-1) | ||
325 | { | 358 | { |
326 | const int maxlen = 255; | 359 | const int maxlen = 255; |
327 | if(len == -1) | 360 | if(len == -1) |
328 | len = qstrlen(c); | 361 | len = qstrlen(c); |
@@ -336,9 +369,9 @@ const unsigned char * p_str(const char * c, int len=-1) | |||
336 | *(ret+len+1) = '\0'; | 369 | *(ret+len+1) = '\0'; |
337 | return ret; | 370 | return ret; |
338 | } | 371 | } |
339 | 372 | ||
340 | const unsigned char * p_str(const QString &s) | 373 | unsigned char * p_str(const QString &s) |
341 | { | 374 | { |
342 | return p_str(s, s.length()); | 375 | return p_str(s, s.length()); |
343 | } | 376 | } |
344 | 377 | ||
@@ -640,10 +673,10 @@ void qSystemWarning( const char* msg, int code ) | |||
640 | \fn void Q_CHECK_PTR( void *p ) | 673 | \fn void Q_CHECK_PTR( void *p ) |
641 | 674 | ||
642 | \relates QApplication | 675 | \relates QApplication |
643 | 676 | ||
644 | If \a p is null, a fatal messages says that the program ran out of | 677 | If \a p is 0, a fatal messages says that the program ran out of |
645 | memory and exits. If \e p is not null, nothing happens. | 678 | memory and exits. If \e p is not 0, nothing happens. |
646 | 679 | ||
647 | This is really a macro defined in \c qglobal.h. | 680 | This is really a macro defined in \c qglobal.h. |
648 | 681 | ||
649 | Example: | 682 | Example: |
@@ -651,9 +684,9 @@ void qSystemWarning( const char* msg, int code ) | |||
651 | int *a; | 684 | int *a; |
652 | 685 | ||
653 | Q_CHECK_PTR( a = new int[80] ); // WRONG! | 686 | Q_CHECK_PTR( a = new int[80] ); // WRONG! |
654 | 687 | ||
655 | a = new int[80]; // Right | 688 | a = new (nothrow) int[80]; // Right |
656 | Q_CHECK_PTR( a ); | 689 | Q_CHECK_PTR( a ); |
657 | \endcode | 690 | \endcode |
658 | 691 | ||
659 | \sa qFatal(), \link debug.html Debugging\endlink | 692 | \sa qFatal(), \link debug.html Debugging\endlink |
diff --git a/qmake/tools/qgpluginmanager.cpp b/qmake/tools/qgpluginmanager.cpp index 46c85f5..72246ac 100644 --- a/qmake/tools/qgpluginmanager.cpp +++ b/qmake/tools/qgpluginmanager.cpp | |||
@@ -2,9 +2,9 @@ | |||
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of QGPluginManager class | 4 | ** Implementation of QGPluginManager class |
5 | ** | 5 | ** |
6 | ** Copyright (C) 2000-2001 Trolltech AS. All rights reserved. | 6 | ** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. |
7 | ** | 7 | ** |
8 | ** This file is part of the tools module of the Qt GUI Toolkit. | 8 | ** This file is part of the tools module of the Qt GUI Toolkit. |
9 | ** | 9 | ** |
10 | ** This file may be distributed under the terms of the Q Public License | 10 | ** This file may be distributed under the terms of the Q Public License |
@@ -474,9 +474,9 @@ bool QGPluginManager::addLibrary( QLibrary* lib ) | |||
474 | fl = fliFace->featureList(); | 474 | fl = fliFace->featureList(); |
475 | else if ( cpiFace ) | 475 | else if ( cpiFace ) |
476 | fl << cpiFace->name(); | 476 | fl << cpiFace->name(); |
477 | 477 | ||
478 | for ( QStringList::Iterator f = fl.begin(); f != fl.end(); f++ ) { | 478 | for ( QStringList::Iterator f = fl.begin(); f != fl.end(); ++f ) { |
479 | QLibrary *old = plugDict[*f]; | 479 | QLibrary *old = plugDict[*f]; |
480 | if ( !old ) { | 480 | if ( !old ) { |
481 | useful = TRUE; | 481 | useful = TRUE; |
482 | plugDict.replace( *f, plugin ); | 482 | plugDict.replace( *f, plugin ); |
diff --git a/qmake/tools/qgvector.cpp b/qmake/tools/qgvector.cpp index 1985f03..3c903ed 100644 --- a/qmake/tools/qgvector.cpp +++ b/qmake/tools/qgvector.cpp | |||
@@ -34,8 +34,14 @@ | |||
34 | ** not clear to you. | 34 | ** not clear to you. |
35 | ** | 35 | ** |
36 | **********************************************************************/ | 36 | **********************************************************************/ |
37 | 37 | ||
38 | #include "qglobal.h" | ||
39 | #if defined(Q_CC_BOR) | ||
40 | // needed for qsort() because of a std namespace problem on Borland | ||
41 | #include "qplatformdefs.h" | ||
42 | #endif | ||
43 | |||
38 | #define QGVECTOR_CPP | 44 | #define QGVECTOR_CPP |
39 | #include "qgvector.h" | 45 | #include "qgvector.h" |
40 | #include "qglist.h" | 46 | #include "qglist.h" |
41 | #include "qstring.h" | 47 | #include "qstring.h" |
@@ -392,9 +398,10 @@ void QGVector::sort() // sort vector | |||
392 | } | 398 | } |
393 | } | 399 | } |
394 | 400 | ||
395 | #ifdef QT_THREAD_SUPPORT | 401 | #ifdef QT_THREAD_SUPPORT |
396 | QMutexLocker locker( qt_global_mutexpool->get( &sort_vec ) ); | 402 | QMutexLocker locker( qt_global_mutexpool ? |
403 | qt_global_mutexpool->get( &sort_vec ) : 0 ); | ||
397 | #endif // QT_THREAD_SUPPORT | 404 | #endif // QT_THREAD_SUPPORT |
398 | 405 | ||
399 | sort_vec = (QGVector*)this; | 406 | sort_vec = (QGVector*)this; |
400 | qsort( vec, count(), sizeof(Item), cmp_vec ); | 407 | qsort( vec, count(), sizeof(Item), cmp_vec ); |
diff --git a/qmake/tools/qlibrary.cpp b/qmake/tools/qlibrary.cpp index 564db30..be1d54b 100644 --- a/qmake/tools/qlibrary.cpp +++ b/qmake/tools/qlibrary.cpp | |||
@@ -2,11 +2,11 @@ | |||
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of QLibrary class | 4 | ** Implementation of QLibrary class |
5 | ** | 5 | ** |
6 | ** Created : 2000-01-01 | 6 | ** Created : 000101 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 2000-2003 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
@@ -70,9 +70,9 @@ QLibraryPrivate::QLibraryPrivate( QLibrary *lib ) | |||
70 | \reentrant | 70 | \reentrant |
71 | \brief The QLibrary class provides a wrapper for handling shared libraries. | 71 | \brief The QLibrary class provides a wrapper for handling shared libraries. |
72 | 72 | ||
73 | \mainclass | 73 | \mainclass |
74 | \group plugins | 74 | \ingroup plugins |
75 | 75 | ||
76 | An instance of a QLibrary object can handle a single shared | 76 | An instance of a QLibrary object can handle a single shared |
77 | library and provide access to the functionality in the library in | 77 | library and provide access to the functionality in the library in |
78 | a platform independent way. If the library is a component server, | 78 | a platform independent way. If the library is a component server, |
@@ -325,16 +325,17 @@ QString QLibrary::library() const | |||
325 | #elif defined(Q_OS_MACX) | 325 | #elif defined(Q_OS_MACX) |
326 | if ( filename.find( ".dylib" ) == -1 ) | 326 | if ( filename.find( ".dylib" ) == -1 ) |
327 | filename += ".dylib"; | 327 | filename += ".dylib"; |
328 | #else | 328 | #else |
329 | if ( filename.find( ".so" ) == -1 ) { | 329 | QString filter = ".so"; |
330 | if ( filename.find(filter) == -1 ) { | ||
330 | const int x = filename.findRev( "/" ); | 331 | const int x = filename.findRev( "/" ); |
331 | if ( x != -1 ) { | 332 | if ( x != -1 ) { |
332 | QString path = filename.left( x + 1 ); | 333 | QString path = filename.left( x + 1 ); |
333 | QString file = filename.right( filename.length() - x - 1 ); | 334 | QString file = filename.right( filename.length() - x - 1 ); |
334 | filename = QString( "%1lib%2.so" ).arg( path ).arg( file ); | 335 | filename = QString( "%1lib%2.%3" ).arg( path ).arg( file ).arg( filter ); |
335 | } else { | 336 | } else { |
336 | filename = QString( "lib%1.so" ).arg( filename ); | 337 | filename = QString( "lib%1.%2" ).arg( filename ).arg( filter ); |
337 | } | 338 | } |
338 | } | 339 | } |
339 | #endif | 340 | #endif |
340 | 341 | ||
diff --git a/qmake/tools/qlibrary_unix.cpp b/qmake/tools/qlibrary_unix.cpp index f0fbdf6..12b9310 100644 --- a/qmake/tools/qlibrary_unix.cpp +++ b/qmake/tools/qlibrary_unix.cpp | |||
@@ -2,9 +2,9 @@ | |||
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of QLibraryPrivate class | 4 | ** Implementation of QLibraryPrivate class |
5 | ** | 5 | ** |
6 | ** Created : 2000-01-01 | 6 | ** Created : 000101 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
@@ -52,9 +52,26 @@ | |||
52 | 52 | ||
53 | It's not too hard to guess what the functions do. | 53 | It's not too hard to guess what the functions do. |
54 | */ | 54 | */ |
55 | 55 | ||
56 | #if defined(QT_HPUX_LD) // for HP-UX < 11.x and 32 bit | 56 | #if defined(Q_OS_MAC) |
57 | |||
58 | bool QLibraryPrivate::loadLibrary() | ||
59 | { | ||
60 | return FALSE; | ||
61 | } | ||
62 | |||
63 | bool QLibraryPrivate::freeLibrary() | ||
64 | { | ||
65 | return FALSE; | ||
66 | } | ||
67 | |||
68 | void* QLibraryPrivate::resolveSymbol( const char* ) | ||
69 | { | ||
70 | return 0; | ||
71 | } | ||
72 | |||
73 | #elif defined(QT_HPUX_LD) // for HP-UX < 11.x and 32 bit | ||
57 | 74 | ||
58 | bool QLibraryPrivate::loadLibrary() | 75 | bool QLibraryPrivate::loadLibrary() |
59 | { | 76 | { |
60 | if ( pHnd ) | 77 | if ( pHnd ) |
diff --git a/qmake/tools/qmutex_unix.cpp b/qmake/tools/qmutex_unix.cpp index c861b2d..3eb59cf 100644 --- a/qmake/tools/qmutex_unix.cpp +++ b/qmake/tools/qmutex_unix.cpp | |||
@@ -42,9 +42,10 @@ | |||
42 | typedef pthread_mutex_t Q_MUTEX_T; | 42 | typedef pthread_mutex_t Q_MUTEX_T; |
43 | 43 | ||
44 | // POSIX threads mutex types | 44 | // POSIX threads mutex types |
45 | #if ((defined(PTHREAD_MUTEX_RECURSIVE) && defined(PTHREAD_MUTEX_DEFAULT)) || \ | 45 | #if ((defined(PTHREAD_MUTEX_RECURSIVE) && defined(PTHREAD_MUTEX_DEFAULT)) || \ |
46 | defined(Q_OS_FREEBSD)) && !defined(Q_OS_UNIXWARE) && !defined(Q_OS_SOLARIS) | 46 | defined(Q_OS_FREEBSD)) && !defined(Q_OS_UNIXWARE) && !defined(Q_OS_SOLARIS) && \ |
47 | !defined(Q_OS_MAC) | ||
47 | // POSIX 1003.1c-1995 - We love this OS | 48 | // POSIX 1003.1c-1995 - We love this OS |
48 | # define Q_MUTEX_SET_TYPE(a, b) pthread_mutexattr_settype((a), (b)) | 49 | # define Q_MUTEX_SET_TYPE(a, b) pthread_mutexattr_settype((a), (b)) |
49 | # if defined(QT_CHECK_RANGE) | 50 | # if defined(QT_CHECK_RANGE) |
50 | # define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK | 51 | # define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK |
@@ -660,9 +661,10 @@ bool QMutex::tryLock() | |||
660 | /*! | 661 | /*! |
661 | \fn QMutexLocker::QMutexLocker( QMutex *mutex ) | 662 | \fn QMutexLocker::QMutexLocker( QMutex *mutex ) |
662 | 663 | ||
663 | Constructs a QMutexLocker and locks \a mutex. The mutex will be | 664 | Constructs a QMutexLocker and locks \a mutex. The mutex will be |
664 | unlocked when the QMutexLocker is destroyed. | 665 | unlocked when the QMutexLocker is destroyed. If \a mutex is zero, |
666 | QMutexLocker does nothing. | ||
665 | 667 | ||
666 | \sa QMutex::lock() | 668 | \sa QMutex::lock() |
667 | */ | 669 | */ |
668 | 670 | ||
diff --git a/qmake/tools/qmutexpool.cpp b/qmake/tools/qmutexpool.cpp index 9ed2829..a8e7402 100644 --- a/qmake/tools/qmutexpool.cpp +++ b/qmake/tools/qmutexpool.cpp | |||
@@ -1,28 +1,47 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** ... | ||
5 | ** | ||
6 | ** Copyright (C) 2002 Trolltech AS. All rights reserved. | ||
7 | ** | ||
8 | ** This file is part of the tools module of the Qt GUI Toolkit. | ||
9 | ** | ||
10 | ** This file may be distributed under the terms of the Q Public License | ||
11 | ** as defined by Trolltech AS of Norway and appearing in the file | ||
12 | ** LICENSE.QPL included in the packaging of this file. | ||
13 | ** | ||
14 | ** This file may be distributed and/or modified under the terms of the | ||
15 | ** GNU General Public License version 2 as published by the Free Software | ||
16 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
17 | ** packaging of this file. | ||
18 | ** | ||
19 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
20 | ** licenses may use this file in accordance with the Qt Commercial License | ||
21 | ** Agreement provided with the Software. | ||
22 | ** | ||
23 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
24 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
25 | ** | ||
26 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
27 | ** information about Qt Commercial License Agreements. | ||
28 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
29 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
30 | ** | ||
31 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
32 | ** not clear to you. | ||
33 | ** | ||
34 | **********************************************************************/ | ||
35 | |||
1 | #include "qmutexpool_p.h" | 36 | #include "qmutexpool_p.h" |
2 | 37 | ||
3 | #ifdef QT_THREAD_SUPPORT | 38 | #ifdef QT_THREAD_SUPPORT |
4 | 39 | ||
5 | #include <qthread.h> | 40 | #include <qthread.h> |
6 | #include <stdio.h> | ||
7 | 41 | ||
8 | QMutexPool *qt_global_mutexpool = 0; | 42 | QMutexPool *qt_global_mutexpool = 0; |
9 | 43 | ||
10 | // this is an internal class used only for inititalizing the global mutexpool | ||
11 | class QGlobalMutexPoolInitializer | ||
12 | { | ||
13 | public: | ||
14 | inline QGlobalMutexPoolInitializer() | ||
15 | { | ||
16 | /* | ||
17 | Purify will report a leak here. However, this mutex pool must be alive | ||
18 | until *everything* in Qt has been destructed. Unfortunately there is | ||
19 | no way to guarantee this, so we never destroy this mutex pool. | ||
20 | */ | ||
21 | qt_global_mutexpool = new QMutexPool( TRUE ); | ||
22 | } | ||
23 | }; | ||
24 | QGlobalMutexPoolInitializer qt_global_mutexpool_initializer; | ||
25 | 44 | ||
26 | /*! | 45 | /*! |
27 | \class QMutexPool qmutexpool_p.h | 46 | \class QMutexPool qmutexpool_p.h |
28 | \brief The QMutexPool class provides a pool of QMutex objects. | 47 | \brief The QMutexPool class provides a pool of QMutex objects. |
@@ -84,11 +103,14 @@ QGlobalMutexPoolInitializer qt_global_mutexpool_initializer; | |||
84 | The QMutexes are created when needed, and deleted when the | 103 | The QMutexes are created when needed, and deleted when the |
85 | QMutexPool is destructed. | 104 | QMutexPool is destructed. |
86 | */ | 105 | */ |
87 | QMutexPool::QMutexPool( bool recursive, int size ) | 106 | QMutexPool::QMutexPool( bool recursive, int size ) |
88 | : mutex( FALSE ), mutexes( size ), recurs( recursive ) | 107 | : mutex( FALSE ), count( size ), recurs( recursive ) |
89 | { | 108 | { |
90 | mutexes.fill( 0 ); | 109 | mutexes = new QMutex*[count]; |
110 | for ( int index = 0; index < count; ++index ) { | ||
111 | mutexes[index] = 0; | ||
112 | } | ||
91 | } | 113 | } |
92 | 114 | ||
93 | /*! | 115 | /*! |
94 | Destructs a QMutexPool. All QMutexes that were created by the pool | 116 | Destructs a QMutexPool. All QMutexes that were created by the pool |
@@ -96,35 +118,35 @@ QMutexPool::QMutexPool( bool recursive, int size ) | |||
96 | */ | 118 | */ |
97 | QMutexPool::~QMutexPool() | 119 | QMutexPool::~QMutexPool() |
98 | { | 120 | { |
99 | QMutexLocker locker( &mutex ); | 121 | QMutexLocker locker( &mutex ); |
100 | QMutex **d = mutexes.data(); | 122 | for ( int index = 0; index < count; ++index ) { |
101 | for ( int index = 0; (uint) index < mutexes.size(); index++ ) { | 123 | delete mutexes[index]; |
102 | delete d[index]; | 124 | mutexes[index] = 0; |
103 | d[index] = 0; | ||
104 | } | 125 | } |
126 | delete [] mutexes; | ||
127 | mutexes = 0; | ||
105 | } | 128 | } |
106 | 129 | ||
107 | /*! | 130 | /*! |
108 | Returns a QMutex from the pool. QMutexPool uses the value \a | 131 | Returns a QMutex from the pool. QMutexPool uses the value \a |
109 | address to determine which mutex is retured from the pool. | 132 | address to determine which mutex is retured from the pool. |
110 | */ | 133 | */ |
111 | QMutex *QMutexPool::get( void *address ) | 134 | QMutex *QMutexPool::get( void *address ) |
112 | { | 135 | { |
113 | QMutex **d = mutexes.data(); | 136 | int index = (int) ( (unsigned long) address % count ); |
114 | int index = (int)( (ulong) address % mutexes.size() ); | ||
115 | 137 | ||
116 | if ( ! d[index] ) { | 138 | if ( ! mutexes[index] ) { |
117 | // mutex not created, create one | 139 | // mutex not created, create one |
118 | 140 | ||
119 | QMutexLocker locker( &mutex ); | 141 | QMutexLocker locker( &mutex ); |
120 | // we need to check once again that the mutex hasn't been created, since | 142 | // we need to check once again that the mutex hasn't been created, since |
121 | // 2 threads could be trying to create a mutex as the same index... | 143 | // 2 threads could be trying to create a mutex as the same index... |
122 | if ( ! d[index] ) { | 144 | if ( ! mutexes[index] ) { |
123 | d[index] = new QMutex( recurs ); | 145 | mutexes[index] = new QMutex( recurs ); |
124 | } | 146 | } |
125 | } | 147 | } |
126 | 148 | ||
127 | return d[index]; | 149 | return mutexes[index]; |
128 | } | 150 | } |
129 | 151 | ||
130 | #endif | 152 | #endif |
diff --git a/qmake/tools/qregexp.cpp b/qmake/tools/qregexp.cpp index 500efed..0c1f060 100644 --- a/qmake/tools/qregexp.cpp +++ b/qmake/tools/qregexp.cpp | |||
@@ -262,17 +262,17 @@ | |||
262 | corresponding to the octal number ooo (between 0 and 0377). | 262 | corresponding to the octal number ooo (between 0 and 0377). |
263 | \row \i <b>. (dot)</b> | 263 | \row \i <b>. (dot)</b> |
264 | \i This matches any character (including newline). | 264 | \i This matches any character (including newline). |
265 | \row \i <b>\\d</b> | 265 | \row \i <b>\\d</b> |
266 | \i This matches a digit (see QChar::isDigit()). | 266 | \i This matches a digit (QChar::isDigit()). |
267 | \row \i <b>\\D</b> | 267 | \row \i <b>\\D</b> |
268 | \i This matches a non-digit. | 268 | \i This matches a non-digit. |
269 | \row \i <b>\\s</b> | 269 | \row \i <b>\\s</b> |
270 | \i This matches a whitespace (see QChar::isSpace()). | 270 | \i This matches a whitespace (QChar::isSpace()). |
271 | \row \i <b>\\S</b> | 271 | \row \i <b>\\S</b> |
272 | \i This matches a non-whitespace. | 272 | \i This matches a non-whitespace. |
273 | \row \i <b>\\w</b> | 273 | \row \i <b>\\w</b> |
274 | \i This matches a word character (see QChar::isLetterOrNumber()). | 274 | \i This matches a word character (QChar::isLetterOrNumber() or '_'). |
275 | \row \i <b>\\W</b> | 275 | \row \i <b>\\W</b> |
276 | \i This matches a non-word character. | 276 | \i This matches a non-word character. |
277 | \row \i <b>\\n</b> | 277 | \row \i <b>\\n</b> |
278 | \i The n-th \link #capturing-text backreference \endlink, | 278 | \i The n-th \link #capturing-text backreference \endlink, |
@@ -546,9 +546,16 @@ | |||
546 | 546 | ||
547 | To substitute a pattern use QString::replace(). | 547 | To substitute a pattern use QString::replace(). |
548 | 548 | ||
549 | Perl's extended \c{/x} syntax is not supported, nor are | 549 | Perl's extended \c{/x} syntax is not supported, nor are |
550 | regexp comments (?#comment) or directives, e.g. (?i). | 550 | directives, e.g. (?i), or regexp comments, e.g. (?#comment). On |
551 | the other hand, C++'s rules for literal strings can be used to | ||
552 | achieve the same: | ||
553 | \code | ||
554 | QRegExp mark( "\\b" // word boundary | ||
555 | "[Mm]ark" // the word we want to match | ||
556 | ); | ||
557 | \endcode | ||
551 | 558 | ||
552 | Both zero-width positive and zero-width negative lookahead | 559 | Both zero-width positive and zero-width negative lookahead |
553 | assertions (?=pattern) and (?!pattern) are supported with the same | 560 | assertions (?=pattern) and (?!pattern) are supported with the same |
554 | syntax as Perl. Perl's lookbehind assertions, "independent" | 561 | syntax as Perl. Perl's lookbehind assertions, "independent" |
@@ -678,11 +685,11 @@ | |||
678 | 685 | ||
679 | \code | 686 | \code |
680 | QRegExp rx( "*.html" ); // invalid regexp: * doesn't quantify anything | 687 | QRegExp rx( "*.html" ); // invalid regexp: * doesn't quantify anything |
681 | rx.setWildcard( TRUE ); // now it's a valid wildcard regexp | 688 | rx.setWildcard( TRUE ); // now it's a valid wildcard regexp |
682 | rx.search( "index.html" ); // returns 0 (matched at position 0) | 689 | rx.exactMatch( "index.html" ); // returns TRUE |
683 | rx.search( "default.htm" ); // returns -1 (no match) | 690 | rx.exactMatch( "default.htm" ); // returns FALSE |
684 | rx.search( "readme.txt" ); // returns -1 (no match) | 691 | rx.exactMatch( "readme.txt" ); // returns FALSE |
685 | \endcode | 692 | \endcode |
686 | 693 | ||
687 | Wildcard matching can be convenient because of its simplicity, but | 694 | Wildcard matching can be convenient because of its simplicity, but |
688 | any wildcard regexp can be defined using full regexps, e.g. | 695 | any wildcard regexp can be defined using full regexps, e.g. |
@@ -714,8 +721,13 @@ const int EmptyCapture = INT_MAX; | |||
714 | const int InftyLen = INT_MAX; | 721 | const int InftyLen = INT_MAX; |
715 | const int InftyRep = 1025; | 722 | const int InftyRep = 1025; |
716 | const int EOS = -1; | 723 | const int EOS = -1; |
717 | 724 | ||
725 | static bool isWord( QChar ch ) | ||
726 | { | ||
727 | return ch.isLetterOrNumber() || ch == QChar( '_' ); | ||
728 | } | ||
729 | |||
718 | /* | 730 | /* |
719 | Merges two QMemArrays of ints and puts the result into the first one. | 731 | Merges two QMemArrays of ints and puts the result into the first one. |
720 | */ | 732 | */ |
721 | static void mergeInto( QMemArray<int> *a, const QMemArray<int>& b ) | 733 | static void mergeInto( QMemArray<int> *a, const QMemArray<int>& b ) |
@@ -1679,11 +1691,11 @@ bool QRegExpEngine::testAnchor( int i, int a, const int *capBegin ) | |||
1679 | if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) { | 1691 | if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) { |
1680 | bool before = FALSE; | 1692 | bool before = FALSE; |
1681 | bool after = FALSE; | 1693 | bool after = FALSE; |
1682 | if ( mmPos + i != 0 ) | 1694 | if ( mmPos + i != 0 ) |
1683 | before = mmIn[mmPos + i - 1].isLetterOrNumber(); | 1695 | before = isWord( mmIn[mmPos + i - 1] ); |
1684 | if ( mmPos + i != mmLen ) | 1696 | if ( mmPos + i != mmLen ) |
1685 | after = mmIn[mmPos + i].isLetterOrNumber(); | 1697 | after = isWord( mmIn[mmPos + i] ); |
1686 | if ( (a & Anchor_Word) != 0 && (before == after) ) | 1698 | if ( (a & Anchor_Word) != 0 && (before == after) ) |
1687 | return FALSE; | 1699 | return FALSE; |
1688 | if ( (a & Anchor_NonWord) != 0 && (before != after) ) | 1700 | if ( (a & Anchor_NonWord) != 0 && (before != after) ) |
1689 | return FALSE; | 1701 | return FALSE; |
@@ -2631,9 +2643,16 @@ int QRegExpEngine::getEscape() | |||
2631 | yyCharClass->addRange( 0x007f, 0x009f ); | 2643 | yyCharClass->addRange( 0x007f, 0x009f ); |
2632 | return Tok_CharClass; | 2644 | return Tok_CharClass; |
2633 | case 'W': | 2645 | case 'W': |
2634 | // see QChar::isLetterOrNumber() | 2646 | // see QChar::isLetterOrNumber() |
2635 | yyCharClass->addCategories( 0x7ff07f8f ); | 2647 | yyCharClass->addCategories( 0x7fe07f8f ); |
2648 | yyCharClass->addRange( 0x203f, 0x2040 ); | ||
2649 | yyCharClass->addSingleton( 0x2040 ); | ||
2650 | yyCharClass->addSingleton( 0x30fb ); | ||
2651 | yyCharClass->addRange( 0xfe33, 0xfe34 ); | ||
2652 | yyCharClass->addRange( 0xfe4d, 0xfe4f ); | ||
2653 | yyCharClass->addSingleton( 0xff3f ); | ||
2654 | yyCharClass->addSingleton( 0xff65 ); | ||
2636 | return Tok_CharClass; | 2655 | return Tok_CharClass; |
2637 | #endif | 2656 | #endif |
2638 | #ifndef QT_NO_REGEXP_ESCAPE | 2657 | #ifndef QT_NO_REGEXP_ESCAPE |
2639 | case 'b': | 2658 | case 'b': |
@@ -2651,8 +2670,9 @@ int QRegExpEngine::getEscape() | |||
2651 | return Tok_CharClass; | 2670 | return Tok_CharClass; |
2652 | case 'w': | 2671 | case 'w': |
2653 | // see QChar::isLetterOrNumber() | 2672 | // see QChar::isLetterOrNumber() |
2654 | yyCharClass->addCategories( 0x000f8070 ); | 2673 | yyCharClass->addCategories( 0x000f8070 ); |
2674 | yyCharClass->addSingleton( 0x005f ); // '_' | ||
2655 | return Tok_CharClass; | 2675 | return Tok_CharClass; |
2656 | #endif | 2676 | #endif |
2657 | #ifndef QT_NO_REGEXP_ESCAPE | 2677 | #ifndef QT_NO_REGEXP_ESCAPE |
2658 | case 'x': | 2678 | case 'x': |
@@ -3182,9 +3202,10 @@ static QRegExpEngine *newEngine( const QString& pattern, bool caseSensitive ) | |||
3182 | { | 3202 | { |
3183 | #ifndef QT_NO_REGEXP_OPTIM | 3203 | #ifndef QT_NO_REGEXP_OPTIM |
3184 | if ( engineCache != 0 ) { | 3204 | if ( engineCache != 0 ) { |
3185 | #ifdef QT_THREAD_SUPPORT | 3205 | #ifdef QT_THREAD_SUPPORT |
3186 | QMutexLocker locker( qt_global_mutexpool->get( &engineCache ) ); | 3206 | QMutexLocker locker( qt_global_mutexpool ? |
3207 | qt_global_mutexpool->get( &engineCache ) : 0 ); | ||
3187 | #endif | 3208 | #endif |
3188 | QRegExpEngine *eng = engineCache->take( pattern ); | 3209 | QRegExpEngine *eng = engineCache->take( pattern ); |
3189 | if ( eng == 0 || eng->caseSensitive() != caseSensitive ) { | 3210 | if ( eng == 0 || eng->caseSensitive() != caseSensitive ) { |
3190 | delete eng; | 3211 | delete eng; |
@@ -3198,13 +3219,14 @@ static QRegExpEngine *newEngine( const QString& pattern, bool caseSensitive ) | |||
3198 | } | 3219 | } |
3199 | 3220 | ||
3200 | static void derefEngine( QRegExpEngine *eng, const QString& pattern ) | 3221 | static void derefEngine( QRegExpEngine *eng, const QString& pattern ) |
3201 | { | 3222 | { |
3202 | if ( eng != 0 && eng->deref() ) { | ||
3203 | #ifndef QT_NO_REGEXP_OPTIM | ||
3204 | #ifdef QT_THREAD_SUPPORT | 3223 | #ifdef QT_THREAD_SUPPORT |
3205 | QMutexLocker locker( qt_global_mutexpool->get( &engineCache ) ); | 3224 | QMutexLocker locker( qt_global_mutexpool ? |
3225 | qt_global_mutexpool->get( &engineCache ) : 0 ); | ||
3206 | #endif | 3226 | #endif |
3227 | if ( eng != 0 && eng->deref() ) { | ||
3228 | #ifndef QT_NO_REGEXP_OPTIM | ||
3207 | if ( engineCache == 0 ) { | 3229 | if ( engineCache == 0 ) { |
3208 | engineCache = new QCache<QRegExpEngine>; | 3230 | engineCache = new QCache<QRegExpEngine>; |
3209 | engineCache->setAutoDelete( TRUE ); | 3231 | engineCache->setAutoDelete( TRUE ); |
3210 | cleanup_cache.set( &engineCache ); | 3232 | cleanup_cache.set( &engineCache ); |
@@ -3564,15 +3586,8 @@ int QRegExp::match( const QString& str, int index, int *len, | |||
3564 | return pos; | 3586 | return pos; |
3565 | } | 3587 | } |
3566 | #endif // QT_NO_COMPAT | 3588 | #endif // QT_NO_COMPAT |
3567 | 3589 | ||
3568 | /*! | ||
3569 | \overload | ||
3570 | |||
3571 | This convenience function searches with a \c CaretMode of \c | ||
3572 | CaretAtZero which is the most common usage. | ||
3573 | */ | ||
3574 | |||
3575 | int QRegExp::search( const QString& str, int offset ) const | 3590 | int QRegExp::search( const QString& str, int offset ) const |
3576 | { | 3591 | { |
3577 | return search( str, offset, CaretAtZero ); | 3592 | return search( str, offset, CaretAtZero ); |
3578 | } | 3593 | } |
@@ -3624,15 +3639,8 @@ int QRegExp::search( const QString& str, int offset, CaretMode caretMode ) const | |||
3624 | return priv->captured[0]; | 3639 | return priv->captured[0]; |
3625 | } | 3640 | } |
3626 | 3641 | ||
3627 | 3642 | ||
3628 | /*! | ||
3629 | \overload | ||
3630 | |||
3631 | This convenience function searches with a \c CaretMode of \c | ||
3632 | CaretAtZero which is the most common usage. | ||
3633 | */ | ||
3634 | |||
3635 | int QRegExp::searchRev( const QString& str, int offset ) const | 3643 | int QRegExp::searchRev( const QString& str, int offset ) const |
3636 | { | 3644 | { |
3637 | return searchRev( str, offset, CaretAtZero ); | 3645 | return searchRev( str, offset, CaretAtZero ); |
3638 | } | 3646 | } |
diff --git a/qmake/tools/qsemaphore_unix.cpp b/qmake/tools/qsemaphore_unix.cpp index fcf28da..4516049 100644 --- a/qmake/tools/qsemaphore_unix.cpp +++ b/qmake/tools/qsemaphore_unix.cpp | |||
@@ -182,20 +182,19 @@ int QSemaphore::operator+=(int n) | |||
182 | int ret; | 182 | int ret; |
183 | 183 | ||
184 | d->mutex.lock(); | 184 | d->mutex.lock(); |
185 | 185 | ||
186 | if ( n < 0 || n > d->max ) { | ||
187 | #ifdef QT_CHECK_RANGE | ||
188 | qWarning( "QSemaphore::operator+=: paramter %d out of range", n ); | ||
189 | #endif // QT_CHECK_RANGE | ||
190 | n = n < 0 ? 0 : d->max; | ||
191 | } | ||
192 | |||
186 | while (d->value + n > d->max) | 193 | while (d->value + n > d->max) |
187 | d->cond.wait(&(d->mutex)); | 194 | d->cond.wait(&(d->mutex)); |
188 | 195 | ||
189 | d->value += n; | 196 | d->value += n; |
190 | |||
191 | #ifdef QT_CHECK_RANGE | ||
192 | if (d->value > d->max) { | ||
193 | qWarning("QSemaphore::operator+=: attempt to allocate more resources than available"); | ||
194 | d->value = d->max; | ||
195 | } | ||
196 | #endif | ||
197 | |||
198 | ret = d->value; | 197 | ret = d->value; |
199 | 198 | ||
200 | d->mutex.unlock(); | 199 | d->mutex.unlock(); |
201 | 200 | ||
@@ -211,17 +210,16 @@ int QSemaphore::operator-=(int n) | |||
211 | int ret; | 210 | int ret; |
212 | 211 | ||
213 | d->mutex.lock(); | 212 | d->mutex.lock(); |
214 | 213 | ||
215 | d->value -= n; | 214 | if ( n < 0 || n > d->value ) { |
216 | |||
217 | #ifdef QT_CHECK_RANGE | 215 | #ifdef QT_CHECK_RANGE |
218 | if (d->value < 0) { | 216 | qWarning( "QSemaphore::operator-=: paramter %d out of range", n ); |
219 | qWarning("QSemaphore::operator-=: attempt to deallocate more resources than taken"); | 217 | #endif // QT_CHECK_RANGE |
220 | d->value = 0; | 218 | n = n < 0 ? 0 : d->value; |
221 | } | 219 | } |
222 | #endif | ||
223 | 220 | ||
221 | d->value -= n; | ||
224 | ret = d->value; | 222 | ret = d->value; |
225 | 223 | ||
226 | d->cond.wakeOne(); | 224 | d->cond.wakeOne(); |
227 | d->mutex.unlock(); | 225 | d->mutex.unlock(); |
diff --git a/qmake/tools/qsettings.cpp b/qmake/tools/qsettings.cpp index 5de105c..35fc039 100644 --- a/qmake/tools/qsettings.cpp +++ b/qmake/tools/qsettings.cpp | |||
@@ -2,9 +2,9 @@ | |||
2 | ** $Id$ | 2 | ** $Id$ |
3 | ** | 3 | ** |
4 | ** Implementation of QSettings class | 4 | ** Implementation of QSettings class |
5 | ** | 5 | ** |
6 | ** Created: 2000.06.26 | 6 | ** Created : 000626 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
@@ -70,10 +70,10 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) | |||
70 | \ingroup misc | 70 | \ingroup misc |
71 | \mainclass | 71 | \mainclass |
72 | 72 | ||
73 | On Unix systems, QSettings uses text files to store settings. On Windows | 73 | On Unix systems, QSettings uses text files to store settings. On Windows |
74 | systems, QSettings uses the system registry. On Mac OS X, QSettings will | 74 | systems, QSettings uses the system registry. On Mac OS X, QSettings uses |
75 | behave as on Unix, and store to text files. | 75 | the Carbon preferences API. |
76 | 76 | ||
77 | Each setting comprises an identifying key and the data associated with | 77 | Each setting comprises an identifying key and the data associated with |
78 | the key. A key is a unicode string which consists of \e two or more | 78 | the key. A key is a unicode string which consists of \e two or more |
79 | subkeys. A subkey is a slash, '/', followed by one or more unicode | 79 | subkeys. A subkey is a slash, '/', followed by one or more unicode |
@@ -100,27 +100,42 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) | |||
100 | /MyCompany/MyApplication/recent files/3 | 100 | /MyCompany/MyApplication/recent files/3 |
101 | \endcode | 101 | \endcode |
102 | Each line above is a complete key, made up of subkeys. | 102 | Each line above is a complete key, made up of subkeys. |
103 | 103 | ||
104 | A typical usage pattern for application startup: | 104 | A typical usage pattern for reading application startup: |
105 | \code | 105 | \code |
106 | QSettings settings; | 106 | QSettings settings; |
107 | settings.insertSearchPath( QSettings::Windows, "/MyCompany" ); | 107 | settings.setPath( "MyCompany.com", "MyApplication" ); |
108 | // No search path needed for Unix; see notes further on. | 108 | |
109 | // Use default values if the keys don't exist | 109 | QString bgColor = settings.readEntry( "/colors/background", "white" ); |
110 | QString bgColor = settings.readEntry( "/MyApplication/background color", "white" ); | 110 | int width = settings.readNumEntry( "/geometry/width", 640 ); |
111 | int width = settings.readNumEntry( "/MyApplication/geometry/width", 640 ); | ||
112 | // ... | 111 | // ... |
113 | \endcode | 112 | \endcode |
114 | 113 | ||
115 | A typical usage pattern for application exit or 'save preferences': | 114 | A typical usage pattern for application exit or 'save preferences': |
116 | \code | 115 | \code |
117 | QSettings settings; | 116 | QSettings settings; |
118 | settings.insertSearchPath( QSettings::Windows, "/MyCompany" ); | 117 | settings.setPath( "MyCompany.com", "MyApplication" ); |
119 | // No search path needed for Unix; see notes further on. | 118 | |
120 | settings.writeEntry( "/MyApplication/background color", bgColor ); | 119 | settings.writeEntry( "/colors/background", bgColor ); |
121 | settings.writeEntry( "/MyApplication/geometry/width", width ); | 120 | settings.writeEntry( "/geometry/width", width ); |
121 | // ... | ||
122 | \endcode | ||
123 | |||
124 | QSettings can build a key prefix that is prepended to all keys. To | ||
125 | build the key prefix, use beginGroup() and endGroup(). | ||
126 | \code | ||
127 | QSettings settings; | ||
128 | |||
129 | settings.beginGroup( "/MainWindow" ); | ||
130 | settings.beginGroup( "/Geometry" ); | ||
131 | int x = settings.readEntry( "/x" ); | ||
132 | // ... | ||
133 | settings.endGroup(); | ||
134 | settings.beginGroup( "/Toolbars" ); | ||
122 | // ... | 135 | // ... |
136 | settings.endGroup(); | ||
137 | settings.endGroup(); | ||
123 | \endcode | 138 | \endcode |
124 | 139 | ||
125 | You can get a list of entry-holding keys by calling entryList(), and | 140 | You can get a list of entry-holding keys by calling entryList(), and |
126 | a list of key-holding keys using subkeyList(). | 141 | a list of key-holding keys using subkeyList(). |
@@ -138,12 +153,8 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) | |||
138 | QStringList subkeys = subkeyList( "/MyApplication/recent files" ); | 153 | QStringList subkeys = subkeyList( "/MyApplication/recent files" ); |
139 | // subkeys is empty. | 154 | // subkeys is empty. |
140 | \endcode | 155 | \endcode |
141 | 156 | ||
142 | If you wish to use a different search path call insertSearchPath() | ||
143 | as often as necessary to add your preferred paths. Call | ||
144 | removeSearchPath() to remove any unwanted paths. | ||
145 | |||
146 | Since settings for Windows are stored in the registry there are size | 157 | Since settings for Windows are stored in the registry there are size |
147 | limits as follows: | 158 | limits as follows: |
148 | \list | 159 | \list |
149 | \i A subkey may not exceed 255 characters. | 160 | \i A subkey may not exceed 255 characters. |
@@ -151,9 +162,27 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode ) | |||
151 | \i All the values of a key (for example, all the 'recent files' | 162 | \i All the values of a key (for example, all the 'recent files' |
152 | subkeys values), may not exceed 65,535 characters. | 163 | subkeys values), may not exceed 65,535 characters. |
153 | \endlist | 164 | \endlist |
154 | 165 | ||
155 | These limitations are not enforced on Unix. | 166 | These limitations are not enforced on Unix or Mac OS X. |
167 | |||
168 | If you wish to use a different search path call insertSearchPath() | ||
169 | as often as necessary to add your preferred paths. Call | ||
170 | removeSearchPath() to remove any unwanted paths. | ||
171 | |||
172 | \section1 Notes for Mac OS X Applications | ||
173 | |||
174 | Internal to the CFPreferences API it is not defined (for Mac OS 9 | ||
175 | support) where the settings will ultimitely be stored. However, at the | ||
176 | time of this writing the settings will be stored (either on a global or | ||
177 | user basis, preferring locally) into a plist file in | ||
178 | $ROOT/System/Library/Preferences (in XML format). QSettings will create | ||
179 | an appropriate plist file (com.<first group name>.plist) out of the | ||
180 | full path to a key. | ||
181 | |||
182 | For further information on CFPreferences see also | ||
183 | \link http://developer.apple.com/techpubs/macosx/CoreFoundation/PreferenceServices/preferenceservices_carbon.html | ||
184 | Apple's Specifications\endlink | ||
156 | 185 | ||
157 | \section1 Notes for Unix Applications | 186 | \section1 Notes for Unix Applications |
158 | 187 | ||
159 | There is no universally accepted place for storing application | 188 | There is no universally accepted place for storing application |
@@ -299,22 +328,22 @@ static HANDLE openlock( const QString &name, int /*type*/ ) | |||
299 | } , { | 328 | } , { |
300 | fd = CreateFileA( name.local8Bit(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); | 329 | fd = CreateFileA( name.local8Bit(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL ); |
301 | } ); | 330 | } ); |
302 | 331 | ||
303 | if ( !LockFile( fd, 0, 0, -1, -1 ) ) { | 332 | if ( !LockFile( fd, 0, 0, (DWORD)-1, (DWORD)-1 ) ) { // ### (DWORD)-1 ??? |
304 | #ifdef QT_CHECK_STATE | 333 | #ifdef QT_CHECK_STATE |
305 | qWarning( "QSettings: openlock failed!" ); | 334 | qWarning( "QSettings: openlock failed!" ); |
306 | #endif | 335 | #endif |
307 | } | 336 | } |
308 | return fd; | 337 | return fd; |
309 | } | 338 | } |
310 | 339 | ||
311 | void closelock( HANDLE fd ) | 340 | static void closelock( HANDLE fd ) |
312 | { | 341 | { |
313 | if ( !fd ) | 342 | if ( !fd ) |
314 | return; | 343 | return; |
315 | 344 | ||
316 | if ( !UnlockFile( fd, 0, 0, -1, -1 ) ) { | 345 | if ( !UnlockFile( fd, 0, 0, (DWORD)-1, (DWORD)-1 ) ) { // ### (DWORD)-1 ??? |
317 | #ifdef QT_CHECK_STATE | 346 | #ifdef QT_CHECK_STATE |
318 | qWarning( "QSettings: closelock failed!"); | 347 | qWarning( "QSettings: closelock failed!"); |
319 | #endif | 348 | #endif |
320 | } | 349 | } |
@@ -454,11 +483,13 @@ void QSettingsHeading::parseLine(QTextStream &stream) | |||
454 | 483 | ||
455 | QSettingsPrivate::QSettingsPrivate( QSettings::Format format ) | 484 | QSettingsPrivate::QSettingsPrivate( QSettings::Format format ) |
456 | : groupDirty( TRUE ), modified(FALSE), globalScope(TRUE) | 485 | : groupDirty( TRUE ), modified(FALSE), globalScope(TRUE) |
457 | { | 486 | { |
458 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 487 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
459 | if ( format != QSettings::Ini ) | 488 | if ( format != QSettings::Ini ) |
460 | return; | 489 | return; |
490 | #else | ||
491 | Q_UNUSED( format ); | ||
461 | #endif | 492 | #endif |
462 | 493 | ||
463 | QString appSettings(QDir::homeDirPath() + "/.qt/"); | 494 | QString appSettings(QDir::homeDirPath() + "/.qt/"); |
464 | QString defPath; | 495 | QString defPath; |
@@ -505,8 +536,10 @@ QSettingsPrivate::QSettingsPrivate( QSettings::Format format ) | |||
505 | if (! dir.exists()) { | 536 | if (! dir.exists()) { |
506 | if (! dir.mkdir(dir.path())) | 537 | if (! dir.mkdir(dir.path())) |
507 | #if defined(QT_CHECK_STATE) | 538 | #if defined(QT_CHECK_STATE) |
508 | qWarning("QSettings: error creating %s", dir.path().latin1()); | 539 | qWarning("QSettings: error creating %s", dir.path().latin1()); |
540 | #else | ||
541 | ; | ||
509 | #endif | 542 | #endif |
510 | } | 543 | } |
511 | 544 | ||
512 | if ( !!defPath ) | 545 | if ( !!defPath ) |
@@ -529,8 +562,10 @@ QSettingsGroup QSettingsPrivate::readGroup() | |||
529 | 562 | ||
530 | QSettingsHeading::Iterator grpit = hd.find(group); | 563 | QSettingsHeading::Iterator grpit = hd.find(group); |
531 | if (grpit == hd.end()) { | 564 | if (grpit == hd.end()) { |
532 | QStringList::Iterator it = searchPaths.begin(); | 565 | QStringList::Iterator it = searchPaths.begin(); |
566 | if ( !globalScope ) | ||
567 | ++it; | ||
533 | while (it != searchPaths.end()) { | 568 | while (it != searchPaths.end()) { |
534 | QString filebase = heading.lower().replace(QRegExp("\\s+"), "_"); | 569 | QString filebase = heading.lower().replace(QRegExp("\\s+"), "_"); |
535 | QString fn((*it++) + "/" + filebase + "rc"); | 570 | QString fn((*it++) + "/" + filebase + "rc"); |
536 | if (! hd.contains(fn + "cached")) { | 571 | if (! hd.contains(fn + "cached")) { |
@@ -563,8 +598,10 @@ void QSettingsPrivate::removeGroup(const QString &key) | |||
563 | 598 | ||
564 | QSettingsHeading::Iterator grpit = hd.find(group); | 599 | QSettingsHeading::Iterator grpit = hd.find(group); |
565 | if (grpit == hd.end()) { | 600 | if (grpit == hd.end()) { |
566 | QStringList::Iterator it = searchPaths.begin(); | 601 | QStringList::Iterator it = searchPaths.begin(); |
602 | if ( !globalScope ) | ||
603 | ++it; | ||
567 | while (it != searchPaths.end()) { | 604 | while (it != searchPaths.end()) { |
568 | QString filebase = heading.lower().replace(QRegExp("\\s+"), "_"); | 605 | QString filebase = heading.lower().replace(QRegExp("\\s+"), "_"); |
569 | QString fn((*it++) + "/" + filebase + "rc"); | 606 | QString fn((*it++) + "/" + filebase + "rc"); |
570 | if (! hd.contains(fn + "cached")) { | 607 | if (! hd.contains(fn + "cached")) { |
@@ -614,8 +651,10 @@ void QSettingsPrivate::writeGroup(const QString &key, const QString &value) | |||
614 | 651 | ||
615 | QSettingsHeading::Iterator grpit = hd.find(group); | 652 | QSettingsHeading::Iterator grpit = hd.find(group); |
616 | if (grpit == hd.end()) { | 653 | if (grpit == hd.end()) { |
617 | QStringList::Iterator it = searchPaths.begin(); | 654 | QStringList::Iterator it = searchPaths.begin(); |
655 | if ( !globalScope ) | ||
656 | ++it; | ||
618 | while (it != searchPaths.end()) { | 657 | while (it != searchPaths.end()) { |
619 | QString filebase = heading.lower().replace(QRegExp("\\s+"), "_"); | 658 | QString filebase = heading.lower().replace(QRegExp("\\s+"), "_"); |
620 | QString fn((*it++) + "/" + filebase + "rc"); | 659 | QString fn((*it++) + "/" + filebase + "rc"); |
621 | if (! hd.contains(fn + "cached")) { | 660 | if (! hd.contains(fn + "cached")) { |
@@ -648,8 +687,10 @@ QDateTime QSettingsPrivate::modificationTime() | |||
648 | 687 | ||
649 | QDateTime datetime; | 688 | QDateTime datetime; |
650 | 689 | ||
651 | QStringList::Iterator it = searchPaths.begin(); | 690 | QStringList::Iterator it = searchPaths.begin(); |
691 | if ( !globalScope ) | ||
692 | ++it; | ||
652 | while (it != searchPaths.end()) { | 693 | while (it != searchPaths.end()) { |
653 | QFileInfo fi((*it++) + "/" + heading + "rc"); | 694 | QFileInfo fi((*it++) + "/" + heading + "rc"); |
654 | if (fi.exists() && fi.lastModified() > datetime) | 695 | if (fi.exists() && fi.lastModified() > datetime) |
655 | datetime = fi.lastModified(); | 696 | datetime = fi.lastModified(); |
@@ -657,19 +698,25 @@ QDateTime QSettingsPrivate::modificationTime() | |||
657 | 698 | ||
658 | return datetime; | 699 | return datetime; |
659 | } | 700 | } |
660 | 701 | ||
661 | static bool verifyKey( const QString &key ) | 702 | bool qt_verify_key( const QString &key ) |
662 | { | 703 | { |
663 | if ( key.isEmpty() || key[0] != '/' || key.contains( QRegExp("[=\\\\r\\\\n" ) ) ) | 704 | if ( key.isEmpty() || key[0] != '/' || key.contains( QRegExp("[=\\\\r\\\\n" ) ) ) |
664 | return FALSE; | 705 | return FALSE; |
665 | return TRUE; | 706 | return TRUE; |
666 | } | 707 | } |
667 | 708 | ||
668 | static inline QString groupKey( const QString &group, const QString &key ) | 709 | static inline QString groupKey( const QString &group, const QString &key ) |
669 | { | 710 | { |
670 | if ( group.endsWith( "/" ) || key.startsWith( "/" ) ) | 711 | if ( group.isEmpty() || ( group.length() == 1 && group[0] == '/' ) ) { |
712 | // group is empty, or it contains a single '/', so we just return the key | ||
713 | if ( key.startsWith( "/" ) ) | ||
714 | return key; | ||
715 | return "/" + key; | ||
716 | } else if ( group.endsWith( "/" ) || key.startsWith( "/" ) ) { | ||
671 | return group + key; | 717 | return group + key; |
718 | } | ||
672 | return group + "/" + key; | 719 | return group + "/" + key; |
673 | } | 720 | } |
674 | 721 | ||
675 | /*! | 722 | /*! |
@@ -756,36 +803,51 @@ static inline QString groupKey( const QString &group, const QString &key ) | |||
756 | 803 | ||
757 | */ | 804 | */ |
758 | void QSettings::insertSearchPath( System s, const QString &path) | 805 | void QSettings::insertSearchPath( System s, const QString &path) |
759 | { | 806 | { |
760 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 807 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
761 | if ( d->sysd ) { | 808 | if ( d->sysd ) { |
762 | d->sysInsertSearchPath( s, path ); | 809 | d->sysInsertSearchPath( s, path ); |
763 | return; | 810 | return; |
764 | } | 811 | } |
765 | #endif | 812 | #endif |
766 | 813 | ||
767 | if ( !verifyKey( path ) ) { | 814 | #if !defined(Q_WS_WIN) |
815 | if ( s == Windows ) | ||
816 | return; | ||
817 | #endif | ||
818 | #if !defined(Q_WS_WIN) | ||
819 | if ( s == Mac ) | ||
820 | return; | ||
821 | #endif | ||
822 | |||
823 | if ( !qt_verify_key( path ) ) { | ||
768 | #if defined(QT_CHECK_STATE) | 824 | #if defined(QT_CHECK_STATE) |
769 | qWarning( "QSettings::insertSearchPath: Invalid key: '%s'", path.isNull() ? "(null)" : path.latin1() ); | 825 | qWarning( "QSettings::insertSearchPath: Invalid key: '%s'", path.isNull() ? "(null)" : path.latin1() ); |
770 | #endif | 826 | #endif |
771 | return; | 827 | return; |
772 | } | 828 | } |
773 | 829 | ||
774 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 830 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
775 | if ( d->sysd && s != Unix ) { | 831 | if ( d->sysd && s != Unix ) { |
776 | #else | 832 | #else |
777 | if ( s != Unix ) { | 833 | if ( s != Unix ) { |
778 | #endif | 834 | #endif |
779 | #ifdef Q_OS_MAC | 835 | #if !defined(QWS) && defined(Q_OS_MAC) |
780 | if(s != Mac) //mac is respected on the mac as well | 836 | if(s != Mac) //mac is respected on the mac as well |
781 | #endif | 837 | #endif |
782 | return; | 838 | return; |
783 | } | 839 | } |
784 | 840 | ||
841 | QString realPath = path; | ||
842 | #if defined(Q_WS_WIN) | ||
843 | QString defPath = d->globalScope ? d->searchPaths.first() : d->searchPaths.last(); | ||
844 | realPath = defPath + path; | ||
845 | #endif | ||
846 | |||
785 | QStringList::Iterator it = d->searchPaths.find(d->searchPaths.last()); | 847 | QStringList::Iterator it = d->searchPaths.find(d->searchPaths.last()); |
786 | if (it != d->searchPaths.end()) { | 848 | if (it != d->searchPaths.end()) { |
787 | d->searchPaths.insert(it, path); | 849 | d->searchPaths.insert(it, realPath); |
788 | } | 850 | } |
789 | } | 851 | } |
790 | 852 | ||
791 | 853 | ||
@@ -797,9 +859,9 @@ void QSettings::insertSearchPath( System s, const QString &path) | |||
797 | \sa insertSearchPath() | 859 | \sa insertSearchPath() |
798 | */ | 860 | */ |
799 | void QSettings::removeSearchPath( System s, const QString &path) | 861 | void QSettings::removeSearchPath( System s, const QString &path) |
800 | { | 862 | { |
801 | if ( !verifyKey( path ) ) { | 863 | if ( !qt_verify_key( path ) ) { |
802 | #if defined(QT_CHECK_STATE) | 864 | #if defined(QT_CHECK_STATE) |
803 | qWarning( "QSettings::insertSearchPath: Invalid key: '%s'", path.isNull() ? "(null)" : path.latin1() ); | 865 | qWarning( "QSettings::insertSearchPath: Invalid key: '%s'", path.isNull() ? "(null)" : path.latin1() ); |
804 | #endif | 866 | #endif |
805 | return; | 867 | return; |
@@ -810,14 +872,14 @@ void QSettings::removeSearchPath( System s, const QString &path) | |||
810 | d->sysRemoveSearchPath( s, path ); | 872 | d->sysRemoveSearchPath( s, path ); |
811 | return; | 873 | return; |
812 | } | 874 | } |
813 | #endif | 875 | #endif |
814 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 876 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
815 | if ( d->sysd && s != Unix ) { | 877 | if ( d->sysd && s != Unix ) { |
816 | #else | 878 | #else |
817 | if ( s != Unix ) { | 879 | if ( s != Unix ) { |
818 | #endif | 880 | #endif |
819 | #ifdef Q_OS_MAC | 881 | #if !defined(QWS) && defined(Q_OS_MAC) |
820 | if(s != Mac) //mac is respected on the mac as well | 882 | if(s != Mac) //mac is respected on the mac as well |
821 | #endif | 883 | #endif |
822 | return; | 884 | return; |
823 | } | 885 | } |
@@ -836,9 +898,9 @@ QSettings::QSettings() | |||
836 | { | 898 | { |
837 | d = new QSettingsPrivate( Native ); | 899 | d = new QSettingsPrivate( Native ); |
838 | Q_CHECK_PTR(d); | 900 | Q_CHECK_PTR(d); |
839 | 901 | ||
840 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 902 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
841 | d->sysd = 0; | 903 | d->sysd = 0; |
842 | d->sysInit(); | 904 | d->sysInit(); |
843 | #endif | 905 | #endif |
844 | } | 906 | } |
@@ -853,9 +915,9 @@ QSettings::QSettings( Format format ) | |||
853 | { | 915 | { |
854 | d = new QSettingsPrivate( format ); | 916 | d = new QSettingsPrivate( format ); |
855 | Q_CHECK_PTR(d); | 917 | Q_CHECK_PTR(d); |
856 | 918 | ||
857 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 919 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
858 | d->sysd = 0; | 920 | d->sysd = 0; |
859 | if ( format == Native ) | 921 | if ( format == Native ) |
860 | d->sysInit(); | 922 | d->sysInit(); |
861 | #else | 923 | #else |
@@ -871,9 +933,9 @@ QSettings::QSettings( Format format ) | |||
871 | QSettings::~QSettings() | 933 | QSettings::~QSettings() |
872 | { | 934 | { |
873 | sync(); | 935 | sync(); |
874 | 936 | ||
875 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 937 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
876 | if ( d->sysd ) | 938 | if ( d->sysd ) |
877 | d->sysClear(); | 939 | d->sysClear(); |
878 | #endif | 940 | #endif |
879 | 941 | ||
@@ -886,9 +948,9 @@ QSettings::~QSettings() | |||
886 | encountered, this function returns FALSE, otherwise it will return TRUE. | 948 | encountered, this function returns FALSE, otherwise it will return TRUE. |
887 | */ | 949 | */ |
888 | bool QSettings::sync() | 950 | bool QSettings::sync() |
889 | { | 951 | { |
890 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 952 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
891 | if ( d->sysd ) | 953 | if ( d->sysd ) |
892 | return d->sysSync(); | 954 | return d->sysSync(); |
893 | #endif | 955 | #endif |
894 | if (! d->modified) | 956 | if (! d->modified) |
@@ -904,8 +966,10 @@ bool QSettings::sync() | |||
904 | QSettingsHeading::Iterator hdit = hd.begin(); | 966 | QSettingsHeading::Iterator hdit = hd.begin(); |
905 | QFile file; | 967 | QFile file; |
906 | 968 | ||
907 | QStringList::Iterator pit = d->searchPaths.begin(); | 969 | QStringList::Iterator pit = d->searchPaths.begin(); |
970 | if ( !d->globalScope ) | ||
971 | ++pit; | ||
908 | while (pit != d->searchPaths.end()) { | 972 | while (pit != d->searchPaths.end()) { |
909 | QString filebase = it.key().lower().replace(QRegExp("\\s+"), "_"); | 973 | QString filebase = it.key().lower().replace(QRegExp("\\s+"), "_"); |
910 | QFileInfo di(*pit); | 974 | QFileInfo di(*pit); |
911 | QFileInfo fi((*pit++) + "/" + filebase + "rc"); | 975 | QFileInfo fi((*pit++) + "/" + filebase + "rc"); |
@@ -916,11 +980,11 @@ bool QSettings::sync() | |||
916 | break; | 980 | break; |
917 | } | 981 | } |
918 | } | 982 | } |
919 | 983 | ||
920 | it++; | 984 | ++it; |
921 | 985 | ||
922 | if (file.name().isNull() || file.name().isEmpty()) { | 986 | if ( file.name().isEmpty() ) { |
923 | 987 | ||
924 | #ifdef QT_CHECK_STATE | 988 | #ifdef QT_CHECK_STATE |
925 | qWarning("QSettings::sync: filename is null/empty"); | 989 | qWarning("QSettings::sync: filename is null/empty"); |
926 | #endif // QT_CHECK_STATE | 990 | #endif // QT_CHECK_STATE |
@@ -962,15 +1026,15 @@ bool QSettings::sync() | |||
962 | v.replace("\n", "\\n"); // escape newlines | 1026 | v.replace("\n", "\\n"); // escape newlines |
963 | } | 1027 | } |
964 | 1028 | ||
965 | stream << grpit.key() << "=" << v << endl; | 1029 | stream << grpit.key() << "=" << v << endl; |
966 | grpit++; | 1030 | ++grpit; |
967 | } | 1031 | } |
968 | 1032 | ||
969 | stream << endl; | 1033 | stream << endl; |
970 | } | 1034 | } |
971 | 1035 | ||
972 | hdit++; | 1036 | ++hdit; |
973 | } | 1037 | } |
974 | 1038 | ||
975 | if (file.status() != IO_Ok) { | 1039 | if (file.status() != IO_Ok) { |
976 | 1040 | ||
@@ -1007,9 +1071,9 @@ bool QSettings::sync() | |||
1007 | \internal | 1071 | \internal |
1008 | */ | 1072 | */ |
1009 | bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok ) | 1073 | bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok ) |
1010 | { | 1074 | { |
1011 | if ( !verifyKey( key ) ) { | 1075 | if ( !qt_verify_key( key ) ) { |
1012 | #if defined(QT_CHECK_STATE) | 1076 | #if defined(QT_CHECK_STATE) |
1013 | qWarning( "QSettings::readBoolEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1077 | qWarning( "QSettings::readBoolEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1014 | #endif | 1078 | #endif |
1015 | if ( ok ) | 1079 | if ( ok ) |
@@ -1017,15 +1081,14 @@ bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok ) | |||
1017 | 1081 | ||
1018 | return def; | 1082 | return def; |
1019 | } | 1083 | } |
1020 | 1084 | ||
1021 | QString theKey = groupKey( group(), key ); | 1085 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1022 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | ||
1023 | if ( d->sysd ) | 1086 | if ( d->sysd ) |
1024 | return d->sysReadBoolEntry( theKey, def, ok ); | 1087 | return d->sysReadBoolEntry( groupKey( group(), key ), def, ok ); |
1025 | #endif | 1088 | #endif |
1026 | 1089 | ||
1027 | QString value = readEntry( theKey, ( def ? "true" : "false" ), ok ); | 1090 | QString value = readEntry( key, ( def ? "true" : "false" ), ok ); |
1028 | 1091 | ||
1029 | if (value.lower() == "true") | 1092 | if (value.lower() == "true") |
1030 | return TRUE; | 1093 | return TRUE; |
1031 | else if (value.lower() == "false") | 1094 | else if (value.lower() == "false") |
@@ -1059,9 +1122,9 @@ bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok ) | |||
1059 | \internal | 1122 | \internal |
1060 | */ | 1123 | */ |
1061 | double QSettings::readDoubleEntry(const QString &key, double def, bool *ok ) | 1124 | double QSettings::readDoubleEntry(const QString &key, double def, bool *ok ) |
1062 | { | 1125 | { |
1063 | if ( !verifyKey( key ) ) { | 1126 | if ( !qt_verify_key( key ) ) { |
1064 | #if defined(QT_CHECK_STATE) | 1127 | #if defined(QT_CHECK_STATE) |
1065 | qWarning( "QSettings::readDoubleEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1128 | qWarning( "QSettings::readDoubleEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1066 | #endif | 1129 | #endif |
1067 | if ( ok ) | 1130 | if ( ok ) |
@@ -1069,15 +1132,14 @@ double QSettings::readDoubleEntry(const QString &key, double def, bool *ok ) | |||
1069 | 1132 | ||
1070 | return def; | 1133 | return def; |
1071 | } | 1134 | } |
1072 | 1135 | ||
1073 | QString theKey = groupKey( group(), key ); | 1136 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1074 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | ||
1075 | if ( d->sysd ) | 1137 | if ( d->sysd ) |
1076 | return d->sysReadDoubleEntry( theKey, def, ok ); | 1138 | return d->sysReadDoubleEntry( groupKey( group(), key ), def, ok ); |
1077 | #endif | 1139 | #endif |
1078 | 1140 | ||
1079 | QString value = readEntry( theKey, QString::number(def), ok ); | 1141 | QString value = readEntry( key, QString::number(def), ok ); |
1080 | bool conv_ok; | 1142 | bool conv_ok; |
1081 | double retval = value.toDouble( &conv_ok ); | 1143 | double retval = value.toDouble( &conv_ok ); |
1082 | if ( conv_ok ) | 1144 | if ( conv_ok ) |
1083 | return retval; | 1145 | return retval; |
@@ -1105,25 +1167,23 @@ double QSettings::readDoubleEntry(const QString &key, double def, bool *ok ) | |||
1105 | \internal | 1167 | \internal |
1106 | */ | 1168 | */ |
1107 | int QSettings::readNumEntry(const QString &key, int def, bool *ok ) | 1169 | int QSettings::readNumEntry(const QString &key, int def, bool *ok ) |
1108 | { | 1170 | { |
1109 | if ( !verifyKey( key ) ) { | 1171 | if ( !qt_verify_key( key ) ) { |
1110 | #if defined(QT_CHECK_STATE) | 1172 | #if defined(QT_CHECK_STATE) |
1111 | qWarning( "QSettings::readNumEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1173 | qWarning( "QSettings::readNumEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1112 | #endif | 1174 | #endif |
1113 | if ( ok ) | 1175 | if ( ok ) |
1114 | *ok = FALSE; | 1176 | *ok = FALSE; |
1115 | return def; | 1177 | return def; |
1116 | } | 1178 | } |
1117 | 1179 | ||
1118 | QString theKey = groupKey( group(), key ); | 1180 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1119 | |||
1120 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | ||
1121 | if ( d->sysd ) | 1181 | if ( d->sysd ) |
1122 | return d->sysReadNumEntry( theKey, def, ok ); | 1182 | return d->sysReadNumEntry( groupKey( group(), key ), def, ok ); |
1123 | #endif | 1183 | #endif |
1124 | 1184 | ||
1125 | QString value = readEntry( theKey, QString::number( def ), ok ); | 1185 | QString value = readEntry( key, QString::number( def ), ok ); |
1126 | bool conv_ok; | 1186 | bool conv_ok; |
1127 | int retval = value.toInt( &conv_ok ); | 1187 | int retval = value.toInt( &conv_ok ); |
1128 | if ( conv_ok ) | 1188 | if ( conv_ok ) |
1129 | return retval; | 1189 | return retval; |
@@ -1151,9 +1211,9 @@ int QSettings::readNumEntry(const QString &key, int def, bool *ok ) | |||
1151 | \internal | 1211 | \internal |
1152 | */ | 1212 | */ |
1153 | QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) | 1213 | QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) |
1154 | { | 1214 | { |
1155 | if ( !verifyKey( key ) ) { | 1215 | if ( !qt_verify_key( key ) ) { |
1156 | #if defined(QT_CHECK_STATE) | 1216 | #if defined(QT_CHECK_STATE) |
1157 | qWarning( "QSettings::readEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1217 | qWarning( "QSettings::readEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1158 | #endif | 1218 | #endif |
1159 | if ( ok ) | 1219 | if ( ok ) |
@@ -1163,9 +1223,9 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) | |||
1163 | } | 1223 | } |
1164 | 1224 | ||
1165 | QString theKey = groupKey( group(), key ); | 1225 | QString theKey = groupKey( group(), key ); |
1166 | 1226 | ||
1167 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 1227 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1168 | if ( d->sysd ) | 1228 | if ( d->sysd ) |
1169 | return d->sysReadEntry( theKey, def, ok ); | 1229 | return d->sysReadEntry( theKey, def, ok ); |
1170 | #endif | 1230 | #endif |
1171 | 1231 | ||
@@ -1205,13 +1265,15 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) | |||
1205 | } else | 1265 | } else |
1206 | realkey = theKey; | 1266 | realkey = theKey; |
1207 | 1267 | ||
1208 | QSettingsGroup grp = d->readGroup(); | 1268 | QSettingsGroup grp = d->readGroup(); |
1209 | QString retval = grp[realkey]; | 1269 | QSettingsGroup::const_iterator it = grp.find( realkey ), end = grp.end(); |
1210 | if ( retval.isNull() ) | 1270 | QString retval = def; |
1211 | retval = def; | 1271 | if ( it != end ) { |
1212 | else if ( ok ) // everything is ok | 1272 | // found the value we needed |
1213 | *ok = TRUE; | 1273 | retval = *it; |
1274 | if ( ok ) *ok = TRUE; | ||
1275 | } | ||
1214 | return retval; | 1276 | return retval; |
1215 | } | 1277 | } |
1216 | 1278 | ||
1217 | 1279 | ||
@@ -1227,23 +1289,21 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok ) | |||
1227 | \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() | 1289 | \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() |
1228 | */ | 1290 | */ |
1229 | bool QSettings::writeEntry(const QString &key, bool value) | 1291 | bool QSettings::writeEntry(const QString &key, bool value) |
1230 | { | 1292 | { |
1231 | if ( !verifyKey( key ) ) { | 1293 | if ( !qt_verify_key( key ) ) { |
1232 | #if defined(QT_CHECK_STATE) | 1294 | #if defined(QT_CHECK_STATE) |
1233 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1295 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1234 | #endif | 1296 | #endif |
1235 | return FALSE; | 1297 | return FALSE; |
1236 | } | 1298 | } |
1237 | 1299 | ||
1238 | QString theKey = groupKey( group(), key ); | 1300 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1239 | |||
1240 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | ||
1241 | if ( d->sysd ) | 1301 | if ( d->sysd ) |
1242 | return d->sysWriteEntry( theKey, value ); | 1302 | return d->sysWriteEntry( groupKey( group(), key ), value ); |
1243 | #endif | 1303 | #endif |
1244 | QString s(value ? "true" : "false"); | 1304 | QString s(value ? "true" : "false"); |
1245 | return writeEntry(theKey, s); | 1305 | return writeEntry(key, s); |
1246 | } | 1306 | } |
1247 | #endif | 1307 | #endif |
1248 | 1308 | ||
1249 | 1309 | ||
@@ -1259,23 +1319,21 @@ bool QSettings::writeEntry(const QString &key, bool value) | |||
1259 | \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() | 1319 | \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() |
1260 | */ | 1320 | */ |
1261 | bool QSettings::writeEntry(const QString &key, double value) | 1321 | bool QSettings::writeEntry(const QString &key, double value) |
1262 | { | 1322 | { |
1263 | if ( !verifyKey( key ) ) { | 1323 | if ( !qt_verify_key( key ) ) { |
1264 | #if defined(QT_CHECK_STATE) | 1324 | #if defined(QT_CHECK_STATE) |
1265 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1325 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1266 | #endif | 1326 | #endif |
1267 | return FALSE; | 1327 | return FALSE; |
1268 | } | 1328 | } |
1269 | 1329 | ||
1270 | QString theKey = groupKey( group(), key ); | 1330 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1271 | |||
1272 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | ||
1273 | if ( d->sysd ) | 1331 | if ( d->sysd ) |
1274 | return d->sysWriteEntry( theKey, value ); | 1332 | return d->sysWriteEntry( groupKey( group(), key ), value ); |
1275 | #endif | 1333 | #endif |
1276 | QString s(QString::number(value)); | 1334 | QString s(QString::number(value)); |
1277 | return writeEntry(theKey, s); | 1335 | return writeEntry(key, s); |
1278 | } | 1336 | } |
1279 | 1337 | ||
1280 | 1338 | ||
1281 | /*! | 1339 | /*! |
@@ -1290,23 +1348,21 @@ bool QSettings::writeEntry(const QString &key, double value) | |||
1290 | \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() | 1348 | \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() |
1291 | */ | 1349 | */ |
1292 | bool QSettings::writeEntry(const QString &key, int value) | 1350 | bool QSettings::writeEntry(const QString &key, int value) |
1293 | { | 1351 | { |
1294 | if ( !verifyKey( key ) ) { | 1352 | if ( !qt_verify_key( key ) ) { |
1295 | #if defined(QT_CHECK_STATE) | 1353 | #if defined(QT_CHECK_STATE) |
1296 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1354 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1297 | #endif | 1355 | #endif |
1298 | return FALSE; | 1356 | return FALSE; |
1299 | } | 1357 | } |
1300 | 1358 | ||
1301 | QString theKey = groupKey( group(), key ); | 1359 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1302 | |||
1303 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | ||
1304 | if ( d->sysd ) | 1360 | if ( d->sysd ) |
1305 | return d->sysWriteEntry( theKey, value ); | 1361 | return d->sysWriteEntry( groupKey( group(), key ), value ); |
1306 | #endif | 1362 | #endif |
1307 | QString s(QString::number(value)); | 1363 | QString s(QString::number(value)); |
1308 | return writeEntry(theKey, s); | 1364 | return writeEntry(key, s); |
1309 | } | 1365 | } |
1310 | 1366 | ||
1311 | 1367 | ||
1312 | /*! | 1368 | /*! |
@@ -1326,18 +1382,16 @@ bool QSettings::writeEntry(const QString &key, int value) | |||
1326 | \sa readEntry(), removeEntry() | 1382 | \sa readEntry(), removeEntry() |
1327 | */ | 1383 | */ |
1328 | bool QSettings::writeEntry(const QString &key, const char *value) | 1384 | bool QSettings::writeEntry(const QString &key, const char *value) |
1329 | { | 1385 | { |
1330 | if ( !verifyKey( key ) ) { | 1386 | if ( !qt_verify_key( key ) ) { |
1331 | #if defined(QT_CHECK_STATE) | 1387 | #if defined(QT_CHECK_STATE) |
1332 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1388 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1333 | #endif | 1389 | #endif |
1334 | return FALSE; | 1390 | return FALSE; |
1335 | } | 1391 | } |
1336 | 1392 | ||
1337 | QString theKey = groupKey( group(), key ); | 1393 | return writeEntry(key, QString(value)); |
1338 | |||
1339 | return writeEntry(theKey, QString(value)); | ||
1340 | } | 1394 | } |
1341 | 1395 | ||
1342 | 1396 | ||
1343 | /*! | 1397 | /*! |
@@ -1353,18 +1407,18 @@ bool QSettings::writeEntry(const QString &key, const char *value) | |||
1353 | \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() | 1407 | \sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry() |
1354 | */ | 1408 | */ |
1355 | bool QSettings::writeEntry(const QString &key, const QString &value) | 1409 | bool QSettings::writeEntry(const QString &key, const QString &value) |
1356 | { | 1410 | { |
1357 | if ( !verifyKey( key ) ) { | 1411 | if ( !qt_verify_key( key ) ) { |
1358 | #if defined(QT_CHECK_STATE) | 1412 | #if defined(QT_CHECK_STATE) |
1359 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1413 | qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1360 | #endif | 1414 | #endif |
1361 | return FALSE; | 1415 | return FALSE; |
1362 | } | 1416 | } |
1363 | 1417 | ||
1364 | QString theKey = groupKey( group(), key ); | 1418 | QString theKey = groupKey( group(), key ); |
1365 | 1419 | ||
1366 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 1420 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1367 | if ( d->sysd ) | 1421 | if ( d->sysd ) |
1368 | return d->sysWriteEntry( theKey, value ); | 1422 | return d->sysWriteEntry( theKey, value ); |
1369 | #endif | 1423 | #endif |
1370 | // NOTE: we *do* allow value to be a null/empty string | 1424 | // NOTE: we *do* allow value to be a null/empty string |
@@ -1414,18 +1468,18 @@ bool QSettings::writeEntry(const QString &key, const QString &value) | |||
1414 | \sa readEntry(), writeEntry() | 1468 | \sa readEntry(), writeEntry() |
1415 | */ | 1469 | */ |
1416 | bool QSettings::removeEntry(const QString &key) | 1470 | bool QSettings::removeEntry(const QString &key) |
1417 | { | 1471 | { |
1418 | if ( !verifyKey( key ) ) { | 1472 | if ( !qt_verify_key( key ) ) { |
1419 | #if defined(QT_CHECK_STATE) | 1473 | #if defined(QT_CHECK_STATE) |
1420 | qWarning( "QSettings::removeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1474 | qWarning( "QSettings::removeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1421 | #endif | 1475 | #endif |
1422 | return FALSE; | 1476 | return FALSE; |
1423 | } | 1477 | } |
1424 | 1478 | ||
1425 | QString theKey = groupKey( group(), key ); | 1479 | QString theKey = groupKey( group(), key ); |
1426 | 1480 | ||
1427 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 1481 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1428 | if ( d->sysd ) | 1482 | if ( d->sysd ) |
1429 | return d->sysRemoveEntry( theKey ); | 1483 | return d->sysRemoveEntry( theKey ); |
1430 | #endif | 1484 | #endif |
1431 | 1485 | ||
@@ -1493,18 +1547,18 @@ bool QSettings::removeEntry(const QString &key) | |||
1493 | \sa subkeyList() | 1547 | \sa subkeyList() |
1494 | */ | 1548 | */ |
1495 | QStringList QSettings::entryList(const QString &key) const | 1549 | QStringList QSettings::entryList(const QString &key) const |
1496 | { | 1550 | { |
1497 | if ( !verifyKey( key ) ) { | 1551 | if ( !qt_verify_key( key ) ) { |
1498 | #if defined(QT_CHECK_STATE) | 1552 | #if defined(QT_CHECK_STATE) |
1499 | qWarning( "QSettings::entryList: Invalid key: %s", key.isNull() ? "(null)" : key.latin1() ); | 1553 | qWarning( "QSettings::entryList: Invalid key: %s", key.isNull() ? "(null)" : key.latin1() ); |
1500 | #endif | 1554 | #endif |
1501 | return QStringList(); | 1555 | return QStringList(); |
1502 | } | 1556 | } |
1503 | 1557 | ||
1504 | QString theKey = groupKey( group(), key ); | 1558 | QString theKey = groupKey( group(), key ); |
1505 | 1559 | ||
1506 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 1560 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1507 | if ( d->sysd ) | 1561 | if ( d->sysd ) |
1508 | return d->sysEntryList( theKey ); | 1562 | return d->sysEntryList( theKey ); |
1509 | #endif | 1563 | #endif |
1510 | 1564 | ||
@@ -1543,9 +1597,9 @@ QStringList QSettings::entryList(const QString &key) const | |||
1543 | QStringList ret; | 1597 | QStringList ret; |
1544 | QString itkey; | 1598 | QString itkey; |
1545 | while (it != grp.end()) { | 1599 | while (it != grp.end()) { |
1546 | itkey = it.key(); | 1600 | itkey = it.key(); |
1547 | it++; | 1601 | ++it; |
1548 | 1602 | ||
1549 | if ( realkey.length() > 0 ) { | 1603 | if ( realkey.length() > 0 ) { |
1550 | if ( itkey.left( realkey.length() ) != realkey ) | 1604 | if ( itkey.left( realkey.length() ) != realkey ) |
1551 | continue; | 1605 | continue; |
@@ -1590,23 +1644,24 @@ QStringList QSettings::entryList(const QString &key) const | |||
1590 | \sa entryList() | 1644 | \sa entryList() |
1591 | */ | 1645 | */ |
1592 | QStringList QSettings::subkeyList(const QString &key) const | 1646 | QStringList QSettings::subkeyList(const QString &key) const |
1593 | { | 1647 | { |
1594 | if ( !verifyKey( key ) ) { | 1648 | if ( !qt_verify_key( key ) ) { |
1595 | #if defined(QT_CHECK_STATE) | 1649 | #if defined(QT_CHECK_STATE) |
1596 | qWarning( "QSettings::subkeyList: Invalid key: %s", key.isNull() ? "(null)" : key.latin1() ); | 1650 | qWarning( "QSettings::subkeyList: Invalid key: %s", key.isNull() ? "(null)" : key.latin1() ); |
1597 | #endif | 1651 | #endif |
1598 | return QStringList(); | 1652 | return QStringList(); |
1599 | } | 1653 | } |
1600 | 1654 | ||
1601 | QString theKey = groupKey( group(), key ); | 1655 | QString theKey = groupKey( group(), key ); |
1602 | 1656 | ||
1603 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 1657 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1604 | if ( d->sysd ) | 1658 | if ( d->sysd ) |
1605 | return d->sysSubkeyList( theKey ); | 1659 | return d->sysSubkeyList( theKey ); |
1606 | #endif | 1660 | #endif |
1607 | 1661 | ||
1608 | QString realkey; | 1662 | QString realkey; |
1663 | int subkeycount = 2; | ||
1609 | if (theKey[0] == '/') { | 1664 | if (theKey[0] == '/') { |
1610 | // parse our key | 1665 | // parse our key |
1611 | QStringList list(QStringList::split('/', theKey)); | 1666 | QStringList list(QStringList::split('/', theKey)); |
1612 | 1667 | ||
@@ -1617,8 +1672,10 @@ QStringList QSettings::subkeyList(const QString &key) const | |||
1617 | 1672 | ||
1618 | return QStringList(); | 1673 | return QStringList(); |
1619 | } | 1674 | } |
1620 | 1675 | ||
1676 | subkeycount = list.count(); | ||
1677 | |||
1621 | if (list.count() == 1) { | 1678 | if (list.count() == 1) { |
1622 | d->heading = list[0]; | 1679 | d->heading = list[0]; |
1623 | d->group = "General"; | 1680 | d->group = "General"; |
1624 | } else { | 1681 | } else { |
@@ -1631,18 +1688,30 @@ QStringList QSettings::subkeyList(const QString &key) const | |||
1631 | list.remove(list.at(0)); | 1688 | list.remove(list.at(0)); |
1632 | 1689 | ||
1633 | realkey = list.join("/"); | 1690 | realkey = list.join("/"); |
1634 | } | 1691 | } |
1692 | |||
1635 | } else | 1693 | } else |
1636 | realkey = theKey; | 1694 | realkey = theKey; |
1637 | 1695 | ||
1696 | QStringList ret; | ||
1697 | if ( subkeycount == 1 ) { | ||
1698 | QMap<QString,QSettingsHeading>::Iterator it = d->headings.begin(); | ||
1699 | while ( it != d->headings.end() ) { | ||
1700 | if ( it.key() != "General" && ! ret.contains( it.key() ) ) | ||
1701 | ret << it.key(); | ||
1702 | ++it; | ||
1703 | } | ||
1704 | |||
1705 | return ret; | ||
1706 | } | ||
1707 | |||
1638 | QSettingsGroup grp = d->readGroup(); | 1708 | QSettingsGroup grp = d->readGroup(); |
1639 | QSettingsGroup::Iterator it = grp.begin(); | 1709 | QSettingsGroup::Iterator it = grp.begin(); |
1640 | QStringList ret; | ||
1641 | QString itkey; | 1710 | QString itkey; |
1642 | while (it != grp.end()) { | 1711 | while (it != grp.end()) { |
1643 | itkey = it.key(); | 1712 | itkey = it.key(); |
1644 | it++; | 1713 | ++it; |
1645 | 1714 | ||
1646 | if ( realkey.length() > 0 ) { | 1715 | if ( realkey.length() > 0 ) { |
1647 | if ( itkey.left( realkey.length() ) != realkey ) | 1716 | if ( itkey.left( realkey.length() ) != realkey ) |
1648 | continue; | 1717 | continue; |
@@ -1669,18 +1738,18 @@ QStringList QSettings::subkeyList(const QString &key) const | |||
1669 | This function returns the time of last modification for \a key. | 1738 | This function returns the time of last modification for \a key. |
1670 | */ | 1739 | */ |
1671 | QDateTime QSettings::lastModficationTime(const QString &key) | 1740 | QDateTime QSettings::lastModficationTime(const QString &key) |
1672 | { | 1741 | { |
1673 | if ( !verifyKey( key ) ) { | 1742 | if ( !qt_verify_key( key ) ) { |
1674 | #if defined(QT_CHECK_STATE) | 1743 | #if defined(QT_CHECK_STATE) |
1675 | qWarning( "QSettings::lastModficationTime: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); | 1744 | qWarning( "QSettings::lastModficationTime: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() ); |
1676 | #endif | 1745 | #endif |
1677 | return QDateTime(); | 1746 | return QDateTime(); |
1678 | } | 1747 | } |
1679 | 1748 | ||
1680 | QString theKey = groupKey( group(), key ); | 1749 | QString theKey = groupKey( group(), key ); |
1681 | 1750 | ||
1682 | #if defined(Q_WS_WIN) || defined(Q_OS_MAC) | 1751 | #if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC)) |
1683 | if ( d->sysd ) | 1752 | if ( d->sysd ) |
1684 | return QDateTime(); | 1753 | return QDateTime(); |
1685 | #endif | 1754 | #endif |
1686 | 1755 | ||
@@ -1714,11 +1783,19 @@ QDateTime QSettings::lastModficationTime(const QString &key) | |||
1714 | 1783 | ||
1715 | Writes the string list entry \a value into key \a key. The \a key | 1784 | Writes the string list entry \a value into key \a key. The \a key |
1716 | is created if it doesn't exist. Any previous value is overwritten | 1785 | is created if it doesn't exist. Any previous value is overwritten |
1717 | by \a value. The list is stored as a sequence of strings separated | 1786 | by \a value. The list is stored as a sequence of strings separated |
1718 | by \a separator, so none of the strings in the list should contain | 1787 | by \a separator (using QStringList::join()), so none of the |
1719 | the separator. If the list is empty or null the key's value will | 1788 | strings in the list should contain the separator. If the list is |
1720 | be an empty string. | 1789 | empty or null the key's value will be an empty string. |
1790 | |||
1791 | \warning The list should not contain empty or null strings, as | ||
1792 | readListEntry() will use QStringList::split() to recreate the | ||
1793 | list. As the documentation states, QStringList::split() will omit | ||
1794 | empty strings from the list. Because of this, it is impossible to | ||
1795 | retrieve identical list data that is stored with this function. | ||
1796 | We recommend using the writeEntry() and readListEntry() overloads | ||
1797 | that do not take a \a separator argument. | ||
1721 | 1798 | ||
1722 | If an error occurs the settings are left unchanged and FALSE is | 1799 | If an error occurs the settings are left unchanged and FALSE is |
1723 | returned; otherwise returns TRUE. | 1800 | returned; otherwise returns TRUE. |
1724 | 1801 | ||
@@ -1767,8 +1844,15 @@ bool QSettings::writeEntry(const QString &key, const QStringList &value) | |||
1767 | is used to create a QStringList by calling QStringList::split(\a | 1844 | is used to create a QStringList by calling QStringList::split(\a |
1768 | separator, entry). If \a ok is not 0: \a *ok is set to TRUE if the | 1845 | separator, entry). If \a ok is not 0: \a *ok is set to TRUE if the |
1769 | key was read, otherwise \a *ok is set to FALSE. | 1846 | key was read, otherwise \a *ok is set to FALSE. |
1770 | 1847 | ||
1848 | \warning As the documentation states, QStringList::split() will | ||
1849 | omit empty strings from the list. Because of this, it is | ||
1850 | impossible to retrieve identical list data with this function. We | ||
1851 | recommend using the readListEntry() and writeEntry() overloads | ||
1852 | that do not take a \a separator argument. | ||
1853 | |||
1854 | |||
1771 | Note that if you want to iterate over the list, you should iterate | 1855 | Note that if you want to iterate over the list, you should iterate |
1772 | over a copy, e.g. | 1856 | over a copy, e.g. |
1773 | \code | 1857 | \code |
1774 | QStringList list = mySettings.readListEntry( "size", " " ); | 1858 | QStringList list = mySettings.readListEntry( "size", " " ); |
@@ -1846,8 +1930,12 @@ QStringList QSettings::readListEntry(const QString &key, bool *ok ) | |||
1846 | } | 1930 | } |
1847 | return l; | 1931 | return l; |
1848 | } | 1932 | } |
1849 | 1933 | ||
1934 | #ifdef Q_OS_MAC | ||
1935 | void qt_setSettingsBasePath(const QString &); //qsettings_mac.cpp | ||
1936 | #endif | ||
1937 | |||
1850 | /*! | 1938 | /*! |
1851 | Insert platform-dependent paths from platform-independent information. | 1939 | Insert platform-dependent paths from platform-independent information. |
1852 | 1940 | ||
1853 | The \a domain should be an Internet domain name | 1941 | The \a domain should be an Internet domain name |
@@ -1859,8 +1947,11 @@ QStringList QSettings::readListEntry(const QString &key, bool *ok ) | |||
1859 | The \a scope should be | 1947 | The \a scope should be |
1860 | QSettings::User for user-specific settings, or | 1948 | QSettings::User for user-specific settings, or |
1861 | QSettings::Global for system-wide settings (generally | 1949 | QSettings::Global for system-wide settings (generally |
1862 | these will be read-only to many users). | 1950 | these will be read-only to many users). |
1951 | |||
1952 | Not all information is relevant on all systems (e.g. scoping is | ||
1953 | currently used only if QSettings accesses the Windows registry). | ||
1863 | */ | 1954 | */ |
1864 | 1955 | ||
1865 | void QSettings::setPath( const QString &domain, const QString &product, Scope scope ) | 1956 | void QSettings::setPath( const QString &domain, const QString &product, Scope scope ) |
1866 | { | 1957 | { |
@@ -1879,30 +1970,37 @@ void QSettings::setPath( const QString &domain, const QString &product, Scope sc | |||
1879 | // The Global scope corresponds to /Library/Preferences/*.plist, while the | 1970 | // The Global scope corresponds to /Library/Preferences/*.plist, while the |
1880 | // User scope corresponds to ~/Library/Preferences/*.plist. | 1971 | // User scope corresponds to ~/Library/Preferences/*.plist. |
1881 | // Note that on most installations, not all users can write to the System | 1972 | // Note that on most installations, not all users can write to the System |
1882 | // scope. | 1973 | // scope. |
1974 | d->globalScope = scope == Global; | ||
1975 | |||
1883 | QString actualSearchPath; | 1976 | QString actualSearchPath; |
1884 | int lastDot = domain.findRev( '.' ); | 1977 | int lastDot = domain.findRev( '.' ); |
1885 | 1978 | ||
1886 | #if defined(Q_WS_WIN) | 1979 | #if defined(Q_WS_WIN) |
1887 | actualSearchPath = "/" + domain.mid( 0, lastDot ) + "/" + product; | 1980 | actualSearchPath = "/" + domain.mid( 0, lastDot ) + "/" + product; |
1888 | insertSearchPath( Windows, actualSearchPath ); | 1981 | insertSearchPath( Windows, actualSearchPath ); |
1889 | #elif defined(Q_WS_MAC) | 1982 | #elif !defined(QWS) && defined(Q_OS_MAC) |
1890 | QString topLevelDomain = domain.right( domain.length() - lastDot - 1 ) + "."; | 1983 | QString topLevelDomain = domain.right( domain.length() - lastDot - 1 ) + "."; |
1891 | if ( topLevelDomain.isEmpty() ) | 1984 | if ( !topLevelDomain.isEmpty() ) |
1892 | topLevelDomain = "com."; | 1985 | qt_setSettingsBasePath( topLevelDomain ); |
1893 | actualSearchPath = "/" + topLevelDomain + domain.left( lastDot ) + product; | 1986 | actualSearchPath = "/" + domain.left( lastDot ) + product; |
1894 | insertSearchPath( Mac, actualSearchPath ); | 1987 | insertSearchPath( Mac, actualSearchPath ); |
1895 | #else | 1988 | #else |
1896 | actualSearchPath = "/" + domain.mid( 0, lastDot ) + "/" + product; | 1989 | actualSearchPath = "/" + domain.mid( 0, lastDot ) + "/" + product; |
1897 | insertSearchPath( Unix, actualSearchPath ); | 1990 | insertSearchPath( Unix, actualSearchPath ); |
1898 | #endif | 1991 | #endif |
1899 | |||
1900 | d->globalScope = scope == Global; | ||
1901 | } | 1992 | } |
1902 | 1993 | ||
1903 | /*! | 1994 | /*! |
1904 | Appends \a group to the current key prefix. | 1995 | Appends \a group to the current key prefix. |
1996 | |||
1997 | \code | ||
1998 | QSettings settings; | ||
1999 | settings.beginGroup( "/MainWindow" ); | ||
2000 | // read values | ||
2001 | settings.endGroup(); | ||
2002 | \endcode | ||
1905 | */ | 2003 | */ |
1906 | void QSettings::beginGroup( const QString &group ) | 2004 | void QSettings::beginGroup( const QString &group ) |
1907 | { | 2005 | { |
1908 | d->groupStack.push( group ); | 2006 | d->groupStack.push( group ); |
@@ -1911,8 +2009,15 @@ void QSettings::beginGroup( const QString &group ) | |||
1911 | 2009 | ||
1912 | /*! | 2010 | /*! |
1913 | Undo previous calls to beginGroup(). Note that a single beginGroup("a/b/c") is undone | 2011 | Undo previous calls to beginGroup(). Note that a single beginGroup("a/b/c") is undone |
1914 | by a single call to endGroup(). | 2012 | by a single call to endGroup(). |
2013 | |||
2014 | \code | ||
2015 | QSettings settings; | ||
2016 | settings.beginGroup( "/MainWindow/Geometry" ); | ||
2017 | // read values | ||
2018 | settings.endGroup(); | ||
2019 | \endcode | ||
1915 | */ | 2020 | */ |
1916 | void QSettings::endGroup() | 2021 | void QSettings::endGroup() |
1917 | { | 2022 | { |
1918 | d->groupStack.pop(); | 2023 | d->groupStack.pop(); |
@@ -1944,9 +2049,9 @@ QString QSettings::group() const | |||
1944 | while ( it != d->groupStack.end() ) { | 2049 | while ( it != d->groupStack.end() ) { |
1945 | QString group = *it; | 2050 | QString group = *it; |
1946 | ++it; | 2051 | ++it; |
1947 | if ( group[0] != '/' ) | 2052 | if ( group[0] != '/' ) |
1948 | group = "/" + group; | 2053 | group.prepend( "/" ); |
1949 | d->groupPrefix += group; | 2054 | d->groupPrefix += group; |
1950 | } | 2055 | } |
1951 | } | 2056 | } |
1952 | return d->groupPrefix; | 2057 | return d->groupPrefix; |
diff --git a/qmake/tools/qstring.cpp b/qmake/tools/qstring.cpp index 56df62b..7f1fac3 100644 --- a/qmake/tools/qstring.cpp +++ b/qmake/tools/qstring.cpp | |||
@@ -4,9 +4,9 @@ | |||
4 | ** Implementation of the QString class and related Unicode functions | 4 | ** Implementation of the QString class and related Unicode functions |
5 | ** | 5 | ** |
6 | ** Created : 920722 | 6 | ** Created : 920722 |
7 | ** | 7 | ** |
8 | ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. | 8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved. |
9 | ** | 9 | ** |
10 | ** This file is part of the tools module of the Qt GUI Toolkit. | 10 | ** This file is part of the tools module of the Qt GUI Toolkit. |
11 | ** | 11 | ** |
12 | ** This file may be distributed under the terms of the Q Public License | 12 | ** This file may be distributed under the terms of the Q Public License |
@@ -46,20 +46,24 @@ | |||
46 | #include "qdatastream.h" | 46 | #include "qdatastream.h" |
47 | #ifndef QT_NO_TEXTCODEC | 47 | #ifndef QT_NO_TEXTCODEC |
48 | #include "qtextcodec.h" | 48 | #include "qtextcodec.h" |
49 | #endif | 49 | #endif |
50 | #include <ctype.h> | ||
51 | #include <limits.h> | 50 | #include <limits.h> |
52 | #include <stdarg.h> | 51 | #include <stdarg.h> |
53 | #include <stdio.h> | 52 | #include <stdio.h> |
54 | #include <stdlib.h> | 53 | #include <stdlib.h> |
54 | #include <string.h> | ||
55 | #if defined(Q_WS_WIN) | 55 | #if defined(Q_WS_WIN) |
56 | #include "qt_windows.h" | 56 | #include "qt_windows.h" |
57 | #endif | 57 | #endif |
58 | #if !defined( QT_NO_COMPONENT ) && !defined( QT_LITE_COMPONENT ) | 58 | #if !defined( QT_NO_COMPONENT ) && !defined( QT_LITE_COMPONENT ) |
59 | #include "qcleanuphandler.h" | 59 | #include "qcleanuphandler.h" |
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | #ifdef QT_NO_UNICODETABLES | ||
63 | # include <ctype.h> | ||
64 | #endif | ||
65 | |||
62 | 66 | ||
63 | /* ------------------------------------------------------------------------- | 67 | /* ------------------------------------------------------------------------- |
64 | * unicode information | 68 | * unicode information |
65 | * these tables are generated from the unicode reference file | 69 | * these tables are generated from the unicode reference file |
@@ -11786,8 +11790,9 @@ static inline QChar::Direction direction( const QChar &c ) | |||
11786 | const Q_UINT8 *rowp = direction_info[c.row()]; | 11790 | const Q_UINT8 *rowp = direction_info[c.row()]; |
11787 | if(!rowp) return QChar::DirL; | 11791 | if(!rowp) return QChar::DirL; |
11788 | return (QChar::Direction) ( *(rowp+c.cell()) & 0x1f ); | 11792 | return (QChar::Direction) ( *(rowp+c.cell()) & 0x1f ); |
11789 | #else | 11793 | #else |
11794 | Q_UNUSED(c); | ||
11790 | return QChar::DirL; | 11795 | return QChar::DirL; |
11791 | #endif | 11796 | #endif |
11792 | } | 11797 | } |
11793 | 11798 | ||
@@ -11798,8 +11803,9 @@ static inline bool mirrored( const QChar &c ) | |||
11798 | if ( !rowp ) | 11803 | if ( !rowp ) |
11799 | return FALSE; | 11804 | return FALSE; |
11800 | return *(rowp+c.cell())>128; | 11805 | return *(rowp+c.cell())>128; |
11801 | #else | 11806 | #else |
11807 | Q_UNUSED(c); | ||
11802 | return FALSE; | 11808 | return FALSE; |
11803 | #endif | 11809 | #endif |
11804 | } | 11810 | } |
11805 | 11811 | ||
@@ -11899,9 +11905,9 @@ static uint computeNewMax( uint len ) | |||
11899 | { | 11905 | { |
11900 | uint newMax = 4; | 11906 | uint newMax = 4; |
11901 | while ( newMax < len ) | 11907 | while ( newMax < len ) |
11902 | newMax *= 2; | 11908 | newMax *= 2; |
11903 | // try to spare some memory | 11909 | // try to save some memory |
11904 | if ( newMax >= 1024 * 1024 && len <= newMax - (newMax >> 2) ) | 11910 | if ( newMax >= 1024 * 1024 && len <= newMax - (newMax >> 2) ) |
11905 | newMax -= newMax >> 2; | 11911 | newMax -= newMax >> 2; |
11906 | return newMax; | 11912 | return newMax; |
11907 | } | 11913 | } |
@@ -12890,9 +12896,9 @@ void QString::compose() | |||
12890 | The caller is responsible for deleting the return value with | 12896 | The caller is responsible for deleting the return value with |
12891 | delete[]. | 12897 | delete[]. |
12892 | */ | 12898 | */ |
12893 | 12899 | ||
12894 | QChar* QString::asciiToUnicode( const QByteArray& ba, uint* len ) | 12900 | QChar* QString::latin1ToUnicode( const QByteArray& ba, uint* len ) |
12895 | { | 12901 | { |
12896 | if ( ba.isNull() ) { | 12902 | if ( ba.isNull() ) { |
12897 | *len = 0; | 12903 | *len = 0; |
12898 | return 0; | 12904 | return 0; |
@@ -12909,9 +12915,9 @@ QChar* QString::asciiToUnicode( const QByteArray& ba, uint* len ) | |||
12909 | *uc++ = *str++; | 12915 | *uc++ = *str++; |
12910 | return result; | 12916 | return result; |
12911 | } | 12917 | } |
12912 | 12918 | ||
12913 | static QChar* internalAsciiToUnicode( const QByteArray& ba, uint* len ) | 12919 | static QChar* internalLatin1ToUnicode( const QByteArray& ba, uint* len ) |
12914 | { | 12920 | { |
12915 | if ( ba.isNull() ) { | 12921 | if ( ba.isNull() ) { |
12916 | *len = 0; | 12922 | *len = 0; |
12917 | return 0; | 12923 | return 0; |
@@ -12939,9 +12945,9 @@ static QChar* internalAsciiToUnicode( const QByteArray& ba, uint* len ) | |||
12939 | The caller is responsible for deleting the return value with | 12945 | The caller is responsible for deleting the return value with |
12940 | delete[]. | 12946 | delete[]. |
12941 | */ | 12947 | */ |
12942 | 12948 | ||
12943 | QChar* QString::asciiToUnicode( const char *str, uint* len, uint maxlen ) | 12949 | QChar* QString::latin1ToUnicode( const char *str, uint* len, uint maxlen ) |
12944 | { | 12950 | { |
12945 | QChar* result = 0; | 12951 | QChar* result = 0; |
12946 | uint l = 0; | 12952 | uint l = 0; |
12947 | if ( str ) { | 12953 | if ( str ) { |
@@ -12949,9 +12955,9 @@ QChar* QString::asciiToUnicode( const char *str, uint* len, uint maxlen ) | |||
12949 | while ( l < maxlen && str[l] ) | 12955 | while ( l < maxlen && str[l] ) |
12950 | l++; | 12956 | l++; |
12951 | } else { | 12957 | } else { |
12952 | // Faster? | 12958 | // Faster? |
12953 | l = qstrlen(str); | 12959 | l = strlen( str ); |
12954 | } | 12960 | } |
12955 | QChar *uc = new QChar[ l ]; // Can't use macro since function is public | 12961 | QChar *uc = new QChar[ l ]; // Can't use macro since function is public |
12956 | result = uc; | 12962 | result = uc; |
12957 | uint i = l; | 12963 | uint i = l; |
@@ -12962,9 +12968,9 @@ QChar* QString::asciiToUnicode( const char *str, uint* len, uint maxlen ) | |||
12962 | *len = l; | 12968 | *len = l; |
12963 | return result; | 12969 | return result; |
12964 | } | 12970 | } |
12965 | 12971 | ||
12966 | static QChar* internalAsciiToUnicode( const char *str, uint* len, | 12972 | static QChar* internalLatin1ToUnicode( const char *str, uint* len, |
12967 | uint maxlen = (uint)-1 ) | 12973 | uint maxlen = (uint)-1 ) |
12968 | { | 12974 | { |
12969 | QChar* result = 0; | 12975 | QChar* result = 0; |
12970 | uint l = 0; | 12976 | uint l = 0; |
@@ -12973,9 +12979,9 @@ static QChar* internalAsciiToUnicode( const char *str, uint* len, | |||
12973 | while ( l < maxlen && str[l] ) | 12979 | while ( l < maxlen && str[l] ) |
12974 | l++; | 12980 | l++; |
12975 | } else { | 12981 | } else { |
12976 | // Faster? | 12982 | // Faster? |
12977 | l = qstrlen(str); | 12983 | l = strlen( str ); |
12978 | } | 12984 | } |
12979 | QChar *uc = QT_ALLOC_QCHAR_VEC( l ); | 12985 | QChar *uc = QT_ALLOC_QCHAR_VEC( l ); |
12980 | result = uc; | 12986 | result = uc; |
12981 | uint i = l; | 12987 | uint i = l; |
@@ -12993,9 +12999,9 @@ static QChar* internalAsciiToUnicode( const char *str, uint* len, | |||
12993 | 12999 | ||
12994 | The caller is responsible for deleting the resultant string with | 13000 | The caller is responsible for deleting the resultant string with |
12995 | delete[]. | 13001 | delete[]. |
12996 | */ | 13002 | */ |
12997 | char* QString::unicodeToAscii(const QChar *uc, uint l) | 13003 | char* QString::unicodeToLatin1(const QChar *uc, uint l) |
12998 | { | 13004 | { |
12999 | if (!uc) { | 13005 | if (!uc) { |
13000 | return 0; | 13006 | return 0; |
13001 | } | 13007 | } |
@@ -13156,37 +13162,8 @@ QStringData* QString::makeSharedNull() | |||
13156 | #endif | 13162 | #endif |
13157 | return QString::shared_null; | 13163 | return QString::shared_null; |
13158 | } | 13164 | } |
13159 | 13165 | ||
13160 | // Uncomment this to get some useful statistics. | ||
13161 | // #define Q2HELPER(x) x | ||
13162 | |||
13163 | #ifdef Q2HELPER | ||
13164 | static int stat_construct_charstar=0; | ||
13165 | static int stat_construct_charstar_size=0; | ||
13166 | static int stat_construct_null=0; | ||
13167 | static int stat_construct_int=0; | ||
13168 | static int stat_construct_int_size=0; | ||
13169 | static int stat_construct_ba=0; | ||
13170 | static int stat_get_ascii=0; | ||
13171 | static int stat_get_ascii_size=0; | ||
13172 | static int stat_copy_on_write=0; | ||
13173 | static int stat_copy_on_write_size=0; | ||
13174 | static int stat_fast_copy=0; | ||
13175 | Q_EXPORT void qt_qstring_stats() | ||
13176 | { | ||
13177 | qDebug("construct_charstar = %d (%d chars)", stat_construct_charstar, stat_construct_charstar_size); | ||
13178 | qDebug("construct_null = %d", stat_construct_null); | ||
13179 | qDebug("construct_int = %d (%d chars)", stat_construct_int, stat_construct_int_size); | ||
13180 | qDebug("construct_ba = %d", stat_construct_ba); | ||
13181 | qDebug("get_ascii = %d (%d chars)", stat_get_ascii, stat_get_ascii_size); | ||
13182 | qDebug("copy_on_write = %d (%d chars)", stat_copy_on_write, stat_copy_on_write_size); | ||
13183 | qDebug("fast_copy = %d", stat_fast_copy); | ||
13184 | } | ||
13185 | #else | ||
13186 | #define Q2HELPER(x) | ||
13187 | #endif | ||
13188 | |||
13189 | /*! | 13166 | /*! |
13190 | \fn QString::QString() | 13167 | \fn QString::QString() |
13191 | 13168 | ||
13192 | Constructs a null string, i.e. both the length and data pointer | 13169 | Constructs a null string, i.e. both the length and data pointer |
@@ -13210,9 +13187,8 @@ QString::QString( QChar ch ) | |||
13210 | */ | 13187 | */ |
13211 | QString::QString( const QString &s ) : | 13188 | QString::QString( const QString &s ) : |
13212 | d(s.d) | 13189 | d(s.d) |
13213 | { | 13190 | { |
13214 | Q2HELPER(stat_fast_copy++) | ||
13215 | d->ref(); | 13191 | d->ref(); |
13216 | } | 13192 | } |
13217 | 13193 | ||
13218 | /*! | 13194 | /*! |
@@ -13229,15 +13205,12 @@ QString::QString( const QString &s ) : | |||
13229 | 13205 | ||
13230 | QString::QString( int size, bool /*dummy*/ ) | 13206 | QString::QString( int size, bool /*dummy*/ ) |
13231 | { | 13207 | { |
13232 | if ( size ) { | 13208 | if ( size ) { |
13233 | Q2HELPER(stat_construct_int++) | ||
13234 | int l = size; | 13209 | int l = size; |
13235 | Q2HELPER(stat_construct_int_size+=l) | ||
13236 | QChar* uc = QT_ALLOC_QCHAR_VEC( l ); | 13210 | QChar* uc = QT_ALLOC_QCHAR_VEC( l ); |
13237 | d = new QStringData( uc, 0, l ); | 13211 | d = new QStringData( uc, 0, l ); |
13238 | } else { | 13212 | } else { |
13239 | Q2HELPER(stat_construct_null++) | ||
13240 | d = shared_null ? shared_null : (shared_null=new QStringData); | 13213 | d = shared_null ? shared_null : (shared_null=new QStringData); |
13241 | d->ref(); | 13214 | d->ref(); |
13242 | } | 13215 | } |
13243 | } | 13216 | } |
@@ -13248,11 +13221,17 @@ QString::QString( int size, bool /*dummy*/ ) | |||
13248 | */ | 13221 | */ |
13249 | 13222 | ||
13250 | QString::QString( const QByteArray& ba ) | 13223 | QString::QString( const QByteArray& ba ) |
13251 | { | 13224 | { |
13252 | Q2HELPER(stat_construct_ba++) | 13225 | #ifndef QT_NO_TEXTCODEC |
13226 | if ( QTextCodec::codecForCStrings() ) { | ||
13227 | d = 0; | ||
13228 | *this = fromAscii( ba.data(), ba.size() ); | ||
13229 | return; | ||
13230 | } | ||
13231 | #endif | ||
13253 | uint l; | 13232 | uint l; |
13254 | QChar *uc = internalAsciiToUnicode(ba,&l); | 13233 | QChar *uc = internalLatin1ToUnicode(ba,&l); |
13255 | d = new QStringData(uc,l,l); | 13234 | d = new QStringData(uc,l,l); |
13256 | } | 13235 | } |
13257 | 13236 | ||
13258 | /*! | 13237 | /*! |
@@ -13301,15 +13280,42 @@ QString::QString( const QChar* unicode, uint length ) | |||
13301 | */ | 13280 | */ |
13302 | 13281 | ||
13303 | QString::QString( const char *str ) | 13282 | QString::QString( const char *str ) |
13304 | { | 13283 | { |
13305 | Q2HELPER(stat_construct_charstar++) | 13284 | #ifndef QT_NO_TEXTCODEC |
13285 | if ( QTextCodec::codecForCStrings() ) { | ||
13286 | d = 0; | ||
13287 | *this = fromAscii( str ); | ||
13288 | return; | ||
13289 | } | ||
13290 | #endif | ||
13306 | uint l; | 13291 | uint l; |
13307 | QChar *uc = internalAsciiToUnicode(str,&l); | 13292 | QChar *uc = internalLatin1ToUnicode(str,&l); |
13308 | Q2HELPER(stat_construct_charstar_size+=l) | ||
13309 | d = new QStringData(uc,l,l); | 13293 | d = new QStringData(uc,l,l); |
13310 | } | 13294 | } |
13311 | 13295 | ||
13296 | #ifndef QT_NO_STL | ||
13297 | /*! | ||
13298 | Constructs a string that is a deep copy of \a str. | ||
13299 | |||
13300 | This is the same as fromAscii(\a str). | ||
13301 | */ | ||
13302 | |||
13303 | QString::QString( const std::string &str ) | ||
13304 | { | ||
13305 | #ifndef QT_NO_TEXTCODEC | ||
13306 | if ( QTextCodec::codecForCStrings() ) { | ||
13307 | d = 0; | ||
13308 | *this = fromAscii( str.c_str() ); | ||
13309 | return; | ||
13310 | } | ||
13311 | #endif | ||
13312 | uint l; | ||
13313 | QChar *uc = internalLatin1ToUnicode(str.c_str(),&l); | ||
13314 | d = new QStringData(uc,l,l); | ||
13315 | } | ||
13316 | #endif | ||
13317 | |||
13312 | /*! | 13318 | /*! |
13313 | \fn QString::~QString() | 13319 | \fn QString::~QString() |
13314 | 13320 | ||
13315 | Destroys the string and frees the string's data if this is the | 13321 | Destroys the string and frees the string's data if this is the |
@@ -13332,12 +13338,12 @@ void QString::real_detach() | |||
13332 | } | 13338 | } |
13333 | 13339 | ||
13334 | void QString::deref() | 13340 | void QString::deref() |
13335 | { | 13341 | { |
13336 | if ( d->deref() ) { | 13342 | if ( d && d->deref() ) { |
13337 | if ( d != shared_null ) | 13343 | if ( d != shared_null ) |
13338 | delete d; | 13344 | delete d; |
13339 | d = 0; // helps debugging | 13345 | d = 0; |
13340 | } | 13346 | } |
13341 | } | 13347 | } |
13342 | 13348 | ||
13343 | void QStringData::deleteSelf() | 13349 | void QStringData::deleteSelf() |
@@ -13351,8 +13357,17 @@ void QStringData::deleteSelf() | |||
13351 | Sets the string to contain just the single character \a c. | 13357 | Sets the string to contain just the single character \a c. |
13352 | */ | 13358 | */ |
13353 | 13359 | ||
13354 | /*! | 13360 | /*! |
13361 | \fn QString& QString::operator=( const std::string& s ) | ||
13362 | |||
13363 | \overload | ||
13364 | |||
13365 | Makes a deep copy of \a s and returns a reference to the deep | ||
13366 | copy. | ||
13367 | */ | ||
13368 | |||
13369 | /*! | ||
13355 | \fn QString& QString::operator=( char c ) | 13370 | \fn QString& QString::operator=( char c ) |
13356 | 13371 | ||
13357 | \overload | 13372 | \overload |
13358 | 13373 | ||
@@ -13367,9 +13382,8 @@ void QStringData::deleteSelf() | |||
13367 | isn't actually copied. | 13382 | isn't actually copied. |
13368 | */ | 13383 | */ |
13369 | QString &QString::operator=( const QString &s ) | 13384 | QString &QString::operator=( const QString &s ) |
13370 | { | 13385 | { |
13371 | Q2HELPER(stat_fast_copy++) | ||
13372 | s.d->ref(); | 13386 | s.d->ref(); |
13373 | deref(); | 13387 | deref(); |
13374 | d = s.d; | 13388 | d = s.d; |
13375 | return *this; | 13389 | return *this; |
@@ -13382,9 +13396,9 @@ QString &QString::operator=( const QString &s ) | |||
13382 | to this string and returns a reference to this string. | 13396 | to this string and returns a reference to this string. |
13383 | */ | 13397 | */ |
13384 | QString &QString::operator=( const QCString& cs ) | 13398 | QString &QString::operator=( const QCString& cs ) |
13385 | { | 13399 | { |
13386 | return setLatin1(cs); | 13400 | return setAscii(cs); |
13387 | } | 13401 | } |
13388 | 13402 | ||
13389 | 13403 | ||
13390 | /*! | 13404 | /*! |
@@ -13398,9 +13412,9 @@ QString &QString::operator=( const QCString& cs ) | |||
13398 | \sa isNull() | 13412 | \sa isNull() |
13399 | */ | 13413 | */ |
13400 | QString &QString::operator=( const char *str ) | 13414 | QString &QString::operator=( const char *str ) |
13401 | { | 13415 | { |
13402 | return setLatin1(str); | 13416 | return setAscii(str); |
13403 | } | 13417 | } |
13404 | 13418 | ||
13405 | 13419 | ||
13406 | /*! | 13420 | /*! |
@@ -13470,10 +13484,9 @@ void QString::truncate( uint newLen ) | |||
13470 | Ensures that at least \a newLen characters are allocated to the | 13484 | Ensures that at least \a newLen characters are allocated to the |
13471 | string, and sets the length of the string to \a newLen. Any new | 13485 | string, and sets the length of the string to \a newLen. Any new |
13472 | space allocated contains arbitrary data. | 13486 | space allocated contains arbitrary data. |
13473 | 13487 | ||
13474 | If \a newLen is 0, then the string becomes empty, unless the | 13488 | If \a newLen is 0, then the string becomes empty (non-null). |
13475 | string is null, in which case it remains null. | ||
13476 | 13489 | ||
13477 | If it is not possible to allocate enough memory, the string | 13490 | If it is not possible to allocate enough memory, the string |
13478 | remains unchanged. | 13491 | remains unchanged. |
13479 | 13492 | ||
@@ -13485,14 +13498,14 @@ void QString::truncate( uint newLen ) | |||
13485 | we want to add to the string until some condition is true, and | 13498 | we want to add to the string until some condition is true, and |
13486 | we're fairly sure that size is big enough: | 13499 | we're fairly sure that size is big enough: |
13487 | \code | 13500 | \code |
13488 | QString result; | 13501 | QString result; |
13489 | int resultLength = 0; | 13502 | int len = 0; |
13490 | result.setLength( newLen ) // allocate some space | 13503 | result.setLength( maxLen ); // allocate some space |
13491 | while ( ... ) { | 13504 | while ( ... ) { |
13492 | result[resultLength++] = ... // fill (part of) the space with data | 13505 | result[len++] = ... // fill part of the space |
13493 | } | 13506 | } |
13494 | result.truncate[resultLength]; // and get rid of the undefined junk | 13507 | result.truncate( len ); // and get rid of the rest |
13495 | \endcode | 13508 | \endcode |
13496 | 13509 | ||
13497 | If \a newLen is an underestimate, the worst that will happen is | 13510 | If \a newLen is an underestimate, the worst that will happen is |
13498 | that the loop will slow down. | 13511 | that the loop will slow down. |
@@ -13504,10 +13517,8 @@ void QString::setLength( uint newLen ) | |||
13504 | { | 13517 | { |
13505 | if ( d->count != 1 || newLen > d->maxl || | 13518 | if ( d->count != 1 || newLen > d->maxl || |
13506 | ( newLen * 4 < d->maxl && d->maxl > 4 ) ) { | 13519 | ( newLen * 4 < d->maxl && d->maxl > 4 ) ) { |
13507 | // detach, grow or shrink | 13520 | // detach, grow or shrink |
13508 | Q2HELPER(stat_copy_on_write++) | ||
13509 | Q2HELPER(stat_copy_on_write_size+=d->len) | ||
13510 | uint newMax = computeNewMax( newLen ); | 13521 | uint newMax = computeNewMax( newLen ); |
13511 | QChar* nd = QT_ALLOC_QCHAR_VEC( newMax ); | 13522 | QChar* nd = QT_ALLOC_QCHAR_VEC( newMax ); |
13512 | if ( nd ) { | 13523 | if ( nd ) { |
13513 | uint len = QMIN( d->len, newLen ); | 13524 | uint len = QMIN( d->len, newLen ); |
@@ -13529,23 +13540,22 @@ void QString::setLength( uint newLen ) | |||
13529 | The \a fieldwidth value specifies the minimum amount of space that | 13540 | The \a fieldwidth value specifies the minimum amount of space that |
13530 | \a a is padded to. A positive value will produce right-aligned | 13541 | \a a is padded to. A positive value will produce right-aligned |
13531 | text, whereas a negative value will produce left-aligned text. | 13542 | text, whereas a negative value will produce left-aligned text. |
13532 | 13543 | ||
13544 | The following example shows how we could create a 'status' string | ||
13545 | when processing a list of files: | ||
13533 | \code | 13546 | \code |
13534 | QString firstName( "Joe" ); | 13547 | QString status = QString( "Processing file %1 of %2: %3" ) |
13535 | QString lastName( "Bloggs" ); | 13548 | .arg( i ) // current file's number |
13536 | QString fullName; | 13549 | .arg( total ) // number of files to process |
13537 | fullName = QString( "First name is '%1', last name is '%2'" ) | 13550 | .arg( fileName ); // current file's name |
13538 | .arg( firstName ) | ||
13539 | .arg( lastName ); | ||
13540 | |||
13541 | // fullName == First name is 'Joe', last name is 'Bloggs' | ||
13542 | \endcode | 13551 | \endcode |
13543 | 13552 | ||
13544 | Note that using arg() to construct sentences as we've done in the | 13553 | It is generally fine to use filenames and numbers as we have done |
13545 | example above does not usually translate well into other languages | 13554 | in the example above. But note that using arg() to construct |
13546 | because sentence structure and word order often differ between | 13555 | natural language sentences does not usually translate well into |
13547 | languages. | 13556 | other languages because sentence structure and word order often |
13557 | differ between languages. | ||
13548 | 13558 | ||
13549 | If there is no place marker (\c %1 or \c %2, etc.), a warning | 13559 | If there is no place marker (\c %1 or \c %2, etc.), a warning |
13550 | message (qWarning()) is output and the text is appended at the | 13560 | message (qWarning()) is output and the text is appended at the |
13551 | end of the string. We recommend that the correct number of place | 13561 | end of the string. We recommend that the correct number of place |
@@ -13773,9 +13783,9 @@ QString &QString::sprintf( const char* cformat, ... ) | |||
13773 | // Qt 1.x compat | 13783 | // Qt 1.x compat |
13774 | *this = fromLatin1( "" ); | 13784 | *this = fromLatin1( "" ); |
13775 | return *this; | 13785 | return *this; |
13776 | } | 13786 | } |
13777 | QString format = fromLatin1( cformat ); | 13787 | QString format = fromAscii( cformat ); |
13778 | 13788 | ||
13779 | QRegExp escape( "%#?0?-? ?\\+?'?[0-9*]*\\.?[0-9*]*h?l?L?q?Z?" ); | 13789 | QRegExp escape( "%#?0?-? ?\\+?'?[0-9*]*\\.?[0-9*]*h?l?L?q?Z?" ); |
13780 | QString result; | 13790 | QString result; |
13781 | uint last = 0; | 13791 | uint last = 0; |
@@ -13912,9 +13922,9 @@ QString &QString::sprintf( const char* cformat, ... ) | |||
13912 | ::sprintf( out, in, width, decimals, value ); | 13922 | ::sprintf( out, in, width, decimals, value ); |
13913 | } | 13923 | } |
13914 | } | 13924 | } |
13915 | } | 13925 | } |
13916 | replacement = fromLatin1( out ); | 13926 | replacement = fromAscii( out ); |
13917 | } | 13927 | } |
13918 | result += replacement; | 13928 | result += replacement; |
13919 | } | 13929 | } |
13920 | *this = result; | 13930 | *this = result; |
@@ -14123,10 +14133,12 @@ int QString::find( const QString& str, int index, bool cs ) const | |||
14123 | return -1; | 14133 | return -1; |
14124 | if ( !sl ) | 14134 | if ( !sl ) |
14125 | return index; | 14135 | return index; |
14126 | 14136 | ||
14137 | #ifndef MACOSX_101 | ||
14127 | if ( sl == 1 ) | 14138 | if ( sl == 1 ) |
14128 | return find( *str.unicode(), index, cs ); | 14139 | return find( *str.unicode(), index, cs ); |
14140 | #endif | ||
14129 | 14141 | ||
14130 | // we use the Boyer-Moore algorithm in cases where the overhead | 14142 | // we use the Boyer-Moore algorithm in cases where the overhead |
14131 | // for the hash table should pay off, otherwise we use a simple | 14143 | // for the hash table should pay off, otherwise we use a simple |
14132 | // hash function | 14144 | // hash function |
@@ -14220,8 +14232,11 @@ int QString::find( const QString& str, int index, bool cs ) const | |||
14220 | */ | 14232 | */ |
14221 | 14233 | ||
14222 | int QString::findRev( QChar c, int index, bool cs ) const | 14234 | int QString::findRev( QChar c, int index, bool cs ) const |
14223 | { | 14235 | { |
14236 | #ifdef MACOSX_101 | ||
14237 | return findRev( QString( c ), index, cs ); | ||
14238 | #else | ||
14224 | const uint l = length(); | 14239 | const uint l = length(); |
14225 | if ( index < 0 ) | 14240 | if ( index < 0 ) |
14226 | index += l; | 14241 | index += l; |
14227 | if ( (uint)index >= l ) | 14242 | if ( (uint)index >= l ) |
@@ -14236,8 +14251,9 @@ int QString::findRev( QChar c, int index, bool cs ) const | |||
14236 | while ( uc >= end && ::lower( *uc ) != c ) | 14251 | while ( uc >= end && ::lower( *uc ) != c ) |
14237 | uc--; | 14252 | uc--; |
14238 | } | 14253 | } |
14239 | return uc - end; | 14254 | return uc - end; |
14255 | #endif | ||
14240 | } | 14256 | } |
14241 | 14257 | ||
14242 | /*! | 14258 | /*! |
14243 | \overload | 14259 | \overload |
@@ -14272,10 +14288,12 @@ int QString::findRev( const QString& str, int index, bool cs ) const | |||
14272 | return -1; | 14288 | return -1; |
14273 | if ( index > delta ) | 14289 | if ( index > delta ) |
14274 | index = delta; | 14290 | index = delta; |
14275 | 14291 | ||
14292 | #ifndef MACOSX_101 | ||
14276 | if ( sl == 1 ) | 14293 | if ( sl == 1 ) |
14277 | return findRev( *str.unicode(), index, cs ); | 14294 | return findRev( *str.unicode(), index, cs ); |
14295 | #endif | ||
14278 | 14296 | ||
14279 | const QChar* needle = str.unicode(); | 14297 | const QChar* needle = str.unicode(); |
14280 | const QChar* haystack = unicode() + index; | 14298 | const QChar* haystack = unicode() + index; |
14281 | const QChar* end = unicode(); | 14299 | const QChar* end = unicode(); |
@@ -14978,21 +14996,26 @@ QString QString::rightJustify( uint width, QChar fill, bool truncate ) const | |||
14978 | */ | 14996 | */ |
14979 | 14997 | ||
14980 | QString QString::lower() const | 14998 | QString QString::lower() const |
14981 | { | 14999 | { |
14982 | QString s(*this); | ||
14983 | int l=length(); | 15000 | int l=length(); |
14984 | if ( l ) { | 15001 | register QChar *p = d->unicode; |
14985 | s.real_detach(); // could do this only when we find a change | 15002 | while ( l ) { |
14986 | register QChar *p=s.d->unicode; | 15003 | if ( *p != ::lower(*p) ) { |
14987 | if ( p ) { | 15004 | QString s( *this ); |
14988 | while ( l-- ) { | 15005 | s.real_detach(); |
15006 | p = s.d->unicode + ( p - d->unicode ); | ||
15007 | while ( l ) { | ||
14989 | *p = ::lower( *p ); | 15008 | *p = ::lower( *p ); |
15009 | l--; | ||
14990 | p++; | 15010 | p++; |
14991 | } | 15011 | } |
15012 | return s; | ||
14992 | } | 15013 | } |
15014 | l--; | ||
15015 | p++; | ||
14993 | } | 15016 | } |
14994 | return s; | 15017 | return *this; |
14995 | } | 15018 | } |
14996 | 15019 | ||
14997 | /*! | 15020 | /*! |
14998 | Returns an uppercase copy of the string. | 15021 | Returns an uppercase copy of the string. |
@@ -15006,21 +15029,26 @@ QString QString::lower() const | |||
15006 | */ | 15029 | */ |
15007 | 15030 | ||
15008 | QString QString::upper() const | 15031 | QString QString::upper() const |
15009 | { | 15032 | { |
15010 | QString s(*this); | ||
15011 | int l=length(); | 15033 | int l=length(); |
15012 | if ( l ) { | 15034 | register QChar *p = d->unicode; |
15013 | s.real_detach(); // could do this only when we find a change | 15035 | while ( l ) { |
15014 | register QChar *p=s.d->unicode; | 15036 | if ( *p != ::upper(*p) ) { |
15015 | if ( p ) { | 15037 | QString s( *this ); |
15016 | while ( l-- ) { | 15038 | s.real_detach(); |
15039 | p = s.d->unicode + ( p - d->unicode ); | ||
15040 | while ( l ) { | ||
15017 | *p = ::upper( *p ); | 15041 | *p = ::upper( *p ); |
15042 | l--; | ||
15018 | p++; | 15043 | p++; |
15019 | } | 15044 | } |
15045 | return s; | ||
15020 | } | 15046 | } |
15047 | l--; | ||
15048 | p++; | ||
15021 | } | 15049 | } |
15022 | return s; | 15050 | return *this; |
15023 | } | 15051 | } |
15024 | 15052 | ||
15025 | 15053 | ||
15026 | /*! | 15054 | /*! |
@@ -15136,10 +15164,10 @@ QString &QString::insert( uint index, const QString &s ) | |||
15136 | 15164 | ||
15137 | /*! | 15165 | /*! |
15138 | \overload | 15166 | \overload |
15139 | 15167 | ||
15140 | Inserts the character in \a s into the string at position \a index | 15168 | Inserts the first \a len characters in \a s into the string at |
15141 | \a len number of times and returns a reference to the string. | 15169 | position \a index and returns a reference to the string. |
15142 | */ | 15170 | */ |
15143 | 15171 | ||
15144 | QString &QString::insert( uint index, const QChar* s, uint len ) | 15172 | QString &QString::insert( uint index, const QChar* s, uint len ) |
15145 | { | 15173 | { |
@@ -15250,8 +15278,18 @@ QString &QString::insert( uint index, QChar c ) // insert char | |||
15250 | 15278 | ||
15251 | \sa insert() | 15279 | \sa insert() |
15252 | */ | 15280 | */ |
15253 | 15281 | ||
15282 | /*! \fn QString& QString::prepend( const std::string &s ) | ||
15283 | \overload | ||
15284 | |||
15285 | Inserts \a s at the beginning of the string and returns a reference to the string. | ||
15286 | |||
15287 | Equivalent to insert(0, \a s). | ||
15288 | |||
15289 | \sa insert() | ||
15290 | */ | ||
15291 | |||
15254 | /*! | 15292 | /*! |
15255 | \overload | 15293 | \overload |
15256 | 15294 | ||
15257 | Inserts \a s at the beginning of the string and returns a reference to the string. | 15295 | Inserts \a s at the beginning of the string and returns a reference to the string. |
@@ -15847,11 +15885,11 @@ static bool ok_in_base( QChar c, int base ) | |||
15847 | 15885 | ||
15848 | long QString::toLong( bool *ok, int base ) const | 15886 | long QString::toLong( bool *ok, int base ) const |
15849 | { | 15887 | { |
15850 | const QChar *p = unicode(); | 15888 | const QChar *p = unicode(); |
15851 | long val = 0; | 15889 | ulong val = 0; |
15852 | int l = length(); | 15890 | int l = length(); |
15853 | const long max_mult = INT_MAX / base; | 15891 | const ulong max_mult = LONG_MAX / base; |
15854 | bool is_ok = FALSE; | 15892 | bool is_ok = FALSE; |
15855 | int neg = 0; | 15893 | int neg = 0; |
15856 | if ( !p ) | 15894 | if ( !p ) |
15857 | goto bye; | 15895 | goto bye; |
@@ -15882,23 +15920,21 @@ long QString::toLong( bool *ok, int base ) const | |||
15882 | else | 15920 | else |
15883 | dv = *p - 'A' + 10; | 15921 | dv = *p - 'A' + 10; |
15884 | } | 15922 | } |
15885 | if ( val > max_mult || | 15923 | if ( val > max_mult || |
15886 | (val == max_mult && dv > (INT_MAX % base) + neg) ) | 15924 | (val == max_mult && dv > (LONG_MAX % base) + neg) ) |
15887 | goto bye; | 15925 | goto bye; |
15888 | val = base * val + dv; | 15926 | val = base * val + dv; |
15889 | p++; | 15927 | p++; |
15890 | } | 15928 | } |
15891 | if ( neg ) | ||
15892 | val = -val; | ||
15893 | while ( l && p->isSpace() ) // skip trailing space | 15929 | while ( l && p->isSpace() ) // skip trailing space |
15894 | l--,p++; | 15930 | l--,p++; |
15895 | if ( !l ) | 15931 | if ( !l ) |
15896 | is_ok = TRUE; | 15932 | is_ok = TRUE; |
15897 | bye: | 15933 | bye: |
15898 | if ( ok ) | 15934 | if ( ok ) |
15899 | *ok = is_ok; | 15935 | *ok = is_ok; |
15900 | return is_ok ? val : 0; | 15936 | return is_ok ? ( neg ? -( (long) val ) : (long) val ) : 0L; |
15901 | } | 15937 | } |
15902 | 15938 | ||
15903 | /*! | 15939 | /*! |
15904 | Returns the string converted to an \c {unsigned long} value to the | 15940 | Returns the string converted to an \c {unsigned long} value to the |
@@ -15914,9 +15950,9 @@ ulong QString::toULong( bool *ok, int base ) const | |||
15914 | { | 15950 | { |
15915 | const QChar *p = unicode(); | 15951 | const QChar *p = unicode(); |
15916 | ulong val = 0; | 15952 | ulong val = 0; |
15917 | int l = length(); | 15953 | int l = length(); |
15918 | const ulong max_mult = UINT_MAX / base; | 15954 | const ulong max_mult = ULONG_MAX / base; |
15919 | bool is_ok = FALSE; | 15955 | bool is_ok = FALSE; |
15920 | if ( !p ) | 15956 | if ( !p ) |
15921 | goto bye; | 15957 | goto bye; |
15922 | while ( l && p->isSpace() ) // skip leading space | 15958 | while ( l && p->isSpace() ) // skip leading space |
@@ -15939,9 +15975,9 @@ ulong QString::toULong( bool *ok, int base ) const | |||
15939 | dv = *p - 'a' + 10; | 15975 | dv = *p - 'a' + 10; |
15940 | else | 15976 | else |
15941 | dv = *p - 'A' + 10; | 15977 | dv = *p - 'A' + 10; |
15942 | } | 15978 | } |
15943 | if ( val > max_mult || (val == max_mult && dv > UINT_MAX % base) ) | 15979 | if ( val > max_mult || (val == max_mult && dv > ULONG_MAX % base) ) |
15944 | goto bye; | 15980 | goto bye; |
15945 | val = base * val + dv; | 15981 | val = base * val + dv; |
15946 | p++; | 15982 | p++; |
15947 | } | 15983 | } |
@@ -15966,9 +16002,9 @@ bye: | |||
15966 | 16002 | ||
15967 | short QString::toShort( bool *ok, int base ) const | 16003 | short QString::toShort( bool *ok, int base ) const |
15968 | { | 16004 | { |
15969 | long v = toLong( ok, base ); | 16005 | long v = toLong( ok, base ); |
15970 | if ( ok && *ok && (v < -32768 || v > 32767) ) { | 16006 | if ( ok && *ok && (v < SHRT_MIN || v > SHRT_MAX) ) { |
15971 | *ok = FALSE; | 16007 | *ok = FALSE; |
15972 | v = 0; | 16008 | v = 0; |
15973 | } | 16009 | } |
15974 | return (short)v; | 16010 | return (short)v; |
@@ -15985,9 +16021,9 @@ short QString::toShort( bool *ok, int base ) const | |||
15985 | 16021 | ||
15986 | ushort QString::toUShort( bool *ok, int base ) const | 16022 | ushort QString::toUShort( bool *ok, int base ) const |
15987 | { | 16023 | { |
15988 | ulong v = toULong( ok, base ); | 16024 | ulong v = toULong( ok, base ); |
15989 | if ( ok && *ok && (v > 65535) ) { | 16025 | if ( ok && *ok && (v > USHRT_MAX) ) { |
15990 | *ok = FALSE; | 16026 | *ok = FALSE; |
15991 | v = 0; | 16027 | v = 0; |
15992 | } | 16028 | } |
15993 | return (ushort)v; | 16029 | return (ushort)v; |
@@ -16012,9 +16048,14 @@ ushort QString::toUShort( bool *ok, int base ) const | |||
16012 | */ | 16048 | */ |
16013 | 16049 | ||
16014 | int QString::toInt( bool *ok, int base ) const | 16050 | int QString::toInt( bool *ok, int base ) const |
16015 | { | 16051 | { |
16016 | return (int)toLong( ok, base ); | 16052 | long v = toLong( ok, base ); |
16053 | if ( ok && *ok && (v < INT_MIN || v > INT_MAX) ) { | ||
16054 | *ok = FALSE; | ||
16055 | v = 0; | ||
16056 | } | ||
16057 | return (int)v; | ||
16017 | } | 16058 | } |
16018 | 16059 | ||
16019 | /*! | 16060 | /*! |
16020 | Returns the string converted to an \c{unsigned int} value to the | 16061 | Returns the string converted to an \c{unsigned int} value to the |
@@ -16027,9 +16068,14 @@ int QString::toInt( bool *ok, int base ) const | |||
16027 | */ | 16068 | */ |
16028 | 16069 | ||
16029 | uint QString::toUInt( bool *ok, int base ) const | 16070 | uint QString::toUInt( bool *ok, int base ) const |
16030 | { | 16071 | { |
16031 | return (uint)toULong( ok, base ); | 16072 | ulong v = toULong( ok, base ); |
16073 | if ( ok && *ok && (v > UINT_MAX) ) { | ||
16074 | *ok = FALSE; | ||
16075 | v = 0; | ||
16076 | } | ||
16077 | return (uint)v; | ||
16032 | } | 16078 | } |
16033 | 16079 | ||
16034 | /*! | 16080 | /*! |
16035 | Returns the string converted to a \c double value. | 16081 | Returns the string converted to a \c double value. |
@@ -16051,9 +16097,9 @@ double QString::toDouble( bool *ok ) const | |||
16051 | 16097 | ||
16052 | const char *a = latin1(); | 16098 | const char *a = latin1(); |
16053 | double val = strtod( a ? a : "", &end ); | 16099 | double val = strtod( a ? a : "", &end ); |
16054 | if ( ok ) | 16100 | if ( ok ) |
16055 | *ok = ( a && *a && (end == 0 || (end - a) == (int)length()) ); | 16101 | *ok = ( a && *a && (end == 0 || *end == '\0') ); |
16056 | return val; | 16102 | return val; |
16057 | } | 16103 | } |
16058 | 16104 | ||
16059 | /*! | 16105 | /*! |
@@ -16097,13 +16143,13 @@ QString &QString::setNum( long n, int base ) | |||
16097 | int len = 0; | 16143 | int len = 0; |
16098 | bool neg; | 16144 | bool neg; |
16099 | if ( n < 0 ) { | 16145 | if ( n < 0 ) { |
16100 | neg = TRUE; | 16146 | neg = TRUE; |
16101 | if ( n == INT_MIN ) { | 16147 | if ( n == LONG_MIN ) { |
16102 | // Cannot always negate this special case | 16148 | // Cannot always negate this special case |
16103 | QString s1, s2; | 16149 | QString s1, s2; |
16104 | s1.setNum(n/base); | 16150 | s1.setNum(n/base, base ); |
16105 | s2.setNum((-(n+base))%base); | 16151 | s2.setNum((-(n+base))%base, base ); |
16106 | *this = s1 + s2; | 16152 | *this = s1 + s2; |
16107 | return *this; | 16153 | return *this; |
16108 | } | 16154 | } |
16109 | n = -n; | 16155 | n = -n; |
@@ -16460,8 +16506,17 @@ void QString::setExpand( uint index, QChar c ) | |||
16460 | 16506 | ||
16461 | Equivalent to operator+=(). | 16507 | Equivalent to operator+=(). |
16462 | */ | 16508 | */ |
16463 | 16509 | ||
16510 | /*! \fn QString& QString::append( const std::string &str ) | ||
16511 | \overload | ||
16512 | |||
16513 | Appends \a str to the string and returns a reference to the result. | ||
16514 | |||
16515 | Equivalent to operator+=(). | ||
16516 | */ | ||
16517 | |||
16518 | |||
16464 | /*! \fn QString& QString::append( const char *str ) | 16519 | /*! \fn QString& QString::append( const char *str ) |
16465 | \overload | 16520 | \overload |
16466 | 16521 | ||
16467 | Appends \a str to the string and returns a reference to the result. | 16522 | Appends \a str to the string and returns a reference to the result. |
@@ -16489,11 +16544,17 @@ QString& QString::operator+=( const QString &str ) | |||
16489 | \overload | 16544 | \overload |
16490 | 16545 | ||
16491 | Appends \a str to the string and returns a reference to the string. | 16546 | Appends \a str to the string and returns a reference to the string. |
16492 | */ | 16547 | */ |
16548 | #ifndef QT_NO_CAST_ASCII | ||
16493 | QString& QString::operator+=( const char *str ) | 16549 | QString& QString::operator+=( const char *str ) |
16494 | { | 16550 | { |
16495 | if ( str ) { | 16551 | if ( str ) { |
16552 | #ifndef QT_NO_TEXTCODEC | ||
16553 | if ( QTextCodec::codecForCStrings() ) | ||
16554 | return operator+=( fromAscii( str ) ); | ||
16555 | #endif | ||
16556 | |||
16496 | uint len1 = length(); | 16557 | uint len1 = length(); |
16497 | uint len2 = strlen( str ); | 16558 | uint len2 = strlen( str ); |
16498 | if ( len2 ) { | 16559 | if ( len2 ) { |
16499 | setLength(len1+len2); | 16560 | setLength(len1+len2); |
@@ -16507,8 +16568,9 @@ QString& QString::operator+=( const char *str ) | |||
16507 | } | 16568 | } |
16508 | } | 16569 | } |
16509 | return *this; | 16570 | return *this; |
16510 | } | 16571 | } |
16572 | #endif | ||
16511 | 16573 | ||
16512 | /*! \overload | 16574 | /*! \overload |
16513 | 16575 | ||
16514 | Appends \a c to the string and returns a reference to the string. | 16576 | Appends \a c to the string and returns a reference to the string. |
@@ -16528,8 +16590,12 @@ QString &QString::operator+=( QChar c ) | |||
16528 | */ | 16590 | */ |
16529 | 16591 | ||
16530 | QString &QString::operator+=( char c ) | 16592 | QString &QString::operator+=( char c ) |
16531 | { | 16593 | { |
16594 | #ifndef QT_NO_TEXTCODEC | ||
16595 | if ( QTextCodec::codecForCStrings() ) | ||
16596 | return operator+=( fromAscii( &c, 1 ) ); | ||
16597 | #endif | ||
16532 | setLength(length()+1); | 16598 | setLength(length()+1); |
16533 | d->unicode[length()-1] = c; | 16599 | d->unicode[length()-1] = c; |
16534 | return *this; | 16600 | return *this; |
16535 | } | 16601 | } |
@@ -16540,20 +16606,27 @@ QString &QString::operator+=( char c ) | |||
16540 | 16606 | ||
16541 | Appends \a str to the string and returns a reference to the string. | 16607 | Appends \a str to the string and returns a reference to the string. |
16542 | */ | 16608 | */ |
16543 | 16609 | ||
16610 | /*! | ||
16611 | \fn QString &QString::operator+=( const std::string &str ) | ||
16612 | \overload | ||
16613 | |||
16614 | Appends \a str to the string and returns a reference to the string. | ||
16615 | */ | ||
16616 | |||
16544 | 16617 | ||
16545 | 16618 | ||
16546 | /*! | 16619 | /*! |
16547 | \fn char QChar::latin1() const | 16620 | \fn char QChar::latin1() const |
16548 | 16621 | ||
16549 | Returns a latin-1 copy of this character, if this character is in | 16622 | Returns the Latin-1 value of this character, or 0 if it |
16550 | the latin-1 character set. If not, this function returns 0. | 16623 | cannot be represented in Latin-1. |
16551 | */ | 16624 | */ |
16552 | 16625 | ||
16553 | 16626 | ||
16554 | /*! | 16627 | /*! |
16555 | Returns a Latin-1 representation of the string. Note that the | 16628 | Returns a Latin-1 representation of the string. The |
16556 | returned value is undefined if the string contains non-Latin-1 | 16629 | returned value is undefined if the string contains non-Latin-1 |
16557 | characters. If you want to convert strings into formats other than | 16630 | characters. If you want to convert strings into formats other than |
16558 | Unicode, see the QTextCodec classes. | 16631 | Unicode, see the QTextCodec classes. |
16559 | 16632 | ||
@@ -16562,33 +16635,51 @@ QString &QString::operator+=( char c ) | |||
16562 | 16635 | ||
16563 | The result remains valid so long as one unmodified copy of the | 16636 | The result remains valid so long as one unmodified copy of the |
16564 | source string exists. | 16637 | source string exists. |
16565 | 16638 | ||
16566 | \sa utf8(), local8Bit() | 16639 | \sa fromLatin1(), ascii(), utf8(), local8Bit() |
16567 | */ | 16640 | */ |
16568 | const char* QString::latin1() const | 16641 | const char* QString::latin1() const |
16569 | { | 16642 | { |
16570 | if ( !d->ascii ) { | 16643 | if ( !d->ascii || !d->islatin1 ) { |
16571 | Q2HELPER(stat_get_ascii++) | 16644 | d->ascii = unicodeToLatin1( d->unicode, d->len ); |
16572 | Q2HELPER(stat_get_ascii_size+=d->len) | 16645 | d->islatin1 = TRUE; |
16573 | d->ascii = unicodeToAscii( d->unicode, d->len ); | ||
16574 | } | 16646 | } |
16575 | return d->ascii; | 16647 | return d->ascii; |
16576 | } | 16648 | } |
16577 | 16649 | ||
16578 | /*! | 16650 | /*! |
16579 | \fn const char* QString::ascii() const | 16651 | Returns an 8-bit ASCII representation of the string. |
16580 | \obsolete | 16652 | |
16653 | If a codec has been set using QTextCodec::codecForCStrings(), | ||
16654 | it is used to convert Unicode to 8-bit char. Otherwise, this function | ||
16655 | does the same as latin1(). | ||
16581 | 16656 | ||
16582 | This function simply calls latin1() and returns the result. | 16657 | \sa fromAscii(), latin1(), utf8(), local8Bit() |
16583 | */ | 16658 | */ |
16659 | const char* QString::ascii() const | ||
16660 | { | ||
16661 | #ifndef QT_NO_TEXTCODEC | ||
16662 | if ( QTextCodec::codecForCStrings() ) { | ||
16663 | if ( !d->ascii || d->islatin1 ) { | ||
16664 | QCString s = QTextCodec::codecForCStrings()->fromUnicode( *this ); | ||
16665 | s.detach(); | ||
16666 | d->ascii = s.data(); | ||
16667 | d->islatin1 = FALSE; | ||
16668 | s.resetRawData( s.data(), s.size() ); // we have stolen the data | ||
16669 | } | ||
16670 | return d->ascii; | ||
16671 | } | ||
16672 | #endif // QT_NO_TEXTCODEC | ||
16673 | return latin1(); | ||
16674 | } | ||
16584 | 16675 | ||
16585 | /*! | 16676 | /*! |
16586 | Returns the string encoded in UTF8 format. | 16677 | Returns the string encoded in UTF-8 format. |
16587 | 16678 | ||
16588 | See QTextCodec for more diverse coding/decoding of Unicode strings. | 16679 | See QTextCodec for more diverse coding/decoding of Unicode strings. |
16589 | 16680 | ||
16590 | \sa QString::fromUtf8(), local8Bit(), latin1() | 16681 | \sa fromUtf8(), ascii(), latin1(), local8Bit() |
16591 | */ | 16682 | */ |
16592 | QCString QString::utf8() const | 16683 | QCString QString::utf8() const |
16593 | { | 16684 | { |
16594 | int l = length(); | 16685 | int l = length(); |
@@ -16632,9 +16723,10 @@ QString QString::fromUtf8( const char* utf8, int len ) | |||
16632 | { | 16723 | { |
16633 | if ( !utf8 ) | 16724 | if ( !utf8 ) |
16634 | return QString::null; | 16725 | return QString::null; |
16635 | 16726 | ||
16636 | if ( len < 0 ) len = qstrlen( utf8 ); | 16727 | if ( len < 0 ) |
16728 | len = strlen( utf8 ); | ||
16637 | QString result; | 16729 | QString result; |
16638 | result.setLength( len ); // worst case | 16730 | result.setLength( len ); // worst case |
16639 | QChar *qch = (QChar *)result.unicode(); | 16731 | QChar *qch = (QChar *)result.unicode(); |
16640 | ushort uc = 0; | 16732 | ushort uc = 0; |
@@ -16673,30 +16765,60 @@ QString QString::fromUtf8( const char* utf8, int len ) | |||
16673 | } | 16765 | } |
16674 | 16766 | ||
16675 | /*! | 16767 | /*! |
16676 | Returns the Unicode string decoded from the first \a len | 16768 | Returns the Unicode string decoded from the first \a len |
16677 | characters of \a chars, ignoring the rest of \a chars. If \a len | 16769 | characters of \a ascii, ignoring the rest of \a ascii. If \a len |
16678 | is -1 then the length of \a chars is used. If \a len is bigger | 16770 | is -1 then the length of \a ascii is used. If \a len is bigger |
16679 | than the length of \a chars then it will use the length of \a | 16771 | than the length of \a ascii then it will use the length of \a |
16680 | chars. | 16772 | ascii. |
16773 | |||
16774 | If a codec has been set using QTextCodec::codecForCStrings(), | ||
16775 | it is used to convert Unicode to 8-bit char. Otherwise, this function | ||
16776 | does the same as fromLatin1(). | ||
16681 | 16777 | ||
16682 | This is the same as the QString(const char*) constructor, but you | 16778 | This is the same as the QString(const char*) constructor, but you |
16683 | can make that constructor invisible if you compile with the define | 16779 | can make that constructor invisible if you compile with the define |
16684 | \c QT_NO_CAST_ASCII, in which case you can explicitly create a | 16780 | \c QT_NO_CAST_ASCII, in which case you can explicitly create a |
16685 | QString from Latin-1 text using this function. | 16781 | QString from 8-bit ASCII text using this function. |
16686 | 16782 | ||
16687 | \code | 16783 | \code |
16688 | QString str = QString::fromLatin1( "123456789", 5 ); | 16784 | QString str = QString::fromAscii( "123456789", 5 ); |
16689 | // str == "12345" | 16785 | // str == "12345" |
16690 | \endcode | 16786 | \endcode |
16691 | */ | 16787 | */ |
16788 | QString QString::fromAscii( const char* ascii, int len ) | ||
16789 | { | ||
16790 | #ifndef QT_NO_TEXTCODEC | ||
16791 | if ( QTextCodec::codecForCStrings() ) { | ||
16792 | if ( !ascii ) | ||
16793 | return QString::null; | ||
16794 | if ( len < 0 ) | ||
16795 | len = strlen( ascii ); | ||
16796 | if ( len == 0 || *ascii == '\0' ) | ||
16797 | return QString::fromLatin1( "" ); | ||
16798 | return QTextCodec::codecForCStrings()->toUnicode( ascii, len ); | ||
16799 | } | ||
16800 | #endif | ||
16801 | return fromLatin1( ascii, len ); | ||
16802 | } | ||
16803 | |||
16804 | |||
16805 | /*! | ||
16806 | Returns the Unicode string decoded from the first \a len | ||
16807 | characters of \a chars, ignoring the rest of \a chars. If \a len | ||
16808 | is -1 then the length of \a chars is used. If \a len is bigger | ||
16809 | than the length of \a chars then it will use the length of \a | ||
16810 | chars. | ||
16811 | |||
16812 | \sa fromAscii() | ||
16813 | */ | ||
16692 | QString QString::fromLatin1( const char* chars, int len ) | 16814 | QString QString::fromLatin1( const char* chars, int len ) |
16693 | { | 16815 | { |
16694 | uint l; | 16816 | uint l; |
16695 | QChar *uc; | 16817 | QChar *uc; |
16696 | if ( len < 0 ) | 16818 | if ( len < 0 ) |
16697 | len = -1; | 16819 | len = -1; |
16698 | uc = internalAsciiToUnicode( chars, &l, len ); | 16820 | uc = internalLatin1ToUnicode( chars, &l, len ); |
16699 | return QString( new QStringData(uc, l, l), TRUE ); | 16821 | return QString( new QStringData(uc, l, l), TRUE ); |
16700 | } | 16822 | } |
16701 | 16823 | ||
16702 | /*! | 16824 | /*! |
@@ -16708,18 +16830,17 @@ QString QString::fromLatin1( const char* chars, int len ) | |||
16708 | 16830 | ||
16709 | /*! | 16831 | /*! |
16710 | Returns the string encoded in a locale-specific format. On X11, | 16832 | Returns the string encoded in a locale-specific format. On X11, |
16711 | this is the QTextCodec::codecForLocale(). On Windows, it is a | 16833 | this is the QTextCodec::codecForLocale(). On Windows, it is a |
16712 | system-defined encoding. On Mac OS X, this always uses utf8 as the | 16834 | system-defined encoding. On Mac OS X, this always uses UTF-8 as |
16713 | encoding. | 16835 | the encoding. |
16714 | 16836 | ||
16715 | See QTextCodec for more diverse coding/decoding of Unicode | 16837 | See QTextCodec for more diverse coding/decoding of Unicode |
16716 | strings. | 16838 | strings. |
16717 | 16839 | ||
16718 | \sa QString::fromLocal8Bit(), latin1(), utf8() | 16840 | \sa fromLocal8Bit(), ascii(), latin1(), utf8() |
16719 | */ | 16841 | */ |
16720 | 16842 | ||
16721 | |||
16722 | QCString QString::local8Bit() const | 16843 | QCString QString::local8Bit() const |
16723 | { | 16844 | { |
16724 | #ifdef QT_NO_TEXTCODEC | 16845 | #ifdef QT_NO_TEXTCODEC |
16725 | return latin1(); | 16846 | return latin1(); |
@@ -16739,9 +16860,9 @@ QCString QString::local8Bit() const | |||
16739 | #ifdef Q_WS_WIN | 16860 | #ifdef Q_WS_WIN |
16740 | return qt_winQString2MB( *this ); | 16861 | return qt_winQString2MB( *this ); |
16741 | #endif | 16862 | #endif |
16742 | #ifdef Q_WS_QWS | 16863 | #ifdef Q_WS_QWS |
16743 | return utf8(); // ##### if there is ANY 8 bit format supported? | 16864 | return utf8(); // ### if there is any 8 bit format supported? |
16744 | #endif | 16865 | #endif |
16745 | #endif | 16866 | #endif |
16746 | } | 16867 | } |
16747 | 16868 | ||
@@ -16770,9 +16891,10 @@ QString QString::fromLocal8Bit( const char* local8Bit, int len ) | |||
16770 | if ( !local8Bit ) | 16891 | if ( !local8Bit ) |
16771 | return QString::null; | 16892 | return QString::null; |
16772 | #ifdef Q_WS_X11 | 16893 | #ifdef Q_WS_X11 |
16773 | QTextCodec* codec = QTextCodec::codecForLocale(); | 16894 | QTextCodec* codec = QTextCodec::codecForLocale(); |
16774 | if ( len < 0 ) len = qstrlen(local8Bit); | 16895 | if ( len < 0 ) |
16896 | len = strlen( local8Bit ); | ||
16775 | return codec | 16897 | return codec |
16776 | ? codec->toUnicode( local8Bit, len ) | 16898 | ? codec->toUnicode( local8Bit, len ) |
16777 | : fromLatin1( local8Bit, len ); | 16899 | : fromLatin1( local8Bit, len ); |
16778 | #endif | 16900 | #endif |
@@ -16803,8 +16925,14 @@ QString QString::fromLocal8Bit( const char* local8Bit, int len ) | |||
16803 | that automatic casts are not done. This has the added advantage | 16925 | that automatic casts are not done. This has the added advantage |
16804 | that you catch the programming error described in operator!(). | 16926 | that you catch the programming error described in operator!(). |
16805 | */ | 16927 | */ |
16806 | 16928 | ||
16929 | /*! | ||
16930 | \fn QString::operator std::string() const | ||
16931 | |||
16932 | Returns ascii(). | ||
16933 | */ | ||
16934 | |||
16807 | 16935 | ||
16808 | /*! | 16936 | /*! |
16809 | Returns the QString as a zero terminated array of unsigned shorts | 16937 | Returns the QString as a zero terminated array of unsigned shorts |
16810 | if the string is not null; otherwise returns zero. | 16938 | if the string is not null; otherwise returns zero. |
@@ -16818,10 +16946,8 @@ const unsigned short *QString::ucs2() const | |||
16818 | return 0; | 16946 | return 0; |
16819 | unsigned int len = d->len; | 16947 | unsigned int len = d->len; |
16820 | if ( d->maxl < len + 1 ) { | 16948 | if ( d->maxl < len + 1 ) { |
16821 | // detach, grow or shrink | 16949 | // detach, grow or shrink |
16822 | Q2HELPER(stat_copy_on_write++) | ||
16823 | Q2HELPER(stat_copy_on_write_size += len) | ||
16824 | uint newMax = computeNewMax( len + 1 ); | 16950 | uint newMax = computeNewMax( len + 1 ); |
16825 | QChar* nd = QT_ALLOC_QCHAR_VEC( newMax ); | 16951 | QChar* nd = QT_ALLOC_QCHAR_VEC( newMax ); |
16826 | if ( nd ) { | 16952 | if ( nd ) { |
16827 | if ( d->unicode ) | 16953 | if ( d->unicode ) |
@@ -16982,10 +17108,8 @@ QString& QString::setUnicode( const QChar *unicode, uint len ) | |||
16982 | } | 17108 | } |
16983 | } else if ( d->count != 1 || len > d->maxl || | 17109 | } else if ( d->count != 1 || len > d->maxl || |
16984 | ( len * 4 < d->maxl && d->maxl > 4 ) ) { | 17110 | ( len * 4 < d->maxl && d->maxl > 4 ) ) { |
16985 | // detach, grown or shrink | 17111 | // detach, grown or shrink |
16986 | Q2HELPER(stat_copy_on_write++) | ||
16987 | Q2HELPER(stat_copy_on_write_size+=d->len) | ||
16988 | uint newMax = computeNewMax( len ); | 17112 | uint newMax = computeNewMax( len ); |
16989 | QChar* nd = QT_ALLOC_QCHAR_VEC( newMax ); | 17113 | QChar* nd = QT_ALLOC_QCHAR_VEC( newMax ); |
16990 | if ( unicode ) | 17114 | if ( unicode ) |
16991 | memcpy( nd, unicode, sizeof(QChar)*len ); | 17115 | memcpy( nd, unicode, sizeof(QChar)*len ); |
@@ -17017,8 +17141,30 @@ QString& QString::setUnicodeCodes( const ushort* unicode_as_ushorts, uint len ) | |||
17017 | } | 17141 | } |
17018 | 17142 | ||
17019 | 17143 | ||
17020 | /*! | 17144 | /*! |
17145 | Sets this string to \a str, interpreted as a classic 8-bit ASCII C | ||
17146 | string. If \a len is -1 (the default), then it is set to | ||
17147 | strlen(str). | ||
17148 | |||
17149 | If \a str is 0 a null string is created. If \a str is "", an empty | ||
17150 | string is created. | ||
17151 | |||
17152 | \sa isNull(), isEmpty() | ||
17153 | */ | ||
17154 | |||
17155 | QString &QString::setAscii( const char *str, int len ) | ||
17156 | { | ||
17157 | #ifndef QT_NO_TEXTCODEC | ||
17158 | if ( QTextCodec::codecForCStrings() ) { | ||
17159 | *this = QString::fromAscii( str, len ); | ||
17160 | return *this; | ||
17161 | } | ||
17162 | #endif // QT_NO_TEXTCODEC | ||
17163 | return setLatin1( str, len ); | ||
17164 | } | ||
17165 | |||
17166 | /*! | ||
17021 | Sets this string to \a str, interpreted as a classic Latin1 C | 17167 | Sets this string to \a str, interpreted as a classic Latin1 C |
17022 | string. If \a len is -1 (the default), then it is set to | 17168 | string. If \a len is -1 (the default), then it is set to |
17023 | strlen(str). | 17169 | strlen(str). |
17024 | 17170 | ||
@@ -17032,9 +17178,9 @@ QString &QString::setLatin1( const char *str, int len ) | |||
17032 | { | 17178 | { |
17033 | if ( str == 0 ) | 17179 | if ( str == 0 ) |
17034 | return setUnicode(0,0); | 17180 | return setUnicode(0,0); |
17035 | if ( len < 0 ) | 17181 | if ( len < 0 ) |
17036 | len = qstrlen(str); | 17182 | len = strlen( str ); |
17037 | if ( len == 0 ) { // won't make a null string | 17183 | if ( len == 0 ) { // won't make a null string |
17038 | *this = QString::fromLatin1( "" ); | 17184 | *this = QString::fromLatin1( "" ); |
17039 | } else { | 17185 | } else { |
17040 | setUnicode( 0, len ); // resize but not copy | 17186 | setUnicode( 0, len ); // resize but not copy |
@@ -17050,18 +17196,18 @@ QString &QString::setLatin1( const char *str, int len ) | |||
17050 | void QString::checkSimpleText() const | 17196 | void QString::checkSimpleText() const |
17051 | { | 17197 | { |
17052 | QChar *p = d->unicode; | 17198 | QChar *p = d->unicode; |
17053 | QChar *end = p + d->len; | 17199 | QChar *end = p + d->len; |
17054 | d->simpletext = 1; | ||
17055 | while( p < end ) { | 17200 | while( p < end ) { |
17056 | ushort uc = p->unicode(); | 17201 | ushort uc = p->unicode(); |
17057 | // sort out regions of complex text formatting | 17202 | // sort out regions of complex text formatting |
17058 | if ( uc > 0x058f && ( uc < 0x1100 || uc > 0xfb0f ) ) { | 17203 | if ( uc > 0x058f && ( uc < 0x1100 || uc > 0xfb0f ) ) { |
17059 | d->simpletext = 0; | 17204 | d->issimpletext = FALSE; |
17060 | return; | 17205 | return; |
17061 | } | 17206 | } |
17062 | p++; | 17207 | p++; |
17063 | } | 17208 | } |
17209 | d->issimpletext = TRUE; | ||
17064 | } | 17210 | } |
17065 | 17211 | ||
17066 | /*! \fn bool QString::simpleText() const | 17212 | /*! \fn bool QString::simpleText() const |
17067 | \internal | 17213 | \internal |
diff --git a/qmake/tools/qtextstream.cpp b/qmake/tools/qtextstream.cpp index 75c6531..ddca5bd 100644 --- a/qmake/tools/qtextstream.cpp +++ b/qmake/tools/qtextstream.cpp | |||
@@ -1088,9 +1088,9 @@ QTextStream &QTextStream::writeBlock( const QChar* p, uint len ) | |||
1088 | dev->writeBlock( block, l ); | 1088 | dev->writeBlock( block, l ); |
1089 | } else | 1089 | } else |
1090 | #endif | 1090 | #endif |
1091 | if ( latin1 ) { | 1091 | if ( latin1 ) { |
1092 | char *str = QString::unicodeToAscii( p, len ); | 1092 | char *str = QString::unicodeToLatin1( p, len ); |
1093 | dev->writeBlock( str, len ); | 1093 | dev->writeBlock( str, len ); |
1094 | delete [] str; | 1094 | delete [] str; |
1095 | } else if ( internalOrder ) { | 1095 | } else if ( internalOrder ) { |
1096 | if ( doUnicodeHeader ) { | 1096 | if ( doUnicodeHeader ) { |
diff --git a/qmake/tools/qucom.cpp b/qmake/tools/qucom.cpp index 6086a79..658da97 100644 --- a/qmake/tools/qucom.cpp +++ b/qmake/tools/qucom.cpp | |||
@@ -295,27 +295,23 @@ void QUType_int::set( QUObject *o, int v ) | |||
295 | } | 295 | } |
296 | 296 | ||
297 | bool QUType_int::canConvertFrom( QUObject *o, QUType *t ) | 297 | bool QUType_int::canConvertFrom( QUObject *o, QUType *t ) |
298 | { | 298 | { |
299 | if ( isEqual( t, &static_QUType_double ) || | 299 | if ( isEqual( t, &static_QUType_double ) ) |
300 | isEqual( t, &static_QUType_float ) ) | ||
301 | return TRUE; | 300 | return TRUE; |
302 | 301 | ||
303 | return t->canConvertTo( o, this ); | 302 | return t->canConvertTo( o, this ); |
304 | } | 303 | } |
305 | 304 | ||
306 | bool QUType_int::canConvertTo( QUObject * /*o*/, QUType *t ) | 305 | bool QUType_int::canConvertTo( QUObject * /*o*/, QUType *t ) |
307 | { | 306 | { |
308 | return isEqual( t, &static_QUType_double ) || | 307 | return isEqual( t, &static_QUType_double ); |
309 | isEqual( t, &static_QUType_float ); | ||
310 | } | 308 | } |
311 | 309 | ||
312 | bool QUType_int::convertFrom( QUObject *o, QUType *t ) | 310 | bool QUType_int::convertFrom( QUObject *o, QUType *t ) |
313 | { | 311 | { |
314 | if ( isEqual( t, &static_QUType_double ) ) | 312 | if ( isEqual( t, &static_QUType_double ) ) |
315 | o->payload.i = (long)o->payload.d; | 313 | o->payload.i = (long)o->payload.d; |
316 | else if ( isEqual( t, &static_QUType_float ) ) | ||
317 | o->payload.i = (long)o->payload.f; | ||
318 | else | 314 | else |
319 | return t->convertTo( o, this ); | 315 | return t->convertTo( o, this ); |
320 | 316 | ||
321 | o->type = this; | 317 | o->type = this; |
@@ -326,11 +322,8 @@ bool QUType_int::convertTo( QUObject *o, QUType *t ) | |||
326 | { | 322 | { |
327 | if ( isEqual( t, &static_QUType_double ) ) { | 323 | if ( isEqual( t, &static_QUType_double ) ) { |
328 | o->payload.d = (double)o->payload.i; | 324 | o->payload.d = (double)o->payload.i; |
329 | o->type = &static_QUType_double; | 325 | o->type = &static_QUType_double; |
330 | } else if ( isEqual( t, &static_QUType_float ) ) { | ||
331 | o->payload.f = (float)o->payload.i; | ||
332 | o->type = &static_QUType_float; | ||
333 | } else | 326 | } else |
334 | return FALSE; | 327 | return FALSE; |
335 | return TRUE; | 328 | return TRUE; |
336 | } | 329 | } |
@@ -344,50 +337,8 @@ int QUType_int::serializeFrom( QUObject *, QUBuffer * ) | |||
344 | { | 337 | { |
345 | return 0; | 338 | return 0; |
346 | } | 339 | } |
347 | 340 | ||
348 | // {5938712A-C496-11D5-8CB2-00C0F03BC0F3} | ||
349 | const QUuid TID_QUType_uint( 0x5938712a, 0xc496, 0x11d5, 0x8c, 0xb2, 0x00, 0xc0, 0xf0, 0x3b, 0xc0, 0xf3); | ||
350 | QUType_uint static_QUType_uint; | ||
351 | const QUuid *QUType_uint::uuid() const { return &TID_QUType_uint; } | ||
352 | const char *QUType_uint::desc() const { return "uint"; } | ||
353 | |||
354 | void QUType_uint::set( QUObject *o, uint v ) | ||
355 | { | ||
356 | o->payload.ui = v; | ||
357 | o->type = this; | ||
358 | } | ||
359 | |||
360 | bool QUType_uint::canConvertFrom( QUObject *o, QUType *t ) | ||
361 | { | ||
362 | return t->canConvertTo( o, this ); | ||
363 | } | ||
364 | |||
365 | bool QUType_uint::canConvertTo( QUObject * /*o*/, QUType * /*t*/ ) | ||
366 | { | ||
367 | return FALSE; | ||
368 | } | ||
369 | |||
370 | bool QUType_uint::convertFrom( QUObject *o, QUType *t ) | ||
371 | { | ||
372 | return t->convertTo( o, this ); | ||
373 | } | ||
374 | |||
375 | bool QUType_uint::convertTo( QUObject * /*o*/, QUType * /*t*/ ) | ||
376 | { | ||
377 | return FALSE; | ||
378 | } | ||
379 | |||
380 | int QUType_uint::serializeTo( QUObject *, QUBuffer * ) | ||
381 | { | ||
382 | return 0; | ||
383 | } | ||
384 | |||
385 | int QUType_uint::serializeFrom( QUObject *, QUBuffer * ) | ||
386 | { | ||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | // {2D0974E5-0BA6-4ec2-8837-C198972CB48C} | 341 | // {2D0974E5-0BA6-4ec2-8837-C198972CB48C} |
391 | const QUuid TID_QUType_double( 0x2d0974e5, 0xba6, 0x4ec2, 0x88, 0x37, 0xc1, 0x98, 0x97, 0x2c, 0xb4, 0x8c ); | 342 | const QUuid TID_QUType_double( 0x2d0974e5, 0xba6, 0x4ec2, 0x88, 0x37, 0xc1, 0x98, 0x97, 0x2c, 0xb4, 0x8c ); |
392 | QUType_double static_QUType_double; | 343 | QUType_double static_QUType_double; |
393 | const QUuid *QUType_double::uuid() const { return &TID_QUType_double; } | 344 | const QUuid *QUType_double::uuid() const { return &TID_QUType_double; } |
@@ -400,27 +351,23 @@ void QUType_double::set( QUObject *o, double v ) | |||
400 | } | 351 | } |
401 | 352 | ||
402 | bool QUType_double::canConvertFrom( QUObject *o, QUType *t ) | 353 | bool QUType_double::canConvertFrom( QUObject *o, QUType *t ) |
403 | { | 354 | { |
404 | if ( isEqual( t, &static_QUType_int ) || | 355 | if ( isEqual( t, &static_QUType_int ) ) |
405 | isEqual( t, &static_QUType_float) ) | ||
406 | return TRUE; | 356 | return TRUE; |
407 | 357 | ||
408 | return t->canConvertTo( o, this ); | 358 | return t->canConvertTo( o, this ); |
409 | } | 359 | } |
410 | 360 | ||
411 | bool QUType_double::canConvertTo( QUObject * /*o*/, QUType *t ) | 361 | bool QUType_double::canConvertTo( QUObject * /*o*/, QUType *t ) |
412 | { | 362 | { |
413 | return isEqual( t, &static_QUType_int ) || | 363 | return isEqual( t, &static_QUType_int ); |
414 | isEqual( t, &static_QUType_float ); | ||
415 | } | 364 | } |
416 | 365 | ||
417 | bool QUType_double::convertFrom( QUObject *o, QUType *t ) | 366 | bool QUType_double::convertFrom( QUObject *o, QUType *t ) |
418 | { | 367 | { |
419 | if ( isEqual( t, &static_QUType_int ) ) | 368 | if ( isEqual( t, &static_QUType_int ) ) |
420 | o->payload.d = (double)o->payload.i; | 369 | o->payload.d = (double)o->payload.i; |
421 | else if ( isEqual( t, &static_QUType_float ) ) | ||
422 | o->payload.d = (double)o->payload.f; | ||
423 | else | 370 | else |
424 | return t->convertTo( o, this ); | 371 | return t->convertTo( o, this ); |
425 | 372 | ||
426 | o->type = this; | 373 | o->type = this; |
@@ -449,72 +396,8 @@ int QUType_double::serializeFrom( QUObject *, QUBuffer * ) | |||
449 | { | 396 | { |
450 | return 0; | 397 | return 0; |
451 | } | 398 | } |
452 | 399 | ||
453 | |||
454 | // {544C5175-6993-4486-B04D-CEC4D21BF4B9 } | ||
455 | const QUuid TID_QUType_float( 0x544c5175, 0x6993, 0x4486, 0xb0, 0x4d, 0xce, 0xc4, 0xd2, 0x1b, 0xf4, 0xb9 ); | ||
456 | QUType_float static_QUType_float; | ||
457 | const QUuid *QUType_float::uuid() const { return &TID_QUType_float; } | ||
458 | const char *QUType_float::desc() const {return "float"; } | ||
459 | |||
460 | void QUType_float::set( QUObject *o, float v ) | ||
461 | { | ||
462 | o->payload.f = v; | ||
463 | o->type = this; | ||
464 | } | ||
465 | |||
466 | bool QUType_float::canConvertFrom( QUObject *o, QUType *t ) | ||
467 | { | ||
468 | if ( isEqual( t, &static_QUType_int ) || | ||
469 | isEqual( t, &static_QUType_double ) ) | ||
470 | return TRUE; | ||
471 | |||
472 | return t->canConvertTo( o, this ); | ||
473 | } | ||
474 | |||
475 | bool QUType_float::canConvertTo( QUObject * /*o*/, QUType *t ) | ||
476 | { | ||
477 | return isEqual( t, &static_QUType_int ) || | ||
478 | isEqual( t, &static_QUType_double ); | ||
479 | } | ||
480 | |||
481 | bool QUType_float::convertFrom( QUObject *o, QUType *t ) | ||
482 | { | ||
483 | if ( isEqual( t, &static_QUType_int ) ) | ||
484 | o->payload.f = (float)o->payload.i; | ||
485 | else if ( isEqual( t, &static_QUType_double ) ) | ||
486 | o->payload.f = (float)o->payload.d; | ||
487 | else | ||
488 | return t->convertTo( o, this ); | ||
489 | |||
490 | o->type = this; | ||
491 | return TRUE; | ||
492 | } | ||
493 | |||
494 | bool QUType_float::convertTo( QUObject *o, QUType *t ) | ||
495 | { | ||
496 | if ( isEqual( t, &static_QUType_int ) ) { | ||
497 | o->payload.i = (int) o->payload.f; | ||
498 | o->type = &static_QUType_int; | ||
499 | } else if ( isEqual( t, &static_QUType_double ) ) { | ||
500 | o->payload.d = (double) o->payload.f; | ||
501 | o->type = &static_QUType_double; | ||
502 | } else | ||
503 | return FALSE; | ||
504 | return TRUE; | ||
505 | } | ||
506 | |||
507 | int QUType_float::serializeTo( QUObject *, QUBuffer * ) | ||
508 | { | ||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | int QUType_float::serializeFrom( QUObject *, QUBuffer * ) | ||
513 | { | ||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | // {EFCDD1D4-77A3-4b8e-8D46-DC14B8D393E9} | 400 | // {EFCDD1D4-77A3-4b8e-8D46-DC14B8D393E9} |
518 | const QUuid TID_QUType_charstar( 0xefcdd1d4, 0x77a3, 0x4b8e, 0x8d, 0x46, 0xdc, 0x14, 0xb8, 0xd3, 0x93, 0xe9 ); | 401 | const QUuid TID_QUType_charstar( 0xefcdd1d4, 0x77a3, 0x4b8e, 0x8d, 0x46, 0xdc, 0x14, 0xb8, 0xd3, 0x93, 0xe9 ); |
519 | QUType_charstar static_QUType_charstar; | 402 | QUType_charstar static_QUType_charstar; |
520 | const QUuid *QUType_charstar::uuid() const { return &TID_QUType_charstar; } | 403 | const QUuid *QUType_charstar::uuid() const { return &TID_QUType_charstar; } |
@@ -592,9 +475,8 @@ void QUType_QString::set( QUObject *o, const QString& v ) | |||
592 | bool QUType_QString::canConvertFrom( QUObject *o, QUType *t ) | 475 | bool QUType_QString::canConvertFrom( QUObject *o, QUType *t ) |
593 | { | 476 | { |
594 | if ( isEqual( t, &static_QUType_charstar ) || | 477 | if ( isEqual( t, &static_QUType_charstar ) || |
595 | isEqual( t, &static_QUType_double ) || | 478 | isEqual( t, &static_QUType_double ) || |
596 | isEqual( t, &static_QUType_float ) || | ||
597 | isEqual( t, &static_QUType_int ) ) | 479 | isEqual( t, &static_QUType_int ) ) |
598 | return TRUE; | 480 | return TRUE; |
599 | 481 | ||
600 | return t->canConvertTo( o, this ); | 482 | return t->canConvertTo( o, this ); |
@@ -603,10 +485,9 @@ bool QUType_QString::canConvertFrom( QUObject *o, QUType *t ) | |||
603 | bool QUType_QString::canConvertTo( QUObject * /*o*/, QUType *t ) | 485 | bool QUType_QString::canConvertTo( QUObject * /*o*/, QUType *t ) |
604 | { | 486 | { |
605 | return isEqual( t, &static_QUType_charstar ) || | 487 | return isEqual( t, &static_QUType_charstar ) || |
606 | isEqual( t, &static_QUType_int ) || | 488 | isEqual( t, &static_QUType_int ) || |
607 | isEqual( t, &static_QUType_double ) || | 489 | isEqual( t, &static_QUType_double ); |
608 | isEqual( t, &static_QUType_float ); | ||
609 | } | 490 | } |
610 | 491 | ||
611 | bool QUType_QString::convertFrom( QUObject *o, QUType *t ) | 492 | bool QUType_QString::convertFrom( QUObject *o, QUType *t ) |
612 | { | 493 | { |
@@ -614,10 +495,8 @@ bool QUType_QString::convertFrom( QUObject *o, QUType *t ) | |||
614 | if ( isEqual( t, &static_QUType_charstar ) ) | 495 | if ( isEqual( t, &static_QUType_charstar ) ) |
615 | str = new QString( o->payload.charstar.ptr ); | 496 | str = new QString( o->payload.charstar.ptr ); |
616 | else if ( isEqual( t, &static_QUType_double ) ) | 497 | else if ( isEqual( t, &static_QUType_double ) ) |
617 | str = new QString( QString::number( o->payload.d ) ); | 498 | str = new QString( QString::number( o->payload.d ) ); |
618 | else if ( isEqual( t, &static_QUType_float ) ) | ||
619 | str = new QString( QString::number( o->payload.f ) ); | ||
620 | else if ( isEqual( t, &static_QUType_int ) ) | 499 | else if ( isEqual( t, &static_QUType_int ) ) |
621 | str = new QString( QString::number( o->payload.i ) ); | 500 | str = new QString( QString::number( o->payload.i ) ); |
622 | else | 501 | else |
623 | return t->convertTo( o, this ); | 502 | return t->convertTo( o, this ); |
@@ -640,11 +519,8 @@ bool QUType_QString::convertTo( QUObject *o, QUType *t ) | |||
640 | o->type = &static_QUType_int; | 519 | o->type = &static_QUType_int; |
641 | } else if ( isEqual( t, &static_QUType_double ) ) { | 520 | } else if ( isEqual( t, &static_QUType_double ) ) { |
642 | o->payload.d = str->toDouble(); | 521 | o->payload.d = str->toDouble(); |
643 | o->type = &static_QUType_double; | 522 | o->type = &static_QUType_double; |
644 | } else if ( isEqual( t, &static_QUType_float ) ) { | ||
645 | o->payload.d = str->toFloat(); | ||
646 | o->type = &static_QUType_float; | ||
647 | } else { | 523 | } else { |
648 | return FALSE; | 524 | return FALSE; |
649 | } | 525 | } |
650 | delete str; | 526 | delete str; |
diff --git a/qmake/tools/qwaitcondition_unix.cpp b/qmake/tools/qwaitcondition_unix.cpp index 99c1014..6684617 100644 --- a/qmake/tools/qwaitcondition_unix.cpp +++ b/qmake/tools/qwaitcondition_unix.cpp | |||
@@ -123,9 +123,9 @@ struct QWaitConditionPrivate { | |||
123 | for (;;) { | 123 | for (;;) { |
124 | getchar(); | 124 | getchar(); |
125 | mymutex.lock(); | 125 | mymutex.lock(); |
126 | // Sleep until there are no busy worker threads | 126 | // Sleep until there are no busy worker threads |
127 | while( count > 0 ) { | 127 | while( mycount > 0 ) { |
128 | mymutex.unlock(); | 128 | mymutex.unlock(); |
129 | sleep( 1 ); | 129 | sleep( 1 ); |
130 | mymutex.lock(); | 130 | mymutex.lock(); |
131 | } | 131 | } |
@@ -223,17 +223,19 @@ void QWaitCondition::wakeAll() | |||
223 | \sa wakeOne(), wakeAll() | 223 | \sa wakeOne(), wakeAll() |
224 | */ | 224 | */ |
225 | bool QWaitCondition::wait(unsigned long time) | 225 | bool QWaitCondition::wait(unsigned long time) |
226 | { | 226 | { |
227 | pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | 227 | pthread_mutex_t mutex; |
228 | pthread_mutex_init( &mutex, 0 ); | ||
229 | pthread_mutex_lock( &mutex ); | ||
228 | 230 | ||
229 | int ret; | 231 | int ret; |
230 | if (time != ULONG_MAX) { | 232 | if (time != ULONG_MAX) { |
231 | struct timeval tv; | 233 | struct timeval tv; |
232 | gettimeofday(&tv, 0); | 234 | gettimeofday(&tv, 0); |
233 | 235 | ||
234 | timespec ti; | 236 | timespec ti; |
235 | ti.tv_nsec = (tv.tv_usec * 1000) + (time % 1000) * 1000; | 237 | ti.tv_nsec = ( tv.tv_usec + ( time % 1000 ) * 1000 ) * 1000; |
236 | ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 ); | 238 | ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 ); |
237 | ti.tv_nsec %= 1000000000; | 239 | ti.tv_nsec %= 1000000000; |
238 | 240 | ||
239 | ret = pthread_cond_timedwait(&d->cond, &mutex, &ti); | 241 | ret = pthread_cond_timedwait(&d->cond, &mutex, &ti); |
@@ -244,8 +246,11 @@ bool QWaitCondition::wait(unsigned long time) | |||
244 | if (ret && ret != ETIMEDOUT) | 246 | if (ret && ret != ETIMEDOUT) |
245 | qWarning("Wait condition wait failure: %s",strerror(ret)); | 247 | qWarning("Wait condition wait failure: %s",strerror(ret)); |
246 | #endif | 248 | #endif |
247 | 249 | ||
250 | pthread_mutex_unlock( &mutex ); | ||
251 | pthread_mutex_destroy( &mutex ); | ||
252 | |||
248 | return (ret == 0); | 253 | return (ret == 0); |
249 | } | 254 | } |
250 | 255 | ||
251 | /*! | 256 | /*! |
@@ -290,9 +295,9 @@ bool QWaitCondition::wait(QMutex *mutex, unsigned long time) | |||
290 | struct timeval tv; | 295 | struct timeval tv; |
291 | gettimeofday(&tv, 0); | 296 | gettimeofday(&tv, 0); |
292 | 297 | ||
293 | timespec ti; | 298 | timespec ti; |
294 | ti.tv_nsec = (tv.tv_usec * 1000) + (time % 1000) * 1000; | 299 | ti.tv_nsec = ( tv.tv_usec + ( time % 1000 ) * 1000 ) * 1000; |
295 | ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 ); | 300 | ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 ); |
296 | ti.tv_nsec %= 1000000000; | 301 | ti.tv_nsec %= 1000000000; |
297 | 302 | ||
298 | ret = pthread_cond_timedwait(&d->cond, &mutex->d->handle, &ti); | 303 | ret = pthread_cond_timedwait(&d->cond, &mutex->d->handle, &ti); |