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