Commit f17c7ce8 authored by Michael Reeves's avatar Michael Reeves

*reformat source files.

parent 0bd4dd9c
...@@ -27,51 +27,43 @@ ...@@ -27,51 +27,43 @@
#include <QStringList> #include <QStringList>
#include <QTextStream> #include <QTextStream>
ValueMap::ValueMap() ValueMap::ValueMap() {
{
} }
ValueMap::~ValueMap() ValueMap::~ValueMap() {
{
} }
void ValueMap::save( QTextStream& ts ) void ValueMap::save( QTextStream& ts ) {
{ std::map<QString, QString>::iterator i;
std::map<QString,QString>::iterator i; for( i = m_map.begin(); i != m_map.end(); ++i ) {
for( i=m_map.begin(); i!=m_map.end(); ++i) QString key = i->first;
{ QString val = i->second;
QString key = i->first; ts << key << "=" << val << "\n";
QString val = i->second; }
ts << key << "=" << val << "\n";
}
} }
QString ValueMap::getAsString() QString ValueMap::getAsString() {
{ QString result;
QString result; std::map<QString, QString>::iterator i;
std::map<QString,QString>::iterator i; for( i = m_map.begin(); i != m_map.end(); ++i ) {
for( i=m_map.begin(); i!=m_map.end(); ++i) QString key = i->first;
{ QString val = i->second;
QString key = i->first; result += key + "=" + val + "\n";
QString val = i->second; }
result += key + "=" + val + "\n"; return result;
}
return result;
} }
void ValueMap::load( QTextStream& ts ) void ValueMap::load( QTextStream& ts ) {
{ while( !ts.atEnd() ) {
while ( !ts.atEnd() ) // until end of file...
{ // until end of file... QString s = ts.readLine(); // line of text excluding '\n'
QString s = ts.readLine(); // line of text excluding '\n' int pos = s.indexOf( '=' );
int pos = s.indexOf('='); if( pos > 0 ) { // seems not to have a tag
if( pos > 0 ) // seems not to have a tag QString key = s.left( pos );
{ QString val = s.mid( pos + 1 );
QString key = s.left(pos); m_map[key] = val;
QString val = s.mid(pos+1); }
m_map[key] = val; }
}
}
} }
/* /*
void ValueMap::load( const QString& s ) void ValueMap::load( const QString& s )
...@@ -96,256 +88,247 @@ void ValueMap::load( const QString& s ) ...@@ -96,256 +88,247 @@ void ValueMap::load( const QString& s )
// safeStringJoin and safeStringSplit allow to convert a stringlist into a string and back // safeStringJoin and safeStringSplit allow to convert a stringlist into a string and back
// safely, even if the individual strings in the list contain the separator character. // safely, even if the individual strings in the list contain the separator character.
QString safeStringJoin(const QStringList& sl, char sepChar, char metaChar ) QString safeStringJoin( const QStringList& sl, char sepChar, char metaChar ) {
{ // Join the strings in the list, using the separator ','
// Join the strings in the list, using the separator ',' // If a string contains the separator character, it will be replaced with "\,".
// If a string contains the separator character, it will be replaced with "\,". // Any occurances of "\" (one backslash) will be replaced with "\\" (2 backslashes)
// Any occurances of "\" (one backslash) will be replaced with "\\" (2 backslashes)
assert( sepChar != metaChar );
assert(sepChar!=metaChar);
QString sep;
QString sep; sep += sepChar;
sep += sepChar; QString meta;
QString meta; meta += metaChar;
meta += metaChar;
QString safeString;
QString safeString;
QStringList::const_iterator i;
QStringList::const_iterator i; for( i = sl.begin(); i != sl.end(); ++i ) {
for (i=sl.begin(); i!=sl.end(); ++i) QString s = *i;
{ s.replace( meta, meta + meta ); // "\" -> "\\"
QString s = *i; s.replace( sep, meta + sep ); // "," -> "\,"
s.replace(meta, meta+meta); // "\" -> "\\" if( i == sl.begin() )
s.replace(sep, meta+sep); // "," -> "\," safeString = s;
if ( i==sl.begin() ) else
safeString = s; safeString += sep + s;
else }
safeString += sep + s; return safeString;
}
return safeString;
} }
// Split a string that was joined with safeStringJoin // Split a string that was joined with safeStringJoin
QStringList safeStringSplit(const QString& s, char sepChar, char metaChar ) QStringList safeStringSplit( const QString& s, char sepChar, char metaChar ) {
{ assert( sepChar != metaChar );
assert(sepChar!=metaChar); QStringList sl;
QStringList sl; // Miniparser
// Miniparser int i = 0;
int i=0; int len = s.length();
int len=s.length(); QString b;
QString b; for( i = 0; i < len; ++i ) {
for(i=0;i<len;++i) if( i + 1 < len && s[i] == metaChar && s[i + 1] == metaChar ) {
{ b += metaChar;
if ( i+1<len && s[i]==metaChar && s[i+1]==metaChar ){ b+=metaChar; ++i; } ++i;
else if ( i+1<len && s[i]==metaChar && s[i+1]==sepChar ){ b+=sepChar; ++i; } }
else if ( s[i]==sepChar ) // real separator else if( i + 1 < len && s[i] == metaChar && s[i + 1] == sepChar ) {
{ b += sepChar;
sl.push_back(b); ++i;
b=""; }
} else if( s[i] == sepChar ) { // real separator
else { b+=s[i]; } sl.push_back( b );
} b = "";
if ( !b.isEmpty() ) }
sl.push_back(b); else {
b += s[i];
return sl; }
}
if( !b.isEmpty() )
sl.push_back( b );
return sl;
} }
static QString numStr(int n) static QString numStr( int n ) {
{ QString s;
QString s; s.setNum( n );
s.setNum( n ); return s;
return s;
} }
static QString subSection( const QString& s, int idx, char sep ) static QString subSection( const QString& s, int idx, char sep ) {
{ int pos = 0;
int pos=0; while( idx > 0 ) {
while( idx>0 ) pos = s.indexOf( sep, pos );
{ --idx;
pos = s.indexOf( sep, pos ); if( pos < 0 ) break;
--idx; ++pos;
if (pos<0) break; }
++pos; if( pos >= 0 ) {
} int pos2 = s.indexOf( sep, pos );
if ( pos>=0 ) if( pos2 > 0 )
{ return s.mid( pos, pos2 - pos );
int pos2 = s.indexOf( sep, pos ); else
if ( pos2>0 ) return s.mid( pos );
return s.mid(pos, pos2-pos); }
else
return s.mid(pos); return "";
}
return "";
} }
static int num( QString& s, int idx ) static int num( QString& s, int idx ) {
{ return subSection( s, idx, ',' ).toInt();
return subSection( s, idx, ',').toInt();
} }
void ValueMap::writeEntry(const QString& k, const QFont& v ) void ValueMap::writeEntry( const QString& k, const QFont& v ) {
{ m_map[k] = v.family() + "," + QString::number( v.pointSize() ) + "," + ( v.bold() ? "bold" : "normal" );
m_map[k] = v.family() + "," + QString::number(v.pointSize()) + "," + (v.bold() ? "bold" : "normal");
} }
void ValueMap::writeEntry(const QString& k, const QColor& v ) void ValueMap::writeEntry( const QString& k, const QColor& v ) {
{ m_map[k] = numStr( v.red() ) + "," + numStr( v.green() ) + "," + numStr( v.blue() );
m_map[k] = numStr(v.red()) + "," + numStr(v.green()) + "," + numStr(v.blue());
} }
void ValueMap::writeEntry(const QString& k, const QSize& v ) void ValueMap::writeEntry( const QString& k, const QSize& v ) {
{ m_map[k] = numStr( v.width() ) + "," + numStr( v.height() );
m_map[k] = numStr(v.width()) + "," + numStr(v.height());
} }
void ValueMap::writeEntry(const QString& k, const QPoint& v ) void ValueMap::writeEntry( const QString& k, const QPoint& v ) {
{ m_map[k] = numStr( v.x() ) + "," + numStr( v.y() );
m_map[k] = numStr(v.x()) + "," + numStr(v.y());
} }
void ValueMap::writeEntry(const QString& k, int v ) void ValueMap::writeEntry( const QString& k, int v ) {
{ m_map[k] = numStr( v );
m_map[k] = numStr(v);
} }
void ValueMap::writeEntry(const QString& k, bool v ) void ValueMap::writeEntry( const QString& k, bool v ) {
{ m_map[k] = numStr( v );
m_map[k] = numStr(v);
} }
void ValueMap::writeEntry(const QString& k, const QString& v ) void ValueMap::writeEntry( const QString& k, const QString& v ) {
{ m_map[k] = v;
m_map[k] = v;
} }
void ValueMap::writeEntry(const QString& k, const char* v ) void ValueMap::writeEntry( const QString& k, const char* v ) {
{ m_map[k] = v;
m_map[k] = v;
} }
void ValueMap::writeEntry(const QString& k, const QStringList& v, char separator ) void ValueMap::writeEntry( const QString& k, const QStringList& v, char separator ) {
{ m_map[k] = safeStringJoin( v, separator );
m_map[k] = safeStringJoin(v, separator);
} }
QFont ValueMap::readFontEntry(const QString& k, const QFont* defaultVal ) QFont ValueMap::readFontEntry( const QString& k, const QFont* defaultVal ) {
{ QFont f = *defaultVal;
QFont f = *defaultVal; std::map<QString, QString>::iterator i = m_map.find( k );
std::map<QString,QString>::iterator i = m_map.find( k ); if( i != m_map.end() ) {
if ( i!=m_map.end() ) f.setFamily( subSection( i->second, 0, ',' ) );
{ f.setPointSize( subSection( i->second, 1, ',' ).toInt() );
f.setFamily( subSection( i->second, 0, ',' ) ); f.setBold( subSection( i->second, 2, ',' ) == "bold" );
f.setPointSize( subSection( i->second, 1, ',' ).toInt() ); //f.fromString(i->second);
f.setBold( subSection( i->second, 2, ',' )=="bold" ); }
//f.fromString(i->second);
}
return f; return f;
} }
QColor ValueMap::readColorEntry(const QString& k, const QColor* defaultVal ) QColor ValueMap::readColorEntry( const QString& k, const QColor* defaultVal ) {
{ QColor c = *defaultVal;
QColor c= *defaultVal; std::map<QString, QString>::iterator i = m_map.find( k );
std::map<QString,QString>::iterator i = m_map.find( k ); if( i != m_map.end() ) {
if ( i!=m_map.end() ) QString s = i->second;
{ c = QColor( num( s, 0 ), num( s, 1 ), num( s, 2 ) );
QString s = i->second; }
c = QColor( num(s,0),num(s,1),num(s,2) );
}
return c; return c;
} }
QSize ValueMap::readSizeEntry(const QString& k, const QSize* defaultVal ) QSize ValueMap::readSizeEntry( const QString& k, const QSize* defaultVal ) {
{ QSize size = defaultVal ? *defaultVal : QSize( 600, 400 );
QSize size = defaultVal ? *defaultVal : QSize(600,400); std::map<QString, QString>::iterator i = m_map.find( k );
std::map<QString,QString>::iterator i = m_map.find( k ); if( i != m_map.end() ) {
if ( i!=m_map.end() )
{
QString s = i->second; QString s = i->second;
size = QSize( num(s,0),num(s,1) ); size = QSize( num( s, 0 ), num( s, 1 ) );
} }
return size; return size;
} }
QPoint ValueMap::readPointEntry(const QString& k, const QPoint* defaultVal) QPoint ValueMap::readPointEntry( const QString& k, const QPoint* defaultVal ) {
{ QPoint point = defaultVal ? *defaultVal : QPoint( 0, 0 );
QPoint point = defaultVal ? *defaultVal : QPoint(0,0); std::map<QString, QString>::iterator i = m_map.find( k );
std::map<QString,QString>::iterator i = m_map.find( k ); if( i != m_map.end() ) {
if ( i!=m_map.end() ) QString s = i->second;
{ point = QPoint( num( s, 0 ), num( s, 1 ) );
QString s = i->second; }
point = QPoint( num(s,0),num(s,1) );
}
return point; return point;
} }
bool ValueMap::readBoolEntry(const QString& k, bool bDefault ) bool ValueMap::readBoolEntry( const QString& k, bool bDefault ) {
{ bool b = bDefault;
bool b = bDefault; std::map<QString, QString>::iterator i = m_map.find( k );
std::map<QString,QString>::iterator i = m_map.find( k ); if( i != m_map.end() ) {
if ( i!=m_map.end() ) QString s = i->second;
{ b = ( bool )num( s, 0 );
QString s = i->second; }
b = (bool)num(s,0);
}
return b; return b;
} }
int ValueMap::readNumEntry(const QString& k, int iDefault ) int ValueMap::readNumEntry( const QString& k, int iDefault ) {
{ int ival = iDefault;
int ival = iDefault; std::map<QString, QString>::iterator i = m_map.find( k );
std::map<QString,QString>::iterator i = m_map.find( k ); if( i != m_map.end() ) {
if ( i!=m_map.end() ) QString s = i->second;
{ ival = num( s, 0 );
QString s = i->second; }
ival = num(s,0);
}
return ival; return ival;
} }
QString ValueMap::readStringEntry(const QString& k, const QString& sDefault ) QString ValueMap::readStringEntry( const QString& k, const QString& sDefault ) {
{ QString sval = sDefault;
QString sval = sDefault; std::map<QString, QString>::iterator i = m_map.find( k );
std::map<QString,QString>::iterator i = m_map.find( k ); if( i != m_map.end() ) {
if ( i!=m_map.end() ) sval = i->second;
{ }
sval = i->second;
}
return sval; return sval;
} }
QStringList ValueMap::readListEntry(const QString& k, const QStringList& defaultVal, char separator ) QStringList ValueMap::readListEntry( const QString& k, const QStringList& defaultVal, char separator ) {
{ QStringList strList;
QStringList strList;
std::map<QString,QString>::iterator i = m_map.find( k ); std::map<QString, QString>::iterator i = m_map.find( k );
if ( i!=m_map.end() ) if( i != m_map.end() ) {
{ strList = safeStringSplit( i->second, separator );
strList = safeStringSplit( i->second, separator ); return strList;
return strList; }
} else
else return defaultVal;
return defaultVal; }
}
QString ValueMap::readEntry( const QString& s, const QString& defaultVal ) {
QString ValueMap::readEntry (const QString& s, const QString& defaultVal ) { return readStringEntry(s, defaultVal); } return readStringEntry( s, defaultVal );
QString ValueMap::readEntry (const QString& s, const char* defaultVal ) { return readStringEntry(s, QString::fromLatin1(defaultVal) ); } }
QFont ValueMap::readEntry (const QString& s, const QFont& defaultVal ){ return readFontEntry(s,&defaultVal); } QString ValueMap::readEntry( const QString& s, const char* defaultVal ) {
QColor ValueMap::readEntry(const QString& s, const QColor defaultVal ){ return readColorEntry(s,&defaultVal); } return readStringEntry( s, QString::fromLatin1( defaultVal ) );
QSize ValueMap::readEntry (const QString& s, const QSize defaultVal ){ return readSizeEntry(s,&defaultVal); } }
QPoint ValueMap::readEntry(const QString& s, const QPoint defaultVal ){ return readPointEntry(s,&defaultVal); } QFont ValueMap::readEntry( const QString& s, const QFont& defaultVal ) {
bool ValueMap::readEntry (const QString& s, bool bDefault ){ return readBoolEntry(s,bDefault); } return readFontEntry( s, &defaultVal );
int ValueMap::readEntry (const QString& s, int iDefault ){ return readNumEntry(s,iDefault); } }
QStringList ValueMap::readEntry (const QString& s, const QStringList& defaultVal, char separator ){ return readListEntry(s,defaultVal,separator); } QColor ValueMap::readEntry( const QString& s, const QColor defaultVal ) {
return readColorEntry( s, &defaultVal );
}
QSize ValueMap::readEntry( const QString& s, const QSize defaultVal ) {
return readSizeEntry( s, &defaultVal );
}
QPoint ValueMap::readEntry( const QString& s, const QPoint defaultVal ) {
return readPointEntry( s, &defaultVal );
}
bool ValueMap::readEntry( const QString& s, bool bDefault ) {
return readBoolEntry( s, bDefault );
}
int ValueMap::readEntry( const QString& s, int iDefault ) {
return readNumEntry( s, iDefault );
}
QStringList ValueMap::readEntry( const QString& s, const QStringList& defaultVal, char separator ) {
return readListEntry( s, defaultVal, separator );
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -35,52 +35,48 @@ ...@@ -35,52 +35,48 @@
#include "gnudiff_diff.h" #include "gnudiff_diff.h"
/* If non NULL, call this function when memory is exhausted. */ /* If non NULL, call this function when memory is exhausted. */
//void (*xalloc_fail_func) PARAMS ((void)) = 0; //void (*xalloc_fail_func) PARAMS ((void)) = 0;
void (*xalloc_fail_func)(void) = 0; void ( *xalloc_fail_func )( void ) = 0;
void GnuDiff::xalloc_die (void) void GnuDiff::xalloc_die( void ) {
{ if( xalloc_fail_func )
if (xalloc_fail_func) ( *xalloc_fail_func )();
(*xalloc_fail_func) (); //error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
//error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted)); /* The `noreturn' cannot be given to error, since it may return if
/* The `noreturn' cannot be given to error, since it may return if its first argument is 0. To help compilers understand the
its first argument is 0. To help compilers understand the xalloc_die does terminate, call exit. */
xalloc_die does terminate, call exit. */ exit( EXIT_FAILURE );
exit (EXIT_FAILURE);
} }
/* Allocate N bytes of memory dynamically, with error checking. */ /* Allocate N bytes of memory dynamically, with error checking. */
void * void *
GnuDiff::xmalloc (size_t n) GnuDiff::xmalloc( size_t n ) {
{ void *p;
void *p;
p = malloc( n == 0 ? 1 : n ); // There are systems where malloc returns 0 for n==0.
p = malloc (n == 0 ? 1 : n); // There are systems where malloc returns 0 for n==0. if( p == 0 )
if (p == 0) xalloc_die();
xalloc_die ();