summaryrefslogtreecommitdiff
path: root/qmake/tools
Side-by-side diff
Diffstat (limited to 'qmake/tools') (more/less context) (ignore whitespace changes)
-rw-r--r--qmake/tools/qbitarray.cpp3
-rw-r--r--qmake/tools/qbuffer.cpp4
-rw-r--r--qmake/tools/qcomlibrary.cpp43
-rw-r--r--qmake/tools/qconfig.cpp14
-rw-r--r--qmake/tools/qcriticalsection_p.cpp2
-rw-r--r--qmake/tools/qcstring.cpp107
-rw-r--r--qmake/tools/qdatastream.cpp24
-rw-r--r--qmake/tools/qdatetime.cpp70
-rw-r--r--qmake/tools/qdir.cpp94
-rw-r--r--qmake/tools/qdir_unix.cpp54
-rw-r--r--qmake/tools/qfile.cpp3
-rw-r--r--qmake/tools/qfile_unix.cpp13
-rw-r--r--qmake/tools/qfileinfo.cpp4
-rw-r--r--qmake/tools/qfileinfo_unix.cpp4
-rw-r--r--qmake/tools/qgarray.cpp97
-rw-r--r--qmake/tools/qgdict.cpp5
-rw-r--r--qmake/tools/qglist.cpp6
-rw-r--r--qmake/tools/qglobal.cpp45
-rw-r--r--qmake/tools/qgpluginmanager.cpp4
-rw-r--r--qmake/tools/qgvector.cpp9
-rw-r--r--qmake/tools/qlibrary.cpp13
-rw-r--r--qmake/tools/qlibrary_unix.cpp21
-rw-r--r--qmake/tools/qmutex_unix.cpp8
-rw-r--r--qmake/tools/qmutexpool.cpp78
-rw-r--r--qmake/tools/qregexp.cpp70
-rw-r--r--qmake/tools/qsemaphore_unix.cpp26
-rw-r--r--qmake/tools/qsettings.cpp387
-rw-r--r--qmake/tools/qstring.cpp434
-rw-r--r--qmake/tools/qtextstream.cpp2
-rw-r--r--qmake/tools/qucom.cpp136
-rw-r--r--qmake/tools/qwaitcondition_unix.cpp13
31 files changed, 1115 insertions, 678 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
@@ -188,25 +188,26 @@ void QBitArray::pad0()
/*!
\fn uint QBitArray::size() const
Returns the bit array's size (number of bits).
\sa resize()
*/
/*!
Resizes the bit array to \a size bits and returns TRUE if the bit
- array could be resized; otherwise returns FALSE.
+ array could be resized; otherwise returns FALSE. The array becomes
+ a null array if \a size == 0.
If the array is expanded, the new bits are set to 0.
\sa size()
*/
bool QBitArray::resize( uint size )
{
uint s = this->size();
if ( !QByteArray::resize( (size+7)/8 ) )
return FALSE; // cannot resize
SHBLOCK->nbits = 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
@@ -187,26 +187,26 @@ bool QBuffer::setBuffer( QByteArray buf )
*/
bool QBuffer::open( int m )
{
if ( isOpen() ) { // buffer already open
#if defined(QT_CHECK_STATE)
qWarning( "QBuffer::open: Buffer already open" );
#endif
return FALSE;
}
setMode( m );
if ( m & IO_Truncate ) { // truncate buffer
- a.resize( 0 );
- a_len = 0;
+ a.resize( 1 );
+ a_len = 1;
}
if ( m & IO_Append ) { // append to end of buffer
ioIndex = a.size();
} else {
ioIndex = 0;
}
a_inc = 16;
setState( IO_Open );
setStatus( 0 );
return TRUE;
}
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
@@ -54,24 +54,28 @@
#endif
QComLibrary::QComLibrary( const QString &filename )
: QLibrary( filename ), entry( 0 ), libiface( 0 ), qt_version( 0 )
{
}
QComLibrary::~QComLibrary()
{
if ( autoUnload() )
unload();
+ if ( libiface )
+ libiface->release();
+ if ( entry )
+ entry->release();
}
bool QComLibrary::unload()
{
if ( libiface ) {
libiface->cleanup();
if ( !libiface->canUnload() )
return FALSE;
libiface->release();
libiface = 0;
}
int refs = entry ? entry->release() : 0;
@@ -382,47 +386,45 @@ void QComLibrary::createInstanceInternal()
QFileInfo fileinfo( library() );
QString lastModified = fileinfo.lastModified().toString();
QString regkey = QString("/Qt Plugins %1.%2/%3")
.arg( ( QT_VERSION & 0xff0000 ) >> 16 )
.arg( ( QT_VERSION & 0xff00 ) >> 8 )
.arg( library() );
QStringList reg;
uint flags = 0;
QCString key;
bool query_done = FALSE;
bool warn_mismatch = TRUE;
- if ( ! query_done ) {
-
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &cache ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &cache ) : 0 );
#endif // QT_THREAD_SUPPORT
- if ( ! cache ) {
- cache = new QSettings;
- cache->insertSearchPath( QSettings::Windows, "/Trolltech" );
- cleanup_cache.set( &cache );
- }
+ if ( ! cache ) {
+ cache = new QSettings;
+ cache->insertSearchPath( QSettings::Windows, "/Trolltech" );
+ cleanup_cache.set( &cache );
+ }
- reg = cache->readListEntry( regkey );
- if ( reg.count() == 4 ) {
- // check timestamp
- if ( lastModified == reg[3] ) {
- qt_version = reg[0].toUInt(0, 16);
- flags = reg[1].toUInt(0, 16);
- key = reg[2].latin1();
+ reg = cache->readListEntry( regkey );
+ if ( reg.count() == 4 ) {
+ // check timestamp
+ if ( lastModified == reg[3] ) {
+ qt_version = reg[0].toUInt(0, 16);
+ flags = reg[1].toUInt(0, 16);
+ key = reg[2].latin1();
- query_done = TRUE;
- warn_mismatch = FALSE;
- }
+ query_done = TRUE;
+ warn_mismatch = FALSE;
}
}
#if defined(Q_OS_UNIX)
if ( ! query_done ) {
// get the query information directly from the plugin without loading
if ( qt_unix_query( library(), &qt_version, &flags, &key ) ) {
// info read succesfully from library
query_done = TRUE;
}
}
#else // !Q_OS_UNIX
@@ -452,29 +454,24 @@ void QComLibrary::createInstanceInternal()
query_done = TRUE;
}
}
#endif // Q_OS_UNIX
QStringList queried;
queried << QString::number( qt_version,16 )
<< QString::number( flags, 16 )
<< key
<< lastModified;
if ( queried != reg ) {
-
-#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &cache ) );
-#endif // QT_THREAD_SUPPORT
-
cache->writeEntry( regkey, queried );
// delete the cache, which forces the settings to be written
delete cache;
cache = 0;
}
if ( ! query_done ) {
if ( warn_mismatch ) {
qWarning( "Conflict in %s:\n Plugin cannot be queried successfully!",
(const char*) QFile::encodeName( library() ) );
}
unload();
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,17 +1,17 @@
/* Install paths from configure */
-static const char QT_INSTALL_PREFIX [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2";
-static const char QT_INSTALL_BINS [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/bin";
-static const char QT_INSTALL_DOCS [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/doc";
-static const char QT_INSTALL_HEADERS[256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/include";
-static const char QT_INSTALL_LIBS [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/lib";
-static const char QT_INSTALL_PLUGINS[256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2/plugins";
-static const char QT_INSTALL_DATA [256] = "/usr/src/coding/projects/userspace/qt-embedded-free-3.1.0-b2";
+static const char QT_INSTALL_PREFIX [256] = "/opt/qt-x11-free-3.1.2";
+static const char QT_INSTALL_BINS [256] = "/opt/qt-x11-free-3.1.2/bin";
+static const char QT_INSTALL_DOCS [256] = "/opt/qt-x11-free-3.1.2/doc";
+static const char QT_INSTALL_HEADERS[256] = "/opt/qt-x11-free-3.1.2/include";
+static const char QT_INSTALL_LIBS [256] = "/opt/qt-x11-free-3.1.2/lib";
+static const char QT_INSTALL_PLUGINS[256] = "/opt/qt-x11-free-3.1.2/plugins";
+static const char QT_INSTALL_DATA [256] = "/opt/qt-x11-free-3.1.2";
const char *qInstallPath() { return QT_INSTALL_PREFIX; }
const char *qInstallPathDocs() { return QT_INSTALL_DOCS; }
const char *qInstallPathHeaders() { return QT_INSTALL_HEADERS; }
const char *qInstallPathLibs() { return QT_INSTALL_LIBS; }
const char *qInstallPathBins() { return QT_INSTALL_BINS; }
const char *qInstallPathPlugins() { return QT_INSTALL_PLUGINS; }
const char *qInstallPathData() { return QT_INSTALL_DATA; }
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
@@ -1,19 +1,17 @@
/****************************************************************************
** $Id$
**
** Implementation of QCriticalSection class
**
-** Created :
-**
** Copyright (C) 2001 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
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
@@ -132,24 +132,35 @@ char *qstrdup( const char *src )
char *qstrncpy( char *dst, const char *src, uint len )
{
if ( !src || !dst )
return 0;
strncpy( dst, src, len );
if ( len > 0 )
dst[len-1] = '\0';
return dst;
}
/*!
+ \fn uint qstrlen( const char *str );
+
+ \relates QCString
+
+ A safe strlen function.
+
+ Returns the number of characters that precede the terminating '\0'.
+ or 0 if \a str is 0.
+*/
+
+/*!
\fn int qstrcmp( const char *str1, const char *str2 );
\relates QCString
A safe strcmp() function.
Compares \a str1 and \a str2. Returns a negative value if \a str1
is less than \a str2, 0 if \a str1 is equal to \a str2 or a
positive value if \a str1 is greater than \a str2.
Special case I: Returns 0 if \a str1 and \a str2 are both 0.
@@ -290,56 +301,63 @@ static void createCRC16Table() // build CRC16 lookup table
\relates QMemArray
Returns the CRC-16 checksum of \a len bytes starting at \a data.
The checksum is independent of the byte order (endianness).
*/
Q_UINT16 qChecksum( const char *data, uint len )
{
if ( !crc_tbl_init ) { // create lookup table
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &crc_tbl_init ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &crc_tbl_init ) : 0 );
#endif // QT_THREAD_SUPPORT
if ( !crc_tbl_init ) {
createCRC16Table();
crc_tbl_init = TRUE;
}
}
register Q_UINT16 crc = 0xffff;
uchar c;
uchar *p = (uchar *)data;
while ( len-- ) {
c = *p++;
crc = ( (crc >> 4) & 0x0fff ) ^ crc_tbl[((crc ^ c) & 15)];
c >>= 4;
crc = ( (crc >> 4) & 0x0fff ) ^ crc_tbl[((crc ^ c) & 15)];
}
return ~crc & 0xffff;
}
-/*! \fn QByteArray qCompress( const QByteArray& data)
- \relates QByteArray
- \overload
+/*!
+ \fn QByteArray qCompress( const QByteArray& data )
+
+ \relates QByteArray
+
+ Compresses the array \a data and returns the compressed byte
+ array.
+
+ \sa qUncompress()
*/
/*!
- \relates QByteArray
+ \relates QByteArray
- Compresses the array \a data which is \a nbytes long and returns the
- compressed byte array.
+ \overload
- \sa qUncompress()
+ Compresses the array \a data which is \a nbytes long and returns the
+ compressed byte array.
*/
#ifndef QT_NO_COMPRESS
QByteArray qCompress( const uchar* data, int nbytes )
{
if ( nbytes == 0 ) {
QByteArray tmp( 4 );
tmp.fill( 0 );
return tmp;
}
if ( !data ) {
#if defined(QT_CHECK_RANGE)
@@ -370,38 +388,50 @@ QByteArray qCompress( const uchar* data, int nbytes )
bazip.resize( 0 );
break;
case Z_BUF_ERROR:
len *= 2;
break;
}
} while ( res == Z_BUF_ERROR );
return bazip;
}
#endif
-/*! \fn QByteArray qUncompress( const QByteArray& data )
- \relates QByteArray
- \overload
+/*!
+ \fn QByteArray qUncompress( const QByteArray& data )
+
+ \relates QByteArray
+
+ Uncompresses the array \a data and returns the uncompressed byte
+ array.
+
+ Returns an empty QByteArray if the input data was corrupt.
+ \omit
+ ADD THE FOLLOWING FOR Qt 4.0
+ This function will uncompress data compressed with qCompress()
+ from this and any earlier Qt version, back to Qt 3.1 when this
+ feature was added.
+ \endomit
+
+ \sa qCompress()
*/
/*!
- \relates QByteArray
-
- Uncompresses the array \a data which is \a nbytes long and returns
- the uncompressed byte array.
+ \relates QByteArray
- Returns an empty QByteArray if the input data was corrupt.
+ \overload
- \sa qCompress()
+ Uncompresses the array \a data which is \a nbytes long and returns
+ the uncompressed byte array.
*/
#ifndef QT_NO_COMPRESS
QByteArray qUncompress( const uchar* data, int nbytes )
{
if ( !data ) {
#if defined(QT_CHECK_RANGE)
qWarning( "qUncompress: data is NULL." );
#endif
return QByteArray();
}
if ( nbytes <= 4 ) {
@@ -927,31 +957,35 @@ int QCString::find( char c, int index, bool cs ) const
The search is case sensitive if \a cs is TRUE, or case insensitive
if \a cs is FALSE.
Returns the position of \a str, or -1 if \a str could not be
found.
\sa \link #asciinotion Note on character comparisons \endlink
*/
int QCString::find( const char *str, int index, bool cs ) const
{
+ return find( str, index, cs, length() );
+}
+
+int QCString::find( const char *str, int index, bool cs, uint l ) const
+{
if ( (uint)index >= size() )
return -1;
if ( !str )
return -1;
if ( !*str )
return index;
- const uint l = length();
const uint sl = qstrlen( str );
if ( sl + index > l )
return -1;
if ( sl == 1 )
return find( *str, index, cs );
/*
See QString::find() for details.
*/
const char* needle = str;
const char* haystack = data() + index;
@@ -1143,46 +1177,46 @@ int QCString::contains( char c, bool cs ) const
This function counts overlapping substrings, for example, "banana"
contains two occurrences of "ana".
\sa findRev()
\link #asciinotion Note on character comparisons \endlink
*/
int QCString::contains( const char *str, bool cs ) const
{
int count = 0;
int i = -1;
+ uint l = length();
// use find for the faster hashing algorithm
- while ( ( i = find ( str, i+1, cs ) ) != -1 )
+ while ( ( i = find ( str, i+1, cs, l ) ) != -1 )
count++;
return count;
}
/*!
Returns a substring that contains the \a len leftmost characters
of the string.
The whole string is returned if \a len exceeds the length of the
string.
Example:
\code
QCString s = "Pineapple";
QCString t = s.left( 4 ); // t == "Pine"
\endcode
\sa right(), mid()
*/
-
QCString QCString::left( uint len ) const
{
if ( isEmpty() ) {
QCString empty;
return empty;
} else if ( len >= size() ) {
QCString same( data() );
return same;
} else {
QCString s( len+1 );
strncpy( s.data(), data(), len );
*(s.data()+len) = '\0';
@@ -1488,32 +1522,34 @@ QCString QCString::simplifyWhiteSpace() const
\endcode
*/
QCString &QCString::insert( uint index, const char *s )
{
int len = qstrlen(s);
if ( len == 0 )
return *this;
uint olen = length();
int nlen = olen + len;
if ( index >= olen ) { // insert after end of string
detach();
- if ( QByteArray::resize(nlen+index-olen+1) ) {
+ if ( QByteArray::resize(nlen+index-olen+1, QByteArray::SpeedOptim ) ) {
memset( data()+olen, ' ', index-olen );
memcpy( data()+index, s, len+1 );
}
- } else if ( QByteArray::resize(nlen+1) ) { // normal insert
+ } else {
detach();
- memmove( data()+index+len, data()+index, olen-index+1 );
- memcpy( data()+index, s, len );
+ if ( QByteArray::resize(nlen+1, QByteArray::SpeedOptim ) ) { // normal insert
+ memmove( data()+index+len, data()+index, olen-index+1 );
+ memcpy( data()+index, s, len );
+ }
}
return *this;
}
/*!
Inserts character \a c into the string at position \a index and
returns a reference to the string.
If \a index is beyond the end of the string, the string is
padded with spaces (ASCII 32) to length \a index and then \a c
is appended.
@@ -1560,25 +1596,25 @@ QCString &QCString::insert( uint index, char c ) // insert char
QCString &QCString::remove( uint index, uint len )
{
uint olen = length();
if ( index + len >= olen ) { // range problems
if ( index < olen ) { // index ok
detach();
resize( index+1 );
}
} else if ( len != 0 ) {
detach();
memmove( data()+index, data()+index+len, olen-index-len+1 );
- QByteArray::resize(olen-len+1);
+ QByteArray::resize(olen-len+1, QByteArray::SpeedOptim );
}
return *this;
}
/*!
Replaces \a len characters from the string, starting at position
\a index, with \a str, and returns a reference to the string.
If \a index is out of range, nothing is removed and \a str is
appended at the end of the string. If \a index is valid, but \a
index + \a len is larger than the length of the string, \a str
replaces the rest of the string from position \a index.
@@ -1622,49 +1658,50 @@ QCString &QCString::replace( char c, const char *after )
/*! \overload
Replaces every occurrence of the string \a before in the string
with the string \a after. Returns a reference to the string.
Example:
\code
QCString s = "Greek is Greek";
s.replace( "Greek", "English" );
// s == "English is English"
\endcode
*/
+
QCString &QCString::replace( const char *before, const char *after )
{
if ( before == after || isNull() )
return *this;
detach();
int index = 0;
const int bl = before ? strlen( before ) : 0;
const int al = after ? strlen( after ) : 0;
char *d = data();
uint len = length();
if ( bl == al ) {
if ( bl ) {
- while( (index = find( before, index ) ) != -1 ) {
+ while( (index = find( before, index, TRUE, len ) ) != -1 ) {
memcpy( d+index, after, al );
index += bl;
}
}
} else if ( al < bl ) {
uint to = 0;
uint movestart = 0;
uint num = 0;
- while( (index = find( before, index ) ) != -1 ) {
+ while( (index = find( before, index, TRUE, len ) ) != -1 ) {
if ( num ) {
int msize = index - movestart;
if ( msize > 0 ) {
memmove( d + to, d + movestart, msize );
to += msize;
}
} else {
to = index;
}
if ( al ) {
memcpy( d + to, after, al );
to += al;
@@ -1677,25 +1714,25 @@ QCString &QCString::replace( const char *before, const char *after )
int msize = len - movestart;
if ( msize > 0 )
memmove( d + to, d + movestart, msize );
resize( len - num*(bl-al) + 1 );
}
} else {
// the most complex case. We don't want to loose performance by doing repeated
// copies and reallocs of the string.
while( index != -1 ) {
uint indices[4096];
uint pos = 0;
while( pos < 4095 ) {
- index = find(before, index);
+ index = find(before, index, TRUE, len);
if ( index == -1 )
break;
indices[pos++] = index;
index += bl;
// avoid infinite loop
if ( !bl )
index++;
}
if ( !pos )
break;
// we have a table of replacement positions, use them for fast replacing
@@ -1754,70 +1791,70 @@ QCString &QCString::replace( char c1, char c2 )
starting at position \a index.
Returns the position of the next match, or -1 if \a rx was not
found.
\warning If you want to apply this function repeatedly to the same
string it is more efficient to convert the string to a QString and
apply the function to that.
*/
int QCString::find( const QRegExp& rx, int index ) const
{
- QString d = QString::fromLatin1( data() );
+ QString d = QString::fromAscii( data() );
return d.find( rx, index );
}
/*!
\overload
Finds the first occurrence of the regular expression \a rx,
starting at position \a index and searching backwards.
Returns the position of the next match (backwards), or -1 if \a rx
was not found.
\warning If you want to apply this function repeatedly to the same
string it is more efficient to convert the string to a QString and
apply the function to that.
*/
int QCString::findRev( const QRegExp& rx, int index ) const
{
- QString d = QString::fromLatin1( data() );
+ QString d = QString::fromAscii( data() );
return d.findRev( rx, index );
}
/*!
\overload
Counts the number of overlapping occurrences of \a rx in the string.
Example:
\code
QString s = "banana and panama";
QRegExp r = QRegExp( "a[nm]a", TRUE, FALSE );
s.contains( r ); // 4 matches
\endcode
\sa find(), findRev()
\warning If you want to apply this function repeatedly to the same
string it is more efficient to convert the string to a QString and
apply the function to that.
*/
int QCString::contains( const QRegExp &rx ) const
{
- QString d = QString::fromLatin1( data() );
+ QString d = QString::fromAscii( data() );
return d.contains( rx );
}
/*!
\overload
Replaces every occurrence of \a rx in the string with \a str.
Returns a reference to the string.
Example:
\code
@@ -1829,26 +1866,26 @@ int QCString::contains( const QRegExp &rx ) const
s = "banana";
s.replace( QRegExp("^[bn]a"), "" ); // becomes "nana"
\endcode
\warning If you want to apply this function repeatedly to the same
string it is more efficient to convert the string to a QString and
apply the function to that.
*/
QCString &QCString::replace( const QRegExp &rx, const char *str )
{
- QString d = QString::fromLatin1( data() );
- QString r = QString::fromLatin1( str );
+ QString d = QString::fromAscii( data() );
+ QString r = QString::fromAscii( str );
d.replace( rx, r );
setStr( d.ascii() );
return *this;
}
#endif //QT_NO_REGEXP
/*!
Returns the string converted to a \c long value.
If \a ok is not 0: \a *ok is set to FALSE if the string is not a
number, or if it has trailing garbage; otherwise \a *ok is set to
TRUE.
@@ -2190,41 +2227,41 @@ bool QCString::setExpand( uint index, char c )
/*!
Appends string \a str to the string and returns a reference to the string.
*/
QCString& QCString::operator+=( const char *str )
{
if ( !str )
return *this; // nothing to append
detach();
uint len1 = length();
uint len2 = qstrlen(str);
- if ( !QByteArray::resize( len1 + len2 + 1 ) )
+ if ( !QByteArray::resize( len1 + len2 + 1, QByteArray::SpeedOptim ) )
return *this; // no memory
memcpy( data() + len1, str, len2 + 1 );
return *this;
}
/*!
\overload
Appends character \a c to the string and returns a reference to the string.
*/
QCString &QCString::operator+=( char c )
{
detach();
uint len = length();
- if ( !QByteArray::resize( len + 2 ) )
+ if ( !QByteArray::resize( len + 2, QByteArray::SpeedOptim ) )
return *this; // no memory
*(data() + len) = c;
*(data() + len+1) = '\0';
return *this;
}
/*****************************************************************************
QCString stream functions
*****************************************************************************/
#ifndef QT_NO_DATASTREAM
/*!
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
@@ -741,26 +741,34 @@ QDataStream &QDataStream::readBytes( char *&s, uint &l )
reference to the stream.
The buffer \a s must be preallocated. The data is \e not encoded.
\sa readBytes(), QIODevice::readBlock(), writeRawBytes()
*/
QDataStream &QDataStream::readRawBytes( char *s, uint len )
{
CHECK_STREAM_PRECOND
if ( printable ) { // printable data
register Q_INT8 *p = (Q_INT8*)s;
- while ( len-- )
- *this >> *p++;
+ if ( version() < 4 ) {
+ while ( len-- ) {
+ Q_INT32 tmp;
+ *this >> tmp;
+ *p++ = tmp;
+ }
+ } else {
+ while ( len-- )
+ *this >> *p++;
+ }
} else { // read data char array
dev->readBlock( s, len );
}
return *this;
}
/*****************************************************************************
QDataStream write functions
*****************************************************************************/
@@ -1003,22 +1011,28 @@ QDataStream &QDataStream::writeBytes(const char *s, uint len)
/*!
Writes \a len bytes from \a s to the stream and returns a
reference to the stream. The data is \e not encoded.
\sa writeBytes(), QIODevice::writeBlock(), readRawBytes()
*/
QDataStream &QDataStream::writeRawBytes( const char *s, uint len )
{
CHECK_STREAM_PRECOND
if ( printable ) { // write printable
- register Q_INT8 *p = (Q_INT8*)s;
- while ( len-- )
- *this << *p++;
+ if ( version() < 4 ) {
+ register char *p = (char *)s;
+ while ( len-- )
+ *this << *p++;
+ } else {
+ register Q_INT8 *p = (Q_INT8*)s;
+ while ( len-- )
+ *this << *p++;
+ }
} else { // write data char array
dev->writeBlock( s, len );
}
return *this;
}
#endif // QT_NO_DATASTREAM
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
@@ -1,20 +1,20 @@
/****************************************************************************
** $Id$
**
** Implementation of date and time classes
**
** Created : 940124
**
-** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
+** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
@@ -26,25 +26,24 @@
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
-// Get the system specific includes and defines
#include "qplatformdefs.h"
#include "qdatetime.h"
#include "qdatastream.h"
#include "qregexp.h"
#include <stdio.h>
#ifndef Q_OS_TEMP
#include <time.h>
#endif
#if defined(Q_OS_WIN32)
@@ -886,24 +885,30 @@ QDate QDate::addMonths( int nmonths ) const
/*!
Returns a QDate object containing a date \a nyears later than the
date of this object (or earlier if \a nyears is negative).
\sa addDays(), addMonths()
*/
QDate QDate::addYears( int nyears ) const
{
int y, m, d;
julianToGregorian( jd, y, m, d );
y += nyears;
+
+ QDate tmp(y,m,1);
+
+ if( d > tmp.daysInMonth() )
+ d = tmp.daysInMonth();
+
QDate date(y, m, d);
return date;
}
/*!
Returns the number of days from this date to \a d (which is
negative if \a d is earlier than this date).
Example:
\code
@@ -981,31 +986,43 @@ QDate QDate::currentDate()
QDate QDate::currentDate( Qt::TimeSpec ts )
{
QDate d;
#if defined(Q_OS_WIN32)
SYSTEMTIME t;
memset( &t, 0, sizeof(SYSTEMTIME) );
if ( ts == Qt::LocalTime )
GetLocalTime( &t );
else
GetSystemTime( &t );
d.jd = gregorianToJulian( t.wYear, t.wMonth, t.wDay );
#else
+ // posix compliant system
time_t ltime;
time( &ltime );
tm *t;
+
+# if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+ // use the reentrant versions of localtime() and gmtime() where available
+ tm res;
+ if ( ts == Qt::LocalTime )
+ t = localtime_r( &ltime, &res );
+ else
+ t = gmtime_r( &ltime, &res );
+# else
if ( ts == Qt::LocalTime )
t = localtime( &ltime );
- else
+ else
t = gmtime( &ltime );
+# endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS
+
d.jd = gregorianToJulian( t->tm_year + 1900, t->tm_mon + 1, t->tm_mday );
#endif
return d;
}
#ifndef QT_NO_DATESTRING
/*!
Returns the QDate represented by the string \a s, using the format
\a f, or an invalid date if the string cannot be parsed.
Note for \c Qt::TextDate: It is recommended that you use the
English short month names (e.g. "Jan"). Although localized month
@@ -1546,25 +1563,25 @@ int QTime::msecsTo( const QTime &t ) const
Returns TRUE if this time is later than \a t; otherwise returns FALSE.
*/
/*!
\fn bool QTime::operator>=( const QTime &t ) const
Returns TRUE if this time is later than or equal to \a t;
otherwise returns FALSE.
*/
-/*!
+/*!
\overload
Returns the current time as reported by the system clock.
Note that the accuracy depends on the accuracy of the underlying
operating system; not all systems provide 1-millisecond accuracy.
*/
QTime QTime::currentTime()
{
return currentTime( Qt::LocalTime );
}
@@ -1644,40 +1661,51 @@ bool QTime::currentTime( QTime *ct, Qt::TimeSpec ts )
}
#if defined(Q_OS_WIN32)
SYSTEMTIME t;
if ( ts == Qt::LocalTime ) {
GetLocalTime( &t );
} else {
GetSystemTime( &t );
}
ct->ds = (uint)( MSECS_PER_HOUR*t.wHour + MSECS_PER_MIN*t.wMinute +
1000*t.wSecond + t.wMilliseconds );
#elif defined(Q_OS_UNIX)
+ // posix compliant system
struct timeval tv;
gettimeofday( &tv, 0 );
time_t ltime = tv.tv_sec;
tm *t;
- if ( ts == Qt::LocalTime ) {
+
+# if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+ // use the reentrant versions of localtime() and gmtime() where available
+ tm res;
+ if ( ts == Qt::LocalTime )
+ t = localtime_r( &ltime, &res );
+ else
+ t = gmtime_r( &ltime, &res );
+# else
+ if ( ts == Qt::LocalTime )
t = localtime( &ltime );
- } else {
+ else
t = gmtime( &ltime );
- }
+# endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS
+
ct->ds = (uint)( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min +
1000 * t->tm_sec + tv.tv_usec / 1000 );
#else
time_t ltime; // no millisecond resolution
::time( &ltime );
tm *t;
- if ( ts == Qt::LocalTime )
+ if ( ts == Qt::LocalTime )
localtime( &ltime );
else
gmtime( &ltime );
ct->ds = (uint) ( MSECS_PER_HOUR * t->tm_hour + MSECS_PER_MIN * t->tm_min +
1000 * t->tm_sec );
#endif
// 00:00.00 to 00:00.59.999 is considered as "midnight or right after"
return ct->ds < (uint) MSECS_PER_MIN;
}
/*!
\overload
@@ -1697,27 +1725,27 @@ bool QTime::currentTime( QTime *ct, Qt::TimeSpec ts )
bool QTime::isValid( int h, int m, int s, int ms )
{
return (uint)h < 24 && (uint)m < 60 && (uint)s < 60 && (uint)ms < 1000;
}
/*!
Sets this time to the current time. This is practical for timing:
\code
QTime t;
- t.start(); // start clock
- ... // some lengthy task
- qDebug( "%d\n", t.elapsed() ); // prints the number of msecs elapsed
+ t.start();
+ some_lengthy_task();
+ qDebug( "Time elapsed: %d ms", t.elapsed() );
\endcode
\sa restart(), elapsed(), currentTime()
*/
void QTime::start()
{
*this = currentTime();
}
/*!
Sets this time to the current time and returns the number of
@@ -1951,34 +1979,52 @@ void QDateTime::setTime_t( uint secsSince1Jan1970UTC )
that do not support timezones this function will behave as if
local time were UTC.
On Windows, only a subset of \a secsSince1Jan1970UTC values are
supported, as Windows starts counting from 1980.
\sa toTime_t()
*/
void QDateTime::setTime_t( uint secsSince1Jan1970UTC, Qt::TimeSpec ts )
{
time_t tmp = (time_t) secsSince1Jan1970UTC;
tm *brokenDown = 0;
+
+#if defined(Q_OS_UNIX) && defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
+ // posix compliant system
+ // use the reentrant versions of localtime() and gmtime() where available
+ tm res;
+ if ( ts == Qt::LocalTime )
+ brokenDown = localtime_r( &tmp, &res );
+ if ( !brokenDown ) {
+ brokenDown = gmtime_r( &tmp, &res );
+ if ( !brokenDown ) {
+ d.jd = QDate::gregorianToJulian( 1970, 1, 1 );
+ t.ds = 0;
+ return;
+ }
+ }
+#else
if ( ts == Qt::LocalTime )
brokenDown = localtime( &tmp );
if ( !brokenDown ) {
brokenDown = gmtime( &tmp );
if ( !brokenDown ) {
d.jd = QDate::gregorianToJulian( 1970, 1, 1 );
t.ds = 0;
return;
}
}
+#endif
+
d.jd = QDate::gregorianToJulian( brokenDown->tm_year + 1900,
brokenDown->tm_mon + 1,
brokenDown->tm_mday );
t.ds = MSECS_PER_HOUR * brokenDown->tm_hour +
MSECS_PER_MIN * brokenDown->tm_min +
1000 * brokenDown->tm_sec;
}
#ifndef QT_NO_DATESTRING
#ifndef QT_NO_SPRINTF
/*!
\overload
@@ -2291,25 +2337,25 @@ bool QDateTime::operator>( const QDateTime &dt ) const
otherwise returns FALSE.
*/
bool QDateTime::operator>=( const QDateTime &dt ) const
{
if ( d > dt.d )
return TRUE;
return d == dt.d ? t >= dt.t : FALSE;
}
/*!
\overload
-
+
Returns the current datetime, as reported by the system clock.
\sa QDate::currentDate(), QTime::currentTime()
*/
QDateTime QDateTime::currentDateTime()
{
return currentDateTime( Qt::LocalTime );
}
/*!
Returns the current datetime, as reported by the system clock, for the
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
@@ -1,20 +1,20 @@
/****************************************************************************
** $Id$
**
** Implementation of QDir class
**
** Created : 950427
**
-** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
+** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
@@ -34,31 +34,36 @@
** not clear to you.
**
**********************************************************************/
#include "qplatformdefs.h"
#include "qdir.h"
#ifndef QT_NO_DIR
#include <private/qdir_p.h>
#include "qfileinfo.h"
#include "qregexp.h"
#include "qstringlist.h"
-#include <stdlib.h>
-#include <ctype.h>
+#include <limits.h>
+#if defined(Q_FS_FAT) && !defined(Q_OS_UNIX)
+const bool CaseSensitiveFS = FALSE;
+#else
+const bool CaseSensitiveFS = TRUE;
+#endif
/*!
\class QDir
+ \reentrant
\brief The QDir class provides access to directory structures and their contents in a platform-independent way.
\ingroup io
\mainclass
A QDir is used to manipulate path names, access information
regarding paths and files, and manipulate the underlying file
system.
A QDir can point to a file using either a relative or an absolute
path. Absolute paths begin with the directory separator "/"
(optionally preceded by a drive specification under Windows). If
@@ -221,24 +226,32 @@ QDir::QDir( const QString &path, const QString &nameFilter,
QDir::QDir( const QDir &d )
{
dPath = d.dPath;
fList = 0;
fiList = 0;
nameFilt = d.nameFilt;
dirty = TRUE;
allDirs = d.allDirs;
filtS = d.filtS;
sortS = d.sortS;
}
+/*!
+ Refreshes the directory information.
+*/
+void QDir::refresh() const
+{
+ QDir* that = (QDir*) this;
+ that->dirty = TRUE;
+}
void QDir::init()
{
fList = 0;
fiList = 0;
nameFilt = QString::fromLatin1("*");
dirty = TRUE;
allDirs = FALSE;
filtS = All;
sortS = SortSpec(Name | IgnoreCase);
}
@@ -373,28 +386,54 @@ QString QDir::filePath( const QString &fileName,
the resultant string returned.
\sa filePath()
*/
QString QDir::absFilePath( const QString &fileName,
bool acceptAbsPath ) const
{
if ( acceptAbsPath && !isRelativePath( fileName ) )
return fileName;
QString tmp = absPath();
- if ( tmp.isEmpty() || (tmp[(int)tmp.length()-1] != '/' && !!fileName &&
- fileName[0] != '/') )
- tmp += '/';
- tmp += fileName;
+#ifdef Q_OS_WIN32
+ if ( fileName[0].isLetter() && fileName[1] == ':' ) {
+ int drv = fileName.upper()[0].latin1() - 'A' + 1;
+ if ( _getdrive() != drv ) {
+ if ( qt_winunicode ) {
+ TCHAR buf[PATH_MAX];
+ ::_tgetdcwd( drv, buf, PATH_MAX );
+ tmp.setUnicodeCodes( (ushort*)buf, ::_tcslen(buf) );
+ } else {
+ char buf[PATH_MAX];
+ ::_getdcwd( drv, buf, PATH_MAX );
+ tmp = buf;
+ }
+ if ( !tmp.endsWith("\\") )
+ tmp += "\\";
+ tmp += fileName.right( fileName.length() - 2 );
+ int x;
+ for ( x = 0; x < (int) tmp.length(); x++ ) {
+ if ( tmp[x] == '\\' )
+ tmp[x] = '/';
+ }
+ }
+ } else
+#endif
+ {
+ if ( tmp.isEmpty() || (tmp[(int)tmp.length()-1] != '/' && !!fileName &&
+ fileName[0] != '/') )
+ tmp += '/';
+ tmp += fileName;
+ }
return tmp;
}
/*!
Returns \a pathName with the '/' separators converted to
separators that are appropriate for the underlying operating
system.
On Windows, convertSeparators("c:/winnt/system32") returns
"c:\winnt\system32".
@@ -925,40 +964,42 @@ QDir &QDir::operator=( const QString &path )
/*!
\fn bool QDir::operator!=( const QDir &d ) const
Returns TRUE if directory \a d and this directory have different
paths or different sort or filter settings; otherwise returns
FALSE.
Example:
\code
// The current directory is "/usr/local"
QDir d1( "/usr/local/bin" );
QDir d2( "bin" );
- if ( d1 != d2 ) qDebug( "They differ\n" ); // This is printed
+ if ( d1 != d2 )
+ qDebug( "They differ" );
\endcode
*/
/*!
Returns TRUE if directory \a d and this directory have the same
path and their sort and filter settings are the same; otherwise
returns FALSE.
Example:
\code
// The current directory is "/usr/local"
QDir d1( "/usr/local/bin" );
QDir d2( "bin" );
d2.convertToAbs();
- if ( d1 == d2 ) qDebug( "They're the same\n" ); // This is printed
+ if ( d1 == d2 )
+ qDebug( "They're the same" );
\endcode
*/
bool QDir::operator==( const QDir &d ) const
{
return dPath == d.dPath &&
nameFilt == d.nameFilt &&
allDirs == d.allDirs &&
filtS == d.filtS &&
sortS == d.sortS;
}
@@ -1078,86 +1119,93 @@ QDir QDir::root()
{
return QDir( rootDirPath() );
}
/*!
\fn QString QDir::homeDirPath()
Returns the absolute path of the user's home directory.
\sa home()
*/
-QStringList qt_makeFilterList( const QString &filter )
+QValueList<QRegExp> qt_makeFilterList( const QString &filter )
{
+ QValueList<QRegExp> regExps;
if ( filter.isEmpty() )
- return QStringList();
+ return regExps;
QChar sep( ';' );
int i = filter.find( sep, 0 );
if ( i == -1 && filter.find( ' ', 0 ) != -1 )
sep = QChar( ' ' );
QStringList list = QStringList::split( sep, filter );
QStringList::Iterator it = list.begin();
- QStringList list2;
+ while ( it != list.end() ) {
+ regExps << QRegExp( (*it).stripWhiteSpace(), CaseSensitiveFS, TRUE );
+ ++it;
+ }
+ return regExps;
+}
- for ( ; it != list.end(); ++it ) {
- QString s = *it;
- list2 << s.stripWhiteSpace();
+bool qt_matchFilterList( const QValueList<QRegExp>& filters,
+ const QString &fileName )
+{
+ QValueList<QRegExp>::ConstIterator rit = filters.begin();
+ while ( rit != filters.end() ) {
+ if ( (*rit).exactMatch(fileName) )
+ return TRUE;
+ ++rit;
}
- return list2;
+ return FALSE;
}
+
/*!
\overload
Returns TRUE if the \a fileName matches any of the wildcard (glob)
patterns in the list of \a filters; otherwise returns FALSE.
(See \link qregexp.html#wildcard-matching QRegExp wildcard
matching.\endlink)
\sa QRegExp::match()
*/
bool QDir::match( const QStringList &filters, const QString &fileName )
{
QStringList::ConstIterator sit = filters.begin();
while ( sit != filters.end() ) {
-#if defined(Q_FS_FAT) && !defined(Q_OS_UNIX)
- QRegExp rx( *sit, FALSE, TRUE ); // The FAT FS is not case sensitive..
-#else
- QRegExp rx( *sit, TRUE, TRUE ); // ..while others are.
-#endif
+ QRegExp rx( *sit, CaseSensitiveFS, TRUE );
if ( rx.exactMatch(fileName) )
return TRUE;
++sit;
}
return FALSE;
}
/*!
Returns TRUE if the \a fileName matches the wildcard (glob)
pattern \a filter; otherwise returns FALSE. The \a filter may
contain multiple patterns separated by spaces or semicolons.
(See \link qregexp.html#wildcard-matching QRegExp wildcard
matching.\endlink)
\sa QRegExp::match()
*/
bool QDir::match( const QString &filter, const QString &fileName )
{
- QStringList lst = qt_makeFilterList( filter );
- return match( lst, fileName );
+ return qt_matchFilterList( qt_makeFilterList(filter), fileName );
}
/*!
Removes all multiple directory separators "/" and resolves any
"."s or ".."s found in the path, \a filePath.
Symbolic links are kept. This function does not return the
canonical path, but rather the simplest version of the input.
For example, "./local" becomes "local", "local/../bin" becomes
"bin" and "/local/usr/../bin" becomes "/local/bin".
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
@@ -1,20 +1,20 @@
/****************************************************************************
** $Id$
**
** Implementation of QDir class
**
** Created : 950628
**
-** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
+** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
@@ -42,69 +42,70 @@
#include "qdir_p.h"
#include "qfileinfo.h"
#include "qregexp.h"
#include "qstringlist.h"
#ifdef QT_THREAD_SUPPORT
# include <private/qmutexpool_p.h>
#endif // QT_THREAD_SUPPORT
#include <stdlib.h>
#include <limits.h>
+#include <errno.h>
void QDir::slashify( QString& )
{
}
QString QDir::homeDirPath()
{
QString d;
d = QFile::decodeName(getenv("HOME"));
slashify( d );
if ( d.isNull() )
d = rootDirPath();
return d;
}
QString QDir::canonicalPath() const
{
QString r;
-
char cur[PATH_MAX+1];
- if ( ::getcwd( cur, PATH_MAX ) )
- if ( ::chdir(QFile::encodeName(dPath)) >= 0 ) {
- char tmp[PATH_MAX+1];
- if ( ::getcwd( tmp, PATH_MAX ) )
- r = QFile::decodeName(tmp);
- ::chdir( cur );
- }
-
- slashify( r );
+ if ( ::getcwd( cur, PATH_MAX ) ) {
+ char tmp[PATH_MAX+1];
+ if( ::realpath( QFile::encodeName( dPath ), tmp ) )
+ r = QFile::decodeName( tmp );
+ slashify( r );
+
+ // always make sure we go back to the current dir
+ ::chdir( cur );
+ }
return r;
}
bool QDir::mkdir( const QString &dirName, bool acceptAbsPath ) const
{
#if defined(Q_OS_MACX) // Mac X doesn't support trailing /'s
QString name = dirName;
if (dirName[dirName.length() - 1] == "/")
name = dirName.left( dirName.length() - 1 );
- return ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 )
- == 0;
+ int status =
+ ::mkdir( QFile::encodeName(filePath(name,acceptAbsPath)), 0777 );
#else
- return ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 )
- == 0;
+ int status =
+ ::mkdir( QFile::encodeName(filePath(dirName,acceptAbsPath)), 0777 );
#endif
+ return status == 0;
}
bool QDir::rmdir( const QString &dirName, bool acceptAbsPath ) const
{
return ::rmdir( QFile::encodeName(filePath(dirName,acceptAbsPath)) ) == 0;
}
bool QDir::isReadable() const
{
return ::access( QFile::encodeName(dPath), R_OK | X_OK ) == 0;
}
@@ -177,52 +178,56 @@ bool QDir::readDirEntries( const QString &nameFilter,
int i;
if ( !fList ) {
fList = new QStringList;
Q_CHECK_PTR( fList );
fiList = new QFileInfoList;
Q_CHECK_PTR( fiList );
fiList->setAutoDelete( TRUE );
} else {
fList->clear();
fiList->clear();
}
- QStringList filters = qt_makeFilterList( nameFilter );
+ QValueList<QRegExp> filters = qt_makeFilterList( nameFilter );
bool doDirs = (filterSpec & Dirs) != 0;
bool doFiles = (filterSpec & Files) != 0;
bool noSymLinks = (filterSpec & NoSymLinks) != 0;
bool doReadable = (filterSpec & Readable) != 0;
bool doWritable = (filterSpec & Writable) != 0;
bool doExecable = (filterSpec & Executable) != 0;
bool doHidden = (filterSpec & Hidden) != 0;
bool doSystem = (filterSpec & System) != 0;
-#if defined(Q_OS_OS2EMX)
- //QRegExp wc( nameFilter, FALSE, TRUE ); // wild card, case insensitive
-#else
- //QRegExp wc( nameFilter, TRUE, TRUE ); // wild card, case sensitive
-#endif
QFileInfo fi;
DIR *dir;
dirent *file;
dir = opendir( QFile::encodeName(dPath) );
if ( !dir )
return FALSE; // cannot read the directory
- while ( (file = readdir(dir)) ) {
+#if defined(QT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) && !defined(Q_OS_CYGWIN)
+ union {
+ struct dirent mt_file;
+ char b[sizeof(struct dirent) + MAXNAMLEN + 1];
+ } u;
+ while ( readdir_r(dir, &u.mt_file, &file ) == 0 && file )
+#else
+ while ( (file = readdir(dir)) )
+#endif // QT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS
+ {
QString fn = QFile::decodeName(file->d_name);
fi.setFile( *this, fn );
- if ( !match( filters, fn ) && !(allDirs && fi.isDir()) )
+ if ( !qt_matchFilterList(filters, fn) && !(allDirs && fi.isDir()) )
continue;
if ( (doDirs && fi.isDir()) || (doFiles && fi.isFile()) ||
(doSystem && (!fi.isFile() && !fi.isDir())) ) {
if ( noSymLinks && fi.isSymLink() )
continue;
if ( (filterSpec & RWEMask) != 0 )
if ( (doReadable && !fi.isReadable()) ||
(doWritable && !fi.isWritable()) ||
(doExecable && !fi.isExecutable()) )
continue;
if ( !doHidden && fn[0] == '.' &&
fn != QString::fromLatin1(".")
@@ -267,25 +272,26 @@ bool QDir::readDirEntries( const QString &nameFilter,
return TRUE;
}
const QFileInfoList * QDir::drives()
{
// at most one instance of QFileInfoList is leaked, and this variable
// points to that list
static QFileInfoList * knownMemoryLeak = 0;
if ( !knownMemoryLeak ) {
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &knownMemoryLeak ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &knownMemoryLeak ) : 0 );
#endif // QT_THREAD_SUPPORT
if ( !knownMemoryLeak ) {
knownMemoryLeak = new QFileInfoList;
// non-win32 versions both use just one root directory
knownMemoryLeak->append( new QFileInfo( rootDirPath() ) );
}
}
return knownMemoryLeak;
}
#endif //QT_NO_DIR
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
@@ -79,25 +79,25 @@ extern bool qt_file_access( const QString& fn, int t );
at() functions. If you've reached the end of the file, atEnd()
returns TRUE. The file handle is returned by handle().
Here is a code fragment that uses QTextStream to read a text file
line by line. It prints each line with a line number.
\code
QStringList lines;
QFile file( "file.txt" );
if ( file.open( IO_ReadOnly ) ) {
QTextStream stream( &file );
QString line;
int i = 1;
- while ( !stream.eof() ) {
+ while ( !stream.atEnd() ) {
line = stream.readLine(); // line of text excluding '\n'
printf( "%3d: %s\n", i++, line.latin1() );
lines += line;
}
file.close();
}
\endcode
Writing text is just as easy. The following example shows how to
write the data we read into the string list from the previous
example:
\code
@@ -281,24 +281,25 @@ bool QFile::remove()
void QFile::flush()
{
if ( isOpen() && fh ) // can only flush open/buffered
fflush( fh ); // file
}
/*! \reimp
\fn QIODevice::Offset QFile::at() const
*/
/*!
Returns TRUE if the end of file has been reached; otherwise returns FALSE.
+ If QFile has not been open()'d, then the behavior is undefined.
\sa size()
*/
bool QFile::atEnd() const
{
if ( !isOpen() ) {
#if defined(QT_CHECK_STATE)
qWarning( "QFile::atEnd: File is not open" );
#endif
return FALSE;
}
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
@@ -426,29 +426,32 @@ bool QFile::open( int m, int f )
}
return TRUE;
}
/*!
Returns the file size.
\sa at()
*/
QIODevice::Offset QFile::size() const
{
struct stat st;
+ int ret = 0;
if ( isOpen() ) {
- ::fstat( fh ? fileno(fh) : fd, &st );
+ ret = ::fstat( fh ? fileno(fh) : fd, &st );
} else {
- ::stat( QFile::encodeName(fn), &st );
+ ret = ::stat( QFile::encodeName(fn), &st );
}
+ if ( ret == -1 )
+ return 0;
#if defined(QT_LARGEFILE_SUPPORT) && !defined(QT_ABI_64BITOFFSET)
return (uint)st.st_size > UINT_MAX ? UINT_MAX : (QIODevice::Offset)st.st_size;
#else
return st.st_size;
#endif
}
/*!
\overload
Sets the file index to \a pos. Returns TRUE if successful;
@@ -529,25 +532,25 @@ Q_LONG QFile::readBlock( char *p, Q_ULONG len )
return -1;
}
if ( !isReadable() ) {
qWarning( "QFile::readBlock: Read operation not permitted" );
return -1;
}
#endif
Q_ULONG nread = 0; // number of bytes read
if ( !ungetchBuffer.isEmpty() ) {
// need to add these to the returned string.
uint l = ungetchBuffer.length();
while( nread < l ) {
- *p = ungetchBuffer[ l - nread - 1 ];
+ *p = ungetchBuffer.at( l - nread - 1 );
p++;
nread++;
}
ungetchBuffer.truncate( l - nread );
}
if ( nread < len ) {
if ( isRaw() ) { // raw file
nread += ::read( fd, p, len-nread );
if ( len && nread <= 0 ) {
nread = 0;
setStatus(IO_ReadError);
@@ -620,25 +623,27 @@ Q_LONG QFile::writeBlock( const char *p, Q_ULONG len )
if ( !isSequentialAccess() )
ioIndex += nwritten;
}
if ( ioIndex > length ) // update file length
length = ioIndex;
return nwritten;
}
/*!
Returns the file handle of the file.
This is a small positive integer, suitable for use with C library
- functions such as fdopen() and fcntl(), as well as with QSocketNotifier.
+ functions such as fdopen() and fcntl(). On systems that use file
+ descriptors for sockets (ie. Unix systems, but not Windows) the handle
+ can be used with QSocketNotifier as well.
If the file is not open or there is an error, handle() returns -1.
\sa QSocketNotifier
*/
int QFile::handle() const
{
if ( !isOpen() )
return -1;
else if ( fh )
return fileno( fh );
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
@@ -626,34 +626,36 @@ QDateTime QFileInfo::lastRead() const
/*!
Returns the absolute path including the file name.
The absolute path name consists of the full path and the file
name. On Unix this will always begin with the root, '/',
directory. On Windows this will always begin 'D:/' where D is a
drive letter, except for network shares that are not mapped to a
drive letter, in which case the path will begin '//sharename/'.
This function returns the same as filePath(), unless isRelative()
is TRUE.
+ If the QFileInfo is empty it returns QDir::currentDirPath().
+
This function can be time consuming under Unix (in the order of
milliseconds).
\sa isRelative(), filePath()
*/
QString QFileInfo::absFilePath() const
{
QString tmp;
if ( QDir::isRelativePath(fn)
-#if defined(Q_OS_WIN32) || defined(Q_OS_WIN64)
+#if defined(Q_OS_WIN32)
&& fn[1] != ':'
#endif
) {
tmp = QDir::currentDirPath();
tmp += '/';
}
tmp += fn;
makeAbs( tmp );
return QDir::cleanDirPath( tmp );
}
#endif
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
@@ -205,27 +205,27 @@ uint QFileInfo::groupId() const
/*!
Tests for file permissions. The \a permissionSpec argument can be
several flags of type \c PermissionSpec OR-ed together to check
for permission combinations.
On systems where files do not have permissions this function
always returns TRUE.
Example:
\code
QFileInfo fi( "/tmp/archive.tar.gz" );
if ( fi.permission( QFileInfo::WriteUser | QFileInfo::ReadGroup ) )
- qWarning( "I can change the file; my group can read the file.");
+ qWarning( "I can change the file; my group can read the file" );
if ( fi.permission( QFileInfo::WriteGroup | QFileInfo::WriteOther ) )
- qWarning( "The group or others can change the file!" );
+ qWarning( "The group or others can change the file" );
\endcode
\sa isReadable(), isWritable(), isExecutable()
*/
bool QFileInfo::permission( int permissionSpec ) const
{
if ( !fic || !cache )
doStat();
if ( fic ) {
uint mask = 0;
if ( permissionSpec & ReadUser )
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
@@ -26,39 +26,49 @@
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
-#include "qglobal.h" // needed to define Q_WS_WIN
-#ifdef Q_WS_WIN
-#include "qt_windows.h" // needed for bsearch on some platforms
+#include "qglobal.h"
+#if defined(Q_CC_BOR)
+ // needed for qsort() because of a std namespace problem on Borland
+# include "qplatformdefs.h"
+#elif defined(Q_WS_WIN)
+ // needed for bsearch on some platforms
+# include "qt_windows.h"
#endif
#define QGARRAY_CPP
#include "qgarray.h"
#include <stdlib.h>
#include <string.h>
#ifdef QT_THREAD_SUPPORT
# include <private/qmutexpool_p.h>
#endif // QT_THREAD_SUPPORT
-#define USE_MALLOC // comment to use new/delete
+/*
+ If USE_MALLOC isn't defined, we use new[] and delete[] to allocate
+ memory. The documentation for QMemArray<T>::assign() explicitly
+ mentions that the array is freed using free(), so don't mess around
+ with USE_MALLOC unless you know what you're doing.
+*/
+#define USE_MALLOC
#undef NEW
#undef DELETE
#if defined(USE_MALLOC)
#define NEW(type,size) ((type*)malloc(size*sizeof(type)))
#define DELETE(array) (free((char*)array))
#else
#define NEW(type,size) (new type[size])
#define DELETE(array) (delete[] array)
#define DONT_USE_REALLOC // comment to use realloc()
#endif
@@ -126,25 +136,29 @@ QGArray::QGArray( int size )
if ( size < 0 ) {
#if defined(QT_CHECK_RANGE)
qWarning( "QGArray: Cannot allocate array with negative length" );
#endif
size = 0;
}
shd = newData();
Q_CHECK_PTR( shd );
if ( size == 0 ) // zero length
return;
shd->data = NEW(char,size);
Q_CHECK_PTR( shd->data );
- shd->len = size;
+ shd->len =
+#ifdef QT_QGARRAY_SPEED_OPTIM
+ shd->maxl =
+#endif
+ size;
}
/*!
Constructs a shallow copy of \a a.
*/
QGArray::QGArray( const QGArray &a )
{
shd = a.shd;
shd->ref();
}
@@ -203,53 +217,88 @@ QGArray::~QGArray()
bool QGArray::isEqual( const QGArray &a ) const
{
if ( size() != a.size() ) // different size
return FALSE;
if ( data() == a.data() ) // has same data
return TRUE;
return (size() ? memcmp( data(), a.data(), size() ) : 0) == 0;
}
/*!
- Resizes the array to \a newsize bytes.
+ Resizes the array to \a newsize bytes. \a optim is either
+ MemOptim (the default) or SpeedOptim.
*/
-
-bool QGArray::resize( uint newsize )
+bool QGArray::resize( uint newsize, Optimization optim )
{
- if ( newsize == shd->len ) // nothing to do
+#ifndef QT_QGARRAY_SPEED_OPTIM
+ Q_UNUSED(optim);
+#endif
+
+ if ( newsize == shd->len
+#ifdef QT_QGARRAY_SPEED_OPTIM
+ && newsize == shd->maxl
+#endif
+ ) // nothing to do
return TRUE;
if ( newsize == 0 ) { // remove array
duplicate( 0, 0 );
return TRUE;
}
+
+ uint newmaxl = newsize;
+#ifdef QT_QGARRAY_SPEED_OPTIM
+ if ( optim == SpeedOptim ) {
+ if ( newsize <= shd->maxl &&
+ ( newsize * 4 > shd->maxl || shd->maxl <= 4 ) ) {
+ shd->len = newsize;
+ return TRUE;
+ }
+ newmaxl = 4;
+ while ( newmaxl < newsize )
+ newmaxl *= 2;
+ // try to spare some memory
+ if ( newmaxl >= 1024 * 1024 && newsize <= newmaxl - (newmaxl >> 2) )
+ newmaxl -= newmaxl >> 2;
+ }
+ shd->maxl = newmaxl;
+#endif
+
if ( shd->data ) { // existing data
#if defined(DONT_USE_REALLOC)
char *newdata = NEW(char,newsize); // manual realloc
- memcpy( newdata, shd->data, QMIN(shd->len,newsize) );
+ memcpy( newdata, shd->data, QMIN(shd->len,newmaxl) );
DELETE(shd->data);
shd->data = newdata;
#else
- shd->data = (char *)realloc( shd->data, newsize );
+ shd->data = (char *)realloc( shd->data, newmaxl );
#endif
} else {
- shd->data = NEW(char,newsize);
+ shd->data = NEW(char,newmaxl);
}
if ( !shd->data ) // no memory
return FALSE;
shd->len = newsize;
return TRUE;
}
+/*!\overload
+*/
+bool QGArray::resize( uint newsize )
+{
+ return resize( newsize, MemOptim );
+}
+
+
/*!
Fills the array with the repeated occurrences of \a d, which is
\a sz bytes long.
If \a len is specified as different from -1, then the array will be
resized to \a len*sz before it is filled.
Returns TRUE if successful, or FALSE if the memory cannot be allocated
(only when \a len != -1).
\sa resize()
*/
@@ -310,25 +359,29 @@ QGArray &QGArray::assign( const QGArray &a )
QGArray &QGArray::assign( const char *d, uint len )
{
if ( shd->count > 1 ) { // disconnect this
shd->count--;
shd = newData();
Q_CHECK_PTR( shd );
} else {
if ( shd->data )
DELETE(shd->data);
}
shd->data = (char *)d;
- shd->len = len;
+ shd->len =
+#ifdef QT_QGARRAY_SPEED_OPTIM
+ shd->maxl =
+#endif
+ len;
return *this;
}
/*!
Deep copy. Dereference the current array and obtains a copy of the data
contained in \a a instead. Returns a reference to this array.
\sa assign(), operator=()
*/
QGArray &QGArray::duplicate( const QGArray &a )
{
if ( a.shd == shd ) { // a.duplicate(a) !
@@ -355,25 +408,29 @@ QGArray &QGArray::duplicate( const QGArray &a )
Q_CHECK_PTR( shd );
} else { // delete after copy was made
oldptr = shd->data;
}
if ( a.shd->len ) { // duplicate data
shd->data = NEW(char,a.shd->len);
Q_CHECK_PTR( shd->data );
if ( shd->data )
memcpy( shd->data, a.shd->data, a.shd->len );
} else {
shd->data = 0;
}
- shd->len = a.shd->len;
+ shd->len =
+#ifdef QT_QGARRAY_SPEED_OPTIM
+ shd->maxl =
+#endif
+ a.shd->len;
if ( oldptr )
DELETE(oldptr);
return *this;
}
/*!
\overload
Deep copy. Dereferences the current array and obtains a copy of
\a len characters from array data \a d instead. Returns a reference
to this array.
\sa assign(), operator=()
*/
@@ -393,25 +450,29 @@ QGArray &QGArray::duplicate( const char *d, uint len )
Q_CHECK_PTR( data );
memcpy( data, d, len );
}
if ( shd->count > 1 ) { // detach
shd->count--;
shd = newData();
Q_CHECK_PTR( shd );
} else { // just a single reference
if ( shd->data )
DELETE(shd->data);
}
shd->data = data;
- shd->len = len;
+ shd->len =
+#ifdef QT_QGARRAY_SPEED_OPTIM
+ shd->maxl =
+#endif
+ len;
return *this;
}
/*!
Resizes this array to \a len bytes and copies the \a len bytes at
address \a d into it.
\warning This function disregards the reference count mechanism. If
other QGArrays reference the same data as this, all will be updated.
*/
void QGArray::store( const char *d, uint len )
@@ -650,43 +711,45 @@ static int cmp_arr( const void *n1, const void *n2 )
/*!
Sorts the first \a sz items of the array.
*/
void QGArray::sort( uint sz )
{
int numItems = size() / sz;
if ( numItems < 2 )
return;
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &cmp_item_size ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &cmp_item_size ) : 0 );
#endif // QT_THREAD_SUPPORT
cmp_item_size = sz;
qsort( shd->data, numItems, sz, cmp_arr );
}
/*!
Binary search; assumes that \a d is a sorted array of size \a sz.
*/
int QGArray::bsearch( const char *d, uint sz ) const
{
int numItems = size() / sz;
if ( !numItems )
return -1;
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &cmp_item_size ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &cmp_item_size ) : 0 );
#endif // QT_THREAD_SUPPORT
cmp_item_size = sz;
char* r = (char*)::bsearch( d, shd->data, numItems, sz, cmp_arr );
if ( !r )
return -1;
while( (r >= shd->data + sz) && (cmp_arr( r - sz, d ) == 0) )
r -= sz; // search to first of equal elements; bsearch is undef
return (int)(( r - shd->data ) / sz);
}
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
@@ -195,25 +195,28 @@ QDataStream& QGDict::write( QDataStream &s, QPtrCollection::Item ) const
\c IntKey or \c PtrKey. The case-sensitivity of lookups is set with
\a caseSensitive. Keys are copied if \a copyKeys is TRUE.
*/
QGDict::QGDict( uint len, KeyType kt, bool caseSensitive, bool copyKeys )
{
init( len, kt, caseSensitive, copyKeys );
}
void QGDict::init( uint len, KeyType kt, bool caseSensitive, bool copyKeys )
{
- vec = new QBaseBucket *[vlen = len]; // allocate hash table
+ vlen = len;
+ if ( vlen == 0 )
+ vlen = 17;
+ vec = new QBaseBucket *[vlen];
Q_CHECK_PTR( vec );
memset( (char*)vec, 0, vlen*sizeof(QBaseBucket*) );
numItems = 0;
iterators = 0;
// The caseSensitive and copyKey options don't make sense for
// all dict types.
switch ( (keytype = (uint)kt) ) {
case StringKey:
cases = caseSensitive;
copyk = FALSE;
break;
case AsciiKey:
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
@@ -320,30 +320,26 @@ bool QGList::operator==( const QGList &list ) const
QLNode *QGList::locate( uint index )
{
if ( index == (uint)curIndex ) // current node ?
return curNode;
if ( !curNode && firstNode ) { // set current node
curNode = firstNode;
curIndex = 0;
}
register QLNode *node;
int distance = index - curIndex; // node distance to cur node
bool forward; // direction to traverse
- if ( index >= numNodes ) {
-#if defined(QT_CHECK_RANGE)
- qWarning( "QGList::locate: Index %d out of range", index );
-#endif
+ if ( index >= numNodes )
return 0;
- }
if ( distance < 0 )
distance = -distance;
if ( (uint)distance < index && (uint)distance < numNodes - index ) {
node = curNode; // start from current node
forward = index > (uint)curIndex;
} else if ( index < numNodes - index ) { // start from first node
node = firstNode;
distance = index;
forward = TRUE;
} else { // start from last node
node = lastNode;
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
@@ -140,25 +140,46 @@ bool qSysInfo( int *wordSize, bool *bigEndian )
if ( be16 != be32 ) { // strange machine!
#if defined(QT_CHECK_RANGE)
qFatal( "qSysInfo: Inconsistent system byte order" );
#endif
return FALSE;
}
*bigEndian = si_bigEndian = be32;
si_alreadyDone = TRUE;
return TRUE;
}
-#if defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
+#if !defined(QWS) && defined(Q_OS_MAC)
+
+#include "qt_mac.h"
+
+int qMacVersion()
+{
+ static int macver = Qt::MV_Unknown;
+ static bool first = TRUE;
+ if(first) {
+ first = FALSE;
+ long gestalt_version;
+ if(Gestalt(gestaltSystemVersion, &gestalt_version) == noErr) {
+ if(gestalt_version >= 0x1020 && gestalt_version < 0x1030)
+ macver = Qt::MV_10_DOT_2;
+ else if(gestalt_version >= 0x1010 && gestalt_version < 0x1020)
+ macver = Qt::MV_10_DOT_1;
+ }
+ }
+ return macver;
+}
+Qt::MacintoshVersion qt_macver = (Qt::MacintoshVersion)qMacVersion();
+#elif defined(Q_OS_WIN32) || defined(Q_OS_CYGWIN)
bool qt_winunicode;
#include "qt_windows.h"
int qWinVersion()
{
#ifndef VER_PLATFORM_WIN32s
#define VER_PLATFORM_WIN32s 0
#endif
#ifndef VER_PLATFORM_WIN32_WINDOWS
#define VER_PLATFORM_WIN32_WINDOWS 1
#endif
@@ -312,41 +333,53 @@ Qt::WindowsVersion qt_winver = (Qt::WindowsVersion)qWinVersion();
to crashes on certain platforms due to the platforms printf implementation.
\sa qDebug(), qWarning(), qInstallMsgHandler(),
\link debug.html Debugging\endlink
*/
static QtMsgHandler handler = 0; // pointer to debug handler
static const int QT_BUFFER_LENGTH = 8196; // internal buffer length
#ifdef Q_OS_MAC
-const unsigned char * p_str(const char * c, int len=-1)
+QString cfstring2qstring(CFStringRef str)
+{
+ CFIndex length = CFStringGetLength(str);
+ if(const UniChar *chars = CFStringGetCharactersPtr(str))
+ return QString((QChar *)chars, length);
+ UniChar *buffer = (UniChar*)malloc(length * sizeof(UniChar));
+ CFStringGetCharacters(str, CFRangeMake(0, length), buffer);
+ QString ret((QChar *)buffer, length);
+ free(buffer);
+ return ret;
+}
+
+unsigned char * p_str(const char * c, int len=-1)
{
const int maxlen = 255;
if(len == -1)
len = qstrlen(c);
if(len > maxlen) {
qWarning( "p_str len must never exceed %d", maxlen );
len = maxlen;
}
unsigned char *ret = (unsigned char*)malloc(len+2);
*ret=len;
memcpy(((char *)ret)+1,c,len);
*(ret+len+1) = '\0';
return ret;
}
-const unsigned char * p_str(const QString &s)
+unsigned char * p_str(const QString &s)
{
return p_str(s, s.length());
}
QCString p2qstring(const unsigned char *c) {
char *arr = (char *)malloc(c[0] + 1);
memcpy(arr, c+1, c[0]);
arr[c[0]] = '\0';
QCString ret = arr;
delete arr;
return ret;
}
@@ -632,36 +665,36 @@ void qSystemWarning( const char* msg, int code )
ASSERT: "b == 0" in div.cpp (9)
\endcode
\sa qWarning(), \link debug.html Debugging\endlink
*/
/*!
\fn void Q_CHECK_PTR( void *p )
\relates QApplication
- If \a p is null, a fatal messages says that the program ran out of
- memory and exits. If \e p is not null, nothing happens.
+ If \a p is 0, a fatal messages says that the program ran out of
+ memory and exits. If \e p is not 0, nothing happens.
This is really a macro defined in \c qglobal.h.
Example:
\code
int *a;
Q_CHECK_PTR( a = new int[80] ); // WRONG!
- a = new int[80]; // Right
+ a = new (nothrow) int[80]; // Right
Q_CHECK_PTR( a );
\endcode
\sa qFatal(), \link debug.html Debugging\endlink
*/
//
// The Q_CHECK_PTR macro calls this function to check if an allocation went ok.
//
#if (QT_VERSION-0 >= 0x040000)
#if defined(Q_CC_GNU)
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
@@ -1,18 +1,18 @@
/****************************************************************************
** $Id$
**
** Implementation of QGPluginManager class
**
-** Copyright (C) 2000-2001 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2003 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
@@ -466,25 +466,25 @@ bool QGPluginManager::addLibrary( QLibrary* lib )
if ( !fliFace ) {
iFace->queryInterface( IID_QComponentInformation, (QUnknownInterface**)&cpiFace );
if ( !cpiFace )
plugin->queryInterface( IID_QComponentInformation, (QUnknownInterface**)&cpiFace );
}
QStringList fl;
if ( fliFace )
// Map all found features to the library
fl = fliFace->featureList();
else if ( cpiFace )
fl << cpiFace->name();
- for ( QStringList::Iterator f = fl.begin(); f != fl.end(); f++ ) {
+ for ( QStringList::Iterator f = fl.begin(); f != fl.end(); ++f ) {
QLibrary *old = plugDict[*f];
if ( !old ) {
useful = TRUE;
plugDict.replace( *f, plugin );
} else {
// we have old *and* plugin, which one to pick?
QComLibrary* first = (QComLibrary*)old;
QComLibrary* second = (QComLibrary*)plugin;
bool takeFirst = TRUE;
if ( first->qtVersion() != QT_VERSION ) {
if ( second->qtVersion() == QT_VERSION )
takeFirst = FALSE;
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
@@ -26,24 +26,30 @@
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
+#include "qglobal.h"
+#if defined(Q_CC_BOR)
+// needed for qsort() because of a std namespace problem on Borland
+#include "qplatformdefs.h"
+#endif
+
#define QGVECTOR_CPP
#include "qgvector.h"
#include "qglist.h"
#include "qstring.h"
#include "qdatastream.h"
#include <stdlib.h>
#ifdef QT_THREAD_SUPPORT
# include <private/qmutexpool_p.h>
#endif // QT_THREAD_SUPPORT
#define USE_MALLOC // comment to use new/delete
@@ -384,25 +390,26 @@ void QGVector::sort() // sort vector
while ( end > start && *end == 0 )
end--;
if ( start < end ) {
tmp = *start;
*start = *end;
*end = tmp;
} else {
break;
}
}
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &sort_vec ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &sort_vec ) : 0 );
#endif // QT_THREAD_SUPPORT
sort_vec = (QGVector*)this;
qsort( vec, count(), sizeof(Item), cmp_vec );
sort_vec = 0;
}
int QGVector::bsearch( Item d ) const // binary search; when sorted
{
if ( !len )
return -1;
if ( !d ) {
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
@@ -1,20 +1,20 @@
/****************************************************************************
** $Id$
**
** Implementation of QLibrary class
**
-** Created : 2000-01-01
+** Created : 000101
**
-** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2003 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
@@ -62,25 +62,25 @@
QLibraryPrivate::QLibraryPrivate( QLibrary *lib )
: pHnd( 0 ), library( lib )
{
}
/*!
\class QLibrary qlibrary.h
\reentrant
\brief The QLibrary class provides a wrapper for handling shared libraries.
\mainclass
- \group plugins
+ \ingroup plugins
An instance of a QLibrary object can handle a single shared
library and provide access to the functionality in the library in
a platform independent way. If the library is a component server,
QLibrary provides access to the exported component and can
directly query this component for interfaces.
QLibrary ensures that the shared library is loaded and stays in
memory whilst it is in use. QLibrary can also unload the library
on destruction and release unused resources.
A typical use of QLibrary is to resolve an exported symbol in a
@@ -317,27 +317,28 @@ QString QLibrary::library() const
if ( libfile.isEmpty() )
return libfile;
QString filename = libfile;
#if defined(Q_WS_WIN)
if ( filename.findRev( '.' ) <= filename.findRev( '/' ) )
filename += ".dll";
#elif defined(Q_OS_MACX)
if ( filename.find( ".dylib" ) == -1 )
filename += ".dylib";
#else
- if ( filename.find( ".so" ) == -1 ) {
+ QString filter = ".so";
+ if ( filename.find(filter) == -1 ) {
const int x = filename.findRev( "/" );
if ( x != -1 ) {
QString path = filename.left( x + 1 );
QString file = filename.right( filename.length() - x - 1 );
- filename = QString( "%1lib%2.so" ).arg( path ).arg( file );
+ filename = QString( "%1lib%2.%3" ).arg( path ).arg( file ).arg( filter );
} else {
- filename = QString( "lib%1.so" ).arg( filename );
+ filename = QString( "lib%1.%2" ).arg( filename ).arg( filter );
}
}
#endif
return filename;
}
#endif //QT_NO_LIBRARY
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
@@ -1,18 +1,18 @@
/****************************************************************************
** $Id$
**
** Implementation of QLibraryPrivate class
**
-** Created : 2000-01-01
+** Created : 000101
**
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
@@ -44,25 +44,42 @@
#include <string.h>
#endif
/*
The platform dependent implementations of
- loadLibrary
- freeLibrary
- resolveSymbol
It's not too hard to guess what the functions do.
*/
-#if defined(QT_HPUX_LD) // for HP-UX < 11.x and 32 bit
+#if defined(Q_OS_MAC)
+
+bool QLibraryPrivate::loadLibrary()
+{
+ return FALSE;
+}
+
+bool QLibraryPrivate::freeLibrary()
+{
+ return FALSE;
+}
+
+void* QLibraryPrivate::resolveSymbol( const char* )
+{
+ return 0;
+}
+
+#elif defined(QT_HPUX_LD) // for HP-UX < 11.x and 32 bit
bool QLibraryPrivate::loadLibrary()
{
if ( pHnd )
return TRUE;
QString filename = library->library();
pHnd = (void*)shl_load( filename.latin1(), BIND_DEFERRED | BIND_NONFATAL | DYNAMIC_PATH, 0 );
#if defined(QT_DEBUG) || defined(QT_DEBUG_COMPONENT)
if ( !pHnd )
qWarning( "%s: failed to load library!", filename.latin1() );
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
@@ -34,26 +34,27 @@
** not clear to you.
**
**********************************************************************/
#if defined(QT_THREAD_SUPPORT)
#include "qplatformdefs.h"
typedef pthread_mutex_t Q_MUTEX_T;
// POSIX threads mutex types
#if ((defined(PTHREAD_MUTEX_RECURSIVE) && defined(PTHREAD_MUTEX_DEFAULT)) || \
- defined(Q_OS_FREEBSD)) && !defined(Q_OS_UNIXWARE) && !defined(Q_OS_SOLARIS)
- // POSIX 1003.1c-1995 - We love this OS
+ defined(Q_OS_FREEBSD)) && !defined(Q_OS_UNIXWARE) && !defined(Q_OS_SOLARIS) && \
+ !defined(Q_OS_MAC)
+// POSIX 1003.1c-1995 - We love this OS
# define Q_MUTEX_SET_TYPE(a, b) pthread_mutexattr_settype((a), (b))
# if defined(QT_CHECK_RANGE)
# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_ERRORCHECK
# else
# define Q_NORMAL_MUTEX_TYPE PTHREAD_MUTEX_DEFAULT
# endif
# define Q_RECURSIVE_MUTEX_TYPE PTHREAD_MUTEX_RECURSIVE
#elif defined(MUTEX_NONRECURSIVE_NP) && defined(MUTEX_RECURSIVE_NP)
// POSIX 1003.4a pthreads draft extensions
# define Q_MUTEX_SET_TYPE(a, b) pthread_mutexattr_setkind_np((a), (b));
# define Q_NORMAL_MUTEX_TYPE MUTEX_NONRECURSIVE_NP
# define Q_RECURSIVE_MUTEX_TYPE MUTEX_RECURSIVE_NP
@@ -652,25 +653,26 @@ bool QMutex::tryLock()
...
}
};
\endcode
\sa QMutex, QWaitCondition
*/
/*!
\fn QMutexLocker::QMutexLocker( QMutex *mutex )
Constructs a QMutexLocker and locks \a mutex. The mutex will be
- unlocked when the QMutexLocker is destroyed.
+ unlocked when the QMutexLocker is destroyed. If \a mutex is zero,
+ QMutexLocker does nothing.
\sa QMutex::lock()
*/
/*!
\fn QMutexLocker::~QMutexLocker()
Destroys the QMutexLocker and unlocks the mutex which was locked
in the constructor.
\sa QMutexLocker::QMutexLocker(), QMutex::unlock()
*/
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,36 +1,55 @@
+/****************************************************************************
+** $Id$
+**
+** ...
+**
+** Copyright (C) 2002 Trolltech AS. All rights reserved.
+**
+** This file is part of the tools module of the Qt GUI Toolkit.
+**
+** This file may be distributed under the terms of the Q Public License
+** as defined by Trolltech AS of Norway and appearing in the file
+** LICENSE.QPL included in the packaging of this file.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
+** licenses may use this file in accordance with the Qt Commercial License
+** Agreement provided with the Software.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
+** information about Qt Commercial License Agreements.
+** See http://www.trolltech.com/qpl/ for QPL licensing information.
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
#include "qmutexpool_p.h"
#ifdef QT_THREAD_SUPPORT
#include <qthread.h>
-#include <stdio.h>
QMutexPool *qt_global_mutexpool = 0;
-// this is an internal class used only for inititalizing the global mutexpool
-class QGlobalMutexPoolInitializer
-{
-public:
- inline QGlobalMutexPoolInitializer()
- {
- /*
- Purify will report a leak here. However, this mutex pool must be alive
- until *everything* in Qt has been destructed. Unfortunately there is
- no way to guarantee this, so we never destroy this mutex pool.
- */
- qt_global_mutexpool = new QMutexPool( TRUE );
- }
-};
-QGlobalMutexPoolInitializer qt_global_mutexpool_initializer;
/*!
\class QMutexPool qmutexpool_p.h
\brief The QMutexPool class provides a pool of QMutex objects.
\internal
\ingroup thread
QMutexPool is a convenience class that provides access to a fixed
number of QMutex objects.
@@ -76,55 +95,58 @@ QGlobalMutexPoolInitializer qt_global_mutexpool_initializer;
QMutexLocker documentation for more details.
*/
/*!
Constructs a QMutexPool, reserving space for \a size QMutexes. If
\a recursive is TRUE, all QMutexes in the pool will be recursive
mutexes; otherwise they will all be non-recursive (the default).
The QMutexes are created when needed, and deleted when the
QMutexPool is destructed.
*/
QMutexPool::QMutexPool( bool recursive, int size )
- : mutex( FALSE ), mutexes( size ), recurs( recursive )
+ : mutex( FALSE ), count( size ), recurs( recursive )
{
- mutexes.fill( 0 );
+ mutexes = new QMutex*[count];
+ for ( int index = 0; index < count; ++index ) {
+ mutexes[index] = 0;
+ }
}
/*!
Destructs a QMutexPool. All QMutexes that were created by the pool
are deleted.
*/
QMutexPool::~QMutexPool()
{
QMutexLocker locker( &mutex );
- QMutex **d = mutexes.data();
- for ( int index = 0; (uint) index < mutexes.size(); index++ ) {
- delete d[index];
- d[index] = 0;
+ for ( int index = 0; index < count; ++index ) {
+ delete mutexes[index];
+ mutexes[index] = 0;
}
+ delete [] mutexes;
+ mutexes = 0;
}
/*!
Returns a QMutex from the pool. QMutexPool uses the value \a
address to determine which mutex is retured from the pool.
*/
QMutex *QMutexPool::get( void *address )
{
- QMutex **d = mutexes.data();
- int index = (int)( (ulong) address % mutexes.size() );
+ int index = (int) ( (unsigned long) address % count );
- if ( ! d[index] ) {
+ if ( ! mutexes[index] ) {
// mutex not created, create one
QMutexLocker locker( &mutex );
// we need to check once again that the mutex hasn't been created, since
// 2 threads could be trying to create a mutex as the same index...
- if ( ! d[index] ) {
- d[index] = new QMutex( recurs );
+ if ( ! mutexes[index] ) {
+ mutexes[index] = new QMutex( recurs );
}
}
- return d[index];
+ return mutexes[index];
}
#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
@@ -254,33 +254,33 @@
\row \i <b>\\t</b>
\i This matches the ASCII horizontal tab character (HT, 0x09).
\row \i <b>\\v</b>
\i This matches the ASCII vertical tab character (VT, 0x0B).
\row \i <b>\\xhhhh</b>
\i This matches the Unicode character corresponding to the
hexadecimal number hhhh (between 0x0000 and 0xFFFF). \0ooo
(i.e., \zero ooo) matches the ASCII/Latin-1 character
corresponding to the octal number ooo (between 0 and 0377).
\row \i <b>. (dot)</b>
\i This matches any character (including newline).
\row \i <b>\\d</b>
- \i This matches a digit (see QChar::isDigit()).
+ \i This matches a digit (QChar::isDigit()).
\row \i <b>\\D</b>
\i This matches a non-digit.
\row \i <b>\\s</b>
- \i This matches a whitespace (see QChar::isSpace()).
+ \i This matches a whitespace (QChar::isSpace()).
\row \i <b>\\S</b>
\i This matches a non-whitespace.
\row \i <b>\\w</b>
- \i This matches a word character (see QChar::isLetterOrNumber()).
+ \i This matches a word character (QChar::isLetterOrNumber() or '_').
\row \i <b>\\W</b>
\i This matches a non-word character.
\row \i <b>\\n</b>
\i The n-th \link #capturing-text backreference \endlink,
e.g. \1, \2, etc.
\endtable
\e {Note that the C++ compiler transforms backslashes in strings
so to include a <b>\\</b> in a regexp you will need to enter it
twice, i.e. <b>\\\\</b>.}
\target sets-of-characters
@@ -538,25 +538,32 @@
Because QRegExp is string oriented there are no \A, \Z or \z
assertions. The \G assertion is not supported but can be emulated
in a loop.
Perl's $& is cap(0) or capturedTexts()[0]. There are no QRegExp
equivalents for $`, $' or $+. Perl's capturing variables, $1, $2,
... correspond to cap(1) or capturedTexts()[1], cap(2) or
capturedTexts()[2], etc.
To substitute a pattern use QString::replace().
Perl's extended \c{/x} syntax is not supported, nor are
- regexp comments (?#comment) or directives, e.g. (?i).
+ directives, e.g. (?i), or regexp comments, e.g. (?#comment). On
+ the other hand, C++'s rules for literal strings can be used to
+ achieve the same:
+ \code
+ QRegExp mark( "\\b" // word boundary
+ "[Mm]ark" // the word we want to match
+ );
+ \endcode
Both zero-width positive and zero-width negative lookahead
assertions (?=pattern) and (?!pattern) are supported with the same
syntax as Perl. Perl's lookbehind assertions, "independent"
subexpressions and conditional expressions are not supported.
Non-capturing parentheses are also supported, with the same
(?:pattern) syntax.
See QStringList::split() and QStringList::join() for equivalents
to Perl's split and join functions.
@@ -668,29 +675,29 @@
QStringList split() function can take a separator string or regexp
as an argument and split a string accordingly.
\code
QStringList field = QStringList::split( "\t", str );
\endcode
Here field[0] is the company, field[1] the web address and so on.
To imitate the matching of a shell we can use wildcard mode.
\code
- QRegExp rx( "*.html" ); // invalid regexp: * doesn't quantify anything
- rx.setWildcard( TRUE ); // now it's a valid wildcard regexp
- rx.search( "index.html" ); // returns 0 (matched at position 0)
- rx.search( "default.htm" ); // returns -1 (no match)
- rx.search( "readme.txt" ); // returns -1 (no match)
+ QRegExp rx( "*.html" ); // invalid regexp: * doesn't quantify anything
+ rx.setWildcard( TRUE ); // now it's a valid wildcard regexp
+ rx.exactMatch( "index.html" ); // returns TRUE
+ rx.exactMatch( "default.htm" ); // returns FALSE
+ rx.exactMatch( "readme.txt" ); // returns FALSE
\endcode
Wildcard matching can be convenient because of its simplicity, but
any wildcard regexp can be defined using full regexps, e.g.
<b>.*\.html$</b>. Notice that we can't match both \c .html and \c
.htm files with a wildcard unless we use <b>*.htm*</b> which will
also match 'test.html.bak'. A full regexp gives us the precision
we need, <b>.*\\.html?$</b>.
QRegExp can match case insensitively using setCaseSensitive(), and
can use non-greedy matching, see setMinimal(). By default QRegExp
uses full regexps but this can be changed with setWildcard().
@@ -706,24 +713,29 @@
\target member-function-documentation
*/
const int NumBadChars = 64;
#define BadChar( ch ) ( (ch).unicode() % NumBadChars )
const int NoOccurrence = INT_MAX;
const int EmptyCapture = INT_MAX;
const int InftyLen = INT_MAX;
const int InftyRep = 1025;
const int EOS = -1;
+static bool isWord( QChar ch )
+{
+ return ch.isLetterOrNumber() || ch == QChar( '_' );
+}
+
/*
Merges two QMemArrays of ints and puts the result into the first one.
*/
static void mergeInto( QMemArray<int> *a, const QMemArray<int>& b )
{
int asize = a->size();
int bsize = b.size();
if ( asize == 0 ) {
*a = b.copy();
#ifndef QT_NO_REGEXP_OPTIM
} else if ( bsize == 1 && (*a)[asize - 1] < b[0] ) {
a->resize( asize + 1 );
@@ -1671,27 +1683,27 @@ bool QRegExpEngine::testAnchor( int i, int a, const int *capBegin )
if ( mmPos + i != mmCaretPos )
return FALSE;
}
if ( (a & Anchor_Dollar) != 0 ) {
if ( mmPos + i != mmLen )
return FALSE;
}
#ifndef QT_NO_REGEXP_ESCAPE
if ( (a & (Anchor_Word | Anchor_NonWord)) != 0 ) {
bool before = FALSE;
bool after = FALSE;
if ( mmPos + i != 0 )
- before = mmIn[mmPos + i - 1].isLetterOrNumber();
+ before = isWord( mmIn[mmPos + i - 1] );
if ( mmPos + i != mmLen )
- after = mmIn[mmPos + i].isLetterOrNumber();
+ after = isWord( mmIn[mmPos + i] );
if ( (a & Anchor_Word) != 0 && (before == after) )
return FALSE;
if ( (a & Anchor_NonWord) != 0 && (before != after) )
return FALSE;
}
#endif
#ifndef QT_NO_REGEXP_LOOKAHEAD
bool catchx = TRUE;
if ( (a & Anchor_LookaheadMask) != 0 ) {
QConstString cstr = QConstString( (QChar *) mmIn + mmPos + i,
mmLen - mmPos - i );
@@ -2623,44 +2635,52 @@ int QRegExpEngine::getEscape()
// see QChar::isDigit()
yyCharClass->addCategories( 0x7fffffef );
return Tok_CharClass;
case 'S':
// see QChar::isSpace()
yyCharClass->addCategories( 0x7ffff87f );
yyCharClass->addRange( 0x0000, 0x0008 );
yyCharClass->addRange( 0x000e, 0x001f );
yyCharClass->addRange( 0x007f, 0x009f );
return Tok_CharClass;
case 'W':
// see QChar::isLetterOrNumber()
- yyCharClass->addCategories( 0x7ff07f8f );
+ yyCharClass->addCategories( 0x7fe07f8f );
+ yyCharClass->addRange( 0x203f, 0x2040 );
+ yyCharClass->addSingleton( 0x2040 );
+ yyCharClass->addSingleton( 0x30fb );
+ yyCharClass->addRange( 0xfe33, 0xfe34 );
+ yyCharClass->addRange( 0xfe4d, 0xfe4f );
+ yyCharClass->addSingleton( 0xff3f );
+ yyCharClass->addSingleton( 0xff65 );
return Tok_CharClass;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'b':
return Tok_Word;
#endif
#ifndef QT_NO_REGEXP_CCLASS
case 'd':
// see QChar::isDigit()
yyCharClass->addCategories( 0x00000010 );
return Tok_CharClass;
case 's':
// see QChar::isSpace()
yyCharClass->addCategories( 0x00000380 );
yyCharClass->addRange( 0x0009, 0x000d );
return Tok_CharClass;
case 'w':
// see QChar::isLetterOrNumber()
yyCharClass->addCategories( 0x000f8070 );
+ yyCharClass->addSingleton( 0x005f ); // '_'
return Tok_CharClass;
#endif
#ifndef QT_NO_REGEXP_ESCAPE
case 'x':
val = 0;
for ( i = 0; i < 4; i++ ) {
low = QChar( yyCh ).lower();
if ( low >= '0' && low <= '9' )
val = ( val << 4 ) | ( low - '0' );
else if ( low >= 'a' && low <= 'f' )
val = ( val << 4 ) | ( low - 'a' + 10 );
else
@@ -3174,45 +3194,47 @@ struct QRegExpPrivate
};
#ifndef QT_NO_REGEXP_OPTIM
static QCache<QRegExpEngine> *engineCache = 0;
static QSingleCleanupHandler<QCache<QRegExpEngine> > cleanup_cache;
#endif
static QRegExpEngine *newEngine( const QString& pattern, bool caseSensitive )
{
#ifndef QT_NO_REGEXP_OPTIM
if ( engineCache != 0 ) {
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &engineCache ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &engineCache ) : 0 );
#endif
QRegExpEngine *eng = engineCache->take( pattern );
if ( eng == 0 || eng->caseSensitive() != caseSensitive ) {
delete eng;
} else {
eng->ref();
return eng;
}
}
#endif
return new QRegExpEngine( pattern, caseSensitive );
}
static void derefEngine( QRegExpEngine *eng, const QString& pattern )
{
- if ( eng != 0 && eng->deref() ) {
-#ifndef QT_NO_REGEXP_OPTIM
#ifdef QT_THREAD_SUPPORT
- QMutexLocker locker( qt_global_mutexpool->get( &engineCache ) );
+ QMutexLocker locker( qt_global_mutexpool ?
+ qt_global_mutexpool->get( &engineCache ) : 0 );
#endif
+ if ( eng != 0 && eng->deref() ) {
+#ifndef QT_NO_REGEXP_OPTIM
if ( engineCache == 0 ) {
engineCache = new QCache<QRegExpEngine>;
engineCache->setAutoDelete( TRUE );
cleanup_cache.set( &engineCache );
}
if ( !pattern.isNull() &&
engineCache->insert(pattern, eng, 4 + pattern.length() / 4) )
return;
#else
Q_UNUSED( pattern );
#endif
delete eng;
@@ -3556,31 +3578,24 @@ bool QRegExp::exactMatch( const QString& str ) const
\sa QString::mid() QConstString
*/
int QRegExp::match( const QString& str, int index, int *len,
bool indexIsStart ) const
{
int pos = search( str, index, indexIsStart ? CaretAtOffset : CaretAtZero );
if ( len != 0 )
*len = matchedLength();
return pos;
}
#endif // QT_NO_COMPAT
-/*!
- \overload
-
- This convenience function searches with a \c CaretMode of \c
- CaretAtZero which is the most common usage.
-*/
-
int QRegExp::search( const QString& str, int offset ) const
{
return search( str, offset, CaretAtZero );
}
/*!
Attempts to find a match in \a str from position \a offset (0 by
default). If \a offset is -1, the search starts at the last
character; if -2, at the next to last character; etc.
Returns the position of the first match, or -1 if there was no
match.
@@ -3616,31 +3631,24 @@ int QRegExp::search( const QString& str, int offset, CaretMode caretMode ) const
if ( offset < 0 )
offset += str.length();
#ifndef QT_NO_REGEXP_CAPTURE
priv->t = str;
priv->capturedCache.clear();
#endif
priv->captured = eng->match( str, offset, priv->min, FALSE,
caretIndex(offset, caretMode) );
return priv->captured[0];
}
-/*!
- \overload
-
- This convenience function searches with a \c CaretMode of \c
- CaretAtZero which is the most common usage.
-*/
-
int QRegExp::searchRev( const QString& str, int offset ) const
{
return searchRev( str, offset, CaretAtZero );
}
/*!
Attempts to find a match backwards in \a str from position \a
offset. If \a offset is -1 (the default), the search starts at the
last character; if -2, at the next to last character; etc.
Returns the position of the first match, or -1 if there was no
match.
@@ -3685,25 +3693,25 @@ int QRegExp::searchRev( const QString& str, int offset,
/*!
Returns the length of the last matched string, or -1 if there was
no match.
\sa exactMatch() search() searchRev()
*/
int QRegExp::matchedLength() const
{
return priv->captured[1];
}
#ifndef QT_NO_REGEXP_CAPTURE
-/*!
+/*!
Returns the number of captures contained in the regular expression.
*/
int QRegExp::numCaptures() const
{
return eng->numCaptures();
}
/*!
Returns a list of the captured text strings.
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
@@ -174,62 +174,60 @@ int QSemaphore::operator--(int)
/*!
Try to get access to the semaphore. If \l available() \< \a n, this
call will block until it can get all the accesses it wants, i.e.
until available() \>= \a n.
*/
int QSemaphore::operator+=(int n)
{
int ret;
d->mutex.lock();
+ if ( n < 0 || n > d->max ) {
+#ifdef QT_CHECK_RANGE
+ qWarning( "QSemaphore::operator+=: paramter %d out of range", n );
+#endif // QT_CHECK_RANGE
+ n = n < 0 ? 0 : d->max;
+ }
+
while (d->value + n > d->max)
d->cond.wait(&(d->mutex));
d->value += n;
-
-#ifdef QT_CHECK_RANGE
- if (d->value > d->max) {
- qWarning("QSemaphore::operator+=: attempt to allocate more resources than available");
- d->value = d->max;
- }
-#endif
-
ret = d->value;
d->mutex.unlock();
return ret;
}
/*!
Release \a n accesses to the semaphore.
*/
int QSemaphore::operator-=(int n)
{
int ret;
d->mutex.lock();
- d->value -= n;
-
+ if ( n < 0 || n > d->value ) {
#ifdef QT_CHECK_RANGE
- if (d->value < 0) {
- qWarning("QSemaphore::operator-=: attempt to deallocate more resources than taken");
- d->value = 0;
+ qWarning( "QSemaphore::operator-=: paramter %d out of range", n );
+#endif // QT_CHECK_RANGE
+ n = n < 0 ? 0 : d->value;
}
-#endif
+ d->value -= n;
ret = d->value;
d->cond.wakeOne();
d->mutex.unlock();
return ret;
}
/*!
Returns the number of accesses currently available to the
semaphore.
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
@@ -1,18 +1,18 @@
/****************************************************************************
** $Id$
**
** Implementation of QSettings class
**
-** Created: 2000.06.26
+** Created : 000626
**
** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
@@ -54,114 +54,143 @@ static inline int qt_open( const char *pathname, int flags, mode_t mode )
#ifndef QT_NO_SETTINGS
#include "qdir.h"
#include "qfile.h"
#include "qfileinfo.h"
#include "qmap.h"
#include "qtextstream.h"
#include "qregexp.h"
#include <private/qsettings_p.h>
#include <errno.h>
/*!
- \class QSettings
- \brief The QSettings class provides persistent platform-independent application settings.
-
- \ingroup io
- \ingroup misc
- \mainclass
-
- On Unix systems, QSettings uses text files to store settings. On Windows
- systems, QSettings uses the system registry. On Mac OS X, QSettings will
- behave as on Unix, and store to text files.
-
- Each setting comprises an identifying key and the data associated with
- the key. A key is a unicode string which consists of \e two or more
- subkeys. A subkey is a slash, '/', followed by one or more unicode
- characters (excluding slashes, newlines, carriage returns and equals,
- '=', signs). The associated data, called the entry or value, may be a
- boolean, an integer, a double, a string or a list of strings. Entry
- strings may contain any unicode characters.
-
- If you want to save and restore the entire desktop's settings, i.e.
- which applications are running, use QSettings to save the settings
- for each individual application and QSessionManager to save the
- desktop's session.
+ \class QSettings
+ \brief The QSettings class provides persistent platform-independent application settings.
+
+ \ingroup io
+ \ingroup misc
+ \mainclass
+
+ On Unix systems, QSettings uses text files to store settings. On Windows
+ systems, QSettings uses the system registry. On Mac OS X, QSettings uses
+ the Carbon preferences API.
+
+ Each setting comprises an identifying key and the data associated with
+ the key. A key is a unicode string which consists of \e two or more
+ subkeys. A subkey is a slash, '/', followed by one or more unicode
+ characters (excluding slashes, newlines, carriage returns and equals,
+ '=', signs). The associated data, called the entry or value, may be a
+ boolean, an integer, a double, a string or a list of strings. Entry
+ strings may contain any unicode characters.
+
+ If you want to save and restore the entire desktop's settings, i.e.
+ which applications are running, use QSettings to save the settings
+ for each individual application and QSessionManager to save the
+ desktop's session.
Example settings:
\code
/MyCompany/MyApplication/background color
/MyCompany/MyApplication/foreground color
/MyCompany/MyApplication/geometry/x
/MyCompany/MyApplication/geometry/y
/MyCompany/MyApplication/geometry/width
/MyCompany/MyApplication/geometry/height
/MyCompany/MyApplication/recent files/1
/MyCompany/MyApplication/recent files/2
/MyCompany/MyApplication/recent files/3
\endcode
Each line above is a complete key, made up of subkeys.
- A typical usage pattern for application startup:
+ A typical usage pattern for reading application startup:
\code
QSettings settings;
- settings.insertSearchPath( QSettings::Windows, "/MyCompany" );
- // No search path needed for Unix; see notes further on.
- // Use default values if the keys don't exist
- QString bgColor = settings.readEntry( "/MyApplication/background color", "white" );
- int width = settings.readNumEntry( "/MyApplication/geometry/width", 640 );
+ settings.setPath( "MyCompany.com", "MyApplication" );
+
+ QString bgColor = settings.readEntry( "/colors/background", "white" );
+ int width = settings.readNumEntry( "/geometry/width", 640 );
// ...
\endcode
A typical usage pattern for application exit or 'save preferences':
\code
QSettings settings;
- settings.insertSearchPath( QSettings::Windows, "/MyCompany" );
- // No search path needed for Unix; see notes further on.
- settings.writeEntry( "/MyApplication/background color", bgColor );
- settings.writeEntry( "/MyApplication/geometry/width", width );
+ settings.setPath( "MyCompany.com", "MyApplication" );
+
+ settings.writeEntry( "/colors/background", bgColor );
+ settings.writeEntry( "/geometry/width", width );
// ...
\endcode
+ QSettings can build a key prefix that is prepended to all keys. To
+ build the key prefix, use beginGroup() and endGroup().
+ \code
+ QSettings settings;
+
+ settings.beginGroup( "/MainWindow" );
+ settings.beginGroup( "/Geometry" );
+ int x = settings.readEntry( "/x" );
+ // ...
+ settings.endGroup();
+ settings.beginGroup( "/Toolbars" );
+ // ...
+ settings.endGroup();
+ settings.endGroup();
+ \endcode
+
You can get a list of entry-holding keys by calling entryList(), and
a list of key-holding keys using subkeyList().
\code
QStringList keys = entryList( "/MyApplication" );
// keys contains 'background color' and 'foreground color'.
QStringList keys = entryList( "/MyApplication/recent files" );
// keys contains '1', '2' and '3'.
QStringList subkeys = subkeyList( "/MyApplication" );
// subkeys contains 'geometry' and 'recent files'
QStringList subkeys = subkeyList( "/MyApplication/recent files" );
// subkeys is empty.
\endcode
- If you wish to use a different search path call insertSearchPath()
- as often as necessary to add your preferred paths. Call
- removeSearchPath() to remove any unwanted paths.
-
Since settings for Windows are stored in the registry there are size
limits as follows:
\list
\i A subkey may not exceed 255 characters.
\i An entry's value may not exceed 16,300 characters.
\i All the values of a key (for example, all the 'recent files'
subkeys values), may not exceed 65,535 characters.
\endlist
- These limitations are not enforced on Unix.
+ These limitations are not enforced on Unix or Mac OS X.
+
+ If you wish to use a different search path call insertSearchPath()
+ as often as necessary to add your preferred paths. Call
+ removeSearchPath() to remove any unwanted paths.
+
+ \section1 Notes for Mac OS X Applications
+
+ Internal to the CFPreferences API it is not defined (for Mac OS 9
+ support) where the settings will ultimitely be stored. However, at the
+ time of this writing the settings will be stored (either on a global or
+ user basis, preferring locally) into a plist file in
+ $ROOT/System/Library/Preferences (in XML format). QSettings will create
+ an appropriate plist file (com.<first group name>.plist) out of the
+ full path to a key.
+
+ For further information on CFPreferences see also
+ \link http://developer.apple.com/techpubs/macosx/CoreFoundation/PreferenceServices/preferenceservices_carbon.html
+ Apple's Specifications\endlink
\section1 Notes for Unix Applications
There is no universally accepted place for storing application
settings under Unix. In the examples the settings file will be
searched for in the following directories:
\list 1
\i INSTALL/etc/settings
\i /opt/MyCompany/share/etc
\i /opt/MyCompany/share/MyApplication/etc
\i $HOME/.qt
\endlist
@@ -291,38 +320,38 @@ static HANDLE openlock( const QString &name, int /*type*/ )
return 0;
return 0;
HANDLE fd = 0;
QT_WA( {
fd = CreateFileW( (TCHAR*)name.ucs2(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
} , {
fd = CreateFileA( name.local8Bit(), GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );
} );
- if ( !LockFile( fd, 0, 0, -1, -1 ) ) {
+ if ( !LockFile( fd, 0, 0, (DWORD)-1, (DWORD)-1 ) ) { // ### (DWORD)-1 ???
#ifdef QT_CHECK_STATE
qWarning( "QSettings: openlock failed!" );
#endif
}
return fd;
}
-void closelock( HANDLE fd )
+static void closelock( HANDLE fd )
{
if ( !fd )
return;
- if ( !UnlockFile( fd, 0, 0, -1, -1 ) ) {
+ if ( !UnlockFile( fd, 0, 0, (DWORD)-1, (DWORD)-1 ) ) { // ### (DWORD)-1 ???
#ifdef QT_CHECK_STATE
qWarning( "QSettings: closelock failed!");
#endif
}
CloseHandle( fd );
}
#endif
QSettingsGroup::QSettingsGroup()
: modified(FALSE)
{
@@ -446,27 +475,29 @@ void QSettingsHeading::parseLine(QTextStream &stream)
#ifndef CSIDL_APPDATA
#define CSIDL_APPDATA 0x001a // <user name>\Application Data
#endif
#ifndef CSIDL_COMMON_APPDATA
#define CSIDL_COMMON_APPDATA 0x0023 // All Users\Application Data
#endif
#endif
QSettingsPrivate::QSettingsPrivate( QSettings::Format format )
: groupDirty( TRUE ), modified(FALSE), globalScope(TRUE)
{
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( format != QSettings::Ini )
return;
+#else
+ Q_UNUSED( format );
#endif
QString appSettings(QDir::homeDirPath() + "/.qt/");
QString defPath;
#ifdef Q_WS_WIN
#ifdef Q_OS_TEMP
TCHAR path[MAX_PATH];
SHGetSpecialFolderPath( 0, path, CSIDL_APPDATA, FALSE );
appSettings = QString::fromUcs2( path );
SHGetSpecialFolderPath( 0, path, CSIDL_COMMON_APPDATA, FALSE );
defPath = QString::fromUcs2( path );
#else
@@ -497,48 +528,52 @@ QSettingsPrivate::QSettingsPrivate( QSettings::Format format )
#else
// for now
#define QSETTINGS_DEFAULT_PATH_SUFFIX "/etc/settings"
defPath = qInstallPath();
defPath += QSETTINGS_DEFAULT_PATH_SUFFIX;
#endif
QDir dir(appSettings);
if (! dir.exists()) {
if (! dir.mkdir(dir.path()))
#if defined(QT_CHECK_STATE)
qWarning("QSettings: error creating %s", dir.path().latin1());
+#else
+ ;
#endif
}
if ( !!defPath )
searchPaths.append(defPath);
searchPaths.append(dir.path());
}
QSettingsPrivate::~QSettingsPrivate()
{
}
QSettingsGroup QSettingsPrivate::readGroup()
{
QSettingsHeading hd;
QSettingsGroup grp;
QMap<QString,QSettingsHeading>::Iterator headingsit = headings.find(heading);
if (headingsit != headings.end())
hd = *headingsit;
QSettingsHeading::Iterator grpit = hd.find(group);
if (grpit == hd.end()) {
QStringList::Iterator it = searchPaths.begin();
+ if ( !globalScope )
+ ++it;
while (it != searchPaths.end()) {
QString filebase = heading.lower().replace(QRegExp("\\s+"), "_");
QString fn((*it++) + "/" + filebase + "rc");
if (! hd.contains(fn + "cached")) {
hd.read(fn);
hd.insert(fn + "cached", QSettingsGroup());
}
}
headings.replace(heading, hd);
grpit = hd.find(group);
@@ -555,24 +590,26 @@ void QSettingsPrivate::removeGroup(const QString &key)
{
QSettingsHeading hd;
QSettingsGroup grp;
bool found = FALSE;
QMap<QString,QSettingsHeading>::Iterator headingsit = headings.find(heading);
if (headingsit != headings.end())
hd = *headingsit;
QSettingsHeading::Iterator grpit = hd.find(group);
if (grpit == hd.end()) {
QStringList::Iterator it = searchPaths.begin();
+ if ( !globalScope )
+ ++it;
while (it != searchPaths.end()) {
QString filebase = heading.lower().replace(QRegExp("\\s+"), "_");
QString fn((*it++) + "/" + filebase + "rc");
if (! hd.contains(fn + "cached")) {
hd.read(fn);
hd.insert(fn + "cached", QSettingsGroup());
}
}
headings.replace(heading, hd);
grpit = hd.find(group);
@@ -606,24 +643,26 @@ void QSettingsPrivate::removeGroup(const QString &key)
void QSettingsPrivate::writeGroup(const QString &key, const QString &value)
{
QSettingsHeading hd;
QSettingsGroup grp;
QMap<QString,QSettingsHeading>::Iterator headingsit = headings.find(heading);
if (headingsit != headings.end())
hd = *headingsit;
QSettingsHeading::Iterator grpit = hd.find(group);
if (grpit == hd.end()) {
QStringList::Iterator it = searchPaths.begin();
+ if ( !globalScope )
+ ++it;
while (it != searchPaths.end()) {
QString filebase = heading.lower().replace(QRegExp("\\s+"), "_");
QString fn((*it++) + "/" + filebase + "rc");
if (! hd.contains(fn + "cached")) {
hd.read(fn);
hd.insert(fn + "cached", QSettingsGroup());
}
}
headings.replace(heading, hd);
grpit = hd.find(group);
@@ -640,86 +679,94 @@ void QSettingsPrivate::writeGroup(const QString &key, const QString &value)
modified = TRUE;
}
QDateTime QSettingsPrivate::modificationTime()
{
QSettingsHeading hd = headings[heading];
QSettingsGroup grp = hd[group];
QDateTime datetime;
QStringList::Iterator it = searchPaths.begin();
+ if ( !globalScope )
+ ++it;
while (it != searchPaths.end()) {
QFileInfo fi((*it++) + "/" + heading + "rc");
if (fi.exists() && fi.lastModified() > datetime)
datetime = fi.lastModified();
}
return datetime;
}
-static bool verifyKey( const QString &key )
+bool qt_verify_key( const QString &key )
{
if ( key.isEmpty() || key[0] != '/' || key.contains( QRegExp("[=\\\\r\\\\n" ) ) )
return FALSE;
return TRUE;
}
static inline QString groupKey( const QString &group, const QString &key )
{
- if ( group.endsWith( "/" ) || key.startsWith( "/" ) )
+ if ( group.isEmpty() || ( group.length() == 1 && group[0] == '/' ) ) {
+ // group is empty, or it contains a single '/', so we just return the key
+ if ( key.startsWith( "/" ) )
+ return key;
+ return "/" + key;
+ } else if ( group.endsWith( "/" ) || key.startsWith( "/" ) ) {
return group + key;
+ }
return group + "/" + key;
}
/*!
Inserts \a path into the settings search path. The semantics of \a
path depends on the system \a s.
When \a s is \e Windows and the execution environment is \e not
Windows the function does nothing. Similarly when \a s is \e Unix and
the execution environment is \e not Unix the function does nothing.
When \a s is \e Windows, and the execution environment is Windows, the
search path list will be used as the first subfolder of the "Software"
folder in the registry.
When reading settings the folders are searched forwards from the
first folder (listed below) to the last, returning the first
- settings found, and ignoring any folders for which the user doesn't
+ settings found, and ignoring any folders for which the user doesn't
have read permission.
\list 1
\i HKEY_CURRENT_USER/Software/MyCompany/MyApplication
\i HKEY_LOCAL_MACHINE/Software/MyCompany/MyApplication
\i HKEY_CURRENT_USER/Software/MyApplication
\i HKEY_LOCAL_MACHINE/Software/MyApplication
\endlist
\code
QSettings settings;
settings.insertSearchPath( QSettings::Windows, "/MyCompany" );
settings.writeEntry( "/MyApplication/Tip of the day", TRUE );
\endcode
The code above will write the subkey "Tip of the day" into the \e
first of the registry folders listed below that is found and for
which the user has write permission.
\list 1
\i HKEY_LOCAL_MACHINE/Software/MyCompany/MyApplication
\i HKEY_CURRENT_USER/Software/MyCompany/MyApplication
\i HKEY_LOCAL_MACHINE/Software/MyApplication
\i HKEY_CURRENT_USER/Software/MyApplication
\endlist
If a setting is found in the HKEY_CURRENT_USER space, this setting
- is overwritten independently of write permissions in the
+ is overwritten independently of write permissions in the
HKEY_LOCAL_MACHINE space.
When \a s is \e Unix, and the execution environment is Unix, the
search path list will be used when trying to determine a suitable
filename for reading and writing settings files. By default, there are
two entries in the search path:
\list 1
\i INSTALL/etc - where \c INSTALL is the directory where Qt was installed.
\i $HOME/.qt/ - where \c $HOME is the user's home directory.
\endlist
@@ -748,187 +795,204 @@ static inline QString groupKey( const QString &group, const QString &key )
first subkey of the key (not including the search path). The algorithm
for creating names is essentially: lowercase the first subkey, replace
spaces with underscores and add 'rc', e.g.
<tt>/MyCompany/MyApplication/background color</tt> will be stored in
<tt>myapplicationrc</tt> (assuming that <tt>/MyCompany</tt> is part of
the search path).
\sa removeSearchPath()
*/
void QSettings::insertSearchPath( System s, const QString &path)
{
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd ) {
d->sysInsertSearchPath( s, path );
return;
}
#endif
- if ( !verifyKey( path ) ) {
+#if !defined(Q_WS_WIN)
+ if ( s == Windows )
+ return;
+#endif
+#if !defined(Q_WS_WIN)
+ if ( s == Mac )
+ return;
+#endif
+
+ if ( !qt_verify_key( path ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::insertSearchPath: Invalid key: '%s'", path.isNull() ? "(null)" : path.latin1() );
#endif
return;
}
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd && s != Unix ) {
#else
if ( s != Unix ) {
#endif
-#ifdef Q_OS_MAC
+#if !defined(QWS) && defined(Q_OS_MAC)
if(s != Mac) //mac is respected on the mac as well
#endif
return;
}
+ QString realPath = path;
+#if defined(Q_WS_WIN)
+ QString defPath = d->globalScope ? d->searchPaths.first() : d->searchPaths.last();
+ realPath = defPath + path;
+#endif
+
QStringList::Iterator it = d->searchPaths.find(d->searchPaths.last());
if (it != d->searchPaths.end()) {
- d->searchPaths.insert(it, path);
+ d->searchPaths.insert(it, realPath);
}
}
/*!
Removes all occurrences of \a path (using exact matching) from the
settings search path for system \a s. Note that the default search
paths cannot be removed.
\sa insertSearchPath()
*/
void QSettings::removeSearchPath( System s, const QString &path)
{
- if ( !verifyKey( path ) ) {
+ if ( !qt_verify_key( path ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::insertSearchPath: Invalid key: '%s'", path.isNull() ? "(null)" : path.latin1() );
#endif
return;
}
#ifdef Q_WS_WIN
if ( d->sysd ) {
d->sysRemoveSearchPath( s, path );
return;
}
#endif
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd && s != Unix ) {
#else
if ( s != Unix ) {
#endif
-#ifdef Q_OS_MAC
+#if !defined(QWS) && defined(Q_OS_MAC)
if(s != Mac) //mac is respected on the mac as well
#endif
return;
}
if (path == d->searchPaths.first() || path == d->searchPaths.last())
return;
d->searchPaths.remove(path);
}
/*!
Creates a settings object.
*/
QSettings::QSettings()
{
d = new QSettingsPrivate( Native );
Q_CHECK_PTR(d);
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
d->sysd = 0;
d->sysInit();
#endif
}
/*!
Creates a settings object. If \a format is 'Ini' the settings will
be stored in a text file, using the Unix strategy (see above). If \a format
is 'Native', the settings will be stored in a platform specific way
(ie. the Windows registry).
*/
QSettings::QSettings( Format format )
{
d = new QSettingsPrivate( format );
Q_CHECK_PTR(d);
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
d->sysd = 0;
if ( format == Native )
d->sysInit();
#else
Q_UNUSED(format);
#endif
}
/*!
Destroys the settings object. All modifications made to the settings
will automatically be saved.
*/
QSettings::~QSettings()
{
sync();
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
d->sysClear();
#endif
delete d;
}
/*! \internal
Writes all modifications to the settings to disk. If any errors are
encountered, this function returns FALSE, otherwise it will return TRUE.
*/
bool QSettings::sync()
{
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
return d->sysSync();
#endif
if (! d->modified)
// fake success
return TRUE;
bool success = TRUE;
QMap<QString,QSettingsHeading>::Iterator it = d->headings.begin();
while (it != d->headings.end()) {
// determine filename
QSettingsHeading hd(*it);
QSettingsHeading::Iterator hdit = hd.begin();
QFile file;
QStringList::Iterator pit = d->searchPaths.begin();
+ if ( !d->globalScope )
+ ++pit;
while (pit != d->searchPaths.end()) {
QString filebase = it.key().lower().replace(QRegExp("\\s+"), "_");
QFileInfo di(*pit);
QFileInfo fi((*pit++) + "/" + filebase + "rc");
if ((fi.exists() && fi.isFile() && fi.isWritable()) ||
(! fi.exists() && di.isDir() && di.isWritable())) {
file.setName(fi.filePath());
break;
}
}
- it++;
+ ++it;
- if (file.name().isNull() || file.name().isEmpty()) {
+ if ( file.name().isEmpty() ) {
#ifdef QT_CHECK_STATE
qWarning("QSettings::sync: filename is null/empty");
#endif // QT_CHECK_STATE
success = FALSE;
continue;
}
HANDLE lockfd = openlock( file.name(), Q_LOCKWRITE );
if (! file.open(IO_WriteOnly)) {
@@ -954,31 +1018,31 @@ bool QSettings::sync()
QSettingsGroup::Iterator grpit = grp.begin();
while (grpit != grp.end()) {
QString v = grpit.data();
if ( v.isNull() ) {
v = "\\0"; // escape null string
} else {
v.replace("\\", "\\\\"); // escape backslash
v.replace("\n", "\\n"); // escape newlines
}
stream << grpit.key() << "=" << v << endl;
- grpit++;
+ ++grpit;
}
stream << endl;
}
- hdit++;
+ ++hdit;
}
if (file.status() != IO_Ok) {
#ifdef QT_CHECK_STATE
qWarning("QSettings::sync: error at end of write");
#endif // QT_CHECK_STATE
success = FALSE;
}
file.close();
@@ -999,41 +1063,40 @@ bool QSettings::sync()
default value, \a def, if the entry couldn't be read.
If \a ok is non-null, *ok is set to TRUE if the key was read, FALSE
otherwise.
\sa readEntry(), readNumEntry(), readDoubleEntry(), writeEntry(), removeEntry()
*/
/*!
\internal
*/
bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok )
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::readBoolEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
if ( ok )
*ok = FALSE;
return def;
}
- QString theKey = groupKey( group(), key );
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
- return d->sysReadBoolEntry( theKey, def, ok );
+ return d->sysReadBoolEntry( groupKey( group(), key ), def, ok );
#endif
- QString value = readEntry( theKey, ( def ? "true" : "false" ), ok );
+ QString value = readEntry( key, ( def ? "true" : "false" ), ok );
if (value.lower() == "true")
return TRUE;
else if (value.lower() == "false")
return FALSE;
else if (value == "1")
return TRUE;
else if (value == "0")
return FALSE;
if (! value.isEmpty())
qWarning("QSettings::readBoolEntry: '%s' is not 'true' or 'false'",
@@ -1051,41 +1114,40 @@ bool QSettings::readBoolEntry(const QString &key, bool def, bool *ok )
default value, \a def, if the entry couldn't be read.
If \a ok is non-null, *ok is set to TRUE if the key was read, FALSE
otherwise.
\sa readEntry(), readNumEntry(), readBoolEntry(), writeEntry(), removeEntry()
*/
/*!
\internal
*/
double QSettings::readDoubleEntry(const QString &key, double def, bool *ok )
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::readDoubleEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
if ( ok )
*ok = FALSE;
return def;
}
- QString theKey = groupKey( group(), key );
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
- return d->sysReadDoubleEntry( theKey, def, ok );
+ return d->sysReadDoubleEntry( groupKey( group(), key ), def, ok );
#endif
- QString value = readEntry( theKey, QString::number(def), ok );
+ QString value = readEntry( key, QString::number(def), ok );
bool conv_ok;
double retval = value.toDouble( &conv_ok );
if ( conv_ok )
return retval;
if ( ! value.isEmpty() )
qWarning( "QSettings::readDoubleEntry: '%s' is not a number",
value.latin1() );
if ( ok )
*ok = FALSE;
return def;
}
@@ -1097,41 +1159,39 @@ double QSettings::readDoubleEntry(const QString &key, double def, bool *ok )
default value, \a def, if the entry couldn't be read.
If \a ok is non-null, *ok is set to TRUE if the key was read, FALSE
otherwise.
\sa readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry()
*/
/*!
\internal
*/
int QSettings::readNumEntry(const QString &key, int def, bool *ok )
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::readNumEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
if ( ok )
*ok = FALSE;
return def;
}
- QString theKey = groupKey( group(), key );
-
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
- return d->sysReadNumEntry( theKey, def, ok );
+ return d->sysReadNumEntry( groupKey( group(), key ), def, ok );
#endif
- QString value = readEntry( theKey, QString::number( def ), ok );
+ QString value = readEntry( key, QString::number( def ), ok );
bool conv_ok;
int retval = value.toInt( &conv_ok );
if ( conv_ok )
return retval;
if ( ! value.isEmpty() )
qWarning( "QSettings::readNumEntry: '%s' is not a number",
value.latin1() );
if ( ok )
*ok = FALSE;
return def;
}
@@ -1143,37 +1203,37 @@ int QSettings::readNumEntry(const QString &key, int def, bool *ok )
default value, \a def, if the entry couldn't be read.
If \a ok is non-null, *ok is set to TRUE if the key was read, FALSE
otherwise.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry()
*/
/*!
\internal
*/
QString QSettings::readEntry(const QString &key, const QString &def, bool *ok )
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::readEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
if ( ok )
*ok = FALSE;
return def;
}
QString theKey = groupKey( group(), key );
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
return d->sysReadEntry( theKey, def, ok );
#endif
if ( ok ) // no, everything is not ok
*ok = FALSE;
QString realkey;
if (theKey[0] == '/') {
// parse our key
QStringList list(QStringList::split('/', theKey));
@@ -1197,182 +1257,176 @@ QString QSettings::readEntry(const QString &key, const QString &def, bool *ok )
// remove the group from the list
list.remove(list.at(1));
// remove the heading from the list
list.remove(list.at(0));
realkey = list.join("/");
}
} else
realkey = theKey;
QSettingsGroup grp = d->readGroup();
- QString retval = grp[realkey];
- if ( retval.isNull() )
- retval = def;
- else if ( ok ) // everything is ok
- *ok = TRUE;
+ QSettingsGroup::const_iterator it = grp.find( realkey ), end = grp.end();
+ QString retval = def;
+ if ( it != end ) {
+ // found the value we needed
+ retval = *it;
+ if ( ok ) *ok = TRUE;
+ }
return retval;
}
#if !defined(Q_NO_BOOL_TYPE)
/*!
Writes the boolean entry \a value into key \a key. The \a key is
created if it doesn't exist. Any previous value is overwritten by \a
value.
If an error occurs the settings are left unchanged and FALSE is
returned; otherwise TRUE is returned.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
bool QSettings::writeEntry(const QString &key, bool value)
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
return FALSE;
}
- QString theKey = groupKey( group(), key );
-
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
- return d->sysWriteEntry( theKey, value );
+ return d->sysWriteEntry( groupKey( group(), key ), value );
#endif
QString s(value ? "true" : "false");
- return writeEntry(theKey, s);
+ return writeEntry(key, s);
}
#endif
/*!
\overload
Writes the double entry \a value into key \a key. The \a key is
created if it doesn't exist. Any previous value is overwritten by \a
value.
If an error occurs the settings are left unchanged and FALSE is
returned; otherwise TRUE is returned.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
bool QSettings::writeEntry(const QString &key, double value)
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
return FALSE;
}
- QString theKey = groupKey( group(), key );
-
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
- return d->sysWriteEntry( theKey, value );
+ return d->sysWriteEntry( groupKey( group(), key ), value );
#endif
QString s(QString::number(value));
- return writeEntry(theKey, s);
+ return writeEntry(key, s);
}
/*!
\overload
Writes the integer entry \a value into key \a key. The \a key is
created if it doesn't exist. Any previous value is overwritten by \a
value.
If an error occurs the settings are left unchanged and FALSE is
returned; otherwise TRUE is returned.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
bool QSettings::writeEntry(const QString &key, int value)
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
return FALSE;
}
- QString theKey = groupKey( group(), key );
-
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
- return d->sysWriteEntry( theKey, value );
+ return d->sysWriteEntry( groupKey( group(), key ), value );
#endif
QString s(QString::number(value));
- return writeEntry(theKey, s);
+ return writeEntry(key, s);
}
/*!
\internal
Writes the entry specified by \a key with the string-literal \a value,
replacing any previous setting. If \a value is zero-length or null, the
entry is replaced by an empty setting.
\e NOTE: This function is provided because some compilers use the
writeEntry (const QString &, bool) overload for this code:
writeEntry ("/foo/bar", "baz")
If an error occurs, this functions returns FALSE and the object is left
unchanged.
\sa readEntry(), removeEntry()
*/
bool QSettings::writeEntry(const QString &key, const char *value)
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
return FALSE;
}
- QString theKey = groupKey( group(), key );
-
- return writeEntry(theKey, QString(value));
+ return writeEntry(key, QString(value));
}
/*!
\overload
Writes the string entry \a value into key \a key. The \a key is
created if it doesn't exist. Any previous value is overwritten by \a
value. If \a value is an empty string or a null string the key's
value will be an empty string.
If an error occurs the settings are left unchanged and FALSE is
returned; otherwise TRUE is returned.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
bool QSettings::writeEntry(const QString &key, const QString &value)
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::writeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
return FALSE;
}
QString theKey = groupKey( group(), key );
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
return d->sysWriteEntry( theKey, value );
#endif
// NOTE: we *do* allow value to be a null/empty string
QString realkey;
if (theKey[0] == '/') {
// parse our key
QStringList list(QStringList::split('/', theKey));
if (list.count() < 2) {
@@ -1406,34 +1460,34 @@ bool QSettings::writeEntry(const QString &key, const QString &value)
}
/*!
Removes the entry specified by \a key.
Returns TRUE if the entry existed and was removed; otherwise returns FALSE.
\sa readEntry(), writeEntry()
*/
bool QSettings::removeEntry(const QString &key)
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::removeEntry: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
return FALSE;
}
QString theKey = groupKey( group(), key );
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
return d->sysRemoveEntry( theKey );
#endif
QString realkey;
if (theKey[0] == '/') {
// parse our key
QStringList list(QStringList::split('/', theKey));
if (list.count() < 2) {
#ifdef QT_CHECK_STATE
@@ -1485,34 +1539,34 @@ bool QSettings::removeEntry(const QString &key)
\c keys contains 'background color' and 'foreground color'. It does
not contain 'geometry' because this key contains keys not entries.
To access the geometry values could either use subkeyList() to read
the keys and then read each entry, or simply read each entry
directly by specifying its full key, e.g.
"/MyCompany/MyApplication/geometry/y".
\sa subkeyList()
*/
QStringList QSettings::entryList(const QString &key) const
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::entryList: Invalid key: %s", key.isNull() ? "(null)" : key.latin1() );
#endif
return QStringList();
}
QString theKey = groupKey( group(), key );
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
return d->sysEntryList( theKey );
#endif
QString realkey;
if (theKey[0] == '/') {
// parse our key
QStringList list(QStringList::split('/', theKey));
if (list.count() < 1) {
#ifdef QT_CHECK_STATE
qWarning("QSettings::listEntries: invalid key '%s'", theKey.latin1());
@@ -1535,25 +1589,25 @@ QStringList QSettings::entryList(const QString &key) const
realkey = list.join("/");
}
} else
realkey = theKey;
QSettingsGroup grp = d->readGroup();
QSettingsGroup::Iterator it = grp.begin();
QStringList ret;
QString itkey;
while (it != grp.end()) {
itkey = it.key();
- it++;
+ ++it;
if ( realkey.length() > 0 ) {
if ( itkey.left( realkey.length() ) != realkey )
continue;
else
itkey.remove( 0, realkey.length() + 1 );
}
if ( itkey.find( '/' ) != -1 )
continue;
ret << itkey;
@@ -1582,75 +1636,90 @@ QStringList QSettings::entryList(const QString &key) const
\code
QStringList keys = subkeyList( "/MyCompany/MyApplication" );
\endcode
\c keys contains 'geometry' and 'recent files'. It does not contain
'background color' or 'foreground color' because they are keys which
contain entries not keys. To get a list of keys that have values
rather than subkeys use entryList().
\sa entryList()
*/
QStringList QSettings::subkeyList(const QString &key) const
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::subkeyList: Invalid key: %s", key.isNull() ? "(null)" : key.latin1() );
#endif
return QStringList();
}
QString theKey = groupKey( group(), key );
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
return d->sysSubkeyList( theKey );
#endif
QString realkey;
+ int subkeycount = 2;
if (theKey[0] == '/') {
// parse our key
QStringList list(QStringList::split('/', theKey));
if (list.count() < 1) {
#ifdef QT_CHECK_STATE
qWarning("QSettings::subkeyList: invalid key '%s'", theKey.latin1());
#endif // QT_CHECK_STATE
return QStringList();
}
+ subkeycount = list.count();
+
if (list.count() == 1) {
d->heading = list[0];
d->group = "General";
} else {
d->heading = list[0];
d->group = list[1];
// remove the group from the list
list.remove(list.at(1));
// remove the heading from the list
list.remove(list.at(0));
realkey = list.join("/");
}
+
} else
realkey = theKey;
+ QStringList ret;
+ if ( subkeycount == 1 ) {
+ QMap<QString,QSettingsHeading>::Iterator it = d->headings.begin();
+ while ( it != d->headings.end() ) {
+ if ( it.key() != "General" && ! ret.contains( it.key() ) )
+ ret << it.key();
+ ++it;
+ }
+
+ return ret;
+ }
+
QSettingsGroup grp = d->readGroup();
QSettingsGroup::Iterator it = grp.begin();
- QStringList ret;
QString itkey;
while (it != grp.end()) {
itkey = it.key();
- it++;
+ ++it;
if ( realkey.length() > 0 ) {
if ( itkey.left( realkey.length() ) != realkey )
continue;
else
itkey.remove( 0, realkey.length() + 1 );
}
int slash = itkey.find( '/' );
if ( slash == -1 )
continue;
itkey.truncate( slash );
@@ -1661,34 +1730,34 @@ QStringList QSettings::subkeyList(const QString &key) const
return ret;
}
/*!
\internal
This function returns the time of last modification for \a key.
*/
QDateTime QSettings::lastModficationTime(const QString &key)
{
- if ( !verifyKey( key ) ) {
+ if ( !qt_verify_key( key ) ) {
#if defined(QT_CHECK_STATE)
qWarning( "QSettings::lastModficationTime: Invalid key: '%s'", key.isNull() ? "(null)" : key.latin1() );
#endif
return QDateTime();
}
QString theKey = groupKey( group(), key );
-#if defined(Q_WS_WIN) || defined(Q_OS_MAC)
+#if !defined(QWS) && (defined(Q_WS_WIN) || defined(Q_OS_MAC))
if ( d->sysd )
return QDateTime();
#endif
if (theKey[0] == '/') {
// parse our key
QStringList list(QStringList::split('/', theKey));
if (list.count() < 2) {
#ifdef QT_CHECK_STATE
qWarning("QSettings::lastModficationTime: invalid key '%s'", theKey.latin1());
#endif // QT_CHECK_STATE
@@ -1706,27 +1775,35 @@ QDateTime QSettings::lastModficationTime(const QString &key)
}
return d->modificationTime();
}
/*!
\overload
Writes the string list entry \a value into key \a key. The \a key
is created if it doesn't exist. Any previous value is overwritten
by \a value. The list is stored as a sequence of strings separated
- by \a separator, so none of the strings in the list should contain
- the separator. If the list is empty or null the key's value will
- be an empty string.
+ by \a separator (using QStringList::join()), so none of the
+ strings in the list should contain the separator. If the list is
+ empty or null the key's value will be an empty string.
+
+ \warning The list should not contain empty or null strings, as
+ readListEntry() will use QStringList::split() to recreate the
+ list. As the documentation states, QStringList::split() will omit
+ empty strings from the list. Because of this, it is impossible to
+ retrieve identical list data that is stored with this function.
+ We recommend using the writeEntry() and readListEntry() overloads
+ that do not take a \a separator argument.
If an error occurs the settings are left unchanged and FALSE is
returned; otherwise returns TRUE.
\sa readListEntry(), readNumEntry(), readDoubleEntry(), readBoolEntry(), removeEntry()
*/
bool QSettings::writeEntry(const QString &key, const QStringList &value,
const QChar &separator)
{
QString s(value.join(separator));
return writeEntry(key, s);
}
@@ -1759,24 +1836,31 @@ bool QSettings::writeEntry(const QString &key, const QStringList &value)
return writeEntry(key, s);
}
/*!
\overload QStringList QSettings::readListEntry(const QString &key, const QChar &separator, bool *ok ) const
Reads the entry specified by \a key as a string. The \a separator
is used to create a QStringList by calling QStringList::split(\a
separator, entry). If \a ok is not 0: \a *ok is set to TRUE if the
key was read, otherwise \a *ok is set to FALSE.
+ \warning As the documentation states, QStringList::split() will
+ omit empty strings from the list. Because of this, it is
+ impossible to retrieve identical list data with this function. We
+ recommend using the readListEntry() and writeEntry() overloads
+ that do not take a \a separator argument.
+
+
Note that if you want to iterate over the list, you should iterate
over a copy, e.g.
\code
QStringList list = mySettings.readListEntry( "size", " " );
QStringList::Iterator it = list.begin();
while( it != list.end() ) {
myProcessing( *it );
++it;
}
\endcode
\sa readEntry(), readDoubleEntry(), readBoolEntry(), writeEntry(), removeEntry(), QStringList::split()
@@ -1838,89 +1922,110 @@ QStringList QSettings::readListEntry(const QString &key, bool *ok )
esc=FALSE;
} else if ( value[i] == '^' ) {
esc = TRUE;
} else {
s.append(value[i]);
if ( i == (int)value.length()-1 )
l.append(s);
}
}
return l;
}
+#ifdef Q_OS_MAC
+void qt_setSettingsBasePath(const QString &); //qsettings_mac.cpp
+#endif
+
/*!
- Insert platform-dependent paths from platform-independent information.
+ Insert platform-dependent paths from platform-independent information.
+
+ The \a domain should be an Internet domain name
+ controlled by the producer of the software, eg. Trolltech products
+ use "trolltech.com".
- The \a domain should be an Internet domain name
- controlled by the producer of the software, eg. Trolltech products
- use "trolltech.com".
+ The \a product should be the official name of the product.
- The \a product should be the official name of the product.
+ The \a scope should be
+ QSettings::User for user-specific settings, or
+ QSettings::Global for system-wide settings (generally
+ these will be read-only to many users).
- The \a scope should be
- QSettings::User for user-specific settings, or
- QSettings::Global for system-wide settings (generally
- these will be read-only to many users).
+ Not all information is relevant on all systems (e.g. scoping is
+ currently used only if QSettings accesses the Windows registry).
*/
void QSettings::setPath( const QString &domain, const QString &product, Scope scope )
{
// On Windows, any trailing ".com(\..*)" is stripped from the domain. The
// Global scope corresponds to HKEY_LOCAL_MACHINE, and User corresponds to
// HKEY_CURRENT_USER. Note that on some installations, not all users can
// write to the Global scope. On UNIX, any trailing ".com(\..*)" is stripped
// from the domain. The Global scope corresponds to "/opt" (this would be
// configurable at library build time - eg. to "/usr/local" or "/usr"),
// while the User scope corresponds to $HOME/.*rc.
// Note that on most installations, not all users can write to the System
// scope.
-//
+//
// On MacOS X, if there is no "." in domain, append ".com", then reverse the
// order of the elements (Mac OS uses "com.apple.finder" as domain+product).
// The Global scope corresponds to /Library/Preferences/*.plist, while the
// User scope corresponds to ~/Library/Preferences/*.plist.
// Note that on most installations, not all users can write to the System
// scope.
+ d->globalScope = scope == Global;
+
QString actualSearchPath;
int lastDot = domain.findRev( '.' );
#if defined(Q_WS_WIN)
actualSearchPath = "/" + domain.mid( 0, lastDot ) + "/" + product;
insertSearchPath( Windows, actualSearchPath );
-#elif defined(Q_WS_MAC)
+#elif !defined(QWS) && defined(Q_OS_MAC)
QString topLevelDomain = domain.right( domain.length() - lastDot - 1 ) + ".";
- if ( topLevelDomain.isEmpty() )
- topLevelDomain = "com.";
- actualSearchPath = "/" + topLevelDomain + domain.left( lastDot ) + product;
+ if ( !topLevelDomain.isEmpty() )
+ qt_setSettingsBasePath( topLevelDomain );
+ actualSearchPath = "/" + domain.left( lastDot ) + product;
insertSearchPath( Mac, actualSearchPath );
#else
actualSearchPath = "/" + domain.mid( 0, lastDot ) + "/" + product;
insertSearchPath( Unix, actualSearchPath );
#endif
-
- d->globalScope = scope == Global;
}
/*!
Appends \a group to the current key prefix.
+
+ \code
+ QSettings settings;
+ settings.beginGroup( "/MainWindow" );
+ // read values
+ settings.endGroup();
+ \endcode
*/
void QSettings::beginGroup( const QString &group )
{
d->groupStack.push( group );
d->groupDirty = TRUE;
}
/*!
Undo previous calls to beginGroup(). Note that a single beginGroup("a/b/c") is undone
by a single call to endGroup().
+
+ \code
+ QSettings settings;
+ settings.beginGroup( "/MainWindow/Geometry" );
+ // read values
+ settings.endGroup();
+ \endcode
*/
void QSettings::endGroup()
{
d->groupStack.pop();
d->groupDirty = TRUE;
}
/*!
Set the current key prefix to the empty string.
*/
void QSettings::resetGroup()
{
@@ -1936,20 +2041,20 @@ void QSettings::resetGroup()
*/
QString QSettings::group() const
{
if ( d->groupDirty ) {
d->groupDirty = FALSE;
d->groupPrefix = QString::null;
QValueStack<QString>::Iterator it = d->groupStack.begin();
while ( it != d->groupStack.end() ) {
QString group = *it;
++it;
if ( group[0] != '/' )
- group = "/" + group;
+ group.prepend( "/" );
d->groupPrefix += group;
}
}
return d->groupPrefix;
}
#endif
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
@@ -1,20 +1,20 @@
/****************************************************************************
** $Id$
**
** Implementation of the QString class and related Unicode functions
**
** Created : 920722
**
-** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
+** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
**
** This file is part of the tools module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
@@ -38,36 +38,40 @@
// Don't define it while compiling this module, or USERS of Qt will
// not be able to link.
#ifdef QT_NO_CAST_ASCII
#undef QT_NO_CAST_ASCII
#endif
#include "qstring.h"
#include "qregexp.h"
#include "qdatastream.h"
#ifndef QT_NO_TEXTCODEC
#include "qtextcodec.h"
#endif
-#include <ctype.h>
#include <limits.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#if defined(Q_WS_WIN)
#include "qt_windows.h"
#endif
#if !defined( QT_NO_COMPONENT ) && !defined( QT_LITE_COMPONENT )
#include "qcleanuphandler.h"
#endif
+#ifdef QT_NO_UNICODETABLES
+# include <ctype.h>
+#endif
+
/* -------------------------------------------------------------------------
* unicode information
* these tables are generated from the unicode reference file
* ftp://ftp.unicode.org/Public/3.2-Update/UnicodeData.txt
*
* Lars
* -------------------------------------------------------------------------
*/
/* Perl script to generate (run perl -x tools/qstring.cpp)
@@ -11778,36 +11782,38 @@ static inline QChar upper( const QChar &c )
else
return QChar( toupper((uchar) c.latin1()) );
#endif
}
static inline QChar::Direction direction( const QChar &c )
{
#ifndef QT_NO_UNICODETABLES
const Q_UINT8 *rowp = direction_info[c.row()];
if(!rowp) return QChar::DirL;
return (QChar::Direction) ( *(rowp+c.cell()) & 0x1f );
#else
+ Q_UNUSED(c);
return QChar::DirL;
#endif
}
static inline bool mirrored( const QChar &c )
{
#ifndef QT_NO_UNICODETABLES
const Q_UINT8 *rowp = direction_info[c.row()];
if ( !rowp )
return FALSE;
return *(rowp+c.cell())>128;
#else
+ Q_UNUSED(c);
return FALSE;
#endif
}
#ifndef QT_NO_UNICODETABLES
static const Q_UINT16 symmetricPairs[] = {
0x0028, 0x0029, 0x003C, 0x003E, 0x005B, 0x005D, 0x007B, 0x007D,
0x00AB, 0x00BB, 0x2039, 0x203A, 0x2045, 0x2046, 0x207D, 0x207E,
0x208D, 0x208E, 0x2208, 0x220B, 0x2209, 0x220C, 0x220A, 0x220D,
0x2215, 0x29F5, 0x223C, 0x223D, 0x2243, 0x22CD, 0x2252, 0x2253,
0x2254, 0x2255, 0x2264, 0x2265, 0x2266, 0x2267, 0x2268, 0x2269,
0x226A, 0x226B, 0x226E, 0x226F, 0x2270, 0x2271, 0x2272, 0x2273,
@@ -11891,25 +11897,25 @@ static int ucstrnicmp( const QChar *a, const QChar *b, int l )
while ( l-- && ::lower( *a ) == ::lower( *b ) )
a++,b++;
if ( l==-1 )
return 0;
return ::lower( *a ).unicode() - ::lower( *b ).unicode();
}
static uint computeNewMax( uint len )
{
uint newMax = 4;
while ( newMax < len )
newMax *= 2;
- // try to spare some memory
+ // try to save some memory
if ( newMax >= 1024 * 1024 && len <= newMax - (newMax >> 2) )
newMax -= newMax >> 2;
return newMax;
}
/*!
\class QCharRef qstring.h
\reentrant
\brief The QCharRef class is a helper class for QString.
\ingroup text
@@ -12882,44 +12888,44 @@ void QString::compose()
#define QT_ALLOC_QCHAR_VEC( N ) (QChar*) new char[ sizeof(QChar)*( N ) ]
#define QT_DELETE_QCHAR_VEC( P ) delete[] ((char*)( P ))
/*!
This utility function converts the 8-bit string \a ba to Unicode,
returning the result.
The caller is responsible for deleting the return value with
delete[].
*/
-QChar* QString::asciiToUnicode( const QByteArray& ba, uint* len )
+QChar* QString::latin1ToUnicode( const QByteArray& ba, uint* len )
{
if ( ba.isNull() ) {
*len = 0;
return 0;
}
int l = 0;
while ( l < (int)ba.size() && ba[l] )
l++;
char* str = ba.data();
QChar *uc = new QChar[ l ]; // Can't use macro, since function is public
QChar *result = uc;
if ( len )
*len = l;
while (l--)
*uc++ = *str++;
return result;
}
-static QChar* internalAsciiToUnicode( const QByteArray& ba, uint* len )
+static QChar* internalLatin1ToUnicode( const QByteArray& ba, uint* len )
{
if ( ba.isNull() ) {
*len = 0;
return 0;
}
int l = 0;
while ( l < (int)ba.size() && ba[l] )
l++;
char* str = ba.data();
QChar *uc = QT_ALLOC_QCHAR_VEC( l );
QChar *result = uc;
if ( len )
@@ -12931,79 +12937,79 @@ static QChar* internalAsciiToUnicode( const QByteArray& ba, uint* len )
/*!
\overload
This utility function converts the '\0'-terminated 8-bit string \a
str to Unicode, returning the result and setting \a *len to the
length of the Unicode string.
The caller is responsible for deleting the return value with
delete[].
*/
-QChar* QString::asciiToUnicode( const char *str, uint* len, uint maxlen )
+QChar* QString::latin1ToUnicode( const char *str, uint* len, uint maxlen )
{
QChar* result = 0;
uint l = 0;
if ( str ) {
if ( maxlen != (uint)-1 ) {
while ( l < maxlen && str[l] )
l++;
} else {
// Faster?
- l = qstrlen(str);
+ l = strlen( str );
}
QChar *uc = new QChar[ l ]; // Can't use macro since function is public
result = uc;
uint i = l;
while ( i-- )
*uc++ = *str++;
}
if ( len )
*len = l;
return result;
}
-static QChar* internalAsciiToUnicode( const char *str, uint* len,
+static QChar* internalLatin1ToUnicode( const char *str, uint* len,
uint maxlen = (uint)-1 )
{
QChar* result = 0;
uint l = 0;
if ( str ) {
if ( maxlen != (uint)-1 ) {
while ( l < maxlen && str[l] )
l++;
} else {
// Faster?
- l = qstrlen(str);
+ l = strlen( str );
}
QChar *uc = QT_ALLOC_QCHAR_VEC( l );
result = uc;
uint i = l;
while ( i-- )
*uc++ = *str++;
}
if ( len )
*len = l;
return result;
}
/*!
This utility function converts \a l 16-bit characters from \a uc
to ASCII, returning a '\0'-terminated string.
The caller is responsible for deleting the resultant string with
delete[].
*/
-char* QString::unicodeToAscii(const QChar *uc, uint l)
+char* QString::unicodeToLatin1(const QChar *uc, uint l)
{
if (!uc) {
return 0;
}
char *a = new char[l+1];
char *result = a;
while (l--) {
*a++ = (uc->unicode() > 0xff) ? '?' : (char)uc->unicode();
uc++;
}
*a = '\0';
return result;
@@ -13148,53 +13154,24 @@ QT_STATIC_CONST_IMPL QChar QChar::byteOrderSwapped((ushort)0xfffe);
QT_STATIC_CONST_IMPL QChar QChar::nbsp((ushort)0x00a0);
QStringData* QString::makeSharedNull()
{
QString::shared_null = new QStringData;
#if defined( Q_OS_MAC )
QString *that = const_cast<QString *>(&QString::null);
that->d = QString::shared_null;
#endif
return QString::shared_null;
}
-// Uncomment this to get some useful statistics.
-// #define Q2HELPER(x) x
-
-#ifdef Q2HELPER
-static int stat_construct_charstar=0;
-static int stat_construct_charstar_size=0;
-static int stat_construct_null=0;
-static int stat_construct_int=0;
-static int stat_construct_int_size=0;
-static int stat_construct_ba=0;
-static int stat_get_ascii=0;
-static int stat_get_ascii_size=0;
-static int stat_copy_on_write=0;
-static int stat_copy_on_write_size=0;
-static int stat_fast_copy=0;
-Q_EXPORT void qt_qstring_stats()
-{
- qDebug("construct_charstar = %d (%d chars)", stat_construct_charstar, stat_construct_charstar_size);
- qDebug("construct_null = %d", stat_construct_null);
- qDebug("construct_int = %d (%d chars)", stat_construct_int, stat_construct_int_size);
- qDebug("construct_ba = %d", stat_construct_ba);
- qDebug("get_ascii = %d (%d chars)", stat_get_ascii, stat_get_ascii_size);
- qDebug("copy_on_write = %d (%d chars)", stat_copy_on_write, stat_copy_on_write_size);
- qDebug("fast_copy = %d", stat_fast_copy);
-}
-#else
-#define Q2HELPER(x)
-#endif
-
/*!
\fn QString::QString()
Constructs a null string, i.e. both the length and data pointer
are 0.
\sa isNull()
*/
/*!
Constructs a string of length one, containing the character \a ch.
*/
@@ -13202,65 +13179,67 @@ QString::QString( QChar ch )
{
d = new QStringData( QT_ALLOC_QCHAR_VEC( 1 ), 1, 1 );
d->unicode[0] = ch;
}
/*!
Constructs an implicitly shared copy of \a s. This is very fast
since it only involves incrementing a reference count.
*/
QString::QString( const QString &s ) :
d(s.d)
{
- Q2HELPER(stat_fast_copy++)
d->ref();
}
/*!
\internal
Private function.
Constructs a string with preallocated space for \a size characters.
The string is empty.
\sa isNull()
*/
QString::QString( int size, bool /*dummy*/ )
{
if ( size ) {
- Q2HELPER(stat_construct_int++)
int l = size;
- Q2HELPER(stat_construct_int_size+=l)
QChar* uc = QT_ALLOC_QCHAR_VEC( l );
d = new QStringData( uc, 0, l );
} else {
- Q2HELPER(stat_construct_null++)
d = shared_null ? shared_null : (shared_null=new QStringData);
d->ref();
}
}
/*!
Constructs a string that is a deep copy of \a ba interpreted as a
classic C string.
*/
QString::QString( const QByteArray& ba )
{
- Q2HELPER(stat_construct_ba++)
+#ifndef QT_NO_TEXTCODEC
+ if ( QTextCodec::codecForCStrings() ) {
+ d = 0;
+ *this = fromAscii( ba.data(), ba.size() );
+ return;
+ }
+#endif
uint l;
- QChar *uc = internalAsciiToUnicode(ba,&l);
+ QChar *uc = internalLatin1ToUnicode(ba,&l);
d = new QStringData(uc,l,l);
}
/*!
Constructs a string that is a deep copy of the first \a length
characters in the QChar array.
If \a unicode and \a length are 0, then a null string is created.
If only \a unicode is 0, the string is empty but has \a length
characters of space preallocated: QString expands automatically
anyway, but this may speed up some cases a little. We recommend
@@ -13293,30 +13272,57 @@ QString::QString( const QChar* unicode, uint length )
Latin1 const char* to QString preserves all the information. You
can disable this constructor by defining \c QT_NO_CAST_ASCII when
you compile your applications. You can also make QString objects
by using setLatin1(), fromLatin1(), fromLocal8Bit(), and
fromUtf8(). Or whatever encoding is appropriate for the 8-bit data
you have.
\sa isNull()
*/
QString::QString( const char *str )
{
- Q2HELPER(stat_construct_charstar++)
+#ifndef QT_NO_TEXTCODEC
+ if ( QTextCodec::codecForCStrings() ) {
+ d = 0;
+ *this = fromAscii( str );
+ return;
+ }
+#endif
+ uint l;
+ QChar *uc = internalLatin1ToUnicode(str,&l);
+ d = new QStringData(uc,l,l);
+}
+
+#ifndef QT_NO_STL
+/*!
+ Constructs a string that is a deep copy of \a str.
+
+ This is the same as fromAscii(\a str).
+*/
+
+QString::QString( const std::string &str )
+{
+#ifndef QT_NO_TEXTCODEC
+ if ( QTextCodec::codecForCStrings() ) {
+ d = 0;
+ *this = fromAscii( str.c_str() );
+ return;
+ }
+#endif
uint l;
- QChar *uc = internalAsciiToUnicode(str,&l);
- Q2HELPER(stat_construct_charstar_size+=l)
+ QChar *uc = internalLatin1ToUnicode(str.c_str(),&l);
d = new QStringData(uc,l,l);
}
+#endif
/*!
\fn QString::~QString()
Destroys the string and frees the string's data if this is the
last reference to the string.
*/
/*!
Deallocates any space reserved solely by this QString.
@@ -13324,91 +13330,99 @@ QString::QString( const char *str )
instance, nothing happens; otherwise the function creates a new,
unique copy of this string. This function is called whenever the
string is modified.
*/
void QString::real_detach()
{
setLength( length() );
}
void QString::deref()
{
- if ( d->deref() ) {
+ if ( d && d->deref() ) {
if ( d != shared_null )
delete d;
- d = 0; // helps debugging
+ d = 0;
}
}
void QStringData::deleteSelf()
{
delete this;
}
/*!
\fn QString& QString::operator=( QChar c )
Sets the string to contain just the single character \a c.
*/
/*!
+ \fn QString& QString::operator=( const std::string& s )
+
+ \overload
+
+ Makes a deep copy of \a s and returns a reference to the deep
+ copy.
+*/
+
+/*!
\fn QString& QString::operator=( char c )
\overload
Sets the string to contain just the single character \a c.
*/
/*!
\overload
Assigns a shallow copy of \a s to this string and returns a
reference to this string. This is very fast because the string
isn't actually copied.
*/
QString &QString::operator=( const QString &s )
{
- Q2HELPER(stat_fast_copy++)
s.d->ref();
deref();
d = s.d;
return *this;
}
/*!
\overload
Assigns a deep copy of \a cs, interpreted as a classic C string,
to this string and returns a reference to this string.
*/
QString &QString::operator=( const QCString& cs )
{
- return setLatin1(cs);
+ return setAscii(cs);
}
/*!
\overload
Assigns a deep copy of \a str, interpreted as a classic C string
to this string and returns a reference to this string.
If \a str is 0, then a null string is created.
\sa isNull()
*/
QString &QString::operator=( const char *str )
{
- return setLatin1(str);
+ return setAscii(str);
}
/*!
\fn bool QString::isNull() const
Returns TRUE if the string is null; otherwise returns FALSE. A
null string is always empty.
\code
QString a; // a.unicode() == 0, a.length() == 0
a.isNull(); // TRUE, because a.unicode() == 0
@@ -13462,98 +13476,94 @@ QString &QString::operator=( const char *str )
void QString::truncate( uint newLen )
{
if ( newLen < d->len )
setLength( newLen );
}
/*!
Ensures that at least \a newLen characters are allocated to the
string, and sets the length of the string to \a newLen. Any new
space allocated contains arbitrary data.
- If \a newLen is 0, then the string becomes empty, unless the
- string is null, in which case it remains null.
+ If \a newLen is 0, then the string becomes empty (non-null).
If it is not possible to allocate enough memory, the string
remains unchanged.
This function always detaches the string from other references to
the same data.
This function is useful for code that needs to build up a long
string and wants to avoid repeated reallocation. In this example,
we want to add to the string until some condition is true, and
we're fairly sure that size is big enough:
\code
QString result;
- int resultLength = 0;
- result.setLength( newLen ) // allocate some space
+ int len = 0;
+ result.setLength( maxLen ); // allocate some space
while ( ... ) {
- result[resultLength++] = ... // fill (part of) the space with data
+ result[len++] = ... // fill part of the space
}
- result.truncate[resultLength]; // and get rid of the undefined junk
+ result.truncate( len ); // and get rid of the rest
\endcode
If \a newLen is an underestimate, the worst that will happen is
that the loop will slow down.
\sa truncate(), isNull(), isEmpty(), length()
*/
void QString::setLength( uint newLen )
{
if ( d->count != 1 || newLen > d->maxl ||
( newLen * 4 < d->maxl && d->maxl > 4 ) ) {
// detach, grow or shrink
- Q2HELPER(stat_copy_on_write++)
- Q2HELPER(stat_copy_on_write_size+=d->len)
uint newMax = computeNewMax( newLen );
QChar* nd = QT_ALLOC_QCHAR_VEC( newMax );
if ( nd ) {
uint len = QMIN( d->len, newLen );
if ( d->unicode )
memcpy( nd, d->unicode, sizeof(QChar)*len );
deref();
d = new QStringData( nd, newLen, newMax );
}
} else {
d->len = newLen;
d->setDirty();
}
}
/*!
This function will return a string that replaces the lowest
numbered occurrence of \c %1, \c %2, ..., \c %9 with \a a.
The \a fieldwidth value specifies the minimum amount of space that
\a a is padded to. A positive value will produce right-aligned
text, whereas a negative value will produce left-aligned text.
+ The following example shows how we could create a 'status' string
+ when processing a list of files:
\code
- QString firstName( "Joe" );
- QString lastName( "Bloggs" );
- QString fullName;
- fullName = QString( "First name is '%1', last name is '%2'" )
- .arg( firstName )
- .arg( lastName );
-
- // fullName == First name is 'Joe', last name is 'Bloggs'
+ QString status = QString( "Processing file %1 of %2: %3" )
+ .arg( i ) // current file's number
+ .arg( total ) // number of files to process
+ .arg( fileName ); // current file's name
\endcode
- Note that using arg() to construct sentences as we've done in the
- example above does not usually translate well into other languages
- because sentence structure and word order often differ between
- languages.
+ It is generally fine to use filenames and numbers as we have done
+ in the example above. But note that using arg() to construct
+ natural language sentences does not usually translate well into
+ other languages because sentence structure and word order often
+ differ between languages.
If there is no place marker (\c %1 or \c %2, etc.), a warning
message (qWarning()) is output and the text is appended at the
end of the string. We recommend that the correct number of place
markers is always used in production code.
*/
QString QString::arg( const QString& a, int fieldwidth ) const
{
int pos, len;
QString r = *this;
if ( !findArg( pos, len ) ) {
@@ -13765,25 +13775,25 @@ bool QString::findArg( int& pos, int& len ) const
#ifndef QT_NO_SPRINTF
QString &QString::sprintf( const char* cformat, ... )
{
va_list ap;
va_start( ap, cformat );
if ( !cformat || !*cformat ) {
// Qt 1.x compat
*this = fromLatin1( "" );
return *this;
}
- QString format = fromLatin1( cformat );
+ QString format = fromAscii( cformat );
QRegExp escape( "%#?0?-? ?\\+?'?[0-9*]*\\.?[0-9*]*h?l?L?q?Z?" );
QString result;
uint last = 0;
int pos;
int len = 0;
for (;;) {
pos = escape.search( format, last );
len = escape.matchedLength();
// Non-escaped text
if ( pos > (int)last )
@@ -13904,25 +13914,25 @@ QString &QString::sprintf( const char* cformat, ... )
switch ( params ) {
case 0:
::sprintf( out, in, value );
break;
case 1:
::sprintf( out, in, width, value );
break;
case 2:
::sprintf( out, in, width, decimals, value );
}
}
}
- replacement = fromLatin1( out );
+ replacement = fromAscii( out );
}
result += replacement;
}
*this = result;
va_end( ap );
return *this;
}
#endif
/*!
Fills the string with \a len characters of value \a c, and returns
@@ -14115,26 +14125,28 @@ static int bm_find( const QString &str, int index, const QString &pattern, uint
int QString::find( const QString& str, int index, bool cs ) const
{
const uint l = length();
const uint sl = str.length();
if ( index < 0 )
index += l;
if ( sl + index > l )
return -1;
if ( !sl )
return index;
+#ifndef MACOSX_101
if ( sl == 1 )
return find( *str.unicode(), index, cs );
+#endif
// we use the Boyer-Moore algorithm in cases where the overhead
// for the hash table should pay off, otherwise we use a simple
// hash function
if ( l > 500 && sl > 5 ) {
uint skiptable[0x100];
bm_init_skiptable( str, skiptable, cs );
return bm_find( *this, index, str, skiptable, cs );
}
/*
We use some hashing for efficiency's sake. Instead of
@@ -14212,40 +14224,44 @@ int QString::find( const QString& str, int index, bool cs ) const
If \a cs is TRUE, the search is case sensitive; otherwise the
search is case insensitive.
\code
QString string( "bananas" );
int i = string.findRev( 'a' ); // i == 5
\endcode
*/
int QString::findRev( QChar c, int index, bool cs ) const
{
+#ifdef MACOSX_101
+ return findRev( QString( c ), index, cs );
+#else
const uint l = length();
if ( index < 0 )
index += l;
if ( (uint)index >= l )
return -1;
const QChar *end = unicode();
register const QChar *uc = end + index;
if ( cs ) {
while ( uc >= end && *uc != c )
uc--;
} else {
c = ::lower( c );
while ( uc >= end && ::lower( *uc ) != c )
uc--;
}
return uc - end;
+#endif
}
/*!
\overload
Finds the first occurrence of the string \a str, starting at
position \a index and searching backwards. If the index is -1, the
search starts at the last character, if it is -2, at the next to
last character and so on.
Returns the position of \a str or -1 if \a str could not be found.
@@ -14264,26 +14280,28 @@ int QString::findRev( const QString& str, int index, bool cs ) const
See QString::find() for explanations.
*/
const uint l = length();
if ( index < 0 )
index += l;
const uint sl = str.length();
int delta = l-sl;
if ( index < 0 || index > (int)l || delta < 0 )
return -1;
if ( index > delta )
index = delta;
+#ifndef MACOSX_101
if ( sl == 1 )
return findRev( *str.unicode(), index, cs );
+#endif
const QChar* needle = str.unicode();
const QChar* haystack = unicode() + index;
const QChar* end = unicode();
const uint sl_minus_1 = sl-1;
const QChar* n = needle+sl_minus_1;
const QChar* h = haystack+sl_minus_1;
uint hashNeedle = 0, hashHaystack = 0, i;
if ( cs ) {
for ( i = 0; i < sl; ++i ) {
hashNeedle = ((hashNeedle<<1) + (n-i)->unicode() );
@@ -14970,65 +14988,75 @@ QString QString::rightJustify( uint width, QChar fill, bool truncate ) const
Returns a lowercase copy of the string.
\code
QString string( "TROlltECH" );
str = string.lower(); // str == "trolltech"
\endcode
\sa upper()
*/
QString QString::lower() const
{
- QString s(*this);
- int l=length();
- if ( l ) {
- s.real_detach(); // could do this only when we find a change
- register QChar *p=s.d->unicode;
- if ( p ) {
- while ( l-- ) {
+ int l = length();
+ register QChar *p = d->unicode;
+ while ( l ) {
+ if ( *p != ::lower(*p) ) {
+ QString s( *this );
+ s.real_detach();
+ p = s.d->unicode + ( p - d->unicode );
+ while ( l ) {
*p = ::lower( *p );
+ l--;
p++;
}
+ return s;
}
+ l--;
+ p++;
}
- return s;
+ return *this;
}
/*!
Returns an uppercase copy of the string.
\code
QString string( "TeXt" );
str = string.upper(); // t == "TEXT"
\endcode
\sa lower()
*/
QString QString::upper() const
{
- QString s(*this);
- int l=length();
- if ( l ) {
- s.real_detach(); // could do this only when we find a change
- register QChar *p=s.d->unicode;
- if ( p ) {
- while ( l-- ) {
+ int l = length();
+ register QChar *p = d->unicode;
+ while ( l ) {
+ if ( *p != ::upper(*p) ) {
+ QString s( *this );
+ s.real_detach();
+ p = s.d->unicode + ( p - d->unicode );
+ while ( l ) {
*p = ::upper( *p );
+ l--;
p++;
}
+ return s;
}
+ l--;
+ p++;
}
- return s;
+ return *this;
}
/*!
Returns a string that has whitespace removed from the start and
the end.
Whitespace means any character for which QChar::isSpace() returns
TRUE. This includes Unicode characters with decimal values 9
(TAB), 10 (LF), 11 (VT), 12 (FF), 13 (CR) and 32 (Space), and may
also include other Unicode characters.
@@ -15128,26 +15156,26 @@ QString QString::simplifyWhiteSpace() const
\sa remove(), replace()
*/
QString &QString::insert( uint index, const QString &s )
{
// the sub function takes care of &s == this case.
return insert( index, s.unicode(), s.length() );
}
/*!
\overload
- Inserts the character in \a s into the string at position \a index
- \a len number of times and returns a reference to the string.
+ Inserts the first \a len characters in \a s into the string at
+ position \a index and returns a reference to the string.
*/
QString &QString::insert( uint index, const QChar* s, uint len )
{
if ( len == 0 )
return *this;
uint olen = length();
int nlen = olen + len;
if ( s >= d->unicode && (uint)(s - d->unicode) < d->maxl ) {
// Part of me - take a copy.
QChar *tmp = QT_ALLOC_QCHAR_VEC( len );
@@ -15242,24 +15270,34 @@ QString &QString::insert( uint index, QChar c ) // insert char
*/
/*! \fn QString& QString::prepend( const QByteArray &s )
\overload
Inserts \a s at the beginning of the string and returns a reference to the string.
Equivalent to insert(0, \a s).
\sa insert()
*/
+/*! \fn QString& QString::prepend( const std::string &s )
+ \overload
+
+ Inserts \a s at the beginning of the string and returns a reference to the string.
+
+ Equivalent to insert(0, \a s).
+
+ \sa insert()
+ */
+
/*!
\overload
Inserts \a s at the beginning of the string and returns a reference to the string.
Equivalent to insert(0, \a s).
\sa insert()
*/
QString &QString::prepend( const char *s )
{
return insert( 0, QString(s) );
@@ -15839,27 +15877,27 @@ static bool ok_in_base( QChar c, int base )
Returns the string converted to a \c long value to the base \a
base, which is 10 by default and must be between 2 and 36.
If \a ok is not 0: if a conversion error occurs, \a *ok is set to
FALSE; otherwise \a *ok is set to TRUE.
\sa number()
*/
long QString::toLong( bool *ok, int base ) const
{
const QChar *p = unicode();
- long val = 0;
+ ulong val = 0;
int l = length();
- const long max_mult = INT_MAX / base;
+ const ulong max_mult = LONG_MAX / base;
bool is_ok = FALSE;
int neg = 0;
if ( !p )
goto bye;
while ( l && p->isSpace() ) // skip leading space
l--,p++;
if ( !l )
goto bye;
if ( *p == '-' ) {
l--;
p++;
neg = 1;
@@ -15874,82 +15912,80 @@ long QString::toLong( bool *ok, int base ) const
while ( l && ok_in_base(*p,base) ) {
l--;
int dv;
if ( p->isDigit() ) {
dv = p->digitValue();
} else {
if ( *p >= 'a' && *p <= 'z' )
dv = *p - 'a' + 10;
else
dv = *p - 'A' + 10;
}
if ( val > max_mult ||
- (val == max_mult && dv > (INT_MAX % base) + neg) )
+ (val == max_mult && dv > (LONG_MAX % base) + neg) )
goto bye;
val = base * val + dv;
p++;
}
- if ( neg )
- val = -val;
while ( l && p->isSpace() ) // skip trailing space
- l--,p++;
+ l--, p++;
if ( !l )
is_ok = TRUE;
bye:
if ( ok )
*ok = is_ok;
- return is_ok ? val : 0;
+ return is_ok ? ( neg ? -( (long) val ) : (long) val ) : 0L;
}
/*!
Returns the string converted to an \c {unsigned long} value to the
base \a base, which is 10 by default and must be between 2 and 36.
If \a ok is not 0: if a conversion error occurs, \a *ok is set to
FALSE; otherwise \a *ok is set to TRUE.
\sa number()
*/
ulong QString::toULong( bool *ok, int base ) const
{
const QChar *p = unicode();
ulong val = 0;
int l = length();
- const ulong max_mult = UINT_MAX / base;
+ const ulong max_mult = ULONG_MAX / base;
bool is_ok = FALSE;
if ( !p )
goto bye;
while ( l && p->isSpace() ) // skip leading space
l--,p++;
if ( !l )
goto bye;
if ( *p == '+' )
l--,p++;
// NOTE: toLong() code is similar
if ( !l || !ok_in_base(*p,base) )
goto bye;
while ( l && ok_in_base(*p,base) ) {
l--;
uint dv;
if ( p->isDigit() ) {
dv = p->digitValue();
} else {
if ( *p >= 'a' && *p <= 'z' )
dv = *p - 'a' + 10;
else
dv = *p - 'A' + 10;
}
- if ( val > max_mult || (val == max_mult && dv > UINT_MAX % base) )
+ if ( val > max_mult || (val == max_mult && dv > ULONG_MAX % base) )
goto bye;
val = base * val + dv;
p++;
}
while ( l && p->isSpace() ) // skip trailing space
l--,p++;
if ( !l )
is_ok = TRUE;
bye:
if ( ok )
*ok = is_ok;
@@ -15958,44 +15994,44 @@ bye:
/*!
Returns the string converted to a \c short value to the base \a
base, which is 10 by default and must be between 2 and 36.
If \a ok is not 0: if a conversion error occurs, \a *ok is set to
FALSE; otherwise \a *ok is set to TRUE.
*/
short QString::toShort( bool *ok, int base ) const
{
long v = toLong( ok, base );
- if ( ok && *ok && (v < -32768 || v > 32767) ) {
+ if ( ok && *ok && (v < SHRT_MIN || v > SHRT_MAX) ) {
*ok = FALSE;
v = 0;
}
return (short)v;
}
/*!
Returns the string converted to an \c {unsigned short} value to
the base \a base, which is 10 by default and must be between 2 and
36.
If \a ok is not 0: if a conversion error occurs, \a *ok is set to
FALSE; otherwise \a *ok is set to TRUE.
*/
ushort QString::toUShort( bool *ok, int base ) const
{
ulong v = toULong( ok, base );
- if ( ok && *ok && (v > 65535) ) {
+ if ( ok && *ok && (v > USHRT_MAX) ) {
*ok = FALSE;
v = 0;
}
return (ushort)v;
}
/*!
Returns the string converted to an \c int value to the base \a
base, which is 10 by default and must be between 2 and 36.
If \a ok is not 0: if a conversion error occurs, \a *ok is set to
@@ -16004,64 +16040,74 @@ ushort QString::toUShort( bool *ok, int base ) const
\code
QString str( "FF" );
bool ok;
int hex = str.toInt( &ok, 16 ); // hex == 255, ok == TRUE
int dec = str.toInt( &ok, 10 ); // dec == 0, ok == FALSE
\endcode
\sa number()
*/
int QString::toInt( bool *ok, int base ) const
{
- return (int)toLong( ok, base );
+ long v = toLong( ok, base );
+ if ( ok && *ok && (v < INT_MIN || v > INT_MAX) ) {
+ *ok = FALSE;
+ v = 0;
+ }
+ return (int)v;
}
/*!
Returns the string converted to an \c{unsigned int} value to the
base \a base, which is 10 by default and must be between 2 and 36.
If \a ok is not 0: if a conversion error occurs, \a *ok is set to
FALSE; otherwise \a *ok is set to TRUE.
\sa number()
*/
uint QString::toUInt( bool *ok, int base ) const
{
- return (uint)toULong( ok, base );
+ ulong v = toULong( ok, base );
+ if ( ok && *ok && (v > UINT_MAX) ) {
+ *ok = FALSE;
+ v = 0;
+ }
+ return (uint)v;
}
/*!
Returns the string converted to a \c double value.
If \a ok is not 0: if a conversion error occurs, \a *ok is set to
FALSE; otherwise \a *ok is set to TRUE.
\code
QString string( "1234.56" );
double a = string.toDouble(); // a == 1234.56
\endcode
\sa number()
*/
double QString::toDouble( bool *ok ) const
{
char *end;
const char *a = latin1();
double val = strtod( a ? a : "", &end );
if ( ok )
- *ok = ( a && *a && (end == 0 || (end - a) == (int)length()) );
+ *ok = ( a && *a && (end == 0 || *end == '\0') );
return val;
}
/*!
Returns the string converted to a \c float value.
If \a ok is not 0: if a conversion error occurs, \a *ok is set to
FALSE; otherwise \a *ok is set to TRUE.
\sa number()
*/
@@ -16089,29 +16135,29 @@ QString &QString::setNum( long n, int base )
if ( base < 2 || base > 36 ) {
qWarning( "QString::setNum: Invalid base %d", base );
base = 10;
}
#endif
char charbuf[65*sizeof(QChar)];
QChar *buf = (QChar*)charbuf;
QChar *p = &buf[64];
int len = 0;
bool neg;
if ( n < 0 ) {
neg = TRUE;
- if ( n == INT_MIN ) {
+ if ( n == LONG_MIN ) {
// Cannot always negate this special case
QString s1, s2;
- s1.setNum(n/base);
- s2.setNum((-(n+base))%base);
+ s1.setNum(n/base, base );
+ s2.setNum((-(n+base))%base, base );
*this = s1 + s2;
return *this;
}
n = -n;
} else {
neg = FALSE;
}
do {
*--p = "0123456789abcdefghijklmnopqrstuvwxyz"[((int)(n%base))];
n /= base;
++len;
} while ( n );
@@ -16452,24 +16498,33 @@ void QString::setExpand( uint index, QChar c )
Equivalent to operator+=().
*/
/*! \fn QString& QString::append( const QByteArray &str )
\overload
Appends \a str to the string and returns a reference to the result.
Equivalent to operator+=().
*/
+/*! \fn QString& QString::append( const std::string &str )
+ \overload
+
+ Appends \a str to the string and returns a reference to the result.
+
+ Equivalent to operator+=().
+ */
+
+
/*! \fn QString& QString::append( const char *str )
\overload
Appends \a str to the string and returns a reference to the result.
Equivalent to operator+=().
*/
/*!
Appends \a str to the string and returns a reference to the string.
*/
QString& QString::operator+=( const QString &str )
@@ -16481,122 +16536,158 @@ QString& QString::operator+=( const QString &str )
memcpy( d->unicode+len1, str.unicode(), sizeof(QChar)*len2 );
} else if ( isNull() && !str.isNull() ) { // ## just for 1.x compat:
*this = fromLatin1( "" );
}
return *this;
}
/*!
\overload
Appends \a str to the string and returns a reference to the string.
*/
+#ifndef QT_NO_CAST_ASCII
QString& QString::operator+=( const char *str )
{
if ( str ) {
+#ifndef QT_NO_TEXTCODEC
+ if ( QTextCodec::codecForCStrings() )
+ return operator+=( fromAscii( str ) );
+#endif
+
uint len1 = length();
uint len2 = strlen( str );
if ( len2 ) {
setLength(len1+len2);
uint i = 0;
while( i < len2 ) {
d->unicode[len1+i] = str[i];
i++;
}
} else if ( isNull() ) { // ## just for 1.x compat:
*this = fromLatin1( "" );
}
}
return *this;
}
+#endif
/*! \overload
Appends \a c to the string and returns a reference to the string.
*/
QString &QString::operator+=( QChar c )
{
setLength(length()+1);
d->unicode[length()-1] = c;
return *this;
}
/*!
\overload
Appends \a c to the string and returns a reference to the string.
*/
QString &QString::operator+=( char c )
{
+#ifndef QT_NO_TEXTCODEC
+ if ( QTextCodec::codecForCStrings() )
+ return operator+=( fromAscii( &c, 1 ) );
+#endif
setLength(length()+1);
d->unicode[length()-1] = c;
return *this;
}
/*!
\fn QString &QString::operator+=( const QByteArray &str )
\overload
Appends \a str to the string and returns a reference to the string.
*/
+/*!
+ \fn QString &QString::operator+=( const std::string &str )
+ \overload
+
+ Appends \a str to the string and returns a reference to the string.
+*/
+
/*!
\fn char QChar::latin1() const
- Returns a latin-1 copy of this character, if this character is in
- the latin-1 character set. If not, this function returns 0.
+ Returns the Latin-1 value of this character, or 0 if it
+ cannot be represented in Latin-1.
*/
/*!
- Returns a Latin-1 representation of the string. Note that the
+ Returns a Latin-1 representation of the string. The
returned value is undefined if the string contains non-Latin-1
characters. If you want to convert strings into formats other than
Unicode, see the QTextCodec classes.
This function is mainly useful for boot-strapping legacy code to
use Unicode.
The result remains valid so long as one unmodified copy of the
source string exists.
- \sa utf8(), local8Bit()
+ \sa fromLatin1(), ascii(), utf8(), local8Bit()
*/
const char* QString::latin1() const
{
- if ( !d->ascii ) {
- Q2HELPER(stat_get_ascii++)
- Q2HELPER(stat_get_ascii_size+=d->len)
- d->ascii = unicodeToAscii( d->unicode, d->len );
+ if ( !d->ascii || !d->islatin1 ) {
+ d->ascii = unicodeToLatin1( d->unicode, d->len );
+ d->islatin1 = TRUE;
}
return d->ascii;
}
/*!
- \fn const char* QString::ascii() const
- \obsolete
+ Returns an 8-bit ASCII representation of the string.
- This function simply calls latin1() and returns the result.
+ If a codec has been set using QTextCodec::codecForCStrings(),
+ it is used to convert Unicode to 8-bit char. Otherwise, this function
+ does the same as latin1().
+
+ \sa fromAscii(), latin1(), utf8(), local8Bit()
*/
+const char* QString::ascii() const
+{
+#ifndef QT_NO_TEXTCODEC
+ if ( QTextCodec::codecForCStrings() ) {
+ if ( !d->ascii || d->islatin1 ) {
+ QCString s = QTextCodec::codecForCStrings()->fromUnicode( *this );
+ s.detach();
+ d->ascii = s.data();
+ d->islatin1 = FALSE;
+ s.resetRawData( s.data(), s.size() ); // we have stolen the data
+ }
+ return d->ascii;
+ }
+#endif // QT_NO_TEXTCODEC
+ return latin1();
+}
/*!
- Returns the string encoded in UTF8 format.
+ Returns the string encoded in UTF-8 format.
See QTextCodec for more diverse coding/decoding of Unicode strings.
- \sa QString::fromUtf8(), local8Bit(), latin1()
+ \sa fromUtf8(), ascii(), latin1(), local8Bit()
*/
QCString QString::utf8() const
{
int l = length();
int rlen = l*3+1;
QCString rstr(rlen);
uchar* cursor = (uchar*)rstr.data();
const QChar *ch = d->unicode;
for (int i=0; i<l; i++) {
ushort u = ch->unicode();
if ( u < 0x80 ) {
*cursor++ = (uchar)u;
@@ -16624,25 +16715,26 @@ QCString QString::utf8() const
\code
QString str = QString::fromUtf8( "123456789", 5 );
// str == "12345"
\endcode
See QTextCodec for more diverse coding/decoding of Unicode strings.
*/
QString QString::fromUtf8( const char* utf8, int len )
{
if ( !utf8 )
return QString::null;
- if ( len < 0 ) len = qstrlen( utf8 );
+ if ( len < 0 )
+ len = strlen( utf8 );
QString result;
result.setLength( len ); // worst case
QChar *qch = (QChar *)result.unicode();
ushort uc = 0;
int need = 0;
for (int i=0; i<len; i++) {
uchar ch = utf8[i];
if (need) {
if ( (ch&0xc0) == 0x80 ) {
uc = (uc << 6) | (ch & 0x3f);
need--;
if ( !need ) {
@@ -16665,91 +16757,120 @@ QString QString::fromUtf8( const char* utf8, int len )
} else if ( (ch&0xf0) == 0xe0 ) {
uc = ch &0x0f;
need = 2;
}
}
}
result.truncate( qch - result.unicode() );
return result;
}
/*!
Returns the Unicode string decoded from the first \a len
- characters of \a chars, ignoring the rest of \a chars. If \a len
- is -1 then the length of \a chars is used. If \a len is bigger
- than the length of \a chars then it will use the length of \a
- chars.
+ characters of \a ascii, ignoring the rest of \a ascii. If \a len
+ is -1 then the length of \a ascii is used. If \a len is bigger
+ than the length of \a ascii then it will use the length of \a
+ ascii.
+
+ If a codec has been set using QTextCodec::codecForCStrings(),
+ it is used to convert Unicode to 8-bit char. Otherwise, this function
+ does the same as fromLatin1().
This is the same as the QString(const char*) constructor, but you
can make that constructor invisible if you compile with the define
\c QT_NO_CAST_ASCII, in which case you can explicitly create a
- QString from Latin-1 text using this function.
+ QString from 8-bit ASCII text using this function.
\code
- QString str = QString::fromLatin1( "123456789", 5 );
+ QString str = QString::fromAscii( "123456789", 5 );
// str == "12345"
\endcode
+ */
+QString QString::fromAscii( const char* ascii, int len )
+{
+#ifndef QT_NO_TEXTCODEC
+ if ( QTextCodec::codecForCStrings() ) {
+ if ( !ascii )
+ return QString::null;
+ if ( len < 0 )
+ len = strlen( ascii );
+ if ( len == 0 || *ascii == '\0' )
+ return QString::fromLatin1( "" );
+ return QTextCodec::codecForCStrings()->toUnicode( ascii, len );
+ }
+#endif
+ return fromLatin1( ascii, len );
+}
+
+
+/*!
+ Returns the Unicode string decoded from the first \a len
+ characters of \a chars, ignoring the rest of \a chars. If \a len
+ is -1 then the length of \a chars is used. If \a len is bigger
+ than the length of \a chars then it will use the length of \a
+ chars.
+
+ \sa fromAscii()
*/
QString QString::fromLatin1( const char* chars, int len )
{
uint l;
QChar *uc;
if ( len < 0 )
len = -1;
- uc = internalAsciiToUnicode( chars, &l, len );
+ uc = internalLatin1ToUnicode( chars, &l, len );
return QString( new QStringData(uc, l, l), TRUE );
}
/*!
\fn const QChar* QString::unicode() const
Returns the Unicode representation of the string. The result
remains valid until the string is modified.
*/
/*!
Returns the string encoded in a locale-specific format. On X11,
this is the QTextCodec::codecForLocale(). On Windows, it is a
- system-defined encoding. On Mac OS X, this always uses utf8 as the
- encoding.
+ system-defined encoding. On Mac OS X, this always uses UTF-8 as
+ the encoding.
See QTextCodec for more diverse coding/decoding of Unicode
strings.
- \sa QString::fromLocal8Bit(), latin1(), utf8()
+ \sa fromLocal8Bit(), ascii(), latin1(), utf8()
*/
-
QCString QString::local8Bit() const
{
#ifdef QT_NO_TEXTCODEC
return latin1();
#else
#ifdef Q_WS_X11
QTextCodec* codec = QTextCodec::codecForLocale();
return codec
? codec->fromUnicode(*this)
: QCString(latin1());
#endif
#if defined( Q_WS_MACX )
return utf8();
#endif
#if defined( Q_WS_MAC9 )
return QCString(latin1()); //I'm evil..
#endif
#ifdef Q_WS_WIN
return qt_winQString2MB( *this );
#endif
#ifdef Q_WS_QWS
- return utf8(); // ##### if there is ANY 8 bit format supported?
+ return utf8(); // ### if there is any 8 bit format supported?
#endif
#endif
}
/*!
Returns the Unicode string decoded from the first \a len
characters of \a local8Bit, ignoring the rest of \a local8Bit. If
\a len is -1 then the length of \a local8Bit is used. If \a len is
bigger than the length of \a local8Bit then it will use the length
of \a local8Bit.
\code
@@ -16762,25 +16883,26 @@ QCString QString::local8Bit() const
See QTextCodec for more diverse coding/decoding of Unicode strings.
*/
QString QString::fromLocal8Bit( const char* local8Bit, int len )
{
#ifdef QT_NO_TEXTCODEC
return fromLatin1( local8Bit, len );
#else
if ( !local8Bit )
return QString::null;
#ifdef Q_WS_X11
QTextCodec* codec = QTextCodec::codecForLocale();
- if ( len < 0 ) len = qstrlen(local8Bit);
+ if ( len < 0 )
+ len = strlen( local8Bit );
return codec
? codec->toUnicode( local8Bit, len )
: fromLatin1( local8Bit, len );
#endif
#if defined( Q_WS_MAC )
return fromUtf8(local8Bit,len);
#endif
// Should this be OS_WIN32?
#ifdef Q_WS_WIN
if ( len >= 0 ) {
QCString s(local8Bit,len+1);
return qt_winMB2QString(s);
@@ -16795,41 +16917,45 @@ QString QString::fromLocal8Bit( const char* local8Bit, int len )
/*!
\fn QString::operator const char *() const
Returns latin1(). Be sure to see the warnings documented in the
latin1() function. Note that for new code which you wish to be
strictly Unicode-clean, you can define the macro \c
QT_NO_ASCII_CAST when compiling your code to hide this function so
that automatic casts are not done. This has the added advantage
that you catch the programming error described in operator!().
*/
+/*!
+ \fn QString::operator std::string() const
+
+ Returns ascii().
+*/
+
/*!
Returns the QString as a zero terminated array of unsigned shorts
if the string is not null; otherwise returns zero.
The result remains valid so long as one unmodified
copy of the source string exists.
*/
const unsigned short *QString::ucs2() const
{
if ( ! d->unicode )
return 0;
unsigned int len = d->len;
if ( d->maxl < len + 1 ) {
// detach, grow or shrink
- Q2HELPER(stat_copy_on_write++)
- Q2HELPER(stat_copy_on_write_size += len)
uint newMax = computeNewMax( len + 1 );
QChar* nd = QT_ALLOC_QCHAR_VEC( newMax );
if ( nd ) {
if ( d->unicode )
memcpy( nd, d->unicode, sizeof(QChar)*len );
((QString *)this)->deref();
((QString *)this)->d = new QStringData( nd, len, newMax );
}
}
d->unicode[len] = 0;
return (unsigned short *) d->unicode;
}
@@ -16974,26 +17100,24 @@ void QString::subat( uint i )
QString& QString::setUnicode( const QChar *unicode, uint len )
{
if ( len == 0 ) { // set to null string
if ( d != shared_null ) { // beware of nullstring being set to nullstring
deref();
d = shared_null ? shared_null : makeSharedNull();
d->ref();
}
} else if ( d->count != 1 || len > d->maxl ||
( len * 4 < d->maxl && d->maxl > 4 ) ) {
// detach, grown or shrink
- Q2HELPER(stat_copy_on_write++)
- Q2HELPER(stat_copy_on_write_size+=d->len)
uint newMax = computeNewMax( len );
QChar* nd = QT_ALLOC_QCHAR_VEC( newMax );
if ( unicode )
memcpy( nd, unicode, sizeof(QChar)*len );
deref();
d = new QStringData( nd, len, newMax );
} else {
d->len = len;
d->setDirty();
if ( unicode )
memcpy( d->unicode, unicode, sizeof(QChar)*len );
}
@@ -17009,67 +17133,89 @@ QString& QString::setUnicode( const QChar *unicode, uint len )
is still resized to \a len. If \a len is zero, the string becomes
a \link isNull() null\endlink string.
\sa setLatin1(), isNull()
*/
QString& QString::setUnicodeCodes( const ushort* unicode_as_ushorts, uint len )
{
return setUnicode((const QChar*)unicode_as_ushorts, len);
}
/*!
+ Sets this string to \a str, interpreted as a classic 8-bit ASCII C
+ string. If \a len is -1 (the default), then it is set to
+ strlen(str).
+
+ If \a str is 0 a null string is created. If \a str is "", an empty
+ string is created.
+
+ \sa isNull(), isEmpty()
+*/
+
+QString &QString::setAscii( const char *str, int len )
+{
+#ifndef QT_NO_TEXTCODEC
+ if ( QTextCodec::codecForCStrings() ) {
+ *this = QString::fromAscii( str, len );
+ return *this;
+ }
+#endif // QT_NO_TEXTCODEC
+ return setLatin1( str, len );
+}
+
+/*!
Sets this string to \a str, interpreted as a classic Latin1 C
string. If \a len is -1 (the default), then it is set to
strlen(str).
If \a str is 0 a null string is created. If \a str is "", an empty
string is created.
\sa isNull(), isEmpty()
*/
QString &QString::setLatin1( const char *str, int len )
{
if ( str == 0 )
return setUnicode(0,0);
if ( len < 0 )
- len = qstrlen(str);
+ len = strlen( str );
if ( len == 0 ) { // won't make a null string
*this = QString::fromLatin1( "" );
} else {
setUnicode( 0, len ); // resize but not copy
QChar *p = d->unicode;
while ( len-- )
*p++ = *str++;
}
return *this;
}
/*! \internal
*/
void QString::checkSimpleText() const
{
QChar *p = d->unicode;
QChar *end = p + d->len;
- d->simpletext = 1;
while( p < end ) {
ushort uc = p->unicode();
// sort out regions of complex text formatting
if ( uc > 0x058f && ( uc < 0x1100 || uc > 0xfb0f ) ) {
- d->simpletext = 0;
+ d->issimpletext = FALSE;
return;
}
p++;
}
+ d->issimpletext = TRUE;
}
/*! \fn bool QString::simpleText() const
\internal
*/
/*! \internal
*/
bool QString::isRightToLeft() const
{
int len = length();
QChar *p = d->unicode;
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
@@ -1080,25 +1080,25 @@ QTextStream &QTextStream::writeBlock( const QChar* p, uint len )
{
#ifndef QT_NO_TEXTCODEC
if ( mapper ) {
if ( !d->encoder )
d->encoder = mapper->makeEncoder();
QConstString s( p, len );
int l = len;
QCString block = d->encoder->fromUnicode( s.string(), l );
dev->writeBlock( block, l );
} else
#endif
if ( latin1 ) {
- char *str = QString::unicodeToAscii( p, len );
+ char *str = QString::unicodeToLatin1( p, len );
dev->writeBlock( str, len );
delete [] str;
} else if ( internalOrder ) {
if ( doUnicodeHeader ) {
doUnicodeHeader = FALSE;
ts_putc( QChar::byteOrderMark );
}
dev->writeBlock( (char*)p, sizeof(QChar)*len );
} else {
for (uint i=0; i<len; i++)
ts_putc( p[i] );
}
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
@@ -287,149 +287,96 @@ const QUuid TID_QUType_int( 0x53c1f3be, 0x73c3, 0x4c7d, 0x9e, 0x5, 0xcc, 0xf0, 0
QUType_int static_QUType_int;
const QUuid *QUType_int::uuid() const { return &TID_QUType_int; }
const char *QUType_int::desc() const { return "int"; }
void QUType_int::set( QUObject *o, int v )
{
o->payload.i = v;
o->type = this;
}
bool QUType_int::canConvertFrom( QUObject *o, QUType *t )
{
- if ( isEqual( t, &static_QUType_double ) ||
- isEqual( t, &static_QUType_float ) )
+ if ( isEqual( t, &static_QUType_double ) )
return TRUE;
return t->canConvertTo( o, this );
}
bool QUType_int::canConvertTo( QUObject * /*o*/, QUType *t )
{
- return isEqual( t, &static_QUType_double ) ||
- isEqual( t, &static_QUType_float );
+ return isEqual( t, &static_QUType_double );
}
bool QUType_int::convertFrom( QUObject *o, QUType *t )
{
if ( isEqual( t, &static_QUType_double ) )
o->payload.i = (long)o->payload.d;
- else if ( isEqual( t, &static_QUType_float ) )
- o->payload.i = (long)o->payload.f;
else
return t->convertTo( o, this );
o->type = this;
return TRUE;
}
bool QUType_int::convertTo( QUObject *o, QUType *t )
{
if ( isEqual( t, &static_QUType_double ) ) {
o->payload.d = (double)o->payload.i;
o->type = &static_QUType_double;
- } else if ( isEqual( t, &static_QUType_float ) ) {
- o->payload.f = (float)o->payload.i;
- o->type = &static_QUType_float;
} else
return FALSE;
return TRUE;
}
int QUType_int::serializeTo( QUObject *, QUBuffer * )
{
return 0;
}
int QUType_int::serializeFrom( QUObject *, QUBuffer * )
{
return 0;
}
-// {5938712A-C496-11D5-8CB2-00C0F03BC0F3}
-const QUuid TID_QUType_uint( 0x5938712a, 0xc496, 0x11d5, 0x8c, 0xb2, 0x00, 0xc0, 0xf0, 0x3b, 0xc0, 0xf3);
-QUType_uint static_QUType_uint;
-const QUuid *QUType_uint::uuid() const { return &TID_QUType_uint; }
-const char *QUType_uint::desc() const { return "uint"; }
-
-void QUType_uint::set( QUObject *o, uint v )
-{
- o->payload.ui = v;
- o->type = this;
-}
-
-bool QUType_uint::canConvertFrom( QUObject *o, QUType *t )
-{
- return t->canConvertTo( o, this );
-}
-
-bool QUType_uint::canConvertTo( QUObject * /*o*/, QUType * /*t*/ )
-{
- return FALSE;
-}
-
-bool QUType_uint::convertFrom( QUObject *o, QUType *t )
-{
- return t->convertTo( o, this );
-}
-
-bool QUType_uint::convertTo( QUObject * /*o*/, QUType * /*t*/ )
-{
- return FALSE;
-}
-
-int QUType_uint::serializeTo( QUObject *, QUBuffer * )
-{
- return 0;
-}
-
-int QUType_uint::serializeFrom( QUObject *, QUBuffer * )
-{
- return 0;
-}
-
// {2D0974E5-0BA6-4ec2-8837-C198972CB48C}
const QUuid TID_QUType_double( 0x2d0974e5, 0xba6, 0x4ec2, 0x88, 0x37, 0xc1, 0x98, 0x97, 0x2c, 0xb4, 0x8c );
QUType_double static_QUType_double;
const QUuid *QUType_double::uuid() const { return &TID_QUType_double; }
const char *QUType_double::desc() const {return "double"; }
void QUType_double::set( QUObject *o, double v )
{
o->payload.d = v;
o->type = this;
}
bool QUType_double::canConvertFrom( QUObject *o, QUType *t )
{
- if ( isEqual( t, &static_QUType_int ) ||
- isEqual( t, &static_QUType_float) )
+ if ( isEqual( t, &static_QUType_int ) )
return TRUE;
return t->canConvertTo( o, this );
}
bool QUType_double::canConvertTo( QUObject * /*o*/, QUType *t )
{
- return isEqual( t, &static_QUType_int ) ||
- isEqual( t, &static_QUType_float );
+ return isEqual( t, &static_QUType_int );
}
bool QUType_double::convertFrom( QUObject *o, QUType *t )
{
if ( isEqual( t, &static_QUType_int ) )
o->payload.d = (double)o->payload.i;
- else if ( isEqual( t, &static_QUType_float ) )
- o->payload.d = (double)o->payload.f;
- else
+ else
return t->convertTo( o, this );
o->type = this;
return TRUE;
}
bool QUType_double::convertTo( QUObject *o, QUType *t )
{
if ( isEqual( t, &static_QUType_int ) ) {
o->payload.i = (int) o->payload.d;
o->type = &static_QUType_int;
} else if ( isEqual( t, &static_QUType_double ) ) {
@@ -441,88 +388,24 @@ bool QUType_double::convertTo( QUObject *o, QUType *t )
}
int QUType_double::serializeTo( QUObject *, QUBuffer * )
{
return 0;
}
int QUType_double::serializeFrom( QUObject *, QUBuffer * )
{
return 0;
}
-
-// {544C5175-6993-4486-B04D-CEC4D21BF4B9 }
-const QUuid TID_QUType_float( 0x544c5175, 0x6993, 0x4486, 0xb0, 0x4d, 0xce, 0xc4, 0xd2, 0x1b, 0xf4, 0xb9 );
-QUType_float static_QUType_float;
-const QUuid *QUType_float::uuid() const { return &TID_QUType_float; }
-const char *QUType_float::desc() const {return "float"; }
-
-void QUType_float::set( QUObject *o, float v )
-{
- o->payload.f = v;
- o->type = this;
-}
-
-bool QUType_float::canConvertFrom( QUObject *o, QUType *t )
-{
- if ( isEqual( t, &static_QUType_int ) ||
- isEqual( t, &static_QUType_double ) )
- return TRUE;
-
- return t->canConvertTo( o, this );
-}
-
-bool QUType_float::canConvertTo( QUObject * /*o*/, QUType *t )
-{
- return isEqual( t, &static_QUType_int ) ||
- isEqual( t, &static_QUType_double );
-}
-
-bool QUType_float::convertFrom( QUObject *o, QUType *t )
-{
- if ( isEqual( t, &static_QUType_int ) )
- o->payload.f = (float)o->payload.i;
- else if ( isEqual( t, &static_QUType_double ) )
- o->payload.f = (float)o->payload.d;
- else
- return t->convertTo( o, this );
-
- o->type = this;
- return TRUE;
-}
-
-bool QUType_float::convertTo( QUObject *o, QUType *t )
-{
- if ( isEqual( t, &static_QUType_int ) ) {
- o->payload.i = (int) o->payload.f;
- o->type = &static_QUType_int;
- } else if ( isEqual( t, &static_QUType_double ) ) {
- o->payload.d = (double) o->payload.f;
- o->type = &static_QUType_double;
- } else
- return FALSE;
- return TRUE;
-}
-
-int QUType_float::serializeTo( QUObject *, QUBuffer * )
-{
- return 0;
-}
-
-int QUType_float::serializeFrom( QUObject *, QUBuffer * )
-{
- return 0;
-}
-
// {EFCDD1D4-77A3-4b8e-8D46-DC14B8D393E9}
const QUuid TID_QUType_charstar( 0xefcdd1d4, 0x77a3, 0x4b8e, 0x8d, 0x46, 0xdc, 0x14, 0xb8, 0xd3, 0x93, 0xe9 );
QUType_charstar static_QUType_charstar;
const QUuid *QUType_charstar::uuid() const { return &TID_QUType_charstar; }
const char *QUType_charstar::desc() const { return "char*"; }
void QUType_charstar::set( QUObject *o, const char* v, bool take )
{
if ( take ) {
if ( v ) {
o->payload.charstar.ptr = new char[ strlen(v) + 1 ];
strcpy( o->payload.charstar.ptr, v );
@@ -584,75 +467,68 @@ const QUuid *QUType_QString::uuid() const { return &TID_QUType_QString; }
const char *QUType_QString::desc() const { return "QString"; }
void QUType_QString::set( QUObject *o, const QString& v )
{
o->payload.ptr = new QString( v );
o->type = this;
}
bool QUType_QString::canConvertFrom( QUObject *o, QUType *t )
{
if ( isEqual( t, &static_QUType_charstar ) ||
isEqual( t, &static_QUType_double ) ||
- isEqual( t, &static_QUType_float ) ||
isEqual( t, &static_QUType_int ) )
return TRUE;
return t->canConvertTo( o, this );
}
bool QUType_QString::canConvertTo( QUObject * /*o*/, QUType *t )
{
return isEqual( t, &static_QUType_charstar ) ||
isEqual( t, &static_QUType_int ) ||
- isEqual( t, &static_QUType_double ) ||
- isEqual( t, &static_QUType_float );
+ isEqual( t, &static_QUType_double );
}
bool QUType_QString::convertFrom( QUObject *o, QUType *t )
{
QString *str = 0;
if ( isEqual( t, &static_QUType_charstar ) )
str = new QString( o->payload.charstar.ptr );
else if ( isEqual( t, &static_QUType_double ) )
str = new QString( QString::number( o->payload.d ) );
- else if ( isEqual( t, &static_QUType_float ) )
- str = new QString( QString::number( o->payload.f ) );
else if ( isEqual( t, &static_QUType_int ) )
str = new QString( QString::number( o->payload.i ) );
else
return t->convertTo( o, this );
o->type->clear( o );
o->payload.ptr = str;
o->type = this;
return TRUE;
}
bool QUType_QString::convertTo( QUObject *o, QUType *t )
{
QString *str = (QString *)o->payload.ptr;
if ( isEqual( t, &static_QUType_charstar ) ) {
o->payload.charstar.ptr = qstrdup( str->local8Bit().data() );
o->payload.charstar.owner = TRUE;
o->type = &static_QUType_charstar;
} else if ( isEqual( t, &static_QUType_int ) ) {
o->payload.l = str->toLong();
o->type = &static_QUType_int;
} else if ( isEqual( t, &static_QUType_double ) ) {
o->payload.d = str->toDouble();
o->type = &static_QUType_double;
- } else if ( isEqual( t, &static_QUType_float ) ) {
- o->payload.d = str->toFloat();
- o->type = &static_QUType_float;
} else {
return FALSE;
}
delete str;
return TRUE;
}
int QUType_QString::serializeTo( QUObject *, QUBuffer * )
{
return 0;
}
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
@@ -115,25 +115,25 @@ struct QWaitConditionPrivate {
mymutex.unlock();
do_something();
mymutex.lock();
mycount--;
mymutex.unlock();
}
// Key reading thread code
for (;;) {
getchar();
mymutex.lock();
// Sleep until there are no busy worker threads
- while( count > 0 ) {
+ while( mycount > 0 ) {
mymutex.unlock();
sleep( 1 );
mymutex.lock();
}
mymutex.unlock();
key_pressed.wakeAll();
}
\endcode
The mutexes are necessary because the results of two threads
attempting to change the value of the same variable simultaneously
are unpredictable.
@@ -215,45 +215,50 @@ void QWaitCondition::wakeAll()
\i Another thread signals it using wakeOne() or wakeAll(). This
function will return TRUE in this case.
\i \a time milliseconds has elapsed. If \a time is ULONG_MAX (the
default), then the wait will never timeout (the event must be
signalled). This function will return FALSE if the wait timed
out.
\endlist
\sa wakeOne(), wakeAll()
*/
bool QWaitCondition::wait(unsigned long time)
{
- pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+ pthread_mutex_t mutex;
+ pthread_mutex_init( &mutex, 0 );
+ pthread_mutex_lock( &mutex );
int ret;
if (time != ULONG_MAX) {
struct timeval tv;
gettimeofday(&tv, 0);
timespec ti;
- ti.tv_nsec = (tv.tv_usec * 1000) + (time % 1000) * 1000;
+ ti.tv_nsec = ( tv.tv_usec + ( time % 1000 ) * 1000 ) * 1000;
ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 );
ti.tv_nsec %= 1000000000;
ret = pthread_cond_timedwait(&d->cond, &mutex, &ti);
} else
ret = pthread_cond_wait(&d->cond, &mutex);
#ifdef QT_CHECK_RANGE
if (ret && ret != ETIMEDOUT)
qWarning("Wait condition wait failure: %s",strerror(ret));
#endif
+ pthread_mutex_unlock( &mutex );
+ pthread_mutex_destroy( &mutex );
+
return (ret == 0);
}
/*!
\overload
Release the locked \a mutex and wait on the thread event object.
The \a mutex must be initially locked by the calling thread. If \a
mutex is not in a locked state, this function returns immediately.
If \a mutex is a recursive mutex, this function returns
immediately. The \a mutex will be unlocked, and the calling thread
will block until either of these conditions is met:
@@ -282,25 +287,25 @@ bool QWaitCondition::wait(QMutex *mutex, unsigned long time)
qWarning("Wait condition warning: using recursive mutexes with\n"
" wait conditions is undefined!");
#endif
return FALSE;
}
int ret;
if (time != ULONG_MAX) {
struct timeval tv;
gettimeofday(&tv, 0);
timespec ti;
- ti.tv_nsec = (tv.tv_usec * 1000) + (time % 1000) * 1000;
+ ti.tv_nsec = ( tv.tv_usec + ( time % 1000 ) * 1000 ) * 1000;
ti.tv_sec = tv.tv_sec + (time / 1000) + ( ti.tv_nsec / 1000000000 );
ti.tv_nsec %= 1000000000;
ret = pthread_cond_timedwait(&d->cond, &mutex->d->handle, &ti);
} else
ret = pthread_cond_wait(&d->cond, &mutex->d->handle);
#ifdef QT_CHECK_RANGE
if (ret && ret != ETIMEDOUT)
qWarning("Wait condition wait failure: %s",strerror(ret));
#endif