annotate kdiff3/src/main.cpp @ 70:5bbfe4784324

KDiff3 0.9.89 for Qt4
author joachim99
date Tue, 18 Apr 2006 20:19:57 +0000
parents 8febbfb1148c
children
rev   line source
joachim99@8 1 /***************************************************************************
joachim99@8 2 main.cpp - Where everything starts.
joachim99@8 3 -------------------
joachim99@8 4 begin : Don Jul 11 12:31:29 CEST 2002
joachim99@69 5 copyright : (C) 2002-2006 by Joachim Eibl
joachim99@69 6 email : joachim.eibl at gmx.de
joachim99@8 7 ***************************************************************************/
joachim99@8 8
joachim99@8 9 /***************************************************************************
joachim99@8 10 * *
joachim99@8 11 * This program is free software; you can redistribute it and/or modify *
joachim99@8 12 * it under the terms of the GNU General Public License as published by *
joachim99@8 13 * the Free Software Foundation; either version 2 of the License, or *
joachim99@8 14 * (at your option) any later version. *
joachim99@8 15 * *
joachim99@8 16 ***************************************************************************/
joachim99@8 17
joachim99@8 18 #include <kcmdlineargs.h>
joachim99@8 19 #include <kaboutdata.h>
joachim99@8 20 #include <klocale.h>
joachim99@40 21 #include "kdiff3_shell.h"
joachim99@69 22 #include <kstandarddirs.h>
friseb123@16 23 #include "version.h"
joachim99@53 24 #include <qtextcodec.h>
joachim99@69 25 #include <qfile.h>
joachim99@69 26 #include <qtextstream.h>
joachim99@70 27 //Added by qt3to4:
joachim99@70 28 #include <QTranslator>
joachim99@69 29 #include <vector>
joachim99@8 30
joachim99@66 31 #ifdef KREPLACEMENTS_H
joachim99@66 32 #include "optiondialog.h"
joachim99@66 33 #endif
joachim99@69 34 #include "common.h"
joachim99@8 35
joachim99@8 36 static const char *description =
joachim99@68 37 I18N_NOOP("Tool for Comparison and Merge of Files and Directories");
joachim99@8 38
joachim99@8 39 static KCmdLineOptions options[] =
joachim99@8 40 {
joachim99@8 41 { "m", 0, 0 },
joachim99@8 42 { "merge", I18N_NOOP("Merge the input."), 0 },
joachim99@8 43 { "b", 0, 0 },
joachim99@8 44 { "base file", I18N_NOOP("Explicit base file. For compatibility with certain tools."), 0 },
joachim99@8 45 { "o", 0, 0 },
joachim99@8 46 { "output file", I18N_NOOP("Output file. Implies -m. E.g.: -o newfile.txt"), 0 },
joachim99@8 47 { "out file", I18N_NOOP("Output file, again. (For compatibility with certain tools.)"), 0 },
joachim99@8 48 { "auto", I18N_NOOP("No GUI if all conflicts are auto-solvable. (Needs -o file)"), 0 },
joachim99@8 49 { "qall", I18N_NOOP("Don't solve conflicts automatically. (For compatibility...)"), 0 },
joachim99@66 50 { "L1 alias1", I18N_NOOP("Visible name replacement for input file 1 (base)."), 0 },
joachim99@66 51 { "L2 alias2", I18N_NOOP("Visible name replacement for input file 2."), 0 },
joachim99@66 52 { "L3 alias3", I18N_NOOP("Visible name replacement for input file 3."), 0 },
joachim99@66 53 { "L", 0, 0 },
joachim99@66 54 { "fname alias", I18N_NOOP("Alternative visible name replacement. Supply this once for every input."), 0 },
joachim99@69 55 { "cs string", I18N_NOOP("Override a config setting. Use once for every setting. E.g.: --cs \"AutoAdvance=1\""), 0 },
joachim99@69 56 { "confighelp", I18N_NOOP("Show list of config settings and current values."), 0 },
joachim99@69 57 { "config file", I18N_NOOP("Use a different config file."), 0 }
joachim99@69 58 };
joachim99@69 59 static KCmdLineOptions options2[] =
joachim99@69 60 {
joachim99@8 61 { "+[File1]", I18N_NOOP("file1 to open (base, if not specified via --base)"), 0 },
joachim99@8 62 { "+[File2]", I18N_NOOP("file2 to open"), 0 },
joachim99@69 63 { "+[File3]", I18N_NOOP("file3 to open"), 0 }
joachim99@8 64 };
joachim99@8 65
joachim99@8 66
joachim99@69 67 void initialiseCmdLineArgs(std::vector<KCmdLineOptions>& vOptions, QStringList& ignorableOptions)
joachim99@69 68 {
joachim99@69 69 vOptions.insert( vOptions.end(), options, (KCmdLineOptions*)((char*)options+sizeof(options)));
joachim99@69 70 QString configFileName = KStandardDirs().findResource("config","kdiff3rc");
joachim99@69 71 QFile configFile( configFileName );
joachim99@70 72 if ( configFile.open( QIODevice::ReadOnly ) )
joachim99@69 73 {
joachim99@69 74 QTextStream ts( &configFile );
joachim99@69 75 while(!ts.atEnd())
joachim99@69 76 {
joachim99@69 77 QString line = ts.readLine();
joachim99@69 78 if ( line.startsWith("IgnorableCmdLineOptions=") )
joachim99@69 79 {
joachim99@69 80 int pos = line.find('=');
joachim99@69 81 if (pos>=0)
joachim99@69 82 {
joachim99@69 83 QString s = line.mid(pos+1);
joachim99@69 84 QStringList sl = QStringList::split( '|', s );
joachim99@69 85 if (!sl.isEmpty())
joachim99@69 86 {
joachim99@69 87 ignorableOptions = QStringList::split( ';', sl.front() );
joachim99@69 88 for (QStringList::iterator i=ignorableOptions.begin(); i!=ignorableOptions.end(); ++i)
joachim99@69 89 {
joachim99@69 90 KCmdLineOptions ignoreOption;
joachim99@69 91 (*i).remove('-');
joachim99@69 92 if (!(*i).isEmpty())
joachim99@69 93 {
joachim99@69 94 ignoreOption.name = (*i).latin1();
joachim99@69 95 ignoreOption.description = I18N_NOOP("Ignored. (User defined.)");
joachim99@69 96 ignoreOption.def = 0;
joachim99@69 97 vOptions.push_back(ignoreOption);
joachim99@69 98 }
joachim99@69 99 }
joachim99@69 100 }
joachim99@69 101 }
joachim99@69 102 break;
joachim99@69 103 }
joachim99@69 104 }
joachim99@69 105 }
joachim99@69 106 vOptions.insert(vOptions.end(),options2,(KCmdLineOptions*)((char*)options2+sizeof(options2)));
joachim99@69 107
joachim99@69 108 KCmdLineOptions last = KCmdLineLastOption;
joachim99@69 109 vOptions.push_back(last);
joachim99@69 110 KCmdLineArgs::addCmdLineOptions( &vOptions[0] ); // Add our own options.
joachim99@69 111 }
joachim99@69 112
joachim99@69 113
joachim99@8 114 #ifdef _WIN32
joachim99@8 115 #include <process.h>
joachim99@8 116 // This command checks the comm
joachim99@8 117 static bool isOptionUsed(const QString& s, int argc, char* argv[])
joachim99@8 118 {
joachim99@8 119 for(int j=0; j<argc; ++j )
joachim99@8 120 {
joachim99@8 121 if( "-"+s == argv[j] || "--"+s==argv[j] )
joachim99@8 122 {
joachim99@8 123 return true;
joachim99@8 124 }
joachim99@8 125 }
joachim99@8 126 return false;
joachim99@8 127 }
joachim99@8 128 #endif
joachim99@8 129
joachim99@8 130 int main(int argc, char *argv[])
joachim99@8 131 {
joachim99@8 132 #ifdef _WIN32
joachim99@8 133 /* KDiff3 can be used as replacement for the text-diff and merge tool provided by
joachim99@8 134 Clearcase. This is experimental and so far has only been tested under Windows.
joachim99@8 135
joachim99@69 136 There are two ways to use KDiff3 with clearcase
joachim99@69 137 - The file lib/mgrs/map contains the list of compare/merge tasks on one side and
joachim99@69 138 the tool on the other. Originally this contains only clearcase tools, but you can
joachim99@69 139 edit this file and put kdiff3 there instead. (Recommended method)
joachim99@69 140 - Exchange the original program with KDiff3: (Hackish, no fine control)
joachim99@69 141 1. In the Clearcase "bin"-directory rename "cleardiffmrg.exe" to "cleardiffmrg_orig.exe".
joachim99@69 142 2. Copy kdiff3.exe into that "bin"-directory and rename it to "cleardiffmrg.exe".
joachim99@69 143 (Also copy the other files that are needed by KDiff3 there.)
joachim99@69 144 Now when a file comparison or merge is done by Clearcase then of course KDiff3 will be
joachim99@69 145 run instead.
joachim99@69 146 If the commandline contains the option "-directory" then KDiff3 can't do it but will
joachim99@69 147 run "cleardiffmrg_orig.exe" instead.
joachim99@8 148 */
joachim99@8 149
joachim99@69 150 // Write all args into a temporary file. Uncomment this for debugging purposes.
joachim99@69 151 /*
joachim99@8 152 FILE* f = fopen("c:\\t.txt","w");
joachim99@8 153 for(int i=0; i< argc; ++i)
joachim99@8 154 fprintf(f,"Arg %d: %s\n", i, argv[i]);
joachim99@69 155
joachim99@69 156 // Call orig cleardiffmrg.exe to see what result it returns.
joachim99@69 157 int result=0;
joachim99@69 158 result = ::_spawnvp(_P_WAIT , "C:\\Programme\\Rational\\ClearCase\\bin\\cleardiffmrg.exe", argv );
joachim99@69 159 fprintf(f,"Result: %d\n", result );
joachim99@8 160 fclose(f);
joachim99@69 161 return result;
joachim99@8 162 */
joachim99@8 163
joachim99@8 164 // KDiff3 can replace cleardiffmrg from clearcase. But not all functions.
joachim99@8 165 if ( isOptionUsed( "directory", argc,argv ) )
joachim99@8 166 {
joachim99@8 167 return ::_spawnvp(_P_WAIT , "cleardiffmrg_orig", argv );
joachim99@8 168 }
joachim99@69 169
joachim99@8 170 #endif
joachim99@69 171 //QApplication::setColorSpec( QApplication::ManyColor ); // Grab all 216 colors
joachim99@8 172
joachim99@8 173 KAboutData aboutData( "kdiff3", I18N_NOOP("KDiff3"),
joachim99@8 174 VERSION, description, KAboutData::License_GPL,
joachim99@69 175 "(c) 2002-2005 Joachim Eibl", 0, "http://kdiff3.sourceforge.net/", "joachim.eibl" "@" "gmx.de");
joachim99@69 176 aboutData.addAuthor("Joachim Eibl",0, "joachim.eibl" "@" "gmx.de");
joachim99@66 177 aboutData.addCredit("Eike Sauer", "Bugfixes, Debian package maintainer" );
joachim99@66 178 aboutData.addCredit("Sebastien Fricker", "Windows installer" );
joachim99@69 179 aboutData.addCredit("Stephan Binner", "i18n-help", "binner" "@" "kde.org" );
joachim99@66 180 aboutData.addCredit("Stefan Partheymueller", "Clipboard-patch" );
joachim99@69 181 aboutData.addCredit("David Faure", "KIO-Help", "faure" "@" "kde.org" );
joachim99@66 182 aboutData.addCredit("Bernd Gehrmann", "Class CvsIgnoreList from Cervisia" );
joachim99@66 183 aboutData.addCredit("Andre Woebbeking", "Class StringMatcher" );
joachim99@68 184 aboutData.addCredit("Michael Denio", "Directory Equality-Coloring patch");
joachim99@66 185 aboutData.addCredit("Paul Eggert, Mike Haertel, David Hayes, Richard Stallman, Len Tower", "GNU-Diffutils");
joachim99@66 186 aboutData.addCredit(I18N_NOOP("+ Many thanks to those who reported bugs and contributed ideas!"));
joachim99@69 187
joachim99@8 188 KCmdLineArgs::init( argc, argv, &aboutData );
joachim99@69 189 std::vector<KCmdLineOptions> vOptions;
joachim99@69 190 QStringList ignorableOptions;
joachim99@69 191 initialiseCmdLineArgs(vOptions, ignorableOptions);
joachim99@8 192
joachim99@53 193 KApplication app;
joachim99@69 194
joachim99@53 195 #ifdef KREPLACEMENTS_H
joachim99@66 196 QString locale;
joachim99@69 197
joachim99@66 198 locale = app.config()->readEntry("Language", "Auto");
joachim99@66 199 int spacePos = locale.find(' ');
joachim99@66 200 if (spacePos>0) locale = locale.left(spacePos);
joachim99@53 201 QTranslator kdiff3Translator( 0 );
joachim99@53 202 QTranslator qtTranslator( 0 );
joachim99@66 203 if (locale != "en_orig")
joachim99@66 204 {
joachim99@66 205 if ( locale == "Auto" || locale.isEmpty() )
joachim99@66 206 locale = QTextCodec::locale();
joachim99@66 207
joachim99@66 208 QString translationDir = getTranslationDir();
joachim99@66 209 kdiff3Translator.load( QString("kdiff3_")+locale, translationDir );
joachim99@66 210 app.installTranslator( &kdiff3Translator );
joachim99@66 211
joachim99@66 212 qtTranslator.load( QString("qt_")+locale, translationDir );
joachim99@66 213 app.installTranslator( &qtTranslator );
joachim99@66 214 }
joachim99@53 215 #endif
joachim99@8 216
joachim99@8 217 if (app.isRestored())
joachim99@8 218 {
joachim99@8 219 RESTORE(KDiff3Shell);
joachim99@8 220 }
joachim99@8 221 else
joachim99@8 222 {
joachim99@8 223 new KDiff3Shell();
joachim99@8 224 }
joachim99@8 225
joachim99@69 226 int retVal = app.exec();
joachim99@69 227 return retVal;
joachim99@8 228 }
joachim99@53 229
joachim99@53 230 // Suppress warning with --enable-final
joachim99@53 231 #undef VERSION