annotate src/main.cpp @ 756:5a0ece4b81b4

main.cpp: Added a try-catch around the application execution call. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@1033 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Mon, 11 Apr 2011 20:32:52 +0000
parents 4ec2ac09969d
children cc2ba63d6005
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
1 /***************************************************************************
727
aae5a8d04f70 Updated comment copyright year.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 724
diff changeset
2 * Copyright (C) 2006-2010 by Thomas Schweitzer *
60
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
3 * thomas-schweitzer(at)arcor.de *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
4 * *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
5 * This program is free software; you can redistribute it and/or modify *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
6 * it under the terms of the GNU General Public License version 2.0 as *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
7 * published by the Free Software Foundation. *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
8 * *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
9 * This program is distributed in the hope that it will be useful, *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
12 * GNU General Public License for more details. *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
13 * *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
14 * You should have received a copy of the GNU General Public License *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
15 * along with this program in the file LICENSE.GPL; if not, write to the *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
16 * Free Software Foundation, Inc., *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
dd7d1c130e86 Updated the source code GPL preamble.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 5
diff changeset
18 ***************************************************************************/
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
19
638
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
20 #include "MainWindow.h"
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
21
638
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
22 #include "UiGuiIndentServer.h"
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
23 #include "debugging/TSLogger.h"
638
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
24 #include "UiGuiIniFileParser.h"
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
25 #include "UiGuiSettings.h"
691
2af225b848bb Enhanced the logger by an info message type and until now use it at start to log the version.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 688
diff changeset
26 #include "UiGuiVersion.h"
692
e3ff3c85d271 Added a class for retrieving info about the operating system and use this for logging info.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 691
diff changeset
27 #include "UiGuiSystemInfo.h"
751
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
28 #include "IndentHandler.h"
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
29 #include "SettingsPaths.h"
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
30
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
31 #include <QApplication>
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
32 #include <QTextCodec>
756
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
33 #include <QDebug>
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
34
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
35 #include <string>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
36 #include <iostream>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
37 #include <algorithm>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
38 #include <tclap/CmdLine.h>
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
39
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
40 #ifdef WIN32
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
41
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
42 #include <windows.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
43 #include <direct.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
44 #include <stdlib.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
45 #include <stdio.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
46 #include <fcntl.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
47 #include <io.h>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
48 #include <iostream>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
49 #include <fstream>
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
50
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
51 /**
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
52 \brief Calling this function tries to attach to the console of the parent process and
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
53 redirect all inputs and outputs from and to this console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
54
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
55 The redirected streams are stdout, stdin, stderr, cout, wcout, cin, wcin, wcerr, cerr, wclog and clog.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
56
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
57 Code based on info from http://dslweb.nwnexus.com/~ast/dload/guicon.htm.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
58 */
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
59 bool attachToConsole(/*enum ATTACH_ONLY|TRY_ATTACH_ELSE_CREATE|CREATE_NEW*/)
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
60 {
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
61 int hConHandle;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
62 long lStdHandle;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
63 CONSOLE_SCREEN_BUFFER_INFO coninfo;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
64 FILE *fp;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
65
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
66 // Trying to attach to the console of the parent process.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
67 BOOL successful = AttachConsole(ATTACH_PARENT_PROCESS);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
68 // In case that the parent process has no console return false and do no input/output redirection.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
69 if ( !successful )
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
70 return false;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
71
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
72 // Set the screen buffer to be big enough to let us scroll text
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
73 GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &coninfo);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
74 // Set maximum console lines.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
75 coninfo.dwSize.Y = 500;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
76 SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE), coninfo.dwSize);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
77
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
78 // Redirect unbuffered STDOUT to the console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
79 lStdHandle = (long)GetStdHandle(STD_OUTPUT_HANDLE);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
80 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
81 fp = _fdopen( hConHandle, "w" );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
82 *stdout = *fp;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
83 setvbuf( stdout, NULL, _IONBF, 0 );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
84
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
85 // Redirect unbuffered STDIN to the console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
86 lStdHandle = (long)GetStdHandle(STD_INPUT_HANDLE);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
87 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
88 fp = _fdopen( hConHandle, "r" );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
89 *stdin = *fp;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
90 setvbuf( stdin, NULL, _IONBF, 0 );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
91
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
92 // Redirect unbuffered STDERR to the console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
93 lStdHandle = (long)GetStdHandle(STD_ERROR_HANDLE);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
94 hConHandle = _open_osfhandle(lStdHandle, _O_TEXT);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
95 fp = _fdopen( hConHandle, "w" );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
96 *stderr = *fp;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
97 setvbuf( stderr, NULL, _IONBF, 0 );
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
98
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
99 // Make cout, wcout, cin, wcin, wcerr, cerr, wclog and clog point to console as well.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
100 std::ios::sync_with_stdio();
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
101
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
102 return true;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
103 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
104 #endif
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
105
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
106 using namespace tschweitzer::debugging;
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
107
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
108 /*!
500
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
109 /brief Entry point to UniversalIndentGUI application.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
110
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
111 Evaluates the following parameters:
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
112 No parameters starts without server and full gui.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
113 -f filename --file filename : Opens the by filename defined file on start.
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
114 -p --plugin : Run as plugin. Server will be started with a simplified gui.
500
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
115 -s --server : Run as server only without gui.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
116 If -p and -s are set, -p will be used.
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
117 -v --verbose needs a following parameter defining the verbose level as a number from 0 to 3.
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
118 */
635
e1fdfb9adf92 According to the previous code formatting also made the function opening brace be consistently placed.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
119 int main(int argc, char *argv[]) {
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
120 QString file2OpenOnStart = "";
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
121 int verboseLevel = 1;
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
122 bool startAsPlugin = false;
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
123 bool startAsServer = false;
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
124 bool tclapExitExceptionThrown = false;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
125 int returnValue = 0;
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
126
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
127 #ifdef WIN32
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
128 bool attachedToConsole = false;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
129 attachedToConsole = attachToConsole();
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
130 #endif
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
131
734
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
132 #ifdef __APPLE__
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
133 // Filter out -psn_0_118813 and similar parameters.
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
134 std::vector<char*> argList;
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
135 for ( int i = 0; i < argc; i++ ) {
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
136 QString argString(argv[i]);
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
137
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
138 if ( argString.startsWith("-psn_") == false ) {
734
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
139 argList.push_back(argv[i]);
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
140 }
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
141 else {
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
142 // std::cerr << std::endl << "The parameter "<< i << " is an invalid finder parameter. Parameter was " << argv[i] << std::endl;
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
143 }
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
144 }
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
145 for ( size_t i = 0; i < argList.size(); i++ ) {
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
146 argv[i] = argList.at(i);
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
147 }
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
148 argc = argList.size();
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
149 #endif
53de31f7e55b Ensure correct command line parsing on Mac, because when opened with Finder, a curious argument starting with "-psn" will be added.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 727
diff changeset
150
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
151 // Wrap everything in a try block. Do this every time,
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
152 // because exceptions will be thrown for problems.
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
153 try {
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
154 // Define the command line object.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
155 TCLAP::CmdLine cmd("If -p and -s are set, -p will be used.\nGiving no parameters starts full gui without server.", ' ', "UiGUI version " PROGRAM_VERSION_STRING " " PROGRAM_REVISION);
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
156 cmd.setExceptionHandling(false);
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
157
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
158 // Define a value argument and add it to the command line.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
159 TCLAP::ValueArg<std::string> filenameArg("f", "file", "Opens the by filename defined file on start" , false, "", "string");
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
160 cmd.add( filenameArg );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
161
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
162 // Define a switch and add it to the command line.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
163 TCLAP::SwitchArg pluginSwitch("p", "plugin", "Run as plugin. Server will be started with a simplified gui", false);
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
164 cmd.add( pluginSwitch );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
165
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
166 // Define a switch and add it to the command line.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
167 TCLAP::SwitchArg serverSwitch("s", "server", "Run as server only without gui", false);
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
168 cmd.add( serverSwitch );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
169
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
170 // Define a value argument and add it to the command line.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
171 TCLAP::ValueArg<int> verboselevelArg("v", "verbose", "Sets how many info is written to the log. 0 means with debug info, 3 means critical messages only" , false, 1, "int");
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
172 cmd.add( verboselevelArg );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
173
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
174 // Parse the args.
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
175 cmd.parse( argc, argv );
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
176
742
edde9cbb2ce4 Corrected filtering of faulty finder command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 734
diff changeset
177 // Get the value parsed by each arg.
753
e64c04dc6f61 Made the code be compatible to the Qt compile variant with "-no-stl" being set.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 751
diff changeset
178 file2OpenOnStart = filenameArg.getValue().c_str();
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
179 startAsPlugin = pluginSwitch.getValue();
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
180 startAsServer = serverSwitch.getValue();
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
181 verboseLevel = verboselevelArg.getValue();
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
182 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
183 catch (TCLAP::ArgException &e) { // catch arg exceptions
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
184 std::cerr << std::endl << "error: " << e.error() << ". " << e.argId() << std::endl;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
185 returnValue = 1;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
186 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
187 catch (TCLAP::ExitException &e) { // catch exit exceptions
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
188 tclapExitExceptionThrown = true;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
189 returnValue = e.getExitStatus();
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
190 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
191 catch (...) { // catch any exceptions
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
192 std::cerr << std::endl << "There was an error! Maybe faulty command line arguments set. See --help." << std::endl;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
193 returnValue = 1;
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
194 }
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
195
721
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
196 if ( returnValue != 0 || tclapExitExceptionThrown ) {
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
197 #ifdef WIN32
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
198 if ( attachedToConsole ) {
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
199 // Workaround for skipped command line prompt: Get the current working directory and print it to console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
200 char* buffer;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
201 if( (buffer = _getcwd( NULL, 0 )) != NULL ) {
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
202 std::cerr << std::endl << buffer << ">";
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
203 free(buffer);
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
204 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
205 // Release the connection to the parents console.
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
206 FreeConsole();
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
207 }
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
208 #endif
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
209 return returnValue;
834d23977a17 Corrected catching of TCLAP exceptions and showing correct console output.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 720
diff changeset
210 }
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
211
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
212 QApplication app(argc, argv);
638
94734b9eb54f Renamed the source files and some classes to have consistent names. What a nice kind of work.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 635
diff changeset
213 UiGuiIndentServer server;
500
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
214 MainWindow *mainWindow = NULL;
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
215 IndentHandler *indentHandler = NULL;
496
205b2f8adf4a In preparation for some kind of IPC added a server class. With this abstraction it will be easier to create plugins for other ides or editors which can communicate with UiGUI.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 479
diff changeset
216
709
718e2e543cd1 Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 692
diff changeset
217 // Init and install the logger function.
718e2e543cd1 Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 692
diff changeset
218 // Setting UTF-8 as default 8-Bit encoding to ensure that qDebug does no false string conversion.
718e2e543cd1 Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 692
diff changeset
219 QTextCodec::setCodecForCStrings( QTextCodec::codecForName("UTF-8") );
718e2e543cd1 Start parsing the command line arguments before the logger is initialized. Otherwise the command line verbose level applies too late and some debug output might be missing.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 692
diff changeset
220 QTextCodec::setCodecForLocale( QTextCodec::codecForName("UTF-8") );
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
221 // Force creation of an TSLogger instance here, to avoid recursion with SettingsPaths init function.
687
b4aee13bc733 - Added a new class, that is responsible for logging of any kind and added some logging/debug output calls.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
222 #ifdef _DEBUG
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
223 TSLogger::getInstance(0);
688
b5b686bac866 Made it possible to set the verbose level via command line parameter.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 687
diff changeset
224 #else
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
225 TSLogger::getInstance(verboseLevel);
687
b4aee13bc733 - Added a new class, that is responsible for logging of any kind and added some logging/debug output calls.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 648
diff changeset
226 #endif
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
227 qInstallMsgHandler( TSLogger::messageHandler );
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
228 TSLogger::messageHandler( TSLoggerInfoMsg, QString("Starting UiGUI Version %1 %2").arg(PROGRAM_VERSION_STRING).arg(PROGRAM_REVISION).toAscii() );
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
229 TSLogger::messageHandler( TSLoggerInfoMsg, QString("Running on %1").arg(UiGuiSystemInfo::getOperatingSystem()).toAscii() );
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 571
diff changeset
230
528
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
231 // Set default values for all by UniversalIndentGUI used settings objects.
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
232 QCoreApplication::setOrganizationName("UniversalIndentGUI");
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
233 QCoreApplication::setOrganizationDomain("universalindent.sf.net");
7a1b429fd4e7 - Removed any warnings.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 500
diff changeset
234 QCoreApplication::setApplicationName("UniversalIndentGUI");
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
235
500
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
236 // Start normal with full gui and without server.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
237 if ( !startAsPlugin && !startAsServer ) {
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
238 mainWindow = new MainWindow(file2OpenOnStart);
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
239 mainWindow->show();
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
240 }
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
241 // Start as plugin with server.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
242 else if ( startAsPlugin ) {
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
243 server.startServer();
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
244 indentHandler = new IndentHandler(0);
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
245 indentHandler->show();
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
246 }
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
247 // Start as server only without any gui.
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
248 else if ( startAsServer ) {
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
249 server.startServer();
70e6985f83a2 Made it possible to start UiGUI with different command line parameters.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 496
diff changeset
250 }
63
aea5d4632a2f replaced tabs by spaces.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 60
diff changeset
251
756
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
252 try {
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
253 returnValue = app.exec();
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
254 }
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
255 catch (std::exception &ex) {
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
256 qCritical() << __LINE__ << " " << __FUNCTION__ << ": Something went terribly wrong:" << ex.what();
5a0ece4b81b4 main.cpp: Added a try-catch around the application execution call.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 754
diff changeset
257 }
571
f401efb5080b Explicitly calling delete on the MainWindow and IndentHandler objects and now the (dependent) destructors are also correctly called.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 557
diff changeset
258
724
6cca48ee1557 Small correction and compiler warning avoid.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 721
diff changeset
259 if ( startAsPlugin || startAsServer )
571
f401efb5080b Explicitly calling delete on the MainWindow and IndentHandler objects and now the (dependent) destructors are also correctly called.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 557
diff changeset
260 server.stopServer();
720
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
261
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
262 delete indentHandler;
22e493961280 Replaced my own command line parsing by TCLAP.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 714
diff changeset
263 delete mainWindow;
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 571
diff changeset
264
751
ac165b6ae67e Done some refactoring:
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 742
diff changeset
265 SettingsPaths::cleanAndRemoveTempDir();
754
4ec2ac09969d Renamed the logger class and put it into a namespace for later universal tool reuse.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 753
diff changeset
266 TSLogger::deleteInstance();
571
f401efb5080b Explicitly calling delete on the MainWindow and IndentHandler objects and now the (dependent) destructors are also correctly called.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 557
diff changeset
267
f401efb5080b Explicitly calling delete on the MainWindow and IndentHandler objects and now the (dependent) destructors are also correctly called.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 557
diff changeset
268 return returnValue;
1
e6a2f4c49682 Restucturing of repository
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
269 }