Commit 1535c52c authored by Michael Reeves's avatar Michael Reeves

Revert "*reformat source files."

This reverts commit edc1422c7e023b71e766d4ac368433c9e4064e73.

# Conflicts:
#	src/common.cpp
#	src/directorymergewindow.cpp
#	src/fileaccess.cpp
#	src/kdiff3.cpp
#	src/kdiff3_part.cpp
#	src/kdiff3_shell.cpp
#	src/main.cpp
#	src/optiondialog.cpp
#	src/smalldialogs.cpp
parent 60f8e118
......@@ -27,43 +27,51 @@
#include <QStringList>
#include <QTextStream>
ValueMap::ValueMap() {
ValueMap::ValueMap()
{
}
ValueMap::~ValueMap() {
ValueMap::~ValueMap()
{
}
void ValueMap::save( QTextStream& ts ) {
std::map<QString, QString>::iterator i;
for( i = m_map.begin(); i != m_map.end(); ++i ) {
QString key = i->first;
QString val = i->second;
ts << key << "=" << val << "\n";
}
void ValueMap::save( QTextStream& ts )
{
std::map<QString,QString>::iterator i;
for( i=m_map.begin(); i!=m_map.end(); ++i)
{
QString key = i->first;
QString val = i->second;
ts << key << "=" << val << "\n";
}
}
QString ValueMap::getAsString() {
QString result;
std::map<QString, QString>::iterator i;
for( i = m_map.begin(); i != m_map.end(); ++i ) {
QString key = i->first;
QString val = i->second;
result += key + "=" + val + "\n";
}
return result;
}
void ValueMap::load( QTextStream& ts ) {
while( !ts.atEnd() ) {
// until end of file...
QString s = ts.readLine(); // line of text excluding '\n'
int pos = s.indexOf( '=' );
if( pos > 0 ) { // seems not to have a tag
QString key = s.left( pos );
QString val = s.mid( pos + 1 );
m_map[key] = val;
}
}
QString ValueMap::getAsString()
{
QString result;
std::map<QString,QString>::iterator i;
for( i=m_map.begin(); i!=m_map.end(); ++i)
{
QString key = i->first;
QString val = i->second;
result += key + "=" + val + "\n";
}
return result;
}
void ValueMap::load( QTextStream& ts )
{
while ( !ts.atEnd() )
{ // until end of file...
QString s = ts.readLine(); // line of text excluding '\n'
int pos = s.indexOf('=');
if( pos > 0 ) // seems not to have a tag
{
QString key = s.left(pos);
QString val = s.mid(pos+1);
m_map[key] = val;
}
}
}
/*
void ValueMap::load( const QString& s )
......@@ -88,212 +96,238 @@ void ValueMap::load( const QString& s )
// 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.
QString safeStringJoin( const QStringList& sl, char sepChar, char metaChar ) {
// Join the strings in the list, using the separator ','
// If a string contains the separator character, it will be replaced with "\,".
// Any occurances of "\" (one backslash) will be replaced with "\\" (2 backslashes)
assert( sepChar != metaChar );
QString sep;
sep += sepChar;
QString meta;
meta += metaChar;
QString safeString;
QStringList::const_iterator i;
for( i = sl.begin(); i != sl.end(); ++i ) {
QString s = *i;
s.replace( meta, meta + meta ); // "\" -> "\\"
s.replace( sep, meta + sep ); // "," -> "\,"
if( i == sl.begin() )
safeString = s;
else
safeString += sep + s;
}
return safeString;
QString safeStringJoin(const QStringList& sl, char sepChar, char metaChar )
{
// Join the strings in the list, using the separator ','
// If a string contains the separator character, it will be replaced with "\,".
// Any occurances of "\" (one backslash) will be replaced with "\\" (2 backslashes)
assert(sepChar!=metaChar);
QString sep;
sep += sepChar;
QString meta;
meta += metaChar;
QString safeString;
QStringList::const_iterator i;
for (i=sl.begin(); i!=sl.end(); ++i)
{
QString s = *i;
s.replace(meta, meta+meta); // "\" -> "\\"
s.replace(sep, meta+sep); // "," -> "\,"
if ( i==sl.begin() )
safeString = s;
else
safeString += sep + s;
}
return safeString;
}
// Split a string that was joined with safeStringJoin
QStringList safeStringSplit( const QString& s, char sepChar, char metaChar ) {
assert( sepChar != metaChar );
QStringList sl;
// Miniparser
int i = 0;
int len = s.length();
QString b;
for( i = 0; i < len; ++i ) {
if( i + 1 < len && s[i] == metaChar && s[i + 1] == metaChar ) {
b += metaChar;
++i;
}
else if( i + 1 < len && s[i] == metaChar && s[i + 1] == sepChar ) {
b += sepChar;
++i;
}
else if( s[i] == sepChar ) { // real separator
sl.push_back( b );
b = "";
}
else {
b += s[i];
}
}
if( !b.isEmpty() )
sl.push_back( b );
QStringList safeStringSplit(const QString& s, char sepChar, char metaChar )
{
assert(sepChar!=metaChar);
QStringList sl;
// Miniparser
int i=0;
int len=s.length();
QString b;
for(i=0;i<len;++i)
{
if ( i+1<len && s[i]==metaChar && s[i+1]==metaChar ){ b+=metaChar; ++i; }
else if ( i+1<len && s[i]==metaChar && s[i+1]==sepChar ){ b+=sepChar; ++i; }
else if ( s[i]==sepChar ) // real separator
{
sl.push_back(b);
b="";
}
else { b+=s[i]; }
}
if ( !b.isEmpty() )
sl.push_back(b);
return sl;
return sl;
}
static QString numStr( int n ) {
QString s;
s.setNum( n );
return s;
static QString numStr(int n)
{
QString s;
s.setNum( n );
return s;
}
static QString subSection( const QString& s, int idx, char sep ) {
int pos = 0;
while( idx > 0 ) {
pos = s.indexOf( sep, pos );
--idx;
if( pos < 0 ) break;
++pos;
}
if( pos >= 0 ) {
int pos2 = s.indexOf( sep, pos );
if( pos2 > 0 )
return s.mid( pos, pos2 - pos );
else
return s.mid( pos );
}
static QString subSection( const QString& s, int idx, char sep )
{
int pos=0;
while( idx>0 )
{
pos = s.indexOf( sep, pos );
--idx;
if (pos<0) break;
++pos;
}
if ( pos>=0 )
{
int pos2 = s.indexOf( sep, pos );
if ( pos2>0 )
return s.mid(pos, pos2-pos);
else
return s.mid(pos);
}
return "";
return "";
}
static int num( QString& s, int idx ) {
return subSection( s, idx, ',' ).toInt();
static int num( QString& s, int idx )
{
return subSection( s, idx, ',').toInt();
}
void ValueMap::writeEntry( const QString& k, const QFont& v ) {
m_map[k] = v.family() + "," + QString::number( v.pointSize() ) + "," + ( v.bold() ? "bold" : "normal" );
void ValueMap::writeEntry(const QString& k, const QFont& v )
{
m_map[k] = v.family() + "," + QString::number(v.pointSize()) + "," + (v.bold() ? "bold" : "normal");
}
void ValueMap::writeEntry( const QString& k, const QColor& v ) {
m_map[k] = numStr( v.red() ) + "," + numStr( v.green() ) + "," + numStr( v.blue() );
void ValueMap::writeEntry(const QString& k, const QColor& v )
{
m_map[k] = numStr(v.red()) + "," + numStr(v.green()) + "," + numStr(v.blue());
}
void ValueMap::writeEntry( const QString& k, const QSize& v ) {
m_map[k] = numStr( v.width() ) + "," + numStr( v.height() );
void ValueMap::writeEntry(const QString& k, const QSize& v )
{
m_map[k] = numStr(v.width()) + "," + numStr(v.height());
}
void ValueMap::writeEntry( const QString& k, const QPoint& v ) {
m_map[k] = numStr( v.x() ) + "," + numStr( v.y() );
void ValueMap::writeEntry(const QString& k, const QPoint& v )
{
m_map[k] = numStr(v.x()) + "," + numStr(v.y());
}
void ValueMap::writeEntry( const QString& k, int v ) {
m_map[k] = numStr( v );
void ValueMap::writeEntry(const QString& k, int v )
{
m_map[k] = numStr(v);
}
void ValueMap::writeEntry( const QString& k, bool v ) {
m_map[k] = numStr( v );
void ValueMap::writeEntry(const QString& k, bool v )
{
m_map[k] = numStr(v);
}
void ValueMap::writeEntry( const QString& k, const QString& v ) {
m_map[k] = v;
void ValueMap::writeEntry(const QString& k, const QString& v )
{
m_map[k] = v;
}
void ValueMap::writeEntry( const QString& k, const char* v ) {
m_map[k] = v;
void ValueMap::writeEntry(const QString& k, const char* v )
{
m_map[k] = v;
}
void ValueMap::writeEntry( const QString& k, const QStringList& v ) {
m_map[k] = safeStringJoin( v );
void ValueMap::writeEntry(const QString& k, const QStringList& v )
{
m_map[k] = safeStringJoin(v);
}
QFont ValueMap::readFontEntry( const QString& k, const QFont* defaultVal ) {
QFont f = *defaultVal;
std::map<QString, QString>::iterator i = m_map.find( k );
if( i != m_map.end() ) {
f.setFamily( subSection( i->second, 0, ',' ) );
f.setPointSize( subSection( i->second, 1, ',' ).toInt() );
f.setBold( subSection( i->second, 2, ',' ) == "bold" );
//f.fromString(i->second);
}
QFont ValueMap::readFontEntry(const QString& k, const QFont* defaultVal )
{
QFont f = *defaultVal;
std::map<QString,QString>::iterator i = m_map.find( k );
if ( i!=m_map.end() )
{
f.setFamily( subSection( i->second, 0, ',' ) );
f.setPointSize( subSection( i->second, 1, ',' ).toInt() );
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 c = *defaultVal;
std::map<QString, QString>::iterator i = m_map.find( k );
if( i != m_map.end() ) {
QString s = i->second;
c = QColor( num( s, 0 ), num( s, 1 ), num( s, 2 ) );
}
QColor ValueMap::readColorEntry(const QString& k, const QColor* defaultVal )
{
QColor c= *defaultVal;
std::map<QString,QString>::iterator i = m_map.find( k );
if ( i!=m_map.end() )
{
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 size = defaultVal ? *defaultVal : QSize( 600, 400 );
std::map<QString, QString>::iterator i = m_map.find( k );
if( i != m_map.end() ) {
QSize ValueMap::readSizeEntry(const QString& k, const QSize* defaultVal )
{
QSize size = defaultVal ? *defaultVal : QSize(600,400);
std::map<QString,QString>::iterator i = m_map.find( k );
if ( i!=m_map.end() )
{
QString s = i->second;
size = QSize( num( s, 0 ), num( s, 1 ) );
}
QString s = i->second;
size = QSize( num(s,0),num(s,1) );
}
return size;
return size;
}
QPoint ValueMap::readPointEntry( const QString& k, const QPoint* defaultVal ) {
QPoint point = defaultVal ? *defaultVal : QPoint( 0, 0 );
std::map<QString, QString>::iterator i = m_map.find( k );
if( i != m_map.end() ) {
QString s = i->second;
point = QPoint( num( s, 0 ), num( s, 1 ) );
}
QPoint ValueMap::readPointEntry(const QString& k, const QPoint* defaultVal)
{
QPoint point = defaultVal ? *defaultVal : QPoint(0,0);
std::map<QString,QString>::iterator i = m_map.find( k );
if ( i!=m_map.end() )
{
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 b = bDefault;
std::map<QString, QString>::iterator i = m_map.find( k );
if( i != m_map.end() ) {
QString s = i->second;
b = ( bool )num( s, 0 );
}
bool ValueMap::readBoolEntry(const QString& k, bool bDefault )
{
bool b = bDefault;
std::map<QString,QString>::iterator i = m_map.find( k );
if ( i!=m_map.end() )
{
QString s = i->second;
b = (bool)num(s,0);
}
return b;
return b;
}
int ValueMap::readNumEntry( const QString& k, int iDefault ) {
int ival = iDefault;
std::map<QString, QString>::iterator i = m_map.find( k );
if( i != m_map.end() ) {
QString s = i->second;
ival = num( s, 0 );
}
int ValueMap::readNumEntry(const QString& k, int iDefault )
{
int ival = iDefault;
std::map<QString,QString>::iterator i = m_map.find( k );
if ( i!=m_map.end() )
{
QString s = i->second;
ival = num(s,0);
}
return ival;
return ival;
}
QString ValueMap::readStringEntry( const QString& k, const QString& sDefault ) {
QString sval = sDefault;
std::map<QString, QString>::iterator i = m_map.find( k );
if( i != m_map.end() ) {
sval = i->second;
}
QString ValueMap::readStringEntry(const QString& k, const QString& sDefault )
{
QString sval = sDefault;
std::map<QString,QString>::iterator i = m_map.find( k );
if ( i!=m_map.end() )
{
sval = i->second;
}
return sval;
return sval;
}
QStringList ValueMap::readListEntry( const QString& k, const QStringList& defaultVal ) {
QStringList ValueMap::readListEntry(const QString& k, const QStringList& defaultVal)
{
QStringList strList;
std::map<QString, QString>::iterator i = m_map.find( k );
......
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,48 +35,52 @@
#include "gnudiff_diff.h"
/* If non NULL, call this function when memory is exhausted. */
//void (*xalloc_fail_func) PARAMS ((void)) = 0;
void ( *xalloc_fail_func )( void ) = 0;
void GnuDiff::xalloc_die( void ) {
if( xalloc_fail_func )
( *xalloc_fail_func )();
//error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
/* The `noreturn' cannot be given to error, since it may return if
its first argument is 0. To help compilers understand the
xalloc_die does terminate, call exit. */
exit( EXIT_FAILURE );
void (*xalloc_fail_func)(void) = 0;
void GnuDiff::xalloc_die (void)
{
if (xalloc_fail_func)
(*xalloc_fail_func) ();
//error (exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
/* The `noreturn' cannot be given to error, since it may return if
its first argument is 0. To help compilers understand the
xalloc_die does terminate, call exit. */
exit (EXIT_FAILURE);
}
/* Allocate N bytes of memory dynamically, with error checking. */
void *
GnuDiff::xmalloc( size_t n ) {
void *p;
p = malloc( n == 0 ? 1 : n ); // There are systems where malloc returns 0 for n==0.
if( p == 0 )
xalloc_die();
return p;
GnuDiff::xmalloc (size_t n)
{
void *p;
p = malloc (n == 0 ? 1 : n); // There are systems where malloc returns 0 for n==0.
if (p == 0)
xalloc_die ();
return p;
}
/* Change the size of an allocated block of memory P to N bytes,
with error checking. */
void *
GnuDiff::xrealloc( void *p, size_t n ) {
p = realloc( p, n == 0 ? 1 : n );
if( p == 0 )
xalloc_die();
return p;
GnuDiff::xrealloc (void *p, size_t n)
{
p = realloc (p, n==0 ? 1 : n);
if (p == 0)
xalloc_die ();
return p;
}
/* Yield a new block of SIZE bytes, initialized to zero. */
void *
GnuDiff::zalloc( size_t size ) {
void *p = xmalloc( size );
memset( p, 0, size );
return p;
GnuDiff::zalloc (size_t size)
{
void *p = xmalloc (size);
memset (p, 0, size);
return p;
}
......@@ -43,7 +43,7 @@ static KAboutData createAboutData()
appVersion += " (64 bit)";
else if ( sizeof(void*)==4 )
appVersion += " (32 bit)";
KAboutData aboutData( "kdiff3part", i18n( "KDiff3 Part" ),
appVersion, i18n( "A KPart to display SVG images" ),
KAboutLicense::GPL_V2,
......@@ -84,17 +84,20 @@ KDiff3Part::KDiff3Part( QWidget *parentWidget, QObject *parent, const QVariantLi
setModified( false );
}
KDiff3Part::~KDiff3Part() {
KDiff3Part::~KDiff3Part()
{
if( m_widget != 0 && ! m_bIsShell ) {
m_widget->saveOptions( KSharedConfig::openConfig() );
}
}
void KDiff3Part::setReadWrite( bool /*rw*/ ) {
void KDiff3Part::setReadWrite( bool /*rw*/ )
{
// ReadWritePart::setReadWrite(rw);
}
void KDiff3Part::setModified( bool /*modified*/ ) {
void KDiff3Part::setModified( bool /*modified*/ )
{
/*
// get a handle on our Save action and make sure it is valid
QAction *save = actionCollection()->action(KStandardAction::stdName(KStandardAction::Save));
......@@ -113,7 +116,8 @@ void KDiff3Part::setModified( bool /*modified*/ ) {
*/
}
static void getNameAndVersion( const QString& str, const QString& lineStart, QString& fileName, QString& version ) {
static void getNameAndVersion( const QString& str, const QString& lineStart, QString& fileName, QString& version )
{
if( str.left( lineStart.length() ) == lineStart && fileName.isEmpty() ) {
int pos = lineStart.length();
while( pos < str.length() && ( str[pos] == ' ' || str[pos] == '\t' ) ) ++pos;
......@@ -136,7 +140,8 @@ static void getNameAndVersion( const QString& str, const QString& lineStart, QSt
}
bool KDiff3Part::openFile() {
bool KDiff3Part::openFile()
{
// m_file is always local so we can use QFile on it
fprintf( stderr, "KDiff3: %s\n", localFilePath().toLatin1().constData() );
QFile file( localFilePath() );
......@@ -238,7 +243,8 @@ bool KDiff3Part::openFile() {
return true;
}
bool KDiff3Part::saveFile() {
bool KDiff3Part::saveFile()
{
/* // if we aren't read-write, return immediately
if (isReadWrite() == false)
return false;
......
......@@ -42,10 +42,11 @@
#include <ktoolbar.h>
KDiff3Shell::KDiff3Shell( bool bCompleteInit )
: KParts::MainWindow( ) {